[CSS Grid Layout] Upgrade align-self and align-items parsing to CSS 3
[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.get() != other.rareNonInheritedData->m_transform.get()
486             && *rareNonInheritedData->m_transform.get() != *other.rareNonInheritedData->m_transform.get()) {
487             changedContextSensitiveProperties |= ContextSensitivePropertyTransform;
488             // Don't return; keep looking for another change
489         }
490
491 #if ENABLE(CSS_GRID_LAYOUT)
492         if (rareNonInheritedData->m_grid.get() != other.rareNonInheritedData->m_grid.get()
493             || rareNonInheritedData->m_gridItem.get() != other.rareNonInheritedData->m_gridItem.get())
494             return true;
495 #endif
496
497 #if ENABLE(DASHBOARD_SUPPORT)
498         // If regions change, trigger a relayout to re-calc regions.
499         if (rareNonInheritedData->m_dashboardRegions != other.rareNonInheritedData->m_dashboardRegions)
500             return true;
501 #endif
502     }
503
504     if (rareInheritedData.get() != other.rareInheritedData.get()) {
505         if (rareInheritedData->indent != other.rareInheritedData->indent
506 #if ENABLE(CSS3_TEXT)
507             || rareInheritedData->m_textAlignLast != other.rareInheritedData->m_textAlignLast
508             || rareInheritedData->m_textJustify != other.rareInheritedData->m_textJustify
509             || rareInheritedData->m_textIndentLine != other.rareInheritedData->m_textIndentLine
510 #endif
511             || rareInheritedData->m_effectiveZoom != other.rareInheritedData->m_effectiveZoom
512 #if ENABLE(IOS_TEXT_AUTOSIZING)
513             || rareInheritedData->textSizeAdjust != other.rareInheritedData->textSizeAdjust
514 #endif
515             || rareInheritedData->wordBreak != other.rareInheritedData->wordBreak
516             || rareInheritedData->overflowWrap != other.rareInheritedData->overflowWrap
517             || rareInheritedData->nbspMode != other.rareInheritedData->nbspMode
518             || rareInheritedData->lineBreak != other.rareInheritedData->lineBreak
519             || rareInheritedData->textSecurity != other.rareInheritedData->textSecurity
520             || rareInheritedData->hyphens != other.rareInheritedData->hyphens
521             || rareInheritedData->hyphenationLimitBefore != other.rareInheritedData->hyphenationLimitBefore
522             || rareInheritedData->hyphenationLimitAfter != other.rareInheritedData->hyphenationLimitAfter
523             || rareInheritedData->hyphenationString != other.rareInheritedData->hyphenationString
524             || rareInheritedData->locale != other.rareInheritedData->locale
525             || rareInheritedData->m_rubyPosition != other.rareInheritedData->m_rubyPosition
526             || rareInheritedData->textEmphasisMark != other.rareInheritedData->textEmphasisMark
527             || rareInheritedData->textEmphasisPosition != other.rareInheritedData->textEmphasisPosition
528             || rareInheritedData->textEmphasisCustomMark != other.rareInheritedData->textEmphasisCustomMark
529             || rareInheritedData->m_textOrientation != other.rareInheritedData->m_textOrientation
530             || rareInheritedData->m_tabSize != other.rareInheritedData->m_tabSize
531             || rareInheritedData->m_lineBoxContain != other.rareInheritedData->m_lineBoxContain
532             || rareInheritedData->m_lineGrid != other.rareInheritedData->m_lineGrid
533 #if ENABLE(CSS_IMAGE_ORIENTATION)
534             || rareInheritedData->m_imageOrientation != other.rareInheritedData->m_imageOrientation
535 #endif
536 #if ENABLE(CSS_IMAGE_RESOLUTION)
537             || rareInheritedData->m_imageResolutionSource != other.rareInheritedData->m_imageResolutionSource
538             || rareInheritedData->m_imageResolutionSnap != other.rareInheritedData->m_imageResolutionSnap
539             || rareInheritedData->m_imageResolution != other.rareInheritedData->m_imageResolution
540 #endif
541             || rareInheritedData->m_lineSnap != other.rareInheritedData->m_lineSnap
542             || rareInheritedData->m_lineAlign != other.rareInheritedData->m_lineAlign
543 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
544             || rareInheritedData->useTouchOverflowScrolling != other.rareInheritedData->useTouchOverflowScrolling
545 #endif
546             || rareInheritedData->listStyleImage != other.rareInheritedData->listStyleImage)
547             return true;
548
549         if (textStrokeWidth() != other.textStrokeWidth())
550             return true;
551     }
552
553 #if ENABLE(TEXT_AUTOSIZING)
554     if (visual->m_textAutosizingMultiplier != other.visual->m_textAutosizingMultiplier)
555         return true;
556 #endif
557
558     if (inherited->line_height != other.inherited->line_height
559 #if ENABLE(IOS_TEXT_AUTOSIZING)
560         || inherited->specifiedLineHeight != other.inherited->specifiedLineHeight
561 #endif
562         || inherited->fontCascade != other.inherited->fontCascade
563         || inherited->horizontal_border_spacing != other.inherited->horizontal_border_spacing
564         || inherited->vertical_border_spacing != other.inherited->vertical_border_spacing
565         || inherited_flags._box_direction != other.inherited_flags._box_direction
566         || inherited_flags.m_rtlOrdering != other.inherited_flags.m_rtlOrdering
567         || noninherited_flags.position() != other.noninherited_flags.position()
568         || noninherited_flags.floating() != other.noninherited_flags.floating()
569         || noninherited_flags.originalDisplay() != other.noninherited_flags.originalDisplay())
570         return true;
571
572
573     if ((noninherited_flags.effectiveDisplay()) >= TABLE) {
574         if (inherited_flags._border_collapse != other.inherited_flags._border_collapse
575             || inherited_flags._empty_cells != other.inherited_flags._empty_cells
576             || inherited_flags._caption_side != other.inherited_flags._caption_side
577             || noninherited_flags.tableLayout() != other.noninherited_flags.tableLayout())
578             return true;
579
580         // In the collapsing border model, 'hidden' suppresses other borders, while 'none'
581         // does not, so these style differences can be width differences.
582         if (inherited_flags._border_collapse
583             && ((borderTopStyle() == BHIDDEN && other.borderTopStyle() == BNONE)
584                 || (borderTopStyle() == BNONE && other.borderTopStyle() == BHIDDEN)
585                 || (borderBottomStyle() == BHIDDEN && other.borderBottomStyle() == BNONE)
586                 || (borderBottomStyle() == BNONE && other.borderBottomStyle() == BHIDDEN)
587                 || (borderLeftStyle() == BHIDDEN && other.borderLeftStyle() == BNONE)
588                 || (borderLeftStyle() == BNONE && other.borderLeftStyle() == BHIDDEN)
589                 || (borderRightStyle() == BHIDDEN && other.borderRightStyle() == BNONE)
590                 || (borderRightStyle() == BNONE && other.borderRightStyle() == BHIDDEN)))
591             return true;
592     }
593
594     if (noninherited_flags.effectiveDisplay() == LIST_ITEM) {
595         if (inherited_flags._list_style_type != other.inherited_flags._list_style_type
596             || inherited_flags._list_style_position != other.inherited_flags._list_style_position)
597             return true;
598     }
599
600     if (inherited_flags._text_align != other.inherited_flags._text_align
601         || inherited_flags._text_transform != other.inherited_flags._text_transform
602         || inherited_flags._direction != other.inherited_flags._direction
603         || inherited_flags._white_space != other.inherited_flags._white_space
604         || noninherited_flags.clear() != other.noninherited_flags.clear()
605         || noninherited_flags.unicodeBidi() != other.noninherited_flags.unicodeBidi())
606         return true;
607
608     // Check block flow direction.
609     if (inherited_flags.m_writingMode != other.inherited_flags.m_writingMode)
610         return true;
611
612     // Check text combine mode.
613     if (rareNonInheritedData->m_textCombine != other.rareNonInheritedData->m_textCombine)
614         return true;
615
616     // Overflow returns a layout hint.
617     if (noninherited_flags.overflowX() != other.noninherited_flags.overflowX()
618         || noninherited_flags.overflowY() != other.noninherited_flags.overflowY())
619         return true;
620
621     // If our border widths change, then we need to layout.  Other changes to borders
622     // only necessitate a repaint.
623     if (borderLeftWidth() != other.borderLeftWidth()
624         || borderTopWidth() != other.borderTopWidth()
625         || borderBottomWidth() != other.borderBottomWidth()
626         || borderRightWidth() != other.borderRightWidth())
627         return true;
628
629     // If the counter directives change, trigger a relayout to re-calculate counter values and rebuild the counter node tree.
630     const CounterDirectiveMap* mapA = rareNonInheritedData->m_counterDirectives.get();
631     const CounterDirectiveMap* mapB = other.rareNonInheritedData->m_counterDirectives.get();
632     if (!(mapA == mapB || (mapA && mapB && *mapA == *mapB)))
633         return true;
634
635     if ((visibility() == COLLAPSE) != (other.visibility() == COLLAPSE))
636         return true;
637
638     if (rareNonInheritedData->hasOpacity() != other.rareNonInheritedData->hasOpacity()) {
639         // FIXME: We would like to use SimplifiedLayout here, but we can't quite do that yet.
640         // We need to make sure SimplifiedLayout can operate correctly on RenderInlines (we will need
641         // to add a selfNeedsSimplifiedLayout bit in order to not get confused and taint every line).
642         // In addition we need to solve the floating object issue when layers come and go. Right now
643         // a full layout is necessary to keep floating object lists sane.
644         return true;
645     }
646
647     if (rareNonInheritedData->hasFilters() != other.rareNonInheritedData->hasFilters())
648         return true;
649
650 #if ENABLE(FILTERS_LEVEL_2)
651     if (rareNonInheritedData->hasBackdropFilters() != other.rareNonInheritedData->hasBackdropFilters())
652         return true;
653 #endif
654
655     const QuotesData* quotesDataA = rareInheritedData->quotes.get();
656     const QuotesData* quotesDataB = other.rareInheritedData->quotes.get();
657     if (!(quotesDataA == quotesDataB || (quotesDataA && quotesDataB && *quotesDataA == *quotesDataB)))
658         return true;
659
660     if (position() != StaticPosition) {
661         if (surround->offset != other.surround->offset) {
662             // FIXME: We would like to use SimplifiedLayout for relative positioning, but we can't quite do that yet.
663             // We need to make sure SimplifiedLayout can operate correctly on RenderInlines (we will need
664             // to add a selfNeedsSimplifiedLayout bit in order to not get confused and taint every line).
665             if (position() != AbsolutePosition)
666                 return true;
667
668             // Optimize for the case where a positioned layer is moving but not changing size.
669             if (!positionChangeIsMovementOnly(surround->offset, other.surround->offset, m_box->width()))
670                 return true;
671         }
672     }
673     
674     return false;
675 }
676
677 bool RenderStyle::changeRequiresPositionedLayoutOnly(const RenderStyle& other, unsigned&) const
678 {
679     if (position() == StaticPosition)
680         return false;
681
682     if (surround->offset != other.surround->offset) {
683         // Optimize for the case where a positioned layer is moving but not changing size.
684         if (position() == AbsolutePosition && positionChangeIsMovementOnly(surround->offset, other.surround->offset, m_box->width()))
685             return true;
686     }
687     
688     return false;
689 }
690
691 bool RenderStyle::changeRequiresLayerRepaint(const RenderStyle& other, unsigned& changedContextSensitiveProperties) const
692 {
693     // StyleResolver has ensured that zIndex is non-auto only if it's applicable.
694     if (m_box->zIndex() != other.m_box->zIndex() || m_box->hasAutoZIndex() != other.m_box->hasAutoZIndex())
695         return true;
696
697     if (position() != StaticPosition) {
698         if (visual->clip != other.visual->clip || visual->hasClip != other.visual->hasClip) {
699             changedContextSensitiveProperties |= ContextSensitivePropertyClipRect;
700             return true;
701         }
702     }
703
704 #if ENABLE(CSS_COMPOSITING)
705     if (rareNonInheritedData->m_effectiveBlendMode != other.rareNonInheritedData->m_effectiveBlendMode)
706         return true;
707 #endif
708
709     if (rareNonInheritedData->opacity != other.rareNonInheritedData->opacity) {
710         changedContextSensitiveProperties |= ContextSensitivePropertyOpacity;
711         // Don't return; keep looking for another change.
712     }
713
714     if (rareNonInheritedData->m_filter.get() != other.rareNonInheritedData->m_filter.get()
715         && *rareNonInheritedData->m_filter.get() != *other.rareNonInheritedData->m_filter.get()) {
716         changedContextSensitiveProperties |= ContextSensitivePropertyFilter;
717         // Don't return; keep looking for another change.
718     }
719
720     if (rareNonInheritedData->m_mask != other.rareNonInheritedData->m_mask
721         || rareNonInheritedData->m_maskBoxImage != other.rareNonInheritedData->m_maskBoxImage)
722         return true;
723
724     return false;
725 }
726
727 bool RenderStyle::changeRequiresRepaint(const RenderStyle& other, unsigned& changedContextSensitiveProperties) const
728 {
729     if (inherited_flags._visibility != other.inherited_flags._visibility
730         || inherited_flags.m_printColorAdjust != other.inherited_flags.m_printColorAdjust
731         || inherited_flags._insideLink != other.inherited_flags._insideLink
732         || inherited_flags._insideDefaultButton != other.inherited_flags._insideDefaultButton
733         || surround->border != other.surround->border
734         || !m_background->isEquivalentForPainting(*other.m_background)
735         || rareInheritedData->userModify != other.rareInheritedData->userModify
736         || rareInheritedData->userSelect != other.rareInheritedData->userSelect
737         || rareNonInheritedData->userDrag != other.rareNonInheritedData->userDrag
738         || rareNonInheritedData->m_borderFit != other.rareNonInheritedData->m_borderFit
739         || rareNonInheritedData->m_objectFit != other.rareNonInheritedData->m_objectFit
740         || rareInheritedData->m_imageRendering != other.rareInheritedData->m_imageRendering)
741         return true;
742
743 #if ENABLE(CSS_SHAPES)
744     if (rareNonInheritedData->m_shapeOutside != other.rareNonInheritedData->m_shapeOutside)
745         return true;
746 #endif
747
748     // FIXME: this should probably be moved to changeRequiresLayerRepaint().
749     if (rareNonInheritedData->m_clipPath != other.rareNonInheritedData->m_clipPath) {
750         changedContextSensitiveProperties |= ContextSensitivePropertyClipPath;
751         // Don't return; keep looking for another change.
752     }
753
754     return false;
755 }
756
757 bool RenderStyle::changeRequiresRepaintIfTextOrBorderOrOutline(const RenderStyle& other, unsigned&) const
758 {
759     if (inherited->color != other.inherited->color
760         || inherited_flags._text_decorations != other.inherited_flags._text_decorations
761         || visual->textDecoration != other.visual->textDecoration
762         || rareNonInheritedData->m_textDecorationStyle != other.rareNonInheritedData->m_textDecorationStyle
763         || rareNonInheritedData->m_textDecorationColor != other.rareNonInheritedData->m_textDecorationColor
764         || rareInheritedData->m_textDecorationSkip != other.rareInheritedData->m_textDecorationSkip
765         || rareInheritedData->textFillColor != other.rareInheritedData->textFillColor
766         || rareInheritedData->textStrokeColor != other.rareInheritedData->textStrokeColor
767         || rareInheritedData->textEmphasisColor != other.rareInheritedData->textEmphasisColor
768         || rareInheritedData->textEmphasisFill != other.rareInheritedData->textEmphasisFill)
769         return true;
770
771     return false;
772 }
773
774 bool RenderStyle::changeRequiresRecompositeLayer(const RenderStyle& other, unsigned&) const
775 {
776     if (rareNonInheritedData.get() != other.rareNonInheritedData.get()) {
777         if (rareNonInheritedData->m_transformStyle3D != other.rareNonInheritedData->m_transformStyle3D
778             || rareNonInheritedData->m_backfaceVisibility != other.rareNonInheritedData->m_backfaceVisibility
779             || rareNonInheritedData->m_perspective != other.rareNonInheritedData->m_perspective
780             || rareNonInheritedData->m_perspectiveOriginX != other.rareNonInheritedData->m_perspectiveOriginX
781             || rareNonInheritedData->m_perspectiveOriginY != other.rareNonInheritedData->m_perspectiveOriginY)
782             return true;
783     }
784
785     return false;
786 }
787
788 StyleDifference RenderStyle::diff(const RenderStyle& other, unsigned& changedContextSensitiveProperties) const
789 {
790     changedContextSensitiveProperties = ContextSensitivePropertyNone;
791
792     StyleDifference svgChange = StyleDifferenceEqual;
793     if (m_svgStyle != other.m_svgStyle) {
794         svgChange = m_svgStyle->diff(other.m_svgStyle.get());
795         if (svgChange == StyleDifferenceLayout)
796             return svgChange;
797     }
798
799     if (changeRequiresLayout(other, changedContextSensitiveProperties))
800         return StyleDifferenceLayout;
801
802     // SVGRenderStyle::diff() might have returned StyleDifferenceRepaint, eg. if fill changes.
803     // If eg. the font-size changed at the same time, we're not allowed to return StyleDifferenceRepaint,
804     // but have to return StyleDifferenceLayout, that's why  this if branch comes after all branches
805     // that are relevant for SVG and might return StyleDifferenceLayout.
806     if (svgChange != StyleDifferenceEqual)
807         return svgChange;
808
809     if (changeRequiresPositionedLayoutOnly(other, changedContextSensitiveProperties))
810         return StyleDifferenceLayoutPositionedMovementOnly;
811
812     if (changeRequiresLayerRepaint(other, changedContextSensitiveProperties))
813         return StyleDifferenceRepaintLayer;
814
815     if (changeRequiresRepaint(other, changedContextSensitiveProperties))
816         return StyleDifferenceRepaint;
817
818     if (changeRequiresRecompositeLayer(other, changedContextSensitiveProperties))
819         return StyleDifferenceRecompositeLayer;
820
821     if (changeRequiresRepaintIfTextOrBorderOrOutline(other, changedContextSensitiveProperties))
822         return StyleDifferenceRepaintIfTextOrBorderOrOutline;
823
824     // Cursors are not checked, since they will be set appropriately in response to mouse events,
825     // so they don't need to cause any repaint or layout.
826
827     // 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
828     // the resulting transition properly.
829     return StyleDifferenceEqual;
830 }
831
832 bool RenderStyle::diffRequiresLayerRepaint(const RenderStyle& style, bool isComposited) const
833 {
834     unsigned changedContextSensitiveProperties = 0;
835
836     if (changeRequiresRepaint(style, changedContextSensitiveProperties))
837         return true;
838
839     if (isComposited && changeRequiresLayerRepaint(style, changedContextSensitiveProperties))
840         return changedContextSensitiveProperties & ContextSensitivePropertyClipRect;
841
842     return false;
843 }
844     
845 void RenderStyle::setMaskImage(const Vector<RefPtr<MaskImageOperation>>& ops)
846 {
847     FillLayer* curLayer = &rareNonInheritedData.access()->m_mask;
848     while (curLayer) {
849         curLayer->setMaskImage(nullptr);
850         curLayer = curLayer->next();
851     }
852
853     curLayer = &rareNonInheritedData.access()->m_mask;
854     FillLayer* prevLayer = nullptr;
855     for (auto& maskImage : ops) {
856         if (!curLayer) {
857             prevLayer->setNext(std::make_unique<FillLayer>(MaskFillLayer));
858             curLayer = prevLayer->next();
859         }
860
861         curLayer->setMaskImage(maskImage);
862         prevLayer = curLayer;
863         curLayer = curLayer->next();
864     }
865 }
866
867 void RenderStyle::setClip(Length top, Length right, Length bottom, Length left)
868 {
869     StyleVisualData* data = visual.access();
870     data->clip.m_top = top;
871     data->clip.m_right = right;
872     data->clip.m_bottom = bottom;
873     data->clip.m_left = left;
874 }
875
876 void RenderStyle::addCursor(PassRefPtr<StyleImage> image, const IntPoint& hotSpot)
877 {
878     if (!rareInheritedData.access()->cursorData)
879         rareInheritedData.access()->cursorData = CursorList::create();
880     rareInheritedData.access()->cursorData->append(CursorData(image, hotSpot));
881 }
882
883 void RenderStyle::setCursorList(PassRefPtr<CursorList> other)
884 {
885     rareInheritedData.access()->cursorData = other;
886 }
887
888 void RenderStyle::setQuotes(PassRefPtr<QuotesData> q)
889 {
890     if (rareInheritedData->quotes == q || (rareInheritedData->quotes && q && *rareInheritedData->quotes == *q))
891         return;
892
893     rareInheritedData.access()->quotes = q;
894 }
895
896 void RenderStyle::clearCursorList()
897 {
898     if (rareInheritedData->cursorData)
899         rareInheritedData.access()->cursorData = 0;
900 }
901
902 void RenderStyle::clearContent()
903 {
904     if (rareNonInheritedData->m_content)
905         rareNonInheritedData.access()->m_content = nullptr;
906 }
907
908 void RenderStyle::appendContent(std::unique_ptr<ContentData> contentData)
909 {
910     auto& content = rareNonInheritedData.access()->m_content;
911     ContentData* lastContent = content.get();
912     while (lastContent && lastContent->next())
913         lastContent = lastContent->next();
914
915     if (lastContent)
916         lastContent->setNext(WTF::move(contentData));
917     else
918         content = WTF::move(contentData);
919 }
920
921 void RenderStyle::setContent(PassRefPtr<StyleImage> image, bool add)
922 {
923     if (!image)
924         return;
925         
926     if (add) {
927         appendContent(std::make_unique<ImageContentData>(image));
928         return;
929     }
930
931     rareNonInheritedData.access()->m_content = std::make_unique<ImageContentData>(image);
932     if (!rareNonInheritedData.access()->m_altText.isNull())
933         rareNonInheritedData.access()->m_content->setAltText(rareNonInheritedData.access()->m_altText);
934 }
935
936 void RenderStyle::setContent(const String& string, bool add)
937 {
938     auto& content = rareNonInheritedData.access()->m_content;
939     if (add) {
940         ContentData* lastContent = content.get();
941         while (lastContent && lastContent->next())
942             lastContent = lastContent->next();
943
944         if (lastContent) {
945             // We attempt to merge with the last ContentData if possible.
946             if (is<TextContentData>(*lastContent)) {
947                 TextContentData& textContent = downcast<TextContentData>(*lastContent);
948                 textContent.setText(textContent.text() + string);
949             } else
950                 lastContent->setNext(std::make_unique<TextContentData>(string));
951
952             if (!rareNonInheritedData.access()->m_altText.isNull())
953                 lastContent->setAltText(rareNonInheritedData.access()->m_altText);
954             return;
955         }
956     }
957
958     content = std::make_unique<TextContentData>(string);
959     if (!rareNonInheritedData.access()->m_altText.isNull())
960         content->setAltText(rareNonInheritedData.access()->m_altText);
961 }
962
963 void RenderStyle::setContent(std::unique_ptr<CounterContent> counter, bool add)
964 {
965     if (!counter)
966         return;
967
968     if (add) {
969         appendContent(std::make_unique<CounterContentData>(WTF::move(counter)));
970         return;
971     }
972
973     rareNonInheritedData.access()->m_content = std::make_unique<CounterContentData>(WTF::move(counter));
974 }
975
976 void RenderStyle::setContent(QuoteType quote, bool add)
977 {
978     if (add) {
979         appendContent(std::make_unique<QuoteContentData>(quote));
980         return;
981     }
982
983     rareNonInheritedData.access()->m_content = std::make_unique<QuoteContentData>(quote);
984 }
985
986 void RenderStyle::setContentAltText(const String& string)
987 {
988     rareNonInheritedData.access()->m_altText = string;
989     
990     if (rareNonInheritedData.access()->m_content)
991         rareNonInheritedData.access()->m_content->setAltText(string);
992 }
993
994 const String& RenderStyle::contentAltText() const
995 {
996     return rareNonInheritedData->m_altText;
997 }
998
999 // FIXME: use affectedByTransformOrigin().
1000 static inline bool requireTransformOrigin(const Vector<RefPtr<TransformOperation>>& transformOperations, RenderStyle::ApplyTransformOrigin applyOrigin)
1001 {
1002     // transform-origin brackets the transform with translate operations.
1003     // Optimize for the case where the only transform is a translation, since the transform-origin is irrelevant
1004     // in that case.
1005     if (applyOrigin != RenderStyle::IncludeTransformOrigin)
1006         return false;
1007
1008     for (auto& operation : transformOperations) {
1009         TransformOperation::OperationType type = operation->type();
1010         if (type != TransformOperation::TRANSLATE_X
1011             && type != TransformOperation::TRANSLATE_Y
1012             && type != TransformOperation::TRANSLATE 
1013             && type != TransformOperation::TRANSLATE_Z // FIXME: doesn't this depend on transform origin?
1014             && type != TransformOperation::TRANSLATE_3D)
1015             return true;
1016     }
1017
1018     return false;
1019 }
1020
1021 void RenderStyle::applyTransform(TransformationMatrix& transform, const FloatRect& boundingBox, ApplyTransformOrigin applyOrigin) const
1022 {
1023     auto& operations = rareNonInheritedData->m_transform->m_operations.operations();
1024     bool applyTransformOrigin = requireTransformOrigin(operations, applyOrigin);
1025
1026     float offsetX = transformOriginX().isPercentNotCalculated() ? boundingBox.x() : 0;
1027     float offsetY = transformOriginY().isPercentNotCalculated() ? boundingBox.y() : 0;
1028
1029     if (applyTransformOrigin) {
1030         transform.translate3d(floatValueForLength(transformOriginX(), boundingBox.width()) + offsetX,
1031                               floatValueForLength(transformOriginY(), boundingBox.height()) + offsetY,
1032                               transformOriginZ());
1033     }
1034
1035     for (auto& operation : operations)
1036         operation->apply(transform, boundingBox.size());
1037
1038     if (applyTransformOrigin) {
1039         transform.translate3d(-floatValueForLength(transformOriginX(), boundingBox.width()) - offsetX,
1040                               -floatValueForLength(transformOriginY(), boundingBox.height()) - offsetY,
1041                               -transformOriginZ());
1042     }
1043 }
1044
1045 void RenderStyle::setPageScaleTransform(float scale)
1046 {
1047     if (scale == 1)
1048         return;
1049     TransformOperations transform;
1050     transform.operations().append(ScaleTransformOperation::create(scale, scale, ScaleTransformOperation::SCALE));
1051     setTransform(transform);
1052     setTransformOriginX(Length(0, Fixed));
1053     setTransformOriginY(Length(0, Fixed));
1054 }
1055
1056 void RenderStyle::setTextShadow(std::unique_ptr<ShadowData> shadowData, bool add)
1057 {
1058     ASSERT(!shadowData || (!shadowData->spread() && shadowData->style() == Normal));
1059
1060     StyleRareInheritedData* rareData = rareInheritedData.access();
1061     if (!add) {
1062         rareData->textShadow = WTF::move(shadowData);
1063         return;
1064     }
1065
1066     shadowData->setNext(WTF::move(rareData->textShadow));
1067     rareData->textShadow = WTF::move(shadowData);
1068 }
1069
1070 void RenderStyle::setBoxShadow(std::unique_ptr<ShadowData> shadowData, bool add)
1071 {
1072     StyleRareNonInheritedData* rareData = rareNonInheritedData.access();
1073     if (!add) {
1074         rareData->m_boxShadow = WTF::move(shadowData);
1075         return;
1076     }
1077
1078     shadowData->setNext(WTF::move(rareData->m_boxShadow));
1079     rareData->m_boxShadow = WTF::move(shadowData);
1080 }
1081
1082 static RoundedRect::Radii calcRadiiFor(const BorderData& border, const LayoutSize& size)
1083 {
1084     return RoundedRect::Radii(
1085         LayoutSize(valueForLength(border.topLeft().width(), size.width()),
1086             valueForLength(border.topLeft().height(), size.height())),
1087         LayoutSize(valueForLength(border.topRight().width(), size.width()),
1088             valueForLength(border.topRight().height(), size.height())),
1089         LayoutSize(valueForLength(border.bottomLeft().width(), size.width()),
1090             valueForLength(border.bottomLeft().height(), size.height())),
1091         LayoutSize(valueForLength(border.bottomRight().width(), size.width()),
1092             valueForLength(border.bottomRight().height(), size.height())));
1093 }
1094
1095 StyleImage* RenderStyle::listStyleImage() const { return rareInheritedData->listStyleImage.get(); }
1096 void RenderStyle::setListStyleImage(PassRefPtr<StyleImage> v)
1097 {
1098     if (rareInheritedData->listStyleImage != v)
1099         rareInheritedData.access()->listStyleImage = v;
1100 }
1101
1102 Color RenderStyle::color() const { return inherited->color; }
1103 Color RenderStyle::visitedLinkColor() const { return inherited->visitedLinkColor; }
1104 void RenderStyle::setColor(const Color& v) { SET_VAR(inherited, color, v); }
1105 void RenderStyle::setVisitedLinkColor(const Color& v) { SET_VAR(inherited, visitedLinkColor, v); }
1106
1107 short RenderStyle::horizontalBorderSpacing() const { return inherited->horizontal_border_spacing; }
1108 short RenderStyle::verticalBorderSpacing() const { return inherited->vertical_border_spacing; }
1109 void RenderStyle::setHorizontalBorderSpacing(short v) { SET_VAR(inherited, horizontal_border_spacing, v); }
1110 void RenderStyle::setVerticalBorderSpacing(short v) { SET_VAR(inherited, vertical_border_spacing, v); }
1111
1112 RoundedRect RenderStyle::getRoundedBorderFor(const LayoutRect& borderRect, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
1113 {
1114     RoundedRect roundedRect(borderRect);
1115     if (hasBorderRadius()) {
1116         RoundedRect::Radii radii = calcRadiiFor(surround->border, borderRect.size());
1117         radii.scale(calcBorderRadiiConstraintScaleFor(borderRect, radii));
1118         roundedRect.includeLogicalEdges(radii, isHorizontalWritingMode(), includeLogicalLeftEdge, includeLogicalRightEdge);
1119     }
1120     return roundedRect;
1121 }
1122
1123 RoundedRect RenderStyle::getRoundedInnerBorderFor(const LayoutRect& borderRect, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
1124 {
1125     bool horizontal = isHorizontalWritingMode();
1126
1127     LayoutUnit leftWidth = (!horizontal || includeLogicalLeftEdge) ? borderLeftWidth() : 0;
1128     LayoutUnit rightWidth = (!horizontal || includeLogicalRightEdge) ? borderRightWidth() : 0;
1129     LayoutUnit topWidth = (horizontal || includeLogicalLeftEdge) ? borderTopWidth() : 0;
1130     LayoutUnit bottomWidth = (horizontal || includeLogicalRightEdge) ? borderBottomWidth() : 0;
1131
1132     return getRoundedInnerBorderFor(borderRect, topWidth, bottomWidth, leftWidth, rightWidth, includeLogicalLeftEdge, includeLogicalRightEdge);
1133 }
1134
1135 RoundedRect RenderStyle::getRoundedInnerBorderFor(const LayoutRect& borderRect, LayoutUnit topWidth, LayoutUnit bottomWidth,
1136     LayoutUnit leftWidth, LayoutUnit rightWidth, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
1137 {
1138     LayoutRect innerRect(borderRect.x() + leftWidth, 
1139                borderRect.y() + topWidth, 
1140                borderRect.width() - leftWidth - rightWidth, 
1141                borderRect.height() - topWidth - bottomWidth);
1142
1143     RoundedRect roundedRect(innerRect);
1144
1145     if (hasBorderRadius()) {
1146         RoundedRect::Radii radii = getRoundedBorderFor(borderRect).radii();
1147         radii.shrink(topWidth, bottomWidth, leftWidth, rightWidth);
1148         roundedRect.includeLogicalEdges(radii, isHorizontalWritingMode(), includeLogicalLeftEdge, includeLogicalRightEdge);
1149     }
1150     return roundedRect;
1151 }
1152
1153 static bool allLayersAreFixed(const FillLayer* layer)
1154 {
1155     bool allFixed = true;
1156     
1157     for (const FillLayer* currLayer = layer; currLayer; currLayer = currLayer->next())
1158         allFixed &= (currLayer->image() && currLayer->attachment() == FixedBackgroundAttachment);
1159
1160     return layer && allFixed;
1161 }
1162
1163 bool RenderStyle::hasEntirelyFixedBackground() const
1164 {
1165     return allLayersAreFixed(backgroundLayers());
1166 }
1167
1168 const CounterDirectiveMap* RenderStyle::counterDirectives() const
1169 {
1170     return rareNonInheritedData->m_counterDirectives.get();
1171 }
1172
1173 CounterDirectiveMap& RenderStyle::accessCounterDirectives()
1174 {
1175     auto& map = rareNonInheritedData.access()->m_counterDirectives;
1176     if (!map)
1177         map = std::make_unique<CounterDirectiveMap>();
1178     return *map;
1179 }
1180
1181 const CounterDirectives RenderStyle::getCounterDirectives(const AtomicString& identifier) const
1182 {
1183     if (const CounterDirectiveMap* directives = counterDirectives())
1184         return directives->get(identifier);
1185     return CounterDirectives();
1186 }
1187
1188 const AtomicString& RenderStyle::hyphenString() const
1189 {
1190     ASSERT(hyphens() != HyphensNone);
1191
1192     const AtomicString& hyphenationString = rareInheritedData.get()->hyphenationString;
1193     if (!hyphenationString.isNull())
1194         return hyphenationString;
1195
1196     // FIXME: This should depend on locale.
1197     DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, hyphenMinusString, (&hyphenMinus, 1));
1198     DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, hyphenString, (&hyphen, 1));
1199     return fontCascade().primaryFont().glyphForCharacter(hyphen) ? hyphenString : hyphenMinusString;
1200 }
1201
1202 const AtomicString& RenderStyle::textEmphasisMarkString() const
1203 {
1204     switch (textEmphasisMark()) {
1205     case TextEmphasisMarkNone:
1206         return nullAtom;
1207     case TextEmphasisMarkCustom:
1208         return textEmphasisCustomMark();
1209     case TextEmphasisMarkDot: {
1210         DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, filledDotString, (&bullet, 1));
1211         DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, openDotString, (&whiteBullet, 1));
1212         return textEmphasisFill() == TextEmphasisFillFilled ? filledDotString : openDotString;
1213     }
1214     case TextEmphasisMarkCircle: {
1215         DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, filledCircleString, (&blackCircle, 1));
1216         DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, openCircleString, (&whiteCircle, 1));
1217         return textEmphasisFill() == TextEmphasisFillFilled ? filledCircleString : openCircleString;
1218     }
1219     case TextEmphasisMarkDoubleCircle: {
1220         DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, filledDoubleCircleString, (&fisheye, 1));
1221         DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, openDoubleCircleString, (&bullseye, 1));
1222         return textEmphasisFill() == TextEmphasisFillFilled ? filledDoubleCircleString : openDoubleCircleString;
1223     }
1224     case TextEmphasisMarkTriangle: {
1225         DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, filledTriangleString, (&blackUpPointingTriangle, 1));
1226         DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, openTriangleString, (&whiteUpPointingTriangle, 1));
1227         return textEmphasisFill() == TextEmphasisFillFilled ? filledTriangleString : openTriangleString;
1228     }
1229     case TextEmphasisMarkSesame: {
1230         DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, filledSesameString, (&sesameDot, 1));
1231         DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, openSesameString, (&whiteSesameDot, 1));
1232         return textEmphasisFill() == TextEmphasisFillFilled ? filledSesameString : openSesameString;
1233     }
1234     case TextEmphasisMarkAuto:
1235         ASSERT_NOT_REACHED();
1236         return nullAtom;
1237     }
1238
1239     ASSERT_NOT_REACHED();
1240     return nullAtom;
1241 }
1242
1243 #if ENABLE(DASHBOARD_SUPPORT)
1244 const Vector<StyleDashboardRegion>& RenderStyle::initialDashboardRegions()
1245 {
1246     DEPRECATED_DEFINE_STATIC_LOCAL(Vector<StyleDashboardRegion>, emptyList, ());
1247     return emptyList;
1248 }
1249
1250 const Vector<StyleDashboardRegion>& RenderStyle::noneDashboardRegions()
1251 {
1252     DEPRECATED_DEFINE_STATIC_LOCAL(Vector<StyleDashboardRegion>, noneList, ());
1253     static bool noneListInitialized = false;
1254
1255     if (!noneListInitialized) {
1256         StyleDashboardRegion region;
1257         region.label = "";
1258         region.offset.m_top  = Length();
1259         region.offset.m_right = Length();
1260         region.offset.m_bottom = Length();
1261         region.offset.m_left = Length();
1262         region.type = StyleDashboardRegion::None;
1263         noneList.append(region);
1264         noneListInitialized = true;
1265     }
1266     return noneList;
1267 }
1268 #endif
1269
1270 void RenderStyle::adjustAnimations()
1271 {
1272     AnimationList* animationList = rareNonInheritedData->m_animations.get();
1273     if (!animationList)
1274         return;
1275
1276     // Get rid of empty animations and anything beyond them
1277     for (size_t i = 0; i < animationList->size(); ++i) {
1278         if (animationList->animation(i).isEmpty()) {
1279             animationList->resize(i);
1280             break;
1281         }
1282     }
1283
1284     if (animationList->isEmpty()) {
1285         clearAnimations();
1286         return;
1287     }
1288
1289     // Repeat patterns into layers that don't have some properties set.
1290     animationList->fillUnsetProperties();
1291 }
1292
1293 void RenderStyle::adjustTransitions()
1294 {
1295     AnimationList* transitionList = rareNonInheritedData->m_transitions.get();
1296     if (!transitionList)
1297         return;
1298
1299     // Get rid of empty transitions and anything beyond them
1300     for (size_t i = 0; i < transitionList->size(); ++i) {
1301         if (transitionList->animation(i).isEmpty()) {
1302             transitionList->resize(i);
1303             break;
1304         }
1305     }
1306
1307     if (transitionList->isEmpty()) {
1308         clearTransitions();
1309         return;
1310     }
1311
1312     // Repeat patterns into layers that don't have some properties set.
1313     transitionList->fillUnsetProperties();
1314
1315     // Make sure there are no duplicate properties. This is an O(n^2) algorithm
1316     // but the lists tend to be very short, so it is probably ok
1317     for (size_t i = 0; i < transitionList->size(); ++i) {
1318         for (size_t j = i+1; j < transitionList->size(); ++j) {
1319             if (transitionList->animation(i).property() == transitionList->animation(j).property()) {
1320                 // toss i
1321                 transitionList->remove(i);
1322                 j = i;
1323             }
1324         }
1325     }
1326 }
1327
1328 AnimationList& RenderStyle::ensureAnimations()
1329 {
1330     if (!rareNonInheritedData.access()->m_animations)
1331         rareNonInheritedData.access()->m_animations = std::make_unique<AnimationList>();
1332     return *rareNonInheritedData->m_animations;
1333 }
1334
1335 AnimationList& RenderStyle::ensureTransitions()
1336 {
1337     if (!rareNonInheritedData.access()->m_transitions)
1338         rareNonInheritedData.access()->m_transitions = std::make_unique<AnimationList>();
1339     return *rareNonInheritedData->m_transitions;
1340 }
1341
1342 const Animation* RenderStyle::transitionForProperty(CSSPropertyID property) const
1343 {
1344     if (transitions()) {
1345         for (size_t i = 0; i < transitions()->size(); ++i) {
1346             const Animation& p = transitions()->animation(i);
1347             if (p.animationMode() == Animation::AnimateAll || p.property() == property) {
1348                 return &p;
1349             }
1350         }
1351     }
1352     return 0;
1353 }
1354
1355 const FontCascade& RenderStyle::fontCascade() const { return inherited->fontCascade; }
1356 const FontMetrics& RenderStyle::fontMetrics() const { return inherited->fontCascade.fontMetrics(); }
1357 const FontDescription& RenderStyle::fontDescription() const { return inherited->fontCascade.fontDescription(); }
1358 float RenderStyle::specifiedFontSize() const { return fontDescription().specifiedSize(); }
1359 float RenderStyle::computedFontSize() const { return fontDescription().computedSize(); }
1360 int RenderStyle::fontSize() const { return inherited->fontCascade.pixelSize(); }
1361
1362 const Length& RenderStyle::wordSpacing() const { return rareInheritedData->wordSpacing; }
1363 float RenderStyle::letterSpacing() const { return inherited->fontCascade.letterSpacing(); }
1364
1365 bool RenderStyle::setFontDescription(const FontDescription& v)
1366 {
1367     if (inherited->fontCascade.fontDescription() != v) {
1368         inherited.access()->fontCascade = FontCascade(v, inherited->fontCascade.letterSpacing(), inherited->fontCascade.wordSpacing());
1369         return true;
1370     }
1371     return false;
1372 }
1373
1374 #if ENABLE(IOS_TEXT_AUTOSIZING)
1375 const Length& RenderStyle::specifiedLineHeight() const { return inherited->specifiedLineHeight; }
1376 void RenderStyle::setSpecifiedLineHeight(Length v) { SET_VAR(inherited, specifiedLineHeight, v); }
1377 #else
1378 const Length& RenderStyle::specifiedLineHeight() const { return inherited->line_height; }
1379 #endif
1380
1381 Length RenderStyle::lineHeight() const
1382 {
1383     const Length& lh = inherited->line_height;
1384 #if ENABLE(TEXT_AUTOSIZING)
1385     // Unlike fontDescription().computedSize() and hence fontSize(), this is
1386     // recalculated on demand as we only store the specified line height.
1387     // FIXME: Should consider scaling the fixed part of any calc expressions
1388     // too, though this involves messily poking into CalcExpressionLength.
1389     float multiplier = textAutosizingMultiplier();
1390     if (multiplier > 1 && lh.isFixed())
1391         return Length(TextAutosizer::computeAutosizedFontSize(lh.value(), multiplier), Fixed);
1392 #endif
1393     return lh;
1394 }
1395 void RenderStyle::setLineHeight(Length specifiedLineHeight) { SET_VAR(inherited, line_height, specifiedLineHeight); }
1396
1397 int RenderStyle::computedLineHeight() const
1398 {
1399     const Length& lh = lineHeight();
1400
1401     // Negative value means the line height is not set. Use the font's built-in spacing.
1402     if (lh.isNegative())
1403         return fontMetrics().lineSpacing();
1404
1405     if (lh.isPercent())
1406         return minimumValueForLength(lh, fontSize());
1407
1408     return lh.value();
1409 }
1410
1411 void RenderStyle::setWordSpacing(Length value)
1412 {
1413     float fontWordSpacing;
1414     switch (value.type()) {
1415     case Auto:
1416         fontWordSpacing = 0;
1417         break;
1418     case Percent:
1419         fontWordSpacing = value.percent() * fontCascade().spaceWidth() / 100;
1420         break;
1421     case Fixed:
1422         fontWordSpacing = value.value();
1423         break;
1424     case Calculated:
1425         fontWordSpacing = value.nonNanCalculatedValue(maxValueForCssLength);
1426         break;
1427     default:
1428         ASSERT_NOT_REACHED();
1429         fontWordSpacing = 0;
1430         break;
1431     }
1432     inherited.access()->fontCascade.setWordSpacing(fontWordSpacing);
1433     rareInheritedData.access()->wordSpacing = WTF::move(value);
1434 }
1435
1436 void RenderStyle::setLetterSpacing(float v) { inherited.access()->fontCascade.setLetterSpacing(v); }
1437
1438 void RenderStyle::setFontSize(float size)
1439 {
1440     // size must be specifiedSize if Text Autosizing is enabled, but computedSize if text
1441     // zoom is enabled (if neither is enabled it's irrelevant as they're probably the same).
1442
1443     ASSERT(std::isfinite(size));
1444     if (!std::isfinite(size) || size < 0)
1445         size = 0;
1446     else
1447         size = std::min(maximumAllowedFontSize, size);
1448
1449     FontSelector* currentFontSelector = fontCascade().fontSelector();
1450     FontDescription desc(fontDescription());
1451     desc.setSpecifiedSize(size);
1452     desc.setComputedSize(size);
1453
1454 #if ENABLE(TEXT_AUTOSIZING)
1455     float multiplier = textAutosizingMultiplier();
1456     if (multiplier > 1) {
1457         float autosizedFontSize = TextAutosizer::computeAutosizedFontSize(size, multiplier);
1458         desc.setComputedSize(min(maximumAllowedFontSize, autosizedFontSize));
1459     }
1460 #endif
1461
1462     setFontDescription(desc);
1463     fontCascade().update(currentFontSelector);
1464 }
1465
1466 void RenderStyle::getShadowExtent(const ShadowData* shadow, LayoutUnit &top, LayoutUnit &right, LayoutUnit &bottom, LayoutUnit &left) const
1467 {
1468     top = 0;
1469     right = 0;
1470     bottom = 0;
1471     left = 0;
1472
1473     for ( ; shadow; shadow = shadow->next()) {
1474         if (shadow->style() == Inset)
1475             continue;
1476
1477         int extentAndSpread = shadow->paintingExtent() + shadow->spread();
1478         top = std::min<LayoutUnit>(top, shadow->y() - extentAndSpread);
1479         right = std::max<LayoutUnit>(right, shadow->x() + extentAndSpread);
1480         bottom = std::max<LayoutUnit>(bottom, shadow->y() + extentAndSpread);
1481         left = std::min<LayoutUnit>(left, shadow->x() - extentAndSpread);
1482     }
1483 }
1484
1485 LayoutBoxExtent RenderStyle::getShadowInsetExtent(const ShadowData* shadow) const
1486 {
1487     LayoutUnit top = 0;
1488     LayoutUnit right = 0;
1489     LayoutUnit bottom = 0;
1490     LayoutUnit left = 0;
1491
1492     for ( ; shadow; shadow = shadow->next()) {
1493         if (shadow->style() == Normal)
1494             continue;
1495
1496         int extentAndSpread = shadow->paintingExtent() + shadow->spread();
1497         top = std::max<LayoutUnit>(top, shadow->y() + extentAndSpread);
1498         right = std::min<LayoutUnit>(right, shadow->x() - extentAndSpread);
1499         bottom = std::min<LayoutUnit>(bottom, shadow->y() - extentAndSpread);
1500         left = std::max<LayoutUnit>(left, shadow->x() + extentAndSpread);
1501     }
1502
1503     return LayoutBoxExtent(top, right, bottom, left);
1504 }
1505
1506 void RenderStyle::getShadowHorizontalExtent(const ShadowData* shadow, LayoutUnit &left, LayoutUnit &right) const
1507 {
1508     left = 0;
1509     right = 0;
1510
1511     for ( ; shadow; shadow = shadow->next()) {
1512         if (shadow->style() == Inset)
1513             continue;
1514
1515         int extentAndSpread = shadow->paintingExtent() + shadow->spread();
1516         left = std::min<LayoutUnit>(left, shadow->x() - extentAndSpread);
1517         right = std::max<LayoutUnit>(right, shadow->x() + extentAndSpread);
1518     }
1519 }
1520
1521 void RenderStyle::getShadowVerticalExtent(const ShadowData* shadow, LayoutUnit &top, LayoutUnit &bottom) const
1522 {
1523     top = 0;
1524     bottom = 0;
1525
1526     for ( ; shadow; shadow = shadow->next()) {
1527         if (shadow->style() == Inset)
1528             continue;
1529
1530         int extentAndSpread = shadow->paintingExtent() + shadow->spread();
1531         top = std::min<LayoutUnit>(top, shadow->y() - extentAndSpread);
1532         bottom = std::max<LayoutUnit>(bottom, shadow->y() + extentAndSpread);
1533     }
1534 }
1535
1536 Color RenderStyle::colorIncludingFallback(int colorProperty, bool visitedLink) const
1537 {
1538     Color result;
1539     EBorderStyle borderStyle = BNONE;
1540     switch (colorProperty) {
1541     case CSSPropertyBackgroundColor:
1542         return visitedLink ? visitedLinkBackgroundColor() : backgroundColor(); // Background color doesn't fall back.
1543     case CSSPropertyBorderLeftColor:
1544         result = visitedLink ? visitedLinkBorderLeftColor() : borderLeftColor();
1545         borderStyle = borderLeftStyle();
1546         break;
1547     case CSSPropertyBorderRightColor:
1548         result = visitedLink ? visitedLinkBorderRightColor() : borderRightColor();
1549         borderStyle = borderRightStyle();
1550         break;
1551     case CSSPropertyBorderTopColor:
1552         result = visitedLink ? visitedLinkBorderTopColor() : borderTopColor();
1553         borderStyle = borderTopStyle();
1554         break;
1555     case CSSPropertyBorderBottomColor:
1556         result = visitedLink ? visitedLinkBorderBottomColor() : borderBottomColor();
1557         borderStyle = borderBottomStyle();
1558         break;
1559     case CSSPropertyColor:
1560         result = visitedLink ? visitedLinkColor() : color();
1561         break;
1562     case CSSPropertyOutlineColor:
1563         result = visitedLink ? visitedLinkOutlineColor() : outlineColor();
1564         break;
1565     case CSSPropertyColumnRuleColor:
1566         result = visitedLink ? visitedLinkColumnRuleColor() : columnRuleColor();
1567         break;
1568     case CSSPropertyWebkitTextDecorationColor:
1569         // Text decoration color fallback is handled in RenderObject::decorationColor.
1570         return visitedLink ? visitedLinkTextDecorationColor() : textDecorationColor();
1571     case CSSPropertyWebkitTextEmphasisColor:
1572         result = visitedLink ? visitedLinkTextEmphasisColor() : textEmphasisColor();
1573         break;
1574     case CSSPropertyWebkitTextFillColor:
1575         result = visitedLink ? visitedLinkTextFillColor() : textFillColor();
1576         break;
1577     case CSSPropertyWebkitTextStrokeColor:
1578         result = visitedLink ? visitedLinkTextStrokeColor() : textStrokeColor();
1579         break;
1580     default:
1581         ASSERT_NOT_REACHED();
1582         break;
1583     }
1584
1585     if (!result.isValid()) {
1586         if (!visitedLink && (borderStyle == INSET || borderStyle == OUTSET || borderStyle == RIDGE || borderStyle == GROOVE))
1587             result.setRGB(238, 238, 238);
1588         else
1589             result = visitedLink ? visitedLinkColor() : color();
1590     }
1591     return result;
1592 }
1593
1594 Color RenderStyle::visitedDependentColor(int colorProperty) const
1595 {
1596     Color unvisitedColor = colorIncludingFallback(colorProperty, false);
1597     if (insideLink() != InsideVisitedLink)
1598         return unvisitedColor;
1599
1600     Color visitedColor = colorIncludingFallback(colorProperty, true);
1601
1602     // Text decoration color validity is preserved (checked in RenderObject::decorationColor).
1603     if (colorProperty == CSSPropertyWebkitTextDecorationColor)
1604         return visitedColor;
1605
1606     // FIXME: Technically someone could explicitly specify the color transparent, but for now we'll just
1607     // assume that if the background color is transparent that it wasn't set. Note that it's weird that
1608     // we're returning unvisited info for a visited link, but given our restriction that the alpha values
1609     // have to match, it makes more sense to return the unvisited background color if specified than it
1610     // does to return black. This behavior matches what Firefox 4 does as well.
1611     if (colorProperty == CSSPropertyBackgroundColor && visitedColor == Color::transparent)
1612         return unvisitedColor;
1613
1614     // Take the alpha from the unvisited color, but get the RGB values from the visited color.
1615     return Color(visitedColor.red(), visitedColor.green(), visitedColor.blue(), unvisitedColor.alpha());
1616 }
1617
1618 const BorderValue& RenderStyle::borderBefore() const
1619 {
1620     switch (writingMode()) {
1621     case TopToBottomWritingMode:
1622         return borderTop();
1623     case BottomToTopWritingMode:
1624         return borderBottom();
1625     case LeftToRightWritingMode:
1626         return borderLeft();
1627     case RightToLeftWritingMode:
1628         return borderRight();
1629     }
1630     ASSERT_NOT_REACHED();
1631     return borderTop();
1632 }
1633
1634 const BorderValue& RenderStyle::borderAfter() const
1635 {
1636     switch (writingMode()) {
1637     case TopToBottomWritingMode:
1638         return borderBottom();
1639     case BottomToTopWritingMode:
1640         return borderTop();
1641     case LeftToRightWritingMode:
1642         return borderRight();
1643     case RightToLeftWritingMode:
1644         return borderLeft();
1645     }
1646     ASSERT_NOT_REACHED();
1647     return borderBottom();
1648 }
1649
1650 const BorderValue& RenderStyle::borderStart() const
1651 {
1652     if (isHorizontalWritingMode())
1653         return isLeftToRightDirection() ? borderLeft() : borderRight();
1654     return isLeftToRightDirection() ? borderTop() : borderBottom();
1655 }
1656
1657 const BorderValue& RenderStyle::borderEnd() const
1658 {
1659     if (isHorizontalWritingMode())
1660         return isLeftToRightDirection() ? borderRight() : borderLeft();
1661     return isLeftToRightDirection() ? borderBottom() : borderTop();
1662 }
1663
1664 float RenderStyle::borderBeforeWidth() const
1665 {
1666     switch (writingMode()) {
1667     case TopToBottomWritingMode:
1668         return borderTopWidth();
1669     case BottomToTopWritingMode:
1670         return borderBottomWidth();
1671     case LeftToRightWritingMode:
1672         return borderLeftWidth();
1673     case RightToLeftWritingMode:
1674         return borderRightWidth();
1675     }
1676     ASSERT_NOT_REACHED();
1677     return borderTopWidth();
1678 }
1679
1680 float RenderStyle::borderAfterWidth() const
1681 {
1682     switch (writingMode()) {
1683     case TopToBottomWritingMode:
1684         return borderBottomWidth();
1685     case BottomToTopWritingMode:
1686         return borderTopWidth();
1687     case LeftToRightWritingMode:
1688         return borderRightWidth();
1689     case RightToLeftWritingMode:
1690         return borderLeftWidth();
1691     }
1692     ASSERT_NOT_REACHED();
1693     return borderBottomWidth();
1694 }
1695
1696 float RenderStyle::borderStartWidth() const
1697 {
1698     if (isHorizontalWritingMode())
1699         return isLeftToRightDirection() ? borderLeftWidth() : borderRightWidth();
1700     return isLeftToRightDirection() ? borderTopWidth() : borderBottomWidth();
1701 }
1702
1703 float RenderStyle::borderEndWidth() const
1704 {
1705     if (isHorizontalWritingMode())
1706         return isLeftToRightDirection() ? borderRightWidth() : borderLeftWidth();
1707     return isLeftToRightDirection() ? borderBottomWidth() : borderTopWidth();
1708 }
1709
1710 void RenderStyle::setMarginStart(Length margin)
1711 {
1712     if (isHorizontalWritingMode()) {
1713         if (isLeftToRightDirection())
1714             setMarginLeft(margin);
1715         else
1716             setMarginRight(margin);
1717     } else {
1718         if (isLeftToRightDirection())
1719             setMarginTop(margin);
1720         else
1721             setMarginBottom(margin);
1722     }
1723 }
1724
1725 void RenderStyle::setMarginEnd(Length margin)
1726 {
1727     if (isHorizontalWritingMode()) {
1728         if (isLeftToRightDirection())
1729             setMarginRight(margin);
1730         else
1731             setMarginLeft(margin);
1732     } else {
1733         if (isLeftToRightDirection())
1734             setMarginBottom(margin);
1735         else
1736             setMarginTop(margin);
1737     }
1738 }
1739
1740 TextEmphasisMark RenderStyle::textEmphasisMark() const
1741 {
1742     TextEmphasisMark mark = static_cast<TextEmphasisMark>(rareInheritedData->textEmphasisMark);
1743     if (mark != TextEmphasisMarkAuto)
1744         return mark;
1745
1746     if (isHorizontalWritingMode())
1747         return TextEmphasisMarkDot;
1748
1749     return TextEmphasisMarkSesame;
1750 }
1751
1752 #if ENABLE(TOUCH_EVENTS)
1753 Color RenderStyle::initialTapHighlightColor()
1754 {
1755     return RenderTheme::tapHighlightColor();
1756 }
1757 #endif
1758
1759 LayoutBoxExtent RenderStyle::imageOutsets(const NinePieceImage& image) const
1760 {
1761     return LayoutBoxExtent(NinePieceImage::computeOutset(image.outset().top(), borderTopWidth()),
1762                            NinePieceImage::computeOutset(image.outset().right(), borderRightWidth()),
1763                            NinePieceImage::computeOutset(image.outset().bottom(), borderBottomWidth()),
1764                            NinePieceImage::computeOutset(image.outset().left(), borderLeftWidth()));
1765 }
1766
1767 void RenderStyle::getFontAndGlyphOrientation(FontOrientation& fontOrientation, NonCJKGlyphOrientation& glyphOrientation)
1768 {
1769     if (isHorizontalWritingMode()) {
1770         fontOrientation = Horizontal;
1771         glyphOrientation = NonCJKGlyphOrientationVerticalRight;
1772         return;
1773     }
1774
1775     switch (textOrientation()) {
1776     case TextOrientationVerticalRight:
1777         fontOrientation = Vertical;
1778         glyphOrientation = NonCJKGlyphOrientationVerticalRight;
1779         return;
1780     case TextOrientationUpright:
1781         fontOrientation = Vertical;
1782         glyphOrientation = NonCJKGlyphOrientationUpright;
1783         return;
1784     case TextOrientationSideways:
1785         if (writingMode() == LeftToRightWritingMode) {
1786             // FIXME: This should map to sideways-left, which is not supported yet.
1787             fontOrientation = Vertical;
1788             glyphOrientation = NonCJKGlyphOrientationVerticalRight;
1789             return;
1790         }
1791         fontOrientation = Horizontal;
1792         glyphOrientation = NonCJKGlyphOrientationVerticalRight;
1793         return;
1794     case TextOrientationSidewaysRight:
1795         fontOrientation = Horizontal;
1796         glyphOrientation = NonCJKGlyphOrientationVerticalRight;
1797         return;
1798     default:
1799         ASSERT_NOT_REACHED();
1800         fontOrientation = Horizontal;
1801         glyphOrientation = NonCJKGlyphOrientationVerticalRight;
1802         return;
1803     }
1804 }
1805
1806 void RenderStyle::setBorderImageSource(PassRefPtr<StyleImage> image)
1807 {
1808     if (surround->border.m_image.image() == image.get())
1809         return;
1810     surround.access()->border.m_image.setImage(image);
1811 }
1812
1813 void RenderStyle::setBorderImageSlices(LengthBox slices)
1814 {
1815     if (surround->border.m_image.imageSlices() == slices)
1816         return;
1817     surround.access()->border.m_image.setImageSlices(slices);
1818 }
1819
1820 void RenderStyle::setBorderImageWidth(LengthBox slices)
1821 {
1822     if (surround->border.m_image.borderSlices() == slices)
1823         return;
1824     surround.access()->border.m_image.setBorderSlices(slices);
1825 }
1826
1827 void RenderStyle::setBorderImageOutset(LengthBox outset)
1828 {
1829     if (surround->border.m_image.outset() == outset)
1830         return;
1831     surround.access()->border.m_image.setOutset(outset);
1832 }
1833
1834 void RenderStyle::setColumnStylesFromPaginationMode(const Pagination::Mode& paginationMode)
1835 {
1836     if (paginationMode == Pagination::Unpaginated)
1837         return;
1838     
1839     setColumnFill(ColumnFillAuto);
1840     
1841     switch (paginationMode) {
1842     case Pagination::LeftToRightPaginated:
1843         setColumnAxis(HorizontalColumnAxis);
1844         if (isHorizontalWritingMode())
1845             setColumnProgression(isLeftToRightDirection() ? NormalColumnProgression : ReverseColumnProgression);
1846         else
1847             setColumnProgression(isFlippedBlocksWritingMode() ? ReverseColumnProgression : NormalColumnProgression);
1848         break;
1849     case Pagination::RightToLeftPaginated:
1850         setColumnAxis(HorizontalColumnAxis);
1851         if (isHorizontalWritingMode())
1852             setColumnProgression(isLeftToRightDirection() ? ReverseColumnProgression : NormalColumnProgression);
1853         else
1854             setColumnProgression(isFlippedBlocksWritingMode() ? NormalColumnProgression : ReverseColumnProgression);
1855         break;
1856     case Pagination::TopToBottomPaginated:
1857         setColumnAxis(VerticalColumnAxis);
1858         if (isHorizontalWritingMode())
1859             setColumnProgression(isFlippedBlocksWritingMode() ? ReverseColumnProgression : NormalColumnProgression);
1860         else
1861             setColumnProgression(isLeftToRightDirection() ? NormalColumnProgression : ReverseColumnProgression);
1862         break;
1863     case Pagination::BottomToTopPaginated:
1864         setColumnAxis(VerticalColumnAxis);
1865         if (isHorizontalWritingMode())
1866             setColumnProgression(isFlippedBlocksWritingMode() ? NormalColumnProgression : ReverseColumnProgression);
1867         else
1868             setColumnProgression(isLeftToRightDirection() ? ReverseColumnProgression : NormalColumnProgression);
1869         break;
1870     case Pagination::Unpaginated:
1871         ASSERT_NOT_REACHED();
1872         break;
1873     }
1874 }
1875
1876 #if ENABLE(CSS_SCROLL_SNAP)
1877 LengthSize RenderStyle::initialScrollSnapDestination()
1878 {
1879     return defaultScrollSnapDestination();
1880 }
1881
1882 Vector<LengthSize> RenderStyle::initialScrollSnapCoordinates()
1883 {
1884     return Vector<LengthSize>();
1885 }
1886
1887 const ScrollSnapPoints* RenderStyle::scrollSnapPointsX() const
1888 {
1889     return rareNonInheritedData->m_scrollSnapPoints->xPoints.get();
1890 }
1891
1892 const ScrollSnapPoints* RenderStyle::scrollSnapPointsY() const
1893 {
1894     return rareNonInheritedData->m_scrollSnapPoints->yPoints.get();
1895 }
1896
1897 const LengthSize& RenderStyle::scrollSnapDestination() const
1898 {
1899     return rareNonInheritedData->m_scrollSnapPoints->destination;
1900 }
1901
1902 const Vector<LengthSize>& RenderStyle::scrollSnapCoordinates() const
1903 {
1904     return rareNonInheritedData->m_scrollSnapPoints->coordinates;
1905 }
1906
1907 void RenderStyle::setScrollSnapPointsX(std::unique_ptr<ScrollSnapPoints> points)
1908 {
1909     if (rareNonInheritedData->m_scrollSnapPoints->xPoints.get() == points.get())
1910         return;
1911     rareNonInheritedData.access()->m_scrollSnapPoints.access()->xPoints = WTF::move(points);
1912 }
1913
1914 void RenderStyle::setScrollSnapPointsY(std::unique_ptr<ScrollSnapPoints> points)
1915 {
1916     if (rareNonInheritedData->m_scrollSnapPoints->yPoints.get() == points.get())
1917         return;
1918     rareNonInheritedData.access()->m_scrollSnapPoints.access()->yPoints = WTF::move(points);
1919 }
1920
1921 void RenderStyle::setScrollSnapDestination(LengthSize destination)
1922 {
1923     if (rareNonInheritedData->m_scrollSnapPoints->destination == destination)
1924         return;
1925     rareNonInheritedData.access()->m_scrollSnapPoints.access()->destination = WTF::move(destination);
1926 }
1927
1928 void RenderStyle::setScrollSnapCoordinates(Vector<LengthSize> coordinates)
1929 {
1930     if (rareNonInheritedData->m_scrollSnapPoints->coordinates == coordinates)
1931         return;
1932     rareNonInheritedData.access()->m_scrollSnapPoints.access()->coordinates = WTF::move(coordinates);
1933 }
1934
1935 #endif
1936
1937 } // namespace WebCore