[css-grid] Remove compilation flag ENABLE_CSS_GRID_LAYOUT
[WebKit-https.git] / Source / WebCore / rendering / style / RenderStyle.cpp
1 /*
2  * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
3  * Copyright (C) 2004-2017 Apple Inc. All rights reserved.
4  * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22
23 #include "config.h"
24 #include "RenderStyle.h"
25
26 #include "ContentData.h"
27 #include "CSSCustomPropertyValue.h"
28 #include "CSSParser.h"
29 #include "CSSPropertyNames.h"
30 #include "CursorList.h"
31 #include "FloatRoundedRect.h"
32 #include "FontCascade.h"
33 #include "FontSelector.h"
34 #include "InlineTextBoxStyle.h"
35 #include "Pagination.h"
36 #include "QuotesData.h"
37 #include "RenderObject.h"
38 #include "RenderTheme.h"
39 #include "RuntimeEnabledFeatures.h"
40 #include "ScaleTransformOperation.h"
41 #include "ShadowData.h"
42 #include "StyleImage.h"
43 #include "StyleInheritedData.h"
44 #include "StyleResolver.h"
45 #include "StyleScrollSnapPoints.h"
46 #include "StyleSelfAlignmentData.h"
47 #include "StyleTreeResolver.h"
48 #include "WillChangeData.h"
49 #include <wtf/MathExtras.h>
50 #include <wtf/PointerComparison.h>
51 #include <wtf/StdLibExtras.h>
52 #include <algorithm>
53
54 #if ENABLE(TEXT_AUTOSIZING)
55 #include <wtf/text/StringHash.h>
56 #endif
57
58 namespace WebCore {
59
60 struct SameSizeAsBorderValue {
61     float m_width;
62     Color m_color;
63     int m_restBits;
64 };
65
66 COMPILE_ASSERT(sizeof(BorderValue) == sizeof(SameSizeAsBorderValue), BorderValue_should_not_grow);
67
68 struct SameSizeAsRenderStyle {
69     void* dataRefs[7];
70     void* ownPtrs[1];
71     void* dataRefSvgStyle;
72     struct InheritedFlags {
73         unsigned m_bitfields[2];
74     } m_inheritedFlags;
75
76     struct NonInheritedFlags {
77         uint64_t m_flags;
78     } m_nonInheritedFlags;
79 #if !ASSERT_DISABLED || ENABLE(SECURITY_ASSERTIONS)
80     bool deletionCheck;
81 #endif
82 };
83
84 COMPILE_ASSERT(sizeof(RenderStyle) == sizeof(SameSizeAsRenderStyle), RenderStyle_should_stay_small);
85
86 RenderStyle& RenderStyle::defaultStyle()
87 {
88     static NeverDestroyed<RenderStyle> style { CreateDefaultStyle };
89     return style;
90 }
91
92 RenderStyle RenderStyle::create()
93 {
94     return clone(defaultStyle());
95 }
96
97 std::unique_ptr<RenderStyle> RenderStyle::createPtr()
98 {
99     return clonePtr(defaultStyle());
100 }
101
102 RenderStyle RenderStyle::clone(const RenderStyle& style)
103 {
104     return RenderStyle(style, Clone);
105 }
106
107 std::unique_ptr<RenderStyle> RenderStyle::clonePtr(const RenderStyle& style)
108 {
109     return std::make_unique<RenderStyle>(style, Clone);
110 }
111
112 RenderStyle RenderStyle::createAnonymousStyleWithDisplay(const RenderStyle& parentStyle, EDisplay display)
113 {
114     auto newStyle = create();
115     newStyle.inheritFrom(parentStyle);
116     newStyle.inheritUnicodeBidiFrom(&parentStyle);
117     newStyle.setDisplay(display);
118     return newStyle;
119 }
120
121 RenderStyle RenderStyle::createStyleInheritingFromPseudoStyle(const RenderStyle& pseudoStyle)
122 {
123     ASSERT(pseudoStyle.styleType() == BEFORE || pseudoStyle.styleType() == AFTER);
124
125     auto style = create();
126     style.inheritFrom(pseudoStyle);
127     return style;
128 }
129
130 RenderStyle::RenderStyle(CreateDefaultStyleTag)
131     : m_boxData(StyleBoxData::create())
132     , m_visualData(StyleVisualData::create())
133     , m_backgroundData(StyleBackgroundData::create())
134     , m_surroundData(StyleSurroundData::create())
135     , m_rareNonInheritedData(StyleRareNonInheritedData::create())
136     , m_rareInheritedData(StyleRareInheritedData::create())
137     , m_inheritedData(StyleInheritedData::create())
138     , m_svgStyle(SVGRenderStyle::create())
139 {
140     m_inheritedFlags.emptyCells = initialEmptyCells();
141     m_inheritedFlags.captionSide = initialCaptionSide();
142     m_inheritedFlags.listStyleType = initialListStyleType();
143     m_inheritedFlags.listStylePosition = initialListStylePosition();
144     m_inheritedFlags.visibility = initialVisibility();
145     m_inheritedFlags.textAlign = initialTextAlign();
146     m_inheritedFlags.textTransform = initialTextTransform();
147     m_inheritedFlags.textDecorations = initialTextDecoration();
148     m_inheritedFlags.cursor = initialCursor();
149 #if ENABLE(CURSOR_VISIBILITY)
150     m_inheritedFlags.cursorVisibility = initialCursorVisibility();
151 #endif
152     m_inheritedFlags.direction = initialDirection();
153     m_inheritedFlags.whiteSpace = initialWhiteSpace();
154     m_inheritedFlags.borderCollapse = initialBorderCollapse();
155     m_inheritedFlags.rtlOrdering = initialRTLOrdering();
156     m_inheritedFlags.boxDirection = initialBoxDirection();
157     m_inheritedFlags.printColorAdjust = initialPrintColorAdjust();
158     m_inheritedFlags.pointerEvents = initialPointerEvents();
159     m_inheritedFlags.insideLink = NotInsideLink;
160     m_inheritedFlags.insideDefaultButton = false;
161     m_inheritedFlags.writingMode = initialWritingMode();
162
163     static_assert((sizeof(InheritedFlags) <= 8), "InheritedFlags does not grow");
164     static_assert((sizeof(NonInheritedFlags) <= 8), "NonInheritedFlags does not grow");
165 }
166
167 inline RenderStyle::RenderStyle(const RenderStyle& other, CloneTag)
168     : m_boxData(other.m_boxData)
169     , m_visualData(other.m_visualData)
170     , m_backgroundData(other.m_backgroundData)
171     , m_surroundData(other.m_surroundData)
172     , m_rareNonInheritedData(other.m_rareNonInheritedData)
173     , m_nonInheritedFlags(other.m_nonInheritedFlags)
174     , m_rareInheritedData(other.m_rareInheritedData)
175     , m_inheritedData(other.m_inheritedData)
176     , m_inheritedFlags(other.m_inheritedFlags)
177     , m_svgStyle(other.m_svgStyle)
178 {
179 }
180
181 inline RenderStyle::RenderStyle(RenderStyle& a, RenderStyle&& b)
182     : m_boxData(a.m_boxData.replace(WTFMove(b.m_boxData)))
183     , m_visualData(a.m_visualData.replace(WTFMove(b.m_visualData)))
184     , m_backgroundData(a.m_backgroundData.replace(WTFMove(b.m_backgroundData)))
185     , m_surroundData(a.m_surroundData.replace(WTFMove(b.m_surroundData)))
186     , m_rareNonInheritedData(a.m_rareNonInheritedData.replace(WTFMove(b.m_rareNonInheritedData)))
187     , m_nonInheritedFlags(std::exchange(a.m_nonInheritedFlags, b.m_nonInheritedFlags))
188     , m_rareInheritedData(a.m_rareInheritedData.replace(WTFMove(b.m_rareInheritedData)))
189     , m_inheritedData(a.m_inheritedData.replace(WTFMove(b.m_inheritedData)))
190     , m_inheritedFlags(std::exchange(a.m_inheritedFlags, b.m_inheritedFlags))
191     , m_cachedPseudoStyles(std::exchange(a.m_cachedPseudoStyles, WTFMove(b.m_cachedPseudoStyles)))
192     , m_svgStyle(a.m_svgStyle.replace(WTFMove(b.m_svgStyle)))
193 {
194 }
195
196 RenderStyle::~RenderStyle()
197 {
198 #if !ASSERT_DISABLED || ENABLE(SECURITY_ASSERTIONS)
199     ASSERT_WITH_SECURITY_IMPLICATION(!m_deletionHasBegun);
200     m_deletionHasBegun = true;
201 #endif
202 }
203
204 RenderStyle RenderStyle::replace(RenderStyle&& newStyle)
205 {
206     return RenderStyle { *this, WTFMove(newStyle) };
207 }
208
209 bool RenderStyle::isCSSGridLayoutEnabled()
210 {
211     return RuntimeEnabledFeatures::sharedFeatures().isCSSGridLayoutEnabled();
212 }
213
214 static StyleSelfAlignmentData resolvedSelfAlignment(const StyleSelfAlignmentData& value, ItemPosition normalValueBehavior)
215 {
216     ASSERT(value.position() != ItemPositionAuto);
217     if (value.position() == ItemPositionNormal)
218         return { normalValueBehavior, OverflowAlignmentDefault };
219     return value;
220 }
221
222 StyleSelfAlignmentData RenderStyle::resolvedAlignItems(ItemPosition normalValueBehaviour) const
223 {
224     return resolvedSelfAlignment(alignItems(), normalValueBehaviour);
225 }
226
227 StyleSelfAlignmentData RenderStyle::resolvedAlignSelf(const RenderStyle& parentStyle, ItemPosition normalValueBehaviour) const
228 {
229     // The auto keyword computes to the parent's align-items computed value.
230     // We will return the behaviour of 'normal' value if needed, which is specific of each layout model.
231     if (alignSelf().position() == ItemPositionAuto)
232         return parentStyle.resolvedAlignItems(normalValueBehaviour);
233     return resolvedSelfAlignment(alignSelf(), normalValueBehaviour);
234 }
235
236 StyleSelfAlignmentData RenderStyle::resolvedJustifyItems(ItemPosition normalValueBehaviour) const
237 {
238     // FIXME: justify-items 'auto' value is allowed only to provide the 'legacy' keyword's behavior, which it's still not implemented for layout.
239     // "If the inherited value of justify-items includes the legacy keyword, auto computes to the inherited value."
240     // https://drafts.csswg.org/css-align/#justify-items-property
241     if (justifyItems().position() == ItemPositionAuto)
242         return { normalValueBehaviour, OverflowAlignmentDefault };
243     return resolvedSelfAlignment(justifyItems(), normalValueBehaviour);
244 }
245
246 StyleSelfAlignmentData RenderStyle::resolvedJustifySelf(const RenderStyle& parentStyle, ItemPosition normalValueBehaviour) const
247 {
248     // The auto keyword computes to the parent's justify-items computed value.
249     // We will return the behaviour of 'normal' value if needed, which is specific of each layout model.
250     if (justifySelf().position() == ItemPositionAuto)
251         return parentStyle.resolvedJustifyItems(normalValueBehaviour);
252     return resolvedSelfAlignment(justifySelf(), normalValueBehaviour);
253 }
254
255 static inline ContentPosition resolvedContentAlignmentPosition(const StyleContentAlignmentData& value, const StyleContentAlignmentData& normalValueBehavior)
256 {
257     return (value.position() == ContentPositionNormal && value.distribution() == ContentDistributionDefault) ? normalValueBehavior.position() : value.position();
258 }
259
260 static inline ContentDistributionType resolvedContentAlignmentDistribution(const StyleContentAlignmentData& value, const StyleContentAlignmentData& normalValueBehavior)
261 {
262     return (value.position() == ContentPositionNormal && value.distribution() == ContentDistributionDefault) ? normalValueBehavior.distribution() : value.distribution();
263 }
264
265 ContentPosition RenderStyle::resolvedJustifyContentPosition(const StyleContentAlignmentData& normalValueBehavior) const
266 {
267     return resolvedContentAlignmentPosition(justifyContent(), normalValueBehavior);
268 }
269
270 ContentDistributionType RenderStyle::resolvedJustifyContentDistribution(const StyleContentAlignmentData& normalValueBehavior) const
271 {
272     return resolvedContentAlignmentDistribution(justifyContent(), normalValueBehavior);
273 }
274
275 ContentPosition RenderStyle::resolvedAlignContentPosition(const StyleContentAlignmentData& normalValueBehavior) const
276 {
277     return resolvedContentAlignmentPosition(alignContent(), normalValueBehavior);
278 }
279
280 ContentDistributionType RenderStyle::resolvedAlignContentDistribution(const StyleContentAlignmentData& normalValueBehavior) const
281 {
282     return resolvedContentAlignmentDistribution(alignContent(), normalValueBehavior);
283 }
284
285 void RenderStyle::inheritFrom(const RenderStyle& inheritParent)
286 {
287     m_rareInheritedData = inheritParent.m_rareInheritedData;
288     m_inheritedData = inheritParent.m_inheritedData;
289     m_inheritedFlags = inheritParent.m_inheritedFlags;
290
291     if (m_svgStyle != inheritParent.m_svgStyle)
292         m_svgStyle.access().inheritFrom(inheritParent.m_svgStyle.get());
293 }
294
295 void RenderStyle::copyNonInheritedFrom(const RenderStyle& other)
296 {
297     m_boxData = other.m_boxData;
298     m_visualData = other.m_visualData;
299     m_backgroundData = other.m_backgroundData;
300     m_surroundData = other.m_surroundData;
301     m_rareNonInheritedData = other.m_rareNonInheritedData;
302     m_nonInheritedFlags.copyNonInheritedFrom(other.m_nonInheritedFlags);
303
304     if (m_svgStyle != other.m_svgStyle)
305         m_svgStyle.access().copyNonInheritedFrom(other.m_svgStyle.get());
306
307     ASSERT(zoom() == initialZoom());
308 }
309
310 bool RenderStyle::operator==(const RenderStyle& other) const
311 {
312     // compare everything except the pseudoStyle pointer
313     return m_inheritedFlags == other.m_inheritedFlags
314         && m_nonInheritedFlags == other.m_nonInheritedFlags
315         && m_boxData == other.m_boxData
316         && m_visualData == other.m_visualData
317         && m_backgroundData == other.m_backgroundData
318         && m_surroundData == other.m_surroundData
319         && m_rareNonInheritedData == other.m_rareNonInheritedData
320         && m_rareInheritedData == other.m_rareInheritedData
321         && m_inheritedData == other.m_inheritedData
322         && m_svgStyle == other.m_svgStyle;
323 }
324
325 bool RenderStyle::hasUniquePseudoStyle() const
326 {
327     if (!m_cachedPseudoStyles || styleType() != NOPSEUDO)
328         return false;
329
330     for (auto& pseudoStyle : *m_cachedPseudoStyles) {
331         if (pseudoStyle->unique())
332             return true;
333     }
334
335     return false;
336 }
337
338 RenderStyle* RenderStyle::getCachedPseudoStyle(PseudoId pid) const
339 {
340     if (!m_cachedPseudoStyles || !m_cachedPseudoStyles->size())
341         return nullptr;
342
343     if (styleType() != NOPSEUDO) 
344         return nullptr;
345
346     for (auto& pseudoStyle : *m_cachedPseudoStyles) {
347         if (pseudoStyle->styleType() == pid)
348             return pseudoStyle.get();
349     }
350
351     return nullptr;
352 }
353
354 RenderStyle* RenderStyle::addCachedPseudoStyle(std::unique_ptr<RenderStyle> pseudo)
355 {
356     if (!pseudo)
357         return nullptr;
358
359     ASSERT(pseudo->styleType() > NOPSEUDO);
360
361     RenderStyle* result = pseudo.get();
362
363     if (!m_cachedPseudoStyles)
364         m_cachedPseudoStyles = std::make_unique<PseudoStyleCache>();
365
366     m_cachedPseudoStyles->append(WTFMove(pseudo));
367
368     return result;
369 }
370
371 void RenderStyle::removeCachedPseudoStyle(PseudoId pid)
372 {
373     if (!m_cachedPseudoStyles)
374         return;
375     for (size_t i = 0; i < m_cachedPseudoStyles->size(); ++i) {
376         RenderStyle* pseudoStyle = m_cachedPseudoStyles->at(i).get();
377         if (pseudoStyle->styleType() == pid) {
378             m_cachedPseudoStyles->remove(i);
379             return;
380         }
381     }
382 }
383
384 bool RenderStyle::inheritedNotEqual(const RenderStyle* other) const
385 {
386     return m_inheritedFlags != other->m_inheritedFlags
387         || m_inheritedData != other->m_inheritedData
388         || m_svgStyle->inheritedNotEqual(other->m_svgStyle)
389         || m_rareInheritedData != other->m_rareInheritedData;
390 }
391
392 #if ENABLE(TEXT_AUTOSIZING)
393
394 static inline unsigned computeFontHash(const FontCascade& font)
395 {
396     IntegerHasher hasher;
397     hasher.add(ASCIICaseInsensitiveHash::hash(font.fontDescription().firstFamily()));
398     hasher.add(font.fontDescription().specifiedSize());
399     return hasher.hash();
400 }
401
402 unsigned RenderStyle::hashForTextAutosizing() const
403 {
404     // FIXME: Not a very smart hash. Could be improved upon. See <https://bugs.webkit.org/show_bug.cgi?id=121131>.
405     unsigned hash = m_rareNonInheritedData->appearance;
406     hash ^= m_rareNonInheritedData->marginBeforeCollapse;
407     hash ^= m_rareNonInheritedData->marginAfterCollapse;
408     hash ^= m_rareNonInheritedData->lineClamp.value();
409     hash ^= m_rareInheritedData->overflowWrap;
410     hash ^= m_rareInheritedData->nbspMode;
411     hash ^= m_rareInheritedData->lineBreak;
412     hash ^= WTF::FloatHash<float>::hash(m_inheritedData->specifiedLineHeight.value());
413     hash ^= computeFontHash(m_inheritedData->fontCascade);
414     hash ^= WTF::FloatHash<float>::hash(m_inheritedData->horizontalBorderSpacing);
415     hash ^= WTF::FloatHash<float>::hash(m_inheritedData->verticalBorderSpacing);
416     hash ^= m_inheritedFlags.boxDirection;
417     hash ^= m_inheritedFlags.rtlOrdering;
418     hash ^= m_nonInheritedFlags.position();
419     hash ^= m_nonInheritedFlags.floating();
420     hash ^= m_rareNonInheritedData->textOverflow;
421     hash ^= m_rareInheritedData->textSecurity;
422     return hash;
423 }
424
425 bool RenderStyle::equalForTextAutosizing(const RenderStyle& other) const
426 {
427     return m_rareNonInheritedData->appearance == other.m_rareNonInheritedData->appearance
428         && m_rareNonInheritedData->marginBeforeCollapse == other.m_rareNonInheritedData->marginBeforeCollapse
429         && m_rareNonInheritedData->marginAfterCollapse == other.m_rareNonInheritedData->marginAfterCollapse
430         && m_rareNonInheritedData->lineClamp == other.m_rareNonInheritedData->lineClamp
431         && m_rareInheritedData->textSizeAdjust == other.m_rareInheritedData->textSizeAdjust
432         && m_rareInheritedData->overflowWrap == other.m_rareInheritedData->overflowWrap
433         && m_rareInheritedData->nbspMode == other.m_rareInheritedData->nbspMode
434         && m_rareInheritedData->lineBreak == other.m_rareInheritedData->lineBreak
435         && m_rareInheritedData->textSecurity == other.m_rareInheritedData->textSecurity
436         && m_inheritedData->specifiedLineHeight == other.m_inheritedData->specifiedLineHeight
437         && m_inheritedData->fontCascade.equalForTextAutoSizing(other.m_inheritedData->fontCascade)
438         && m_inheritedData->horizontalBorderSpacing == other.m_inheritedData->horizontalBorderSpacing
439         && m_inheritedData->verticalBorderSpacing == other.m_inheritedData->verticalBorderSpacing
440         && m_inheritedFlags.boxDirection == other.m_inheritedFlags.boxDirection
441         && m_inheritedFlags.rtlOrdering == other.m_inheritedFlags.rtlOrdering
442         && m_nonInheritedFlags.position() == other.m_nonInheritedFlags.position()
443         && m_nonInheritedFlags.floating() == other.m_nonInheritedFlags.floating()
444         && m_rareNonInheritedData->textOverflow == other.m_rareNonInheritedData->textOverflow;
445 }
446
447 #endif // ENABLE(TEXT_AUTOSIZING)
448
449 bool RenderStyle::inheritedDataShared(const RenderStyle* other) const
450 {
451     // This is a fast check that only looks if the data structures are shared.
452     return m_inheritedFlags == other->m_inheritedFlags
453         && m_inheritedData.get() == other->m_inheritedData.get()
454         && m_svgStyle.get() == other->m_svgStyle.get()
455         && m_rareInheritedData.get() == other->m_rareInheritedData.get();
456 }
457
458 static bool positionChangeIsMovementOnly(const LengthBox& a, const LengthBox& b, const Length& width)
459 {
460     // If any unit types are different, then we can't guarantee
461     // that this was just a movement.
462     if (a.left().type() != b.left().type()
463         || a.right().type() != b.right().type()
464         || a.top().type() != b.top().type()
465         || a.bottom().type() != b.bottom().type())
466         return false;
467
468     // Only one unit can be non-auto in the horizontal direction and
469     // in the vertical direction.  Otherwise the adjustment of values
470     // is changing the size of the box.
471     if (!a.left().isIntrinsicOrAuto() && !a.right().isIntrinsicOrAuto())
472         return false;
473     if (!a.top().isIntrinsicOrAuto() && !a.bottom().isIntrinsicOrAuto())
474         return false;
475     // If our width is auto and left or right is specified then this 
476     // is not just a movement - we need to resize to our container.
477     if ((!a.left().isIntrinsicOrAuto() || !a.right().isIntrinsicOrAuto()) && width.isIntrinsicOrAuto())
478         return false;
479
480     // One of the units is fixed or percent in both directions and stayed
481     // that way in the new style.  Therefore all we are doing is moving.
482     return true;
483 }
484
485 inline bool RenderStyle::changeAffectsVisualOverflow(const RenderStyle& other) const
486 {
487     if (m_rareNonInheritedData.get() != other.m_rareNonInheritedData.get()
488         && !arePointingToEqualData(m_rareNonInheritedData->boxShadow, other.m_rareNonInheritedData->boxShadow))
489         return true;
490
491     if (m_rareInheritedData.get() != other.m_rareInheritedData.get()
492         && !arePointingToEqualData(m_rareInheritedData->textShadow, other.m_rareInheritedData->textShadow))
493         return true;
494
495     if (m_inheritedFlags.textDecorations != other.m_inheritedFlags.textDecorations
496         || m_visualData->textDecoration != other.m_visualData->textDecoration
497         || m_rareNonInheritedData->textDecorationStyle != other.m_rareNonInheritedData->textDecorationStyle) {
498         // Underlines are always drawn outside of their textbox bounds when text-underline-position: under;
499         // is specified. We can take an early out here.
500         if (textUnderlinePosition() == TextUnderlinePositionUnder
501             || other.textUnderlinePosition() == TextUnderlinePositionUnder)
502             return true;
503         return visualOverflowForDecorations(*this, nullptr) != visualOverflowForDecorations(other, nullptr);
504     }
505
506     if (hasOutlineInVisualOverflow() != other.hasOutlineInVisualOverflow())
507         return true;
508     return false;
509 }
510
511 bool RenderStyle::changeRequiresLayout(const RenderStyle& other, unsigned& changedContextSensitiveProperties) const
512 {
513     if (m_boxData->width() != other.m_boxData->width()
514         || m_boxData->minWidth() != other.m_boxData->minWidth()
515         || m_boxData->maxWidth() != other.m_boxData->maxWidth()
516         || m_boxData->height() != other.m_boxData->height()
517         || m_boxData->minHeight() != other.m_boxData->minHeight()
518         || m_boxData->maxHeight() != other.m_boxData->maxHeight())
519         return true;
520
521     if (m_boxData->verticalAlign() != other.m_boxData->verticalAlign() || m_nonInheritedFlags.verticalAlign() != other.m_nonInheritedFlags.verticalAlign())
522         return true;
523
524     if (m_boxData->boxSizing() != other.m_boxData->boxSizing())
525         return true;
526
527     if (m_surroundData->margin != other.m_surroundData->margin)
528         return true;
529
530     if (m_surroundData->padding != other.m_surroundData->padding)
531         return true;
532
533     // FIXME: We should add an optimized form of layout that just recomputes visual overflow.
534     if (changeAffectsVisualOverflow(other))
535         return true;
536
537     if (m_rareNonInheritedData.get() != other.m_rareNonInheritedData.get()) {
538         if (m_rareNonInheritedData->appearance != other.m_rareNonInheritedData->appearance
539             || m_rareNonInheritedData->marginBeforeCollapse != other.m_rareNonInheritedData->marginBeforeCollapse
540             || m_rareNonInheritedData->marginAfterCollapse != other.m_rareNonInheritedData->marginAfterCollapse
541             || m_rareNonInheritedData->lineClamp != other.m_rareNonInheritedData->lineClamp
542             || m_rareNonInheritedData->initialLetter != other.m_rareNonInheritedData->initialLetter
543             || m_rareNonInheritedData->textOverflow != other.m_rareNonInheritedData->textOverflow)
544             return true;
545
546         if (m_rareNonInheritedData->regionFragment != other.m_rareNonInheritedData->regionFragment)
547             return true;
548
549         if (m_rareNonInheritedData->shapeMargin != other.m_rareNonInheritedData->shapeMargin)
550             return true;
551
552         if (m_rareNonInheritedData->deprecatedFlexibleBox != other.m_rareNonInheritedData->deprecatedFlexibleBox)
553             return true;
554
555         if (m_rareNonInheritedData->flexibleBox != other.m_rareNonInheritedData->flexibleBox)
556             return true;
557
558         if (m_rareNonInheritedData->order != other.m_rareNonInheritedData->order
559             || m_rareNonInheritedData->alignContent != other.m_rareNonInheritedData->alignContent
560             || m_rareNonInheritedData->alignItems != other.m_rareNonInheritedData->alignItems
561             || m_rareNonInheritedData->alignSelf != other.m_rareNonInheritedData->alignSelf
562             || m_rareNonInheritedData->justifyContent != other.m_rareNonInheritedData->justifyContent
563             || m_rareNonInheritedData->justifyItems != other.m_rareNonInheritedData->justifyItems
564             || m_rareNonInheritedData->justifySelf != other.m_rareNonInheritedData->justifySelf)
565             return true;
566
567         if (!arePointingToEqualData(m_rareNonInheritedData->boxReflect, other.m_rareNonInheritedData->boxReflect))
568             return true;
569
570         if (m_rareNonInheritedData->multiCol != other.m_rareNonInheritedData->multiCol)
571             return true;
572
573         if (m_rareNonInheritedData->transform != other.m_rareNonInheritedData->transform) {
574             if (m_rareNonInheritedData->transform->hasTransform() != other.m_rareNonInheritedData->transform->hasTransform())
575                 return true;
576             if (*m_rareNonInheritedData->transform != *other.m_rareNonInheritedData->transform) {
577                 changedContextSensitiveProperties |= ContextSensitivePropertyTransform;
578                 // Don't return; keep looking for another change
579             }
580         }
581
582         if (m_rareNonInheritedData->grid != other.m_rareNonInheritedData->grid
583             || m_rareNonInheritedData->gridItem != other.m_rareNonInheritedData->gridItem)
584             return true;
585
586 #if ENABLE(DASHBOARD_SUPPORT)
587         // If regions change, trigger a relayout to re-calc regions.
588         if (m_rareNonInheritedData->dashboardRegions != other.m_rareNonInheritedData->dashboardRegions)
589             return true;
590 #endif
591
592         if (!arePointingToEqualData(m_rareNonInheritedData->willChange, other.m_rareNonInheritedData->willChange)) {
593             changedContextSensitiveProperties |= ContextSensitivePropertyWillChange;
594             // Don't return; keep looking for another change
595         }
596     }
597
598     if (m_rareInheritedData.get() != other.m_rareInheritedData.get()) {
599         if (m_rareInheritedData->indent != other.m_rareInheritedData->indent
600 #if ENABLE(CSS3_TEXT)
601             || m_rareInheritedData->textAlignLast != other.m_rareInheritedData->textAlignLast
602             || m_rareInheritedData->textJustify != other.m_rareInheritedData->textJustify
603             || m_rareInheritedData->textIndentLine != other.m_rareInheritedData->textIndentLine
604 #endif
605             || m_rareInheritedData->effectiveZoom != other.m_rareInheritedData->effectiveZoom
606             || m_rareInheritedData->textZoom != other.m_rareInheritedData->textZoom
607 #if ENABLE(TEXT_AUTOSIZING)
608             || m_rareInheritedData->textSizeAdjust != other.m_rareInheritedData->textSizeAdjust
609 #endif
610             || m_rareInheritedData->wordBreak != other.m_rareInheritedData->wordBreak
611             || m_rareInheritedData->overflowWrap != other.m_rareInheritedData->overflowWrap
612             || m_rareInheritedData->nbspMode != other.m_rareInheritedData->nbspMode
613             || m_rareInheritedData->lineBreak != other.m_rareInheritedData->lineBreak
614             || m_rareInheritedData->textSecurity != other.m_rareInheritedData->textSecurity
615             || m_rareInheritedData->hyphens != other.m_rareInheritedData->hyphens
616             || m_rareInheritedData->hyphenationLimitBefore != other.m_rareInheritedData->hyphenationLimitBefore
617             || m_rareInheritedData->hyphenationLimitAfter != other.m_rareInheritedData->hyphenationLimitAfter
618             || m_rareInheritedData->hyphenationString != other.m_rareInheritedData->hyphenationString
619             || m_rareInheritedData->rubyPosition != other.m_rareInheritedData->rubyPosition
620             || m_rareInheritedData->textEmphasisMark != other.m_rareInheritedData->textEmphasisMark
621             || m_rareInheritedData->textEmphasisPosition != other.m_rareInheritedData->textEmphasisPosition
622             || m_rareInheritedData->textEmphasisCustomMark != other.m_rareInheritedData->textEmphasisCustomMark
623             || m_rareInheritedData->textOrientation != other.m_rareInheritedData->textOrientation
624             || m_rareInheritedData->tabSize != other.m_rareInheritedData->tabSize
625             || m_rareInheritedData->lineBoxContain != other.m_rareInheritedData->lineBoxContain
626             || m_rareInheritedData->lineGrid != other.m_rareInheritedData->lineGrid
627 #if ENABLE(CSS_IMAGE_ORIENTATION)
628             || m_rareInheritedData->imageOrientation != other.m_rareInheritedData->imageOrientation
629 #endif
630 #if ENABLE(CSS_IMAGE_RESOLUTION)
631             || m_rareInheritedData->imageResolutionSource != other.m_rareInheritedData->imageResolutionSource
632             || m_rareInheritedData->imageResolutionSnap != other.m_rareInheritedData->imageResolutionSnap
633             || m_rareInheritedData->imageResolution != other.m_rareInheritedData->imageResolution
634 #endif
635             || m_rareInheritedData->lineSnap != other.m_rareInheritedData->lineSnap
636             || m_rareInheritedData->lineAlign != other.m_rareInheritedData->lineAlign
637             || m_rareInheritedData->hangingPunctuation != other.m_rareInheritedData->hangingPunctuation
638 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
639             || m_rareInheritedData->useTouchOverflowScrolling != other.m_rareInheritedData->useTouchOverflowScrolling
640 #endif
641             || m_rareInheritedData->listStyleImage != other.m_rareInheritedData->listStyleImage) // FIXME: needs arePointingToEqualData()?
642             return true;
643
644         if (textStrokeWidth() != other.textStrokeWidth())
645             return true;
646     }
647
648     if (m_inheritedData->lineHeight != other.m_inheritedData->lineHeight
649 #if ENABLE(TEXT_AUTOSIZING)
650         || m_inheritedData->specifiedLineHeight != other.m_inheritedData->specifiedLineHeight
651 #endif
652         || m_inheritedData->fontCascade != other.m_inheritedData->fontCascade
653         || m_inheritedData->horizontalBorderSpacing != other.m_inheritedData->horizontalBorderSpacing
654         || m_inheritedData->verticalBorderSpacing != other.m_inheritedData->verticalBorderSpacing
655         || m_inheritedFlags.boxDirection != other.m_inheritedFlags.boxDirection
656         || m_inheritedFlags.rtlOrdering != other.m_inheritedFlags.rtlOrdering
657         || m_nonInheritedFlags.position() != other.m_nonInheritedFlags.position()
658         || m_nonInheritedFlags.floating() != other.m_nonInheritedFlags.floating()
659         || m_nonInheritedFlags.originalDisplay() != other.m_nonInheritedFlags.originalDisplay())
660         return true;
661
662
663     if ((m_nonInheritedFlags.effectiveDisplay()) >= TABLE) {
664         if (m_inheritedFlags.borderCollapse != other.m_inheritedFlags.borderCollapse
665             || m_inheritedFlags.emptyCells != other.m_inheritedFlags.emptyCells
666             || m_inheritedFlags.captionSide != other.m_inheritedFlags.captionSide
667             || m_nonInheritedFlags.tableLayout() != other.m_nonInheritedFlags.tableLayout())
668             return true;
669
670         // In the collapsing border model, 'hidden' suppresses other borders, while 'none'
671         // does not, so these style differences can be width differences.
672         if (m_inheritedFlags.borderCollapse
673             && ((borderTopStyle() == BHIDDEN && other.borderTopStyle() == BNONE)
674                 || (borderTopStyle() == BNONE && other.borderTopStyle() == BHIDDEN)
675                 || (borderBottomStyle() == BHIDDEN && other.borderBottomStyle() == BNONE)
676                 || (borderBottomStyle() == BNONE && other.borderBottomStyle() == BHIDDEN)
677                 || (borderLeftStyle() == BHIDDEN && other.borderLeftStyle() == BNONE)
678                 || (borderLeftStyle() == BNONE && other.borderLeftStyle() == BHIDDEN)
679                 || (borderRightStyle() == BHIDDEN && other.borderRightStyle() == BNONE)
680                 || (borderRightStyle() == BNONE && other.borderRightStyle() == BHIDDEN)))
681             return true;
682     }
683
684     if (m_nonInheritedFlags.effectiveDisplay() == LIST_ITEM) {
685         if (m_inheritedFlags.listStyleType != other.m_inheritedFlags.listStyleType
686             || m_inheritedFlags.listStylePosition != other.m_inheritedFlags.listStylePosition)
687             return true;
688     }
689
690     if (m_inheritedFlags.textAlign != other.m_inheritedFlags.textAlign
691         || m_inheritedFlags.textTransform != other.m_inheritedFlags.textTransform
692         || m_inheritedFlags.direction != other.m_inheritedFlags.direction
693         || m_inheritedFlags.whiteSpace != other.m_inheritedFlags.whiteSpace
694         || m_nonInheritedFlags.clear() != other.m_nonInheritedFlags.clear()
695         || m_nonInheritedFlags.unicodeBidi() != other.m_nonInheritedFlags.unicodeBidi())
696         return true;
697
698     // Check block flow direction.
699     if (m_inheritedFlags.writingMode != other.m_inheritedFlags.writingMode)
700         return true;
701
702     // Check text combine mode.
703     if (m_rareNonInheritedData->textCombine != other.m_rareNonInheritedData->textCombine)
704         return true;
705
706     // Check breaks.
707     if (m_rareNonInheritedData->breakBefore != other.m_rareNonInheritedData->breakBefore
708         || m_rareNonInheritedData->breakAfter != other.m_rareNonInheritedData->breakAfter
709         || m_rareNonInheritedData->breakInside != other.m_rareNonInheritedData->breakInside)
710         return true;
711
712     // Overflow returns a layout hint.
713     if (m_nonInheritedFlags.overflowX() != other.m_nonInheritedFlags.overflowX()
714         || m_nonInheritedFlags.overflowY() != other.m_nonInheritedFlags.overflowY())
715         return true;
716
717     // If our border widths change, then we need to layout.  Other changes to borders
718     // only necessitate a repaint.
719     if (borderLeftWidth() != other.borderLeftWidth()
720         || borderTopWidth() != other.borderTopWidth()
721         || borderBottomWidth() != other.borderBottomWidth()
722         || borderRightWidth() != other.borderRightWidth())
723         return true;
724
725     // If the counter directives change, trigger a relayout to re-calculate counter values and rebuild the counter node tree.
726     if (!arePointingToEqualData(m_rareNonInheritedData->counterDirectives, other.m_rareNonInheritedData->counterDirectives))
727         return true;
728
729     if ((visibility() == COLLAPSE) != (other.visibility() == COLLAPSE))
730         return true;
731
732     if (m_rareNonInheritedData->hasOpacity() != other.m_rareNonInheritedData->hasOpacity()) {
733         // FIXME: We would like to use SimplifiedLayout here, but we can't quite do that yet.
734         // We need to make sure SimplifiedLayout can operate correctly on RenderInlines (we will need
735         // to add a selfNeedsSimplifiedLayout bit in order to not get confused and taint every line).
736         // In addition we need to solve the floating object issue when layers come and go. Right now
737         // a full layout is necessary to keep floating object lists sane.
738         return true;
739     }
740
741     if (m_rareNonInheritedData->hasFilters() != other.m_rareNonInheritedData->hasFilters())
742         return true;
743
744 #if ENABLE(FILTERS_LEVEL_2)
745     if (m_rareNonInheritedData->hasBackdropFilters() != other.m_rareNonInheritedData->hasBackdropFilters())
746         return true;
747 #endif
748
749     if (!arePointingToEqualData(m_rareInheritedData->quotes, other.m_rareInheritedData->quotes))
750         return true;
751
752     if (position() != StaticPosition) {
753         if (m_surroundData->offset != other.m_surroundData->offset) {
754             // FIXME: We would like to use SimplifiedLayout for relative positioning, but we can't quite do that yet.
755             // We need to make sure SimplifiedLayout can operate correctly on RenderInlines (we will need
756             // to add a selfNeedsSimplifiedLayout bit in order to not get confused and taint every line).
757             if (position() != AbsolutePosition)
758                 return true;
759
760             // Optimize for the case where a positioned layer is moving but not changing size.
761             if (!positionChangeIsMovementOnly(m_surroundData->offset, other.m_surroundData->offset, m_boxData->width()))
762                 return true;
763         }
764     }
765
766     bool hasFirstLineStyle = hasPseudoStyle(FIRST_LINE);
767     if (hasFirstLineStyle != other.hasPseudoStyle(FIRST_LINE))
768         return true;
769     if (hasFirstLineStyle) {
770         auto* firstLineStyle = getCachedPseudoStyle(FIRST_LINE);
771         if (!firstLineStyle)
772             return true;
773         auto* otherFirstLineStyle = other.getCachedPseudoStyle(FIRST_LINE);
774         if (!otherFirstLineStyle)
775             return true;
776         // FIXME: Not all first line style changes actually need layout.
777         if (*firstLineStyle != *otherFirstLineStyle)
778             return true;
779     }
780
781     return false;
782 }
783
784 bool RenderStyle::changeRequiresPositionedLayoutOnly(const RenderStyle& other, unsigned&) const
785 {
786     if (position() == StaticPosition)
787         return false;
788
789     if (m_surroundData->offset != other.m_surroundData->offset) {
790         // Optimize for the case where a positioned layer is moving but not changing size.
791         if (position() == AbsolutePosition && positionChangeIsMovementOnly(m_surroundData->offset, other.m_surroundData->offset, m_boxData->width()))
792             return true;
793     }
794     
795     return false;
796 }
797
798 bool RenderStyle::changeRequiresLayerRepaint(const RenderStyle& other, unsigned& changedContextSensitiveProperties) const
799 {
800     // StyleResolver has ensured that zIndex is non-auto only if it's applicable.
801     if (m_boxData->zIndex() != other.m_boxData->zIndex() || m_boxData->hasAutoZIndex() != other.m_boxData->hasAutoZIndex())
802         return true;
803
804     if (position() != StaticPosition) {
805         if (m_visualData->clip != other.m_visualData->clip || m_visualData->hasClip != other.m_visualData->hasClip) {
806             changedContextSensitiveProperties |= ContextSensitivePropertyClipRect;
807             return true;
808         }
809     }
810
811 #if ENABLE(CSS_COMPOSITING)
812     if (m_rareNonInheritedData->effectiveBlendMode != other.m_rareNonInheritedData->effectiveBlendMode)
813         return true;
814 #endif
815
816     if (m_rareNonInheritedData->opacity != other.m_rareNonInheritedData->opacity) {
817         changedContextSensitiveProperties |= ContextSensitivePropertyOpacity;
818         // Don't return; keep looking for another change.
819     }
820
821     if (m_rareNonInheritedData->filter != other.m_rareNonInheritedData->filter) {
822         changedContextSensitiveProperties |= ContextSensitivePropertyFilter;
823         // Don't return; keep looking for another change.
824     }
825
826 #if ENABLE(FILTERS_LEVEL_2)
827     if (m_rareNonInheritedData->backdropFilter != other.m_rareNonInheritedData->backdropFilter) {
828         changedContextSensitiveProperties |= ContextSensitivePropertyFilter;
829         // Don't return; keep looking for another change.
830     }
831 #endif
832
833     if (m_rareNonInheritedData->mask != other.m_rareNonInheritedData->mask
834         || m_rareNonInheritedData->maskBoxImage != other.m_rareNonInheritedData->maskBoxImage)
835         return true;
836
837     return false;
838 }
839
840 bool RenderStyle::changeRequiresRepaint(const RenderStyle& other, unsigned& changedContextSensitiveProperties) const
841 {
842     if (m_inheritedFlags.visibility != other.m_inheritedFlags.visibility
843         || m_inheritedFlags.printColorAdjust != other.m_inheritedFlags.printColorAdjust
844         || m_inheritedFlags.insideLink != other.m_inheritedFlags.insideLink
845         || m_inheritedFlags.insideDefaultButton != other.m_inheritedFlags.insideDefaultButton
846         || m_surroundData->border != other.m_surroundData->border
847         || !m_backgroundData->isEquivalentForPainting(*other.m_backgroundData)
848         || m_rareInheritedData->userModify != other.m_rareInheritedData->userModify
849         || m_rareInheritedData->userSelect != other.m_rareInheritedData->userSelect
850         || m_rareNonInheritedData->userDrag != other.m_rareNonInheritedData->userDrag
851         || m_rareNonInheritedData->borderFit != other.m_rareNonInheritedData->borderFit
852         || m_rareNonInheritedData->objectFit != other.m_rareNonInheritedData->objectFit
853         || m_rareNonInheritedData->objectPosition != other.m_rareNonInheritedData->objectPosition
854         || m_rareInheritedData->imageRendering != other.m_rareInheritedData->imageRendering)
855         return true;
856
857     if (m_rareNonInheritedData->shapeOutside != other.m_rareNonInheritedData->shapeOutside)
858         return true;
859
860     // FIXME: this should probably be moved to changeRequiresLayerRepaint().
861     if (m_rareNonInheritedData->clipPath != other.m_rareNonInheritedData->clipPath) {
862         changedContextSensitiveProperties |= ContextSensitivePropertyClipPath;
863         // Don't return; keep looking for another change.
864     }
865
866     return false;
867 }
868
869 bool RenderStyle::changeRequiresRepaintIfTextOrBorderOrOutline(const RenderStyle& other, unsigned&) const
870 {
871     if (m_inheritedData->color != other.m_inheritedData->color
872         || m_inheritedFlags.textDecorations != other.m_inheritedFlags.textDecorations
873         || m_visualData->textDecoration != other.m_visualData->textDecoration
874         || m_rareNonInheritedData->textDecorationStyle != other.m_rareNonInheritedData->textDecorationStyle
875         || m_rareNonInheritedData->textDecorationColor != other.m_rareNonInheritedData->textDecorationColor
876         || m_rareInheritedData->textDecorationSkip != other.m_rareInheritedData->textDecorationSkip
877         || m_rareInheritedData->textFillColor != other.m_rareInheritedData->textFillColor
878         || m_rareInheritedData->textStrokeColor != other.m_rareInheritedData->textStrokeColor
879         || m_rareInheritedData->textEmphasisColor != other.m_rareInheritedData->textEmphasisColor
880         || m_rareInheritedData->textEmphasisFill != other.m_rareInheritedData->textEmphasisFill)
881         return true;
882
883     return false;
884 }
885
886 bool RenderStyle::changeRequiresRecompositeLayer(const RenderStyle& other, unsigned&) const
887 {
888     if (m_rareNonInheritedData.get() != other.m_rareNonInheritedData.get()) {
889         if (m_rareNonInheritedData->transformStyle3D != other.m_rareNonInheritedData->transformStyle3D
890             || m_rareNonInheritedData->backfaceVisibility != other.m_rareNonInheritedData->backfaceVisibility
891             || m_rareNonInheritedData->perspective != other.m_rareNonInheritedData->perspective
892             || m_rareNonInheritedData->perspectiveOriginX != other.m_rareNonInheritedData->perspectiveOriginX
893             || m_rareNonInheritedData->perspectiveOriginY != other.m_rareNonInheritedData->perspectiveOriginY)
894             return true;
895     }
896
897     return false;
898 }
899
900 StyleDifference RenderStyle::diff(const RenderStyle& other, unsigned& changedContextSensitiveProperties) const
901 {
902     changedContextSensitiveProperties = ContextSensitivePropertyNone;
903
904     StyleDifference svgChange = StyleDifferenceEqual;
905     if (m_svgStyle != other.m_svgStyle) {
906         svgChange = m_svgStyle->diff(other.m_svgStyle.get());
907         if (svgChange == StyleDifferenceLayout)
908             return svgChange;
909     }
910
911     // These properties affect the cached stroke bounding box rects.
912     if (m_rareInheritedData->capStyle != other.m_rareInheritedData->capStyle
913         || m_rareInheritedData->joinStyle != other.m_rareInheritedData->joinStyle
914         || m_rareInheritedData->strokeWidth != other.m_rareInheritedData->strokeWidth)
915         return StyleDifferenceLayout;
916
917     if (changeRequiresLayout(other, changedContextSensitiveProperties))
918         return StyleDifferenceLayout;
919
920     // SVGRenderStyle::diff() might have returned StyleDifferenceRepaint, eg. if fill changes.
921     // If eg. the font-size changed at the same time, we're not allowed to return StyleDifferenceRepaint,
922     // but have to return StyleDifferenceLayout, that's why  this if branch comes after all branches
923     // that are relevant for SVG and might return StyleDifferenceLayout.
924     if (svgChange != StyleDifferenceEqual)
925         return svgChange;
926
927     if (changeRequiresPositionedLayoutOnly(other, changedContextSensitiveProperties))
928         return StyleDifferenceLayoutPositionedMovementOnly;
929
930     if (changeRequiresLayerRepaint(other, changedContextSensitiveProperties))
931         return StyleDifferenceRepaintLayer;
932
933     if (changeRequiresRepaint(other, changedContextSensitiveProperties))
934         return StyleDifferenceRepaint;
935
936     if (changeRequiresRecompositeLayer(other, changedContextSensitiveProperties))
937         return StyleDifferenceRecompositeLayer;
938
939     if (changeRequiresRepaintIfTextOrBorderOrOutline(other, changedContextSensitiveProperties))
940         return StyleDifferenceRepaintIfTextOrBorderOrOutline;
941
942     // Cursors are not checked, since they will be set appropriately in response to mouse events,
943     // so they don't need to cause any repaint or layout.
944
945     // Animations don't need to be checked either.  We always set the new style on the RenderObject, so we will get a chance to fire off
946     // the resulting transition properly.
947     return StyleDifferenceEqual;
948 }
949
950 bool RenderStyle::diffRequiresLayerRepaint(const RenderStyle& style, bool isComposited) const
951 {
952     unsigned changedContextSensitiveProperties = 0;
953
954     if (changeRequiresRepaint(style, changedContextSensitiveProperties))
955         return true;
956
957     if (isComposited && changeRequiresLayerRepaint(style, changedContextSensitiveProperties))
958         return changedContextSensitiveProperties & ContextSensitivePropertyClipRect;
959
960     return false;
961 }
962
963 void RenderStyle::setClip(Length&& top, Length&& right, Length&& bottom, Length&& left)
964 {
965     auto& data = m_visualData.access();
966     data.clip.top() = WTFMove(top);
967     data.clip.right() = WTFMove(right);
968     data.clip.bottom() = WTFMove(bottom);
969     data.clip.left() = WTFMove(left);
970 }
971
972 void RenderStyle::addCursor(RefPtr<StyleImage>&& image, const IntPoint& hotSpot)
973 {
974     auto& cursorData = m_rareInheritedData.access().cursorData;
975     if (!cursorData)
976         cursorData = CursorList::create();
977     cursorData->append(CursorData(WTFMove(image), hotSpot));
978 }
979
980 void RenderStyle::setCursorList(RefPtr<CursorList>&& list)
981 {
982     m_rareInheritedData.access().cursorData = WTFMove(list);
983 }
984
985 void RenderStyle::setQuotes(RefPtr<QuotesData>&& q)
986 {
987     if (m_rareInheritedData->quotes == q || (m_rareInheritedData->quotes && q && *m_rareInheritedData->quotes == *q))
988         return;
989
990     m_rareInheritedData.access().quotes = WTFMove(q);
991 }
992
993 void RenderStyle::setWillChange(RefPtr<WillChangeData>&& willChangeData)
994 {
995     if (arePointingToEqualData(m_rareNonInheritedData->willChange.get(), willChangeData.get()))
996         return;
997
998     m_rareNonInheritedData.access().willChange = WTFMove(willChangeData);
999 }
1000
1001 void RenderStyle::clearCursorList()
1002 {
1003     if (m_rareInheritedData->cursorData)
1004         m_rareInheritedData.access().cursorData = nullptr;
1005 }
1006
1007 void RenderStyle::clearContent()
1008 {
1009     if (m_rareNonInheritedData->content)
1010         m_rareNonInheritedData.access().content = nullptr;
1011 }
1012
1013 static inline ContentData& lastContent(ContentData& firstContent)
1014 {
1015     auto* lastContent = &firstContent;
1016     for (auto* content = &firstContent; content; content = content->next())
1017         lastContent = content;
1018     return *lastContent;
1019 }
1020
1021 void RenderStyle::setContent(std::unique_ptr<ContentData> contentData, bool add)
1022 {
1023     auto& data = m_rareNonInheritedData.access();
1024     if (add && data.content)
1025         lastContent(*data.content).setNext(WTFMove(contentData));
1026     else {
1027         data.content = WTFMove(contentData);
1028         auto& altText = data.altText;
1029         if (!altText.isNull())
1030             data.content->setAltText(altText);
1031     }
1032 }
1033
1034 void RenderStyle::setContent(RefPtr<StyleImage>&& image, bool add)
1035 {
1036     if (!image)
1037         return;
1038     setContent(std::make_unique<ImageContentData>(image.releaseNonNull()), add);
1039 }
1040
1041 void RenderStyle::setContent(const String& string, bool add)
1042 {
1043     auto& data = m_rareNonInheritedData.access();
1044     if (add && data.content) {
1045         auto& last = lastContent(*data.content);
1046         if (!is<TextContentData>(last))
1047             last.setNext(std::make_unique<TextContentData>(string));
1048         else {
1049             auto& textContent = downcast<TextContentData>(last);
1050             textContent.setText(textContent.text() + string);
1051         }
1052     } else {
1053         data.content = std::make_unique<TextContentData>(string);
1054         auto& altText = data.altText;
1055         if (!altText.isNull())
1056             data.content->setAltText(altText);
1057     }
1058 }
1059
1060 void RenderStyle::setContent(std::unique_ptr<CounterContent> counter, bool add)
1061 {
1062     if (!counter)
1063         return;
1064     setContent(std::make_unique<CounterContentData>(WTFMove(counter)), add);
1065 }
1066
1067 void RenderStyle::setContent(QuoteType quote, bool add)
1068 {
1069     setContent(std::make_unique<QuoteContentData>(quote), add);
1070 }
1071
1072 void RenderStyle::setContentAltText(const String& string)
1073 {
1074     auto& data = m_rareNonInheritedData.access();
1075     data.altText = string;
1076     if (data.content)
1077         data.content->setAltText(string);
1078 }
1079
1080 const String& RenderStyle::contentAltText() const
1081 {
1082     return m_rareNonInheritedData->altText;
1083 }
1084
1085 void RenderStyle::setHasAttrContent()
1086 {
1087     setUnique();
1088     SET_VAR(m_rareNonInheritedData, hasAttrContent, true);
1089 }
1090
1091 static inline bool requireTransformOrigin(const Vector<RefPtr<TransformOperation>>& transformOperations, RenderStyle::ApplyTransformOrigin applyOrigin)
1092 {
1093     // The transform-origin property brackets the transform with translate operations.
1094     // When the only transform is a translation, the transform-origin is irrelevant.
1095
1096     if (applyOrigin != RenderStyle::IncludeTransformOrigin)
1097         return false;
1098
1099     for (auto& operation : transformOperations) {
1100         // FIXME: Use affectedByTransformOrigin().
1101         auto type = operation->type();
1102         if (type != TransformOperation::TRANSLATE
1103             && type != TransformOperation::TRANSLATE_3D
1104             && type != TransformOperation::TRANSLATE_X
1105             && type != TransformOperation::TRANSLATE_Y
1106             && type != TransformOperation::TRANSLATE_Z)
1107             return true;
1108     }
1109
1110     return false;
1111 }
1112
1113 void RenderStyle::applyTransform(TransformationMatrix& transform, const FloatRect& boundingBox, ApplyTransformOrigin applyOrigin) const
1114 {
1115     auto& operations = m_rareNonInheritedData->transform->operations.operations();
1116     bool applyTransformOrigin = requireTransformOrigin(operations, applyOrigin);
1117
1118     float offsetX = transformOriginX().isPercent() ? boundingBox.x() : 0;
1119     float offsetY = transformOriginY().isPercent() ? boundingBox.y() : 0;
1120
1121     if (applyTransformOrigin) {
1122         transform.translate3d(floatValueForLength(transformOriginX(), boundingBox.width()) + offsetX,
1123                               floatValueForLength(transformOriginY(), boundingBox.height()) + offsetY,
1124                               transformOriginZ());
1125     }
1126
1127     for (auto& operation : operations)
1128         operation->apply(transform, boundingBox.size());
1129
1130     if (applyTransformOrigin) {
1131         transform.translate3d(-floatValueForLength(transformOriginX(), boundingBox.width()) - offsetX,
1132                               -floatValueForLength(transformOriginY(), boundingBox.height()) - offsetY,
1133                               -transformOriginZ());
1134     }
1135 }
1136
1137 void RenderStyle::setPageScaleTransform(float scale)
1138 {
1139     if (scale == 1)
1140         return;
1141     TransformOperations transform;
1142     transform.operations().append(ScaleTransformOperation::create(scale, scale, ScaleTransformOperation::SCALE));
1143     setTransform(transform);
1144     setTransformOriginX(Length(0, Fixed));
1145     setTransformOriginY(Length(0, Fixed));
1146 }
1147
1148 void RenderStyle::setTextShadow(std::unique_ptr<ShadowData> shadowData, bool add)
1149 {
1150     ASSERT(!shadowData || (!shadowData->spread() && shadowData->style() == Normal));
1151
1152     auto& rareData = m_rareInheritedData.access();
1153     if (!add) {
1154         rareData.textShadow = WTFMove(shadowData);
1155         return;
1156     }
1157
1158     shadowData->setNext(WTFMove(rareData.textShadow));
1159     rareData.textShadow = WTFMove(shadowData);
1160 }
1161
1162 void RenderStyle::setBoxShadow(std::unique_ptr<ShadowData> shadowData, bool add)
1163 {
1164     auto& rareData = m_rareNonInheritedData.access();
1165     if (!add) {
1166         rareData.boxShadow = WTFMove(shadowData);
1167         return;
1168     }
1169
1170     shadowData->setNext(WTFMove(rareData.boxShadow));
1171     rareData.boxShadow = WTFMove(shadowData);
1172 }
1173
1174 static RoundedRect::Radii calcRadiiFor(const BorderData& border, const LayoutSize& size)
1175 {
1176     return {
1177         sizeForLengthSize(border.topLeft(), size),
1178         sizeForLengthSize(border.topRight(), size),
1179         sizeForLengthSize(border.bottomLeft(), size),
1180         sizeForLengthSize(border.bottomRight(), size)
1181     };
1182 }
1183
1184 StyleImage* RenderStyle::listStyleImage() const { return m_rareInheritedData->listStyleImage.get(); }
1185
1186 void RenderStyle::setListStyleImage(RefPtr<StyleImage>&& v)
1187 {
1188     if (m_rareInheritedData->listStyleImage != v)
1189         m_rareInheritedData.access().listStyleImage = WTFMove(v);
1190 }
1191
1192 const Color& RenderStyle::color() const
1193 {
1194     return m_inheritedData->color;
1195 }
1196
1197 const Color& RenderStyle::visitedLinkColor() const
1198 {
1199     return m_inheritedData->visitedLinkColor;
1200 }
1201
1202 void RenderStyle::setColor(const Color& v)
1203 {
1204     SET_VAR(m_inheritedData, color, v);
1205 }
1206
1207 void RenderStyle::setVisitedLinkColor(const Color& v)
1208 {
1209     SET_VAR(m_inheritedData, visitedLinkColor, v);
1210 }
1211
1212 float RenderStyle::horizontalBorderSpacing() const
1213 {
1214     return m_inheritedData->horizontalBorderSpacing;
1215 }
1216
1217 float RenderStyle::verticalBorderSpacing() const
1218 {
1219     return m_inheritedData->verticalBorderSpacing;
1220 }
1221
1222 void RenderStyle::setHorizontalBorderSpacing(float v)
1223 {
1224     SET_VAR(m_inheritedData, horizontalBorderSpacing, v);
1225 }
1226
1227 void RenderStyle::setVerticalBorderSpacing(float v)
1228 {
1229     SET_VAR(m_inheritedData, verticalBorderSpacing, v);
1230 }
1231
1232 RoundedRect RenderStyle::getRoundedBorderFor(const LayoutRect& borderRect, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
1233 {
1234     RoundedRect roundedRect(borderRect);
1235     if (hasBorderRadius()) {
1236         RoundedRect::Radii radii = calcRadiiFor(m_surroundData->border, borderRect.size());
1237         radii.scale(calcBorderRadiiConstraintScaleFor(borderRect, radii));
1238         roundedRect.includeLogicalEdges(radii, isHorizontalWritingMode(), includeLogicalLeftEdge, includeLogicalRightEdge);
1239     }
1240     return roundedRect;
1241 }
1242
1243 RoundedRect RenderStyle::getRoundedInnerBorderFor(const LayoutRect& borderRect, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
1244 {
1245     bool horizontal = isHorizontalWritingMode();
1246     auto leftWidth = (!horizontal || includeLogicalLeftEdge) ? borderLeftWidth() : 0;
1247     auto rightWidth = (!horizontal || includeLogicalRightEdge) ? borderRightWidth() : 0;
1248     auto topWidth = (horizontal || includeLogicalLeftEdge) ? borderTopWidth() : 0;
1249     auto bottomWidth = (horizontal || includeLogicalRightEdge) ? borderBottomWidth() : 0;
1250     return getRoundedInnerBorderFor(borderRect, topWidth, bottomWidth, leftWidth, rightWidth, includeLogicalLeftEdge, includeLogicalRightEdge);
1251 }
1252
1253 RoundedRect RenderStyle::getRoundedInnerBorderFor(const LayoutRect& borderRect, LayoutUnit topWidth, LayoutUnit bottomWidth,
1254     LayoutUnit leftWidth, LayoutUnit rightWidth, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
1255 {
1256     RoundedRect roundedRect { { borderRect.x() + leftWidth, borderRect.y() + topWidth,
1257         borderRect.width() - leftWidth - rightWidth, borderRect.height() - topWidth - bottomWidth } };
1258     if (hasBorderRadius()) {
1259         auto radii = getRoundedBorderFor(borderRect).radii();
1260         radii.shrink(topWidth, bottomWidth, leftWidth, rightWidth);
1261         roundedRect.includeLogicalEdges(radii, isHorizontalWritingMode(), includeLogicalLeftEdge, includeLogicalRightEdge);
1262     }
1263     return roundedRect;
1264 }
1265
1266 static bool allLayersAreFixed(const FillLayer& layers)
1267 {
1268     for (auto* layer = &layers; layer; layer = layer->next()) {
1269         if (!(layer->image() && layer->attachment() == FixedBackgroundAttachment))
1270             return false;
1271     }
1272     return true;
1273 }
1274
1275 bool RenderStyle::hasEntirelyFixedBackground() const
1276 {
1277     return allLayersAreFixed(backgroundLayers());
1278 }
1279
1280 const CounterDirectiveMap* RenderStyle::counterDirectives() const
1281 {
1282     return m_rareNonInheritedData->counterDirectives.get();
1283 }
1284
1285 CounterDirectiveMap& RenderStyle::accessCounterDirectives()
1286 {
1287     auto& map = m_rareNonInheritedData.access().counterDirectives;
1288     if (!map)
1289         map = std::make_unique<CounterDirectiveMap>();
1290     return *map;
1291 }
1292
1293 const CounterDirectives RenderStyle::getCounterDirectives(const AtomicString& identifier) const
1294 {
1295     if (const CounterDirectiveMap* directives = counterDirectives())
1296         return directives->get(identifier);
1297     return CounterDirectives();
1298 }
1299
1300 const AtomicString& RenderStyle::hyphenString() const
1301 {
1302     ASSERT(hyphens() != HyphensNone);
1303
1304     auto& hyphenationString = m_rareInheritedData->hyphenationString;
1305     if (!hyphenationString.isNull())
1306         return hyphenationString;
1307
1308     // FIXME: This should depend on locale.
1309     static NeverDestroyed<AtomicString> hyphenMinusString(&hyphenMinus, 1);
1310     static NeverDestroyed<AtomicString> hyphenString(&hyphen, 1);
1311     return fontCascade().primaryFont().glyphForCharacter(hyphen) ? hyphenString : hyphenMinusString;
1312 }
1313
1314 const AtomicString& RenderStyle::textEmphasisMarkString() const
1315 {
1316     switch (textEmphasisMark()) {
1317     case TextEmphasisMarkNone:
1318         return nullAtom;
1319     case TextEmphasisMarkCustom:
1320         return textEmphasisCustomMark();
1321     case TextEmphasisMarkDot: {
1322         static NeverDestroyed<AtomicString> filledDotString(&bullet, 1);
1323         static NeverDestroyed<AtomicString> openDotString(&whiteBullet, 1);
1324         return textEmphasisFill() == TextEmphasisFillFilled ? filledDotString : openDotString;
1325     }
1326     case TextEmphasisMarkCircle: {
1327         static NeverDestroyed<AtomicString> filledCircleString(&blackCircle, 1);
1328         static NeverDestroyed<AtomicString> openCircleString(&whiteCircle, 1);
1329         return textEmphasisFill() == TextEmphasisFillFilled ? filledCircleString : openCircleString;
1330     }
1331     case TextEmphasisMarkDoubleCircle: {
1332         static NeverDestroyed<AtomicString> filledDoubleCircleString(&fisheye, 1);
1333         static NeverDestroyed<AtomicString> openDoubleCircleString(&bullseye, 1);
1334         return textEmphasisFill() == TextEmphasisFillFilled ? filledDoubleCircleString : openDoubleCircleString;
1335     }
1336     case TextEmphasisMarkTriangle: {
1337         static NeverDestroyed<AtomicString> filledTriangleString(&blackUpPointingTriangle, 1);
1338         static NeverDestroyed<AtomicString> openTriangleString(&whiteUpPointingTriangle, 1);
1339         return textEmphasisFill() == TextEmphasisFillFilled ? filledTriangleString : openTriangleString;
1340     }
1341     case TextEmphasisMarkSesame: {
1342         static NeverDestroyed<AtomicString> filledSesameString(&sesameDot, 1);
1343         static NeverDestroyed<AtomicString> openSesameString(&whiteSesameDot, 1);
1344         return textEmphasisFill() == TextEmphasisFillFilled ? filledSesameString : openSesameString;
1345     }
1346     case TextEmphasisMarkAuto:
1347         ASSERT_NOT_REACHED();
1348         return nullAtom;
1349     }
1350
1351     ASSERT_NOT_REACHED();
1352     return nullAtom;
1353 }
1354
1355 #if ENABLE(DASHBOARD_SUPPORT)
1356
1357 const Vector<StyleDashboardRegion>& RenderStyle::initialDashboardRegions()
1358 {
1359     static NeverDestroyed<Vector<StyleDashboardRegion>> emptyList;
1360     return emptyList;
1361 }
1362
1363 const Vector<StyleDashboardRegion>& RenderStyle::noneDashboardRegions()
1364 {
1365     static NeverDestroyed<Vector<StyleDashboardRegion>> noneList;
1366     static bool noneListInitialized = false;
1367     if (!noneListInitialized) {
1368         noneList.get().append(StyleDashboardRegion { emptyString(), { }, StyleDashboardRegion::None });
1369         noneListInitialized = true;
1370     }
1371     return noneList;
1372 }
1373
1374 #endif
1375
1376 void RenderStyle::adjustAnimations()
1377 {
1378     auto* animationList = m_rareNonInheritedData->animations.get();
1379     if (!animationList)
1380         return;
1381
1382     // Get rid of empty animations and anything beyond them
1383     for (size_t i = 0, size = animationList->size(); i < size; ++i) {
1384         if (animationList->animation(i).isEmpty()) {
1385             animationList->resize(i);
1386             break;
1387         }
1388     }
1389
1390     if (animationList->isEmpty()) {
1391         clearAnimations();
1392         return;
1393     }
1394
1395     // Repeat patterns into layers that don't have some properties set.
1396     animationList->fillUnsetProperties();
1397 }
1398
1399 void RenderStyle::adjustTransitions()
1400 {
1401     auto* transitionList = m_rareNonInheritedData->transitions.get();
1402     if (!transitionList)
1403         return;
1404
1405     // Get rid of empty transitions and anything beyond them
1406     for (size_t i = 0, size = transitionList->size(); i < size; ++i) {
1407         if (transitionList->animation(i).isEmpty()) {
1408             transitionList->resize(i);
1409             break;
1410         }
1411     }
1412
1413     if (transitionList->isEmpty()) {
1414         clearTransitions();
1415         return;
1416     }
1417
1418     // Repeat patterns into layers that don't have some properties set.
1419     transitionList->fillUnsetProperties();
1420
1421     // Make sure there are no duplicate properties.
1422     // This is an O(n^2) algorithm but the lists tend to be short, so it is probably OK.
1423     for (size_t i = 0; i < transitionList->size(); ++i) {
1424         for (size_t j = i + 1; j < transitionList->size(); ++j) {
1425             if (transitionList->animation(i).property() == transitionList->animation(j).property()) {
1426                 // toss i
1427                 transitionList->remove(i);
1428                 j = i;
1429             }
1430         }
1431     }
1432 }
1433
1434 AnimationList& RenderStyle::ensureAnimations()
1435 {
1436     if (!m_rareNonInheritedData.access().animations)
1437         m_rareNonInheritedData.access().animations = std::make_unique<AnimationList>();
1438     return *m_rareNonInheritedData->animations;
1439 }
1440
1441 AnimationList& RenderStyle::ensureTransitions()
1442 {
1443     if (!m_rareNonInheritedData.access().transitions)
1444         m_rareNonInheritedData.access().transitions = std::make_unique<AnimationList>();
1445     return *m_rareNonInheritedData->transitions;
1446 }
1447
1448 const Animation* RenderStyle::transitionForProperty(CSSPropertyID property) const
1449 {
1450     auto* transitions = this->transitions();
1451     if (!transitions)
1452         return nullptr;
1453     for (size_t i = 0, size = transitions->size(); i < size; ++i) {
1454         auto& animation = transitions->animation(i);
1455         if (animation.animationMode() == Animation::AnimateAll || animation.property() == property)
1456             return &animation;
1457     }
1458     return nullptr;
1459 }
1460
1461 const FontCascade& RenderStyle::fontCascade() const
1462 {
1463     return m_inheritedData->fontCascade;
1464 }
1465
1466 const FontMetrics& RenderStyle::fontMetrics() const
1467 {
1468     return m_inheritedData->fontCascade.fontMetrics();
1469 }
1470
1471 const FontCascadeDescription& RenderStyle::fontDescription() const
1472 {
1473     return m_inheritedData->fontCascade.fontDescription();
1474 }
1475
1476 float RenderStyle::specifiedFontSize() const
1477 {
1478     return fontDescription().specifiedSize();
1479 }
1480
1481 float RenderStyle::computedFontSize() const
1482 {
1483     return fontDescription().computedSize();
1484 }
1485
1486 int RenderStyle::fontSize() const
1487 {
1488     return m_inheritedData->fontCascade.pixelSize();
1489 }
1490
1491 const Length& RenderStyle::wordSpacing() const
1492 {
1493     return m_rareInheritedData->wordSpacing;
1494 }
1495
1496 float RenderStyle::letterSpacing() const
1497 {
1498     return m_inheritedData->fontCascade.letterSpacing();
1499 }
1500
1501 bool RenderStyle::setFontDescription(const FontCascadeDescription& description)
1502 {
1503     if (m_inheritedData->fontCascade.fontDescription() == description)
1504         return false;
1505     auto& cascade = m_inheritedData.access().fontCascade;
1506     cascade = { description, cascade.letterSpacing(), cascade.wordSpacing() };
1507     return true;
1508 }
1509
1510 const Length& RenderStyle::specifiedLineHeight() const
1511 {
1512 #if ENABLE(TEXT_AUTOSIZING)
1513     return m_inheritedData->specifiedLineHeight;
1514 #else
1515     return m_inheritedData->lineHeight;
1516 #endif
1517 }
1518
1519 #if ENABLE(TEXT_AUTOSIZING)
1520
1521 void RenderStyle::setSpecifiedLineHeight(Length&& height)
1522 {
1523     SET_VAR(m_inheritedData, specifiedLineHeight, WTFMove(height));
1524 }
1525
1526 #endif
1527
1528 const Length& RenderStyle::lineHeight() const
1529 {
1530     return m_inheritedData->lineHeight;
1531 }
1532
1533 void RenderStyle::setLineHeight(Length&& height)
1534 {
1535     SET_VAR(m_inheritedData, lineHeight, WTFMove(height));
1536 }
1537
1538 int RenderStyle::computedLineHeight() const
1539 {
1540     const Length& lh = lineHeight();
1541
1542     // Negative value means the line height is not set. Use the font's built-in spacing.
1543     if (lh.isNegative())
1544         return fontMetrics().lineSpacing();
1545
1546     if (lh.isPercentOrCalculated())
1547         return minimumValueForLength(lh, fontSize());
1548
1549     return clampTo<int>(lh.value());
1550 }
1551
1552 void RenderStyle::setWordSpacing(Length&& value)
1553 {
1554     float fontWordSpacing;
1555     switch (value.type()) {
1556     case Auto:
1557         fontWordSpacing = 0;
1558         break;
1559     case Percent:
1560         fontWordSpacing = value.percent() * fontCascade().spaceWidth() / 100;
1561         break;
1562     case Fixed:
1563         fontWordSpacing = value.value();
1564         break;
1565     case Calculated:
1566         fontWordSpacing = value.nonNanCalculatedValue(maxValueForCssLength);
1567         break;
1568     default:
1569         ASSERT_NOT_REACHED();
1570         fontWordSpacing = 0;
1571         break;
1572     }
1573     m_inheritedData.access().fontCascade.setWordSpacing(fontWordSpacing);
1574     m_rareInheritedData.access().wordSpacing = WTFMove(value);
1575 }
1576
1577 void RenderStyle::setLetterSpacing(float v) { m_inheritedData.access().fontCascade.setLetterSpacing(v); }
1578
1579 void RenderStyle::setFontSize(float size)
1580 {
1581     // size must be specifiedSize if Text Autosizing is enabled, but computedSize if text
1582     // zoom is enabled (if neither is enabled it's irrelevant as they're probably the same).
1583
1584     ASSERT(std::isfinite(size));
1585     if (!std::isfinite(size) || size < 0)
1586         size = 0;
1587     else
1588         size = std::min(maximumAllowedFontSize, size);
1589
1590     FontSelector* currentFontSelector = fontCascade().fontSelector();
1591     auto description = fontDescription();
1592     description.setSpecifiedSize(size);
1593     description.setComputedSize(size);
1594
1595     setFontDescription(description);
1596     fontCascade().update(currentFontSelector);
1597 }
1598
1599 #if ENABLE(VARIATION_FONTS)
1600 void RenderStyle::setFontVariationSettings(FontVariationSettings settings)
1601 {
1602     FontSelector* currentFontSelector = fontCascade().fontSelector();
1603     auto description = fontDescription();
1604     description.setVariationSettings(WTFMove(settings));
1605
1606     setFontDescription(description);
1607     fontCascade().update(currentFontSelector);
1608 }
1609 #endif
1610
1611 void RenderStyle::getShadowExtent(const ShadowData* shadow, LayoutUnit& top, LayoutUnit& right, LayoutUnit& bottom, LayoutUnit& left) const
1612 {
1613     top = 0;
1614     right = 0;
1615     bottom = 0;
1616     left = 0;
1617
1618     for ( ; shadow; shadow = shadow->next()) {
1619         if (shadow->style() == Inset)
1620             continue;
1621
1622         int extentAndSpread = shadow->paintingExtent() + shadow->spread();
1623         top = std::min<LayoutUnit>(top, shadow->y() - extentAndSpread);
1624         right = std::max<LayoutUnit>(right, shadow->x() + extentAndSpread);
1625         bottom = std::max<LayoutUnit>(bottom, shadow->y() + extentAndSpread);
1626         left = std::min<LayoutUnit>(left, shadow->x() - extentAndSpread);
1627     }
1628 }
1629
1630 LayoutBoxExtent RenderStyle::getShadowInsetExtent(const ShadowData* shadow) const
1631 {
1632     LayoutUnit top = 0;
1633     LayoutUnit right = 0;
1634     LayoutUnit bottom = 0;
1635     LayoutUnit left = 0;
1636
1637     for ( ; shadow; shadow = shadow->next()) {
1638         if (shadow->style() == Normal)
1639             continue;
1640
1641         int extentAndSpread = shadow->paintingExtent() + shadow->spread();
1642         top = std::max<LayoutUnit>(top, shadow->y() + extentAndSpread);
1643         right = std::min<LayoutUnit>(right, shadow->x() - extentAndSpread);
1644         bottom = std::min<LayoutUnit>(bottom, shadow->y() - extentAndSpread);
1645         left = std::max<LayoutUnit>(left, shadow->x() + extentAndSpread);
1646     }
1647
1648     return LayoutBoxExtent(top, right, bottom, left);
1649 }
1650
1651 void RenderStyle::getShadowHorizontalExtent(const ShadowData* shadow, LayoutUnit &left, LayoutUnit &right) const
1652 {
1653     left = 0;
1654     right = 0;
1655
1656     for ( ; shadow; shadow = shadow->next()) {
1657         if (shadow->style() == Inset)
1658             continue;
1659
1660         int extentAndSpread = shadow->paintingExtent() + shadow->spread();
1661         left = std::min<LayoutUnit>(left, shadow->x() - extentAndSpread);
1662         right = std::max<LayoutUnit>(right, shadow->x() + extentAndSpread);
1663     }
1664 }
1665
1666 void RenderStyle::getShadowVerticalExtent(const ShadowData* shadow, LayoutUnit &top, LayoutUnit &bottom) const
1667 {
1668     top = 0;
1669     bottom = 0;
1670
1671     for ( ; shadow; shadow = shadow->next()) {
1672         if (shadow->style() == Inset)
1673             continue;
1674
1675         int extentAndSpread = shadow->paintingExtent() + shadow->spread();
1676         top = std::min<LayoutUnit>(top, shadow->y() - extentAndSpread);
1677         bottom = std::max<LayoutUnit>(bottom, shadow->y() + extentAndSpread);
1678     }
1679 }
1680
1681 Color RenderStyle::colorIncludingFallback(int colorProperty, bool visitedLink) const
1682 {
1683     Color result;
1684     EBorderStyle borderStyle = BNONE;
1685     switch (colorProperty) {
1686     case CSSPropertyBackgroundColor:
1687         return visitedLink ? visitedLinkBackgroundColor() : backgroundColor(); // Background color doesn't fall back.
1688     case CSSPropertyBorderLeftColor:
1689         result = visitedLink ? visitedLinkBorderLeftColor() : borderLeftColor();
1690         borderStyle = borderLeftStyle();
1691         break;
1692     case CSSPropertyBorderRightColor:
1693         result = visitedLink ? visitedLinkBorderRightColor() : borderRightColor();
1694         borderStyle = borderRightStyle();
1695         break;
1696     case CSSPropertyBorderTopColor:
1697         result = visitedLink ? visitedLinkBorderTopColor() : borderTopColor();
1698         borderStyle = borderTopStyle();
1699         break;
1700     case CSSPropertyBorderBottomColor:
1701         result = visitedLink ? visitedLinkBorderBottomColor() : borderBottomColor();
1702         borderStyle = borderBottomStyle();
1703         break;
1704     case CSSPropertyColor:
1705         result = visitedLink ? visitedLinkColor() : color();
1706         break;
1707     case CSSPropertyOutlineColor:
1708         result = visitedLink ? visitedLinkOutlineColor() : outlineColor();
1709         break;
1710     case CSSPropertyColumnRuleColor:
1711         result = visitedLink ? visitedLinkColumnRuleColor() : columnRuleColor();
1712         break;
1713     case CSSPropertyWebkitTextDecorationColor:
1714         // Text decoration color fallback is handled in RenderObject::decorationColor.
1715         return visitedLink ? visitedLinkTextDecorationColor() : textDecorationColor();
1716     case CSSPropertyWebkitTextEmphasisColor:
1717         result = visitedLink ? visitedLinkTextEmphasisColor() : textEmphasisColor();
1718         break;
1719     case CSSPropertyWebkitTextFillColor:
1720         result = visitedLink ? visitedLinkTextFillColor() : textFillColor();
1721         break;
1722     case CSSPropertyWebkitTextStrokeColor:
1723         result = visitedLink ? visitedLinkTextStrokeColor() : textStrokeColor();
1724         break;
1725     default:
1726         ASSERT_NOT_REACHED();
1727         break;
1728     }
1729
1730     if (!result.isValid()) {
1731         if (!visitedLink && (borderStyle == INSET || borderStyle == OUTSET || borderStyle == RIDGE || borderStyle == GROOVE))
1732             result = Color(238, 238, 238);
1733         else
1734             result = visitedLink ? visitedLinkColor() : color();
1735     }
1736     return result;
1737 }
1738
1739 Color RenderStyle::visitedDependentColor(int colorProperty) const
1740 {
1741     Color unvisitedColor = colorIncludingFallback(colorProperty, false);
1742     if (insideLink() != InsideVisitedLink)
1743         return unvisitedColor;
1744
1745     Color visitedColor = colorIncludingFallback(colorProperty, true);
1746
1747     // Text decoration color validity is preserved (checked in RenderObject::decorationColor).
1748     if (colorProperty == CSSPropertyWebkitTextDecorationColor)
1749         return visitedColor;
1750
1751     // FIXME: Technically someone could explicitly specify the color transparent, but for now we'll just
1752     // assume that if the background color is transparent that it wasn't set. Note that it's weird that
1753     // we're returning unvisited info for a visited link, but given our restriction that the alpha values
1754     // have to match, it makes more sense to return the unvisited background color if specified than it
1755     // does to return black. This behavior matches what Firefox 4 does as well.
1756     if (colorProperty == CSSPropertyBackgroundColor && visitedColor == Color::transparent)
1757         return unvisitedColor;
1758
1759     // Take the alpha from the unvisited color, but get the RGB values from the visited color.
1760     return visitedColor.colorWithAlpha(unvisitedColor.alphaAsFloat());
1761 }
1762
1763 const BorderValue& RenderStyle::borderBefore() const
1764 {
1765     switch (writingMode()) {
1766     case TopToBottomWritingMode:
1767         return borderTop();
1768     case BottomToTopWritingMode:
1769         return borderBottom();
1770     case LeftToRightWritingMode:
1771         return borderLeft();
1772     case RightToLeftWritingMode:
1773         return borderRight();
1774     }
1775     ASSERT_NOT_REACHED();
1776     return borderTop();
1777 }
1778
1779 const BorderValue& RenderStyle::borderAfter() const
1780 {
1781     switch (writingMode()) {
1782     case TopToBottomWritingMode:
1783         return borderBottom();
1784     case BottomToTopWritingMode:
1785         return borderTop();
1786     case LeftToRightWritingMode:
1787         return borderRight();
1788     case RightToLeftWritingMode:
1789         return borderLeft();
1790     }
1791     ASSERT_NOT_REACHED();
1792     return borderBottom();
1793 }
1794
1795 const BorderValue& RenderStyle::borderStart() const
1796 {
1797     if (isHorizontalWritingMode())
1798         return isLeftToRightDirection() ? borderLeft() : borderRight();
1799     return isLeftToRightDirection() ? borderTop() : borderBottom();
1800 }
1801
1802 const BorderValue& RenderStyle::borderEnd() const
1803 {
1804     if (isHorizontalWritingMode())
1805         return isLeftToRightDirection() ? borderRight() : borderLeft();
1806     return isLeftToRightDirection() ? borderBottom() : borderTop();
1807 }
1808
1809 float RenderStyle::borderBeforeWidth() const
1810 {
1811     switch (writingMode()) {
1812     case TopToBottomWritingMode:
1813         return borderTopWidth();
1814     case BottomToTopWritingMode:
1815         return borderBottomWidth();
1816     case LeftToRightWritingMode:
1817         return borderLeftWidth();
1818     case RightToLeftWritingMode:
1819         return borderRightWidth();
1820     }
1821     ASSERT_NOT_REACHED();
1822     return borderTopWidth();
1823 }
1824
1825 float RenderStyle::borderAfterWidth() const
1826 {
1827     switch (writingMode()) {
1828     case TopToBottomWritingMode:
1829         return borderBottomWidth();
1830     case BottomToTopWritingMode:
1831         return borderTopWidth();
1832     case LeftToRightWritingMode:
1833         return borderRightWidth();
1834     case RightToLeftWritingMode:
1835         return borderLeftWidth();
1836     }
1837     ASSERT_NOT_REACHED();
1838     return borderBottomWidth();
1839 }
1840
1841 float RenderStyle::borderStartWidth() const
1842 {
1843     if (isHorizontalWritingMode())
1844         return isLeftToRightDirection() ? borderLeftWidth() : borderRightWidth();
1845     return isLeftToRightDirection() ? borderTopWidth() : borderBottomWidth();
1846 }
1847
1848 float RenderStyle::borderEndWidth() const
1849 {
1850     if (isHorizontalWritingMode())
1851         return isLeftToRightDirection() ? borderRightWidth() : borderLeftWidth();
1852     return isLeftToRightDirection() ? borderBottomWidth() : borderTopWidth();
1853 }
1854
1855 void RenderStyle::setMarginStart(Length&& margin)
1856 {
1857     if (isHorizontalWritingMode()) {
1858         if (isLeftToRightDirection())
1859             setMarginLeft(WTFMove(margin));
1860         else
1861             setMarginRight(WTFMove(margin));
1862     } else {
1863         if (isLeftToRightDirection())
1864             setMarginTop(WTFMove(margin));
1865         else
1866             setMarginBottom(WTFMove(margin));
1867     }
1868 }
1869
1870 void RenderStyle::setMarginEnd(Length&& margin)
1871 {
1872     if (isHorizontalWritingMode()) {
1873         if (isLeftToRightDirection())
1874             setMarginRight(WTFMove(margin));
1875         else
1876             setMarginLeft(WTFMove(margin));
1877     } else {
1878         if (isLeftToRightDirection())
1879             setMarginBottom(WTFMove(margin));
1880         else
1881             setMarginTop(WTFMove(margin));
1882     }
1883 }
1884
1885 TextEmphasisMark RenderStyle::textEmphasisMark() const
1886 {
1887     auto mark = static_cast<TextEmphasisMark>(m_rareInheritedData->textEmphasisMark);
1888     if (mark != TextEmphasisMarkAuto)
1889         return mark;
1890     if (isHorizontalWritingMode())
1891         return TextEmphasisMarkDot;
1892     return TextEmphasisMarkSesame;
1893 }
1894
1895 #if ENABLE(TOUCH_EVENTS)
1896
1897 Color RenderStyle::initialTapHighlightColor()
1898 {
1899     return RenderTheme::tapHighlightColor();
1900 }
1901
1902 #endif
1903
1904 LayoutBoxExtent RenderStyle::imageOutsets(const NinePieceImage& image) const
1905 {
1906     return LayoutBoxExtent(NinePieceImage::computeOutset(image.outset().top(), borderTopWidth()),
1907                            NinePieceImage::computeOutset(image.outset().right(), borderRightWidth()),
1908                            NinePieceImage::computeOutset(image.outset().bottom(), borderBottomWidth()),
1909                            NinePieceImage::computeOutset(image.outset().left(), borderLeftWidth()));
1910 }
1911
1912 std::pair<FontOrientation, NonCJKGlyphOrientation> RenderStyle::fontAndGlyphOrientation()
1913 {
1914     // FIXME: TextOrientationSideways should map to sideways-left in vertical-lr, which is not supported yet.
1915
1916     if (isHorizontalWritingMode())
1917         return { Horizontal, NonCJKGlyphOrientation::Mixed };
1918
1919     switch (textOrientation()) {
1920     case TextOrientation::Mixed:
1921         return { Vertical, NonCJKGlyphOrientation::Mixed };
1922     case TextOrientation::Upright:
1923         return { Vertical, NonCJKGlyphOrientation::Upright };
1924     case TextOrientation::Sideways:
1925         return { Horizontal, NonCJKGlyphOrientation::Mixed };
1926     default:
1927         ASSERT_NOT_REACHED();
1928         return { Horizontal, NonCJKGlyphOrientation::Mixed };
1929     }
1930 }
1931
1932 void RenderStyle::setBorderImageSource(RefPtr<StyleImage>&& image)
1933 {
1934     if (m_surroundData->border.m_image.image() == image.get())
1935         return;
1936     m_surroundData.access().border.m_image.setImage(WTFMove(image));
1937 }
1938
1939 void RenderStyle::setBorderImageSlices(LengthBox&& slices)
1940 {
1941     if (m_surroundData->border.m_image.imageSlices() == slices)
1942         return;
1943     m_surroundData.access().border.m_image.setImageSlices(WTFMove(slices));
1944 }
1945
1946 void RenderStyle::setBorderImageWidth(LengthBox&& slices)
1947 {
1948     if (m_surroundData->border.m_image.borderSlices() == slices)
1949         return;
1950     m_surroundData.access().border.m_image.setBorderSlices(WTFMove(slices));
1951 }
1952
1953 void RenderStyle::setBorderImageOutset(LengthBox&& outset)
1954 {
1955     if (m_surroundData->border.m_image.outset() == outset)
1956         return;
1957     m_surroundData.access().border.m_image.setOutset(WTFMove(outset));
1958 }
1959
1960 void RenderStyle::setColumnStylesFromPaginationMode(const Pagination::Mode& paginationMode)
1961 {
1962     if (paginationMode == Pagination::Unpaginated)
1963         return;
1964     
1965     setColumnFill(ColumnFillAuto);
1966     
1967     switch (paginationMode) {
1968     case Pagination::LeftToRightPaginated:
1969         setColumnAxis(HorizontalColumnAxis);
1970         if (isHorizontalWritingMode())
1971             setColumnProgression(isLeftToRightDirection() ? NormalColumnProgression : ReverseColumnProgression);
1972         else
1973             setColumnProgression(isFlippedBlocksWritingMode() ? ReverseColumnProgression : NormalColumnProgression);
1974         break;
1975     case Pagination::RightToLeftPaginated:
1976         setColumnAxis(HorizontalColumnAxis);
1977         if (isHorizontalWritingMode())
1978             setColumnProgression(isLeftToRightDirection() ? ReverseColumnProgression : NormalColumnProgression);
1979         else
1980             setColumnProgression(isFlippedBlocksWritingMode() ? NormalColumnProgression : ReverseColumnProgression);
1981         break;
1982     case Pagination::TopToBottomPaginated:
1983         setColumnAxis(VerticalColumnAxis);
1984         if (isHorizontalWritingMode())
1985             setColumnProgression(isFlippedBlocksWritingMode() ? ReverseColumnProgression : NormalColumnProgression);
1986         else
1987             setColumnProgression(isLeftToRightDirection() ? NormalColumnProgression : ReverseColumnProgression);
1988         break;
1989     case Pagination::BottomToTopPaginated:
1990         setColumnAxis(VerticalColumnAxis);
1991         if (isHorizontalWritingMode())
1992             setColumnProgression(isFlippedBlocksWritingMode() ? NormalColumnProgression : ReverseColumnProgression);
1993         else
1994             setColumnProgression(isLeftToRightDirection() ? ReverseColumnProgression : NormalColumnProgression);
1995         break;
1996     case Pagination::Unpaginated:
1997         ASSERT_NOT_REACHED();
1998         break;
1999     }
2000 }
2001
2002 #if ENABLE(CSS_SCROLL_SNAP)
2003
2004 ScrollSnapType RenderStyle::initialScrollSnapType()
2005 {
2006     return { };
2007 }
2008
2009 ScrollSnapAlign RenderStyle::initialScrollSnapAlign()
2010 {
2011     return { };
2012 }
2013
2014 const StyleScrollSnapArea& RenderStyle::scrollSnapArea() const
2015 {
2016     return *m_rareNonInheritedData->scrollSnapArea;
2017 }
2018
2019 const StyleScrollSnapPort& RenderStyle::scrollSnapPort() const
2020 {
2021     return *m_rareNonInheritedData->scrollSnapPort;
2022 }
2023
2024 const ScrollSnapType& RenderStyle::scrollSnapType() const
2025 {
2026     return m_rareNonInheritedData->scrollSnapPort->type;
2027 }
2028
2029 const LengthBox& RenderStyle::scrollPadding() const
2030 {
2031     return m_rareNonInheritedData->scrollSnapPort->scrollPadding;
2032 }
2033
2034 const Length& RenderStyle::scrollPaddingTop() const
2035 {
2036     return scrollPadding().top();
2037 }
2038
2039 const Length& RenderStyle::scrollPaddingBottom() const
2040 {
2041     return scrollPadding().bottom();
2042 }
2043
2044 const Length& RenderStyle::scrollPaddingLeft() const
2045 {
2046     return scrollPadding().left();
2047 }
2048
2049 const Length& RenderStyle::scrollPaddingRight() const
2050 {
2051     return scrollPadding().right();
2052 }
2053
2054 const ScrollSnapAlign& RenderStyle::scrollSnapAlign() const
2055 {
2056     return m_rareNonInheritedData->scrollSnapArea->alignment;
2057 }
2058
2059 const LengthBox& RenderStyle::scrollSnapMargin() const
2060 {
2061     return m_rareNonInheritedData->scrollSnapArea->scrollSnapMargin;
2062 }
2063
2064 const Length& RenderStyle::scrollSnapMarginTop() const
2065 {
2066     return scrollSnapMargin().top();
2067 }
2068
2069 const Length& RenderStyle::scrollSnapMarginBottom() const
2070 {
2071     return scrollSnapMargin().bottom();
2072 }
2073
2074 const Length& RenderStyle::scrollSnapMarginLeft() const
2075 {
2076     return scrollSnapMargin().left();
2077 }
2078
2079 const Length& RenderStyle::scrollSnapMarginRight() const
2080 {
2081     return scrollSnapMargin().right();
2082 }
2083
2084 void RenderStyle::setScrollSnapType(const ScrollSnapType& type)
2085 {
2086     SET_NESTED_VAR(m_rareNonInheritedData, scrollSnapPort, type, type);
2087 }
2088
2089 void RenderStyle::setScrollPaddingTop(Length&& length)
2090 {
2091     SET_NESTED_VAR(m_rareNonInheritedData, scrollSnapPort, scrollPadding.top(), WTFMove(length));
2092 }
2093
2094 void RenderStyle::setScrollPaddingBottom(Length&& length)
2095 {
2096     SET_NESTED_VAR(m_rareNonInheritedData, scrollSnapPort, scrollPadding.bottom(), WTFMove(length));
2097 }
2098
2099 void RenderStyle::setScrollPaddingLeft(Length&& length)
2100 {
2101     SET_NESTED_VAR(m_rareNonInheritedData, scrollSnapPort, scrollPadding.left(), WTFMove(length));
2102 }
2103
2104 void RenderStyle::setScrollPaddingRight(Length&& length)
2105 {
2106     SET_NESTED_VAR(m_rareNonInheritedData, scrollSnapPort, scrollPadding.right(), WTFMove(length));
2107 }
2108
2109 void RenderStyle::setScrollSnapAlign(const ScrollSnapAlign& alignment)
2110 {
2111     SET_NESTED_VAR(m_rareNonInheritedData, scrollSnapArea, alignment, alignment);
2112 }
2113
2114 void RenderStyle::setScrollSnapMarginTop(Length&& length)
2115 {
2116     SET_NESTED_VAR(m_rareNonInheritedData, scrollSnapArea, scrollSnapMargin.top(), WTFMove(length));
2117 }
2118
2119 void RenderStyle::setScrollSnapMarginBottom(Length&& length)
2120 {
2121     SET_NESTED_VAR(m_rareNonInheritedData, scrollSnapArea, scrollSnapMargin.bottom(), WTFMove(length));
2122 }
2123
2124 void RenderStyle::setScrollSnapMarginLeft(Length&& length)
2125 {
2126     SET_NESTED_VAR(m_rareNonInheritedData, scrollSnapArea, scrollSnapMargin.left(), WTFMove(length));
2127 }
2128
2129 void RenderStyle::setScrollSnapMarginRight(Length&& length)
2130 {
2131     SET_NESTED_VAR(m_rareNonInheritedData, scrollSnapArea, scrollSnapMargin.right(), WTFMove(length));
2132 }
2133
2134 #endif
2135
2136 bool RenderStyle::hasReferenceFilterOnly() const
2137 {
2138     if (!hasFilter())
2139         return false;
2140     auto& filterOperations = m_rareNonInheritedData->filter->operations;
2141     return filterOperations.size() == 1 && filterOperations.at(0)->type() == FilterOperation::REFERENCE;
2142 }
2143
2144 void RenderStyle::checkVariablesInCustomProperties()
2145 {
2146     if (!m_rareInheritedData->customProperties->containsVariables)
2147         return;
2148
2149     auto& customPropertyData = m_rareInheritedData.access().customProperties.access();
2150
2151     // Our first pass checks the variables for validity and replaces any properties that became
2152     // invalid with empty values.
2153     auto& customProperties = customPropertyData.values;
2154     HashSet<AtomicString> invalidProperties;
2155     for (auto entry : customProperties) {
2156         if (!entry.value->containsVariables())
2157             continue;
2158         HashSet<AtomicString> seenProperties;
2159         entry.value->checkVariablesForCycles(entry.key, customProperties, seenProperties, invalidProperties);
2160     }
2161     
2162     // Now insert invalid values.
2163     if (!invalidProperties.isEmpty()) {
2164         auto invalidValue = CSSCustomPropertyValue::createInvalid();
2165         for (auto& property : invalidProperties)
2166             customProperties.set(property, invalidValue.copyRef());
2167     }
2168
2169     // Now that all of the properties have been tested for validity and replaced with
2170     // invalid values if they failed, we can perform variable substitution on the valid values.
2171     Vector<Ref<CSSCustomPropertyValue>> resolvedValues;
2172     for (auto entry : customProperties) {
2173         if (!entry.value->containsVariables())
2174             continue;
2175         entry.value->resolveVariableReferences(customProperties, resolvedValues);
2176     }
2177     
2178     // With all results computed, we can now mutate our table to eliminate the variables and
2179     // hold the final values. This way when we inherit, we don't end up resubstituting variables, etc.
2180     for (auto& resolvedValue : resolvedValues)
2181         customProperties.set(resolvedValue->name(), resolvedValue.copyRef());
2182
2183     customPropertyData.containsVariables = false;
2184 }
2185
2186 float RenderStyle::outlineWidth() const
2187 {
2188     if (m_backgroundData->outline.style() == BNONE)
2189         return 0;
2190     if (outlineStyleIsAuto())
2191         return std::max(m_backgroundData->outline.width(), RenderTheme::platformFocusRingWidth());
2192     return m_backgroundData->outline.width();
2193 }
2194
2195 float RenderStyle::outlineOffset() const
2196 {
2197     if (m_backgroundData->outline.style() == BNONE)
2198         return 0;
2199     if (outlineStyleIsAuto())
2200         return (m_backgroundData->outline.offset() + RenderTheme::platformFocusRingOffset(outlineWidth()));
2201     return m_backgroundData->outline.offset();
2202 }
2203
2204 bool RenderStyle::shouldPlaceBlockDirectionScrollbarOnLeft() const
2205 {
2206     return !isLeftToRightDirection() && isHorizontalWritingMode();
2207 }
2208
2209 #if ENABLE(DASHBOARD_SUPPORT)
2210
2211 void RenderStyle::setDashboardRegion(int type, const String& label, Length&& top, Length&& right, Length&& bottom, Length&& left, bool append)
2212 {
2213     if (!append)
2214         m_rareNonInheritedData.access().dashboardRegions.clear();
2215     m_rareNonInheritedData.access().dashboardRegions.append({ label, { WTFMove(top), WTFMove(right), WTFMove(bottom), WTFMove(left) }, type });
2216 }
2217
2218 #endif
2219
2220 Vector<PaintType, 3> RenderStyle::paintTypesForPaintOrder() const
2221 {
2222     Vector<PaintType, 3> paintOrder;
2223     switch (this->paintOrder()) {
2224     case PaintOrderNormal:
2225         FALLTHROUGH;
2226     case PaintOrderFill:
2227         paintOrder.append(PaintTypeFill);
2228         paintOrder.append(PaintTypeStroke);
2229         paintOrder.append(PaintTypeMarkers);
2230         break;
2231     case PaintOrderFillMarkers:
2232         paintOrder.append(PaintTypeFill);
2233         paintOrder.append(PaintTypeMarkers);
2234         paintOrder.append(PaintTypeStroke);
2235         break;
2236     case PaintOrderStroke:
2237         paintOrder.append(PaintTypeStroke);
2238         paintOrder.append(PaintTypeFill);
2239         paintOrder.append(PaintTypeMarkers);
2240         break;
2241     case PaintOrderStrokeMarkers:
2242         paintOrder.append(PaintTypeStroke);
2243         paintOrder.append(PaintTypeMarkers);
2244         paintOrder.append(PaintTypeFill);
2245         break;
2246     case PaintOrderMarkers:
2247         paintOrder.append(PaintTypeMarkers);
2248         paintOrder.append(PaintTypeFill);
2249         paintOrder.append(PaintTypeStroke);
2250         break;
2251     case PaintOrderMarkersStroke:
2252         paintOrder.append(PaintTypeMarkers);
2253         paintOrder.append(PaintTypeStroke);
2254         paintOrder.append(PaintTypeFill);
2255         break;
2256     };
2257     return paintOrder;
2258 }
2259
2260
2261 } // namespace WebCore