1 /* 2 * Copyright (C) 2000 Lars Knoll (knoll (at) kde.org) 3 * (C) 2000 Antti Koivisto (koivisto (at) kde.org) 4 * (C) 2000 Dirk Mueller (mueller (at) kde.org) 5 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 6 * Copyright (C) 2006 Graham Dennis (graham.dennis (at) 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/platform/Length.h" 29 #include "core/platform/LengthSize.h" 30 #include "core/platform/graphics/GraphicsTypes.h" 31 #include "core/rendering/style/RenderStyleConstants.h" 32 #include "core/rendering/style/StyleImage.h" 33 #include "wtf/RefPtr.h" 34 35 namespace WebCore { 36 37 struct FillSize { 38 FillSize() 39 : type(SizeLength) 40 { 41 } 42 43 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 68 StyleImage* image() const { return m_image.get(); } 69 Length xPosition() const { return m_xPosition; } 70 Length yPosition() const { return m_yPosition; } 71 BackgroundEdgeOrigin backgroundXOrigin() const { return static_cast<BackgroundEdgeOrigin>(m_backgroundXOrigin); } 72 BackgroundEdgeOrigin backgroundYOrigin() const { return static_cast<BackgroundEdgeOrigin>(m_backgroundYOrigin); } 73 EFillAttachment attachment() const { return static_cast<EFillAttachment>(m_attachment); } 74 EFillBox clip() const { return static_cast<EFillBox>(m_clip); } 75 EFillBox origin() const { return static_cast<EFillBox>(m_origin); } 76 EFillRepeat repeatX() const { return static_cast<EFillRepeat>(m_repeatX); } 77 EFillRepeat repeatY() const { return static_cast<EFillRepeat>(m_repeatY); } 78 CompositeOperator composite() const { return static_cast<CompositeOperator>(m_composite); } 79 BlendMode blendMode() const { return static_cast<BlendMode>(m_blendMode); } 80 LengthSize sizeLength() const { return m_sizeLength; } 81 EFillSizeType sizeType() const { return static_cast<EFillSizeType>(m_sizeType); } 82 FillSize size() const { return FillSize(static_cast<EFillSizeType>(m_sizeType), m_sizeLength); } 83 84 const FillLayer* next() const { return m_next; } 85 FillLayer* next() { return m_next; } 86 87 bool isImageSet() const { return m_imageSet; } 88 bool isXPositionSet() const { return m_xPosSet; } 89 bool isYPositionSet() const { return m_yPosSet; } 90 bool isBackgroundOriginSet() const { return m_backgroundOriginSet; } 91 bool isAttachmentSet() const { return m_attachmentSet; } 92 bool isClipSet() const { return m_clipSet; } 93 bool isOriginSet() const { return m_originSet; } 94 bool isRepeatXSet() const { return m_repeatXSet; } 95 bool isRepeatYSet() const { return m_repeatYSet; } 96 bool isCompositeSet() const { return m_compositeSet; } 97 bool isBlendModeSet() const { return m_blendModeSet; } 98 bool isSizeSet() const { return m_sizeType != SizeNone; } 99 100 void setImage(PassRefPtr<StyleImage> i) { m_image = i; m_imageSet = true; } 101 void setXPosition(Length l) { m_xPosition = l; m_xPosSet = true; } 102 void setYPosition(Length l) { m_yPosition = l; m_yPosSet = true; } 103 void setBackgroundXOrigin(BackgroundEdgeOrigin o) { m_backgroundXOrigin = o; m_backgroundOriginSet = true; } 104 void setBackgroundYOrigin(BackgroundEdgeOrigin o) { m_backgroundYOrigin = o; m_backgroundOriginSet = true; } 105 void setAttachment(EFillAttachment attachment) { m_attachment = attachment; m_attachmentSet = true; } 106 void setClip(EFillBox b) { m_clip = b; m_clipSet = true; } 107 void setOrigin(EFillBox b) { m_origin = b; m_originSet = true; } 108 void setRepeatX(EFillRepeat r) { m_repeatX = r; m_repeatXSet = true; } 109 void setRepeatY(EFillRepeat r) { m_repeatY = r; m_repeatYSet = true; } 110 void setComposite(CompositeOperator c) { m_composite = c; m_compositeSet = true; } 111 void setBlendMode(BlendMode b) { m_blendMode = b; m_blendModeSet = true; } 112 void setSizeType(EFillSizeType b) { m_sizeType = b; } 113 void setSizeLength(LengthSize l) { m_sizeLength = l; } 114 void setSize(FillSize f) { m_sizeType = f.type; m_sizeLength = f.size; } 115 116 void clearImage() { m_image.clear(); m_imageSet = false; } 117 void clearXPosition() 118 { 119 m_xPosSet = false; 120 m_backgroundOriginSet = false; 121 } 122 void clearYPosition() 123 { 124 m_yPosSet = false; 125 m_backgroundOriginSet = false; 126 } 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 = SizeNone; } 136 137 void setNext(FillLayer* n) { if (m_next != n) { delete m_next; m_next = n; } } 138 139 FillLayer& operator=(const FillLayer& o); 140 FillLayer(const FillLayer& o); 141 142 bool operator==(const FillLayer& o) const; 143 bool operator!=(const FillLayer& o) const 144 { 145 return !(*this == o); 146 } 147 148 bool containsImage(StyleImage*) const; 149 bool imagesAreLoaded() const; 150 151 bool hasImage() const 152 { 153 if (m_image) 154 return true; 155 return m_next ? m_next->hasImage() : false; 156 } 157 158 bool hasFixedImage() const 159 { 160 if (m_image && m_attachment == FixedBackgroundAttachment) 161 return true; 162 return m_next ? m_next->hasFixedImage() : false; 163 } 164 165 bool hasOpaqueImage(const RenderObject*) const; 166 bool hasRepeatXY() const; 167 bool clipOccludesNextLayers(bool firstLayer) const; 168 169 EFillLayerType type() const { return static_cast<EFillLayerType>(m_type); } 170 171 void fillUnsetProperties(); 172 void cullEmptyLayers(); 173 174 static EFillAttachment initialFillAttachment(EFillLayerType) { return ScrollBackgroundAttachment; } 175 static EFillBox initialFillClip(EFillLayerType) { return BorderFillBox; } 176 static EFillBox initialFillOrigin(EFillLayerType type) { return type == BackgroundFillLayer ? PaddingFillBox : BorderFillBox; } 177 static EFillRepeat initialFillRepeatX(EFillLayerType) { return RepeatFill; } 178 static EFillRepeat initialFillRepeatY(EFillLayerType) { return RepeatFill; } 179 static CompositeOperator initialFillComposite(EFillLayerType) { return CompositeSourceOver; } 180 static BlendMode initialFillBlendMode(EFillLayerType) { return BlendModeNormal; } 181 static EFillSizeType initialFillSizeType(EFillLayerType) { return SizeNone; } 182 static LengthSize initialFillSizeLength(EFillLayerType) { return LengthSize(); } 183 static FillSize initialFillSize(EFillLayerType type) { return FillSize(initialFillSizeType(type), initialFillSizeLength(type)); } 184 static Length initialFillXPosition(EFillLayerType) { return Length(0.0, Percent); } 185 static Length initialFillYPosition(EFillLayerType) { return Length(0.0, Percent); } 186 static StyleImage* initialFillImage(EFillLayerType) { return 0; } 187 188 private: 189 friend class RenderStyle; 190 191 void computeClipMax() const; 192 193 FillLayer() { } 194 195 FillLayer* m_next; 196 197 RefPtr<StyleImage> m_image; 198 199 Length m_xPosition; 200 Length m_yPosition; 201 202 LengthSize m_sizeLength; 203 204 unsigned m_attachment : 2; // EFillAttachment 205 unsigned m_clip : 2; // EFillBox 206 unsigned m_origin : 2; // EFillBox 207 unsigned m_repeatX : 3; // EFillRepeat 208 unsigned m_repeatY : 3; // EFillRepeat 209 unsigned m_composite : 4; // CompositeOperator 210 unsigned m_sizeType : 2; // EFillSizeType 211 unsigned m_blendMode : 5; // BlendMode 212 213 unsigned m_imageSet : 1; 214 unsigned m_attachmentSet : 1; 215 unsigned m_clipSet : 1; 216 unsigned m_originSet : 1; 217 unsigned m_repeatXSet : 1; 218 unsigned m_repeatYSet : 1; 219 unsigned m_xPosSet : 1; 220 unsigned m_yPosSet : 1; 221 unsigned m_backgroundOriginSet : 1; 222 unsigned m_backgroundXOrigin : 2; // BackgroundEdgeOrigin 223 unsigned m_backgroundYOrigin : 2; // BackgroundEdgeOrigin 224 unsigned m_compositeSet : 1; 225 unsigned m_blendModeSet : 1; 226 227 unsigned m_type : 1; // EFillLayerType 228 229 mutable unsigned m_clipMax : 2; // EFillBox, maximum m_clip value from this to bottom layer 230 }; 231 232 } // namespace WebCore 233 234 #endif // FillLayer_h 235