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