c60240bcaf4e5257686b80ba2c3a69d10e93a063
[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     , textEmphasisCustomMark(o.textEmphasisCustomMark)
210     , m_lineGrid(o.m_lineGrid)
211     , m_tabSize(o.m_tabSize)
212 #if ENABLE(IOS_TEXT_AUTOSIZING)
213     , textSizeAdjust(o.textSizeAdjust)
214 #endif
215 #if ENABLE(CSS_IMAGE_RESOLUTION)
216     , m_imageResolution(o.m_imageResolution)
217 #endif
218 #if ENABLE(TOUCH_EVENTS)
219     , tapHighlightColor(o.tapHighlightColor)
220 #endif
221 {
222 }
223
224 Ref<StyleRareInheritedData> StyleRareInheritedData::copy() const
225 {
226     return adoptRef(*new StyleRareInheritedData(*this));
227 }
228
229 StyleRareInheritedData::~StyleRareInheritedData()
230 {
231 }
232
233 static bool cursorDataEquivalent(const CursorList* c1, const CursorList* c2)
234 {
235     if (c1 == c2)
236         return true;
237     if ((!c1 && c2) || (c1 && !c2))
238         return false;
239     return (*c1 == *c2);
240 }
241
242 static bool quotesDataEquivalent(const QuotesData* q1, const QuotesData* q2)
243 {
244     if (q1 == q2)
245         return true;
246     if ((!q1 && q2) || (q1 && !q2))
247         return false;
248     return (*q1 == *q2);
249 }
250
251 bool StyleRareInheritedData::operator==(const StyleRareInheritedData& o) const
252 {
253     return textStrokeColor == o.textStrokeColor
254         && textStrokeWidth == o.textStrokeWidth
255         && textFillColor == o.textFillColor
256         && textEmphasisColor == o.textEmphasisColor
257         && visitedLinkTextStrokeColor == o.visitedLinkTextStrokeColor
258         && visitedLinkTextFillColor == o.visitedLinkTextFillColor
259         && visitedLinkTextEmphasisColor == o.visitedLinkTextEmphasisColor
260 #if ENABLE(TOUCH_EVENTS)
261         && tapHighlightColor == o.tapHighlightColor
262 #endif
263         && shadowDataEquivalent(o)
264         && cursorDataEquivalent(cursorData.get(), o.cursorData.get())
265         && indent == o.indent
266         && m_effectiveZoom == o.m_effectiveZoom
267         && widows == o.widows
268         && orphans == o.orphans
269         && m_hasAutoWidows == o.m_hasAutoWidows
270         && m_hasAutoOrphans == o.m_hasAutoOrphans
271         && textSecurity == o.textSecurity
272         && userModify == o.userModify
273         && wordBreak == o.wordBreak
274         && overflowWrap == o.overflowWrap
275         && nbspMode == o.nbspMode
276         && lineBreak == o.lineBreak
277 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
278         && useTouchOverflowScrolling == o.useTouchOverflowScrolling
279 #endif
280 #if ENABLE(IOS_TEXT_AUTOSIZING)
281         && textSizeAdjust == o.textSizeAdjust
282 #endif
283         && resize == o.resize
284         && userSelect == o.userSelect
285         && colorSpace == o.colorSpace
286         && speak == o.speak
287         && hyphens == o.hyphens
288         && hyphenationLimitBefore == o.hyphenationLimitBefore
289         && hyphenationLimitAfter == o.hyphenationLimitAfter
290         && hyphenationLimitLines == o.hyphenationLimitLines
291         && textEmphasisFill == o.textEmphasisFill
292         && textEmphasisMark == o.textEmphasisMark
293         && textEmphasisPosition == o.textEmphasisPosition
294         && m_textOrientation == o.m_textOrientation
295 #if ENABLE(CSS3_TEXT)
296         && m_textIndentLine == o.m_textIndentLine
297         && m_textIndentType == o.m_textIndentType
298 #endif
299         && m_lineBoxContain == o.m_lineBoxContain
300 #if PLATFORM(IOS)
301         && touchCalloutEnabled == o.touchCalloutEnabled
302 #endif
303         && hyphenationString == o.hyphenationString
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         && m_textDecorationSkip == o.m_textDecorationSkip
322         && m_textUnderlinePosition == o.m_textUnderlinePosition
323         && m_rubyPosition == o.m_rubyPosition
324         && m_textZoom == o.m_textZoom
325         && m_lineSnap == o.m_lineSnap
326         && m_lineAlign == o.m_lineAlign
327 #if ENABLE(CSS_TRAILING_WORD)
328         && trailingWord == o.trailingWord
329 #endif
330         && StyleImage::imagesEquivalent(listStyleImage.get(), o.listStyleImage.get());
331 }
332
333 bool StyleRareInheritedData::shadowDataEquivalent(const StyleRareInheritedData& o) const
334 {
335     if ((!textShadow && o.textShadow) || (textShadow && !o.textShadow))
336         return false;
337     if (textShadow && o.textShadow && (*textShadow != *o.textShadow))
338         return false;
339     return true;
340 }
341
342 } // namespace WebCore