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 "CSSValueKeywords.h"
26 #include "MemoryCache.h"
27 #include "CachedImage.h"
28 #include "CachedResourceLoader.h"
29 #include "StyleCachedImage.h"
30 #include "StylePendingImage.h"
34 CSSImageValue::CSSImageValue(const String& url)
35 : CSSPrimitiveValue(url, CSS_URI)
36 , m_accessedImage(false)
40 CSSImageValue::CSSImageValue()
41 : CSSPrimitiveValue(CSSValueNone)
42 , m_accessedImage(true)
46 CSSImageValue::~CSSImageValue()
48 if (m_image && m_image->isCachedImage())
49 static_cast<StyleCachedImage*>(m_image.get())->cachedImage()->removeClient(this);
52 StyleImage* CSSImageValue::cachedOrPendingImage()
54 if (getIdent() == CSSValueNone)
58 m_image = StylePendingImage::create(this);
63 StyleCachedImage* CSSImageValue::cachedImage(CachedResourceLoader* loader)
65 return cachedImage(loader, getStringValue());
68 StyleCachedImage* CSSImageValue::cachedImage(CachedResourceLoader* loader, const String& url)
72 if (!m_accessedImage) {
73 m_accessedImage = true;
75 ResourceRequest request(loader->document()->completeURL(url));
76 if (CachedImage* cachedImage = loader->requestImage(request)) {
77 cachedImage->addClient(this);
78 m_image = StyleCachedImage::create(cachedImage);
82 return (m_image && m_image->isCachedImage()) ? static_cast<StyleCachedImage*>(m_image.get()) : 0;
85 String CSSImageValue::cachedImageURL()
87 if (!m_image || !m_image->isCachedImage())
89 return static_cast<StyleCachedImage*>(m_image.get())->cachedImage()->url();
92 void CSSImageValue::clearCachedImage()
94 if (m_image && m_image->isCachedImage())
95 static_cast<StyleCachedImage*>(m_image.get())->cachedImage()->removeClient(this);
97 m_accessedImage = false;
100 } // namespace WebCore