1 /*
2 * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 */
21
22 #include "config.h"
23 #include "FillLayer.h"
24
25 namespace WebCore {
26
FillLayer(EFillLayerType type)27 FillLayer::FillLayer(EFillLayerType type)
28 : m_image(FillLayer::initialFillImage(type))
29 , m_xPosition(FillLayer::initialFillXPosition(type))
30 , m_yPosition(FillLayer::initialFillYPosition(type))
31 , m_attachment(FillLayer::initialFillAttachment(type))
32 , m_clip(FillLayer::initialFillClip(type))
33 , m_origin(FillLayer::initialFillOrigin(type))
34 , m_repeat(FillLayer::initialFillRepeat(type))
35 , m_composite(FillLayer::initialFillComposite(type))
36 , m_size(FillLayer::initialFillSize(type))
37 , m_imageSet(false)
38 , m_attachmentSet(false)
39 , m_clipSet(false)
40 , m_originSet(false)
41 , m_repeatSet(false)
42 , m_xPosSet(false)
43 , m_yPosSet(false)
44 , m_compositeSet(type == MaskFillLayer)
45 , m_sizeSet(false)
46 , m_type(type)
47 , m_next(0)
48 {
49 }
50
FillLayer(const FillLayer & o)51 FillLayer::FillLayer(const FillLayer& o)
52 : m_image(o.m_image)
53 , m_xPosition(o.m_xPosition)
54 , m_yPosition(o.m_yPosition)
55 , m_attachment(o.m_attachment)
56 , m_clip(o.m_clip)
57 , m_origin(o.m_origin)
58 , m_repeat(o.m_repeat)
59 , m_composite(o.m_composite)
60 , m_size(o.m_size)
61 , m_imageSet(o.m_imageSet)
62 , m_attachmentSet(o.m_attachmentSet)
63 , m_clipSet(o.m_clipSet)
64 , m_originSet(o.m_originSet)
65 , m_repeatSet(o.m_repeatSet)
66 , m_xPosSet(o.m_xPosSet)
67 , m_yPosSet(o.m_yPosSet)
68 , m_compositeSet(o.m_compositeSet)
69 , m_sizeSet(o.m_sizeSet)
70 , m_type(o.m_type)
71 , m_next(o.m_next ? new FillLayer(*o.m_next) : 0)
72 {
73 }
74
~FillLayer()75 FillLayer::~FillLayer()
76 {
77 delete m_next;
78 }
79
operator =(const FillLayer & o)80 FillLayer& FillLayer::operator=(const FillLayer& o)
81 {
82 if (m_next != o.m_next) {
83 delete m_next;
84 m_next = o.m_next ? new FillLayer(*o.m_next) : 0;
85 }
86
87 m_image = o.m_image;
88 m_xPosition = o.m_xPosition;
89 m_yPosition = o.m_yPosition;
90 m_attachment = o.m_attachment;
91 m_clip = o.m_clip;
92 m_composite = o.m_composite;
93 m_origin = o.m_origin;
94 m_repeat = o.m_repeat;
95 m_size = o.m_size;
96
97 m_imageSet = o.m_imageSet;
98 m_attachmentSet = o.m_attachmentSet;
99 m_clipSet = o.m_clipSet;
100 m_compositeSet = o.m_compositeSet;
101 m_originSet = o.m_originSet;
102 m_repeatSet = o.m_repeatSet;
103 m_xPosSet = o.m_xPosSet;
104 m_yPosSet = o.m_yPosSet;
105 m_sizeSet = o.m_sizeSet;
106
107 m_type = o.m_type;
108
109 return *this;
110 }
111
operator ==(const FillLayer & o) const112 bool FillLayer::operator==(const FillLayer& o) const
113 {
114 // We do not check the "isSet" booleans for each property, since those are only used during initial construction
115 // to propagate patterns into layers. All layer comparisons happen after values have all been filled in anyway.
116 return StyleImage::imagesEquivalent(m_image.get(), o.m_image.get()) && m_xPosition == o.m_xPosition && m_yPosition == o.m_yPosition &&
117 m_attachment == o.m_attachment && m_clip == o.m_clip &&
118 m_composite == o.m_composite && m_origin == o.m_origin && m_repeat == o.m_repeat &&
119 m_size == o.m_size && m_type == o.m_type &&
120 ((m_next && o.m_next) ? *m_next == *o.m_next : m_next == o.m_next);
121 }
122
fillUnsetProperties()123 void FillLayer::fillUnsetProperties()
124 {
125 FillLayer* curr;
126 for (curr = this; curr && curr->isImageSet(); curr = curr->next()) { }
127 if (curr && curr != this) {
128 // We need to fill in the remaining values with the pattern specified.
129 for (FillLayer* pattern = this; curr; curr = curr->next()) {
130 curr->m_image = pattern->m_image;
131 pattern = pattern->next();
132 if (pattern == curr || !pattern)
133 pattern = this;
134 }
135 }
136
137 for (curr = this; curr && curr->isXPositionSet(); curr = curr->next()) { }
138 if (curr && curr != this) {
139 // We need to fill in the remaining values with the pattern specified.
140 for (FillLayer* pattern = this; curr; curr = curr->next()) {
141 curr->m_xPosition = pattern->m_xPosition;
142 pattern = pattern->next();
143 if (pattern == curr || !pattern)
144 pattern = this;
145 }
146 }
147
148 for (curr = this; curr && curr->isYPositionSet(); curr = curr->next()) { }
149 if (curr && curr != this) {
150 // We need to fill in the remaining values with the pattern specified.
151 for (FillLayer* pattern = this; curr; curr = curr->next()) {
152 curr->m_yPosition = pattern->m_yPosition;
153 pattern = pattern->next();
154 if (pattern == curr || !pattern)
155 pattern = this;
156 }
157 }
158
159 for (curr = this; curr && curr->isAttachmentSet(); curr = curr->next()) { }
160 if (curr && curr != this) {
161 // We need to fill in the remaining values with the pattern specified.
162 for (FillLayer* pattern = this; curr; curr = curr->next()) {
163 curr->m_attachment = pattern->m_attachment;
164 pattern = pattern->next();
165 if (pattern == curr || !pattern)
166 pattern = this;
167 }
168 }
169
170 for (curr = this; curr && curr->isClipSet(); curr = curr->next()) { }
171 if (curr && curr != this) {
172 // We need to fill in the remaining values with the pattern specified.
173 for (FillLayer* pattern = this; curr; curr = curr->next()) {
174 curr->m_clip = pattern->m_clip;
175 pattern = pattern->next();
176 if (pattern == curr || !pattern)
177 pattern = this;
178 }
179 }
180
181 for (curr = this; curr && curr->isCompositeSet(); curr = curr->next()) { }
182 if (curr && curr != this) {
183 // We need to fill in the remaining values with the pattern specified.
184 for (FillLayer* pattern = this; curr; curr = curr->next()) {
185 curr->m_composite = pattern->m_composite;
186 pattern = pattern->next();
187 if (pattern == curr || !pattern)
188 pattern = this;
189 }
190 }
191
192 for (curr = this; curr && curr->isOriginSet(); curr = curr->next()) { }
193 if (curr && curr != this) {
194 // We need to fill in the remaining values with the pattern specified.
195 for (FillLayer* pattern = this; curr; curr = curr->next()) {
196 curr->m_origin = pattern->m_origin;
197 pattern = pattern->next();
198 if (pattern == curr || !pattern)
199 pattern = this;
200 }
201 }
202
203 for (curr = this; curr && curr->isRepeatSet(); curr = curr->next()) { }
204 if (curr && curr != this) {
205 // We need to fill in the remaining values with the pattern specified.
206 for (FillLayer* pattern = this; curr; curr = curr->next()) {
207 curr->m_repeat = pattern->m_repeat;
208 pattern = pattern->next();
209 if (pattern == curr || !pattern)
210 pattern = this;
211 }
212 }
213
214 for (curr = this; curr && curr->isSizeSet(); curr = curr->next()) { }
215 if (curr && curr != this) {
216 // We need to fill in the remaining values with the pattern specified.
217 for (FillLayer* pattern = this; curr; curr = curr->next()) {
218 curr->m_size = pattern->m_size;
219 pattern = pattern->next();
220 if (pattern == curr || !pattern)
221 pattern = this;
222 }
223 }
224 }
225
cullEmptyLayers()226 void FillLayer::cullEmptyLayers()
227 {
228 FillLayer* next;
229 for (FillLayer* p = this; p; p = next) {
230 next = p->m_next;
231 if (next && !next->isImageSet() &&
232 !next->isXPositionSet() && !next->isYPositionSet() &&
233 !next->isAttachmentSet() && !next->isClipSet() &&
234 !next->isCompositeSet() && !next->isOriginSet() &&
235 !next->isRepeatSet() && !next->isSizeSet()) {
236 delete next;
237 p->m_next = 0;
238 break;
239 }
240 }
241 }
242
containsImage(StyleImage * s) const243 bool FillLayer::containsImage(StyleImage* s) const
244 {
245 if (!s)
246 return false;
247 if (m_image && *s == *m_image)
248 return true;
249 if (m_next)
250 return m_next->containsImage(s);
251 return false;
252 }
253
254 } // namespace WebCore
255