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 class FillLayer { 63 WTF_MAKE_FAST_ALLOCATED; 64 public: 65 FillLayer(EFillLayerType); 66 ~FillLayer(); 67 image()68 StyleImage* image() const { return m_image.get(); } xPosition()69 Length xPosition() const { return m_xPosition; } yPosition()70 Length yPosition() const { return m_yPosition; } attachment()71 EFillAttachment attachment() const { return static_cast<EFillAttachment>(m_attachment); } clip()72 EFillBox clip() const { return static_cast<EFillBox>(m_clip); } origin()73 EFillBox origin() const { return static_cast<EFillBox>(m_origin); } repeatX()74 EFillRepeat repeatX() const { return static_cast<EFillRepeat>(m_repeatX); } repeatY()75 EFillRepeat repeatY() const { return static_cast<EFillRepeat>(m_repeatY); } composite()76 CompositeOperator composite() const { return static_cast<CompositeOperator>(m_composite); } sizeLength()77 LengthSize sizeLength() const { return m_sizeLength; } sizeType()78 EFillSizeType sizeType() const { return static_cast<EFillSizeType>(m_sizeType); } size()79 FillSize size() const { return FillSize(static_cast<EFillSizeType>(m_sizeType), m_sizeLength); } 80 next()81 const FillLayer* next() const { return m_next; } next()82 FillLayer* next() { return m_next; } 83 isImageSet()84 bool isImageSet() const { return m_imageSet; } isXPositionSet()85 bool isXPositionSet() const { return m_xPosSet; } isYPositionSet()86 bool isYPositionSet() const { return m_yPosSet; } isAttachmentSet()87 bool isAttachmentSet() const { return m_attachmentSet; } isClipSet()88 bool isClipSet() const { return m_clipSet; } isOriginSet()89 bool isOriginSet() const { return m_originSet; } isRepeatXSet()90 bool isRepeatXSet() const { return m_repeatXSet; } isRepeatYSet()91 bool isRepeatYSet() const { return m_repeatYSet; } isCompositeSet()92 bool isCompositeSet() const { return m_compositeSet; } isSizeSet()93 bool isSizeSet() const { return m_sizeType != SizeNone; } 94 setImage(StyleImage * i)95 void setImage(StyleImage* i) { m_image = i; m_imageSet = true; } setXPosition(Length l)96 void setXPosition(Length l) { m_xPosition = l; m_xPosSet = true; } setYPosition(Length l)97 void setYPosition(Length l) { m_yPosition = l; m_yPosSet = true; } setAttachment(EFillAttachment attachment)98 void setAttachment(EFillAttachment attachment) { m_attachment = attachment; m_attachmentSet = true; } setClip(EFillBox b)99 void setClip(EFillBox b) { m_clip = b; m_clipSet = true; } setOrigin(EFillBox b)100 void setOrigin(EFillBox b) { m_origin = b; m_originSet = true; } setRepeatX(EFillRepeat r)101 void setRepeatX(EFillRepeat r) { m_repeatX = r; m_repeatXSet = true; } setRepeatY(EFillRepeat r)102 void setRepeatY(EFillRepeat r) { m_repeatY = r; m_repeatYSet = true; } setComposite(CompositeOperator c)103 void setComposite(CompositeOperator c) { m_composite = c; m_compositeSet = true; } setSizeType(EFillSizeType b)104 void setSizeType(EFillSizeType b) { m_sizeType = b; } setSizeLength(LengthSize l)105 void setSizeLength(LengthSize l) { m_sizeLength = l; } setSize(FillSize f)106 void setSize(FillSize f) { m_sizeType = f.type; m_sizeLength = f.size; } 107 clearImage()108 void clearImage() { m_imageSet = false; } clearXPosition()109 void clearXPosition() { m_xPosSet = false; } clearYPosition()110 void clearYPosition() { m_yPosSet = false; } clearAttachment()111 void clearAttachment() { m_attachmentSet = false; } clearClip()112 void clearClip() { m_clipSet = false; } clearOrigin()113 void clearOrigin() { m_originSet = false; } clearRepeatX()114 void clearRepeatX() { m_repeatXSet = false; } clearRepeatY()115 void clearRepeatY() { m_repeatYSet = false; } clearComposite()116 void clearComposite() { m_compositeSet = false; } clearSize()117 void clearSize() { m_sizeType = SizeNone; } 118 setNext(FillLayer * n)119 void setNext(FillLayer* n) { if (m_next != n) { delete m_next; m_next = n; } } 120 121 FillLayer& operator=(const FillLayer& o); 122 FillLayer(const FillLayer& o); 123 124 bool operator==(const FillLayer& o) const; 125 bool operator!=(const FillLayer& o) const 126 { 127 return !(*this == o); 128 } 129 130 bool containsImage(StyleImage*) const; 131 bool imagesAreLoaded() const; 132 hasImage()133 bool hasImage() const 134 { 135 if (m_image) 136 return true; 137 return m_next ? m_next->hasImage() : false; 138 } 139 hasFixedImage()140 bool hasFixedImage() const 141 { 142 if (m_image && m_attachment == FixedBackgroundAttachment) 143 return true; 144 return m_next ? m_next->hasFixedImage() : false; 145 } 146 type()147 EFillLayerType type() const { return static_cast<EFillLayerType>(m_type); } 148 149 void fillUnsetProperties(); 150 void cullEmptyLayers(); 151 initialFillAttachment(EFillLayerType)152 static EFillAttachment initialFillAttachment(EFillLayerType) { return ScrollBackgroundAttachment; } initialFillClip(EFillLayerType)153 static EFillBox initialFillClip(EFillLayerType) { return BorderFillBox; } initialFillOrigin(EFillLayerType type)154 static EFillBox initialFillOrigin(EFillLayerType type) { return type == BackgroundFillLayer ? PaddingFillBox : BorderFillBox; } initialFillRepeatX(EFillLayerType)155 static EFillRepeat initialFillRepeatX(EFillLayerType) { return RepeatFill; } initialFillRepeatY(EFillLayerType)156 static EFillRepeat initialFillRepeatY(EFillLayerType) { return RepeatFill; } initialFillComposite(EFillLayerType)157 static CompositeOperator initialFillComposite(EFillLayerType) { return CompositeSourceOver; } initialFillSizeType(EFillLayerType)158 static EFillSizeType initialFillSizeType(EFillLayerType) { return SizeLength; } initialFillSizeLength(EFillLayerType)159 static LengthSize initialFillSizeLength(EFillLayerType) { return LengthSize(); } initialFillSize(EFillLayerType)160 static FillSize initialFillSize(EFillLayerType) { return FillSize(); } initialFillXPosition(EFillLayerType)161 static Length initialFillXPosition(EFillLayerType) { return Length(0.0, Percent); } initialFillYPosition(EFillLayerType)162 static Length initialFillYPosition(EFillLayerType) { return Length(0.0, Percent); } initialFillImage(EFillLayerType)163 static StyleImage* initialFillImage(EFillLayerType) { return 0; } 164 165 private: 166 friend class RenderStyle; 167 FillLayer()168 FillLayer() { } 169 170 FillLayer* m_next; 171 172 RefPtr<StyleImage> m_image; 173 174 Length m_xPosition; 175 Length m_yPosition; 176 177 unsigned m_attachment : 2; // EFillAttachment 178 unsigned m_clip : 2; // EFillBox 179 unsigned m_origin : 2; // EFillBox 180 unsigned m_repeatX : 3; // EFillRepeat 181 unsigned m_repeatY : 3; // EFillRepeat 182 unsigned m_composite : 4; // CompositeOperator 183 unsigned m_sizeType : 2; // EFillSizeType 184 185 LengthSize m_sizeLength; 186 187 bool m_imageSet : 1; 188 bool m_attachmentSet : 1; 189 bool m_clipSet : 1; 190 bool m_originSet : 1; 191 bool m_repeatXSet : 1; 192 bool m_repeatYSet : 1; 193 bool m_xPosSet : 1; 194 bool m_yPosSet : 1; 195 bool m_compositeSet : 1; 196 197 unsigned m_type : 1; // EFillLayerType 198 }; 199 200 } // namespace WebCore 201 202 #endif // FillLayer_h 203