PageRenderTime 22ms CodeModel.GetById 16ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/platform/external/webkit/WebCore/css/CSSImageValue.cpp

https://github.com/aharish/totoro-gb-opensource-update2
C++ | 92 lines | 58 code | 14 blank | 20 comment | 7 complexity | a9a49bba520ba9728d61ec46f112287f MD5 | raw file
 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 "StyleCachedImage.h"
29
30namespace WebCore {
31
32CSSImageValue::CSSImageValue(const String& url)
33    : CSSPrimitiveValue(url, CSS_URI)
34    , m_accessedImage(false)
35{
36}
37
38CSSImageValue::CSSImageValue()
39    : CSSPrimitiveValue(CSSValueNone)
40    , m_accessedImage(true)
41{
42}
43
44CSSImageValue::~CSSImageValue()
45{
46    if (m_image)
47        m_image->cachedImage()->removeClient(this);
48}
49
50StyleCachedImage* CSSImageValue::cachedImage(DocLoader* loader)
51{
52    return cachedImage(loader, getStringValue());
53}
54
55StyleCachedImage* 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
77String CSSImageValue::cachedImageURL()
78{
79    if (!m_image)
80        return String();
81    return m_image->cachedImage()->url();
82}
83
84void 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