• 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 WebCore {
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     blink::WebBlendMode blendMode() const { return static_cast<blink::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; }
87 
isImageSet()88     bool isImageSet() const { return m_imageSet; }
isXPositionSet()89     bool isXPositionSet() const { return m_xPosSet; }
isYPositionSet()90     bool isYPositionSet() const { return m_yPosSet; }
isBackgroundXOriginSet()91     bool isBackgroundXOriginSet() const { return m_backgroundXOriginSet; }
isBackgroundYOriginSet()92     bool isBackgroundYOriginSet() const { return m_backgroundYOriginSet; }
isAttachmentSet()93     bool isAttachmentSet() const { return m_attachmentSet; }
isClipSet()94     bool isClipSet() const { return m_clipSet; }
isOriginSet()95     bool isOriginSet() const { return m_originSet; }
isRepeatXSet()96     bool isRepeatXSet() const { return m_repeatXSet; }
isRepeatYSet()97     bool isRepeatYSet() const { return m_repeatYSet; }
isCompositeSet()98     bool isCompositeSet() const { return m_compositeSet; }
isBlendModeSet()99     bool isBlendModeSet() const { return m_blendModeSet; }
isSizeSet()100     bool isSizeSet() const { return m_sizeType != SizeNone; }
isMaskSourceTypeSet()101     bool isMaskSourceTypeSet() const { return m_maskSourceTypeSet; }
102 
setImage(PassRefPtr<StyleImage> i)103     void setImage(PassRefPtr<StyleImage> i) { m_image = i; m_imageSet = true; }
setXPosition(const Length & position)104     void setXPosition(const Length& position) { m_xPosition = position; m_xPosSet = true; m_backgroundXOriginSet = false; m_backgroundXOrigin = LeftEdge; }
setYPosition(const Length & position)105     void setYPosition(const Length& position) { m_yPosition = position; m_yPosSet = true; m_backgroundYOriginSet = false; m_backgroundYOrigin = TopEdge; }
setBackgroundXOrigin(BackgroundEdgeOrigin origin)106     void setBackgroundXOrigin(BackgroundEdgeOrigin origin) { m_backgroundXOrigin = origin; m_backgroundXOriginSet = true; }
setBackgroundYOrigin(BackgroundEdgeOrigin origin)107     void setBackgroundYOrigin(BackgroundEdgeOrigin origin) { m_backgroundYOrigin = origin; m_backgroundYOriginSet = true; }
setAttachment(EFillAttachment attachment)108     void setAttachment(EFillAttachment attachment) { m_attachment = attachment; m_attachmentSet = true; }
setClip(EFillBox b)109     void setClip(EFillBox b) { m_clip = b; m_clipSet = true; }
setOrigin(EFillBox b)110     void setOrigin(EFillBox b) { m_origin = b; m_originSet = true; }
setRepeatX(EFillRepeat r)111     void setRepeatX(EFillRepeat r) { m_repeatX = r; m_repeatXSet = true; }
setRepeatY(EFillRepeat r)112     void setRepeatY(EFillRepeat r) { m_repeatY = r; m_repeatYSet = true; }
setComposite(CompositeOperator c)113     void setComposite(CompositeOperator c) { m_composite = c; m_compositeSet = true; }
setBlendMode(blink::WebBlendMode b)114     void setBlendMode(blink::WebBlendMode b) { m_blendMode = b; m_blendModeSet = true; }
setSizeType(EFillSizeType b)115     void setSizeType(EFillSizeType b) { m_sizeType = b; }
setSizeLength(const LengthSize & l)116     void setSizeLength(const LengthSize& l) { m_sizeLength = l; }
setSize(FillSize f)117     void setSize(FillSize f) { m_sizeType = f.type; m_sizeLength = f.size; }
setMaskSourceType(EMaskSourceType m)118     void setMaskSourceType(EMaskSourceType m) { m_maskSourceType = m; m_maskSourceTypeSet = true; }
119 
clearImage()120     void clearImage() { m_image.clear(); m_imageSet = false; }
clearXPosition()121     void clearXPosition()
122     {
123         m_xPosSet = false;
124         m_backgroundXOriginSet = false;
125     }
clearYPosition()126     void clearYPosition()
127     {
128         m_yPosSet = false;
129         m_backgroundYOriginSet = false;
130     }
131 
clearAttachment()132     void clearAttachment() { m_attachmentSet = false; }
clearClip()133     void clearClip() { m_clipSet = false; }
clearOrigin()134     void clearOrigin() { m_originSet = false; }
clearRepeatX()135     void clearRepeatX() { m_repeatXSet = false; }
clearRepeatY()136     void clearRepeatY() { m_repeatYSet = false; }
clearComposite()137     void clearComposite() { m_compositeSet = false; }
clearBlendMode()138     void clearBlendMode() { m_blendModeSet = false; }
clearSize()139     void clearSize() { m_sizeType = SizeNone; }
clearMaskSourceType()140     void clearMaskSourceType() { m_maskSourceTypeSet = false; }
141 
setNext(FillLayer * n)142     void setNext(FillLayer* n) { if (m_next != n) { delete m_next; m_next = n; } }
143 
144     FillLayer& operator=(const FillLayer& o);
145     FillLayer(const FillLayer& o);
146 
147     bool operator==(const FillLayer& o) const;
148     bool operator!=(const FillLayer& o) const
149     {
150         return !(*this == o);
151     }
152 
153     bool containsImage(StyleImage*) const;
154     bool imagesAreLoaded() const;
155 
hasImage()156     bool hasImage() const
157     {
158         if (m_image)
159             return true;
160         return m_next ? m_next->hasImage() : false;
161     }
162 
hasFixedImage()163     bool hasFixedImage() const
164     {
165         if (m_image && m_attachment == FixedBackgroundAttachment)
166             return true;
167         return m_next ? m_next->hasFixedImage() : false;
168     }
169 
170     bool hasOpaqueImage(const RenderObject*) const;
171     bool hasRepeatXY() const;
172     bool clipOccludesNextLayers(bool firstLayer) const;
173 
type()174     EFillLayerType type() const { return static_cast<EFillLayerType>(m_type); }
175 
176     void fillUnsetProperties();
177     void cullEmptyLayers();
178 
initialFillAttachment(EFillLayerType)179     static EFillAttachment initialFillAttachment(EFillLayerType) { return ScrollBackgroundAttachment; }
initialFillClip(EFillLayerType)180     static EFillBox initialFillClip(EFillLayerType) { return BorderFillBox; }
initialFillOrigin(EFillLayerType type)181     static EFillBox initialFillOrigin(EFillLayerType type) { return type == BackgroundFillLayer ? PaddingFillBox : BorderFillBox; }
initialFillRepeatX(EFillLayerType)182     static EFillRepeat initialFillRepeatX(EFillLayerType) { return RepeatFill; }
initialFillRepeatY(EFillLayerType)183     static EFillRepeat initialFillRepeatY(EFillLayerType) { return RepeatFill; }
initialFillComposite(EFillLayerType)184     static CompositeOperator initialFillComposite(EFillLayerType) { return CompositeSourceOver; }
initialFillBlendMode(EFillLayerType)185     static blink::WebBlendMode initialFillBlendMode(EFillLayerType) { return blink::WebBlendModeNormal; }
initialFillSizeType(EFillLayerType)186     static EFillSizeType initialFillSizeType(EFillLayerType) { return SizeLength; }
initialFillSizeLength(EFillLayerType)187     static LengthSize initialFillSizeLength(EFillLayerType) { return LengthSize(); }
initialFillSize(EFillLayerType type)188     static FillSize initialFillSize(EFillLayerType type) { return FillSize(initialFillSizeType(type), initialFillSizeLength(type)); }
initialFillXPosition(EFillLayerType)189     static Length initialFillXPosition(EFillLayerType) { return Length(0.0, Percent); }
initialFillYPosition(EFillLayerType)190     static Length initialFillYPosition(EFillLayerType) { return Length(0.0, Percent); }
initialFillImage(EFillLayerType)191     static StyleImage* initialFillImage(EFillLayerType) { return 0; }
initialFillMaskSourceType(EFillLayerType)192     static EMaskSourceType initialFillMaskSourceType(EFillLayerType) { return MaskAlpha; }
193 
194 private:
195     friend class RenderStyle;
196 
197     void computeClipMax() const;
198 
FillLayer()199     FillLayer() { }
200 
201     FillLayer* m_next;
202 
203     RefPtr<StyleImage> m_image;
204 
205     Length m_xPosition;
206     Length m_yPosition;
207 
208     LengthSize m_sizeLength;
209 
210     unsigned m_attachment : 2; // EFillAttachment
211     unsigned m_clip : 2; // EFillBox
212     unsigned m_origin : 2; // EFillBox
213     unsigned m_repeatX : 3; // EFillRepeat
214     unsigned m_repeatY : 3; // EFillRepeat
215     unsigned m_composite : 4; // CompositeOperator
216     unsigned m_sizeType : 2; // EFillSizeType
217     unsigned m_blendMode : 5; // blink::WebBlendMode
218     unsigned m_maskSourceType : 1; // EMaskSourceType
219     unsigned m_backgroundXOrigin : 2; // BackgroundEdgeOrigin
220     unsigned m_backgroundYOrigin : 2; // BackgroundEdgeOrigin
221 
222     unsigned m_imageSet : 1;
223     unsigned m_attachmentSet : 1;
224     unsigned m_clipSet : 1;
225     unsigned m_originSet : 1;
226     unsigned m_repeatXSet : 1;
227     unsigned m_repeatYSet : 1;
228     unsigned m_xPosSet : 1;
229     unsigned m_yPosSet : 1;
230     unsigned m_backgroundXOriginSet : 1;
231     unsigned m_backgroundYOriginSet : 1;
232     unsigned m_compositeSet : 1;
233     unsigned m_blendModeSet : 1;
234     unsigned m_maskSourceTypeSet : 1;
235 
236     unsigned m_type : 1; // EFillLayerType
237 
238     mutable unsigned m_clipMax : 2; // EFillBox, maximum m_clip value from this to bottom layer
239 };
240 
241 } // namespace WebCore
242 
243 #endif // FillLayer_h
244