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