Out-of-line RenderStyle substructure copying helpers.
[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
65 COMPILE_ASSERT(sizeof(StyleRareInheritedData) == sizeof(SameSizeAsStyleRareInheritedData), StyleRareInheritedData_should_bit_pack);
66
67 StyleRareInheritedData::StyleRareInheritedData()
68     : listStyleImage(RenderStyle::initialListStyleImage())
69     , textStrokeWidth(RenderStyle::initialTextStrokeWidth())
70     , indent(RenderStyle::initialTextIndent())
71     , m_effectiveZoom(RenderStyle::initialZoom())
72     , widows(RenderStyle::initialWidows())
73     , orphans(RenderStyle::initialOrphans())
74     , m_hasAutoWidows(true)
75     , m_hasAutoOrphans(true)
76     , textSecurity(RenderStyle::initialTextSecurity())
77     , userModify(READ_ONLY)
78     , wordBreak(RenderStyle::initialWordBreak())
79     , overflowWrap(RenderStyle::initialOverflowWrap())
80     , nbspMode(NBNORMAL)
81     , lineBreak(LineBreakAuto)
82     , resize(RenderStyle::initialResize())
83     , userSelect(RenderStyle::initialUserSelect())
84     , colorSpace(ColorSpaceDeviceRGB)
85     , speak(SpeakNormal)
86     , hyphens(HyphensManual)
87     , textEmphasisFill(TextEmphasisFillFilled)
88     , textEmphasisMark(TextEmphasisMarkNone)
89     , textEmphasisPosition(TextEmphasisPositionOver)
90     , m_textOrientation(TextOrientationVerticalRight)
91 #if ENABLE(CSS3_TEXT)
92     , m_textIndentLine(RenderStyle::initialTextIndentLine())
93     , m_textIndentType(RenderStyle::initialTextIndentType())
94 #endif
95     , m_lineBoxContain(RenderStyle::initialLineBoxContain())
96 #if ENABLE(CSS_IMAGE_ORIENTATION)
97     , m_imageOrientation(RenderStyle::initialImageOrientation())
98 #endif
99     , m_imageRendering(RenderStyle::initialImageRendering())
100     , m_lineSnap(RenderStyle::initialLineSnap())
101     , m_lineAlign(RenderStyle::initialLineAlign())
102 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
103     , useTouchOverflowScrolling(RenderStyle::initialUseTouchOverflowScrolling())
104 #endif
105 #if ENABLE(CSS_IMAGE_RESOLUTION)
106     , m_imageResolutionSource(RenderStyle::initialImageResolutionSource())
107     , m_imageResolutionSnap(RenderStyle::initialImageResolutionSnap())
108 #endif
109 #if ENABLE(CSS3_TEXT)
110     , m_textAlignLast(RenderStyle::initialTextAlignLast())
111     , m_textJustify(RenderStyle::initialTextJustify())
112 #endif // CSS3_TEXT
113 #if ENABLE(CSS3_TEXT_DECORATION)
114     , m_textDecorationSkip(RenderStyle::initialTextDecorationSkip())
115     , m_textUnderlinePosition(RenderStyle::initialTextUnderlinePosition())
116 #endif
117     , m_rubyPosition(RenderStyle::initialRubyPosition())
118 #if PLATFORM(IOS)
119     , touchCalloutEnabled(RenderStyle::initialTouchCalloutEnabled())
120 #endif
121     , hyphenationLimitBefore(-1)
122     , hyphenationLimitAfter(-1)
123     , hyphenationLimitLines(-1)
124     , m_lineGrid(RenderStyle::initialLineGrid())
125     , m_tabSize(RenderStyle::initialTabSize())
126 #if ENABLE(IOS_TEXT_AUTOSIZING)
127     , textSizeAdjust(RenderStyle::initialTextSizeAdjust())
128 #endif
129 #if ENABLE(CSS_IMAGE_RESOLUTION)
130     , m_imageResolution(RenderStyle::initialImageResolution())
131 #endif
132 #if ENABLE(TOUCH_EVENTS)
133     , tapHighlightColor(RenderStyle::initialTapHighlightColor())
134 #endif
135 {
136 }
137
138 inline StyleRareInheritedData::StyleRareInheritedData(const StyleRareInheritedData& o)
139     : RefCounted<StyleRareInheritedData>()
140     , listStyleImage(o.listStyleImage)
141     , textStrokeColor(o.textStrokeColor)
142     , textStrokeWidth(o.textStrokeWidth)
143     , textFillColor(o.textFillColor)
144     , textEmphasisColor(o.textEmphasisColor)
145     , visitedLinkTextStrokeColor(o.visitedLinkTextStrokeColor)
146     , visitedLinkTextFillColor(o.visitedLinkTextFillColor)
147     , visitedLinkTextEmphasisColor(o.visitedLinkTextEmphasisColor)
148     , textShadow(o.textShadow ? adoptPtr(new ShadowData(*o.textShadow)) : nullptr)
149     , highlight(o.highlight)
150     , cursorData(o.cursorData)
151     , indent(o.indent)
152     , m_effectiveZoom(o.m_effectiveZoom)
153     , widows(o.widows)
154     , orphans(o.orphans)
155     , m_hasAutoWidows(o.m_hasAutoWidows)
156     , m_hasAutoOrphans(o.m_hasAutoOrphans)
157     , textSecurity(o.textSecurity)
158     , userModify(o.userModify)
159     , wordBreak(o.wordBreak)
160     , overflowWrap(o.overflowWrap)
161     , nbspMode(o.nbspMode)
162     , lineBreak(o.lineBreak)
163     , resize(o.resize)
164     , userSelect(o.userSelect)
165     , colorSpace(o.colorSpace)
166     , speak(o.speak)
167     , hyphens(o.hyphens)
168     , textEmphasisFill(o.textEmphasisFill)
169     , textEmphasisMark(o.textEmphasisMark)
170     , textEmphasisPosition(o.textEmphasisPosition)
171     , m_textOrientation(o.m_textOrientation)
172 #if ENABLE(CSS3_TEXT)
173     , m_textIndentLine(o.m_textIndentLine)
174     , m_textIndentType(o.m_textIndentType)
175 #endif
176     , m_lineBoxContain(o.m_lineBoxContain)
177 #if ENABLE(CSS_IMAGE_ORIENTATION)
178     , m_imageOrientation(o.m_imageOrientation)
179 #endif
180     , m_imageRendering(o.m_imageRendering)
181     , m_lineSnap(o.m_lineSnap)
182     , m_lineAlign(o.m_lineAlign)
183 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
184     , useTouchOverflowScrolling(o.useTouchOverflowScrolling)
185 #endif
186 #if ENABLE(CSS_IMAGE_RESOLUTION)
187     , m_imageResolutionSource(o.m_imageResolutionSource)
188     , m_imageResolutionSnap(o.m_imageResolutionSnap)
189 #endif
190 #if ENABLE(CSS3_TEXT)
191     , m_textAlignLast(o.m_textAlignLast)
192     , m_textJustify(o.m_textJustify)
193 #endif // CSS3_TEXT
194 #if ENABLE(CSS3_TEXT_DECORATION)
195     , m_textDecorationSkip(o.m_textDecorationSkip)
196     , m_textUnderlinePosition(o.m_textUnderlinePosition)
197 #endif
198     , m_rubyPosition(o.m_rubyPosition)
199 #if PLATFORM(IOS)
200     , touchCalloutEnabled(o.touchCalloutEnabled)
201 #endif
202     , hyphenationString(o.hyphenationString)
203     , hyphenationLimitBefore(o.hyphenationLimitBefore)
204     , hyphenationLimitAfter(o.hyphenationLimitAfter)
205     , hyphenationLimitLines(o.hyphenationLimitLines)
206     , locale(o.locale)
207     , textEmphasisCustomMark(o.textEmphasisCustomMark)
208     , m_lineGrid(o.m_lineGrid)
209     , m_tabSize(o.m_tabSize)
210 #if ENABLE(IOS_TEXT_AUTOSIZING)
211     , textSizeAdjust(o.textSizeAdjust)
212 #endif
213 #if ENABLE(CSS_IMAGE_RESOLUTION)
214     , m_imageResolution(o.m_imageResolution)
215 #endif
216 #if ENABLE(TOUCH_EVENTS)
217     , tapHighlightColor(o.tapHighlightColor)
218 #endif
219 {
220 }
221
222 PassRef<StyleRareInheritedData> StyleRareInheritedData::copy() const
223 {
224     return adoptRef(*new StyleRareInheritedData(*this));
225 }
226
227 StyleRareInheritedData::~StyleRareInheritedData()
228 {
229 }
230
231 static bool cursorDataEquivalent(const CursorList* c1, const CursorList* c2)
232 {
233     if (c1 == c2)
234         return true;
235     if ((!c1 && c2) || (c1 && !c2))
236         return false;
237     return (*c1 == *c2);
238 }
239
240 static bool quotesDataEquivalent(const QuotesData* q1, const QuotesData* q2)
241 {
242     if (q1 == q2)
243         return true;
244     if ((!q1 && q2) || (q1 && !q2))
245         return false;
246     return (*q1 == *q2);
247 }
248
249 bool StyleRareInheritedData::operator==(const StyleRareInheritedData& o) const
250 {
251     return textStrokeColor == o.textStrokeColor
252         && textStrokeWidth == o.textStrokeWidth
253         && textFillColor == o.textFillColor
254         && textEmphasisColor == o.textEmphasisColor
255         && visitedLinkTextStrokeColor == o.visitedLinkTextStrokeColor
256         && visitedLinkTextFillColor == o.visitedLinkTextFillColor
257         && visitedLinkTextEmphasisColor == o.visitedLinkTextEmphasisColor
258 #if ENABLE(TOUCH_EVENTS)
259         && tapHighlightColor == o.tapHighlightColor
260 #endif
261         && shadowDataEquivalent(o)
262         && highlight == o.highlight
263         && cursorDataEquivalent(cursorData.get(), o.cursorData.get())
264         && indent == o.indent
265         && m_effectiveZoom == o.m_effectiveZoom
266         && widows == o.widows
267         && orphans == o.orphans
268         && m_hasAutoWidows == o.m_hasAutoWidows
269         && m_hasAutoOrphans == o.m_hasAutoOrphans
270         && textSecurity == o.textSecurity
271         && userModify == o.userModify
272         && wordBreak == o.wordBreak
273         && overflowWrap == o.overflowWrap
274         && nbspMode == o.nbspMode
275         && lineBreak == o.lineBreak
276 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
277         && useTouchOverflowScrolling == o.useTouchOverflowScrolling
278 #endif
279 #if ENABLE(IOS_TEXT_AUTOSIZING)
280         && textSizeAdjust == o.textSizeAdjust
281 #endif
282         && resize == o.resize
283         && userSelect == o.userSelect
284         && colorSpace == o.colorSpace
285         && speak == o.speak
286         && hyphens == o.hyphens
287         && hyphenationLimitBefore == o.hyphenationLimitBefore
288         && hyphenationLimitAfter == o.hyphenationLimitAfter
289         && hyphenationLimitLines == o.hyphenationLimitLines
290         && textEmphasisFill == o.textEmphasisFill
291         && textEmphasisMark == o.textEmphasisMark
292         && textEmphasisPosition == o.textEmphasisPosition
293         && m_textOrientation == o.m_textOrientation
294 #if ENABLE(CSS3_TEXT)
295         && m_textIndentLine == o.m_textIndentLine
296         && m_textIndentType == o.m_textIndentType
297 #endif
298         && m_lineBoxContain == o.m_lineBoxContain
299 #if PLATFORM(IOS)
300         && touchCalloutEnabled == o.touchCalloutEnabled
301 #endif
302         && hyphenationString == o.hyphenationString
303         && locale == o.locale
304         && textEmphasisCustomMark == o.textEmphasisCustomMark
305         && quotesDataEquivalent(quotes.get(), o.quotes.get())
306         && m_tabSize == o.m_tabSize
307         && m_lineGrid == o.m_lineGrid
308 #if ENABLE(CSS_IMAGE_ORIENTATION)
309         && m_imageOrientation == o.m_imageOrientation
310 #endif
311         && m_imageRendering == o.m_imageRendering
312 #if ENABLE(CSS_IMAGE_RESOLUTION)
313         && m_imageResolutionSource == o.m_imageResolutionSource
314         && m_imageResolutionSnap == o.m_imageResolutionSnap
315         && m_imageResolution == o.m_imageResolution
316 #endif
317 #if ENABLE(CSS3_TEXT)
318         && m_textAlignLast == o.m_textAlignLast
319         && m_textJustify == o.m_textJustify
320 #endif // CSS3_TEXT
321 #if ENABLE(CSS3_TEXT_DECORATION)
322         && m_textDecorationSkip == o.m_textDecorationSkip
323         && m_textUnderlinePosition == o.m_textUnderlinePosition
324 #endif
325         && m_rubyPosition == o.m_rubyPosition
326         && m_lineSnap == o.m_lineSnap
327         && m_lineAlign == o.m_lineAlign
328         && StyleImage::imagesEquivalent(listStyleImage.get(), o.listStyleImage.get());
329 }
330
331 bool StyleRareInheritedData::shadowDataEquivalent(const StyleRareInheritedData& o) const
332 {
333     if ((!textShadow && o.textShadow) || (textShadow && !o.textShadow))
334         return false;
335     if (textShadow && o.textShadow && (*textShadow != *o.textShadow))
336         return false;
337     return true;
338 }
339
340 } // namespace WebCore