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