Implement the updated port/area-based Scroll Snap Module Level 1 Spec
[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 #include <wtf/PointerComparison.h>
35 #include <wtf/RefPtr.h>
36
37 namespace WebCore {
38
39 StyleRareNonInheritedData::StyleRareNonInheritedData()
40     : m_opacity(RenderStyle::initialOpacity())
41     , m_aspectRatioDenominator(RenderStyle::initialAspectRatioDenominator())
42     , m_aspectRatioNumerator(RenderStyle::initialAspectRatioNumerator())
43     , m_perspective(RenderStyle::initialPerspective())
44     , m_perspectiveOriginX(RenderStyle::initialPerspectiveOriginX())
45     , m_perspectiveOriginY(RenderStyle::initialPerspectiveOriginY())
46     , lineClamp(RenderStyle::initialLineClamp())
47     , m_initialLetter(RenderStyle::initialInitialLetter())
48     , m_deprecatedFlexibleBox(StyleDeprecatedFlexibleBoxData::create())
49     , m_flexibleBox(StyleFlexibleBoxData::create())
50     , m_marquee(StyleMarqueeData::create())
51     , m_multiCol(StyleMultiColData::create())
52     , m_transform(StyleTransformData::create())
53     , m_filter(StyleFilterData::create())
54 #if ENABLE(FILTERS_LEVEL_2)
55     , m_backdropFilter(StyleFilterData::create())
56 #endif
57 #if ENABLE(CSS_GRID_LAYOUT)
58     , m_grid(StyleGridData::create())
59     , m_gridItem(StyleGridItemData::create())
60 #endif
61 #if ENABLE(CSS_SCROLL_SNAP)
62     , m_scrollSnapPort(StyleScrollSnapPort::create())
63     , m_scrollSnapArea(StyleScrollSnapArea::create())
64 #endif
65     , m_willChange(RenderStyle::initialWillChange())
66     , m_mask(FillLayer(MaskFillLayer))
67     , m_objectPosition(RenderStyle::initialObjectPosition())
68     , m_shapeOutside(RenderStyle::initialShapeOutside())
69     , m_shapeMargin(RenderStyle::initialShapeMargin())
70     , m_shapeImageThreshold(RenderStyle::initialShapeImageThreshold())
71     , m_clipPath(RenderStyle::initialClipPath())
72     , m_visitedLinkBackgroundColor(RenderStyle::initialBackgroundColor())
73     , m_order(RenderStyle::initialOrder())
74     , m_flowThread(RenderStyle::initialFlowThread())
75     , m_regionThread(RenderStyle::initialRegionThread())
76     , m_alignContent(RenderStyle::initialContentAlignment())
77     , m_alignItems(RenderStyle::initialDefaultAlignment())
78     , m_alignSelf(RenderStyle::initialSelfAlignment())
79     , m_justifyContent(RenderStyle::initialContentAlignment())
80     , m_justifyItems(RenderStyle::initialSelfAlignment())
81     , m_justifySelf(RenderStyle::initialSelfAlignment())
82 #if ENABLE(TOUCH_EVENTS)
83     , m_touchAction(static_cast<unsigned>(RenderStyle::initialTouchAction()))
84 #endif
85     , m_regionFragment(RenderStyle::initialRegionFragment())
86     , m_pageSizeType(PAGE_SIZE_AUTO)
87     , m_transformStyle3D(RenderStyle::initialTransformStyle3D())
88     , m_backfaceVisibility(RenderStyle::initialBackfaceVisibility())
89     , userDrag(RenderStyle::initialUserDrag())
90     , textOverflow(RenderStyle::initialTextOverflow())
91     , marginBeforeCollapse(MCOLLAPSE)
92     , marginAfterCollapse(MCOLLAPSE)
93     , m_appearance(RenderStyle::initialAppearance())
94     , m_borderFit(RenderStyle::initialBorderFit())
95     , m_textCombine(RenderStyle::initialTextCombine())
96     , m_textDecorationStyle(RenderStyle::initialTextDecorationStyle())
97     , m_aspectRatioType(RenderStyle::initialAspectRatioType())
98 #if ENABLE(CSS_COMPOSITING)
99     , m_effectiveBlendMode(RenderStyle::initialBlendMode())
100     , m_isolation(RenderStyle::initialIsolation())
101 #endif
102 #if ENABLE(APPLE_PAY)
103     , m_applePayButtonStyle(static_cast<unsigned>(RenderStyle::initialApplePayButtonStyle()))
104     , m_applePayButtonType(static_cast<unsigned>(RenderStyle::initialApplePayButtonType()))
105 #endif
106     , m_objectFit(RenderStyle::initialObjectFit())
107     , m_breakBefore(RenderStyle::initialBreakBetween())
108     , m_breakAfter(RenderStyle::initialBreakBetween())
109     , m_breakInside(RenderStyle::initialBreakInside())
110     , m_resize(RenderStyle::initialResize())
111     , m_hasAttrContent(false)
112     , m_isPlaceholderStyle(false)
113 {
114     m_maskBoxImage.setMaskDefaults();
115 }
116
117 inline StyleRareNonInheritedData::StyleRareNonInheritedData(const StyleRareNonInheritedData& o)
118     : RefCounted<StyleRareNonInheritedData>()
119     , m_opacity(o.m_opacity)
120     , m_aspectRatioDenominator(o.m_aspectRatioDenominator)
121     , m_aspectRatioNumerator(o.m_aspectRatioNumerator)
122     , m_perspective(o.m_perspective)
123     , m_perspectiveOriginX(o.m_perspectiveOriginX)
124     , m_perspectiveOriginY(o.m_perspectiveOriginY)
125     , lineClamp(o.lineClamp)
126     , m_initialLetter(o.m_initialLetter)
127     , m_deprecatedFlexibleBox(o.m_deprecatedFlexibleBox)
128     , m_flexibleBox(o.m_flexibleBox)
129     , m_marquee(o.m_marquee)
130     , m_multiCol(o.m_multiCol)
131     , m_transform(o.m_transform)
132     , m_filter(o.m_filter)
133 #if ENABLE(FILTERS_LEVEL_2)
134     , m_backdropFilter(o.m_backdropFilter)
135 #endif
136 #if ENABLE(CSS_GRID_LAYOUT)
137     , m_grid(o.m_grid)
138     , m_gridItem(o.m_gridItem)
139 #endif
140 #if ENABLE(CSS_SCROLL_SNAP)
141     , m_scrollSnapPort(o.m_scrollSnapPort)
142     , m_scrollSnapArea(o.m_scrollSnapArea)
143 #endif
144     , m_content(o.m_content ? o.m_content->clone() : nullptr)
145     , m_counterDirectives(o.m_counterDirectives ? clone(*o.m_counterDirectives) : nullptr)
146     , m_altText(o.m_altText)
147     , m_boxShadow(o.m_boxShadow ? std::make_unique<ShadowData>(*o.m_boxShadow) : nullptr)
148     , m_willChange(o.m_willChange)
149     , m_boxReflect(o.m_boxReflect)
150     , m_animations(o.m_animations ? std::make_unique<AnimationList>(*o.m_animations) : nullptr)
151     , m_transitions(o.m_transitions ? std::make_unique<AnimationList>(*o.m_transitions) : nullptr)
152     , m_mask(o.m_mask)
153     , m_maskBoxImage(o.m_maskBoxImage)
154     , m_pageSize(o.m_pageSize)
155     , m_objectPosition(o.m_objectPosition)
156     , m_shapeOutside(o.m_shapeOutside)
157     , m_shapeMargin(o.m_shapeMargin)
158     , m_shapeImageThreshold(o.m_shapeImageThreshold)
159     , m_clipPath(o.m_clipPath)
160     , m_textDecorationColor(o.m_textDecorationColor)
161     , m_visitedLinkTextDecorationColor(o.m_visitedLinkTextDecorationColor)
162     , m_visitedLinkBackgroundColor(o.m_visitedLinkBackgroundColor)
163     , m_visitedLinkOutlineColor(o.m_visitedLinkOutlineColor)
164     , m_visitedLinkBorderLeftColor(o.m_visitedLinkBorderLeftColor)
165     , m_visitedLinkBorderRightColor(o.m_visitedLinkBorderRightColor)
166     , m_visitedLinkBorderTopColor(o.m_visitedLinkBorderTopColor)
167     , m_visitedLinkBorderBottomColor(o.m_visitedLinkBorderBottomColor)
168     , m_order(o.m_order)
169     , m_flowThread(o.m_flowThread)
170     , m_regionThread(o.m_regionThread)
171     , m_alignContent(o.m_alignContent)
172     , m_alignItems(o.m_alignItems)
173     , m_alignSelf(o.m_alignSelf)
174     , m_justifyContent(o.m_justifyContent)
175     , m_justifyItems(o.m_justifyItems)
176     , m_justifySelf(o.m_justifySelf)
177 #if ENABLE(TOUCH_EVENTS)
178     , m_touchAction(o.m_touchAction)
179 #endif
180     , m_regionFragment(o.m_regionFragment)
181     , m_pageSizeType(o.m_pageSizeType)
182     , m_transformStyle3D(o.m_transformStyle3D)
183     , m_backfaceVisibility(o.m_backfaceVisibility)
184     , userDrag(o.userDrag)
185     , textOverflow(o.textOverflow)
186     , marginBeforeCollapse(o.marginBeforeCollapse)
187     , marginAfterCollapse(o.marginAfterCollapse)
188     , m_appearance(o.m_appearance)
189     , m_borderFit(o.m_borderFit)
190     , m_textCombine(o.m_textCombine)
191     , m_textDecorationStyle(o.m_textDecorationStyle)
192     , m_aspectRatioType(o.m_aspectRatioType)
193 #if ENABLE(CSS_COMPOSITING)
194     , m_effectiveBlendMode(o.m_effectiveBlendMode)
195     , m_isolation(o.m_isolation)
196 #endif
197 #if ENABLE(APPLE_PAY)
198     , m_applePayButtonStyle(o.m_applePayButtonStyle)
199     , m_applePayButtonType(o.m_applePayButtonType)
200 #endif
201     , m_objectFit(o.m_objectFit)
202     , m_breakBefore(o.m_breakBefore)
203     , m_breakAfter(o.m_breakAfter)
204     , m_breakInside(o.m_breakInside)
205     , m_resize(o.m_resize)
206     , m_hasAttrContent(o.m_hasAttrContent)
207     , m_isPlaceholderStyle(o.m_isPlaceholderStyle)
208 {
209 }
210
211 Ref<StyleRareNonInheritedData> StyleRareNonInheritedData::copy() const
212 {
213     return adoptRef(*new StyleRareNonInheritedData(*this));
214 }
215
216 StyleRareNonInheritedData::~StyleRareNonInheritedData()
217 {
218 }
219
220 bool StyleRareNonInheritedData::operator==(const StyleRareNonInheritedData& o) const
221 {
222     return m_opacity == o.m_opacity
223         && m_aspectRatioDenominator == o.m_aspectRatioDenominator
224         && m_aspectRatioNumerator == o.m_aspectRatioNumerator
225         && m_perspective == o.m_perspective
226         && m_perspectiveOriginX == o.m_perspectiveOriginX
227         && m_perspectiveOriginY == o.m_perspectiveOriginY
228         && lineClamp == o.lineClamp
229         && m_initialLetter == o.m_initialLetter
230 #if ENABLE(DASHBOARD_SUPPORT)
231         && m_dashboardRegions == o.m_dashboardRegions
232 #endif
233         && m_deprecatedFlexibleBox == o.m_deprecatedFlexibleBox
234         && m_flexibleBox == o.m_flexibleBox
235         && m_marquee == o.m_marquee
236         && m_multiCol == o.m_multiCol
237         && m_transform == o.m_transform
238         && m_filter == o.m_filter
239 #if ENABLE(FILTERS_LEVEL_2)
240         && m_backdropFilter == o.m_backdropFilter
241 #endif
242 #if ENABLE(CSS_GRID_LAYOUT)
243         && m_grid == o.m_grid
244         && m_gridItem == o.m_gridItem
245 #endif
246 #if ENABLE(CSS_SCROLL_SNAP)
247         && m_scrollSnapPort == o.m_scrollSnapPort
248         && m_scrollSnapArea == o.m_scrollSnapArea
249 #endif
250         && contentDataEquivalent(o)
251         && arePointingToEqualData(m_counterDirectives, o.m_counterDirectives)
252         && m_altText == o.m_altText
253         && arePointingToEqualData(m_boxShadow, o.m_boxShadow)
254         && arePointingToEqualData(m_willChange, o.m_willChange)
255         && arePointingToEqualData(m_boxReflect, o.m_boxReflect)
256         && arePointingToEqualData(m_animations, o.m_animations)
257         && arePointingToEqualData(m_transitions, o.m_transitions)
258         && m_mask == o.m_mask
259         && m_maskBoxImage == o.m_maskBoxImage
260         && m_pageSize == o.m_pageSize
261         && m_objectPosition == o.m_objectPosition
262         && arePointingToEqualData(m_shapeOutside, o.m_shapeOutside)
263         && m_shapeMargin == o.m_shapeMargin
264         && m_shapeImageThreshold == o.m_shapeImageThreshold
265         && arePointingToEqualData(m_clipPath, o.m_clipPath)
266         && m_textDecorationColor == o.m_textDecorationColor
267         && m_visitedLinkTextDecorationColor == o.m_visitedLinkTextDecorationColor
268         && m_visitedLinkBackgroundColor == o.m_visitedLinkBackgroundColor
269         && m_visitedLinkOutlineColor == o.m_visitedLinkOutlineColor
270         && m_visitedLinkBorderLeftColor == o.m_visitedLinkBorderLeftColor
271         && m_visitedLinkBorderRightColor == o.m_visitedLinkBorderRightColor
272         && m_visitedLinkBorderTopColor == o.m_visitedLinkBorderTopColor
273         && m_visitedLinkBorderBottomColor == o.m_visitedLinkBorderBottomColor
274         && m_order == o.m_order
275         && m_flowThread == o.m_flowThread
276         && m_alignContent == o.m_alignContent
277         && m_alignItems == o.m_alignItems
278         && m_alignSelf == o.m_alignSelf
279         && m_justifyContent == o.m_justifyContent
280         && m_justifyItems == o.m_justifyItems
281         && m_justifySelf == o.m_justifySelf
282         && m_regionThread == o.m_regionThread
283         && m_regionFragment == o.m_regionFragment
284         && m_pageSizeType == o.m_pageSizeType
285         && m_transformStyle3D == o.m_transformStyle3D
286         && m_backfaceVisibility == o.m_backfaceVisibility
287         && userDrag == o.userDrag
288         && textOverflow == o.textOverflow
289         && marginBeforeCollapse == o.marginBeforeCollapse
290         && marginAfterCollapse == o.marginAfterCollapse
291         && m_appearance == o.m_appearance
292         && m_borderFit == o.m_borderFit
293         && m_textCombine == o.m_textCombine
294         && m_textDecorationStyle == o.m_textDecorationStyle
295 #if ENABLE(TOUCH_EVENTS)
296         && m_touchAction == o.m_touchAction
297 #endif
298 #if ENABLE(CSS_COMPOSITING)
299         && m_effectiveBlendMode == o.m_effectiveBlendMode
300         && m_isolation == o.m_isolation
301 #endif
302 #if ENABLE(APPLE_PAY)
303         && m_applePayButtonStyle == o.m_applePayButtonStyle
304         && m_applePayButtonType == o.m_applePayButtonType
305 #endif
306         && m_aspectRatioType == o.m_aspectRatioType
307         && m_objectFit == o.m_objectFit
308         && m_breakAfter == o.m_breakAfter
309         && m_breakBefore == o.m_breakBefore
310         && m_breakInside == o.m_breakInside
311         && m_resize == o.m_resize
312         && m_hasAttrContent == o.m_hasAttrContent
313         && m_isPlaceholderStyle == o.m_isPlaceholderStyle;
314 }
315
316 bool StyleRareNonInheritedData::contentDataEquivalent(const StyleRareNonInheritedData& o) const
317 {
318     ContentData* a = m_content.get();
319     ContentData* b = o.m_content.get();
320
321     while (a && b && *a == *b) {
322         a = a->next();
323         b = b->next();
324     }
325
326     return !a && !b;
327 }
328
329 bool StyleRareNonInheritedData::hasFilters() const
330 {
331     return m_filter.get() && !m_filter->m_operations.isEmpty();
332 }
333
334 #if ENABLE(FILTERS_LEVEL_2)
335 bool StyleRareNonInheritedData::hasBackdropFilters() const
336 {
337     return m_backdropFilter.get() && !m_backdropFilter->m_operations.isEmpty();
338 }
339 #endif
340
341 } // namespace WebCore