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