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