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