Revert r187626 (and r188025) as it caused a PLT regression
[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 "DataRef.h"
27 #include "QuotesData.h"
28 #include "RenderStyle.h"
29 #include "RenderStyleConstants.h"
30 #include "ShadowData.h"
31 #include "StyleCustomPropertyData.h"
32 #include "StyleImage.h"
33
34 namespace WebCore {
35
36 struct GreaterThanOrSameSizeAsStyleRareInheritedData : public RefCounted<GreaterThanOrSameSizeAsStyleRareInheritedData> {
37     void* styleImage;
38     Color firstColor;
39     float firstFloat;
40     Color colors[5];
41     void* ownPtrs[1];
42     AtomicString atomicStrings[5];
43     void* refPtrs[2];
44     Length lengths[2];
45     float secondFloat;
46     unsigned m_bitfields[4];
47     short pagedMediaShorts[2];
48     unsigned unsigneds[1];
49     short hyphenationShorts[3];
50
51 #if PLATFORM(IOS)
52     Color compositionColor;
53 #endif
54 #if ENABLE(IOS_TEXT_AUTOSIZING)
55     TextSizeAdjustment textSizeAdjust;
56 #endif
57
58 #if ENABLE(CSS_IMAGE_RESOLUTION)
59     float imageResolutionFloats;
60 #endif
61
62 #if ENABLE(TOUCH_EVENTS)
63     Color tapHighlightColor;
64 #endif
65
66     void* customPropertyDataRefs[1];
67 };
68
69 COMPILE_ASSERT(sizeof(StyleRareInheritedData) <= sizeof(GreaterThanOrSameSizeAsStyleRareInheritedData), 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     , m_customProperties(StyleCustomPropertyData::create())
77     , widows(RenderStyle::initialWidows())
78     , orphans(RenderStyle::initialOrphans())
79     , m_hasAutoWidows(true)
80     , m_hasAutoOrphans(true)
81     , textSecurity(RenderStyle::initialTextSecurity())
82     , userModify(READ_ONLY)
83     , wordBreak(RenderStyle::initialWordBreak())
84     , overflowWrap(RenderStyle::initialOverflowWrap())
85     , nbspMode(NBNORMAL)
86     , lineBreak(LineBreakAuto)
87     , resize(RenderStyle::initialResize())
88     , userSelect(RenderStyle::initialUserSelect())
89     , speak(SpeakNormal)
90     , hyphens(HyphensManual)
91     , textEmphasisFill(TextEmphasisFillFilled)
92     , textEmphasisMark(TextEmphasisMarkNone)
93     , textEmphasisPosition(TextEmphasisPositionOver | TextEmphasisPositionRight)
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 #endif // CSS3_TEXT
117     , m_textDecorationSkip(RenderStyle::initialTextDecorationSkip())
118     , m_textUnderlinePosition(RenderStyle::initialTextUnderlinePosition())
119     , m_rubyPosition(RenderStyle::initialRubyPosition())
120     , m_textZoom(RenderStyle::initialTextZoom())
121 #if PLATFORM(IOS)
122     , touchCalloutEnabled(RenderStyle::initialTouchCalloutEnabled())
123 #endif
124 #if ENABLE(CSS_TRAILING_WORD)
125     , trailingWord(static_cast<unsigned>(RenderStyle::initialTrailingWord()))
126 #endif
127     , hyphenationLimitBefore(-1)
128     , hyphenationLimitAfter(-1)
129     , hyphenationLimitLines(-1)
130     , m_lineGrid(RenderStyle::initialLineGrid())
131     , m_tabSize(RenderStyle::initialTabSize())
132 #if ENABLE(IOS_TEXT_AUTOSIZING)
133     , textSizeAdjust(RenderStyle::initialTextSizeAdjust())
134 #endif
135 #if ENABLE(CSS_IMAGE_RESOLUTION)
136     , m_imageResolution(RenderStyle::initialImageResolution())
137 #endif
138 #if ENABLE(TOUCH_EVENTS)
139     , tapHighlightColor(RenderStyle::initialTapHighlightColor())
140 #endif
141 {
142 }
143
144 inline StyleRareInheritedData::StyleRareInheritedData(const StyleRareInheritedData& o)
145     : RefCounted<StyleRareInheritedData>()
146     , listStyleImage(o.listStyleImage)
147     , textStrokeColor(o.textStrokeColor)
148     , textStrokeWidth(o.textStrokeWidth)
149     , textFillColor(o.textFillColor)
150     , textEmphasisColor(o.textEmphasisColor)
151     , visitedLinkTextStrokeColor(o.visitedLinkTextStrokeColor)
152     , visitedLinkTextFillColor(o.visitedLinkTextFillColor)
153     , visitedLinkTextEmphasisColor(o.visitedLinkTextEmphasisColor)
154     , textShadow(o.textShadow ? std::make_unique<ShadowData>(*o.textShadow) : nullptr)
155     , cursorData(o.cursorData)
156     , indent(o.indent)
157     , m_effectiveZoom(o.m_effectiveZoom)
158     , m_customProperties(o.m_customProperties)
159     , widows(o.widows)
160     , orphans(o.orphans)
161     , m_hasAutoWidows(o.m_hasAutoWidows)
162     , m_hasAutoOrphans(o.m_hasAutoOrphans)
163     , textSecurity(o.textSecurity)
164     , userModify(o.userModify)
165     , wordBreak(o.wordBreak)
166     , overflowWrap(o.overflowWrap)
167     , nbspMode(o.nbspMode)
168     , lineBreak(o.lineBreak)
169     , resize(o.resize)
170     , userSelect(o.userSelect)
171     , speak(o.speak)
172     , hyphens(o.hyphens)
173     , textEmphasisFill(o.textEmphasisFill)
174     , textEmphasisMark(o.textEmphasisMark)
175     , textEmphasisPosition(o.textEmphasisPosition)
176     , m_textOrientation(o.m_textOrientation)
177 #if ENABLE(CSS3_TEXT)
178     , m_textIndentLine(o.m_textIndentLine)
179     , m_textIndentType(o.m_textIndentType)
180 #endif
181     , m_lineBoxContain(o.m_lineBoxContain)
182 #if ENABLE(CSS_IMAGE_ORIENTATION)
183     , m_imageOrientation(o.m_imageOrientation)
184 #endif
185     , m_imageRendering(o.m_imageRendering)
186     , m_lineSnap(o.m_lineSnap)
187     , m_lineAlign(o.m_lineAlign)
188 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
189     , useTouchOverflowScrolling(o.useTouchOverflowScrolling)
190 #endif
191 #if ENABLE(CSS_IMAGE_RESOLUTION)
192     , m_imageResolutionSource(o.m_imageResolutionSource)
193     , m_imageResolutionSnap(o.m_imageResolutionSnap)
194 #endif
195 #if ENABLE(CSS3_TEXT)
196     , m_textAlignLast(o.m_textAlignLast)
197     , m_textJustify(o.m_textJustify)
198 #endif // CSS3_TEXT
199     , m_textDecorationSkip(o.m_textDecorationSkip)
200     , m_textUnderlinePosition(o.m_textUnderlinePosition)
201     , m_rubyPosition(o.m_rubyPosition)
202     , m_textZoom(o.m_textZoom)
203 #if PLATFORM(IOS)
204     , touchCalloutEnabled(o.touchCalloutEnabled)
205 #endif
206 #if ENABLE(CSS_TRAILING_WORD)
207     , trailingWord(o.trailingWord)
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 {
227 }
228
229 Ref<StyleRareInheritedData> StyleRareInheritedData::copy() const
230 {
231     return adoptRef(*new StyleRareInheritedData(*this));
232 }
233
234 StyleRareInheritedData::~StyleRareInheritedData()
235 {
236 }
237
238 static bool cursorDataEquivalent(const CursorList* c1, const CursorList* c2)
239 {
240     if (c1 == c2)
241         return true;
242     if ((!c1 && c2) || (c1 && !c2))
243         return false;
244     return (*c1 == *c2);
245 }
246
247 static bool quotesDataEquivalent(const QuotesData* q1, const QuotesData* q2)
248 {
249     if (q1 == q2)
250         return true;
251     if ((!q1 && q2) || (q1 && !q2))
252         return false;
253     return (*q1 == *q2);
254 }
255
256 bool StyleRareInheritedData::operator==(const StyleRareInheritedData& o) const
257 {
258     return textStrokeColor == o.textStrokeColor
259         && textStrokeWidth == o.textStrokeWidth
260         && textFillColor == o.textFillColor
261         && textEmphasisColor == o.textEmphasisColor
262         && visitedLinkTextStrokeColor == o.visitedLinkTextStrokeColor
263         && visitedLinkTextFillColor == o.visitedLinkTextFillColor
264         && visitedLinkTextEmphasisColor == o.visitedLinkTextEmphasisColor
265 #if ENABLE(TOUCH_EVENTS)
266         && tapHighlightColor == o.tapHighlightColor
267 #endif
268         && shadowDataEquivalent(o)
269         && cursorDataEquivalent(cursorData.get(), o.cursorData.get())
270         && indent == o.indent
271         && m_effectiveZoom == o.m_effectiveZoom
272         && widows == o.widows
273         && orphans == o.orphans
274         && m_hasAutoWidows == o.m_hasAutoWidows
275         && m_hasAutoOrphans == o.m_hasAutoOrphans
276         && textSecurity == o.textSecurity
277         && userModify == o.userModify
278         && wordBreak == o.wordBreak
279         && overflowWrap == o.overflowWrap
280         && nbspMode == o.nbspMode
281         && lineBreak == o.lineBreak
282 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
283         && useTouchOverflowScrolling == o.useTouchOverflowScrolling
284 #endif
285 #if ENABLE(IOS_TEXT_AUTOSIZING)
286         && textSizeAdjust == o.textSizeAdjust
287 #endif
288         && resize == o.resize
289         && userSelect == o.userSelect
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 #endif // CSS3_TEXT
326         && m_textDecorationSkip == o.m_textDecorationSkip
327         && m_textUnderlinePosition == o.m_textUnderlinePosition
328         && m_rubyPosition == o.m_rubyPosition
329         && m_textZoom == o.m_textZoom
330         && m_lineSnap == o.m_lineSnap
331         && m_lineAlign == o.m_lineAlign
332 #if ENABLE(CSS_TRAILING_WORD)
333         && trailingWord == o.trailingWord
334 #endif
335         && m_customProperties == o.m_customProperties
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