[CSS Grid Layout] Upgrade align-self and align-items parsing to CSS 3
[WebKit-https.git] / Source / WebCore / rendering / style / StyleRareNonInheritedData.cpp
1 /*
2  * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
3  * Copyright (C) 2004, 2005, 2006, 2007, 2008 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 "StyleRareNonInheritedData.h"
24
25 #include "ContentData.h"
26 #include "RenderCounter.h"
27 #include "RenderStyle.h"
28 #include "ShadowData.h"
29 #include "StyleFilterData.h"
30 #include "StyleTransformData.h"
31 #include "StyleImage.h"
32 #include "StyleResolver.h"
33 #include "StyleScrollSnapPoints.h"
34
35 namespace WebCore {
36
37 StyleRareNonInheritedData::StyleRareNonInheritedData()
38     : opacity(RenderStyle::initialOpacity())
39     , m_aspectRatioDenominator(RenderStyle::initialAspectRatioDenominator())
40     , m_aspectRatioNumerator(RenderStyle::initialAspectRatioNumerator())
41     , m_perspective(RenderStyle::initialPerspective())
42     , m_perspectiveOriginX(RenderStyle::initialPerspectiveOriginX())
43     , m_perspectiveOriginY(RenderStyle::initialPerspectiveOriginY())
44     , lineClamp(RenderStyle::initialLineClamp())
45     , m_initialLetter(RenderStyle::initialInitialLetter())
46     , m_deprecatedFlexibleBox(StyleDeprecatedFlexibleBoxData::create())
47     , m_flexibleBox(StyleFlexibleBoxData::create())
48     , m_marquee(StyleMarqueeData::create())
49     , m_multiCol(StyleMultiColData::create())
50     , m_transform(StyleTransformData::create())
51     , m_filter(StyleFilterData::create())
52 #if ENABLE(FILTERS_LEVEL_2)
53     , m_backdropFilter(StyleFilterData::create())
54 #endif
55 #if ENABLE(CSS_GRID_LAYOUT)
56     , m_grid(StyleGridData::create())
57     , m_gridItem(StyleGridItemData::create())
58 #endif
59 #if ENABLE(CSS_SCROLL_SNAP)
60     , m_scrollSnapPoints(StyleScrollSnapPoints::create())
61 #endif
62     , m_mask(FillLayer(MaskFillLayer))
63     , m_pageSize()
64 #if ENABLE(CSS_SHAPES)
65     , m_shapeOutside(RenderStyle::initialShapeOutside())
66     , m_shapeMargin(RenderStyle::initialShapeMargin())
67     , m_shapeImageThreshold(RenderStyle::initialShapeImageThreshold())
68 #endif
69     , m_clipPath(RenderStyle::initialClipPath())
70     , m_visitedLinkBackgroundColor(RenderStyle::initialBackgroundColor())
71     , m_order(RenderStyle::initialOrder())
72     , m_flowThread(RenderStyle::initialFlowThread())
73     , m_regionThread(RenderStyle::initialRegionThread())
74 #if ENABLE(CSS_SCROLL_SNAP)
75     , m_scrollSnapType(static_cast<unsigned>(RenderStyle::initialScrollSnapType()))
76 #endif
77     , m_regionFragment(RenderStyle::initialRegionFragment())
78     , m_regionBreakAfter(RenderStyle::initialPageBreak())
79     , m_regionBreakBefore(RenderStyle::initialPageBreak())
80     , m_regionBreakInside(RenderStyle::initialPageBreak())
81     , m_pageSizeType(PAGE_SIZE_AUTO)
82     , m_transformStyle3D(RenderStyle::initialTransformStyle3D())
83     , m_backfaceVisibility(RenderStyle::initialBackfaceVisibility())
84     , m_alignContent(RenderStyle::initialAlignContent())
85     , m_alignItems(RenderStyle::initialAlignItems())
86     , m_alignItemsOverflowAlignment(RenderStyle::initialAlignItemsOverflowAlignment())
87     , m_alignSelf(RenderStyle::initialAlignSelf())
88     , m_alignSelfOverflowAlignment(RenderStyle::initialAlignSelfOverflowAlignment())
89     , m_justifyContent(RenderStyle::initialJustifyContent())
90     , m_justifySelf(RenderStyle::initialJustifySelf())
91     , m_justifySelfOverflowAlignment(RenderStyle::initialJustifySelfOverflowAlignment())
92     , userDrag(RenderStyle::initialUserDrag())
93     , textOverflow(RenderStyle::initialTextOverflow())
94     , marginBeforeCollapse(MCOLLAPSE)
95     , marginAfterCollapse(MCOLLAPSE)
96     , m_appearance(RenderStyle::initialAppearance())
97     , m_borderFit(RenderStyle::initialBorderFit())
98     , m_textCombine(RenderStyle::initialTextCombine())
99     , m_textDecorationStyle(RenderStyle::initialTextDecorationStyle())
100     , m_runningAcceleratedAnimation(false)
101     , m_aspectRatioType(RenderStyle::initialAspectRatioType())
102 #if ENABLE(CSS_COMPOSITING)
103     , m_effectiveBlendMode(RenderStyle::initialBlendMode())
104     , m_isolation(RenderStyle::initialIsolation())
105 #endif
106     , m_objectFit(RenderStyle::initialObjectFit())
107 {
108     m_maskBoxImage.setMaskDefaults();
109 }
110
111 inline StyleRareNonInheritedData::StyleRareNonInheritedData(const StyleRareNonInheritedData& o)
112     : RefCounted<StyleRareNonInheritedData>()
113     , opacity(o.opacity)
114     , m_aspectRatioDenominator(o.m_aspectRatioDenominator)
115     , m_aspectRatioNumerator(o.m_aspectRatioNumerator)
116     , m_perspective(o.m_perspective)
117     , m_perspectiveOriginX(o.m_perspectiveOriginX)
118     , m_perspectiveOriginY(o.m_perspectiveOriginY)
119     , lineClamp(o.lineClamp)
120     , m_initialLetter(o.m_initialLetter)
121     , m_deprecatedFlexibleBox(o.m_deprecatedFlexibleBox)
122     , m_flexibleBox(o.m_flexibleBox)
123     , m_marquee(o.m_marquee)
124     , m_multiCol(o.m_multiCol)
125     , m_transform(o.m_transform)
126     , m_filter(o.m_filter)
127 #if ENABLE(FILTERS_LEVEL_2)
128     , m_backdropFilter(o.m_backdropFilter)
129 #endif
130 #if ENABLE(CSS_GRID_LAYOUT)
131     , m_grid(o.m_grid)
132     , m_gridItem(o.m_gridItem)
133 #endif
134 #if ENABLE(CSS_SCROLL_SNAP)
135     , m_scrollSnapPoints(o.m_scrollSnapPoints)
136 #endif
137     , m_content(o.m_content ? o.m_content->clone() : nullptr)
138     , m_counterDirectives(o.m_counterDirectives ? clone(*o.m_counterDirectives) : nullptr)
139     , m_altText(o.m_altText)
140     , m_boxShadow(o.m_boxShadow ? std::make_unique<ShadowData>(*o.m_boxShadow) : nullptr)
141     , m_boxReflect(o.m_boxReflect)
142     , m_animations(o.m_animations ? std::make_unique<AnimationList>(*o.m_animations) : nullptr)
143     , m_transitions(o.m_transitions ? std::make_unique<AnimationList>(*o.m_transitions) : nullptr)
144     , m_mask(o.m_mask)
145     , m_maskBoxImage(o.m_maskBoxImage)
146     , m_pageSize(o.m_pageSize)
147 #if ENABLE(CSS_SHAPES)
148     , m_shapeOutside(o.m_shapeOutside)
149     , m_shapeMargin(o.m_shapeMargin)
150     , m_shapeImageThreshold(o.m_shapeImageThreshold)
151 #endif
152     , m_clipPath(o.m_clipPath)
153     , m_textDecorationColor(o.m_textDecorationColor)
154     , m_visitedLinkTextDecorationColor(o.m_visitedLinkTextDecorationColor)
155     , m_visitedLinkBackgroundColor(o.m_visitedLinkBackgroundColor)
156     , m_visitedLinkOutlineColor(o.m_visitedLinkOutlineColor)
157     , m_visitedLinkBorderLeftColor(o.m_visitedLinkBorderLeftColor)
158     , m_visitedLinkBorderRightColor(o.m_visitedLinkBorderRightColor)
159     , m_visitedLinkBorderTopColor(o.m_visitedLinkBorderTopColor)
160     , m_visitedLinkBorderBottomColor(o.m_visitedLinkBorderBottomColor)
161     , m_order(o.m_order)
162     , m_flowThread(o.m_flowThread)
163     , m_regionThread(o.m_regionThread)
164 #if ENABLE(CSS_SCROLL_SNAP)
165     , m_scrollSnapType(o.m_scrollSnapType)
166 #endif
167     , m_regionFragment(o.m_regionFragment)
168     , m_regionBreakAfter(o.m_regionBreakAfter)
169     , m_regionBreakBefore(o.m_regionBreakBefore)
170     , m_regionBreakInside(o.m_regionBreakInside)
171     , m_pageSizeType(o.m_pageSizeType)
172     , m_transformStyle3D(o.m_transformStyle3D)
173     , m_backfaceVisibility(o.m_backfaceVisibility)
174     , m_alignContent(o.m_alignContent)
175     , m_alignItems(o.m_alignItems)
176     , m_alignItemsOverflowAlignment(o.m_alignItemsOverflowAlignment)
177     , m_alignSelf(o.m_alignSelf)
178     , m_alignSelfOverflowAlignment(o.m_alignSelfOverflowAlignment)
179     , m_justifyContent(o.m_justifyContent)
180     , m_justifySelf(o.m_justifySelf)
181     , m_justifySelfOverflowAlignment(o.m_justifySelfOverflowAlignment)
182     , userDrag(o.userDrag)
183     , textOverflow(o.textOverflow)
184     , marginBeforeCollapse(o.marginBeforeCollapse)
185     , marginAfterCollapse(o.marginAfterCollapse)
186     , m_appearance(o.m_appearance)
187     , m_borderFit(o.m_borderFit)
188     , m_textCombine(o.m_textCombine)
189     , m_textDecorationStyle(o.m_textDecorationStyle)
190     , m_runningAcceleratedAnimation(o.m_runningAcceleratedAnimation)
191     , m_aspectRatioType(o.m_aspectRatioType)
192 #if ENABLE(CSS_COMPOSITING)
193     , m_effectiveBlendMode(o.m_effectiveBlendMode)
194     , m_isolation(o.m_isolation)
195 #endif
196     , m_objectFit(o.m_objectFit)
197 {
198 }
199
200 Ref<StyleRareNonInheritedData> StyleRareNonInheritedData::copy() const
201 {
202     return adoptRef(*new StyleRareNonInheritedData(*this));
203 }
204
205 StyleRareNonInheritedData::~StyleRareNonInheritedData()
206 {
207 }
208
209 bool StyleRareNonInheritedData::operator==(const StyleRareNonInheritedData& o) const
210 {
211     return opacity == o.opacity
212         && m_aspectRatioDenominator == o.m_aspectRatioDenominator
213         && m_aspectRatioNumerator == o.m_aspectRatioNumerator
214         && m_perspective == o.m_perspective
215         && m_perspectiveOriginX == o.m_perspectiveOriginX
216         && m_perspectiveOriginY == o.m_perspectiveOriginY
217         && lineClamp == o.lineClamp
218         && m_initialLetter == o.m_initialLetter
219 #if ENABLE(DASHBOARD_SUPPORT)
220         && m_dashboardRegions == o.m_dashboardRegions
221 #endif
222         && m_deprecatedFlexibleBox == o.m_deprecatedFlexibleBox
223         && m_flexibleBox == o.m_flexibleBox
224         && m_marquee == o.m_marquee
225         && m_multiCol == o.m_multiCol
226         && m_transform == o.m_transform
227         && m_filter == o.m_filter
228 #if ENABLE(FILTERS_LEVEL_2)
229         && m_backdropFilter == o.m_backdropFilter
230 #endif
231 #if ENABLE(CSS_GRID_LAYOUT)
232         && m_grid == o.m_grid
233         && m_gridItem == o.m_gridItem
234 #endif
235 #if ENABLE(CSS_SCROLL_SNAP)
236         && m_scrollSnapPoints == o.m_scrollSnapPoints
237 #endif
238         && contentDataEquivalent(o)
239         && counterDataEquivalent(o)
240         && shadowDataEquivalent(o)
241         && reflectionDataEquivalent(o)
242         && animationDataEquivalent(o)
243         && transitionDataEquivalent(o)
244         && m_mask == o.m_mask
245         && m_maskBoxImage == o.m_maskBoxImage
246         && m_pageSize == o.m_pageSize
247 #if ENABLE(CSS_SHAPES)
248         && m_shapeOutside == o.m_shapeOutside
249         && m_shapeMargin == o.m_shapeMargin
250         && m_shapeImageThreshold == o.m_shapeImageThreshold
251 #endif
252         && m_clipPath == o.m_clipPath
253         && m_textDecorationColor == o.m_textDecorationColor
254         && m_visitedLinkTextDecorationColor == o.m_visitedLinkTextDecorationColor
255         && m_visitedLinkBackgroundColor == o.m_visitedLinkBackgroundColor
256         && m_visitedLinkOutlineColor == o.m_visitedLinkOutlineColor
257         && m_visitedLinkBorderLeftColor == o.m_visitedLinkBorderLeftColor
258         && m_visitedLinkBorderRightColor == o.m_visitedLinkBorderRightColor
259         && m_visitedLinkBorderTopColor == o.m_visitedLinkBorderTopColor
260         && m_visitedLinkBorderBottomColor == o.m_visitedLinkBorderBottomColor
261         && m_order == o.m_order
262         && m_flowThread == o.m_flowThread
263         && m_regionThread == o.m_regionThread
264         && m_regionFragment == o.m_regionFragment
265         && m_regionBreakAfter == o.m_regionBreakAfter
266         && m_regionBreakBefore == o.m_regionBreakBefore
267         && m_regionBreakInside == o.m_regionBreakInside
268         && m_pageSizeType == o.m_pageSizeType
269         && m_transformStyle3D == o.m_transformStyle3D
270         && m_backfaceVisibility == o.m_backfaceVisibility
271         && m_alignContent == o.m_alignContent
272         && m_alignItems == o.m_alignItems
273         && m_alignItemsOverflowAlignment == o.m_alignItemsOverflowAlignment
274         && m_alignSelf == o.m_alignSelf
275         && m_alignSelfOverflowAlignment == o.m_alignSelfOverflowAlignment
276         && m_justifyContent == o.m_justifyContent
277         && userDrag == o.userDrag
278         && textOverflow == o.textOverflow
279         && marginBeforeCollapse == o.marginBeforeCollapse
280         && marginAfterCollapse == o.marginAfterCollapse
281         && m_appearance == o.m_appearance
282         && m_borderFit == o.m_borderFit
283         && m_textCombine == o.m_textCombine
284         && m_textDecorationStyle == o.m_textDecorationStyle
285 #if ENABLE(CSS_SCROLL_SNAP)
286         && m_scrollSnapType == o.m_scrollSnapType
287 #endif
288         && !m_runningAcceleratedAnimation && !o.m_runningAcceleratedAnimation
289 #if ENABLE(CSS_COMPOSITING)
290         && m_effectiveBlendMode == o.m_effectiveBlendMode
291         && m_isolation == o.m_isolation
292 #endif
293         && m_aspectRatioType == o.m_aspectRatioType
294         && m_objectFit == o.m_objectFit
295         && m_justifySelf == o.m_justifySelf
296         && m_justifySelfOverflowAlignment == o.m_justifySelfOverflowAlignment;
297 }
298
299 bool StyleRareNonInheritedData::contentDataEquivalent(const StyleRareNonInheritedData& o) const
300 {
301     ContentData* a = m_content.get();
302     ContentData* b = o.m_content.get();
303
304     while (a && b && *a == *b) {
305         a = a->next();
306         b = b->next();
307     }
308
309     return !a && !b;
310 }
311
312 bool StyleRareNonInheritedData::counterDataEquivalent(const StyleRareNonInheritedData& o) const
313 {
314     if (m_counterDirectives.get() == o.m_counterDirectives.get())
315         return true;
316         
317     if (m_counterDirectives && o.m_counterDirectives && *m_counterDirectives == *o.m_counterDirectives)
318         return true;
319
320     return false;
321 }
322
323 bool StyleRareNonInheritedData::shadowDataEquivalent(const StyleRareNonInheritedData& o) const
324 {
325     if ((!m_boxShadow && o.m_boxShadow) || (m_boxShadow && !o.m_boxShadow))
326         return false;
327     if (m_boxShadow && o.m_boxShadow && (*m_boxShadow != *o.m_boxShadow))
328         return false;
329     return true;
330 }
331
332 bool StyleRareNonInheritedData::reflectionDataEquivalent(const StyleRareNonInheritedData& o) const
333 {
334     if (m_boxReflect != o.m_boxReflect) {
335         if (!m_boxReflect || !o.m_boxReflect)
336             return false;
337         return *m_boxReflect == *o.m_boxReflect;
338     }
339     return true;
340 }
341
342 bool StyleRareNonInheritedData::animationDataEquivalent(const StyleRareNonInheritedData& o) const
343 {
344     if ((!m_animations && o.m_animations) || (m_animations && !o.m_animations))
345         return false;
346     if (m_animations && o.m_animations && (*m_animations != *o.m_animations))
347         return false;
348     return true;
349 }
350
351 bool StyleRareNonInheritedData::transitionDataEquivalent(const StyleRareNonInheritedData& o) const
352 {
353     if ((!m_transitions && o.m_transitions) || (m_transitions && !o.m_transitions))
354         return false;
355     if (m_transitions && o.m_transitions && (*m_transitions != *o.m_transitions))
356         return false;
357     return true;
358 }
359
360 bool StyleRareNonInheritedData::hasFilters() const
361 {
362     return m_filter.get() && !m_filter->m_operations.isEmpty();
363 }
364
365 #if ENABLE(FILTERS_LEVEL_2)
366 bool StyleRareNonInheritedData::hasBackdropFilters() const
367 {
368     return m_backdropFilter.get() && !m_backdropFilter->m_operations.isEmpty();
369 }
370 #endif
371
372 } // namespace WebCore