Implement hanging-punctuation property parsing.
[WebKit-https.git] / Source / WebCore / rendering / style / RenderStyle.cpp
1 /*
2  * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
3  * Copyright (C) 2004-2015 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 "CSSPropertyNames.h"
29 #include "CSSVariableDependentValue.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 "ScaleTransformOperation.h"
39 #include "ShadowData.h"
40 #include "StyleImage.h"
41 #include "StyleInheritedData.h"
42 #include "StyleResolver.h"
43 #include "StyleScrollSnapPoints.h"
44 #include "StyleSelfAlignmentData.h"
45 #include "StyleTreeResolver.h"
46 #include "WillChangeData.h"
47 #include <wtf/MathExtras.h>
48 #include <wtf/PointerComparison.h>
49 #include <wtf/StdLibExtras.h>
50 #include <algorithm>
51
52 #if ENABLE(IOS_TEXT_AUTOSIZING)
53 #include <wtf/text/StringHash.h>
54 #endif
55
56 #if ENABLE(TEXT_AUTOSIZING)
57 #include "TextAutosizer.h"
58 #endif
59
60 #if ENABLE(TOUCH_EVENTS)
61 #include "RenderTheme.h"
62 #endif
63
64 namespace WebCore {
65
66 struct SameSizeAsBorderValue {
67     float m_width;
68     RGBA32 m_color;
69     int m_restBits;
70 };
71
72 COMPILE_ASSERT(sizeof(BorderValue) == sizeof(SameSizeAsBorderValue), BorderValue_should_not_grow);
73
74 struct SameSizeAsRenderStyle : public RefCounted<SameSizeAsRenderStyle> {
75     void* dataRefs[7];
76     void* ownPtrs[1];
77     void* dataRefSvgStyle;
78     struct InheritedFlags {
79         unsigned m_bitfields[2];
80     } inherited_flags;
81
82     struct NonInheritedFlags {
83         uint64_t m_flags;
84     } noninherited_flags;
85 };
86
87 COMPILE_ASSERT(sizeof(RenderStyle) == sizeof(SameSizeAsRenderStyle), RenderStyle_should_stay_small);
88
89 inline RenderStyle& defaultStyle()
90 {
91     static RenderStyle& style = RenderStyle::createDefaultStyle().leakRef();
92     return style;
93 }
94
95 Ref<RenderStyle> RenderStyle::create()
96 {
97     return adoptRef(*new RenderStyle(defaultStyle()));
98 }
99
100 Ref<RenderStyle> RenderStyle::createDefaultStyle()
101 {
102     return adoptRef(*new RenderStyle(true));
103 }
104
105 Ref<RenderStyle> RenderStyle::createAnonymousStyleWithDisplay(const RenderStyle* parentStyle, EDisplay display)
106 {
107     auto newStyle = RenderStyle::create();
108     newStyle.get().inheritFrom(parentStyle);
109     newStyle.get().inheritUnicodeBidiFrom(parentStyle);
110     newStyle.get().setDisplay(display);
111     return newStyle;
112 }
113
114 Ref<RenderStyle> RenderStyle::clone(const RenderStyle* other)
115 {
116     return adoptRef(*new RenderStyle(*other));
117 }
118
119 Ref<RenderStyle> RenderStyle::createStyleInheritingFromPseudoStyle(const RenderStyle& pseudoStyle)
120 {
121     ASSERT(pseudoStyle.styleType() == BEFORE || pseudoStyle.styleType() == AFTER);
122
123     auto style = RenderStyle::create();
124     style.get().inheritFrom(&pseudoStyle);
125     return style;
126 }
127
128 ALWAYS_INLINE RenderStyle::RenderStyle(bool)
129     : m_box(StyleBoxData::create())
130     , visual(StyleVisualData::create())
131     , m_background(StyleBackgroundData::create())
132     , surround(StyleSurroundData::create())
133     , rareNonInheritedData(StyleRareNonInheritedData::create())
134     , rareInheritedData(StyleRareInheritedData::create())
135     , inherited(StyleInheritedData::create())
136     , m_svgStyle(SVGRenderStyle::create())
137 {
138     inherited_flags._empty_cells = initialEmptyCells();
139     inherited_flags._caption_side = initialCaptionSide();
140     inherited_flags._list_style_type = initialListStyleType();
141     inherited_flags._list_style_position = initialListStylePosition();
142     inherited_flags._visibility = initialVisibility();
143     inherited_flags._text_align = initialTextAlign();
144     inherited_flags._text_transform = initialTextTransform();
145     inherited_flags._text_decorations = initialTextDecoration();
146     inherited_flags._cursor_style = initialCursor();
147 #if ENABLE(CURSOR_VISIBILITY)
148     inherited_flags.m_cursorVisibility = initialCursorVisibility();
149 #endif
150     inherited_flags._direction = initialDirection();
151     inherited_flags._white_space = initialWhiteSpace();
152     inherited_flags._border_collapse = initialBorderCollapse();
153     inherited_flags.m_rtlOrdering = initialRTLOrdering();
154     inherited_flags._box_direction = initialBoxDirection();
155     inherited_flags.m_printColorAdjust = initialPrintColorAdjust();
156     inherited_flags._pointerEvents = initialPointerEvents();
157     inherited_flags._insideLink = NotInsideLink;
158     inherited_flags._insideDefaultButton = false;
159     inherited_flags.m_writingMode = initialWritingMode();
160
161     static_assert((sizeof(InheritedFlags) <= 8), "InheritedFlags does not grow");
162     static_assert((sizeof(NonInheritedFlags) <= 8), "NonInheritedFlags does not grow");
163 }
164
165 ALWAYS_INLINE RenderStyle::RenderStyle(const RenderStyle& o)
166     : RefCounted<RenderStyle>()
167     , m_box(o.m_box)
168     , visual(o.visual)
169     , m_background(o.m_background)
170     , surround(o.surround)
171     , rareNonInheritedData(o.rareNonInheritedData)
172     , rareInheritedData(o.rareInheritedData)
173     , inherited(o.inherited)
174     , m_svgStyle(o.m_svgStyle)
175     , inherited_flags(o.inherited_flags)
176     , noninherited_flags(o.noninherited_flags)
177 {
178 }
179
180 static inline StyleSelfAlignmentData resolveAlignmentData(const RenderStyle& parentStyle, const RenderStyle& childStyle, ItemPosition resolvedAutoPositionForRenderer)
181 {
182     // The auto keyword computes to the parent's align-items computed value, or to "stretch", if not set or "auto".
183     if (childStyle.alignSelfPosition() == ItemPositionAuto)
184         return (parentStyle.alignItemsPosition() == ItemPositionAuto) ? StyleSelfAlignmentData(resolvedAutoPositionForRenderer, OverflowAlignmentDefault) : parentStyle.alignItems();
185     return childStyle.alignSelf();
186 }
187
188 static inline StyleSelfAlignmentData resolveJustificationData(const RenderStyle& parentStyle, const RenderStyle& childStyle, ItemPosition resolvedAutoPositionForRenderer)
189 {
190     // The auto keyword computes to the parent's justify-items computed value, or to "stretch", if not set or "auto".
191     if (childStyle.justifySelfPosition() == ItemPositionAuto)
192         return (parentStyle.justifyItemsPosition() == ItemPositionAuto) ? StyleSelfAlignmentData(resolvedAutoPositionForRenderer, OverflowAlignmentDefault) : parentStyle.justifyItems();
193     return childStyle.justifySelf();
194 }
195
196 ItemPosition RenderStyle::resolveAlignment(const RenderStyle& parentStyle, const RenderStyle& childStyle, ItemPosition resolvedAutoPositionForRenderer)
197 {
198     return resolveAlignmentData(parentStyle, childStyle, resolvedAutoPositionForRenderer).position();
199 }
200
201 OverflowAlignment RenderStyle::resolveAlignmentOverflow(const RenderStyle& parentStyle, const RenderStyle& childStyle)
202 {
203     return resolveAlignmentData(parentStyle, childStyle, ItemPositionStretch).overflow();
204 }
205
206 ItemPosition RenderStyle::resolveJustification(const RenderStyle& parentStyle, const RenderStyle& childStyle, ItemPosition resolvedAutoPositionForRenderer)
207 {
208     return resolveJustificationData(parentStyle, childStyle, resolvedAutoPositionForRenderer).position();
209 }
210
211 OverflowAlignment RenderStyle::resolveJustificationOverflow(const RenderStyle& parentStyle, const RenderStyle& childStyle)
212 {
213     return resolveJustificationData(parentStyle, childStyle, ItemPositionStretch).overflow();
214 }
215
216 ContentPosition RenderStyle::resolvedAlignContentPosition() const
217 {
218     const StyleContentAlignmentData& align = alignContent();
219     if (align.position() != ContentPositionAuto || align.distribution() != ContentDistributionDefault)
220         return align.position();
221     // 'auto' computes to 'stretch' for flexbox, hence it's managed by distribution().
222     return isDisplayFlexibleBox() ? ContentPositionAuto : ContentPositionStart;
223 }
224
225 ContentDistributionType RenderStyle::resolvedAlignContentDistribution() const
226 {
227     const StyleContentAlignmentData& align = alignContent();
228     if (align.position() != ContentPositionAuto || align.distribution() != ContentDistributionDefault)
229         return align.distribution();
230     return isDisplayFlexibleBox() ? ContentDistributionStretch : ContentDistributionDefault;
231 }
232
233 ContentPosition RenderStyle::resolvedJustifyContentPosition() const
234 {
235     const StyleContentAlignmentData& justify = justifyContent();
236     if (justify.position() != ContentPositionAuto || justify.distribution() != ContentDistributionDefault)
237         return justify.position();
238     // 'auto' computes to 'stretch' for flexbox, but since flexing in the main axis is controlled by flex, it behaves as flex-start.
239     return isDisplayFlexibleBox() ? ContentPositionFlexStart : ContentPositionStart;
240 }
241
242 ContentDistributionType RenderStyle::resolvedJustifyContentDistribution() const
243 {
244     // even that 'auto' computes to 'stretch' for flexbox it behaves as flex-start, hence it's managed by position().
245     return justifyContentDistribution();
246 }
247
248 void RenderStyle::inheritFrom(const RenderStyle* inheritParent, IsAtShadowBoundary isAtShadowBoundary)
249 {
250     if (isAtShadowBoundary == AtShadowBoundary) {
251         // Even if surrounding content is user-editable, shadow DOM should act as a single unit, and not necessarily be editable
252         EUserModify currentUserModify = userModify();
253         rareInheritedData = inheritParent->rareInheritedData;
254         setUserModify(currentUserModify);
255     } else
256         rareInheritedData = inheritParent->rareInheritedData;
257     inherited = inheritParent->inherited;
258     inherited_flags = inheritParent->inherited_flags;
259
260     if (m_svgStyle != inheritParent->m_svgStyle)
261         m_svgStyle.access()->inheritFrom(inheritParent->m_svgStyle.get());
262 }
263
264 void RenderStyle::copyNonInheritedFrom(const RenderStyle* other)
265 {
266     m_box = other->m_box;
267     visual = other->visual;
268     m_background = other->m_background;
269     surround = other->surround;
270     rareNonInheritedData = other->rareNonInheritedData;
271     noninherited_flags.copyNonInheritedFrom(other->noninherited_flags);
272
273     if (m_svgStyle != other->m_svgStyle)
274         m_svgStyle.access()->copyNonInheritedFrom(other->m_svgStyle.get());
275
276     ASSERT(zoom() == initialZoom());
277 }
278
279 bool RenderStyle::operator==(const RenderStyle& o) const
280 {
281     // compare everything except the pseudoStyle pointer
282     return inherited_flags == o.inherited_flags
283         && noninherited_flags == o.noninherited_flags
284         && m_box == o.m_box
285         && visual == o.visual
286         && m_background == o.m_background
287         && surround == o.surround
288         && rareNonInheritedData == o.rareNonInheritedData
289         && rareInheritedData == o.rareInheritedData
290         && inherited == o.inherited
291         && m_svgStyle == o.m_svgStyle
292             ;
293 }
294
295 bool RenderStyle::isStyleAvailable() const
296 {
297     return !Style::isPlaceholderStyle(*this);
298 }
299
300 bool RenderStyle::hasUniquePseudoStyle() const
301 {
302     if (!m_cachedPseudoStyles || styleType() != NOPSEUDO)
303         return false;
304
305     for (size_t i = 0; i < m_cachedPseudoStyles->size(); ++i) {
306         RenderStyle* pseudoStyle = m_cachedPseudoStyles->at(i).get();
307         if (pseudoStyle->unique())
308             return true;
309     }
310
311     return false;
312 }
313
314 RenderStyle* RenderStyle::getCachedPseudoStyle(PseudoId pid) const
315 {
316     if (!m_cachedPseudoStyles || !m_cachedPseudoStyles->size())
317         return nullptr;
318
319     if (styleType() != NOPSEUDO) 
320         return nullptr;
321
322     for (size_t i = 0; i < m_cachedPseudoStyles->size(); ++i) {
323         RenderStyle* pseudoStyle = m_cachedPseudoStyles->at(i).get();
324         if (pseudoStyle->styleType() == pid)
325             return pseudoStyle;
326     }
327
328     return nullptr;
329 }
330
331 RenderStyle* RenderStyle::addCachedPseudoStyle(PassRefPtr<RenderStyle> pseudo)
332 {
333     if (!pseudo)
334         return nullptr;
335
336     ASSERT(pseudo->styleType() > NOPSEUDO);
337
338     RenderStyle* result = pseudo.get();
339
340     if (!m_cachedPseudoStyles)
341         m_cachedPseudoStyles = std::make_unique<PseudoStyleCache>();
342
343     m_cachedPseudoStyles->append(pseudo);
344
345     return result;
346 }
347
348 void RenderStyle::removeCachedPseudoStyle(PseudoId pid)
349 {
350     if (!m_cachedPseudoStyles)
351         return;
352     for (size_t i = 0; i < m_cachedPseudoStyles->size(); ++i) {
353         RenderStyle* pseudoStyle = m_cachedPseudoStyles->at(i).get();
354         if (pseudoStyle->styleType() == pid) {
355             m_cachedPseudoStyles->remove(i);
356             return;
357         }
358     }
359 }
360
361 bool RenderStyle::inheritedNotEqual(const RenderStyle* other) const
362 {
363     return inherited_flags != other->inherited_flags
364            || inherited != other->inherited
365            || m_svgStyle->inheritedNotEqual(other->m_svgStyle.get())
366            || rareInheritedData != other->rareInheritedData;
367 }
368
369 #if ENABLE(IOS_TEXT_AUTOSIZING)
370
371 static inline unsigned computeFontHash(const FontCascade& font)
372 {
373     IntegerHasher hasher;
374     hasher.add(ASCIICaseInsensitiveHash::hash(font.fontDescription().firstFamily()));
375     hasher.add(font.fontDescription().specifiedSize());
376     return hasher.hash();
377 }
378
379 unsigned RenderStyle::hashForTextAutosizing() const
380 {
381     // FIXME: Not a very smart hash. Could be improved upon. See <https://bugs.webkit.org/show_bug.cgi?id=121131>.
382     unsigned hash = rareNonInheritedData->m_appearance;
383     hash ^= rareNonInheritedData->marginBeforeCollapse;
384     hash ^= rareNonInheritedData->marginAfterCollapse;
385     hash ^= rareNonInheritedData->lineClamp.value();
386     hash ^= rareInheritedData->overflowWrap;
387     hash ^= rareInheritedData->nbspMode;
388     hash ^= rareInheritedData->lineBreak;
389     hash ^= WTF::FloatHash<float>::hash(inherited->specifiedLineHeight.value());
390     hash ^= computeFontHash(inherited->fontCascade);
391     hash ^= inherited->horizontal_border_spacing;
392     hash ^= inherited->vertical_border_spacing;
393     hash ^= inherited_flags._box_direction;
394     hash ^= inherited_flags.m_rtlOrdering;
395     hash ^= noninherited_flags.position();
396     hash ^= noninherited_flags.floating();
397     hash ^= rareNonInheritedData->textOverflow;
398     hash ^= rareInheritedData->textSecurity;
399     return hash;
400 }
401
402 bool RenderStyle::equalForTextAutosizing(const RenderStyle* other) const
403 {
404     return rareNonInheritedData->m_appearance == other->rareNonInheritedData->m_appearance
405         && rareNonInheritedData->marginBeforeCollapse == other->rareNonInheritedData->marginBeforeCollapse
406         && rareNonInheritedData->marginAfterCollapse == other->rareNonInheritedData->marginAfterCollapse
407         && rareNonInheritedData->lineClamp == other->rareNonInheritedData->lineClamp
408         && rareInheritedData->textSizeAdjust == other->rareInheritedData->textSizeAdjust
409         && rareInheritedData->overflowWrap == other->rareInheritedData->overflowWrap
410         && rareInheritedData->nbspMode == other->rareInheritedData->nbspMode
411         && rareInheritedData->lineBreak == other->rareInheritedData->lineBreak
412         && rareInheritedData->textSecurity == other->rareInheritedData->textSecurity
413         && inherited->specifiedLineHeight == other->inherited->specifiedLineHeight
414         && inherited->fontCascade.equalForTextAutoSizing(other->inherited->fontCascade)
415         && inherited->horizontal_border_spacing == other->inherited->horizontal_border_spacing
416         && inherited->vertical_border_spacing == other->inherited->vertical_border_spacing
417         && inherited_flags._box_direction == other->inherited_flags._box_direction
418         && inherited_flags.m_rtlOrdering == other->inherited_flags.m_rtlOrdering
419         && noninherited_flags.position() == other->noninherited_flags.position()
420         && noninherited_flags.floating() == other->noninherited_flags.floating()
421         && rareNonInheritedData->textOverflow == other->rareNonInheritedData->textOverflow;
422 }
423
424 #endif // ENABLE(IOS_TEXT_AUTOSIZING)
425
426 bool RenderStyle::inheritedDataShared(const RenderStyle* other) const
427 {
428     // This is a fast check that only looks if the data structures are shared.
429     return inherited_flags == other->inherited_flags
430         && inherited.get() == other->inherited.get()
431         && m_svgStyle.get() == other->m_svgStyle.get()
432         && rareInheritedData.get() == other->rareInheritedData.get();
433 }
434
435 static bool positionChangeIsMovementOnly(const LengthBox& a, const LengthBox& b, const Length& width)
436 {
437     // If any unit types are different, then we can't guarantee
438     // that this was just a movement.
439     if (a.left().type() != b.left().type()
440         || a.right().type() != b.right().type()
441         || a.top().type() != b.top().type()
442         || a.bottom().type() != b.bottom().type())
443         return false;
444
445     // Only one unit can be non-auto in the horizontal direction and
446     // in the vertical direction.  Otherwise the adjustment of values
447     // is changing the size of the box.
448     if (!a.left().isIntrinsicOrAuto() && !a.right().isIntrinsicOrAuto())
449         return false;
450     if (!a.top().isIntrinsicOrAuto() && !a.bottom().isIntrinsicOrAuto())
451         return false;
452     // If our width is auto and left or right is specified then this 
453     // is not just a movement - we need to resize to our container.
454     if ((!a.left().isIntrinsicOrAuto() || !a.right().isIntrinsicOrAuto()) && width.isIntrinsicOrAuto())
455         return false;
456
457     // One of the units is fixed or percent in both directions and stayed
458     // that way in the new style.  Therefore all we are doing is moving.
459     return true;
460 }
461
462 inline bool RenderStyle::changeAffectsVisualOverflow(const RenderStyle& other) const
463 {
464     if (rareNonInheritedData.get() != other.rareNonInheritedData.get()
465         && !arePointingToEqualData(rareNonInheritedData->m_boxShadow, other.rareNonInheritedData->m_boxShadow))
466         return true;
467
468     if (rareInheritedData.get() != other.rareInheritedData.get()
469         && !arePointingToEqualData(rareInheritedData->textShadow, other.rareInheritedData->textShadow))
470         return true;
471
472     if (inherited_flags._text_decorations != other.inherited_flags._text_decorations
473         || visual->textDecoration != other.visual->textDecoration
474         || rareNonInheritedData->m_textDecorationStyle != other.rareNonInheritedData->m_textDecorationStyle) {
475         // Underlines are always drawn outside of their textbox bounds when text-underline-position: under;
476         // is specified. We can take an early out here.
477         if (textUnderlinePosition() == TextUnderlinePositionUnder
478             || other.textUnderlinePosition() == TextUnderlinePositionUnder)
479             return true;
480         return visualOverflowForDecorations(*this, nullptr) != visualOverflowForDecorations(other, nullptr);
481     }
482
483     return false;
484 }
485
486 bool RenderStyle::changeRequiresLayout(const RenderStyle& other, unsigned& changedContextSensitiveProperties) const
487 {
488     if (m_box->width() != other.m_box->width()
489         || m_box->minWidth() != other.m_box->minWidth()
490         || m_box->maxWidth() != other.m_box->maxWidth()
491         || m_box->height() != other.m_box->height()
492         || m_box->minHeight() != other.m_box->minHeight()
493         || m_box->maxHeight() != other.m_box->maxHeight())
494         return true;
495
496     if (m_box->verticalAlign() != other.m_box->verticalAlign() || noninherited_flags.verticalAlign() != other.noninherited_flags.verticalAlign())
497         return true;
498
499     if (m_box->boxSizing() != other.m_box->boxSizing())
500         return true;
501
502     if (surround->margin != other.surround->margin)
503         return true;
504
505     if (surround->padding != other.surround->padding)
506         return true;
507
508     // FIXME: We should add an optimized form of layout that just recomputes visual overflow.
509     if (changeAffectsVisualOverflow(other))
510         return true;
511
512     if (rareNonInheritedData.get() != other.rareNonInheritedData.get()) {
513         if (rareNonInheritedData->m_appearance != other.rareNonInheritedData->m_appearance
514             || rareNonInheritedData->marginBeforeCollapse != other.rareNonInheritedData->marginBeforeCollapse
515             || rareNonInheritedData->marginAfterCollapse != other.rareNonInheritedData->marginAfterCollapse
516             || rareNonInheritedData->lineClamp != other.rareNonInheritedData->lineClamp
517             || rareNonInheritedData->m_initialLetter != other.rareNonInheritedData->m_initialLetter
518             || rareNonInheritedData->textOverflow != other.rareNonInheritedData->textOverflow)
519             return true;
520
521         if (rareNonInheritedData->m_regionFragment != other.rareNonInheritedData->m_regionFragment)
522             return true;
523
524 #if ENABLE(CSS_SHAPES)
525         if (rareNonInheritedData->m_shapeMargin != other.rareNonInheritedData->m_shapeMargin)
526             return true;
527 #endif
528
529         if (rareNonInheritedData->m_deprecatedFlexibleBox != other.rareNonInheritedData->m_deprecatedFlexibleBox)
530             return true;
531
532         if (rareNonInheritedData->m_flexibleBox != other.rareNonInheritedData->m_flexibleBox)
533             return true;
534
535         if (rareNonInheritedData->m_order != other.rareNonInheritedData->m_order
536             || rareNonInheritedData->m_alignContent != other.rareNonInheritedData->m_alignContent
537             || rareNonInheritedData->m_alignItems != other.rareNonInheritedData->m_alignItems
538             || rareNonInheritedData->m_alignSelf != other.rareNonInheritedData->m_alignSelf
539             || rareNonInheritedData->m_justifyContent != other.rareNonInheritedData->m_justifyContent
540             || rareNonInheritedData->m_justifyItems != other.rareNonInheritedData->m_justifyItems
541             || rareNonInheritedData->m_justifySelf != other.rareNonInheritedData->m_justifySelf)
542             return true;
543
544         if (!arePointingToEqualData(rareNonInheritedData->m_boxReflect, other.rareNonInheritedData->m_boxReflect))
545             return true;
546
547         if (rareNonInheritedData->m_multiCol != other.rareNonInheritedData->m_multiCol)
548             return true;
549
550         if (rareNonInheritedData->m_transform != other.rareNonInheritedData->m_transform) {
551             if (rareNonInheritedData->m_transform->hasTransform() != other.rareNonInheritedData->m_transform->hasTransform())
552                 return true;
553             if (*rareNonInheritedData->m_transform != *other.rareNonInheritedData->m_transform) {
554                 changedContextSensitiveProperties |= ContextSensitivePropertyTransform;
555                 // Don't return; keep looking for another change
556             }
557         }
558
559 #if ENABLE(CSS_GRID_LAYOUT)
560         if (rareNonInheritedData->m_grid != other.rareNonInheritedData->m_grid
561             || rareNonInheritedData->m_gridItem != other.rareNonInheritedData->m_gridItem)
562             return true;
563 #endif
564
565 #if ENABLE(DASHBOARD_SUPPORT)
566         // If regions change, trigger a relayout to re-calc regions.
567         if (rareNonInheritedData->m_dashboardRegions != other.rareNonInheritedData->m_dashboardRegions)
568             return true;
569 #endif
570
571         if (!arePointingToEqualData(rareNonInheritedData->m_willChange, other.rareNonInheritedData->m_willChange)) {
572             changedContextSensitiveProperties |= ContextSensitivePropertyWillChange;
573             // Don't return; keep looking for another change
574         }
575     }
576
577     if (rareInheritedData.get() != other.rareInheritedData.get()) {
578         if (rareInheritedData->indent != other.rareInheritedData->indent
579 #if ENABLE(CSS3_TEXT)
580             || rareInheritedData->m_textAlignLast != other.rareInheritedData->m_textAlignLast
581             || rareInheritedData->m_textJustify != other.rareInheritedData->m_textJustify
582             || rareInheritedData->m_textIndentLine != other.rareInheritedData->m_textIndentLine
583 #endif
584             || rareInheritedData->m_effectiveZoom != other.rareInheritedData->m_effectiveZoom
585             || rareInheritedData->m_textZoom != other.rareInheritedData->m_textZoom
586 #if ENABLE(IOS_TEXT_AUTOSIZING)
587             || rareInheritedData->textSizeAdjust != other.rareInheritedData->textSizeAdjust
588 #endif
589             || rareInheritedData->wordBreak != other.rareInheritedData->wordBreak
590             || rareInheritedData->overflowWrap != other.rareInheritedData->overflowWrap
591             || rareInheritedData->nbspMode != other.rareInheritedData->nbspMode
592             || rareInheritedData->lineBreak != other.rareInheritedData->lineBreak
593             || rareInheritedData->textSecurity != other.rareInheritedData->textSecurity
594             || rareInheritedData->hyphens != other.rareInheritedData->hyphens
595             || rareInheritedData->hyphenationLimitBefore != other.rareInheritedData->hyphenationLimitBefore
596             || rareInheritedData->hyphenationLimitAfter != other.rareInheritedData->hyphenationLimitAfter
597             || rareInheritedData->hyphenationString != other.rareInheritedData->hyphenationString
598             || rareInheritedData->m_rubyPosition != other.rareInheritedData->m_rubyPosition
599             || rareInheritedData->textEmphasisMark != other.rareInheritedData->textEmphasisMark
600             || rareInheritedData->textEmphasisPosition != other.rareInheritedData->textEmphasisPosition
601             || rareInheritedData->textEmphasisCustomMark != other.rareInheritedData->textEmphasisCustomMark
602             || rareInheritedData->m_textOrientation != other.rareInheritedData->m_textOrientation
603             || rareInheritedData->m_tabSize != other.rareInheritedData->m_tabSize
604             || rareInheritedData->m_lineBoxContain != other.rareInheritedData->m_lineBoxContain
605             || rareInheritedData->m_lineGrid != other.rareInheritedData->m_lineGrid
606 #if ENABLE(CSS_IMAGE_ORIENTATION)
607             || rareInheritedData->m_imageOrientation != other.rareInheritedData->m_imageOrientation
608 #endif
609 #if ENABLE(CSS_IMAGE_RESOLUTION)
610             || rareInheritedData->m_imageResolutionSource != other.rareInheritedData->m_imageResolutionSource
611             || rareInheritedData->m_imageResolutionSnap != other.rareInheritedData->m_imageResolutionSnap
612             || rareInheritedData->m_imageResolution != other.rareInheritedData->m_imageResolution
613 #endif
614             || rareInheritedData->m_lineSnap != other.rareInheritedData->m_lineSnap
615             || rareInheritedData->m_lineAlign != other.rareInheritedData->m_lineAlign
616             || rareInheritedData->m_hangingPunctuation != other.rareInheritedData->m_hangingPunctuation
617 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
618             || rareInheritedData->useTouchOverflowScrolling != other.rareInheritedData->useTouchOverflowScrolling
619 #endif
620             || rareInheritedData->listStyleImage != other.rareInheritedData->listStyleImage) // FIXME: needs arePointingToEqualData()?
621             return true;
622
623         if (textStrokeWidth() != other.textStrokeWidth())
624             return true;
625     }
626
627 #if ENABLE(TEXT_AUTOSIZING)
628     if (visual->m_textAutosizingMultiplier != other.visual->m_textAutosizingMultiplier)
629         return true;
630 #endif
631
632     if (inherited->line_height != other.inherited->line_height
633 #if ENABLE(IOS_TEXT_AUTOSIZING)
634         || inherited->specifiedLineHeight != other.inherited->specifiedLineHeight
635 #endif
636         || inherited->fontCascade != other.inherited->fontCascade
637         || inherited->horizontal_border_spacing != other.inherited->horizontal_border_spacing
638         || inherited->vertical_border_spacing != other.inherited->vertical_border_spacing
639         || inherited_flags._box_direction != other.inherited_flags._box_direction
640         || inherited_flags.m_rtlOrdering != other.inherited_flags.m_rtlOrdering
641         || noninherited_flags.position() != other.noninherited_flags.position()
642         || noninherited_flags.floating() != other.noninherited_flags.floating()
643         || noninherited_flags.originalDisplay() != other.noninherited_flags.originalDisplay())
644         return true;
645
646
647     if ((noninherited_flags.effectiveDisplay()) >= TABLE) {
648         if (inherited_flags._border_collapse != other.inherited_flags._border_collapse
649             || inherited_flags._empty_cells != other.inherited_flags._empty_cells
650             || inherited_flags._caption_side != other.inherited_flags._caption_side
651             || noninherited_flags.tableLayout() != other.noninherited_flags.tableLayout())
652             return true;
653
654         // In the collapsing border model, 'hidden' suppresses other borders, while 'none'
655         // does not, so these style differences can be width differences.
656         if (inherited_flags._border_collapse
657             && ((borderTopStyle() == BHIDDEN && other.borderTopStyle() == BNONE)
658                 || (borderTopStyle() == BNONE && other.borderTopStyle() == BHIDDEN)
659                 || (borderBottomStyle() == BHIDDEN && other.borderBottomStyle() == BNONE)
660                 || (borderBottomStyle() == BNONE && other.borderBottomStyle() == BHIDDEN)
661                 || (borderLeftStyle() == BHIDDEN && other.borderLeftStyle() == BNONE)
662                 || (borderLeftStyle() == BNONE && other.borderLeftStyle() == BHIDDEN)
663                 || (borderRightStyle() == BHIDDEN && other.borderRightStyle() == BNONE)
664                 || (borderRightStyle() == BNONE && other.borderRightStyle() == BHIDDEN)))
665             return true;
666     }
667
668     if (noninherited_flags.effectiveDisplay() == LIST_ITEM) {
669         if (inherited_flags._list_style_type != other.inherited_flags._list_style_type
670             || inherited_flags._list_style_position != other.inherited_flags._list_style_position)
671             return true;
672     }
673
674     if (inherited_flags._text_align != other.inherited_flags._text_align
675         || inherited_flags._text_transform != other.inherited_flags._text_transform
676         || inherited_flags._direction != other.inherited_flags._direction
677         || inherited_flags._white_space != other.inherited_flags._white_space
678         || noninherited_flags.clear() != other.noninherited_flags.clear()
679         || noninherited_flags.unicodeBidi() != other.noninherited_flags.unicodeBidi())
680         return true;
681
682     // Check block flow direction.
683     if (inherited_flags.m_writingMode != other.inherited_flags.m_writingMode)
684         return true;
685
686     // Check text combine mode.
687     if (rareNonInheritedData->m_textCombine != other.rareNonInheritedData->m_textCombine)
688         return true;
689
690     // Check breaks.
691     if (rareNonInheritedData->m_breakBefore != other.rareNonInheritedData->m_breakBefore
692         || rareNonInheritedData->m_breakAfter != other.rareNonInheritedData->m_breakAfter
693         || rareNonInheritedData->m_breakInside != other.rareNonInheritedData->m_breakInside)
694         return true;
695
696     // Overflow returns a layout hint.
697     if (noninherited_flags.overflowX() != other.noninherited_flags.overflowX()
698         || noninherited_flags.overflowY() != other.noninherited_flags.overflowY())
699         return true;
700
701     // If our border widths change, then we need to layout.  Other changes to borders
702     // only necessitate a repaint.
703     if (borderLeftWidth() != other.borderLeftWidth()
704         || borderTopWidth() != other.borderTopWidth()
705         || borderBottomWidth() != other.borderBottomWidth()
706         || borderRightWidth() != other.borderRightWidth())
707         return true;
708
709     // If the counter directives change, trigger a relayout to re-calculate counter values and rebuild the counter node tree.
710     if (!arePointingToEqualData(rareNonInheritedData->m_counterDirectives, other.rareNonInheritedData->m_counterDirectives))
711         return true;
712
713     if ((visibility() == COLLAPSE) != (other.visibility() == COLLAPSE))
714         return true;
715
716     if (rareNonInheritedData->hasOpacity() != other.rareNonInheritedData->hasOpacity()) {
717         // FIXME: We would like to use SimplifiedLayout here, but we can't quite do that yet.
718         // We need to make sure SimplifiedLayout can operate correctly on RenderInlines (we will need
719         // to add a selfNeedsSimplifiedLayout bit in order to not get confused and taint every line).
720         // In addition we need to solve the floating object issue when layers come and go. Right now
721         // a full layout is necessary to keep floating object lists sane.
722         return true;
723     }
724
725     if (rareNonInheritedData->hasFilters() != other.rareNonInheritedData->hasFilters())
726         return true;
727
728 #if ENABLE(FILTERS_LEVEL_2)
729     if (rareNonInheritedData->hasBackdropFilters() != other.rareNonInheritedData->hasBackdropFilters())
730         return true;
731 #endif
732
733     if (!arePointingToEqualData(rareInheritedData->quotes, other.rareInheritedData->quotes))
734         return true;
735
736     if (position() != StaticPosition) {
737         if (surround->offset != other.surround->offset) {
738             // FIXME: We would like to use SimplifiedLayout for relative positioning, but we can't quite do that yet.
739             // We need to make sure SimplifiedLayout can operate correctly on RenderInlines (we will need
740             // to add a selfNeedsSimplifiedLayout bit in order to not get confused and taint every line).
741             if (position() != AbsolutePosition)
742                 return true;
743
744             // Optimize for the case where a positioned layer is moving but not changing size.
745             if (!positionChangeIsMovementOnly(surround->offset, other.surround->offset, m_box->width()))
746                 return true;
747         }
748     }
749     
750     return false;
751 }
752
753 bool RenderStyle::changeRequiresPositionedLayoutOnly(const RenderStyle& other, unsigned&) const
754 {
755     if (position() == StaticPosition)
756         return false;
757
758     if (surround->offset != other.surround->offset) {
759         // Optimize for the case where a positioned layer is moving but not changing size.
760         if (position() == AbsolutePosition && positionChangeIsMovementOnly(surround->offset, other.surround->offset, m_box->width()))
761             return true;
762     }
763     
764     return false;
765 }
766
767 bool RenderStyle::changeRequiresLayerRepaint(const RenderStyle& other, unsigned& changedContextSensitiveProperties) const
768 {
769     // StyleResolver has ensured that zIndex is non-auto only if it's applicable.
770     if (m_box->zIndex() != other.m_box->zIndex() || m_box->hasAutoZIndex() != other.m_box->hasAutoZIndex())
771         return true;
772
773     if (position() != StaticPosition) {
774         if (visual->clip != other.visual->clip || visual->hasClip != other.visual->hasClip) {
775             changedContextSensitiveProperties |= ContextSensitivePropertyClipRect;
776             return true;
777         }
778     }
779
780 #if ENABLE(CSS_COMPOSITING)
781     if (rareNonInheritedData->m_effectiveBlendMode != other.rareNonInheritedData->m_effectiveBlendMode)
782         return true;
783 #endif
784
785     if (rareNonInheritedData->opacity != other.rareNonInheritedData->opacity) {
786         changedContextSensitiveProperties |= ContextSensitivePropertyOpacity;
787         // Don't return; keep looking for another change.
788     }
789
790     if (rareNonInheritedData->m_filter != other.rareNonInheritedData->m_filter) {
791         changedContextSensitiveProperties |= ContextSensitivePropertyFilter;
792         // Don't return; keep looking for another change.
793     }
794
795     if (rareNonInheritedData->m_mask != other.rareNonInheritedData->m_mask
796         || rareNonInheritedData->m_maskBoxImage != other.rareNonInheritedData->m_maskBoxImage)
797         return true;
798
799     return false;
800 }
801
802 bool RenderStyle::changeRequiresRepaint(const RenderStyle& other, unsigned& changedContextSensitiveProperties) const
803 {
804     if (inherited_flags._visibility != other.inherited_flags._visibility
805         || inherited_flags.m_printColorAdjust != other.inherited_flags.m_printColorAdjust
806         || inherited_flags._insideLink != other.inherited_flags._insideLink
807         || inherited_flags._insideDefaultButton != other.inherited_flags._insideDefaultButton
808         || surround->border != other.surround->border
809         || !m_background->isEquivalentForPainting(*other.m_background)
810         || rareInheritedData->userModify != other.rareInheritedData->userModify
811         || rareInheritedData->userSelect != other.rareInheritedData->userSelect
812         || rareNonInheritedData->userDrag != other.rareNonInheritedData->userDrag
813         || rareNonInheritedData->m_borderFit != other.rareNonInheritedData->m_borderFit
814         || rareNonInheritedData->m_objectFit != other.rareNonInheritedData->m_objectFit
815         || rareInheritedData->m_imageRendering != other.rareInheritedData->m_imageRendering)
816         return true;
817
818 #if ENABLE(CSS_SHAPES)
819     if (rareNonInheritedData->m_shapeOutside != other.rareNonInheritedData->m_shapeOutside)
820         return true;
821 #endif
822
823     // FIXME: this should probably be moved to changeRequiresLayerRepaint().
824     if (rareNonInheritedData->m_clipPath != other.rareNonInheritedData->m_clipPath) {
825         changedContextSensitiveProperties |= ContextSensitivePropertyClipPath;
826         // Don't return; keep looking for another change.
827     }
828
829     return false;
830 }
831
832 bool RenderStyle::changeRequiresRepaintIfTextOrBorderOrOutline(const RenderStyle& other, unsigned&) const
833 {
834     if (inherited->color != other.inherited->color
835         || inherited_flags._text_decorations != other.inherited_flags._text_decorations
836         || visual->textDecoration != other.visual->textDecoration
837         || rareNonInheritedData->m_textDecorationStyle != other.rareNonInheritedData->m_textDecorationStyle
838         || rareNonInheritedData->m_textDecorationColor != other.rareNonInheritedData->m_textDecorationColor
839         || rareInheritedData->m_textDecorationSkip != other.rareInheritedData->m_textDecorationSkip
840         || rareInheritedData->textFillColor != other.rareInheritedData->textFillColor
841         || rareInheritedData->textStrokeColor != other.rareInheritedData->textStrokeColor
842         || rareInheritedData->textEmphasisColor != other.rareInheritedData->textEmphasisColor
843         || rareInheritedData->textEmphasisFill != other.rareInheritedData->textEmphasisFill)
844         return true;
845
846     return false;
847 }
848
849 bool RenderStyle::changeRequiresRecompositeLayer(const RenderStyle& other, unsigned&) const
850 {
851     if (rareNonInheritedData.get() != other.rareNonInheritedData.get()) {
852         if (rareNonInheritedData->m_transformStyle3D != other.rareNonInheritedData->m_transformStyle3D
853             || rareNonInheritedData->m_backfaceVisibility != other.rareNonInheritedData->m_backfaceVisibility
854             || rareNonInheritedData->m_perspective != other.rareNonInheritedData->m_perspective
855             || rareNonInheritedData->m_perspectiveOriginX != other.rareNonInheritedData->m_perspectiveOriginX
856             || rareNonInheritedData->m_perspectiveOriginY != other.rareNonInheritedData->m_perspectiveOriginY)
857             return true;
858     }
859
860     return false;
861 }
862
863 StyleDifference RenderStyle::diff(const RenderStyle& other, unsigned& changedContextSensitiveProperties) const
864 {
865     changedContextSensitiveProperties = ContextSensitivePropertyNone;
866
867     StyleDifference svgChange = StyleDifferenceEqual;
868     if (m_svgStyle != other.m_svgStyle) {
869         svgChange = m_svgStyle->diff(other.m_svgStyle.get());
870         if (svgChange == StyleDifferenceLayout)
871             return svgChange;
872     }
873
874     if (changeRequiresLayout(other, changedContextSensitiveProperties))
875         return StyleDifferenceLayout;
876
877     // SVGRenderStyle::diff() might have returned StyleDifferenceRepaint, eg. if fill changes.
878     // If eg. the font-size changed at the same time, we're not allowed to return StyleDifferenceRepaint,
879     // but have to return StyleDifferenceLayout, that's why  this if branch comes after all branches
880     // that are relevant for SVG and might return StyleDifferenceLayout.
881     if (svgChange != StyleDifferenceEqual)
882         return svgChange;
883
884     if (changeRequiresPositionedLayoutOnly(other, changedContextSensitiveProperties))
885         return StyleDifferenceLayoutPositionedMovementOnly;
886
887     if (changeRequiresLayerRepaint(other, changedContextSensitiveProperties))
888         return StyleDifferenceRepaintLayer;
889
890     if (changeRequiresRepaint(other, changedContextSensitiveProperties))
891         return StyleDifferenceRepaint;
892
893     if (changeRequiresRecompositeLayer(other, changedContextSensitiveProperties))
894         return StyleDifferenceRecompositeLayer;
895
896     if (changeRequiresRepaintIfTextOrBorderOrOutline(other, changedContextSensitiveProperties))
897         return StyleDifferenceRepaintIfTextOrBorderOrOutline;
898
899     // Cursors are not checked, since they will be set appropriately in response to mouse events,
900     // so they don't need to cause any repaint or layout.
901
902     // 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
903     // the resulting transition properly.
904     return StyleDifferenceEqual;
905 }
906
907 bool RenderStyle::diffRequiresLayerRepaint(const RenderStyle& style, bool isComposited) const
908 {
909     unsigned changedContextSensitiveProperties = 0;
910
911     if (changeRequiresRepaint(style, changedContextSensitiveProperties))
912         return true;
913
914     if (isComposited && changeRequiresLayerRepaint(style, changedContextSensitiveProperties))
915         return changedContextSensitiveProperties & ContextSensitivePropertyClipRect;
916
917     return false;
918 }
919
920 void RenderStyle::setClip(Length top, Length right, Length bottom, Length left)
921 {
922     StyleVisualData* data = visual.access();
923     data->clip.top() = top;
924     data->clip.right() = right;
925     data->clip.bottom() = bottom;
926     data->clip.left() = left;
927 }
928
929 void RenderStyle::addCursor(PassRefPtr<StyleImage> image, const IntPoint& hotSpot)
930 {
931     if (!rareInheritedData.access()->cursorData)
932         rareInheritedData.access()->cursorData = CursorList::create();
933     rareInheritedData.access()->cursorData->append(CursorData(image, hotSpot));
934 }
935
936 void RenderStyle::setCursorList(PassRefPtr<CursorList> other)
937 {
938     rareInheritedData.access()->cursorData = other;
939 }
940
941 void RenderStyle::setQuotes(PassRefPtr<QuotesData> q)
942 {
943     if (rareInheritedData->quotes == q || (rareInheritedData->quotes && q && *rareInheritedData->quotes == *q))
944         return;
945
946     rareInheritedData.access()->quotes = q;
947 }
948
949 void RenderStyle::setWillChange(PassRefPtr<WillChangeData> willChangeData)
950 {
951     if (arePointingToEqualData(rareNonInheritedData->m_willChange.get(), willChangeData.get()))
952         return;
953
954     rareNonInheritedData.access()->m_willChange = WTFMove(willChangeData);
955 }
956
957 void RenderStyle::clearCursorList()
958 {
959     if (rareInheritedData->cursorData)
960         rareInheritedData.access()->cursorData = nullptr;
961 }
962
963 void RenderStyle::clearContent()
964 {
965     if (rareNonInheritedData->m_content)
966         rareNonInheritedData.access()->m_content = nullptr;
967 }
968
969 void RenderStyle::appendContent(std::unique_ptr<ContentData> contentData)
970 {
971     auto& content = rareNonInheritedData.access()->m_content;
972     ContentData* lastContent = content.get();
973     while (lastContent && lastContent->next())
974         lastContent = lastContent->next();
975
976     if (lastContent)
977         lastContent->setNext(WTFMove(contentData));
978     else
979         content = WTFMove(contentData);
980 }
981
982 void RenderStyle::setContent(PassRefPtr<StyleImage> image, bool add)
983 {
984     if (!image)
985         return;
986         
987     if (add) {
988         appendContent(std::make_unique<ImageContentData>(image));
989         return;
990     }
991
992     rareNonInheritedData.access()->m_content = std::make_unique<ImageContentData>(image);
993     if (!rareNonInheritedData.access()->m_altText.isNull())
994         rareNonInheritedData.access()->m_content->setAltText(rareNonInheritedData.access()->m_altText);
995 }
996
997 void RenderStyle::setContent(const String& string, bool add)
998 {
999     auto& content = rareNonInheritedData.access()->m_content;
1000     if (add) {
1001         ContentData* lastContent = content.get();
1002         while (lastContent && lastContent->next())
1003             lastContent = lastContent->next();
1004
1005         if (lastContent) {
1006             // We attempt to merge with the last ContentData if possible.
1007             if (is<TextContentData>(*lastContent)) {
1008                 TextContentData& textContent = downcast<TextContentData>(*lastContent);
1009                 textContent.setText(textContent.text() + string);
1010             } else
1011                 lastContent->setNext(std::make_unique<TextContentData>(string));
1012
1013             if (!rareNonInheritedData.access()->m_altText.isNull())
1014                 lastContent->setAltText(rareNonInheritedData.access()->m_altText);
1015             return;
1016         }
1017     }
1018
1019     content = std::make_unique<TextContentData>(string);
1020     if (!rareNonInheritedData.access()->m_altText.isNull())
1021         content->setAltText(rareNonInheritedData.access()->m_altText);
1022 }
1023
1024 void RenderStyle::setContent(std::unique_ptr<CounterContent> counter, bool add)
1025 {
1026     if (!counter)
1027         return;
1028
1029     if (add) {
1030         appendContent(std::make_unique<CounterContentData>(WTFMove(counter)));
1031         return;
1032     }
1033
1034     rareNonInheritedData.access()->m_content = std::make_unique<CounterContentData>(WTFMove(counter));
1035 }
1036
1037 void RenderStyle::setContent(QuoteType quote, bool add)
1038 {
1039     if (add) {
1040         appendContent(std::make_unique<QuoteContentData>(quote));
1041         return;
1042     }
1043
1044     rareNonInheritedData.access()->m_content = std::make_unique<QuoteContentData>(quote);
1045 }
1046
1047 void RenderStyle::setContentAltText(const String& string)
1048 {
1049     rareNonInheritedData.access()->m_altText = string;
1050     
1051     if (rareNonInheritedData.access()->m_content)
1052         rareNonInheritedData.access()->m_content->setAltText(string);
1053 }
1054
1055 const String& RenderStyle::contentAltText() const
1056 {
1057     return rareNonInheritedData->m_altText;
1058 }
1059
1060 // FIXME: use affectedByTransformOrigin().
1061 static inline bool requireTransformOrigin(const Vector<RefPtr<TransformOperation>>& transformOperations, RenderStyle::ApplyTransformOrigin applyOrigin)
1062 {
1063     // transform-origin brackets the transform with translate operations.
1064     // Optimize for the case where the only transform is a translation, since the transform-origin is irrelevant
1065     // in that case.
1066     if (applyOrigin != RenderStyle::IncludeTransformOrigin)
1067         return false;
1068
1069     for (auto& operation : transformOperations) {
1070         TransformOperation::OperationType type = operation->type();
1071         if (type != TransformOperation::TRANSLATE_X
1072             && type != TransformOperation::TRANSLATE_Y
1073             && type != TransformOperation::TRANSLATE 
1074             && type != TransformOperation::TRANSLATE_Z
1075             && type != TransformOperation::TRANSLATE_3D)
1076             return true;
1077     }
1078
1079     return false;
1080 }
1081
1082 void RenderStyle::applyTransform(TransformationMatrix& transform, const FloatRect& boundingBox, ApplyTransformOrigin applyOrigin) const
1083 {
1084     auto& operations = rareNonInheritedData->m_transform->m_operations.operations();
1085     bool applyTransformOrigin = requireTransformOrigin(operations, applyOrigin);
1086
1087     float offsetX = transformOriginX().isPercent() ? boundingBox.x() : 0;
1088     float offsetY = transformOriginY().isPercent() ? boundingBox.y() : 0;
1089
1090     if (applyTransformOrigin) {
1091         transform.translate3d(floatValueForLength(transformOriginX(), boundingBox.width()) + offsetX,
1092                               floatValueForLength(transformOriginY(), boundingBox.height()) + offsetY,
1093                               transformOriginZ());
1094     }
1095
1096     for (auto& operation : operations)
1097         operation->apply(transform, boundingBox.size());
1098
1099     if (applyTransformOrigin) {
1100         transform.translate3d(-floatValueForLength(transformOriginX(), boundingBox.width()) - offsetX,
1101                               -floatValueForLength(transformOriginY(), boundingBox.height()) - offsetY,
1102                               -transformOriginZ());
1103     }
1104 }
1105
1106 void RenderStyle::setPageScaleTransform(float scale)
1107 {
1108     if (scale == 1)
1109         return;
1110     TransformOperations transform;
1111     transform.operations().append(ScaleTransformOperation::create(scale, scale, ScaleTransformOperation::SCALE));
1112     setTransform(transform);
1113     setTransformOriginX(Length(0, Fixed));
1114     setTransformOriginY(Length(0, Fixed));
1115 }
1116
1117 void RenderStyle::setTextShadow(std::unique_ptr<ShadowData> shadowData, bool add)
1118 {
1119     ASSERT(!shadowData || (!shadowData->spread() && shadowData->style() == Normal));
1120
1121     StyleRareInheritedData* rareData = rareInheritedData.access();
1122     if (!add) {
1123         rareData->textShadow = WTFMove(shadowData);
1124         return;
1125     }
1126
1127     shadowData->setNext(WTFMove(rareData->textShadow));
1128     rareData->textShadow = WTFMove(shadowData);
1129 }
1130
1131 void RenderStyle::setBoxShadow(std::unique_ptr<ShadowData> shadowData, bool add)
1132 {
1133     StyleRareNonInheritedData* rareData = rareNonInheritedData.access();
1134     if (!add) {
1135         rareData->m_boxShadow = WTFMove(shadowData);
1136         return;
1137     }
1138
1139     shadowData->setNext(WTFMove(rareData->m_boxShadow));
1140     rareData->m_boxShadow = WTFMove(shadowData);
1141 }
1142
1143 static RoundedRect::Radii calcRadiiFor(const BorderData& border, const LayoutSize& size)
1144 {
1145     return RoundedRect::Radii(
1146         LayoutSize(valueForLength(border.topLeft().width(), size.width()),
1147             valueForLength(border.topLeft().height(), size.height())),
1148         LayoutSize(valueForLength(border.topRight().width(), size.width()),
1149             valueForLength(border.topRight().height(), size.height())),
1150         LayoutSize(valueForLength(border.bottomLeft().width(), size.width()),
1151             valueForLength(border.bottomLeft().height(), size.height())),
1152         LayoutSize(valueForLength(border.bottomRight().width(), size.width()),
1153             valueForLength(border.bottomRight().height(), size.height())));
1154 }
1155
1156 StyleImage* RenderStyle::listStyleImage() const { return rareInheritedData->listStyleImage.get(); }
1157 void RenderStyle::setListStyleImage(PassRefPtr<StyleImage> v)
1158 {
1159     if (rareInheritedData->listStyleImage != v)
1160         rareInheritedData.access()->listStyleImage = v;
1161 }
1162
1163 Color RenderStyle::color() const { return inherited->color; }
1164 Color RenderStyle::visitedLinkColor() const { return inherited->visitedLinkColor; }
1165 void RenderStyle::setColor(const Color& v) { SET_VAR(inherited, color, v); }
1166 void RenderStyle::setVisitedLinkColor(const Color& v) { SET_VAR(inherited, visitedLinkColor, v); }
1167
1168 short RenderStyle::horizontalBorderSpacing() const { return inherited->horizontal_border_spacing; }
1169 short RenderStyle::verticalBorderSpacing() const { return inherited->vertical_border_spacing; }
1170 void RenderStyle::setHorizontalBorderSpacing(short v) { SET_VAR(inherited, horizontal_border_spacing, v); }
1171 void RenderStyle::setVerticalBorderSpacing(short v) { SET_VAR(inherited, vertical_border_spacing, v); }
1172
1173 RoundedRect RenderStyle::getRoundedBorderFor(const LayoutRect& borderRect, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
1174 {
1175     RoundedRect roundedRect(borderRect);
1176     if (hasBorderRadius()) {
1177         RoundedRect::Radii radii = calcRadiiFor(surround->border, borderRect.size());
1178         radii.scale(calcBorderRadiiConstraintScaleFor(borderRect, radii));
1179         roundedRect.includeLogicalEdges(radii, isHorizontalWritingMode(), includeLogicalLeftEdge, includeLogicalRightEdge);
1180     }
1181     return roundedRect;
1182 }
1183
1184 RoundedRect RenderStyle::getRoundedInnerBorderFor(const LayoutRect& borderRect, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
1185 {
1186     bool horizontal = isHorizontalWritingMode();
1187
1188     LayoutUnit leftWidth = (!horizontal || includeLogicalLeftEdge) ? borderLeftWidth() : 0;
1189     LayoutUnit rightWidth = (!horizontal || includeLogicalRightEdge) ? borderRightWidth() : 0;
1190     LayoutUnit topWidth = (horizontal || includeLogicalLeftEdge) ? borderTopWidth() : 0;
1191     LayoutUnit bottomWidth = (horizontal || includeLogicalRightEdge) ? borderBottomWidth() : 0;
1192
1193     return getRoundedInnerBorderFor(borderRect, topWidth, bottomWidth, leftWidth, rightWidth, includeLogicalLeftEdge, includeLogicalRightEdge);
1194 }
1195
1196 RoundedRect RenderStyle::getRoundedInnerBorderFor(const LayoutRect& borderRect, LayoutUnit topWidth, LayoutUnit bottomWidth,
1197     LayoutUnit leftWidth, LayoutUnit rightWidth, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
1198 {
1199     LayoutRect innerRect(borderRect.x() + leftWidth, 
1200                borderRect.y() + topWidth, 
1201                borderRect.width() - leftWidth - rightWidth, 
1202                borderRect.height() - topWidth - bottomWidth);
1203
1204     RoundedRect roundedRect(innerRect);
1205
1206     if (hasBorderRadius()) {
1207         RoundedRect::Radii radii = getRoundedBorderFor(borderRect).radii();
1208         radii.shrink(topWidth, bottomWidth, leftWidth, rightWidth);
1209         roundedRect.includeLogicalEdges(radii, isHorizontalWritingMode(), includeLogicalLeftEdge, includeLogicalRightEdge);
1210     }
1211     return roundedRect;
1212 }
1213
1214 static bool allLayersAreFixed(const FillLayer* layer)
1215 {
1216     bool allFixed = true;
1217     
1218     for (const FillLayer* currLayer = layer; currLayer; currLayer = currLayer->next())
1219         allFixed &= (currLayer->image() && currLayer->attachment() == FixedBackgroundAttachment);
1220
1221     return layer && allFixed;
1222 }
1223
1224 bool RenderStyle::hasEntirelyFixedBackground() const
1225 {
1226     return allLayersAreFixed(backgroundLayers());
1227 }
1228
1229 const CounterDirectiveMap* RenderStyle::counterDirectives() const
1230 {
1231     return rareNonInheritedData->m_counterDirectives.get();
1232 }
1233
1234 CounterDirectiveMap& RenderStyle::accessCounterDirectives()
1235 {
1236     auto& map = rareNonInheritedData.access()->m_counterDirectives;
1237     if (!map)
1238         map = std::make_unique<CounterDirectiveMap>();
1239     return *map;
1240 }
1241
1242 const CounterDirectives RenderStyle::getCounterDirectives(const AtomicString& identifier) const
1243 {
1244     if (const CounterDirectiveMap* directives = counterDirectives())
1245         return directives->get(identifier);
1246     return CounterDirectives();
1247 }
1248
1249 const AtomicString& RenderStyle::hyphenString() const
1250 {
1251     ASSERT(hyphens() != HyphensNone);
1252
1253     const AtomicString& hyphenationString = rareInheritedData.get()->hyphenationString;
1254     if (!hyphenationString.isNull())
1255         return hyphenationString;
1256
1257     // FIXME: This should depend on locale.
1258     static NeverDestroyed<AtomicString> hyphenMinusString(&hyphenMinus, 1);
1259     static NeverDestroyed<AtomicString> hyphenString(&hyphen, 1);
1260     return fontCascade().primaryFont().glyphForCharacter(hyphen) ? hyphenString : hyphenMinusString;
1261 }
1262
1263 const AtomicString& RenderStyle::textEmphasisMarkString() const
1264 {
1265     switch (textEmphasisMark()) {
1266     case TextEmphasisMarkNone:
1267         return nullAtom;
1268     case TextEmphasisMarkCustom:
1269         return textEmphasisCustomMark();
1270     case TextEmphasisMarkDot: {
1271         static NeverDestroyed<AtomicString> filledDotString(&bullet, 1);
1272         static NeverDestroyed<AtomicString> openDotString(&whiteBullet, 1);
1273         return textEmphasisFill() == TextEmphasisFillFilled ? filledDotString : openDotString;
1274     }
1275     case TextEmphasisMarkCircle: {
1276         static NeverDestroyed<AtomicString> filledCircleString(&blackCircle, 1);
1277         static NeverDestroyed<AtomicString> openCircleString(&whiteCircle, 1);
1278         return textEmphasisFill() == TextEmphasisFillFilled ? filledCircleString : openCircleString;
1279     }
1280     case TextEmphasisMarkDoubleCircle: {
1281         static NeverDestroyed<AtomicString> filledDoubleCircleString(&fisheye, 1);
1282         static NeverDestroyed<AtomicString> openDoubleCircleString(&bullseye, 1);
1283         return textEmphasisFill() == TextEmphasisFillFilled ? filledDoubleCircleString : openDoubleCircleString;
1284     }
1285     case TextEmphasisMarkTriangle: {
1286         static NeverDestroyed<AtomicString> filledTriangleString(&blackUpPointingTriangle, 1);
1287         static NeverDestroyed<AtomicString> openTriangleString(&whiteUpPointingTriangle, 1);
1288         return textEmphasisFill() == TextEmphasisFillFilled ? filledTriangleString : openTriangleString;
1289     }
1290     case TextEmphasisMarkSesame: {
1291         static NeverDestroyed<AtomicString> filledSesameString(&sesameDot, 1);
1292         static NeverDestroyed<AtomicString> openSesameString(&whiteSesameDot, 1);
1293         return textEmphasisFill() == TextEmphasisFillFilled ? filledSesameString : openSesameString;
1294     }
1295     case TextEmphasisMarkAuto:
1296         ASSERT_NOT_REACHED();
1297         return nullAtom;
1298     }
1299
1300     ASSERT_NOT_REACHED();
1301     return nullAtom;
1302 }
1303
1304 #if ENABLE(DASHBOARD_SUPPORT)
1305 const Vector<StyleDashboardRegion>& RenderStyle::initialDashboardRegions()
1306 {
1307     static NeverDestroyed<Vector<StyleDashboardRegion>> emptyList;
1308     return emptyList;
1309 }
1310
1311 const Vector<StyleDashboardRegion>& RenderStyle::noneDashboardRegions()
1312 {
1313     static NeverDestroyed<Vector<StyleDashboardRegion>> noneList;
1314     static bool noneListInitialized = false;
1315
1316     if (!noneListInitialized) {
1317         StyleDashboardRegion region;
1318         region.label = "";
1319         region.offset.top()  = Length();
1320         region.offset.right() = Length();
1321         region.offset.bottom() = Length();
1322         region.offset.left() = Length();
1323         region.type = StyleDashboardRegion::None;
1324         noneList.get().append(region);
1325         noneListInitialized = true;
1326     }
1327     return noneList;
1328 }
1329 #endif
1330
1331 void RenderStyle::adjustAnimations()
1332 {
1333     AnimationList* animationList = rareNonInheritedData->m_animations.get();
1334     if (!animationList)
1335         return;
1336
1337     // Get rid of empty animations and anything beyond them
1338     for (size_t i = 0; i < animationList->size(); ++i) {
1339         if (animationList->animation(i).isEmpty()) {
1340             animationList->resize(i);
1341             break;
1342         }
1343     }
1344
1345     if (animationList->isEmpty()) {
1346         clearAnimations();
1347         return;
1348     }
1349
1350     // Repeat patterns into layers that don't have some properties set.
1351     animationList->fillUnsetProperties();
1352 }
1353
1354 void RenderStyle::adjustTransitions()
1355 {
1356     AnimationList* transitionList = rareNonInheritedData->m_transitions.get();
1357     if (!transitionList)
1358         return;
1359
1360     // Get rid of empty transitions and anything beyond them
1361     for (size_t i = 0; i < transitionList->size(); ++i) {
1362         if (transitionList->animation(i).isEmpty()) {
1363             transitionList->resize(i);
1364             break;
1365         }
1366     }
1367
1368     if (transitionList->isEmpty()) {
1369         clearTransitions();
1370         return;
1371     }
1372
1373     // Repeat patterns into layers that don't have some properties set.
1374     transitionList->fillUnsetProperties();
1375
1376     // Make sure there are no duplicate properties. This is an O(n^2) algorithm
1377     // but the lists tend to be very short, so it is probably ok
1378     for (size_t i = 0; i < transitionList->size(); ++i) {
1379         for (size_t j = i+1; j < transitionList->size(); ++j) {
1380             if (transitionList->animation(i).property() == transitionList->animation(j).property()) {
1381                 // toss i
1382                 transitionList->remove(i);
1383                 j = i;
1384             }
1385         }
1386     }
1387 }
1388
1389 AnimationList& RenderStyle::ensureAnimations()
1390 {
1391     if (!rareNonInheritedData.access()->m_animations)
1392         rareNonInheritedData.access()->m_animations = std::make_unique<AnimationList>();
1393     return *rareNonInheritedData->m_animations;
1394 }
1395
1396 AnimationList& RenderStyle::ensureTransitions()
1397 {
1398     if (!rareNonInheritedData.access()->m_transitions)
1399         rareNonInheritedData.access()->m_transitions = std::make_unique<AnimationList>();
1400     return *rareNonInheritedData->m_transitions;
1401 }
1402
1403 const Animation* RenderStyle::transitionForProperty(CSSPropertyID property) const
1404 {
1405     if (transitions()) {
1406         for (size_t i = 0; i < transitions()->size(); ++i) {
1407             const Animation& p = transitions()->animation(i);
1408             if (p.animationMode() == Animation::AnimateAll || p.property() == property) {
1409                 return &p;
1410             }
1411         }
1412     }
1413     return 0;
1414 }
1415
1416 const FontCascade& RenderStyle::fontCascade() const { return inherited->fontCascade; }
1417 const FontMetrics& RenderStyle::fontMetrics() const { return inherited->fontCascade.fontMetrics(); }
1418 const FontCascadeDescription& RenderStyle::fontDescription() const { return inherited->fontCascade.fontDescription(); }
1419 float RenderStyle::specifiedFontSize() const { return fontDescription().specifiedSize(); }
1420 float RenderStyle::computedFontSize() const { return fontDescription().computedSize(); }
1421 int RenderStyle::fontSize() const { return inherited->fontCascade.pixelSize(); }
1422
1423 const Length& RenderStyle::wordSpacing() const { return rareInheritedData->wordSpacing; }
1424 float RenderStyle::letterSpacing() const { return inherited->fontCascade.letterSpacing(); }
1425
1426 bool RenderStyle::setFontDescription(const FontCascadeDescription& v)
1427 {
1428     if (inherited->fontCascade.fontDescription() != v) {
1429         inherited.access()->fontCascade = FontCascade(v, inherited->fontCascade.letterSpacing(), inherited->fontCascade.wordSpacing());
1430         return true;
1431     }
1432     return false;
1433 }
1434
1435 #if ENABLE(IOS_TEXT_AUTOSIZING)
1436 const Length& RenderStyle::specifiedLineHeight() const { return inherited->specifiedLineHeight; }
1437 void RenderStyle::setSpecifiedLineHeight(Length v) { SET_VAR(inherited, specifiedLineHeight, v); }
1438 #else
1439 const Length& RenderStyle::specifiedLineHeight() const { return inherited->line_height; }
1440 #endif
1441
1442 Length RenderStyle::lineHeight() const
1443 {
1444     const Length& lh = inherited->line_height;
1445 #if ENABLE(TEXT_AUTOSIZING)
1446     // Unlike fontDescription().computedSize() and hence fontSize(), this is
1447     // recalculated on demand as we only store the specified line height.
1448     // FIXME: Should consider scaling the fixed part of any calc expressions
1449     // too, though this involves messily poking into CalcExpressionLength.
1450     float multiplier = textAutosizingMultiplier();
1451     if (multiplier > 1 && lh.isFixed())
1452         return Length(TextAutosizer::computeAutosizedFontSize(lh.value(), multiplier), Fixed);
1453 #endif
1454     return lh;
1455 }
1456 void RenderStyle::setLineHeight(Length specifiedLineHeight) { SET_VAR(inherited, line_height, specifiedLineHeight); }
1457
1458 int RenderStyle::computedLineHeight() const
1459 {
1460     const Length& lh = lineHeight();
1461
1462     // Negative value means the line height is not set. Use the font's built-in spacing.
1463     if (lh.isNegative())
1464         return fontMetrics().lineSpacing();
1465
1466     if (lh.isPercentOrCalculated())
1467         return minimumValueForLength(lh, fontSize());
1468
1469     return clampTo<int>(lh.value());
1470 }
1471
1472 void RenderStyle::setWordSpacing(Length value)
1473 {
1474     float fontWordSpacing;
1475     switch (value.type()) {
1476     case Auto:
1477         fontWordSpacing = 0;
1478         break;
1479     case Percent:
1480         fontWordSpacing = value.percent() * fontCascade().spaceWidth() / 100;
1481         break;
1482     case Fixed:
1483         fontWordSpacing = value.value();
1484         break;
1485     case Calculated:
1486         fontWordSpacing = value.nonNanCalculatedValue(maxValueForCssLength);
1487         break;
1488     default:
1489         ASSERT_NOT_REACHED();
1490         fontWordSpacing = 0;
1491         break;
1492     }
1493     inherited.access()->fontCascade.setWordSpacing(fontWordSpacing);
1494     rareInheritedData.access()->wordSpacing = WTFMove(value);
1495 }
1496
1497 void RenderStyle::setLetterSpacing(float v) { inherited.access()->fontCascade.setLetterSpacing(v); }
1498
1499 void RenderStyle::setFontSize(float size)
1500 {
1501     // size must be specifiedSize if Text Autosizing is enabled, but computedSize if text
1502     // zoom is enabled (if neither is enabled it's irrelevant as they're probably the same).
1503
1504     ASSERT(std::isfinite(size));
1505     if (!std::isfinite(size) || size < 0)
1506         size = 0;
1507     else
1508         size = std::min(maximumAllowedFontSize, size);
1509
1510     FontSelector* currentFontSelector = fontCascade().fontSelector();
1511     auto description = fontDescription();
1512     description.setSpecifiedSize(size);
1513     description.setComputedSize(size);
1514
1515 #if ENABLE(TEXT_AUTOSIZING)
1516     float multiplier = textAutosizingMultiplier();
1517     if (multiplier > 1) {
1518         float autosizedFontSize = TextAutosizer::computeAutosizedFontSize(size, multiplier);
1519         description.setComputedSize(min(maximumAllowedFontSize, autosizedFontSize));
1520     }
1521 #endif
1522
1523     setFontDescription(description);
1524     fontCascade().update(currentFontSelector);
1525 }
1526
1527 void RenderStyle::getShadowExtent(const ShadowData* shadow, LayoutUnit &top, LayoutUnit &right, LayoutUnit &bottom, LayoutUnit &left) const
1528 {
1529     top = 0;
1530     right = 0;
1531     bottom = 0;
1532     left = 0;
1533
1534     for ( ; shadow; shadow = shadow->next()) {
1535         if (shadow->style() == Inset)
1536             continue;
1537
1538         int extentAndSpread = shadow->paintingExtent() + shadow->spread();
1539         top = std::min<LayoutUnit>(top, shadow->y() - extentAndSpread);
1540         right = std::max<LayoutUnit>(right, shadow->x() + extentAndSpread);
1541         bottom = std::max<LayoutUnit>(bottom, shadow->y() + extentAndSpread);
1542         left = std::min<LayoutUnit>(left, shadow->x() - extentAndSpread);
1543     }
1544 }
1545
1546 LayoutBoxExtent RenderStyle::getShadowInsetExtent(const ShadowData* shadow) const
1547 {
1548     LayoutUnit top = 0;
1549     LayoutUnit right = 0;
1550     LayoutUnit bottom = 0;
1551     LayoutUnit left = 0;
1552
1553     for ( ; shadow; shadow = shadow->next()) {
1554         if (shadow->style() == Normal)
1555             continue;
1556
1557         int extentAndSpread = shadow->paintingExtent() + shadow->spread();
1558         top = std::max<LayoutUnit>(top, shadow->y() + extentAndSpread);
1559         right = std::min<LayoutUnit>(right, shadow->x() - extentAndSpread);
1560         bottom = std::min<LayoutUnit>(bottom, shadow->y() - extentAndSpread);
1561         left = std::max<LayoutUnit>(left, shadow->x() + extentAndSpread);
1562     }
1563
1564     return LayoutBoxExtent(top, right, bottom, left);
1565 }
1566
1567 void RenderStyle::getShadowHorizontalExtent(const ShadowData* shadow, LayoutUnit &left, LayoutUnit &right) const
1568 {
1569     left = 0;
1570     right = 0;
1571
1572     for ( ; shadow; shadow = shadow->next()) {
1573         if (shadow->style() == Inset)
1574             continue;
1575
1576         int extentAndSpread = shadow->paintingExtent() + shadow->spread();
1577         left = std::min<LayoutUnit>(left, shadow->x() - extentAndSpread);
1578         right = std::max<LayoutUnit>(right, shadow->x() + extentAndSpread);
1579     }
1580 }
1581
1582 void RenderStyle::getShadowVerticalExtent(const ShadowData* shadow, LayoutUnit &top, LayoutUnit &bottom) const
1583 {
1584     top = 0;
1585     bottom = 0;
1586
1587     for ( ; shadow; shadow = shadow->next()) {
1588         if (shadow->style() == Inset)
1589             continue;
1590
1591         int extentAndSpread = shadow->paintingExtent() + shadow->spread();
1592         top = std::min<LayoutUnit>(top, shadow->y() - extentAndSpread);
1593         bottom = std::max<LayoutUnit>(bottom, shadow->y() + extentAndSpread);
1594     }
1595 }
1596
1597 Color RenderStyle::colorIncludingFallback(int colorProperty, bool visitedLink) const
1598 {
1599     Color result;
1600     EBorderStyle borderStyle = BNONE;
1601     switch (colorProperty) {
1602     case CSSPropertyBackgroundColor:
1603         return visitedLink ? visitedLinkBackgroundColor() : backgroundColor(); // Background color doesn't fall back.
1604     case CSSPropertyBorderLeftColor:
1605         result = visitedLink ? visitedLinkBorderLeftColor() : borderLeftColor();
1606         borderStyle = borderLeftStyle();
1607         break;
1608     case CSSPropertyBorderRightColor:
1609         result = visitedLink ? visitedLinkBorderRightColor() : borderRightColor();
1610         borderStyle = borderRightStyle();
1611         break;
1612     case CSSPropertyBorderTopColor:
1613         result = visitedLink ? visitedLinkBorderTopColor() : borderTopColor();
1614         borderStyle = borderTopStyle();
1615         break;
1616     case CSSPropertyBorderBottomColor:
1617         result = visitedLink ? visitedLinkBorderBottomColor() : borderBottomColor();
1618         borderStyle = borderBottomStyle();
1619         break;
1620     case CSSPropertyColor:
1621         result = visitedLink ? visitedLinkColor() : color();
1622         break;
1623     case CSSPropertyOutlineColor:
1624         result = visitedLink ? visitedLinkOutlineColor() : outlineColor();
1625         break;
1626     case CSSPropertyColumnRuleColor:
1627         result = visitedLink ? visitedLinkColumnRuleColor() : columnRuleColor();
1628         break;
1629     case CSSPropertyWebkitTextDecorationColor:
1630         // Text decoration color fallback is handled in RenderObject::decorationColor.
1631         return visitedLink ? visitedLinkTextDecorationColor() : textDecorationColor();
1632     case CSSPropertyWebkitTextEmphasisColor:
1633         result = visitedLink ? visitedLinkTextEmphasisColor() : textEmphasisColor();
1634         break;
1635     case CSSPropertyWebkitTextFillColor:
1636         result = visitedLink ? visitedLinkTextFillColor() : textFillColor();
1637         break;
1638     case CSSPropertyWebkitTextStrokeColor:
1639         result = visitedLink ? visitedLinkTextStrokeColor() : textStrokeColor();
1640         break;
1641     default:
1642         ASSERT_NOT_REACHED();
1643         break;
1644     }
1645
1646     if (!result.isValid()) {
1647         if (!visitedLink && (borderStyle == INSET || borderStyle == OUTSET || borderStyle == RIDGE || borderStyle == GROOVE))
1648             result.setRGB(238, 238, 238);
1649         else
1650             result = visitedLink ? visitedLinkColor() : color();
1651     }
1652     return result;
1653 }
1654
1655 Color RenderStyle::visitedDependentColor(int colorProperty) const
1656 {
1657     Color unvisitedColor = colorIncludingFallback(colorProperty, false);
1658     if (insideLink() != InsideVisitedLink)
1659         return unvisitedColor;
1660
1661     Color visitedColor = colorIncludingFallback(colorProperty, true);
1662
1663     // Text decoration color validity is preserved (checked in RenderObject::decorationColor).
1664     if (colorProperty == CSSPropertyWebkitTextDecorationColor)
1665         return visitedColor;
1666
1667     // FIXME: Technically someone could explicitly specify the color transparent, but for now we'll just
1668     // assume that if the background color is transparent that it wasn't set. Note that it's weird that
1669     // we're returning unvisited info for a visited link, but given our restriction that the alpha values
1670     // have to match, it makes more sense to return the unvisited background color if specified than it
1671     // does to return black. This behavior matches what Firefox 4 does as well.
1672     if (colorProperty == CSSPropertyBackgroundColor && visitedColor == Color::transparent)
1673         return unvisitedColor;
1674
1675     // Take the alpha from the unvisited color, but get the RGB values from the visited color.
1676     return Color(visitedColor.red(), visitedColor.green(), visitedColor.blue(), unvisitedColor.alpha());
1677 }
1678
1679 const BorderValue& RenderStyle::borderBefore() const
1680 {
1681     switch (writingMode()) {
1682     case TopToBottomWritingMode:
1683         return borderTop();
1684     case BottomToTopWritingMode:
1685         return borderBottom();
1686     case LeftToRightWritingMode:
1687         return borderLeft();
1688     case RightToLeftWritingMode:
1689         return borderRight();
1690     }
1691     ASSERT_NOT_REACHED();
1692     return borderTop();
1693 }
1694
1695 const BorderValue& RenderStyle::borderAfter() const
1696 {
1697     switch (writingMode()) {
1698     case TopToBottomWritingMode:
1699         return borderBottom();
1700     case BottomToTopWritingMode:
1701         return borderTop();
1702     case LeftToRightWritingMode:
1703         return borderRight();
1704     case RightToLeftWritingMode:
1705         return borderLeft();
1706     }
1707     ASSERT_NOT_REACHED();
1708     return borderBottom();
1709 }
1710
1711 const BorderValue& RenderStyle::borderStart() const
1712 {
1713     if (isHorizontalWritingMode())
1714         return isLeftToRightDirection() ? borderLeft() : borderRight();
1715     return isLeftToRightDirection() ? borderTop() : borderBottom();
1716 }
1717
1718 const BorderValue& RenderStyle::borderEnd() const
1719 {
1720     if (isHorizontalWritingMode())
1721         return isLeftToRightDirection() ? borderRight() : borderLeft();
1722     return isLeftToRightDirection() ? borderBottom() : borderTop();
1723 }
1724
1725 float RenderStyle::borderBeforeWidth() const
1726 {
1727     switch (writingMode()) {
1728     case TopToBottomWritingMode:
1729         return borderTopWidth();
1730     case BottomToTopWritingMode:
1731         return borderBottomWidth();
1732     case LeftToRightWritingMode:
1733         return borderLeftWidth();
1734     case RightToLeftWritingMode:
1735         return borderRightWidth();
1736     }
1737     ASSERT_NOT_REACHED();
1738     return borderTopWidth();
1739 }
1740
1741 float RenderStyle::borderAfterWidth() const
1742 {
1743     switch (writingMode()) {
1744     case TopToBottomWritingMode:
1745         return borderBottomWidth();
1746     case BottomToTopWritingMode:
1747         return borderTopWidth();
1748     case LeftToRightWritingMode:
1749         return borderRightWidth();
1750     case RightToLeftWritingMode:
1751         return borderLeftWidth();
1752     }
1753     ASSERT_NOT_REACHED();
1754     return borderBottomWidth();
1755 }
1756
1757 float RenderStyle::borderStartWidth() const
1758 {
1759     if (isHorizontalWritingMode())
1760         return isLeftToRightDirection() ? borderLeftWidth() : borderRightWidth();
1761     return isLeftToRightDirection() ? borderTopWidth() : borderBottomWidth();
1762 }
1763
1764 float RenderStyle::borderEndWidth() const
1765 {
1766     if (isHorizontalWritingMode())
1767         return isLeftToRightDirection() ? borderRightWidth() : borderLeftWidth();
1768     return isLeftToRightDirection() ? borderBottomWidth() : borderTopWidth();
1769 }
1770
1771 void RenderStyle::setMarginStart(Length margin)
1772 {
1773     if (isHorizontalWritingMode()) {
1774         if (isLeftToRightDirection())
1775             setMarginLeft(margin);
1776         else
1777             setMarginRight(margin);
1778     } else {
1779         if (isLeftToRightDirection())
1780             setMarginTop(margin);
1781         else
1782             setMarginBottom(margin);
1783     }
1784 }
1785
1786 void RenderStyle::setMarginEnd(Length margin)
1787 {
1788     if (isHorizontalWritingMode()) {
1789         if (isLeftToRightDirection())
1790             setMarginRight(margin);
1791         else
1792             setMarginLeft(margin);
1793     } else {
1794         if (isLeftToRightDirection())
1795             setMarginBottom(margin);
1796         else
1797             setMarginTop(margin);
1798     }
1799 }
1800
1801 TextEmphasisMark RenderStyle::textEmphasisMark() const
1802 {
1803     TextEmphasisMark mark = static_cast<TextEmphasisMark>(rareInheritedData->textEmphasisMark);
1804     if (mark != TextEmphasisMarkAuto)
1805         return mark;
1806
1807     if (isHorizontalWritingMode())
1808         return TextEmphasisMarkDot;
1809
1810     return TextEmphasisMarkSesame;
1811 }
1812
1813 #if ENABLE(TOUCH_EVENTS)
1814 Color RenderStyle::initialTapHighlightColor()
1815 {
1816     return RenderTheme::tapHighlightColor();
1817 }
1818 #endif
1819
1820 LayoutBoxExtent RenderStyle::imageOutsets(const NinePieceImage& image) const
1821 {
1822     return LayoutBoxExtent(NinePieceImage::computeOutset(image.outset().top(), borderTopWidth()),
1823                            NinePieceImage::computeOutset(image.outset().right(), borderRightWidth()),
1824                            NinePieceImage::computeOutset(image.outset().bottom(), borderBottomWidth()),
1825                            NinePieceImage::computeOutset(image.outset().left(), borderLeftWidth()));
1826 }
1827
1828 std::pair<FontOrientation, NonCJKGlyphOrientation> RenderStyle::fontAndGlyphOrientation()
1829 {
1830     // FIXME: TextOrientationSideways should map to sideways-left in vertical-lr, which is not supported yet.
1831
1832     if (isHorizontalWritingMode())
1833         return { Horizontal, NonCJKGlyphOrientation::Mixed };
1834
1835     switch (textOrientation()) {
1836     case TextOrientation::Mixed:
1837         return { Vertical, NonCJKGlyphOrientation::Mixed };
1838     case TextOrientation::Upright:
1839         return { Vertical, NonCJKGlyphOrientation::Upright };
1840     case TextOrientation::Sideways:
1841         return { Horizontal, NonCJKGlyphOrientation::Mixed };
1842     default:
1843         ASSERT_NOT_REACHED();
1844         return { Horizontal, NonCJKGlyphOrientation::Mixed };
1845     }
1846 }
1847
1848 void RenderStyle::setBorderImageSource(PassRefPtr<StyleImage> image)
1849 {
1850     if (surround->border.m_image.image() == image.get())
1851         return;
1852     surround.access()->border.m_image.setImage(image);
1853 }
1854
1855 void RenderStyle::setBorderImageSlices(LengthBox slices)
1856 {
1857     if (surround->border.m_image.imageSlices() == slices)
1858         return;
1859     surround.access()->border.m_image.setImageSlices(slices);
1860 }
1861
1862 void RenderStyle::setBorderImageWidth(LengthBox slices)
1863 {
1864     if (surround->border.m_image.borderSlices() == slices)
1865         return;
1866     surround.access()->border.m_image.setBorderSlices(slices);
1867 }
1868
1869 void RenderStyle::setBorderImageOutset(LengthBox outset)
1870 {
1871     if (surround->border.m_image.outset() == outset)
1872         return;
1873     surround.access()->border.m_image.setOutset(outset);
1874 }
1875
1876 void RenderStyle::setColumnStylesFromPaginationMode(const Pagination::Mode& paginationMode)
1877 {
1878     if (paginationMode == Pagination::Unpaginated)
1879         return;
1880     
1881     setColumnFill(ColumnFillAuto);
1882     
1883     switch (paginationMode) {
1884     case Pagination::LeftToRightPaginated:
1885         setColumnAxis(HorizontalColumnAxis);
1886         if (isHorizontalWritingMode())
1887             setColumnProgression(isLeftToRightDirection() ? NormalColumnProgression : ReverseColumnProgression);
1888         else
1889             setColumnProgression(isFlippedBlocksWritingMode() ? ReverseColumnProgression : NormalColumnProgression);
1890         break;
1891     case Pagination::RightToLeftPaginated:
1892         setColumnAxis(HorizontalColumnAxis);
1893         if (isHorizontalWritingMode())
1894             setColumnProgression(isLeftToRightDirection() ? ReverseColumnProgression : NormalColumnProgression);
1895         else
1896             setColumnProgression(isFlippedBlocksWritingMode() ? NormalColumnProgression : ReverseColumnProgression);
1897         break;
1898     case Pagination::TopToBottomPaginated:
1899         setColumnAxis(VerticalColumnAxis);
1900         if (isHorizontalWritingMode())
1901             setColumnProgression(isFlippedBlocksWritingMode() ? ReverseColumnProgression : NormalColumnProgression);
1902         else
1903             setColumnProgression(isLeftToRightDirection() ? NormalColumnProgression : ReverseColumnProgression);
1904         break;
1905     case Pagination::BottomToTopPaginated:
1906         setColumnAxis(VerticalColumnAxis);
1907         if (isHorizontalWritingMode())
1908             setColumnProgression(isFlippedBlocksWritingMode() ? NormalColumnProgression : ReverseColumnProgression);
1909         else
1910             setColumnProgression(isLeftToRightDirection() ? ReverseColumnProgression : NormalColumnProgression);
1911         break;
1912     case Pagination::Unpaginated:
1913         ASSERT_NOT_REACHED();
1914         break;
1915     }
1916 }
1917
1918 #if ENABLE(CSS_SCROLL_SNAP)
1919 LengthSize RenderStyle::initialScrollSnapDestination()
1920 {
1921     return defaultScrollSnapDestination();
1922 }
1923
1924 Vector<LengthSize> RenderStyle::initialScrollSnapCoordinates()
1925 {
1926     return Vector<LengthSize>();
1927 }
1928
1929 const ScrollSnapPoints* RenderStyle::scrollSnapPointsX() const
1930 {
1931     return rareNonInheritedData->m_scrollSnapPoints->xPoints.get();
1932 }
1933
1934 const ScrollSnapPoints* RenderStyle::scrollSnapPointsY() const
1935 {
1936     return rareNonInheritedData->m_scrollSnapPoints->yPoints.get();
1937 }
1938
1939 const LengthSize& RenderStyle::scrollSnapDestination() const
1940 {
1941     return rareNonInheritedData->m_scrollSnapPoints->destination;
1942 }
1943
1944 const Vector<LengthSize>& RenderStyle::scrollSnapCoordinates() const
1945 {
1946     return rareNonInheritedData->m_scrollSnapPoints->coordinates;
1947 }
1948
1949 void RenderStyle::setScrollSnapPointsX(std::unique_ptr<ScrollSnapPoints> points)
1950 {
1951     if (rareNonInheritedData->m_scrollSnapPoints->xPoints.get() == points.get())
1952         return;
1953     rareNonInheritedData.access()->m_scrollSnapPoints.access()->xPoints = WTFMove(points);
1954 }
1955
1956 void RenderStyle::setScrollSnapPointsY(std::unique_ptr<ScrollSnapPoints> points)
1957 {
1958     if (rareNonInheritedData->m_scrollSnapPoints->yPoints.get() == points.get())
1959         return;
1960     rareNonInheritedData.access()->m_scrollSnapPoints.access()->yPoints = WTFMove(points);
1961 }
1962
1963 void RenderStyle::setScrollSnapDestination(LengthSize destination)
1964 {
1965     if (rareNonInheritedData->m_scrollSnapPoints->destination == destination)
1966         return;
1967     rareNonInheritedData.access()->m_scrollSnapPoints.access()->destination = WTFMove(destination);
1968 }
1969
1970 void RenderStyle::setScrollSnapCoordinates(Vector<LengthSize> coordinates)
1971 {
1972     if (rareNonInheritedData->m_scrollSnapPoints->coordinates == coordinates)
1973         return;
1974     rareNonInheritedData.access()->m_scrollSnapPoints.access()->coordinates = WTFMove(coordinates);
1975 }
1976
1977 #endif
1978
1979 void RenderStyle::checkVariablesInCustomProperties()
1980 {
1981     if (!rareInheritedData->m_customProperties->containsVariables())
1982         return;
1983     
1984     // Our first pass checks the variables for validity and replaces any properties that became
1985     // invalid with empty values.
1986     auto& customProperties = rareInheritedData.access()->m_customProperties.access()->values();
1987     HashSet<AtomicString> invalidProperties;
1988     for (auto entry : customProperties) {
1989         if (!entry.value->isVariableDependentValue())
1990             continue;
1991         HashSet<AtomicString> seenProperties;
1992         downcast<CSSVariableDependentValue>(*entry.value).checkVariablesForCycles(entry.key, customProperties, seenProperties, invalidProperties);
1993     }
1994     
1995     // Now insert invalid values.
1996     if (!invalidProperties.isEmpty()) {
1997         RefPtr<CSSValue> invalidValue = CSSCustomPropertyValue::createInvalid();
1998         for (auto& property : invalidProperties)
1999             customProperties.set(property, invalidValue);
2000     }
2001
2002     // Now that all of the properties have been tested for validity and replaced with
2003     // invalid values if they failed, we can perform variable substitution on the valid values.
2004     Vector<RefPtr<CSSCustomPropertyValue>> resolvedValues;
2005     for (auto entry : customProperties) {
2006         if (!entry.value->isVariableDependentValue())
2007             continue;
2008         
2009         CSSParserValueList parserList;
2010         RefPtr<CSSCustomPropertyValue> result;
2011         if (!downcast<CSSVariableDependentValue>(*entry.value).valueList()->buildParserValueListSubstitutingVariables(&parserList, customProperties)) {
2012             RefPtr<CSSValue> invalidResult = CSSCustomPropertyValue::createInvalid();
2013             result = CSSCustomPropertyValue::create(entry.key, invalidResult);
2014         } else {
2015             RefPtr<CSSValue> newValueList = CSSValueList::createFromParserValueList(parserList);
2016             result = CSSCustomPropertyValue::create(entry.key, newValueList);
2017         }
2018         resolvedValues.append(result);
2019     }
2020     
2021     // With all results computed, we can now mutate our table to eliminate the variables and
2022     // hold the final values. This way when we inherit, we don't end up resubstituting variables, etc.
2023     for (auto& resolvedValue : resolvedValues)
2024         customProperties.set(resolvedValue->name(), resolvedValue->value());
2025
2026     rareInheritedData.access()->m_customProperties.access()->setContainsVariables(false);
2027 }
2028
2029 } // namespace WebCore