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 "StyleImage.h"
27
28namespace WebCore {
29
30class CSSValue;
31class CSSImageGeneratorValue;
32
33class StyleGeneratedImage final : public StyleImage {
34public:
35 static Ref<StyleGeneratedImage> create(Ref<CSSImageGeneratorValue>&& value)
36 {
37 return adoptRef(*new StyleGeneratedImage(WTFMove(value)));
38 }
39
40 CSSImageGeneratorValue& imageValue() { return m_imageGeneratorValue; }
41
42private:
43 bool operator==(const StyleImage& other) const final { return data() == other.data(); }
44
45 WrappedImagePtr data() const final { return m_imageGeneratorValue.ptr(); }
46
47 Ref<CSSValue> cssValue() const final;
48
49 bool isPending() const override;
50 void load(CachedResourceLoader&, const ResourceLoaderOptions&) final;
51 FloatSize imageSize(const RenderElement*, float multiplier) const final;
52 bool imageHasRelativeWidth() const final { return !m_fixedSize; }
53 bool imageHasRelativeHeight() const final { return !m_fixedSize; }
54 void computeIntrinsicDimensions(const RenderElement*, Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio) final;
55 bool usesImageContainerSize() const final { return !m_fixedSize; }
56 void setContainerContextForRenderer(const RenderElement&, const FloatSize& containerSize, float) final { m_containerSize = containerSize; }
57 void addClient(RenderElement*) final;
58 void removeClient(RenderElement*) final;
59 RefPtr<Image> image(RenderElement*, const FloatSize&) const final;
60 bool knownToBeOpaque(const RenderElement*) const final;
61
62 explicit StyleGeneratedImage(Ref<CSSImageGeneratorValue>&&);
63
64 Ref<CSSImageGeneratorValue> m_imageGeneratorValue;
65 FloatSize m_containerSize;
66 bool m_fixedSize;
67};
68
69} // namespace WebCore
70
71SPECIALIZE_TYPE_TRAITS_STYLE_IMAGE(StyleGeneratedImage, isGeneratedImage)
72