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#pragma once
22
23#include "CSSValue.h"
24#include "CachedResourceHandle.h"
25#include "ResourceLoaderOptions.h"
26#include <wtf/Function.h>
27#include <wtf/Ref.h>
28
29namespace WebCore {
30
31class CachedImage;
32class CachedResourceLoader;
33class DeprecatedCSSOMValue;
34class CSSStyleDeclaration;
35class RenderElement;
36
37class CSSImageValue final : public CSSValue {
38public:
39 static Ref<CSSImageValue> create(URL&& url, LoadedFromOpaqueSource loadedFromOpaqueSource) { return adoptRef(*new CSSImageValue(WTFMove(url), loadedFromOpaqueSource)); }
40 static Ref<CSSImageValue> create(CachedImage& image) { return adoptRef(*new CSSImageValue(image)); }
41 ~CSSImageValue();
42
43 bool isPending() const;
44 CachedImage* loadImage(CachedResourceLoader&, const ResourceLoaderOptions&);
45 CachedImage* cachedImage() const { return m_cachedImage.get(); }
46
47 const URL& url() const { return m_url; }
48
49 String customCSSText() const;
50
51 Ref<DeprecatedCSSOMValue> createDeprecatedCSSOMWrapper(CSSStyleDeclaration&) const;
52
53 bool traverseSubresources(const WTF::Function<bool (const CachedResource&)>& handler) const;
54
55 bool equals(const CSSImageValue&) const;
56
57 bool knownToBeOpaque(const RenderElement&) const;
58
59 void setInitiator(const AtomString& name) { m_initiatorName = name; }
60
61private:
62 CSSImageValue(URL&&, LoadedFromOpaqueSource);
63 explicit CSSImageValue(CachedImage&);
64
65 URL m_url;
66 CachedResourceHandle<CachedImage> m_cachedImage;
67 bool m_accessedImage;
68 AtomString m_initiatorName;
69 LoadedFromOpaqueSource m_loadedFromOpaqueSource { LoadedFromOpaqueSource::No };
70};
71
72} // namespace WebCore
73
74SPECIALIZE_TYPE_TRAITS_CSS_VALUE(CSSImageValue, isImageValue())
75