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