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