[CSS Grid Layout] Implement justify-self and justify-item css properties.
[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_justifyItems(RenderStyle::initialJustifyItems())
91     , m_justifyItemsOverflowAlignment(RenderStyle::initialJustifyItemsOverflowAlignment())
92     , m_justifyItemsPositionType(NonLegacyPosition)
93     , m_justifySelf(RenderStyle::initialJustifySelf())
94     , m_justifySelfOverflowAlignment(RenderStyle::initialJustifySelfOverflowAlignment())
95     , userDrag(RenderStyle::initialUserDrag())
96     , textOverflow(RenderStyle::initialTextOverflow())
97     , marginBeforeCollapse(MCOLLAPSE)
98     , marginAfterCollapse(MCOLLAPSE)
99     , m_appearance(RenderStyle::initialAppearance())
100     , m_borderFit(RenderStyle::initialBorderFit())
101     , m_textCombine(RenderStyle::initialTextCombine())
102     , m_textDecorationStyle(RenderStyle::initialTextDecorationStyle())
103     , m_runningAcceleratedAnimation(false)
104     , m_aspectRatioType(RenderStyle::initialAspectRatioType())
105 #if ENABLE(CSS_COMPOSITING)
106     , m_effectiveBlendMode(RenderStyle::initialBlendMode())
107     , m_isolation(RenderStyle::initialIsolation())
108 #endif
109     , m_objectFit(RenderStyle::initialObjectFit())
110 {
111     m_maskBoxImage.setMaskDefaults();
112 }
113
114 inline StyleRareNonInheritedData::StyleRareNonInheritedData(const StyleRareNonInheritedData& o)
115     : RefCounted<StyleRareNonInheritedData>()
116     , opacity(o.opacity)
117     , m_aspectRatioDenominator(o.m_aspectRatioDenominator)
118     , m_aspectRatioNumerator(o.m_aspectRatioNumerator)
119     , m_perspective(o.m_perspective)
120     , m_perspectiveOriginX(o.m_perspectiveOriginX)
121     , m_perspectiveOriginY(o.m_perspectiveOriginY)
122     , lineClamp(o.lineClamp)
123     , m_initialLetter(o.m_initialLetter)
124     , m_deprecatedFlexibleBox(o.m_deprecatedFlexibleBox)
125     , m_flexibleBox(o.m_flexibleBox)
126     , m_marquee(o.m_marquee)
127     , m_multiCol(o.m_multiCol)
128     , m_transform(o.m_transform)
129     , m_filter(o.m_filter)
130 #if ENABLE(FILTERS_LEVEL_2)
131     , m_backdropFilter(o.m_backdropFilter)
132 #endif
133 #if ENABLE(CSS_GRID_LAYOUT)
134     , m_grid(o.m_grid)
135     , m_gridItem(o.m_gridItem)
136 #endif
137 #if ENABLE(CSS_SCROLL_SNAP)
138     , m_scrollSnapPoints(o.m_scrollSnapPoints)
139 #endif
140     , m_content(o.m_content ? o.m_content->clone() : nullptr)
141     , m_counterDirectives(o.m_counterDirectives ? clone(*o.m_counterDirectives) : nullptr)
142     , m_altText(o.m_altText)
143     , m_boxShadow(o.m_boxShadow ? std::make_unique<ShadowData>(*o.m_boxShadow) : nullptr)
144     , m_boxReflect(o.m_boxReflect)
145     , m_animations(o.m_animations ? std::make_unique<AnimationList>(*o.m_animations) : nullptr)
146     , m_transitions(o.m_transitions ? std::make_unique<AnimationList>(*o.m_transitions) : nullptr)
147     , m_mask(o.m_mask)
148     , m_maskBoxImage(o.m_maskBoxImage)
149     , m_pageSize(o.m_pageSize)
150 #if ENABLE(CSS_SHAPES)
151     , m_shapeOutside(o.m_shapeOutside)
152     , m_shapeMargin(o.m_shapeMargin)
153     , m_shapeImageThreshold(o.m_shapeImageThreshold)
154 #endif
155     , m_clipPath(o.m_clipPath)
156     , m_textDecorationColor(o.m_textDecorationColor)
157     , m_visitedLinkTextDecorationColor(o.m_visitedLinkTextDecorationColor)
158     , m_visitedLinkBackgroundColor(o.m_visitedLinkBackgroundColor)
159     , m_visitedLinkOutlineColor(o.m_visitedLinkOutlineColor)
160     , m_visitedLinkBorderLeftColor(o.m_visitedLinkBorderLeftColor)
161     , m_visitedLinkBorderRightColor(o.m_visitedLinkBorderRightColor)
162     , m_visitedLinkBorderTopColor(o.m_visitedLinkBorderTopColor)
163     , m_visitedLinkBorderBottomColor(o.m_visitedLinkBorderBottomColor)
164     , m_order(o.m_order)
165     , m_flowThread(o.m_flowThread)
166     , m_regionThread(o.m_regionThread)
167 #if ENABLE(CSS_SCROLL_SNAP)
168     , m_scrollSnapType(o.m_scrollSnapType)
169 #endif
170     , m_regionFragment(o.m_regionFragment)
171     , m_regionBreakAfter(o.m_regionBreakAfter)
172     , m_regionBreakBefore(o.m_regionBreakBefore)
173     , m_regionBreakInside(o.m_regionBreakInside)
174     , m_pageSizeType(o.m_pageSizeType)
175     , m_transformStyle3D(o.m_transformStyle3D)
176     , m_backfaceVisibility(o.m_backfaceVisibility)
177     , m_alignContent(o.m_alignContent)
178     , m_alignItems(o.m_alignItems)
179     , m_alignItemsOverflowAlignment(o.m_alignItemsOverflowAlignment)
180     , m_alignSelf(o.m_alignSelf)
181     , m_alignSelfOverflowAlignment(o.m_alignSelfOverflowAlignment)
182     , m_justifyContent(o.m_justifyContent)
183     , m_justifyItems(o.m_justifyItems)
184     , m_justifyItemsOverflowAlignment(o.m_justifyItemsOverflowAlignment)
185     , m_justifyItemsPositionType(o.m_justifyItemsPositionType)
186     , m_justifySelf(o.m_justifySelf)
187     , m_justifySelfOverflowAlignment(o.m_justifySelfOverflowAlignment)
188     , userDrag(o.userDrag)
189     , textOverflow(o.textOverflow)
190     , marginBeforeCollapse(o.marginBeforeCollapse)
191     , marginAfterCollapse(o.marginAfterCollapse)
192     , m_appearance(o.m_appearance)
193     , m_borderFit(o.m_borderFit)
194     , m_textCombine(o.m_textCombine)
195     , m_textDecorationStyle(o.m_textDecorationStyle)
196     , m_runningAcceleratedAnimation(o.m_runningAcceleratedAnimation)
197     , m_aspectRatioType(o.m_aspectRatioType)
198 #if ENABLE(CSS_COMPOSITING)
199     , m_effectiveBlendMode(o.m_effectiveBlendMode)
200     , m_isolation(o.m_isolation)
201 #endif
202     , m_objectFit(o.m_objectFit)
203 {
204 }
205
206 Ref<StyleRareNonInheritedData> StyleRareNonInheritedData::copy() const
207 {
208     return adoptRef(*new StyleRareNonInheritedData(*this));
209 }
210
211 StyleRareNonInheritedData::~StyleRareNonInheritedData()
212 {
213 }
214
215 bool StyleRareNonInheritedData::operator==(const StyleRareNonInheritedData& o) const
216 {
217     return opacity == o.opacity
218         && m_aspectRatioDenominator == o.m_aspectRatioDenominator
219         && m_aspectRatioNumerator == o.m_aspectRatioNumerator
220         && m_perspective == o.m_perspective
221         && m_perspectiveOriginX == o.m_perspectiveOriginX
222         && m_perspectiveOriginY == o.m_perspectiveOriginY
223         && lineClamp == o.lineClamp
224         && m_initialLetter == o.m_initialLetter
225 #if ENABLE(DASHBOARD_SUPPORT)
226         && m_dashboardRegions == o.m_dashboardRegions
227 #endif
228         && m_deprecatedFlexibleBox == o.m_deprecatedFlexibleBox
229         && m_flexibleBox == o.m_flexibleBox
230         && m_marquee == o.m_marquee
231         && m_multiCol == o.m_multiCol
232         && m_transform == o.m_transform
233         && m_filter == o.m_filter
234 #if ENABLE(FILTERS_LEVEL_2)
235         && m_backdropFilter == o.m_backdropFilter
236 #endif
237 #if ENABLE(CSS_GRID_LAYOUT)
238         && m_grid == o.m_grid
239         && m_gridItem == o.m_gridItem
240 #endif
241 #if ENABLE(CSS_SCROLL_SNAP)
242         && m_scrollSnapPoints == o.m_scrollSnapPoints
243 #endif
244         && contentDataEquivalent(o)
245         && counterDataEquivalent(o)
246         && shadowDataEquivalent(o)
247         && reflectionDataEquivalent(o)
248         && animationDataEquivalent(o)
249         && transitionDataEquivalent(o)
250         && m_mask == o.m_mask
251         && m_maskBoxImage == o.m_maskBoxImage
252         && m_pageSize == o.m_pageSize
253 #if ENABLE(CSS_SHAPES)
254         && m_shapeOutside == o.m_shapeOutside
255         && m_shapeMargin == o.m_shapeMargin
256         && m_shapeImageThreshold == o.m_shapeImageThreshold
257 #endif
258         && m_clipPath == o.m_clipPath
259         && m_textDecorationColor == o.m_textDecorationColor
260         && m_visitedLinkTextDecorationColor == o.m_visitedLinkTextDecorationColor
261         && m_visitedLinkBackgroundColor == o.m_visitedLinkBackgroundColor
262         && m_visitedLinkOutlineColor == o.m_visitedLinkOutlineColor
263         && m_visitedLinkBorderLeftColor == o.m_visitedLinkBorderLeftColor
264         && m_visitedLinkBorderRightColor == o.m_visitedLinkBorderRightColor
265         && m_visitedLinkBorderTopColor == o.m_visitedLinkBorderTopColor
266         && m_visitedLinkBorderBottomColor == o.m_visitedLinkBorderBottomColor
267         && m_order == o.m_order
268         && m_flowThread == o.m_flowThread
269         && m_regionThread == o.m_regionThread
270         && m_regionFragment == o.m_regionFragment
271         && m_regionBreakAfter == o.m_regionBreakAfter
272         && m_regionBreakBefore == o.m_regionBreakBefore
273         && m_regionBreakInside == o.m_regionBreakInside
274         && m_pageSizeType == o.m_pageSizeType
275         && m_transformStyle3D == o.m_transformStyle3D
276         && m_backfaceVisibility == o.m_backfaceVisibility
277         && m_alignContent == o.m_alignContent
278         && m_alignItems == o.m_alignItems
279         && m_alignItemsOverflowAlignment == o.m_alignItemsOverflowAlignment
280         && m_alignSelf == o.m_alignSelf
281         && m_alignSelfOverflowAlignment == o.m_alignSelfOverflowAlignment
282         && m_justifyContent == o.m_justifyContent
283         && userDrag == o.userDrag
284         && textOverflow == o.textOverflow
285         && marginBeforeCollapse == o.marginBeforeCollapse
286         && marginAfterCollapse == o.marginAfterCollapse
287         && m_appearance == o.m_appearance
288         && m_borderFit == o.m_borderFit
289         && m_textCombine == o.m_textCombine
290         && m_textDecorationStyle == o.m_textDecorationStyle
291 #if ENABLE(CSS_SCROLL_SNAP)
292         && m_scrollSnapType == o.m_scrollSnapType
293 #endif
294         && !m_runningAcceleratedAnimation && !o.m_runningAcceleratedAnimation
295 #if ENABLE(CSS_COMPOSITING)
296         && m_effectiveBlendMode == o.m_effectiveBlendMode
297         && m_isolation == o.m_isolation
298 #endif
299         && m_aspectRatioType == o.m_aspectRatioType
300         && m_objectFit == o.m_objectFit
301         && m_justifyItems == o.m_justifyItems
302         && m_justifyItemsOverflowAlignment == o.m_justifyItemsOverflowAlignment
303         && m_justifyItemsPositionType == o.m_justifyItemsPositionType
304         && m_justifySelf == o.m_justifySelf
305         && m_justifySelfOverflowAlignment == o.m_justifySelfOverflowAlignment;
306 }
307
308 bool StyleRareNonInheritedData::contentDataEquivalent(const StyleRareNonInheritedData& o) const
309 {
310     ContentData* a = m_content.get();
311     ContentData* b = o.m_content.get();
312
313     while (a && b && *a == *b) {
314         a = a->next();
315         b = b->next();
316     }
317
318     return !a && !b;
319 }
320
321 bool StyleRareNonInheritedData::counterDataEquivalent(const StyleRareNonInheritedData& o) const
322 {
323     if (m_counterDirectives.get() == o.m_counterDirectives.get())
324         return true;
325         
326     if (m_counterDirectives && o.m_counterDirectives && *m_counterDirectives == *o.m_counterDirectives)
327         return true;
328
329     return false;
330 }
331
332 bool StyleRareNonInheritedData::shadowDataEquivalent(const StyleRareNonInheritedData& o) const
333 {
334     if ((!m_boxShadow && o.m_boxShadow) || (m_boxShadow && !o.m_boxShadow))
335         return false;
336     if (m_boxShadow && o.m_boxShadow && (*m_boxShadow != *o.m_boxShadow))
337         return false;
338     return true;
339 }
340
341 bool StyleRareNonInheritedData::reflectionDataEquivalent(const StyleRareNonInheritedData& o) const
342 {
343     if (m_boxReflect != o.m_boxReflect) {
344         if (!m_boxReflect || !o.m_boxReflect)
345             return false;
346         return *m_boxReflect == *o.m_boxReflect;
347     }
348     return true;
349 }
350
351 bool StyleRareNonInheritedData::animationDataEquivalent(const StyleRareNonInheritedData& o) const
352 {
353     if ((!m_animations && o.m_animations) || (m_animations && !o.m_animations))
354         return false;
355     if (m_animations && o.m_animations && (*m_animations != *o.m_animations))
356         return false;
357     return true;
358 }
359
360 bool StyleRareNonInheritedData::transitionDataEquivalent(const StyleRareNonInheritedData& o) const
361 {
362     if ((!m_transitions && o.m_transitions) || (m_transitions && !o.m_transitions))
363         return false;
364     if (m_transitions && o.m_transitions && (*m_transitions != *o.m_transitions))
365         return false;
366     return true;
367 }
368
369 bool StyleRareNonInheritedData::hasFilters() const
370 {
371     return m_filter.get() && !m_filter->m_operations.isEmpty();
372 }
373
374 #if ENABLE(FILTERS_LEVEL_2)
375 bool StyleRareNonInheritedData::hasBackdropFilters() const
376 {
377     return m_backdropFilter.get() && !m_backdropFilter->m_operations.isEmpty();
378 }
379 #endif
380
381 } // namespace WebCore