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