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 "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 { 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 struct FillLayer : FastAllocBase { 63 public: 64 FillLayer(EFillLayerType); 65 ~FillLayer(); 66 67 StyleImage* image() const { return m_image.get(); } 68 Length xPosition() const { return m_xPosition; } 69 Length yPosition() const { return m_yPosition; } 70 EFillAttachment attachment() const { return static_cast<EFillAttachment>(m_attachment); } 71 EFillBox clip() const { return static_cast<EFillBox>(m_clip); } 72 EFillBox origin() const { return static_cast<EFillBox>(m_origin); } 73 EFillRepeat repeatX() const { return static_cast<EFillRepeat>(m_repeatX); } 74 EFillRepeat repeatY() const { return static_cast<EFillRepeat>(m_repeatY); } 75 CompositeOperator composite() const { return static_cast<CompositeOperator>(m_composite); } 76 LengthSize sizeLength() const { return m_sizeLength; } 77 FillSize size() const { return FillSize(static_cast<EFillSizeType>(m_sizeType), m_sizeLength); } 78 79 const FillLayer* next() const { return m_next; } 80 FillLayer* next() { return m_next; } 81 82 bool isImageSet() const { return m_imageSet; } 83 bool isXPositionSet() const { return m_xPosSet; } 84 bool isYPositionSet() const { return m_yPosSet; } 85 bool isAttachmentSet() const { return m_attachmentSet; } 86 bool isClipSet() const { return m_clipSet; } 87 bool isOriginSet() const { return m_originSet; } 88 bool isRepeatXSet() const { return m_repeatXSet; } 89 bool isRepeatYSet() const { return m_repeatYSet; } 90 bool isCompositeSet() const { return m_compositeSet; } 91 bool isSizeSet() const { return m_sizeType != SizeNone; } 92 93 void setImage(StyleImage* i) { m_image = i; m_imageSet = true; } 94 void setXPosition(Length l) { m_xPosition = l; m_xPosSet = true; } 95 void setYPosition(Length l) { m_yPosition = l; m_yPosSet = true; } 96 void setAttachment(EFillAttachment attachment) { m_attachment = attachment; m_attachmentSet = true; } 97 void setClip(EFillBox b) { m_clip = b; m_clipSet = true; } 98 void setOrigin(EFillBox b) { m_origin = b; m_originSet = true; } 99 void setRepeatX(EFillRepeat r) { m_repeatX = r; m_repeatXSet = true; } 100 void setRepeatY(EFillRepeat r) { m_repeatY = r; m_repeatYSet = true; } 101 void setComposite(CompositeOperator c) { m_composite = c; m_compositeSet = true; } 102 void setSizeType(EFillSizeType b) { m_sizeType = b; } 103 void setSizeLength(LengthSize l) { m_sizeLength = l; } 104 void setSize(FillSize f) { m_sizeType = f.type; m_sizeLength = f.size; } 105 106 void clearImage() { m_imageSet = false; } 107 void clearXPosition() { m_xPosSet = false; } 108 void clearYPosition() { m_yPosSet = false; } 109 void clearAttachment() { m_attachmentSet = false; } 110 void clearClip() { m_clipSet = false; } 111 void clearOrigin() { m_originSet = false; } 112 void clearRepeatX() { m_repeatXSet = false; } 113 void clearRepeatY() { m_repeatYSet = false; } 114 void clearComposite() { m_compositeSet = false; } 115 void clearSize() { m_sizeType = SizeNone; } 116 117 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 131 bool hasImage() const 132 { 133 if (m_image) 134 return true; 135 return m_next ? m_next->hasImage() : false; 136 } 137 138 bool hasFixedImage() const 139 { 140 if (m_image && m_attachment == FixedBackgroundAttachment) 141 return true; 142 return m_next ? m_next->hasFixedImage() : false; 143 } 144 145 EFillLayerType type() const { return static_cast<EFillLayerType>(m_type); } 146 147 void fillUnsetProperties(); 148 void cullEmptyLayers(); 149 150 static EFillAttachment initialFillAttachment(EFillLayerType) { return ScrollBackgroundAttachment; } 151 static EFillBox initialFillClip(EFillLayerType) { return BorderFillBox; } 152 static EFillBox initialFillOrigin(EFillLayerType type) { return type == BackgroundFillLayer ? PaddingFillBox : BorderFillBox; } 153 static EFillRepeat initialFillRepeatX(EFillLayerType) { return RepeatFill; } 154 static EFillRepeat initialFillRepeatY(EFillLayerType) { return RepeatFill; } 155 static CompositeOperator initialFillComposite(EFillLayerType) { return CompositeSourceOver; } 156 static EFillSizeType initialFillSizeType(EFillLayerType) { return SizeLength; } 157 static LengthSize initialFillSizeLength(EFillLayerType) { return LengthSize(); } 158 static FillSize initialFillSize(EFillLayerType) { return FillSize(); } 159 static Length initialFillXPosition(EFillLayerType) { return Length(0.0, Percent); } 160 static Length initialFillYPosition(EFillLayerType) { return Length(0.0, Percent); } 161 static StyleImage* initialFillImage(EFillLayerType) { return 0; } 162 163 private: 164 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