Source/WebCore: [css3-text] Parsing -webkit-each-line value for text-indent from...
[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 #include "WebCoreMemoryInstrumentation.h"
32 #include <wtf/MemoryObjectInfo.h>
33
34 namespace WebCore {
35
36 struct SameSizeAsStyleRareInheritedData : public RefCounted<SameSizeAsStyleRareInheritedData> {
37     void* styleImage;
38     Color firstColor;
39     float firstFloat;
40     Color colors[5];
41     void* ownPtrs[1];
42     AtomicString atomicStrings[5];
43     void* refPtrs[2];
44     Length lengths[1];
45     float secondFloat;
46     unsigned m_bitfields[2];
47     short pagedMediaShorts[2];
48     unsigned unsigneds[1];
49     short hyphenationShorts[3];
50
51 #if ENABLE(CSS_IMAGE_RESOLUTION)
52     float imageResolutionFloats;
53 #endif
54
55 #if ENABLE(TOUCH_EVENTS)
56     Color touchColors;
57 #endif
58
59 #if ENABLE(CSS_VARIABLES)
60     void* variableDataRefs[1];
61 #endif
62 };
63
64 COMPILE_ASSERT(sizeof(StyleRareInheritedData) == sizeof(SameSizeAsStyleRareInheritedData), StyleRareInheritedData_should_bit_pack);
65
66 StyleRareInheritedData::StyleRareInheritedData()
67     : listStyleImage(RenderStyle::initialListStyleImage())
68     , textStrokeWidth(RenderStyle::initialTextStrokeWidth())
69     , indent(RenderStyle::initialTextIndent())
70     , m_effectiveZoom(RenderStyle::initialZoom())
71     , widows(RenderStyle::initialWidows())
72     , orphans(RenderStyle::initialOrphans())
73     , m_hasAutoWidows(true)
74     , m_hasAutoOrphans(true)
75     , textSecurity(RenderStyle::initialTextSecurity())
76     , userModify(READ_ONLY)
77     , wordBreak(RenderStyle::initialWordBreak())
78     , overflowWrap(RenderStyle::initialOverflowWrap())
79     , nbspMode(NBNORMAL)
80     , lineBreak(LineBreakAuto)
81     , resize(RenderStyle::initialResize())
82     , userSelect(RenderStyle::initialUserSelect())
83     , colorSpace(ColorSpaceDeviceRGB)
84     , speak(SpeakNormal)
85     , hyphens(HyphensManual)
86     , textEmphasisFill(TextEmphasisFillFilled)
87     , textEmphasisMark(TextEmphasisMarkNone)
88     , textEmphasisPosition(TextEmphasisPositionOver)
89     , m_textOrientation(TextOrientationVerticalRight)
90 #if ENABLE(CSS3_TEXT)
91     , m_textIndentLine(RenderStyle::initialTextIndentLine())
92 #endif
93     , m_lineBoxContain(RenderStyle::initialLineBoxContain())
94 #if ENABLE(CSS_IMAGE_ORIENTATION)
95     , m_imageOrientation(RenderStyle::initialImageOrientation())
96 #endif
97     , m_imageRendering(RenderStyle::initialImageRendering())
98     , m_lineSnap(RenderStyle::initialLineSnap())
99     , m_lineAlign(RenderStyle::initialLineAlign())
100 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
101     , useTouchOverflowScrolling(RenderStyle::initialUseTouchOverflowScrolling())
102 #endif
103 #if ENABLE(CSS_IMAGE_RESOLUTION)
104     , m_imageResolutionSource(RenderStyle::initialImageResolutionSource())
105     , m_imageResolutionSnap(RenderStyle::initialImageResolutionSnap())
106 #endif
107 #if ENABLE(CSS3_TEXT)
108     , m_textAlignLast(RenderStyle::initialTextAlignLast())
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 #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_textUnderlinePosition(o.m_textUnderlinePosition)
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 bool StyleRareInheritedData::operator==(const StyleRareInheritedData& o) const
219 {
220     return textStrokeColor == o.textStrokeColor
221         && textStrokeWidth == o.textStrokeWidth
222         && textFillColor == o.textFillColor
223         && textEmphasisColor == o.textEmphasisColor
224         && visitedLinkTextStrokeColor == o.visitedLinkTextStrokeColor
225         && visitedLinkTextFillColor == o.visitedLinkTextFillColor
226         && visitedLinkTextEmphasisColor == o.visitedLinkTextEmphasisColor
227 #if ENABLE(TOUCH_EVENTS)
228         && tapHighlightColor == o.tapHighlightColor
229 #endif
230         && shadowDataEquivalent(o)
231         && highlight == o.highlight
232         && cursorDataEquivalent(cursorData.get(), o.cursorData.get())
233         && indent == o.indent
234         && m_effectiveZoom == o.m_effectiveZoom
235         && widows == o.widows
236         && orphans == o.orphans
237         && m_hasAutoWidows == o.m_hasAutoWidows
238         && m_hasAutoOrphans == o.m_hasAutoOrphans
239         && textSecurity == o.textSecurity
240         && userModify == o.userModify
241         && wordBreak == o.wordBreak
242         && overflowWrap == o.overflowWrap
243         && nbspMode == o.nbspMode
244         && lineBreak == o.lineBreak
245 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
246         && useTouchOverflowScrolling == o.useTouchOverflowScrolling
247 #endif
248         && resize == o.resize
249         && userSelect == o.userSelect
250         && colorSpace == o.colorSpace
251         && speak == o.speak
252         && hyphens == o.hyphens
253         && hyphenationLimitBefore == o.hyphenationLimitBefore
254         && hyphenationLimitAfter == o.hyphenationLimitAfter
255         && hyphenationLimitLines == o.hyphenationLimitLines
256         && textEmphasisFill == o.textEmphasisFill
257         && textEmphasisMark == o.textEmphasisMark
258         && textEmphasisPosition == o.textEmphasisPosition
259         && m_textOrientation == o.m_textOrientation
260 #if ENABLE(CSS3_TEXT)
261         && m_textIndentLine == o.m_textIndentLine
262 #endif
263         && m_lineBoxContain == o.m_lineBoxContain
264         && hyphenationString == o.hyphenationString
265         && locale == o.locale
266         && textEmphasisCustomMark == o.textEmphasisCustomMark
267         && QuotesData::equals(quotes.get(), o.quotes.get())
268         && m_tabSize == o.m_tabSize
269         && m_lineGrid == o.m_lineGrid
270 #if ENABLE(CSS_IMAGE_ORIENTATION)
271         && m_imageOrientation == o.m_imageOrientation
272 #endif
273         && m_imageRendering == o.m_imageRendering
274 #if ENABLE(CSS_IMAGE_RESOLUTION)
275         && m_imageResolutionSource == o.m_imageResolutionSource
276         && m_imageResolutionSnap == o.m_imageResolutionSnap
277         && m_imageResolution == o.m_imageResolution
278 #endif
279 #if ENABLE(CSS3_TEXT)
280         && m_textAlignLast == o.m_textAlignLast
281         && m_textUnderlinePosition == o.m_textUnderlinePosition
282 #endif // CSS3_TEXT
283         && m_rubyPosition == o.m_rubyPosition
284         && m_lineSnap == o.m_lineSnap
285 #if ENABLE(CSS_VARIABLES)
286         && m_variables == o.m_variables
287 #endif
288         && m_lineAlign == o.m_lineAlign
289         && StyleImage::imagesEquivalent(listStyleImage.get(), o.listStyleImage.get());
290 }
291
292 bool StyleRareInheritedData::shadowDataEquivalent(const StyleRareInheritedData& o) const
293 {
294     if ((!textShadow && o.textShadow) || (textShadow && !o.textShadow))
295         return false;
296     if (textShadow && o.textShadow && (*textShadow != *o.textShadow))
297         return false;
298     return true;
299 }
300
301 void StyleRareInheritedData::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
302 {
303     MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS);
304     info.addMember(listStyleImage, "listStyleImage");
305     info.addMember(indent, "indent");
306     info.addMember(textShadow, "textShadow");
307     info.addMember(highlight, "highlight");
308     info.addMember(cursorData, "cursorData");
309     info.addMember(hyphenationString, "hyphenationString");
310     info.addMember(locale, "locale");
311     info.addMember(textEmphasisCustomMark, "textEmphasisCustomMark");
312     info.addMember(quotes, "quotes");
313     info.addMember(m_lineGrid, "lineGrid");
314 #if ENABLE(CSS_VARIABLES)
315     info.addMember(m_variables, "variables");
316 #endif
317 }
318
319 } // namespace WebCore