1 /* 2 * (C) 1999-2003 Lars Knoll (knoll (at) kde.org) 3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21 #include "config.h" 22 #include "CSSImageValue.h" 23 24 #include "CSSValueKeywords.h" 25 #include "Cache.h" 26 #include "CachedImage.h" 27 #include "DocLoader.h" 28 #include "StyleCachedImage.h" 29 30 namespace WebCore { 31 32 CSSImageValue::CSSImageValue(const String& url) 33 : CSSPrimitiveValue(url, CSS_URI) 34 , m_accessedImage(false) 35 { 36 } 37 38 CSSImageValue::CSSImageValue() 39 : CSSPrimitiveValue(CSSValueNone) 40 , m_accessedImage(true) 41 { 42 } 43 44 CSSImageValue::~CSSImageValue() 45 { 46 if (m_image) 47 m_image->cachedImage()->removeClient(this); 48 } 49 50 StyleCachedImage* CSSImageValue::cachedImage(DocLoader* loader) 51 { 52 return cachedImage(loader, getStringValue()); 53 } 54 55 StyleCachedImage* CSSImageValue::cachedImage(DocLoader* loader, const String& url) 56 { 57 if (!m_accessedImage) { 58 m_accessedImage = true; 59 60 CachedImage* cachedImage = 0; 61 if (loader) 62 cachedImage = loader->requestImage(url); 63 else { 64 // FIXME: Should find a way to make these images sit in their own memory partition, since they are user agent images. 65 cachedImage = static_cast<CachedImage*>(cache()->requestResource(0, CachedResource::ImageResource, KURL(ParsedURLString, url), String())); 66 } 67 68 if (cachedImage) { 69 cachedImage->addClient(this); 70 m_image = StyleCachedImage::create(cachedImage); 71 } 72 } 73 74 return m_image.get(); 75 } 76 77 String CSSImageValue::cachedImageURL() 78 { 79 if (!m_image) 80 return String(); 81 return m_image->cachedImage()->url(); 82 } 83 84 void CSSImageValue::clearCachedImage() 85 { 86 if (m_image) 87 m_image->cachedImage()->removeClient(this); 88 m_image = 0; 89 m_accessedImage = false; 90 } 91 92 } // namespace WebCore 93