fcd3a61b02426cbf0a835d46db083f83f7cfefe8
[WebKit-https.git] / Source / WebCore / rendering / style / StyleRareInheritedData.cpp
1 /*
2  * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
3  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 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 "StyleRareInheritedData.h"
24
25 #include "CursorList.h"
26 #include "QuotesData.h"
27 #include "RenderStyle.h"
28 #include "RenderStyleConstants.h"
29 #include "ShadowData.h"
30 #include "StyleImage.h"
31
32 namespace WebCore {
33
34 struct SameSizeAsStyleRareInheritedData : public RefCounted<SameSizeAsStyleRareInheritedData> {
35     void* styleImage;
36     Color firstColor;
37     float firstFloat;
38     Color colors[5];
39     void* ownPtrs[1];
40     AtomicString atomicStrings[5];
41     void* refPtrs[2];
42     Length lengths[1];
43     float secondFloat;
44     unsigned m_bitfields[2];
45 #if ENABLE(CSS3_TEXT_DECORATION) && ENABLE(CSS_IMAGE_ORIENTATION)
46     unsigned m_bitfieldsExtra;
47 #endif
48     short pagedMediaShorts[2];
49     unsigned unsigneds[1];
50     short hyphenationShorts[3];
51
52 #if ENABLE(IOS_TEXT_AUTOSIZING)
53     TextSizeAdjustment textSizeAdjust;
54 #endif
55
56 #if ENABLE(CSS_IMAGE_RESOLUTION)
57     float imageResolutionFloats;
58 #endif
59
60 #if ENABLE(TOUCH_EVENTS)
61     Color touchColors;
62 #endif
63
64 #if ENABLE(CSS_VARIABLES)
65     void* variableDataRefs[1];
66 #endif
67 };
68
69 COMPILE_ASSERT(sizeof(StyleRareInheritedData) == sizeof(SameSizeAsStyleRareInheritedData), StyleRareInheritedData_should_bit_pack);
70
71 StyleRareInheritedData::StyleRareInheritedData()
72     : listStyleImage(RenderStyle::initialListStyleImage())
73     , textStrokeWidth(RenderStyle::initialTextStrokeWidth())
74     , indent(RenderStyle::initialTextIndent())
75     , m_effectiveZoom(RenderStyle::initialZoom())
76     , widows(RenderStyle::initialWidows())
77     , orphans(RenderStyle::initialOrphans())
78     , m_hasAutoWidows(true)
79     , m_hasAutoOrphans(true)
80     , textSecurity(RenderStyle::initialTextSecurity())
81     , userModify(READ_ONLY)
82     , wordBreak(RenderStyle::initialWordBreak())
83     , overflowWrap(RenderStyle::initialOverflowWrap())
84     , nbspMode(NBNORMAL)
85     , lineBreak(LineBreakAuto)
86     , resize(RenderStyle::initialResize())
87     , userSelect(RenderStyle::initialUserSelect())
88     , colorSpace(ColorSpaceDeviceRGB)
89     , speak(SpeakNormal)
90     , hyphens(HyphensManual)
91     , textEmphasisFill(TextEmphasisFillFilled)
92     , textEmphasisMark(TextEmphasisMarkNone)
93     , textEmphasisPosition(TextEmphasisPositionOver)
94     , m_textOrientation(TextOrientationVerticalRight)
95 #if ENABLE(CSS3_TEXT)
96     , m_textIndentLine(RenderStyle::initialTextIndentLine())
97     , m_textIndentType(RenderStyle::initialTextIndentType())
98 #endif
99     , m_lineBoxContain(RenderStyle::initialLineBoxContain())
100 #if ENABLE(CSS_IMAGE_ORIENTATION)
101     , m_imageOrientation(RenderStyle::initialImageOrientation())
102 #endif
103     , m_imageRendering(RenderStyle::initialImageRendering())
104     , m_lineSnap(RenderStyle::initialLineSnap())
105     , m_lineAlign(RenderStyle::initialLineAlign())
106 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
107     , useTouchOverflowScrolling(RenderStyle::initialUseTouchOverflowScrolling())
108 #endif
109 #if ENABLE(CSS_IMAGE_RESOLUTION)
110     , m_imageResolutionSource(RenderStyle::initialImageResolutionSource())
111     , m_imageResolutionSnap(RenderStyle::initialImageResolutionSnap())
112 #endif
113 #if ENABLE(CSS3_TEXT)
114     , m_textAlignLast(RenderStyle::initialTextAlignLast())
115     , m_textJustify(RenderStyle::initialTextJustify())
116     , m_textUnderlinePosition(RenderStyle::initialTextUnderlinePosition())
117 #endif // CSS3_TEXT
118 #if ENABLE(CSS3_TEXT_DECORATION)
119     , m_textDecorationSkip(RenderStyle::initialTextDecorationSkip())
120 #endif
121     , m_rubyPosition(RenderStyle::initialRubyPosition())
122 #if PLATFORM(IOS)
123     , touchCalloutEnabled(RenderStyle::initialTouchCalloutEnabled())
124 #endif
125     , hyphenationLimitBefore(-1)
126     , hyphenationLimitAfter(-1)
127     , hyphenationLimitLines(-1)
128     , m_lineGrid(RenderStyle::initialLineGrid())
129     , m_tabSize(RenderStyle::initialTabSize())
130 #if ENABLE(IOS_TEXT_AUTOSIZING)
131     , textSizeAdjust(RenderStyle::initialTextSizeAdjust())
132 #endif
133 #if ENABLE(CSS_IMAGE_RESOLUTION)
134     , m_imageResolution(RenderStyle::initialImageResolution())
135 #endif
136 #if ENABLE(TOUCH_EVENTS)
137     , tapHighlightColor(RenderStyle::initialTapHighlightColor())
138 #endif
139 #if ENABLE(CSS_VARIABLES)
140     , m_variables(StyleVariableData::create())
141 #endif
142 {
143 }
144
145 StyleRareInheritedData::StyleRareInheritedData(const StyleRareInheritedData& o)
146     : RefCounted<StyleRareInheritedData>()
147     , listStyleImage(o.listStyleImage)
148     , textStrokeColor(o.textStrokeColor)
149     , textStrokeWidth(o.textStrokeWidth)
150     , textFillColor(o.textFillColor)
151     , textEmphasisColor(o.textEmphasisColor)
152     , visitedLinkTextStrokeColor(o.visitedLinkTextStrokeColor)
153     , visitedLinkTextFillColor(o.visitedLinkTextFillColor)
154     , visitedLinkTextEmphasisColor(o.visitedLinkTextEmphasisColor)
155     , textShadow(o.textShadow ? adoptPtr(new ShadowData(*o.textShadow)) : nullptr)
156     , highlight(o.highlight)
157     , cursorData(o.cursorData)
158     , indent(o.indent)
159     , m_effectiveZoom(o.m_effectiveZoom)
160     , widows(o.widows)
161     , orphans(o.orphans)
162     , m_hasAutoWidows(o.m_hasAutoWidows)
163     , m_hasAutoOrphans(o.m_hasAutoOrphans)
164     , textSecurity(o.textSecurity)
165     , userModify(o.userModify)
166     , wordBreak(o.wordBreak)
167     , overflowWrap(o.overflowWrap)
168     , nbspMode(o.nbspMode)
169     , lineBreak(o.lineBreak)
170     , resize(o.resize)
171     , userSelect(o.userSelect)
172     , colorSpace(o.colorSpace)
173     , speak(o.speak)
174     , hyphens(o.hyphens)
175     , textEmphasisFill(o.textEmphasisFill)
176     , textEmphasisMark(o.textEmphasisMark)
177     , textEmphasisPosition(o.textEmphasisPosition)
178     , m_textOrientation(o.m_textOrientation)
179 #if ENABLE(CSS3_TEXT)
180     , m_textIndentLine(o.m_textIndentLine)
181     , m_textIndentType(o.m_textIndentType)
182 #endif
183     , m_lineBoxContain(o.m_lineBoxContain)
184 #if ENABLE(CSS_IMAGE_ORIENTATION)
185     , m_imageOrientation(o.m_imageOrientation)
186 #endif
187     , m_imageRendering(o.m_imageRendering)
188     , m_lineSnap(o.m_lineSnap)
189     , m_lineAlign(o.m_lineAlign)
190 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
191     , useTouchOverflowScrolling(o.useTouchOverflowScrolling)
192 #endif
193 #if ENABLE(CSS_IMAGE_RESOLUTION)
194     , m_imageResolutionSource(o.m_imageResolutionSource)
195     , m_imageResolutionSnap(o.m_imageResolutionSnap)
196 #endif
197 #if ENABLE(CSS3_TEXT)
198     , m_textAlignLast(o.m_textAlignLast)
199     , m_textJustify(o.m_textJustify)
200     , m_textUnderlinePosition(o.m_textUnderlinePosition)
201 #endif // CSS3_TEXT
202 #if ENABLE(CSS3_TEXT_DECORATION)
203     , m_textDecorationSkip(o.m_textDecorationSkip)
204 #endif
205     , m_rubyPosition(o.m_rubyPosition)
206 #if PLATFORM(IOS)
207     , touchCalloutEnabled(o.touchCalloutEnabled)
208 #endif
209     , hyphenationString(o.hyphenationString)
210     , hyphenationLimitBefore(o.hyphenationLimitBefore)
211     , hyphenationLimitAfter(o.hyphenationLimitAfter)
212     , hyphenationLimitLines(o.hyphenationLimitLines)
213     , locale(o.locale)
214     , textEmphasisCustomMark(o.textEmphasisCustomMark)
215     , m_lineGrid(o.m_lineGrid)
216     , m_tabSize(o.m_tabSize)
217 #if ENABLE(IOS_TEXT_AUTOSIZING)
218     , textSizeAdjust(o.textSizeAdjust)
219 #endif
220 #if ENABLE(CSS_IMAGE_RESOLUTION)
221     , m_imageResolution(o.m_imageResolution)
222 #endif
223 #if ENABLE(TOUCH_EVENTS)
224     , tapHighlightColor(o.tapHighlightColor)
225 #endif
226 #if ENABLE(CSS_VARIABLES)
227     , m_variables(o.m_variables)
228 #endif
229 {
230 }
231
232 StyleRareInheritedData::~StyleRareInheritedData()
233 {
234 }
235
236 static bool cursorDataEquivalent(const CursorList* c1, const CursorList* c2)
237 {
238     if (c1 == c2)
239         return true;
240     if ((!c1 && c2) || (c1 && !c2))
241         return false;
242     return (*c1 == *c2);
243 }
244
245 static bool quotesDataEquivalent(const QuotesData* q1, const QuotesData* q2)
246 {
247     if (q1 == q2)
248         return true;
249     if ((!q1 && q2) || (q1 && !q2))
250         return false;
251     return (*q1 == *q2);
252 }
253
254 bool StyleRareInheritedData::operator==(const StyleRareInheritedData& o) const
255 {
256     return textStrokeColor == o.textStrokeColor
257         && textStrokeWidth == o.textStrokeWidth
258         && textFillColor == o.textFillColor
259         && textEmphasisColor == o.textEmphasisColor
260         && visitedLinkTextStrokeColor == o.visitedLinkTextStrokeColor
261         && visitedLinkTextFillColor == o.visitedLinkTextFillColor
262         && visitedLinkTextEmphasisColor == o.visitedLinkTextEmphasisColor
263 #if ENABLE(TOUCH_EVENTS)
264         && tapHighlightColor == o.tapHighlightColor
265 #endif
266         && shadowDataEquivalent(o)
267         && highlight == o.highlight
268         && cursorDataEquivalent(cursorData.get(), o.cursorData.get())
269         && indent == o.indent
270         && m_effectiveZoom == o.m_effectiveZoom
271         && widows == o.widows
272         && orphans == o.orphans
273         && m_hasAutoWidows == o.m_hasAutoWidows
274         && m_hasAutoOrphans == o.m_hasAutoOrphans
275         && textSecurity == o.textSecurity
276         && userModify == o.userModify
277         && wordBreak == o.wordBreak
278         && overflowWrap == o.overflowWrap
279         && nbspMode == o.nbspMode
280         && lineBreak == o.lineBreak
281 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
282         && useTouchOverflowScrolling == o.useTouchOverflowScrolling
283 #endif
284 #if ENABLE(IOS_TEXT_AUTOSIZING)
285         && textSizeAdjust == o.textSizeAdjust
286 #endif
287         && resize == o.resize
288         && userSelect == o.userSelect
289         && colorSpace == o.colorSpace
290         && speak == o.speak
291         && hyphens == o.hyphens
292         && hyphenationLimitBefore == o.hyphenationLimitBefore
293         && hyphenationLimitAfter == o.hyphenationLimitAfter
294         && hyphenationLimitLines == o.hyphenationLimitLines
295         && textEmphasisFill == o.textEmphasisFill
296         && textEmphasisMark == o.textEmphasisMark
297         && textEmphasisPosition == o.textEmphasisPosition
298         && m_textOrientation == o.m_textOrientation
299 #if ENABLE(CSS3_TEXT)
300         && m_textIndentLine == o.m_textIndentLine
301         && m_textIndentType == o.m_textIndentType
302 #endif
303         && m_lineBoxContain == o.m_lineBoxContain
304 #if PLATFORM(IOS)
305         && touchCalloutEnabled == o.touchCalloutEnabled
306 #endif
307         && hyphenationString == o.hyphenationString
308         && locale == o.locale
309         && textEmphasisCustomMark == o.textEmphasisCustomMark
310         && quotesDataEquivalent(quotes.get(), o.quotes.get())
311         && m_tabSize == o.m_tabSize
312         && m_lineGrid == o.m_lineGrid
313 #if ENABLE(CSS_IMAGE_ORIENTATION)
314         && m_imageOrientation == o.m_imageOrientation
315 #endif
316         && m_imageRendering == o.m_imageRendering
317 #if ENABLE(CSS_IMAGE_RESOLUTION)
318         && m_imageResolutionSource == o.m_imageResolutionSource
319         && m_imageResolutionSnap == o.m_imageResolutionSnap
320         && m_imageResolution == o.m_imageResolution
321 #endif
322 #if ENABLE(CSS3_TEXT)
323         && m_textAlignLast == o.m_textAlignLast
324         && m_textJustify == o.m_textJustify
325         && m_textUnderlinePosition == o.m_textUnderlinePosition
326 #endif // CSS3_TEXT
327 #if ENABLE(CSS3_TEXT_DECORATION)
328         && m_textDecorationSkip == o.m_textDecorationSkip
329 #endif
330         && m_rubyPosition == o.m_rubyPosition
331         && m_lineSnap == o.m_lineSnap
332 #if ENABLE(CSS_VARIABLES)
333         && m_variables == o.m_variables
334 #endif
335         && m_lineAlign == o.m_lineAlign
336         && StyleImage::imagesEquivalent(listStyleImage.get(), o.listStyleImage.get());
337 }
338
339 bool StyleRareInheritedData::shadowDataEquivalent(const StyleRareInheritedData& o) const
340 {
341     if ((!textShadow && o.textShadow) || (textShadow && !o.textShadow))
342         return false;
343     if (textShadow && o.textShadow && (*textShadow != *o.textShadow))
344         return false;
345     return true;
346 }
347
348 } // namespace WebCore