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