Add snap to css3-images image-resolution
[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     , m_imageRendering(RenderStyle::initialImageRendering())
85     , m_lineSnap(RenderStyle::initialLineSnap())
86     , m_lineAlign(RenderStyle::initialLineAlign())
87 #if ENABLE(OVERFLOW_SCROLLING)
88     , useTouchOverflowScrolling(RenderStyle::initialUseTouchOverflowScrolling())
89 #endif
90 #if ENABLE(CSS_IMAGE_RESOLUTION)
91     , m_imageResolutionSource(RenderStyle::initialImageResolutionSource())
92     , m_imageResolutionSnap(RenderStyle::initialImageResolutionSnap())
93 #endif
94     , hyphenationLimitBefore(-1)
95     , hyphenationLimitAfter(-1)
96     , hyphenationLimitLines(-1)
97     , m_lineGrid(RenderStyle::initialLineGrid())
98     , m_tabSize(RenderStyle::initialTabSize())
99 #if ENABLE(CSS_IMAGE_RESOLUTION)
100     , m_imageResolution(RenderStyle::initialImageResolution())
101 #endif
102 #if ENABLE(TOUCH_EVENTS)
103     , tapHighlightColor(RenderStyle::initialTapHighlightColor())
104 #endif    
105 {
106 #if ENABLE(CSS_VARIABLES)
107     m_variables.init();
108 #endif
109 }
110
111 StyleRareInheritedData::StyleRareInheritedData(const StyleRareInheritedData& o)
112     : RefCounted<StyleRareInheritedData>()
113     , textStrokeColor(o.textStrokeColor)
114     , textStrokeWidth(o.textStrokeWidth)
115     , textFillColor(o.textFillColor)
116     , textEmphasisColor(o.textEmphasisColor)
117     , visitedLinkTextStrokeColor(o.visitedLinkTextStrokeColor)
118     , visitedLinkTextFillColor(o.visitedLinkTextFillColor)
119     , visitedLinkTextEmphasisColor(o.visitedLinkTextEmphasisColor)
120     , textShadow(o.textShadow ? adoptPtr(new ShadowData(*o.textShadow)) : nullptr)
121     , highlight(o.highlight)
122     , cursorData(o.cursorData)
123     , indent(o.indent)
124     , m_effectiveZoom(o.m_effectiveZoom)
125     , widows(o.widows)
126     , orphans(o.orphans)
127     , textSecurity(o.textSecurity)
128     , userModify(o.userModify)
129     , wordBreak(o.wordBreak)
130     , wordWrap(o.wordWrap)
131     , nbspMode(o.nbspMode)
132     , khtmlLineBreak(o.khtmlLineBreak)
133     , textSizeAdjust(o.textSizeAdjust)
134     , resize(o.resize)
135     , userSelect(o.userSelect)
136     , colorSpace(o.colorSpace)
137     , speak(o.speak)
138     , hyphens(o.hyphens)
139     , textEmphasisFill(o.textEmphasisFill)
140     , textEmphasisMark(o.textEmphasisMark)
141     , textEmphasisPosition(o.textEmphasisPosition)
142     , m_lineBoxContain(o.m_lineBoxContain)
143     , m_imageRendering(o.m_imageRendering)
144     , m_lineSnap(o.m_lineSnap)
145     , m_lineAlign(o.m_lineAlign)
146 #if ENABLE(OVERFLOW_SCROLLING)
147     , useTouchOverflowScrolling(o.useTouchOverflowScrolling)
148 #endif
149 #if ENABLE(CSS_IMAGE_RESOLUTION)
150     , m_imageResolutionSource(o.m_imageResolutionSource)
151     , m_imageResolutionSnap(o.m_imageResolutionSnap)
152 #endif
153     , hyphenationString(o.hyphenationString)
154     , hyphenationLimitBefore(o.hyphenationLimitBefore)
155     , hyphenationLimitAfter(o.hyphenationLimitAfter)
156     , hyphenationLimitLines(o.hyphenationLimitLines)
157     , locale(o.locale)
158     , textEmphasisCustomMark(o.textEmphasisCustomMark)
159     , m_lineGrid(o.m_lineGrid)
160     , m_tabSize(o.m_tabSize)
161 #if ENABLE(CSS_IMAGE_RESOLUTION)
162     , m_imageResolution(o.m_imageResolution)
163 #endif
164 #if ENABLE(TOUCH_EVENTS)
165     , tapHighlightColor(o.tapHighlightColor)
166 #endif
167 #if ENABLE(CSS_VARIABLES)
168     , m_variables(o.m_variables)
169 #endif
170 {
171 }
172
173 StyleRareInheritedData::~StyleRareInheritedData()
174 {
175 }
176
177 static bool cursorDataEquivalent(const CursorList* c1, const CursorList* c2)
178 {
179     if (c1 == c2)
180         return true;
181     if ((!c1 && c2) || (c1 && !c2))
182         return false;
183     return (*c1 == *c2);
184 }
185
186 bool StyleRareInheritedData::operator==(const StyleRareInheritedData& o) const
187 {
188     return textStrokeColor == o.textStrokeColor
189         && textStrokeWidth == o.textStrokeWidth
190         && textFillColor == o.textFillColor
191         && textEmphasisColor == o.textEmphasisColor
192         && visitedLinkTextStrokeColor == o.visitedLinkTextStrokeColor
193         && visitedLinkTextFillColor == o.visitedLinkTextFillColor
194         && visitedLinkTextEmphasisColor == o.visitedLinkTextEmphasisColor
195 #if ENABLE(TOUCH_EVENTS)
196         && tapHighlightColor == o.tapHighlightColor
197 #endif
198         && shadowDataEquivalent(o)
199         && highlight == o.highlight
200         && cursorDataEquivalent(cursorData.get(), o.cursorData.get())
201         && indent == o.indent
202         && m_effectiveZoom == o.m_effectiveZoom
203         && widows == o.widows
204         && orphans == o.orphans
205         && textSecurity == o.textSecurity
206         && userModify == o.userModify
207         && wordBreak == o.wordBreak
208         && wordWrap == o.wordWrap
209         && nbspMode == o.nbspMode
210         && khtmlLineBreak == o.khtmlLineBreak
211 #if ENABLE(OVERFLOW_SCROLLING)
212         && useTouchOverflowScrolling == o.useTouchOverflowScrolling
213 #endif
214         && textSizeAdjust == o.textSizeAdjust
215         && resize == o.resize
216         && userSelect == o.userSelect
217         && colorSpace == o.colorSpace
218         && speak == o.speak
219         && hyphens == o.hyphens
220         && hyphenationLimitBefore == o.hyphenationLimitBefore
221         && hyphenationLimitAfter == o.hyphenationLimitAfter
222         && hyphenationLimitLines == o.hyphenationLimitLines
223         && textEmphasisFill == o.textEmphasisFill
224         && textEmphasisMark == o.textEmphasisMark
225         && textEmphasisPosition == o.textEmphasisPosition
226         && m_lineBoxContain == o.m_lineBoxContain
227         && hyphenationString == o.hyphenationString
228         && locale == o.locale
229         && textEmphasisCustomMark == o.textEmphasisCustomMark
230         && QuotesData::equal(quotes.get(), o.quotes.get())
231         && m_tabSize == o.m_tabSize
232         && m_lineGrid == o.m_lineGrid
233         && m_imageRendering == o.m_imageRendering
234 #if ENABLE(CSS_IMAGE_RESOLUTION)
235         && m_imageResolutionSource == o.m_imageResolutionSource
236         && m_imageResolutionSnap == o.m_imageResolutionSnap
237         && m_imageResolution == o.m_imageResolution
238 #endif
239         && m_lineSnap == o.m_lineSnap
240 #if ENABLE(CSS_VARIABLES)
241         && m_variables == o.m_variables
242 #endif
243         && m_lineAlign == o.m_lineAlign;
244 }
245
246 bool StyleRareInheritedData::shadowDataEquivalent(const StyleRareInheritedData& o) const
247 {
248     if ((!textShadow && o.textShadow) || (textShadow && !o.textShadow))
249         return false;
250     if (textShadow && o.textShadow && (*textShadow != *o.textShadow))
251         return false;
252     return true;
253 }
254
255 } // namespace WebCore