• 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 "GraphicsTypes.h"
29 #include "Length.h"
30 #include "LengthSize.h"
31 #include "RenderStyleConstants.h"
32 #include "StyleImage.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, 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 struct FillLayer : FastAllocBase {
63 public:
64     FillLayer(EFillLayerType);
65     ~FillLayer();
66 
imageFillLayer67     StyleImage* image() const { return m_image.get(); }
xPositionFillLayer68     Length xPosition() const { return m_xPosition; }
yPositionFillLayer69     Length yPosition() const { return m_yPosition; }
attachmentFillLayer70     EFillAttachment attachment() const { return static_cast<EFillAttachment>(m_attachment); }
clipFillLayer71     EFillBox clip() const { return static_cast<EFillBox>(m_clip); }
originFillLayer72     EFillBox origin() const { return static_cast<EFillBox>(m_origin); }
repeatXFillLayer73     EFillRepeat repeatX() const { return static_cast<EFillRepeat>(m_repeatX); }
repeatYFillLayer74     EFillRepeat repeatY() const { return static_cast<EFillRepeat>(m_repeatY); }
compositeFillLayer75     CompositeOperator composite() const { return static_cast<CompositeOperator>(m_composite); }
sizeLengthFillLayer76     LengthSize sizeLength() const { return m_sizeLength; }
sizeFillLayer77     FillSize size() const { return FillSize(static_cast<EFillSizeType>(m_sizeType), m_sizeLength); }
78 
nextFillLayer79     const FillLayer* next() const { return m_next; }
nextFillLayer80     FillLayer* next() { return m_next; }
81 
isImageSetFillLayer82     bool isImageSet() const { return m_imageSet; }
isXPositionSetFillLayer83     bool isXPositionSet() const { return m_xPosSet; }
isYPositionSetFillLayer84     bool isYPositionSet() const { return m_yPosSet; }
isAttachmentSetFillLayer85     bool isAttachmentSet() const { return m_attachmentSet; }
isClipSetFillLayer86     bool isClipSet() const { return m_clipSet; }
isOriginSetFillLayer87     bool isOriginSet() const { return m_originSet; }
isRepeatXSetFillLayer88     bool isRepeatXSet() const { return m_repeatXSet; }
isRepeatYSetFillLayer89     bool isRepeatYSet() const { return m_repeatYSet; }
isCompositeSetFillLayer90     bool isCompositeSet() const { return m_compositeSet; }
isSizeSetFillLayer91     bool isSizeSet() const { return m_sizeType != SizeNone; }
92 
setImageFillLayer93     void setImage(StyleImage* i) { m_image = i; m_imageSet = true; }
setXPositionFillLayer94     void setXPosition(Length l) { m_xPosition = l; m_xPosSet = true; }
setYPositionFillLayer95     void setYPosition(Length l) { m_yPosition = l; m_yPosSet = true; }
setAttachmentFillLayer96     void setAttachment(EFillAttachment attachment) { m_attachment = attachment; m_attachmentSet = true; }
setClipFillLayer97     void setClip(EFillBox b) { m_clip = b; m_clipSet = true; }
setOriginFillLayer98     void setOrigin(EFillBox b) { m_origin = b; m_originSet = true; }
setRepeatXFillLayer99     void setRepeatX(EFillRepeat r) { m_repeatX = r; m_repeatXSet = true; }
setRepeatYFillLayer100     void setRepeatY(EFillRepeat r) { m_repeatY = r; m_repeatYSet = true; }
setCompositeFillLayer101     void setComposite(CompositeOperator c) { m_composite = c; m_compositeSet = true; }
setSizeTypeFillLayer102     void setSizeType(EFillSizeType b) { m_sizeType = b; }
setSizeLengthFillLayer103     void setSizeLength(LengthSize l) { m_sizeLength = l; }
setSizeFillLayer104     void setSize(FillSize f) { m_sizeType = f.type; m_sizeLength = f.size; }
105 
clearImageFillLayer106     void clearImage() { m_imageSet = false; }
clearXPositionFillLayer107     void clearXPosition() { m_xPosSet = false; }
clearYPositionFillLayer108     void clearYPosition() { m_yPosSet = false; }
clearAttachmentFillLayer109     void clearAttachment() { m_attachmentSet = false; }
clearClipFillLayer110     void clearClip() { m_clipSet = false; }
clearOriginFillLayer111     void clearOrigin() { m_originSet = false; }
clearRepeatXFillLayer112     void clearRepeatX() { m_repeatXSet = false; }
clearRepeatYFillLayer113     void clearRepeatY() { m_repeatYSet = false; }
clearCompositeFillLayer114     void clearComposite() { m_compositeSet = false; }
clearSizeFillLayer115     void clearSize() { m_sizeType = SizeNone; }
116 
setNextFillLayer117     void setNext(FillLayer* n) { if (m_next != n) { delete m_next; m_next = n; } }
118 
119     FillLayer& operator=(const FillLayer& o);
120     FillLayer(const FillLayer& o);
121 
122     bool operator==(const FillLayer& o) const;
123     bool operator!=(const FillLayer& o) const
124     {
125         return !(*this == o);
126     }
127 
128     bool containsImage(StyleImage*) const;
129     bool imagesAreLoaded() const;
130 
hasImageFillLayer131     bool hasImage() const
132     {
133         if (m_image)
134             return true;
135         return m_next ? m_next->hasImage() : false;
136     }
137 
hasFixedImageFillLayer138     bool hasFixedImage() const
139     {
140         if (m_image && m_attachment == FixedBackgroundAttachment)
141             return true;
142         return m_next ? m_next->hasFixedImage() : false;
143     }
144 
typeFillLayer145     EFillLayerType type() const { return static_cast<EFillLayerType>(m_type); }
146 
147     void fillUnsetProperties();
148     void cullEmptyLayers();
149 
initialFillAttachmentFillLayer150     static EFillAttachment initialFillAttachment(EFillLayerType) { return ScrollBackgroundAttachment; }
initialFillClipFillLayer151     static EFillBox initialFillClip(EFillLayerType) { return BorderFillBox; }
initialFillOriginFillLayer152     static EFillBox initialFillOrigin(EFillLayerType type) { return type == BackgroundFillLayer ? PaddingFillBox : BorderFillBox; }
initialFillRepeatXFillLayer153     static EFillRepeat initialFillRepeatX(EFillLayerType) { return RepeatFill; }
initialFillRepeatYFillLayer154     static EFillRepeat initialFillRepeatY(EFillLayerType) { return RepeatFill; }
initialFillCompositeFillLayer155     static CompositeOperator initialFillComposite(EFillLayerType) { return CompositeSourceOver; }
initialFillSizeTypeFillLayer156     static EFillSizeType initialFillSizeType(EFillLayerType) { return SizeLength; }
initialFillSizeLengthFillLayer157     static LengthSize initialFillSizeLength(EFillLayerType) { return LengthSize(); }
initialFillSizeFillLayer158     static FillSize initialFillSize(EFillLayerType) { return FillSize(); }
initialFillXPositionFillLayer159     static Length initialFillXPosition(EFillLayerType) { return Length(0.0, Percent); }
initialFillYPositionFillLayer160     static Length initialFillYPosition(EFillLayerType) { return Length(0.0, Percent); }
initialFillImageFillLayer161     static StyleImage* initialFillImage(EFillLayerType) { return 0; }
162 
163 private:
FillLayerFillLayer164     FillLayer() { }
165 
166 public:
167     RefPtr<StyleImage> m_image;
168 
169     Length m_xPosition;
170     Length m_yPosition;
171 
172     unsigned m_attachment : 2; // EFillAttachment
173     unsigned m_clip : 2; // EFillBox
174     unsigned m_origin : 2; // EFillBox
175     unsigned m_repeatX : 3; // EFillRepeat
176     unsigned m_repeatY : 3; // EFillRepeat
177     unsigned m_composite : 4; // CompositeOperator
178     unsigned m_sizeType : 2; // EFillSizeType
179 
180     LengthSize m_sizeLength;
181 
182     bool m_imageSet : 1;
183     bool m_attachmentSet : 1;
184     bool m_clipSet : 1;
185     bool m_originSet : 1;
186     bool m_repeatXSet : 1;
187     bool m_repeatYSet : 1;
188     bool m_xPosSet : 1;
189     bool m_yPosSet : 1;
190     bool m_compositeSet : 1;
191 
192     unsigned m_type : 1; // EFillLayerType
193 
194     FillLayer* m_next;
195 };
196 
197 } // namespace WebCore
198 
199 #endif // FillLayer_h
200