1/*
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24#pragma once
25
26#include "CachedResourceHandle.h"
27#include "StyleImage.h"
28
29namespace WebCore {
30
31class CSSValue;
32class CachedImage;
33class Document;
34
35class StyleCachedImage final : public StyleImage {
36 WTF_MAKE_FAST_ALLOCATED;
37public:
38 static Ref<StyleCachedImage> create(CSSValue& cssValue) { return adoptRef(*new StyleCachedImage(cssValue)); }
39 virtual ~StyleCachedImage();
40
41 bool operator==(const StyleImage& other) const final;
42
43 CachedImage* cachedImage() const final;
44
45 WrappedImagePtr data() const final { return m_cachedImage.get(); }
46
47 Ref<CSSValue> cssValue() const final;
48
49 bool canRender(const RenderElement*, float multiplier) const final;
50 bool isPending() const final;
51 void load(CachedResourceLoader&, const ResourceLoaderOptions&) final;
52 bool isLoaded() const final;
53 bool errorOccurred() const final;
54 FloatSize imageSize(const RenderElement*, float multiplier) const final;
55 bool imageHasRelativeWidth() const final;
56 bool imageHasRelativeHeight() const final;
57 void computeIntrinsicDimensions(const RenderElement*, Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio) final;
58 bool usesImageContainerSize() const final;
59 void setContainerContextForRenderer(const RenderElement&, const FloatSize&, float) final;
60 void addClient(RenderElement*) final;
61 void removeClient(RenderElement*) final;
62 RefPtr<Image> image(RenderElement*, const FloatSize&) const final;
63 float imageScaleFactor() const final;
64 bool knownToBeOpaque(const RenderElement*) const final;
65
66private:
67 StyleCachedImage(CSSValue&);
68 URL imageURL();
69
70 Ref<CSSValue> m_cssValue;
71 bool m_isPending { true };
72 mutable float m_scaleFactor { 1 };
73 mutable CachedResourceHandle<CachedImage> m_cachedImage;
74};
75
76} // namespace WebCore
77
78SPECIALIZE_TYPE_TRAITS_STYLE_IMAGE(StyleCachedImage, isCachedImage)
79