1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@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 "RenderStyle.h"
29 #include "StyleCachedImage.h"
30
31 namespace WebCore {
32
CSSImageValue(const String & url)33 CSSImageValue::CSSImageValue(const String& url)
34 : CSSPrimitiveValue(url, CSS_URI)
35 , m_accessedImage(false)
36 {
37 }
38
CSSImageValue()39 CSSImageValue::CSSImageValue()
40 : CSSPrimitiveValue(CSSValueNone)
41 , m_accessedImage(true)
42 {
43 }
44
~CSSImageValue()45 CSSImageValue::~CSSImageValue()
46 {
47 if (m_image)
48 m_image->cachedImage()->removeClient(this);
49 }
50
cachedImage(DocLoader * loader)51 StyleCachedImage* CSSImageValue::cachedImage(DocLoader* loader)
52 {
53 return cachedImage(loader, getStringValue());
54 }
55
cachedImage(DocLoader * loader,const String & url)56 StyleCachedImage* CSSImageValue::cachedImage(DocLoader* loader, const String& url)
57 {
58 if (!m_accessedImage) {
59 m_accessedImage = true;
60
61 CachedImage* cachedImage = 0;
62 if (loader)
63 cachedImage = loader->requestImage(url);
64 else {
65 // FIXME: Should find a way to make these images sit in their own memory partition, since they are user agent images.
66 cachedImage = static_cast<CachedImage*>(cache()->requestResource(0, CachedResource::ImageResource, KURL(url), String()));
67 }
68
69 if (cachedImage) {
70 cachedImage->addClient(this);
71 m_image = StyleCachedImage::create(cachedImage);
72 }
73 }
74
75 return m_image.get();
76 }
77
cachedImageURL()78 String CSSImageValue::cachedImageURL()
79 {
80 if (!m_image)
81 return String();
82 return m_image->cachedImage()->url();
83 }
84
clearCachedImage()85 void CSSImageValue::clearCachedImage()
86 {
87 if (m_image)
88 m_image->cachedImage()->removeClient(this);
89 m_image = 0;
90 m_accessedImage = false;
91 }
92
93 } // namespace WebCore
94