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, 2014 Apple Inc. All rights reserved. |
6 | * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) |
7 | * |
8 | * This library is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; either |
11 | * version 2 of the License, or (at your option) any later version. |
12 | * |
13 | * This library is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | * Library General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU Library General Public License |
19 | * along with this library; see the file COPYING.LIB. If not, write to |
20 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | * Boston, MA 02110-1301, USA. |
22 | * |
23 | */ |
24 | |
25 | #pragma once |
26 | |
27 | #include "GraphicsTypes.h" |
28 | #include "LengthSize.h" |
29 | #include "RenderStyleConstants.h" |
30 | #include "StyleImage.h" |
31 | #include <wtf/RefPtr.h> |
32 | |
33 | namespace WebCore { |
34 | |
35 | class RenderElement; |
36 | |
37 | struct FillSize { |
38 | FillSize() |
39 | : type(FillSizeType::Size) |
40 | { |
41 | } |
42 | |
43 | FillSize(FillSizeType type, const LengthSize& size) |
44 | : type(type) |
45 | , size(size) |
46 | { |
47 | } |
48 | |
49 | FillSizeType type; |
50 | LengthSize size; |
51 | }; |
52 | |
53 | inline bool operator==(const FillSize& a, const FillSize& b) |
54 | { |
55 | return a.type == b.type && a.size == b.size; |
56 | } |
57 | |
58 | inline bool operator!=(const FillSize& a, const FillSize& b) |
59 | { |
60 | return !(a == b); |
61 | } |
62 | |
63 | class FillLayer { |
64 | WTF_MAKE_FAST_ALLOCATED; |
65 | public: |
66 | explicit FillLayer(FillLayerType); |
67 | ~FillLayer(); |
68 | |
69 | StyleImage* image() const { return m_image.get(); } |
70 | const Length& xPosition() const { return m_xPosition; } |
71 | const Length& yPosition() const { return m_yPosition; } |
72 | Edge backgroundXOrigin() const { return static_cast<Edge>(m_backgroundXOrigin); } |
73 | Edge backgroundYOrigin() const { return static_cast<Edge>(m_backgroundYOrigin); } |
74 | FillAttachment attachment() const { return static_cast<FillAttachment>(m_attachment); } |
75 | FillBox clip() const { return static_cast<FillBox>(m_clip); } |
76 | FillBox origin() const { return static_cast<FillBox>(m_origin); } |
77 | FillRepeat repeatX() const { return static_cast<FillRepeat>(m_repeatX); } |
78 | FillRepeat repeatY() const { return static_cast<FillRepeat>(m_repeatY); } |
79 | CompositeOperator composite() const { return static_cast<CompositeOperator>(m_composite); } |
80 | BlendMode blendMode() const { return static_cast<BlendMode>(m_blendMode); } |
81 | const LengthSize& sizeLength() const { return m_sizeLength; } |
82 | FillSizeType sizeType() const { return static_cast<FillSizeType>(m_sizeType); } |
83 | FillSize size() const { return FillSize(static_cast<FillSizeType>(m_sizeType), m_sizeLength); } |
84 | MaskSourceType maskSourceType() const { return static_cast<MaskSourceType>(m_maskSourceType); } |
85 | |
86 | const FillLayer* next() const { return m_next.get(); } |
87 | FillLayer* next() { return m_next.get(); } |
88 | |
89 | bool isImageSet() const { return m_imageSet; } |
90 | bool isXPositionSet() const { return m_xPosSet; } |
91 | bool isYPositionSet() const { return m_yPosSet; } |
92 | bool isBackgroundXOriginSet() const { return m_backgroundXOriginSet; } |
93 | bool isBackgroundYOriginSet() const { return m_backgroundYOriginSet; } |
94 | bool isAttachmentSet() const { return m_attachmentSet; } |
95 | bool isClipSet() const { return m_clipSet; } |
96 | bool isOriginSet() const { return m_originSet; } |
97 | bool isRepeatXSet() const { return m_repeatXSet; } |
98 | bool isRepeatYSet() const { return m_repeatYSet; } |
99 | bool isCompositeSet() const { return m_compositeSet; } |
100 | bool isBlendModeSet() const { return m_blendModeSet; } |
101 | bool isSizeSet() const { return static_cast<FillSizeType>(m_sizeType) != FillSizeType::None; } |
102 | bool isMaskSourceTypeSet() const { return m_maskSourceTypeSet; } |
103 | |
104 | bool isEmpty() const { return (sizeType() == FillSizeType::Size && m_sizeLength.isEmpty()) || sizeType() == FillSizeType::None; } |
105 | |
106 | void setImage(RefPtr<StyleImage>&& image) { m_image = WTFMove(image); m_imageSet = true; } |
107 | void setXPosition(Length length) { m_xPosition = WTFMove(length); m_xPosSet = true; } |
108 | void setYPosition(Length length) { m_yPosition = WTFMove(length); m_yPosSet = true; } |
109 | void setBackgroundXOrigin(Edge o) { m_backgroundXOrigin = static_cast<unsigned>(o); m_backgroundXOriginSet = true; } |
110 | void setBackgroundYOrigin(Edge o) { m_backgroundYOrigin = static_cast<unsigned>(o); m_backgroundYOriginSet = true; } |
111 | void setAttachment(FillAttachment attachment) { m_attachment = static_cast<unsigned>(attachment); m_attachmentSet = true; } |
112 | void setClip(FillBox b) { m_clip = static_cast<unsigned>(b); m_clipSet = true; } |
113 | void setOrigin(FillBox b) { m_origin = static_cast<unsigned>(b); m_originSet = true; } |
114 | void setRepeatX(FillRepeat r) { m_repeatX = static_cast<unsigned>(r); m_repeatXSet = true; } |
115 | void setRepeatY(FillRepeat r) { m_repeatY = static_cast<unsigned>(r); m_repeatYSet = true; } |
116 | void setComposite(CompositeOperator c) { m_composite = static_cast<unsigned>(c); m_compositeSet = true; } |
117 | void setBlendMode(BlendMode b) { m_blendMode = static_cast<unsigned>(b); m_blendModeSet = true; } |
118 | void setSizeType(FillSizeType b) { m_sizeType = static_cast<unsigned>(b); } |
119 | void setSizeLength(LengthSize l) { m_sizeLength = l; } |
120 | void setSize(FillSize f) { m_sizeType = static_cast<unsigned>(f.type); m_sizeLength = f.size; } |
121 | void setMaskSourceType(MaskSourceType m) { m_maskSourceType = static_cast<unsigned>(m); m_maskSourceTypeSet = true; } |
122 | |
123 | void clearImage() { m_image = nullptr; m_imageSet = false; } |
124 | |
125 | void clearXPosition() { m_xPosSet = false; m_backgroundXOriginSet = false; } |
126 | void clearYPosition() { m_yPosSet = false; m_backgroundYOriginSet = false; } |
127 | |
128 | void clearAttachment() { m_attachmentSet = false; } |
129 | void clearClip() { m_clipSet = false; } |
130 | void clearOrigin() { m_originSet = false; } |
131 | void clearRepeatX() { m_repeatXSet = false; } |
132 | void clearRepeatY() { m_repeatYSet = false; } |
133 | void clearComposite() { m_compositeSet = false; } |
134 | void clearBlendMode() { m_blendModeSet = false; } |
135 | void clearSize() { m_sizeType = static_cast<unsigned>(FillSizeType::None); } |
136 | void clearMaskSourceType() { m_maskSourceTypeSet = false; } |
137 | |
138 | void setNext(std::unique_ptr<FillLayer> next) { m_next = WTFMove(next); } |
139 | |
140 | FillLayer& operator=(const FillLayer&); |
141 | FillLayer(const FillLayer&); |
142 | |
143 | bool operator==(const FillLayer&) const; |
144 | bool operator!=(const FillLayer& other) const { return !(*this == other); } |
145 | |
146 | bool containsImage(StyleImage&) const; |
147 | bool imagesAreLoaded() const; |
148 | bool hasImage() const; |
149 | bool hasFixedImage() const; |
150 | bool hasOpaqueImage(const RenderElement&) const; |
151 | bool hasRepeatXY() const; |
152 | bool clipOccludesNextLayers(bool firstLayer) const; |
153 | |
154 | FillLayerType type() const { return static_cast<FillLayerType>(m_type); } |
155 | |
156 | void fillUnsetProperties(); |
157 | void cullEmptyLayers(); |
158 | |
159 | static bool imagesIdentical(const FillLayer*, const FillLayer*); |
160 | |
161 | static FillAttachment initialFillAttachment(FillLayerType) { return FillAttachment::ScrollBackground; } |
162 | static FillBox initialFillClip(FillLayerType) { return FillBox::Border; } |
163 | static FillBox initialFillOrigin(FillLayerType type) { return type == FillLayerType::Background ? FillBox::Padding : FillBox::Border; } |
164 | static FillRepeat initialFillRepeatX(FillLayerType) { return FillRepeat::Repeat; } |
165 | static FillRepeat initialFillRepeatY(FillLayerType) { return FillRepeat::Repeat; } |
166 | static CompositeOperator initialFillComposite(FillLayerType) { return CompositeSourceOver; } |
167 | static BlendMode initialFillBlendMode(FillLayerType) { return BlendMode::Normal; } |
168 | static FillSize initialFillSize(FillLayerType) { return { }; } |
169 | static Length initialFillXPosition(FillLayerType) { return Length(0.0f, Percent); } |
170 | static Length initialFillYPosition(FillLayerType) { return Length(0.0f, Percent); } |
171 | static StyleImage* initialFillImage(FillLayerType) { return nullptr; } |
172 | static MaskSourceType initialFillMaskSourceType(FillLayerType) { return MaskSourceType::Alpha; } |
173 | |
174 | private: |
175 | friend class RenderStyle; |
176 | |
177 | void computeClipMax() const; |
178 | |
179 | std::unique_ptr<FillLayer> m_next; |
180 | |
181 | RefPtr<StyleImage> m_image; |
182 | |
183 | Length m_xPosition; |
184 | Length m_yPosition; |
185 | |
186 | LengthSize m_sizeLength; |
187 | |
188 | unsigned m_attachment : 2; // FillAttachment |
189 | unsigned m_clip : 2; // FillBox |
190 | unsigned m_origin : 2; // FillBox |
191 | unsigned m_repeatX : 3; // FillRepeat |
192 | unsigned m_repeatY : 3; // FillRepeat |
193 | unsigned m_composite : 4; // CompositeOperator |
194 | unsigned m_sizeType : 2; // FillSizeType |
195 | unsigned m_blendMode : 5; // BlendMode |
196 | unsigned m_maskSourceType : 1; // MaskSourceType |
197 | |
198 | unsigned m_imageSet : 1; |
199 | unsigned m_attachmentSet : 1; |
200 | unsigned m_clipSet : 1; |
201 | unsigned m_originSet : 1; |
202 | unsigned m_repeatXSet : 1; |
203 | unsigned m_repeatYSet : 1; |
204 | unsigned m_xPosSet : 1; |
205 | unsigned m_yPosSet : 1; |
206 | unsigned m_backgroundXOriginSet : 1; |
207 | unsigned m_backgroundYOriginSet : 1; |
208 | unsigned m_backgroundXOrigin : 2; // Edge |
209 | unsigned m_backgroundYOrigin : 2; // Edge |
210 | unsigned m_compositeSet : 1; |
211 | unsigned m_blendModeSet : 1; |
212 | unsigned m_maskSourceTypeSet : 1; |
213 | |
214 | unsigned m_type : 1; // FillLayerType |
215 | |
216 | mutable unsigned m_clipMax : 2; // FillBox, maximum m_clip value from this to bottom layer |
217 | }; |
218 | |
219 | WTF::TextStream& operator<<(WTF::TextStream&, FillSize); |
220 | WTF::TextStream& operator<<(WTF::TextStream&, const FillLayer&); |
221 | |
222 | } // namespace WebCore |
223 | |