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