Make QuotesData use a Vector of pairs
[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
31 namespace WebCore {
32
33 struct SameSizeAsStyleRareInheritedData : public RefCounted<SameSizeAsStyleRareInheritedData> {
34     Color firstColor;
35     float firstFloat;
36     Color colors[5];
37     void* ownPtrs[1];
38     AtomicString atomicStrings[5];
39     void* refPtrs[2];
40     Length lengths[1];
41     float secondFloat;
42     unsigned m_bitfields[2];
43     short pagedMediaShorts[2];
44     unsigned unsigneds[1];
45     short hyphenationShorts[3];
46
47 #if ENABLE(CSS_IMAGE_RESOLUTION)
48     float imageResolutionFloats;
49 #endif
50
51 #if ENABLE(TOUCH_EVENTS)
52     Color touchColors;
53 #endif
54
55 #if ENABLE(CSS_VARIABLES)
56     void* variableDataRefs[1];
57 #endif
58 };
59
60 COMPILE_ASSERT(sizeof(StyleRareInheritedData) == sizeof(SameSizeAsStyleRareInheritedData), StyleRareInheritedData_should_bit_pack);
61
62 StyleRareInheritedData::StyleRareInheritedData()
63     : textStrokeWidth(RenderStyle::initialTextStrokeWidth())
64     , indent(RenderStyle::initialTextIndent())
65     , m_effectiveZoom(RenderStyle::initialZoom())
66     , widows(RenderStyle::initialWidows())
67     , orphans(RenderStyle::initialOrphans())
68     , textSecurity(RenderStyle::initialTextSecurity())
69     , userModify(READ_ONLY)
70     , wordBreak(RenderStyle::initialWordBreak())
71     , wordWrap(RenderStyle::initialWordWrap())
72     , nbspMode(NBNORMAL)
73     , khtmlLineBreak(LBNORMAL)
74     , textSizeAdjust(RenderStyle::initialTextSizeAdjust())
75     , resize(RenderStyle::initialResize())
76     , userSelect(RenderStyle::initialUserSelect())
77     , colorSpace(ColorSpaceDeviceRGB)
78     , speak(SpeakNormal)
79     , hyphens(HyphensManual)
80     , textEmphasisFill(TextEmphasisFillFilled)
81     , textEmphasisMark(TextEmphasisMarkNone)
82     , textEmphasisPosition(TextEmphasisPositionOver)
83     , m_lineBoxContain(RenderStyle::initialLineBoxContain())
84 #if ENABLE(CSS_IMAGE_ORIENTATION)
85     , m_imageOrientation(RenderStyle::initialImageOrientation())
86 #endif
87     , m_imageRendering(RenderStyle::initialImageRendering())
88     , m_lineSnap(RenderStyle::initialLineSnap())
89     , m_lineAlign(RenderStyle::initialLineAlign())
90 #if ENABLE(OVERFLOW_SCROLLING)
91     , useTouchOverflowScrolling(RenderStyle::initialUseTouchOverflowScrolling())
92 #endif
93 #if ENABLE(CSS_IMAGE_RESOLUTION)
94     , m_imageResolutionSource(RenderStyle::initialImageResolutionSource())
95     , m_imageResolutionSnap(RenderStyle::initialImageResolutionSnap())
96 #endif
97     , hyphenationLimitBefore(-1)
98     , hyphenationLimitAfter(-1)
99     , hyphenationLimitLines(-1)
100     , m_lineGrid(RenderStyle::initialLineGrid())
101     , m_tabSize(RenderStyle::initialTabSize())
102 #if ENABLE(CSS_IMAGE_RESOLUTION)
103     , m_imageResolution(RenderStyle::initialImageResolution())
104 #endif
105 #if ENABLE(TOUCH_EVENTS)
106     , tapHighlightColor(RenderStyle::initialTapHighlightColor())
107 #endif    
108 {
109 #if ENABLE(CSS_VARIABLES)
110     m_variables.init();
111 #endif
112 }
113
114 StyleRareInheritedData::StyleRareInheritedData(const StyleRareInheritedData& o)
115     : RefCounted<StyleRareInheritedData>()
116     , textStrokeColor(o.textStrokeColor)
117     , textStrokeWidth(o.textStrokeWidth)
118     , textFillColor(o.textFillColor)
119     , textEmphasisColor(o.textEmphasisColor)
120     , visitedLinkTextStrokeColor(o.visitedLinkTextStrokeColor)
121     , visitedLinkTextFillColor(o.visitedLinkTextFillColor)
122     , visitedLinkTextEmphasisColor(o.visitedLinkTextEmphasisColor)
123     , textShadow(o.textShadow ? adoptPtr(new ShadowData(*o.textShadow)) : nullptr)
124     , highlight(o.highlight)
125     , cursorData(o.cursorData)
126     , indent(o.indent)
127     , m_effectiveZoom(o.m_effectiveZoom)
128     , widows(o.widows)
129     , orphans(o.orphans)
130     , textSecurity(o.textSecurity)
131     , userModify(o.userModify)
132     , wordBreak(o.wordBreak)
133     , wordWrap(o.wordWrap)
134     , nbspMode(o.nbspMode)
135     , khtmlLineBreak(o.khtmlLineBreak)
136     , textSizeAdjust(o.textSizeAdjust)
137     , resize(o.resize)
138     , userSelect(o.userSelect)
139     , colorSpace(o.colorSpace)
140     , speak(o.speak)
141     , hyphens(o.hyphens)
142     , textEmphasisFill(o.textEmphasisFill)
143     , textEmphasisMark(o.textEmphasisMark)
144     , textEmphasisPosition(o.textEmphasisPosition)
145     , m_lineBoxContain(o.m_lineBoxContain)
146 #if ENABLE(CSS_IMAGE_ORIENTATION)
147     , m_imageOrientation(o.m_imageOrientation)
148 #endif
149     , m_imageRendering(o.m_imageRendering)
150     , m_lineSnap(o.m_lineSnap)
151     , m_lineAlign(o.m_lineAlign)
152 #if ENABLE(OVERFLOW_SCROLLING)
153     , useTouchOverflowScrolling(o.useTouchOverflowScrolling)
154 #endif
155 #if ENABLE(CSS_IMAGE_RESOLUTION)
156     , m_imageResolutionSource(o.m_imageResolutionSource)
157     , m_imageResolutionSnap(o.m_imageResolutionSnap)
158 #endif
159     , hyphenationString(o.hyphenationString)
160     , hyphenationLimitBefore(o.hyphenationLimitBefore)
161     , hyphenationLimitAfter(o.hyphenationLimitAfter)
162     , hyphenationLimitLines(o.hyphenationLimitLines)
163     , locale(o.locale)
164     , textEmphasisCustomMark(o.textEmphasisCustomMark)
165     , m_lineGrid(o.m_lineGrid)
166     , m_tabSize(o.m_tabSize)
167 #if ENABLE(CSS_IMAGE_RESOLUTION)
168     , m_imageResolution(o.m_imageResolution)
169 #endif
170 #if ENABLE(TOUCH_EVENTS)
171     , tapHighlightColor(o.tapHighlightColor)
172 #endif
173 #if ENABLE(CSS_VARIABLES)
174     , m_variables(o.m_variables)
175 #endif
176 {
177 }
178
179 StyleRareInheritedData::~StyleRareInheritedData()
180 {
181 }
182
183 static bool cursorDataEquivalent(const CursorList* c1, const CursorList* c2)
184 {
185     if (c1 == c2)
186         return true;
187     if ((!c1 && c2) || (c1 && !c2))
188         return false;
189     return (*c1 == *c2);
190 }
191
192 bool StyleRareInheritedData::operator==(const StyleRareInheritedData& o) const
193 {
194     return textStrokeColor == o.textStrokeColor
195         && textStrokeWidth == o.textStrokeWidth
196         && textFillColor == o.textFillColor
197         && textEmphasisColor == o.textEmphasisColor
198         && visitedLinkTextStrokeColor == o.visitedLinkTextStrokeColor
199         && visitedLinkTextFillColor == o.visitedLinkTextFillColor
200         && visitedLinkTextEmphasisColor == o.visitedLinkTextEmphasisColor
201 #if ENABLE(TOUCH_EVENTS)
202         && tapHighlightColor == o.tapHighlightColor
203 #endif
204         && shadowDataEquivalent(o)
205         && highlight == o.highlight
206         && cursorDataEquivalent(cursorData.get(), o.cursorData.get())
207         && indent == o.indent
208         && m_effectiveZoom == o.m_effectiveZoom
209         && widows == o.widows
210         && orphans == o.orphans
211         && textSecurity == o.textSecurity
212         && userModify == o.userModify
213         && wordBreak == o.wordBreak
214         && wordWrap == o.wordWrap
215         && nbspMode == o.nbspMode
216         && khtmlLineBreak == o.khtmlLineBreak
217 #if ENABLE(OVERFLOW_SCROLLING)
218         && useTouchOverflowScrolling == o.useTouchOverflowScrolling
219 #endif
220         && textSizeAdjust == o.textSizeAdjust
221         && resize == o.resize
222         && userSelect == o.userSelect
223         && colorSpace == o.colorSpace
224         && speak == o.speak
225         && hyphens == o.hyphens
226         && hyphenationLimitBefore == o.hyphenationLimitBefore
227         && hyphenationLimitAfter == o.hyphenationLimitAfter
228         && hyphenationLimitLines == o.hyphenationLimitLines
229         && textEmphasisFill == o.textEmphasisFill
230         && textEmphasisMark == o.textEmphasisMark
231         && textEmphasisPosition == o.textEmphasisPosition
232         && m_lineBoxContain == o.m_lineBoxContain
233         && hyphenationString == o.hyphenationString
234         && locale == o.locale
235         && textEmphasisCustomMark == o.textEmphasisCustomMark
236         && QuotesData::equals(quotes.get(), o.quotes.get())
237         && m_tabSize == o.m_tabSize
238         && m_lineGrid == o.m_lineGrid
239 #if ENABLE(CSS_IMAGE_ORIENTATION)
240         && m_imageOrientation == o.m_imageOrientation
241 #endif
242         && m_imageRendering == o.m_imageRendering
243 #if ENABLE(CSS_IMAGE_RESOLUTION)
244         && m_imageResolutionSource == o.m_imageResolutionSource
245         && m_imageResolutionSnap == o.m_imageResolutionSnap
246         && m_imageResolution == o.m_imageResolution
247 #endif
248         && m_lineSnap == o.m_lineSnap
249 #if ENABLE(CSS_VARIABLES)
250         && m_variables == o.m_variables
251 #endif
252         && m_lineAlign == o.m_lineAlign;
253 }
254
255 bool StyleRareInheritedData::shadowDataEquivalent(const StyleRareInheritedData& o) const
256 {
257     if ((!textShadow && o.textShadow) || (textShadow && !o.textShadow))
258         return false;
259     if (textShadow && o.textShadow && (*textShadow != *o.textShadow))
260         return false;
261     return true;
262 }
263
264 } // namespace WebCore