• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * 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 #ifndef FillLayer_h
26 #define FillLayer_h
27 
28 #include "core/rendering/style/RenderStyleConstants.h"
29 #include "core/rendering/style/StyleImage.h"
30 #include "platform/Length.h"
31 #include "platform/LengthSize.h"
32 #include "platform/graphics/GraphicsTypes.h"
33 #include "wtf/RefPtr.h"
34 
35 namespace blink {
36 
37 struct FillSize {
FillSizeFillSize38     FillSize()
39         : type(SizeLength)
40     {
41     }
42 
FillSizeFillSize43     FillSize(EFillSizeType t, const LengthSize& l)
44         : type(t)
45         , size(l)
46     {
47     }
48 
49     bool operator==(const FillSize& o) const
50     {
51         return type == o.type && size == o.size;
52     }
53     bool operator!=(const FillSize& o) const
54     {
55         return !(*this == o);
56     }
57 
58     EFillSizeType type;
59     LengthSize size;
60 };
61 
62 class FillLayer {
63     WTF_MAKE_FAST_ALLOCATED;
64 public:
65     FillLayer(EFillLayerType, bool useInitialValues = false);
66     ~FillLayer();
67 
image()68     StyleImage* image() const { return m_image.get(); }
xPosition()69     const Length& xPosition() const { return m_xPosition; }
yPosition()70     const Length& yPosition() const { return m_yPosition; }
backgroundXOrigin()71     BackgroundEdgeOrigin backgroundXOrigin() const { return static_cast<BackgroundEdgeOrigin>(m_backgroundXOrigin); }
backgroundYOrigin()72     BackgroundEdgeOrigin backgroundYOrigin() const { return static_cast<BackgroundEdgeOrigin>(m_backgroundYOrigin); }
attachment()73     EFillAttachment attachment() const { return static_cast<EFillAttachment>(m_attachment); }
clip()74     EFillBox clip() const { return static_cast<EFillBox>(m_clip); }
origin()75     EFillBox origin() const { return static_cast<EFillBox>(m_origin); }
repeatX()76     EFillRepeat repeatX() const { return static_cast<EFillRepeat>(m_repeatX); }
repeatY()77     EFillRepeat repeatY() const { return static_cast<EFillRepeat>(m_repeatY); }
composite()78     CompositeOperator composite() const { return static_cast<CompositeOperator>(m_composite); }
blendMode()79     WebBlendMode blendMode() const { return static_cast<WebBlendMode>(m_blendMode); }
sizeLength()80     const LengthSize& sizeLength() const { return m_sizeLength; }
sizeType()81     EFillSizeType sizeType() const { return static_cast<EFillSizeType>(m_sizeType); }
size()82     FillSize size() const { return FillSize(static_cast<EFillSizeType>(m_sizeType), m_sizeLength); }
maskSourceType()83     EMaskSourceType maskSourceType() const { return static_cast<EMaskSourceType>(m_maskSourceType); }
84 
next()85     const FillLayer* next() const { return m_next; }
next()86     FillLayer* next() { return m_next; }
ensureNext()87     FillLayer* ensureNext()
88     {
89         if (!m_next)
90             m_next = new FillLayer(type());
91         return m_next;
92     }
93 
isImageSet()94     bool isImageSet() const { return m_imageSet; }
isXPositionSet()95     bool isXPositionSet() const { return m_xPosSet; }
isYPositionSet()96     bool isYPositionSet() const { return m_yPosSet; }
isBackgroundXOriginSet()97     bool isBackgroundXOriginSet() const { return m_backgroundXOriginSet; }
isBackgroundYOriginSet()98     bool isBackgroundYOriginSet() const { return m_backgroundYOriginSet; }
isAttachmentSet()99     bool isAttachmentSet() const { return m_attachmentSet; }
isClipSet()100     bool isClipSet() const { return m_clipSet; }
isOriginSet()101     bool isOriginSet() const { return m_originSet; }
isRepeatXSet()102     bool isRepeatXSet() const { return m_repeatXSet; }
isRepeatYSet()103     bool isRepeatYSet() const { return m_repeatYSet; }
isCompositeSet()104     bool isCompositeSet() const { return m_compositeSet; }
isBlendModeSet()105     bool isBlendModeSet() const { return m_blendModeSet; }
isSizeSet()106     bool isSizeSet() const { return m_sizeType != SizeNone; }
isMaskSourceTypeSet()107     bool isMaskSourceTypeSet() const { return m_maskSourceTypeSet; }
108 
setImage(PassRefPtr<StyleImage> i)109     void setImage(PassRefPtr<StyleImage> i) { m_image = i; m_imageSet = true; }
setXPosition(const Length & position)110     void setXPosition(const Length& position) { m_xPosition = position; m_xPosSet = true; m_backgroundXOriginSet = false; m_backgroundXOrigin = LeftEdge; }
setYPosition(const Length & position)111     void setYPosition(const Length& position) { m_yPosition = position; m_yPosSet = true; m_backgroundYOriginSet = false; m_backgroundYOrigin = TopEdge; }
setBackgroundXOrigin(BackgroundEdgeOrigin origin)112     void setBackgroundXOrigin(BackgroundEdgeOrigin origin) { m_backgroundXOrigin = origin; m_backgroundXOriginSet = true; }
setBackgroundYOrigin(BackgroundEdgeOrigin origin)113     void setBackgroundYOrigin(BackgroundEdgeOrigin origin) { m_backgroundYOrigin = origin; m_backgroundYOriginSet = true; }
setAttachment(EFillAttachment attachment)114     void setAttachment(EFillAttachment attachment) { m_attachment = attachment; m_attachmentSet = true; }
setClip(EFillBox b)115     void setClip(EFillBox b) { m_clip = b; m_clipSet = true; }
setOrigin(EFillBox b)116     void setOrigin(EFillBox b) { m_origin = b; m_originSet = true; }
setRepeatX(EFillRepeat r)117     void setRepeatX(EFillRepeat r) { m_repeatX = r; m_repeatXSet = true; }
setRepeatY(EFillRepeat r)118     void setRepeatY(EFillRepeat r) { m_repeatY = r; m_repeatYSet = true; }
setComposite(CompositeOperator c)119     void setComposite(CompositeOperator c) { m_composite = c; m_compositeSet = true; }
setBlendMode(WebBlendMode b)120     void setBlendMode(WebBlendMode b) { m_blendMode = b; m_blendModeSet = true; }
setSizeType(EFillSizeType b)121     void setSizeType(EFillSizeType b) { m_sizeType = b; }
setSizeLength(const LengthSize & l)122     void setSizeLength(const LengthSize& l) { m_sizeLength = l; }
setSize(FillSize f)123     void setSize(FillSize f) { m_sizeType = f.type; m_sizeLength = f.size; }
setMaskSourceType(EMaskSourceType m)124     void setMaskSourceType(EMaskSourceType m) { m_maskSourceType = m; m_maskSourceTypeSet = true; }
125 
clearImage()126     void clearImage() { m_image.clear(); m_imageSet = false; }
clearXPosition()127     void clearXPosition()
128     {
129         m_xPosSet = false;
130         m_backgroundXOriginSet = false;
131     }
clearYPosition()132     void clearYPosition()
133     {
134         m_yPosSet = false;
135         m_backgroundYOriginSet = false;
136     }
137 
clearAttachment()138     void clearAttachment() { m_attachmentSet = false; }
clearClip()139     void clearClip() { m_clipSet = false; }
clearOrigin()140     void clearOrigin() { m_originSet = false; }
clearRepeatX()141     void clearRepeatX() { m_repeatXSet = false; }
clearRepeatY()142     void clearRepeatY() { m_repeatYSet = false; }
clearComposite()143     void clearComposite() { m_compositeSet = false; }
clearBlendMode()144     void clearBlendMode() { m_blendModeSet = false; }
clearSize()145     void clearSize() { m_sizeType = SizeNone; }
clearMaskSourceType()146     void clearMaskSourceType() { m_maskSourceTypeSet = false; }
147 
148     FillLayer& operator=(const FillLayer& o);
149     FillLayer(const FillLayer& o);
150 
151     bool operator==(const FillLayer& o) const;
152     bool operator!=(const FillLayer& o) const
153     {
154         return !(*this == o);
155     }
156 
157     bool containsImage(StyleImage*) const;
158     bool imagesAreLoaded() const;
159 
hasImage()160     bool hasImage() const
161     {
162         if (m_image)
163             return true;
164         return m_next ? m_next->hasImage() : false;
165     }
166 
hasFixedImage()167     bool hasFixedImage() const
168     {
169         if (m_image && m_attachment == FixedBackgroundAttachment)
170             return true;
171         return m_next ? m_next->hasFixedImage() : false;
172     }
173 
174     bool hasOpaqueImage(const RenderObject*) const;
175     bool hasRepeatXY() const;
176     bool clipOccludesNextLayers(bool firstLayer) const;
177 
type()178     EFillLayerType type() const { return static_cast<EFillLayerType>(m_type); }
179 
180     void fillUnsetProperties();
181     void cullEmptyLayers();
182 
initialFillAttachment(EFillLayerType)183     static EFillAttachment initialFillAttachment(EFillLayerType) { return ScrollBackgroundAttachment; }
initialFillClip(EFillLayerType)184     static EFillBox initialFillClip(EFillLayerType) { return BorderFillBox; }
initialFillOrigin(EFillLayerType type)185     static EFillBox initialFillOrigin(EFillLayerType type) { return type == BackgroundFillLayer ? PaddingFillBox : BorderFillBox; }
initialFillRepeatX(EFillLayerType)186     static EFillRepeat initialFillRepeatX(EFillLayerType) { return RepeatFill; }
initialFillRepeatY(EFillLayerType)187     static EFillRepeat initialFillRepeatY(EFillLayerType) { return RepeatFill; }
initialFillComposite(EFillLayerType)188     static CompositeOperator initialFillComposite(EFillLayerType) { return CompositeSourceOver; }
initialFillBlendMode(EFillLayerType)189     static WebBlendMode initialFillBlendMode(EFillLayerType) { return WebBlendModeNormal; }
initialFillSizeType(EFillLayerType)190     static EFillSizeType initialFillSizeType(EFillLayerType) { return SizeLength; }
initialFillSizeLength(EFillLayerType)191     static LengthSize initialFillSizeLength(EFillLayerType) { return LengthSize(); }
initialFillSize(EFillLayerType type)192     static FillSize initialFillSize(EFillLayerType type) { return FillSize(initialFillSizeType(type), initialFillSizeLength(type)); }
initialFillXPosition(EFillLayerType)193     static Length initialFillXPosition(EFillLayerType) { return Length(0.0, Percent); }
initialFillYPosition(EFillLayerType)194     static Length initialFillYPosition(EFillLayerType) { return Length(0.0, Percent); }
initialFillImage(EFillLayerType)195     static StyleImage* initialFillImage(EFillLayerType) { return 0; }
initialFillMaskSourceType(EFillLayerType)196     static EMaskSourceType initialFillMaskSourceType(EFillLayerType) { return MaskAlpha; }
197 
198 private:
199     friend class RenderStyle;
200 
201     void computeClipMax() const;
202 
FillLayer()203     FillLayer() { }
204 
205     FillLayer* m_next;
206 
207     RefPtr<StyleImage> m_image;
208 
209     Length m_xPosition;
210     Length m_yPosition;
211 
212     LengthSize m_sizeLength;
213 
214     unsigned m_attachment : 2; // EFillAttachment
215     unsigned m_clip : 2; // EFillBox
216     unsigned m_origin : 2; // EFillBox
217     unsigned m_repeatX : 3; // EFillRepeat
218     unsigned m_repeatY : 3; // EFillRepeat
219     unsigned m_composite : 4; // CompositeOperator
220     unsigned m_sizeType : 2; // EFillSizeType
221     unsigned m_blendMode : 5; // WebBlendMode
222     unsigned m_maskSourceType : 1; // EMaskSourceType
223     unsigned m_backgroundXOrigin : 2; // BackgroundEdgeOrigin
224     unsigned m_backgroundYOrigin : 2; // BackgroundEdgeOrigin
225 
226     unsigned m_imageSet : 1;
227     unsigned m_attachmentSet : 1;
228     unsigned m_clipSet : 1;
229     unsigned m_originSet : 1;
230     unsigned m_repeatXSet : 1;
231     unsigned m_repeatYSet : 1;
232     unsigned m_xPosSet : 1;
233     unsigned m_yPosSet : 1;
234     unsigned m_backgroundXOriginSet : 1;
235     unsigned m_backgroundYOriginSet : 1;
236     unsigned m_compositeSet : 1;
237     unsigned m_blendModeSet : 1;
238     unsigned m_maskSourceTypeSet : 1;
239 
240     unsigned m_type : 1; // EFillLayerType
241 
242     mutable unsigned m_clipMax : 2; // EFillBox, maximum m_clip value from this to bottom layer
243 };
244 
245 } // namespace blink
246 
247 #endif // FillLayer_h
248