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