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