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