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