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 "CachedImage.h"
27 #include "DocLoader.h"
28 #include "StyleCachedImage.h"
32 CSSImageValue::CSSImageValue(const String& url)
33 : CSSPrimitiveValue(url, CSS_URI)
34 , m_accessedImage(false)
38 CSSImageValue::CSSImageValue()
39 : CSSPrimitiveValue(CSSValueNone)
40 , m_accessedImage(true)
44 CSSImageValue::~CSSImageValue()
47 m_image->cachedImage()->removeClient(this);
50 StyleCachedImage* CSSImageValue::cachedImage(DocLoader* loader)
52 return cachedImage(loader, getStringValue());
55 StyleCachedImage* CSSImageValue::cachedImage(DocLoader* loader, const String& url)
57 if (!m_accessedImage) {
58 m_accessedImage = true;
60 CachedImage* cachedImage = 0;
62 cachedImage = loader->requestImage(url);
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()));
69 cachedImage->addClient(this);
70 m_image = StyleCachedImage::create(cachedImage);
77 String CSSImageValue::cachedImageURL()
81 return m_image->cachedImage()->url();
84 void CSSImageValue::clearCachedImage()
87 m_image->cachedImage()->removeClient(this);
89 m_accessedImage = false;
92 } // namespace WebCore