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