dffa90e260ae30f360237d6f9b36e4dff27bf4b9
[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 GreaterThanOrSameSizeAsStyleRareInheritedData : public RefCounted<GreaterThanOrSameSizeAsStyleRareInheritedData> {
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[2];
43     float secondFloat;
44     unsigned m_bitfields[4];
45     short pagedMediaShorts[2];
46     unsigned unsigneds[1];
47     short hyphenationShorts[3];
48
49 #if PLATFORM(IOS)
50     Color compositionColor;
51 #endif
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 tapHighlightColor;
62 #endif
63 };
64
65 COMPILE_ASSERT(sizeof(StyleRareInheritedData) <= sizeof(GreaterThanOrSameSizeAsStyleRareInheritedData), 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 | TextEmphasisPositionRight)
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     , m_textDecorationSkip(RenderStyle::initialTextDecorationSkip())
114     , m_textUnderlinePosition(RenderStyle::initialTextUnderlinePosition())
115     , m_rubyPosition(RenderStyle::initialRubyPosition())
116     , m_textZoom(RenderStyle::initialTextZoom())
117 #if PLATFORM(IOS)
118     , touchCalloutEnabled(RenderStyle::initialTouchCalloutEnabled())
119 #endif
120 #if ENABLE(CSS_TRAILING_WORD)
121     , trailingWord(static_cast<unsigned>(RenderStyle::initialTrailingWord()))
122 #endif
123     , hyphenationLimitBefore(-1)
124     , hyphenationLimitAfter(-1)
125     , hyphenationLimitLines(-1)
126     , m_lineGrid(RenderStyle::initialLineGrid())
127     , m_tabSize(RenderStyle::initialTabSize())
128 #if ENABLE(IOS_TEXT_AUTOSIZING)
129     , textSizeAdjust(RenderStyle::initialTextSizeAdjust())
130 #endif
131 #if ENABLE(CSS_IMAGE_RESOLUTION)
132     , m_imageResolution(RenderStyle::initialImageResolution())
133 #endif
134 #if ENABLE(TOUCH_EVENTS)
135     , tapHighlightColor(RenderStyle::initialTapHighlightColor())
136 #endif
137 {
138 }
139
140 inline StyleRareInheritedData::StyleRareInheritedData(const StyleRareInheritedData& o)
141     : RefCounted<StyleRareInheritedData>()
142     , listStyleImage(o.listStyleImage)
143     , textStrokeColor(o.textStrokeColor)
144     , textStrokeWidth(o.textStrokeWidth)
145     , textFillColor(o.textFillColor)
146     , textEmphasisColor(o.textEmphasisColor)
147     , visitedLinkTextStrokeColor(o.visitedLinkTextStrokeColor)
148     , visitedLinkTextFillColor(o.visitedLinkTextFillColor)
149     , visitedLinkTextEmphasisColor(o.visitedLinkTextEmphasisColor)
150     , textShadow(o.textShadow ? std::make_unique<ShadowData>(*o.textShadow) : nullptr)
151     , cursorData(o.cursorData)
152     , indent(o.indent)
153     , m_effectiveZoom(o.m_effectiveZoom)
154     , widows(o.widows)
155     , orphans(o.orphans)
156     , m_hasAutoWidows(o.m_hasAutoWidows)
157     , m_hasAutoOrphans(o.m_hasAutoOrphans)
158     , textSecurity(o.textSecurity)
159     , userModify(o.userModify)
160     , wordBreak(o.wordBreak)
161     , overflowWrap(o.overflowWrap)
162     , nbspMode(o.nbspMode)
163     , lineBreak(o.lineBreak)
164     , resize(o.resize)
165     , userSelect(o.userSelect)
166     , colorSpace(o.colorSpace)
167     , speak(o.speak)
168     , hyphens(o.hyphens)
169     , textEmphasisFill(o.textEmphasisFill)
170     , textEmphasisMark(o.textEmphasisMark)
171     , textEmphasisPosition(o.textEmphasisPosition)
172     , m_textOrientation(o.m_textOrientation)
173 #if ENABLE(CSS3_TEXT)
174     , m_textIndentLine(o.m_textIndentLine)
175     , m_textIndentType(o.m_textIndentType)
176 #endif
177     , m_lineBoxContain(o.m_lineBoxContain)
178 #if ENABLE(CSS_IMAGE_ORIENTATION)
179     , m_imageOrientation(o.m_imageOrientation)
180 #endif
181     , m_imageRendering(o.m_imageRendering)
182     , m_lineSnap(o.m_lineSnap)
183     , m_lineAlign(o.m_lineAlign)
184 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
185     , useTouchOverflowScrolling(o.useTouchOverflowScrolling)
186 #endif
187 #if ENABLE(CSS_IMAGE_RESOLUTION)
188     , m_imageResolutionSource(o.m_imageResolutionSource)
189     , m_imageResolutionSnap(o.m_imageResolutionSnap)
190 #endif
191 #if ENABLE(CSS3_TEXT)
192     , m_textAlignLast(o.m_textAlignLast)
193     , m_textJustify(o.m_textJustify)
194 #endif // CSS3_TEXT
195     , m_textDecorationSkip(o.m_textDecorationSkip)
196     , m_textUnderlinePosition(o.m_textUnderlinePosition)
197     , m_rubyPosition(o.m_rubyPosition)
198     , m_textZoom(o.m_textZoom)
199 #if PLATFORM(IOS)
200     , touchCalloutEnabled(o.touchCalloutEnabled)
201 #endif
202 #if ENABLE(CSS_TRAILING_WORD)
203     , trailingWord(o.trailingWord)
204 #endif
205     , hyphenationString(o.hyphenationString)
206     , hyphenationLimitBefore(o.hyphenationLimitBefore)
207     , hyphenationLimitAfter(o.hyphenationLimitAfter)
208     , hyphenationLimitLines(o.hyphenationLimitLines)
209     , locale(o.locale)
210     , textEmphasisCustomMark(o.textEmphasisCustomMark)
211     , m_lineGrid(o.m_lineGrid)
212     , m_tabSize(o.m_tabSize)
213 #if ENABLE(IOS_TEXT_AUTOSIZING)
214     , textSizeAdjust(o.textSizeAdjust)
215 #endif
216 #if ENABLE(CSS_IMAGE_RESOLUTION)
217     , m_imageResolution(o.m_imageResolution)
218 #endif
219 #if ENABLE(TOUCH_EVENTS)
220     , tapHighlightColor(o.tapHighlightColor)
221 #endif
222 {
223 }
224
225 Ref<StyleRareInheritedData> StyleRareInheritedData::copy() const
226 {
227     return adoptRef(*new StyleRareInheritedData(*this));
228 }
229
230 StyleRareInheritedData::~StyleRareInheritedData()
231 {
232 }
233
234 static bool cursorDataEquivalent(const CursorList* c1, const CursorList* c2)
235 {
236     if (c1 == c2)
237         return true;
238     if ((!c1 && c2) || (c1 && !c2))
239         return false;
240     return (*c1 == *c2);
241 }
242
243 static bool quotesDataEquivalent(const QuotesData* q1, const QuotesData* q2)
244 {
245     if (q1 == q2)
246         return true;
247     if ((!q1 && q2) || (q1 && !q2))
248         return false;
249     return (*q1 == *q2);
250 }
251
252 bool StyleRareInheritedData::operator==(const StyleRareInheritedData& o) const
253 {
254     return textStrokeColor == o.textStrokeColor
255         && textStrokeWidth == o.textStrokeWidth
256         && textFillColor == o.textFillColor
257         && textEmphasisColor == o.textEmphasisColor
258         && visitedLinkTextStrokeColor == o.visitedLinkTextStrokeColor
259         && visitedLinkTextFillColor == o.visitedLinkTextFillColor
260         && visitedLinkTextEmphasisColor == o.visitedLinkTextEmphasisColor
261 #if ENABLE(TOUCH_EVENTS)
262         && tapHighlightColor == o.tapHighlightColor
263 #endif
264         && shadowDataEquivalent(o)
265         && cursorDataEquivalent(cursorData.get(), o.cursorData.get())
266         && indent == o.indent
267         && m_effectiveZoom == o.m_effectiveZoom
268         && widows == o.widows
269         && orphans == o.orphans
270         && m_hasAutoWidows == o.m_hasAutoWidows
271         && m_hasAutoOrphans == o.m_hasAutoOrphans
272         && textSecurity == o.textSecurity
273         && userModify == o.userModify
274         && wordBreak == o.wordBreak
275         && overflowWrap == o.overflowWrap
276         && nbspMode == o.nbspMode
277         && lineBreak == o.lineBreak
278 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
279         && useTouchOverflowScrolling == o.useTouchOverflowScrolling
280 #endif
281 #if ENABLE(IOS_TEXT_AUTOSIZING)
282         && textSizeAdjust == o.textSizeAdjust
283 #endif
284         && resize == o.resize
285         && userSelect == o.userSelect
286         && colorSpace == o.colorSpace
287         && speak == o.speak
288         && hyphens == o.hyphens
289         && hyphenationLimitBefore == o.hyphenationLimitBefore
290         && hyphenationLimitAfter == o.hyphenationLimitAfter
291         && hyphenationLimitLines == o.hyphenationLimitLines
292         && textEmphasisFill == o.textEmphasisFill
293         && textEmphasisMark == o.textEmphasisMark
294         && textEmphasisPosition == o.textEmphasisPosition
295         && m_textOrientation == o.m_textOrientation
296 #if ENABLE(CSS3_TEXT)
297         && m_textIndentLine == o.m_textIndentLine
298         && m_textIndentType == o.m_textIndentType
299 #endif
300         && m_lineBoxContain == o.m_lineBoxContain
301 #if PLATFORM(IOS)
302         && touchCalloutEnabled == o.touchCalloutEnabled
303 #endif
304         && hyphenationString == o.hyphenationString
305         && locale == o.locale
306         && textEmphasisCustomMark == o.textEmphasisCustomMark
307         && quotesDataEquivalent(quotes.get(), o.quotes.get())
308         && m_tabSize == o.m_tabSize
309         && m_lineGrid == o.m_lineGrid
310 #if ENABLE(CSS_IMAGE_ORIENTATION)
311         && m_imageOrientation == o.m_imageOrientation
312 #endif
313         && m_imageRendering == o.m_imageRendering
314 #if ENABLE(CSS_IMAGE_RESOLUTION)
315         && m_imageResolutionSource == o.m_imageResolutionSource
316         && m_imageResolutionSnap == o.m_imageResolutionSnap
317         && m_imageResolution == o.m_imageResolution
318 #endif
319 #if ENABLE(CSS3_TEXT)
320         && m_textAlignLast == o.m_textAlignLast
321         && m_textJustify == o.m_textJustify
322 #endif // CSS3_TEXT
323         && m_textDecorationSkip == o.m_textDecorationSkip
324         && m_textUnderlinePosition == o.m_textUnderlinePosition
325         && m_rubyPosition == o.m_rubyPosition
326         && m_textZoom == o.m_textZoom
327         && m_lineSnap == o.m_lineSnap
328         && m_lineAlign == o.m_lineAlign
329 #if ENABLE(CSS_TRAILING_WORD)
330         && trailingWord == o.trailingWord
331 #endif
332         && StyleImage::imagesEquivalent(listStyleImage.get(), o.listStyleImage.get());
333 }
334
335 bool StyleRareInheritedData::shadowDataEquivalent(const StyleRareInheritedData& o) const
336 {
337     if ((!textShadow && o.textShadow) || (textShadow && !o.textShadow))
338         return false;
339     if (textShadow && o.textShadow && (*textShadow != *o.textShadow))
340         return false;
341     return true;
342 }
343
344 } // namespace WebCore