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