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