[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_boxShadow(o.m_boxShadow ? std::make_unique<ShadowData>(*o.m_boxShadow) : nullptr)
140     , m_boxReflect(o.m_boxReflect)
141     , m_animations(o.m_animations ? std::make_unique<AnimationList>(*o.m_animations) : nullptr)
142     , m_transitions(o.m_transitions ? std::make_unique<AnimationList>(*o.m_transitions) : nullptr)
143     , m_mask(o.m_mask)
144     , m_maskBoxImage(o.m_maskBoxImage)
145     , m_pageSize(o.m_pageSize)
146 #if ENABLE(CSS_SHAPES)
147     , m_shapeOutside(o.m_shapeOutside)
148     , m_shapeMargin(o.m_shapeMargin)
149     , m_shapeImageThreshold(o.m_shapeImageThreshold)
150 #endif
151     , m_clipPath(o.m_clipPath)
152     , m_textDecorationColor(o.m_textDecorationColor)
153     , m_visitedLinkTextDecorationColor(o.m_visitedLinkTextDecorationColor)
154     , m_visitedLinkBackgroundColor(o.m_visitedLinkBackgroundColor)
155     , m_visitedLinkOutlineColor(o.m_visitedLinkOutlineColor)
156     , m_visitedLinkBorderLeftColor(o.m_visitedLinkBorderLeftColor)
157     , m_visitedLinkBorderRightColor(o.m_visitedLinkBorderRightColor)
158     , m_visitedLinkBorderTopColor(o.m_visitedLinkBorderTopColor)
159     , m_visitedLinkBorderBottomColor(o.m_visitedLinkBorderBottomColor)
160     , m_order(o.m_order)
161     , m_flowThread(o.m_flowThread)
162     , m_regionThread(o.m_regionThread)
163 #if ENABLE(CSS_SCROLL_SNAP)
164     , m_scrollSnapType(o.m_scrollSnapType)
165 #endif
166     , m_regionFragment(o.m_regionFragment)
167     , m_regionBreakAfter(o.m_regionBreakAfter)
168     , m_regionBreakBefore(o.m_regionBreakBefore)
169     , m_regionBreakInside(o.m_regionBreakInside)
170     , m_pageSizeType(o.m_pageSizeType)
171     , m_transformStyle3D(o.m_transformStyle3D)
172     , m_backfaceVisibility(o.m_backfaceVisibility)
173     , m_alignContent(o.m_alignContent)
174     , m_alignItems(o.m_alignItems)
175     , m_alignItemsOverflowAlignment(o.m_alignItemsOverflowAlignment)
176     , m_alignSelf(o.m_alignSelf)
177     , m_alignSelfOverflowAlignment(o.m_alignSelfOverflowAlignment)
178     , m_justifyContent(o.m_justifyContent)
179     , m_justifySelf(o.m_justifySelf)
180     , m_justifySelfOverflowAlignment(o.m_justifySelfOverflowAlignment)
181     , userDrag(o.userDrag)
182     , textOverflow(o.textOverflow)
183     , marginBeforeCollapse(o.marginBeforeCollapse)
184     , marginAfterCollapse(o.marginAfterCollapse)
185     , m_appearance(o.m_appearance)
186     , m_borderFit(o.m_borderFit)
187     , m_textCombine(o.m_textCombine)
188     , m_textDecorationStyle(o.m_textDecorationStyle)
189     , m_runningAcceleratedAnimation(o.m_runningAcceleratedAnimation)
190     , m_aspectRatioType(o.m_aspectRatioType)
191 #if ENABLE(CSS_COMPOSITING)
192     , m_effectiveBlendMode(o.m_effectiveBlendMode)
193     , m_isolation(o.m_isolation)
194 #endif
195     , m_objectFit(o.m_objectFit)
196 {
197 }
198
199 PassRef<StyleRareNonInheritedData> StyleRareNonInheritedData::copy() const
200 {
201     return adoptRef(*new StyleRareNonInheritedData(*this));
202 }
203
204 StyleRareNonInheritedData::~StyleRareNonInheritedData()
205 {
206 }
207
208 bool StyleRareNonInheritedData::operator==(const StyleRareNonInheritedData& o) const
209 {
210     return opacity == o.opacity
211         && m_aspectRatioDenominator == o.m_aspectRatioDenominator
212         && m_aspectRatioNumerator == o.m_aspectRatioNumerator
213         && m_perspective == o.m_perspective
214         && m_perspectiveOriginX == o.m_perspectiveOriginX
215         && m_perspectiveOriginY == o.m_perspectiveOriginY
216         && lineClamp == o.lineClamp
217         && m_initialLetter == o.m_initialLetter
218 #if ENABLE(DASHBOARD_SUPPORT)
219         && m_dashboardRegions == o.m_dashboardRegions
220 #endif
221         && m_deprecatedFlexibleBox == o.m_deprecatedFlexibleBox
222         && m_flexibleBox == o.m_flexibleBox
223         && m_marquee == o.m_marquee
224         && m_multiCol == o.m_multiCol
225         && m_transform == o.m_transform
226         && m_filter == o.m_filter
227 #if ENABLE(FILTERS_LEVEL_2)
228         && m_backdropFilter == o.m_backdropFilter
229 #endif
230 #if ENABLE(CSS_GRID_LAYOUT)
231         && m_grid == o.m_grid
232         && m_gridItem == o.m_gridItem
233 #endif
234 #if ENABLE(CSS_SCROLL_SNAP)
235         && m_scrollSnapPoints == o.m_scrollSnapPoints
236 #endif
237         && contentDataEquivalent(o)
238         && counterDataEquivalent(o)
239         && shadowDataEquivalent(o)
240         && reflectionDataEquivalent(o)
241         && animationDataEquivalent(o)
242         && transitionDataEquivalent(o)
243         && m_mask == o.m_mask
244         && m_maskBoxImage == o.m_maskBoxImage
245         && m_pageSize == o.m_pageSize
246 #if ENABLE(CSS_SHAPES)
247         && m_shapeOutside == o.m_shapeOutside
248         && m_shapeMargin == o.m_shapeMargin
249         && m_shapeImageThreshold == o.m_shapeImageThreshold
250 #endif
251         && m_clipPath == o.m_clipPath
252         && m_textDecorationColor == o.m_textDecorationColor
253         && m_visitedLinkTextDecorationColor == o.m_visitedLinkTextDecorationColor
254         && m_visitedLinkBackgroundColor == o.m_visitedLinkBackgroundColor
255         && m_visitedLinkOutlineColor == o.m_visitedLinkOutlineColor
256         && m_visitedLinkBorderLeftColor == o.m_visitedLinkBorderLeftColor
257         && m_visitedLinkBorderRightColor == o.m_visitedLinkBorderRightColor
258         && m_visitedLinkBorderTopColor == o.m_visitedLinkBorderTopColor
259         && m_visitedLinkBorderBottomColor == o.m_visitedLinkBorderBottomColor
260         && m_order == o.m_order
261         && m_flowThread == o.m_flowThread
262         && m_regionThread == o.m_regionThread
263         && m_regionFragment == o.m_regionFragment
264         && m_regionBreakAfter == o.m_regionBreakAfter
265         && m_regionBreakBefore == o.m_regionBreakBefore
266         && m_regionBreakInside == o.m_regionBreakInside
267         && m_pageSizeType == o.m_pageSizeType
268         && m_transformStyle3D == o.m_transformStyle3D
269         && m_backfaceVisibility == o.m_backfaceVisibility
270         && m_alignContent == o.m_alignContent
271         && m_alignItems == o.m_alignItems
272         && m_alignItemsOverflowAlignment == o.m_alignItemsOverflowAlignment
273         && m_alignSelf == o.m_alignSelf
274         && m_alignSelfOverflowAlignment == o.m_alignSelfOverflowAlignment
275         && m_justifyContent == o.m_justifyContent
276         && userDrag == o.userDrag
277         && textOverflow == o.textOverflow
278         && marginBeforeCollapse == o.marginBeforeCollapse
279         && marginAfterCollapse == o.marginAfterCollapse
280         && m_appearance == o.m_appearance
281         && m_borderFit == o.m_borderFit
282         && m_textCombine == o.m_textCombine
283         && m_textDecorationStyle == o.m_textDecorationStyle
284 #if ENABLE(CSS_SCROLL_SNAP)
285         && m_scrollSnapType == o.m_scrollSnapType
286 #endif
287         && !m_runningAcceleratedAnimation && !o.m_runningAcceleratedAnimation
288 #if ENABLE(CSS_COMPOSITING)
289         && m_effectiveBlendMode == o.m_effectiveBlendMode
290         && m_isolation == o.m_isolation
291 #endif
292         && m_aspectRatioType == o.m_aspectRatioType
293         && m_objectFit == o.m_objectFit
294         && m_justifySelf == o.m_justifySelf
295         && m_justifySelfOverflowAlignment == o.m_justifySelfOverflowAlignment;
296 }
297
298 bool StyleRareNonInheritedData::contentDataEquivalent(const StyleRareNonInheritedData& o) const
299 {
300     ContentData* a = m_content.get();
301     ContentData* b = o.m_content.get();
302
303     while (a && b && *a == *b) {
304         a = a->next();
305         b = b->next();
306     }
307
308     return !a && !b;
309 }
310
311 bool StyleRareNonInheritedData::counterDataEquivalent(const StyleRareNonInheritedData& o) const
312 {
313     if (m_counterDirectives.get() == o.m_counterDirectives.get())
314         return true;
315         
316     if (m_counterDirectives && o.m_counterDirectives && *m_counterDirectives == *o.m_counterDirectives)
317         return true;
318
319     return false;
320 }
321
322 bool StyleRareNonInheritedData::shadowDataEquivalent(const StyleRareNonInheritedData& o) const
323 {
324     if ((!m_boxShadow && o.m_boxShadow) || (m_boxShadow && !o.m_boxShadow))
325         return false;
326     if (m_boxShadow && o.m_boxShadow && (*m_boxShadow != *o.m_boxShadow))
327         return false;
328     return true;
329 }
330
331 bool StyleRareNonInheritedData::reflectionDataEquivalent(const StyleRareNonInheritedData& o) const
332 {
333     if (m_boxReflect != o.m_boxReflect) {
334         if (!m_boxReflect || !o.m_boxReflect)
335             return false;
336         return *m_boxReflect == *o.m_boxReflect;
337     }
338     return true;
339 }
340
341 bool StyleRareNonInheritedData::animationDataEquivalent(const StyleRareNonInheritedData& o) const
342 {
343     if ((!m_animations && o.m_animations) || (m_animations && !o.m_animations))
344         return false;
345     if (m_animations && o.m_animations && (*m_animations != *o.m_animations))
346         return false;
347     return true;
348 }
349
350 bool StyleRareNonInheritedData::transitionDataEquivalent(const StyleRareNonInheritedData& o) const
351 {
352     if ((!m_transitions && o.m_transitions) || (m_transitions && !o.m_transitions))
353         return false;
354     if (m_transitions && o.m_transitions && (*m_transitions != *o.m_transitions))
355         return false;
356     return true;
357 }
358
359 bool StyleRareNonInheritedData::hasFilters() const
360 {
361     return m_filter.get() && !m_filter->m_operations.isEmpty();
362 }
363
364 #if ENABLE(FILTERS_LEVEL_2)
365 bool StyleRareNonInheritedData::hasBackdropFilters() const
366 {
367     return m_backdropFilter.get() && !m_backdropFilter->m_operations.isEmpty();
368 }
369 #endif
370
371 } // namespace WebCore