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