-webkit-text-underline-position should not be inherited
[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 #endif // CSS3_TEXT
110     , m_rubyPosition(RenderStyle::initialRubyPosition())
111     , hyphenationLimitBefore(-1)
112     , hyphenationLimitAfter(-1)
113     , hyphenationLimitLines(-1)
114     , m_lineGrid(RenderStyle::initialLineGrid())
115     , m_tabSize(RenderStyle::initialTabSize())
116 #if ENABLE(CSS_IMAGE_RESOLUTION)
117     , m_imageResolution(RenderStyle::initialImageResolution())
118 #endif
119 #if ENABLE(TOUCH_EVENTS)
120     , tapHighlightColor(RenderStyle::initialTapHighlightColor())
121 #endif    
122 {
123 #if ENABLE(CSS_VARIABLES)
124     m_variables.init();
125 #endif
126 }
127
128 StyleRareInheritedData::StyleRareInheritedData(const StyleRareInheritedData& o)
129     : RefCounted<StyleRareInheritedData>()
130     , listStyleImage(o.listStyleImage)
131     , textStrokeColor(o.textStrokeColor)
132     , textStrokeWidth(o.textStrokeWidth)
133     , textFillColor(o.textFillColor)
134     , textEmphasisColor(o.textEmphasisColor)
135     , visitedLinkTextStrokeColor(o.visitedLinkTextStrokeColor)
136     , visitedLinkTextFillColor(o.visitedLinkTextFillColor)
137     , visitedLinkTextEmphasisColor(o.visitedLinkTextEmphasisColor)
138     , textShadow(o.textShadow ? adoptPtr(new ShadowData(*o.textShadow)) : nullptr)
139     , highlight(o.highlight)
140     , cursorData(o.cursorData)
141     , indent(o.indent)
142     , m_effectiveZoom(o.m_effectiveZoom)
143     , widows(o.widows)
144     , orphans(o.orphans)
145     , m_hasAutoWidows(o.m_hasAutoWidows)
146     , m_hasAutoOrphans(o.m_hasAutoOrphans)
147     , textSecurity(o.textSecurity)
148     , userModify(o.userModify)
149     , wordBreak(o.wordBreak)
150     , overflowWrap(o.overflowWrap)
151     , nbspMode(o.nbspMode)
152     , lineBreak(o.lineBreak)
153     , resize(o.resize)
154     , userSelect(o.userSelect)
155     , colorSpace(o.colorSpace)
156     , speak(o.speak)
157     , hyphens(o.hyphens)
158     , textEmphasisFill(o.textEmphasisFill)
159     , textEmphasisMark(o.textEmphasisMark)
160     , textEmphasisPosition(o.textEmphasisPosition)
161     , m_textOrientation(o.m_textOrientation)
162 #if ENABLE(CSS3_TEXT)
163     , m_textIndentLine(o.m_textIndentLine)
164     , m_textIndentType(o.m_textIndentType)
165 #endif
166     , m_lineBoxContain(o.m_lineBoxContain)
167 #if ENABLE(CSS_IMAGE_ORIENTATION)
168     , m_imageOrientation(o.m_imageOrientation)
169 #endif
170     , m_imageRendering(o.m_imageRendering)
171     , m_lineSnap(o.m_lineSnap)
172     , m_lineAlign(o.m_lineAlign)
173 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
174     , useTouchOverflowScrolling(o.useTouchOverflowScrolling)
175 #endif
176 #if ENABLE(CSS_IMAGE_RESOLUTION)
177     , m_imageResolutionSource(o.m_imageResolutionSource)
178     , m_imageResolutionSnap(o.m_imageResolutionSnap)
179 #endif
180 #if ENABLE(CSS3_TEXT)
181     , m_textAlignLast(o.m_textAlignLast)
182     , m_textJustify(o.m_textJustify)
183 #endif // CSS3_TEXT
184     , m_rubyPosition(o.m_rubyPosition)
185     , hyphenationString(o.hyphenationString)
186     , hyphenationLimitBefore(o.hyphenationLimitBefore)
187     , hyphenationLimitAfter(o.hyphenationLimitAfter)
188     , hyphenationLimitLines(o.hyphenationLimitLines)
189     , locale(o.locale)
190     , textEmphasisCustomMark(o.textEmphasisCustomMark)
191     , m_lineGrid(o.m_lineGrid)
192     , m_tabSize(o.m_tabSize)
193 #if ENABLE(CSS_IMAGE_RESOLUTION)
194     , m_imageResolution(o.m_imageResolution)
195 #endif
196 #if ENABLE(TOUCH_EVENTS)
197     , tapHighlightColor(o.tapHighlightColor)
198 #endif
199 #if ENABLE(CSS_VARIABLES)
200     , m_variables(o.m_variables)
201 #endif
202 {
203 }
204
205 StyleRareInheritedData::~StyleRareInheritedData()
206 {
207 }
208
209 static bool cursorDataEquivalent(const CursorList* c1, const CursorList* c2)
210 {
211     if (c1 == c2)
212         return true;
213     if ((!c1 && c2) || (c1 && !c2))
214         return false;
215     return (*c1 == *c2);
216 }
217
218 static bool quotesDataEquivalent(const QuotesData* q1, const QuotesData* q2)
219 {
220     if (q1 == q2)
221         return true;
222     if ((!q1 && q2) || (q1 && !q2))
223         return false;
224     return (*q1 == *q2);
225 }
226
227 bool StyleRareInheritedData::operator==(const StyleRareInheritedData& o) const
228 {
229     return textStrokeColor == o.textStrokeColor
230         && textStrokeWidth == o.textStrokeWidth
231         && textFillColor == o.textFillColor
232         && textEmphasisColor == o.textEmphasisColor
233         && visitedLinkTextStrokeColor == o.visitedLinkTextStrokeColor
234         && visitedLinkTextFillColor == o.visitedLinkTextFillColor
235         && visitedLinkTextEmphasisColor == o.visitedLinkTextEmphasisColor
236 #if ENABLE(TOUCH_EVENTS)
237         && tapHighlightColor == o.tapHighlightColor
238 #endif
239         && shadowDataEquivalent(o)
240         && highlight == o.highlight
241         && cursorDataEquivalent(cursorData.get(), o.cursorData.get())
242         && indent == o.indent
243         && m_effectiveZoom == o.m_effectiveZoom
244         && widows == o.widows
245         && orphans == o.orphans
246         && m_hasAutoWidows == o.m_hasAutoWidows
247         && m_hasAutoOrphans == o.m_hasAutoOrphans
248         && textSecurity == o.textSecurity
249         && userModify == o.userModify
250         && wordBreak == o.wordBreak
251         && overflowWrap == o.overflowWrap
252         && nbspMode == o.nbspMode
253         && lineBreak == o.lineBreak
254 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
255         && useTouchOverflowScrolling == o.useTouchOverflowScrolling
256 #endif
257         && resize == o.resize
258         && userSelect == o.userSelect
259         && colorSpace == o.colorSpace
260         && speak == o.speak
261         && hyphens == o.hyphens
262         && hyphenationLimitBefore == o.hyphenationLimitBefore
263         && hyphenationLimitAfter == o.hyphenationLimitAfter
264         && hyphenationLimitLines == o.hyphenationLimitLines
265         && textEmphasisFill == o.textEmphasisFill
266         && textEmphasisMark == o.textEmphasisMark
267         && textEmphasisPosition == o.textEmphasisPosition
268         && m_textOrientation == o.m_textOrientation
269 #if ENABLE(CSS3_TEXT)
270         && m_textIndentLine == o.m_textIndentLine
271         && m_textIndentType == o.m_textIndentType
272 #endif
273         && m_lineBoxContain == o.m_lineBoxContain
274         && hyphenationString == o.hyphenationString
275         && locale == o.locale
276         && textEmphasisCustomMark == o.textEmphasisCustomMark
277         && quotesDataEquivalent(quotes.get(), o.quotes.get())
278         && m_tabSize == o.m_tabSize
279         && m_lineGrid == o.m_lineGrid
280 #if ENABLE(CSS_IMAGE_ORIENTATION)
281         && m_imageOrientation == o.m_imageOrientation
282 #endif
283         && m_imageRendering == o.m_imageRendering
284 #if ENABLE(CSS_IMAGE_RESOLUTION)
285         && m_imageResolutionSource == o.m_imageResolutionSource
286         && m_imageResolutionSnap == o.m_imageResolutionSnap
287         && m_imageResolution == o.m_imageResolution
288 #endif
289 #if ENABLE(CSS3_TEXT)
290         && m_textAlignLast == o.m_textAlignLast
291         && m_textJustify == o.m_textJustify
292 #endif // CSS3_TEXT
293         && m_rubyPosition == o.m_rubyPosition
294         && m_lineSnap == o.m_lineSnap
295 #if ENABLE(CSS_VARIABLES)
296         && m_variables == o.m_variables
297 #endif
298         && m_lineAlign == o.m_lineAlign
299         && StyleImage::imagesEquivalent(listStyleImage.get(), o.listStyleImage.get());
300 }
301
302 bool StyleRareInheritedData::shadowDataEquivalent(const StyleRareInheritedData& o) const
303 {
304     if ((!textShadow && o.textShadow) || (textShadow && !o.textShadow))
305         return false;
306     if (textShadow && o.textShadow && (*textShadow != *o.textShadow))
307         return false;
308     return true;
309 }
310
311 } // namespace WebCore