1/*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2008, 2012 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#ifndef CSSImageValue_h
22#define CSSImageValue_h
23
24#include "core/css/CSSValue.h"
25#include "core/fetch/ResourceFetcher.h"
26#include "platform/weborigin/Referrer.h"
27#include "wtf/RefPtr.h"
28
29namespace blink {
30
31class Document;
32class KURL;
33class StyleFetchedImage;
34class StyleImage;
35class RenderObject;
36
37class CSSImageValue : public CSSValue {
38public:
39    static PassRefPtrWillBeRawPtr<CSSImageValue> create(const KURL& url, StyleImage* image = 0)
40    {
41        return adoptRefWillBeNoop(new CSSImageValue(url, url, image));
42    }
43    static PassRefPtrWillBeRawPtr<CSSImageValue> create(const String& rawValue, const KURL& url, StyleImage* image = 0)
44    {
45        return adoptRefWillBeNoop(new CSSImageValue(rawValue, url, image));
46    }
47    ~CSSImageValue();
48
49    StyleFetchedImage* cachedImage(ResourceFetcher*, const ResourceLoaderOptions&);
50    StyleFetchedImage* cachedImage(ResourceFetcher* fetcher) { return cachedImage(fetcher, ResourceFetcher::defaultResourceOptions()); }
51    // Returns a StyleFetchedImage if the image is cached already, otherwise a StylePendingImage.
52    StyleImage* cachedOrPendingImage();
53
54    const String& url() { return m_absoluteURL; }
55
56    void setReferrer(const Referrer& referrer) { m_referrer = referrer; }
57    const Referrer& referrer() const { return m_referrer; }
58
59    void reResolveURL(const Document&);
60
61    String customCSSText() const;
62
63    PassRefPtrWillBeRawPtr<CSSValue> cloneForCSSOM() const;
64
65    bool hasFailedOrCanceledSubresources() const;
66
67    bool equals(const CSSImageValue&) const;
68
69    bool knownToBeOpaque(const RenderObject*) const;
70
71    void setInitiator(const AtomicString& name) { m_initiatorName = name; }
72
73    void traceAfterDispatch(Visitor*);
74    void restoreCachedResourceIfNeeded(Document&);
75
76private:
77    CSSImageValue(const String& rawValue, const KURL&, StyleImage*);
78
79    String m_relativeURL;
80    String m_absoluteURL;
81    Referrer m_referrer;
82    RefPtr<StyleImage> m_image;
83    bool m_accessedImage;
84    AtomicString m_initiatorName;
85};
86
87DEFINE_CSS_VALUE_TYPE_CASTS(CSSImageValue, isImageValue());
88
89} // namespace blink
90
91#endif // CSSImageValue_h
92