651420099f9780052abe0e42614bd0d437a4ffd8
[WebKit-https.git] / Source / WebCore / rendering / style / StyleRareNonInheritedData.cpp
1 /*
2  * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
3  * Copyright (C) 2004-2017 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     , aspectRatioDenominator(RenderStyle::initialAspectRatioDenominator())
42     , aspectRatioNumerator(RenderStyle::initialAspectRatioNumerator())
43     , perspective(RenderStyle::initialPerspective())
44     , perspectiveOriginX(RenderStyle::initialPerspectiveOriginX())
45     , perspectiveOriginY(RenderStyle::initialPerspectiveOriginY())
46     , lineClamp(RenderStyle::initialLineClamp())
47     , initialLetter(RenderStyle::initialInitialLetter())
48     , deprecatedFlexibleBox(StyleDeprecatedFlexibleBoxData::create())
49     , flexibleBox(StyleFlexibleBoxData::create())
50     , marquee(StyleMarqueeData::create())
51     , multiCol(StyleMultiColData::create())
52     , transform(StyleTransformData::create())
53     , filter(StyleFilterData::create())
54 #if ENABLE(FILTERS_LEVEL_2)
55     , backdropFilter(StyleFilterData::create())
56 #endif
57 #if ENABLE(CSS_GRID_LAYOUT)
58     , grid(StyleGridData::create())
59     , gridItem(StyleGridItemData::create())
60 #endif
61 #if ENABLE(CSS_SCROLL_SNAP)
62     , scrollSnapPort(StyleScrollSnapPort::create())
63     , scrollSnapArea(StyleScrollSnapArea::create())
64 #endif
65     , willChange(RenderStyle::initialWillChange())
66     , mask(FillLayer(MaskFillLayer))
67     , objectPosition(RenderStyle::initialObjectPosition())
68     , shapeOutside(RenderStyle::initialShapeOutside())
69     , shapeMargin(RenderStyle::initialShapeMargin())
70     , shapeImageThreshold(RenderStyle::initialShapeImageThreshold())
71     , clipPath(RenderStyle::initialClipPath())
72     , visitedLinkBackgroundColor(RenderStyle::initialBackgroundColor())
73     , order(RenderStyle::initialOrder())
74     , flowThread(RenderStyle::initialFlowThread())
75     , regionThread(RenderStyle::initialRegionThread())
76     , alignContent(RenderStyle::initialContentAlignment())
77     , alignItems(RenderStyle::initialDefaultAlignment())
78     , alignSelf(RenderStyle::initialSelfAlignment())
79     , justifyContent(RenderStyle::initialContentAlignment())
80     , justifyItems(RenderStyle::initialSelfAlignment())
81     , justifySelf(RenderStyle::initialSelfAlignment())
82 #if ENABLE(TOUCH_EVENTS)
83     , touchAction(static_cast<unsigned>(RenderStyle::initialTouchAction()))
84 #endif
85     , regionFragment(RenderStyle::initialRegionFragment())
86     , pageSizeType(PAGE_SIZE_AUTO)
87     , transformStyle3D(RenderStyle::initialTransformStyle3D())
88     , backfaceVisibility(RenderStyle::initialBackfaceVisibility())
89     , userDrag(RenderStyle::initialUserDrag())
90     , textOverflow(RenderStyle::initialTextOverflow())
91     , marginBeforeCollapse(MCOLLAPSE)
92     , marginAfterCollapse(MCOLLAPSE)
93     , appearance(RenderStyle::initialAppearance())
94     , borderFit(RenderStyle::initialBorderFit())
95     , textCombine(RenderStyle::initialTextCombine())
96     , textDecorationStyle(RenderStyle::initialTextDecorationStyle())
97     , aspectRatioType(RenderStyle::initialAspectRatioType())
98 #if ENABLE(CSS_COMPOSITING)
99     , effectiveBlendMode(RenderStyle::initialBlendMode())
100     , isolation(RenderStyle::initialIsolation())
101 #endif
102 #if ENABLE(APPLE_PAY)
103     , applePayButtonStyle(static_cast<unsigned>(RenderStyle::initialApplePayButtonStyle()))
104     , applePayButtonType(static_cast<unsigned>(RenderStyle::initialApplePayButtonType()))
105 #endif
106     , objectFit(RenderStyle::initialObjectFit())
107     , breakBefore(RenderStyle::initialBreakBetween())
108     , breakAfter(RenderStyle::initialBreakBetween())
109     , breakInside(RenderStyle::initialBreakInside())
110     , resize(RenderStyle::initialResize())
111     , hasAttrContent(false)
112     , isPlaceholderStyle(false)
113 {
114     maskBoxImage.setMaskDefaults();
115 }
116
117 inline StyleRareNonInheritedData::StyleRareNonInheritedData(const StyleRareNonInheritedData& o)
118     : RefCounted<StyleRareNonInheritedData>()
119     , opacity(o.opacity)
120     , aspectRatioDenominator(o.aspectRatioDenominator)
121     , aspectRatioNumerator(o.aspectRatioNumerator)
122     , perspective(o.perspective)
123     , perspectiveOriginX(o.perspectiveOriginX)
124     , perspectiveOriginY(o.perspectiveOriginY)
125     , lineClamp(o.lineClamp)
126     , initialLetter(o.initialLetter)
127     , deprecatedFlexibleBox(o.deprecatedFlexibleBox)
128     , flexibleBox(o.flexibleBox)
129     , marquee(o.marquee)
130     , multiCol(o.multiCol)
131     , transform(o.transform)
132     , filter(o.filter)
133 #if ENABLE(FILTERS_LEVEL_2)
134     , backdropFilter(o.backdropFilter)
135 #endif
136 #if ENABLE(CSS_GRID_LAYOUT)
137     , grid(o.grid)
138     , gridItem(o.gridItem)
139 #endif
140 #if ENABLE(CSS_SCROLL_SNAP)
141     , scrollSnapPort(o.scrollSnapPort)
142     , scrollSnapArea(o.scrollSnapArea)
143 #endif
144     , content(o.content ? o.content->clone() : nullptr)
145     , counterDirectives(o.counterDirectives ? clone(*o.counterDirectives) : nullptr)
146     , altText(o.altText)
147     , boxShadow(o.boxShadow ? std::make_unique<ShadowData>(*o.boxShadow) : nullptr)
148     , willChange(o.willChange)
149     , boxReflect(o.boxReflect)
150     , animations(o.animations ? std::make_unique<AnimationList>(*o.animations) : nullptr)
151     , transitions(o.transitions ? std::make_unique<AnimationList>(*o.transitions) : nullptr)
152     , mask(o.mask)
153     , maskBoxImage(o.maskBoxImage)
154     , pageSize(o.pageSize)
155     , objectPosition(o.objectPosition)
156     , shapeOutside(o.shapeOutside)
157     , shapeMargin(o.shapeMargin)
158     , shapeImageThreshold(o.shapeImageThreshold)
159     , clipPath(o.clipPath)
160     , textDecorationColor(o.textDecorationColor)
161     , visitedLinkTextDecorationColor(o.visitedLinkTextDecorationColor)
162     , visitedLinkBackgroundColor(o.visitedLinkBackgroundColor)
163     , visitedLinkOutlineColor(o.visitedLinkOutlineColor)
164     , visitedLinkBorderLeftColor(o.visitedLinkBorderLeftColor)
165     , visitedLinkBorderRightColor(o.visitedLinkBorderRightColor)
166     , visitedLinkBorderTopColor(o.visitedLinkBorderTopColor)
167     , visitedLinkBorderBottomColor(o.visitedLinkBorderBottomColor)
168     , order(o.order)
169     , flowThread(o.flowThread)
170     , regionThread(o.regionThread)
171     , alignContent(o.alignContent)
172     , alignItems(o.alignItems)
173     , alignSelf(o.alignSelf)
174     , justifyContent(o.justifyContent)
175     , justifyItems(o.justifyItems)
176     , justifySelf(o.justifySelf)
177 #if ENABLE(TOUCH_EVENTS)
178     , touchAction(o.touchAction)
179 #endif
180     , regionFragment(o.regionFragment)
181     , pageSizeType(o.pageSizeType)
182     , transformStyle3D(o.transformStyle3D)
183     , backfaceVisibility(o.backfaceVisibility)
184     , userDrag(o.userDrag)
185     , textOverflow(o.textOverflow)
186     , marginBeforeCollapse(o.marginBeforeCollapse)
187     , marginAfterCollapse(o.marginAfterCollapse)
188     , appearance(o.appearance)
189     , borderFit(o.borderFit)
190     , textCombine(o.textCombine)
191     , textDecorationStyle(o.textDecorationStyle)
192     , aspectRatioType(o.aspectRatioType)
193 #if ENABLE(CSS_COMPOSITING)
194     , effectiveBlendMode(o.effectiveBlendMode)
195     , isolation(o.isolation)
196 #endif
197 #if ENABLE(APPLE_PAY)
198     , applePayButtonStyle(o.applePayButtonStyle)
199     , applePayButtonType(o.applePayButtonType)
200 #endif
201     , objectFit(o.objectFit)
202     , breakBefore(o.breakBefore)
203     , breakAfter(o.breakAfter)
204     , breakInside(o.breakInside)
205     , resize(o.resize)
206     , hasAttrContent(o.hasAttrContent)
207     , isPlaceholderStyle(o.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 opacity == o.opacity
223         && aspectRatioDenominator == o.aspectRatioDenominator
224         && aspectRatioNumerator == o.aspectRatioNumerator
225         && perspective == o.perspective
226         && perspectiveOriginX == o.perspectiveOriginX
227         && perspectiveOriginY == o.perspectiveOriginY
228         && lineClamp == o.lineClamp
229         && initialLetter == o.initialLetter
230 #if ENABLE(DASHBOARD_SUPPORT)
231         && dashboardRegions == o.dashboardRegions
232 #endif
233         && deprecatedFlexibleBox == o.deprecatedFlexibleBox
234         && flexibleBox == o.flexibleBox
235         && marquee == o.marquee
236         && multiCol == o.multiCol
237         && transform == o.transform
238         && filter == o.filter
239 #if ENABLE(FILTERS_LEVEL_2)
240         && backdropFilter == o.backdropFilter
241 #endif
242 #if ENABLE(CSS_GRID_LAYOUT)
243         && grid == o.grid
244         && gridItem == o.gridItem
245 #endif
246 #if ENABLE(CSS_SCROLL_SNAP)
247         && scrollSnapPort == o.scrollSnapPort
248         && scrollSnapArea == o.scrollSnapArea
249 #endif
250         && contentDataEquivalent(o)
251         && arePointingToEqualData(counterDirectives, o.counterDirectives)
252         && altText == o.altText
253         && arePointingToEqualData(boxShadow, o.boxShadow)
254         && arePointingToEqualData(willChange, o.willChange)
255         && arePointingToEqualData(boxReflect, o.boxReflect)
256         && arePointingToEqualData(animations, o.animations)
257         && arePointingToEqualData(transitions, o.transitions)
258         && mask == o.mask
259         && maskBoxImage == o.maskBoxImage
260         && pageSize == o.pageSize
261         && objectPosition == o.objectPosition
262         && arePointingToEqualData(shapeOutside, o.shapeOutside)
263         && shapeMargin == o.shapeMargin
264         && shapeImageThreshold == o.shapeImageThreshold
265         && arePointingToEqualData(clipPath, o.clipPath)
266         && textDecorationColor == o.textDecorationColor
267         && visitedLinkTextDecorationColor == o.visitedLinkTextDecorationColor
268         && visitedLinkBackgroundColor == o.visitedLinkBackgroundColor
269         && visitedLinkOutlineColor == o.visitedLinkOutlineColor
270         && visitedLinkBorderLeftColor == o.visitedLinkBorderLeftColor
271         && visitedLinkBorderRightColor == o.visitedLinkBorderRightColor
272         && visitedLinkBorderTopColor == o.visitedLinkBorderTopColor
273         && visitedLinkBorderBottomColor == o.visitedLinkBorderBottomColor
274         && order == o.order
275         && flowThread == o.flowThread
276         && alignContent == o.alignContent
277         && alignItems == o.alignItems
278         && alignSelf == o.alignSelf
279         && justifyContent == o.justifyContent
280         && justifyItems == o.justifyItems
281         && justifySelf == o.justifySelf
282         && regionThread == o.regionThread
283         && regionFragment == o.regionFragment
284         && pageSizeType == o.pageSizeType
285         && transformStyle3D == o.transformStyle3D
286         && backfaceVisibility == o.backfaceVisibility
287         && userDrag == o.userDrag
288         && textOverflow == o.textOverflow
289         && marginBeforeCollapse == o.marginBeforeCollapse
290         && marginAfterCollapse == o.marginAfterCollapse
291         && appearance == o.appearance
292         && borderFit == o.borderFit
293         && textCombine == o.textCombine
294         && textDecorationStyle == o.textDecorationStyle
295 #if ENABLE(TOUCH_EVENTS)
296         && touchAction == o.touchAction
297 #endif
298 #if ENABLE(CSS_COMPOSITING)
299         && effectiveBlendMode == o.effectiveBlendMode
300         && isolation == o.isolation
301 #endif
302 #if ENABLE(APPLE_PAY)
303         && applePayButtonStyle == o.applePayButtonStyle
304         && applePayButtonType == o.applePayButtonType
305 #endif
306         && aspectRatioType == o.aspectRatioType
307         && objectFit == o.objectFit
308         && breakAfter == o.breakAfter
309         && breakBefore == o.breakBefore
310         && breakInside == o.breakInside
311         && resize == o.resize
312         && hasAttrContent == o.hasAttrContent
313         && isPlaceholderStyle == o.isPlaceholderStyle;
314 }
315
316 bool StyleRareNonInheritedData::contentDataEquivalent(const StyleRareNonInheritedData& other) const
317 {
318     auto* a = content.get();
319     auto* b = other.content.get();
320     while (a && b && *a == *b) {
321         a = a->next();
322         b = b->next();
323     }
324     return !a && !b;
325 }
326
327 bool StyleRareNonInheritedData::hasFilters() const
328 {
329     return !filter->operations.isEmpty();
330 }
331
332 #if ENABLE(FILTERS_LEVEL_2)
333
334 bool StyleRareNonInheritedData::hasBackdropFilters() const
335 {
336     return !backdropFilter->operations.isEmpty();
337 }
338
339 #endif
340
341 } // namespace WebCore