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