2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
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.
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.
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.
22 #include "CSSImageValue.h"
24 #include "CSSCursorImageValue.h"
25 #include "CSSParser.h"
26 #include "CSSValueKeywords.h"
28 #include "MemoryCache.h"
29 #include "CachedImage.h"
30 #include "CachedResourceLoader.h"
31 #include "StyleCachedImage.h"
32 #include "StylePendingImage.h"
36 CSSImageValue::CSSImageValue(ClassType classType, const String& url)
39 , m_accessedImage(false)
43 CSSImageValue::CSSImageValue(const String& url)
44 : CSSValue(ImageClass)
46 , m_accessedImage(false)
50 CSSImageValue::CSSImageValue(const String& url, StyleImage* image)
51 : CSSValue(ImageClass)
54 , m_accessedImage(true)
58 CSSImageValue::~CSSImageValue()
62 StyleImage* CSSImageValue::cachedOrPendingImage()
65 m_image = StylePendingImage::create(this);
70 StyleCachedImage* CSSImageValue::cachedImage(CachedResourceLoader* loader)
72 if (isCursorImageValue())
73 return static_cast<CSSCursorImageValue*>(this)->cachedImage(loader);
74 return cachedImage(loader, m_url);
77 StyleCachedImage* CSSImageValue::cachedImage(CachedResourceLoader* loader, const String& url)
81 if (!m_accessedImage) {
82 m_accessedImage = true;
84 ResourceRequest request(loader->document()->completeURL(url));
85 if (CachedResourceHandle<CachedImage> cachedImage = loader->requestImage(request))
86 m_image = StyleCachedImage::create(cachedImage.get());
89 return (m_image && m_image->isCachedImage()) ? static_cast<StyleCachedImage*>(m_image.get()) : 0;
92 String CSSImageValue::cachedImageURL()
94 if (!m_image || !m_image->isCachedImage())
96 return static_cast<StyleCachedImage*>(m_image.get())->cachedImage()->url();
99 void CSSImageValue::clearCachedImage()
102 m_accessedImage = false;
105 String CSSImageValue::customCssText() const
107 return "url(" + quoteCSSURLIfNeeded(m_url) + ")";
110 PassRefPtr<CSSValue> CSSImageValue::cloneForCSSOM() const
112 // NOTE: We expose CSSImageValues as URI primitive values in CSSOM to maintain old behavior.
113 RefPtr<CSSPrimitiveValue> uriValue = CSSPrimitiveValue::create(m_url, CSSPrimitiveValue::CSS_URI);
114 uriValue->setCSSOMSafe();
115 return uriValue.release();
118 } // namespace WebCore