Make QuotesData use a Vector of pairs
[WebKit-https.git] / Source / WebCore / rendering / style / RenderStyle.cpp
1 /*
2  * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
3  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 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 "CSSWrapShapes.h"
30 #include "FontSelector.h"
31 #include "QuotesData.h"
32 #include "RenderArena.h"
33 #include "RenderObject.h"
34 #include "ScaleTransformOperation.h"
35 #include "ShadowData.h"
36 #include "StyleImage.h"
37 #include "StyleResolver.h"
38 #if ENABLE(TOUCH_EVENTS)
39 #include "RenderTheme.h"
40 #endif
41 #include <wtf/StdLibExtras.h>
42 #include <algorithm>
43
44 using namespace std;
45
46 namespace WebCore {
47
48 struct SameSizeAsBorderValue {
49     RGBA32 m_color;
50     unsigned m_width;
51 };
52
53 COMPILE_ASSERT(sizeof(BorderValue) == sizeof(SameSizeAsBorderValue), BorderValue_should_not_grow);
54
55 struct SameSizeAsRenderStyle : public RefCounted<SameSizeAsRenderStyle> {
56     unsigned m_bitfields;
57
58     void* dataRefs[7];
59     void* ownPtrs[1];
60 #if ENABLE(SVG)
61     void* dataRefSvgStyle;
62 #endif
63     struct InheritedFlags {
64         unsigned m_bitfields[2];
65     } inherited_flags;
66
67     struct NonInheritedFlags {
68         unsigned m_bitfields[2];
69     } noninherited_flags;
70 };
71
72 COMPILE_ASSERT(sizeof(RenderStyle) == sizeof(SameSizeAsRenderStyle), RenderStyle_should_stay_small);
73
74 inline RenderStyle* defaultStyle()
75 {
76     static RenderStyle* s_defaultStyle = RenderStyle::createDefaultStyle().leakRef();
77     return s_defaultStyle;
78 }
79
80 PassRefPtr<RenderStyle> RenderStyle::create()
81 {
82     return adoptRef(new RenderStyle());
83 }
84
85 PassRefPtr<RenderStyle> RenderStyle::createDefaultStyle()
86 {
87     return adoptRef(new RenderStyle(true));
88 }
89
90 PassRefPtr<RenderStyle> RenderStyle::createAnonymousStyleWithDisplay(const RenderStyle* parentStyle, EDisplay display)
91 {
92     RefPtr<RenderStyle> newStyle = RenderStyle::create();
93     newStyle->inheritFrom(parentStyle);
94     newStyle->inheritUnicodeBidiFrom(parentStyle);
95     newStyle->setDisplay(display);
96     return newStyle;
97 }
98
99 PassRefPtr<RenderStyle> RenderStyle::clone(const RenderStyle* other)
100 {
101     return adoptRef(new RenderStyle(*other));
102 }
103
104 ALWAYS_INLINE RenderStyle::RenderStyle()
105     : m_box(defaultStyle()->m_box)
106     , visual(defaultStyle()->visual)
107     , m_background(defaultStyle()->m_background)
108     , surround(defaultStyle()->surround)
109     , rareNonInheritedData(defaultStyle()->rareNonInheritedData)
110     , rareInheritedData(defaultStyle()->rareInheritedData)
111     , inherited(defaultStyle()->inherited)
112 #if ENABLE(SVG)
113     , m_svgStyle(defaultStyle()->m_svgStyle)
114 #endif
115 {
116     setBitDefaults(); // Would it be faster to copy this from the default style?
117     COMPILE_ASSERT((sizeof(InheritedFlags) <= 8), InheritedFlags_does_not_grow);
118     COMPILE_ASSERT((sizeof(NonInheritedFlags) <= 8), NonInheritedFlags_does_not_grow);
119 }
120
121 ALWAYS_INLINE RenderStyle::RenderStyle(bool)
122 {
123     setBitDefaults();
124
125     m_box.init();
126     visual.init();
127     m_background.init();
128     surround.init();
129     rareNonInheritedData.init();
130     rareNonInheritedData.access()->m_deprecatedFlexibleBox.init();
131     rareNonInheritedData.access()->m_flexibleBox.init();
132     rareNonInheritedData.access()->m_marquee.init();
133     rareNonInheritedData.access()->m_multiCol.init();
134     rareNonInheritedData.access()->m_transform.init();
135 #if ENABLE(CSS_FILTERS)
136     rareNonInheritedData.access()->m_filter.init();
137 #endif
138     rareNonInheritedData.access()->m_grid.init();
139     rareNonInheritedData.access()->m_gridItem.init();
140     rareInheritedData.init();
141     inherited.init();
142 #if ENABLE(SVG)
143     m_svgStyle.init();
144 #endif
145 }
146
147 ALWAYS_INLINE RenderStyle::RenderStyle(const RenderStyle& o)
148     : RefCounted<RenderStyle>()
149     , m_box(o.m_box)
150     , visual(o.visual)
151     , m_background(o.m_background)
152     , surround(o.surround)
153     , rareNonInheritedData(o.rareNonInheritedData)
154     , rareInheritedData(o.rareInheritedData)
155     , inherited(o.inherited)
156 #if ENABLE(SVG)
157     , m_svgStyle(o.m_svgStyle)
158 #endif
159     , inherited_flags(o.inherited_flags)
160     , noninherited_flags(o.noninherited_flags)
161 {
162 }
163
164 void RenderStyle::inheritFrom(const RenderStyle* inheritParent, IsAtShadowBoundary isAtShadowBoundary)
165 {
166     if (isAtShadowBoundary == AtShadowBoundary) {
167         // Even if surrounding content is user-editable, shadow DOM should act as a single unit, and not necessarily be editable
168         EUserModify currentUserModify = userModify();
169         rareInheritedData = inheritParent->rareInheritedData;
170         setUserModify(currentUserModify);
171     } else
172         rareInheritedData = inheritParent->rareInheritedData;
173     inherited = inheritParent->inherited;
174     inherited_flags = inheritParent->inherited_flags;
175 #if ENABLE(SVG)
176     if (m_svgStyle != inheritParent->m_svgStyle)
177         m_svgStyle.access()->inheritFrom(inheritParent->m_svgStyle.get());
178 #endif
179 }
180
181 void RenderStyle::copyNonInheritedFrom(const RenderStyle* other)
182 {
183     m_box = other->m_box;
184     visual = other->visual;
185     m_background = other->m_background;
186     surround = other->surround;
187     rareNonInheritedData = other->rareNonInheritedData;
188     // The flags are copied one-by-one because noninherited_flags contains a bunch of stuff other than real style data.
189     noninherited_flags._effectiveDisplay = other->noninherited_flags._effectiveDisplay;
190     noninherited_flags._originalDisplay = other->noninherited_flags._originalDisplay;
191     noninherited_flags._overflowX = other->noninherited_flags._overflowX;
192     noninherited_flags._overflowY = other->noninherited_flags._overflowY;
193     noninherited_flags._vertical_align = other->noninherited_flags._vertical_align;
194     noninherited_flags._clear = other->noninherited_flags._clear;
195     noninherited_flags._position = other->noninherited_flags._position;
196     noninherited_flags._floating = other->noninherited_flags._floating;
197     noninherited_flags._table_layout = other->noninherited_flags._table_layout;
198     noninherited_flags._unicodeBidi = other->noninherited_flags._unicodeBidi;
199     noninherited_flags._page_break_before = other->noninherited_flags._page_break_before;
200     noninherited_flags._page_break_after = other->noninherited_flags._page_break_after;
201     noninherited_flags._page_break_inside = other->noninherited_flags._page_break_inside;
202 #if ENABLE(SVG)
203     if (m_svgStyle != other->m_svgStyle)
204         m_svgStyle.access()->copyNonInheritedFrom(other->m_svgStyle.get());
205 #endif
206     ASSERT(zoom() == initialZoom());
207 }
208
209 bool RenderStyle::operator==(const RenderStyle& o) const
210 {
211     // compare everything except the pseudoStyle pointer
212     return inherited_flags == o.inherited_flags
213         && noninherited_flags == o.noninherited_flags
214         && m_box == o.m_box
215         && visual == o.visual
216         && m_background == o.m_background
217         && surround == o.surround
218         && rareNonInheritedData == o.rareNonInheritedData
219         && rareInheritedData == o.rareInheritedData
220         && inherited == o.inherited
221 #if ENABLE(SVG)
222         && m_svgStyle == o.m_svgStyle
223 #endif
224             ;
225 }
226
227 bool RenderStyle::isStyleAvailable() const
228 {
229     return this != StyleResolver::styleNotYetAvailable();
230 }
231
232 static inline int pseudoBit(PseudoId pseudo)
233 {
234     return 1 << (pseudo - 1);
235 }
236
237 bool RenderStyle::hasAnyPublicPseudoStyles() const
238 {
239     return PUBLIC_PSEUDOID_MASK & noninherited_flags._pseudoBits;
240 }
241
242 bool RenderStyle::hasPseudoStyle(PseudoId pseudo) const
243 {
244     ASSERT(pseudo > NOPSEUDO);
245     ASSERT(pseudo < FIRST_INTERNAL_PSEUDOID);
246     return pseudoBit(pseudo) & noninherited_flags._pseudoBits;
247 }
248
249 void RenderStyle::setHasPseudoStyle(PseudoId pseudo)
250 {
251     ASSERT(pseudo > NOPSEUDO);
252     ASSERT(pseudo < FIRST_INTERNAL_PSEUDOID);
253     noninherited_flags._pseudoBits |= pseudoBit(pseudo);
254 }
255
256 RenderStyle* RenderStyle::getCachedPseudoStyle(PseudoId pid) const
257 {
258     if (!m_cachedPseudoStyles || !m_cachedPseudoStyles->size())
259         return 0;
260
261     if (styleType() != NOPSEUDO) 
262         return 0;
263
264     for (size_t i = 0; i < m_cachedPseudoStyles->size(); ++i) {
265         RenderStyle* pseudoStyle = m_cachedPseudoStyles->at(i).get();
266         if (pseudoStyle->styleType() == pid)
267             return pseudoStyle;
268     }
269
270     return 0;
271 }
272
273 RenderStyle* RenderStyle::addCachedPseudoStyle(PassRefPtr<RenderStyle> pseudo)
274 {
275     if (!pseudo)
276         return 0;
277
278     ASSERT(pseudo->styleType() > NOPSEUDO);
279
280     RenderStyle* result = pseudo.get();
281
282     if (!m_cachedPseudoStyles)
283         m_cachedPseudoStyles = adoptPtr(new PseudoStyleCache);
284
285     m_cachedPseudoStyles->append(pseudo);
286
287     return result;
288 }
289
290 void RenderStyle::removeCachedPseudoStyle(PseudoId pid)
291 {
292     if (!m_cachedPseudoStyles)
293         return;
294     for (size_t i = 0; i < m_cachedPseudoStyles->size(); ++i) {
295         RenderStyle* pseudoStyle = m_cachedPseudoStyles->at(i).get();
296         if (pseudoStyle->styleType() == pid) {
297             m_cachedPseudoStyles->remove(i);
298             return;
299         }
300     }
301 }
302
303 bool RenderStyle::inheritedNotEqual(const RenderStyle* other) const
304 {
305     return inherited_flags != other->inherited_flags
306            || inherited != other->inherited
307 #if ENABLE(SVG)
308            || m_svgStyle->inheritedNotEqual(other->m_svgStyle.get())
309 #endif
310            || rareInheritedData != other->rareInheritedData;
311 }
312
313 bool RenderStyle::inheritedDataShared(const RenderStyle* other) const
314 {
315     // This is a fast check that only looks if the data structures are shared.
316     return inherited_flags == other->inherited_flags
317         && inherited.get() == other->inherited.get()
318 #if ENABLE(SVG)
319         && m_svgStyle.get() == other->m_svgStyle.get()
320 #endif
321         && rareInheritedData.get() == other->rareInheritedData.get();
322 }
323
324 static bool positionedObjectMoved(const LengthBox& a, const LengthBox& b)
325 {
326     // If any unit types are different, then we can't guarantee
327     // that this was just a movement.
328     if (a.left().type() != b.left().type()
329         || a.right().type() != b.right().type()
330         || a.top().type() != b.top().type()
331         || a.bottom().type() != b.bottom().type())
332         return false;
333
334     // Only one unit can be non-auto in the horizontal direction and
335     // in the vertical direction.  Otherwise the adjustment of values
336     // is changing the size of the box.
337     if (!a.left().isIntrinsicOrAuto() && !a.right().isIntrinsicOrAuto())
338         return false;
339     if (!a.top().isIntrinsicOrAuto() && !a.bottom().isIntrinsicOrAuto())
340         return false;
341
342     // One of the units is fixed or percent in both directions and stayed
343     // that way in the new style.  Therefore all we are doing is moving.
344     return true;
345 }
346
347 StyleDifference RenderStyle::diff(const RenderStyle* other, unsigned& changedContextSensitiveProperties) const
348 {
349     changedContextSensitiveProperties = ContextSensitivePropertyNone;
350
351 #if ENABLE(SVG)
352     StyleDifference svgChange = StyleDifferenceEqual;
353     if (m_svgStyle != other->m_svgStyle) {
354         svgChange = m_svgStyle->diff(other->m_svgStyle.get());
355         if (svgChange == StyleDifferenceLayout)
356             return svgChange;
357     }
358 #endif
359
360     if (m_box->width() != other->m_box->width()
361         || m_box->minWidth() != other->m_box->minWidth()
362         || m_box->maxWidth() != other->m_box->maxWidth()
363         || m_box->height() != other->m_box->height()
364         || m_box->minHeight() != other->m_box->minHeight()
365         || m_box->maxHeight() != other->m_box->maxHeight())
366         return StyleDifferenceLayout;
367
368     if (m_box->verticalAlign() != other->m_box->verticalAlign() || noninherited_flags._vertical_align != other->noninherited_flags._vertical_align)
369         return StyleDifferenceLayout;
370
371     if (m_box->boxSizing() != other->m_box->boxSizing())
372         return StyleDifferenceLayout;
373
374     if (surround->margin != other->surround->margin)
375         return StyleDifferenceLayout;
376
377     if (surround->padding != other->surround->padding)
378         return StyleDifferenceLayout;
379
380     if (rareNonInheritedData.get() != other->rareNonInheritedData.get()) {
381         if (rareNonInheritedData->m_appearance != other->rareNonInheritedData->m_appearance 
382             || rareNonInheritedData->marginBeforeCollapse != other->rareNonInheritedData->marginBeforeCollapse
383             || rareNonInheritedData->marginAfterCollapse != other->rareNonInheritedData->marginAfterCollapse
384             || rareNonInheritedData->lineClamp != other->rareNonInheritedData->lineClamp
385             || rareNonInheritedData->textOverflow != other->rareNonInheritedData->textOverflow)
386             return StyleDifferenceLayout;
387
388         if (rareNonInheritedData->m_regionOverflow != other->rareNonInheritedData->m_regionOverflow)
389             return StyleDifferenceLayout;
390
391         if (rareNonInheritedData->m_wrapFlow != other->rareNonInheritedData->m_wrapFlow
392             || rareNonInheritedData->m_wrapThrough != other->rareNonInheritedData->m_wrapThrough
393             || rareNonInheritedData->m_wrapMargin != other->rareNonInheritedData->m_wrapMargin
394             || rareNonInheritedData->m_wrapPadding != other->rareNonInheritedData->m_wrapPadding)
395             return StyleDifferenceLayout;
396
397         if (rareNonInheritedData->m_deprecatedFlexibleBox.get() != other->rareNonInheritedData->m_deprecatedFlexibleBox.get()
398             && *rareNonInheritedData->m_deprecatedFlexibleBox.get() != *other->rareNonInheritedData->m_deprecatedFlexibleBox.get())
399             return StyleDifferenceLayout;
400
401         if (rareNonInheritedData->m_flexibleBox.get() != other->rareNonInheritedData->m_flexibleBox.get()
402             && *rareNonInheritedData->m_flexibleBox.get() != *other->rareNonInheritedData->m_flexibleBox.get())
403             return StyleDifferenceLayout;
404         if (rareNonInheritedData->m_order != other->rareNonInheritedData->m_order
405             || rareNonInheritedData->m_alignContent != other->rareNonInheritedData->m_alignContent
406             || rareNonInheritedData->m_alignItems != other->rareNonInheritedData->m_alignItems
407             || rareNonInheritedData->m_alignSelf != other->rareNonInheritedData->m_alignSelf
408             || rareNonInheritedData->m_justifyContent != other->rareNonInheritedData->m_justifyContent)
409             return StyleDifferenceLayout;
410
411         // FIXME: We should add an optimized form of layout that just recomputes visual overflow.
412         if (!rareNonInheritedData->shadowDataEquivalent(*other->rareNonInheritedData.get()))
413             return StyleDifferenceLayout;
414
415         if (!rareNonInheritedData->reflectionDataEquivalent(*other->rareNonInheritedData.get()))
416             return StyleDifferenceLayout;
417
418         if (rareNonInheritedData->m_multiCol.get() != other->rareNonInheritedData->m_multiCol.get()
419             && *rareNonInheritedData->m_multiCol.get() != *other->rareNonInheritedData->m_multiCol.get())
420             return StyleDifferenceLayout;
421
422         if (rareNonInheritedData->m_transform.get() != other->rareNonInheritedData->m_transform.get()
423             && *rareNonInheritedData->m_transform.get() != *other->rareNonInheritedData->m_transform.get()) {
424 #if USE(ACCELERATED_COMPOSITING)
425             changedContextSensitiveProperties |= ContextSensitivePropertyTransform;
426             // Don't return; keep looking for another change
427 #else
428             return StyleDifferenceLayout;
429 #endif
430         }
431
432         if (rareNonInheritedData->m_grid.get() != other->rareNonInheritedData->m_grid.get()
433             && rareNonInheritedData->m_gridItem.get() != other->rareNonInheritedData->m_gridItem.get())
434             return StyleDifferenceLayout;
435
436 #if !USE(ACCELERATED_COMPOSITING)
437         if (rareNonInheritedData.get() != other->rareNonInheritedData.get()) {
438             if (rareNonInheritedData->m_transformStyle3D != other->rareNonInheritedData->m_transformStyle3D
439                 || rareNonInheritedData->m_backfaceVisibility != other->rareNonInheritedData->m_backfaceVisibility
440                 || rareNonInheritedData->m_perspective != other->rareNonInheritedData->m_perspective
441                 || rareNonInheritedData->m_perspectiveOriginX != other->rareNonInheritedData->m_perspectiveOriginX
442                 || rareNonInheritedData->m_perspectiveOriginY != other->rareNonInheritedData->m_perspectiveOriginY)
443                 return StyleDifferenceLayout;
444         }
445 #endif
446
447 #if ENABLE(DASHBOARD_SUPPORT)
448         // If regions change, trigger a relayout to re-calc regions.
449         if (rareNonInheritedData->m_dashboardRegions != other->rareNonInheritedData->m_dashboardRegions)
450             return StyleDifferenceLayout;
451 #endif
452     }
453
454     if (rareInheritedData.get() != other->rareInheritedData.get()) {
455         if (rareInheritedData->highlight != other->rareInheritedData->highlight
456             || rareInheritedData->indent != other->rareInheritedData->indent
457             || rareInheritedData->m_effectiveZoom != other->rareInheritedData->m_effectiveZoom
458             || rareInheritedData->textSizeAdjust != other->rareInheritedData->textSizeAdjust
459             || rareInheritedData->wordBreak != other->rareInheritedData->wordBreak
460             || rareInheritedData->wordWrap != other->rareInheritedData->wordWrap
461             || rareInheritedData->nbspMode != other->rareInheritedData->nbspMode
462             || rareInheritedData->khtmlLineBreak != other->rareInheritedData->khtmlLineBreak
463             || rareInheritedData->textSecurity != other->rareInheritedData->textSecurity
464             || rareInheritedData->hyphens != other->rareInheritedData->hyphens
465             || rareInheritedData->hyphenationLimitBefore != other->rareInheritedData->hyphenationLimitBefore
466             || rareInheritedData->hyphenationLimitAfter != other->rareInheritedData->hyphenationLimitAfter
467             || rareInheritedData->hyphenationString != other->rareInheritedData->hyphenationString
468             || rareInheritedData->locale != other->rareInheritedData->locale
469             || rareInheritedData->textEmphasisMark != other->rareInheritedData->textEmphasisMark
470             || rareInheritedData->textEmphasisPosition != other->rareInheritedData->textEmphasisPosition
471             || rareInheritedData->textEmphasisCustomMark != other->rareInheritedData->textEmphasisCustomMark
472             || rareInheritedData->m_tabSize != other->rareInheritedData->m_tabSize
473             || rareInheritedData->m_lineBoxContain != other->rareInheritedData->m_lineBoxContain
474             || rareInheritedData->m_lineGrid != other->rareInheritedData->m_lineGrid
475 #if ENABLE(CSS_IMAGE_RESOLUTION)
476             || rareInheritedData->m_imageResolutionSource != other->rareInheritedData->m_imageResolutionSource
477             || rareInheritedData->m_imageResolutionSnap != other->rareInheritedData->m_imageResolutionSnap
478             || rareInheritedData->m_imageResolution != other->rareInheritedData->m_imageResolution
479 #endif
480             || rareInheritedData->m_lineSnap != other->rareInheritedData->m_lineSnap
481             || rareInheritedData->m_lineAlign != other->rareInheritedData->m_lineAlign)
482             return StyleDifferenceLayout;
483
484         if (!rareInheritedData->shadowDataEquivalent(*other->rareInheritedData.get()))
485             return StyleDifferenceLayout;
486
487         if (textStrokeWidth() != other->textStrokeWidth())
488             return StyleDifferenceLayout;
489     }
490
491     if (inherited->line_height != other->inherited->line_height
492         || inherited->list_style_image != other->inherited->list_style_image
493         || inherited->font != other->inherited->font
494         || inherited->horizontal_border_spacing != other->inherited->horizontal_border_spacing
495         || inherited->vertical_border_spacing != other->inherited->vertical_border_spacing
496         || inherited_flags._box_direction != other->inherited_flags._box_direction
497         || inherited_flags.m_rtlOrdering != other->inherited_flags.m_rtlOrdering
498         || noninherited_flags._position != other->noninherited_flags._position
499         || noninherited_flags._floating != other->noninherited_flags._floating
500         || noninherited_flags._originalDisplay != other->noninherited_flags._originalDisplay)
501         return StyleDifferenceLayout;
502
503
504     if (((int)noninherited_flags._effectiveDisplay) >= TABLE) {
505         if (inherited_flags._border_collapse != other->inherited_flags._border_collapse
506             || inherited_flags._empty_cells != other->inherited_flags._empty_cells
507             || inherited_flags._caption_side != other->inherited_flags._caption_side
508             || noninherited_flags._table_layout != other->noninherited_flags._table_layout)
509             return StyleDifferenceLayout;
510
511         // In the collapsing border model, 'hidden' suppresses other borders, while 'none'
512         // does not, so these style differences can be width differences.
513         if (inherited_flags._border_collapse
514             && ((borderTopStyle() == BHIDDEN && other->borderTopStyle() == BNONE)
515                 || (borderTopStyle() == BNONE && other->borderTopStyle() == BHIDDEN)
516                 || (borderBottomStyle() == BHIDDEN && other->borderBottomStyle() == BNONE)
517                 || (borderBottomStyle() == BNONE && other->borderBottomStyle() == BHIDDEN)
518                 || (borderLeftStyle() == BHIDDEN && other->borderLeftStyle() == BNONE)
519                 || (borderLeftStyle() == BNONE && other->borderLeftStyle() == BHIDDEN)
520                 || (borderRightStyle() == BHIDDEN && other->borderRightStyle() == BNONE)
521                 || (borderRightStyle() == BNONE && other->borderRightStyle() == BHIDDEN)))
522             return StyleDifferenceLayout;
523     }
524
525     if (noninherited_flags._effectiveDisplay == LIST_ITEM) {
526         if (inherited_flags._list_style_type != other->inherited_flags._list_style_type
527             || inherited_flags._list_style_position != other->inherited_flags._list_style_position)
528             return StyleDifferenceLayout;
529     }
530
531     if (inherited_flags._text_align != other->inherited_flags._text_align
532         || inherited_flags._text_transform != other->inherited_flags._text_transform
533         || inherited_flags._direction != other->inherited_flags._direction
534         || inherited_flags._white_space != other->inherited_flags._white_space
535         || noninherited_flags._clear != other->noninherited_flags._clear
536         || noninherited_flags._unicodeBidi != other->noninherited_flags._unicodeBidi)
537         return StyleDifferenceLayout;
538
539     // Check block flow direction.
540     if (inherited_flags.m_writingMode != other->inherited_flags.m_writingMode)
541         return StyleDifferenceLayout;
542
543     // Check text combine mode.
544     if (rareNonInheritedData->m_textCombine != other->rareNonInheritedData->m_textCombine)
545         return StyleDifferenceLayout;
546
547     // Overflow returns a layout hint.
548     if (noninherited_flags._overflowX != other->noninherited_flags._overflowX
549         || noninherited_flags._overflowY != other->noninherited_flags._overflowY)
550         return StyleDifferenceLayout;
551
552     // If our border widths change, then we need to layout.  Other changes to borders
553     // only necessitate a repaint.
554     if (borderLeftWidth() != other->borderLeftWidth()
555         || borderTopWidth() != other->borderTopWidth()
556         || borderBottomWidth() != other->borderBottomWidth()
557         || borderRightWidth() != other->borderRightWidth())
558         return StyleDifferenceLayout;
559
560     // If the counter directives change, trigger a relayout to re-calculate counter values and rebuild the counter node tree.
561     const CounterDirectiveMap* mapA = rareNonInheritedData->m_counterDirectives.get();
562     const CounterDirectiveMap* mapB = other->rareNonInheritedData->m_counterDirectives.get();
563     if (!(mapA == mapB || (mapA && mapB && *mapA == *mapB)))
564         return StyleDifferenceLayout;
565     if (rareNonInheritedData->m_counterIncrement != other->rareNonInheritedData->m_counterIncrement
566         || rareNonInheritedData->m_counterReset != other->rareNonInheritedData->m_counterReset)
567         return StyleDifferenceLayout;
568
569     if ((visibility() == COLLAPSE) != (other->visibility() == COLLAPSE))
570         return StyleDifferenceLayout;
571
572     if ((rareNonInheritedData->opacity == 1 && other->rareNonInheritedData->opacity < 1)
573         || (rareNonInheritedData->opacity < 1 && other->rareNonInheritedData->opacity == 1)) {
574         // FIXME: We would like to use SimplifiedLayout here, but we can't quite do that yet.
575         // We need to make sure SimplifiedLayout can operate correctly on RenderInlines (we will need
576         // to add a selfNeedsSimplifiedLayout bit in order to not get confused and taint every line).
577         // In addition we need to solve the floating object issue when layers come and go. Right now
578         // a full layout is necessary to keep floating object lists sane.
579         return StyleDifferenceLayout;
580     }
581
582 #if ENABLE(SVG)
583     // SVGRenderStyle::diff() might have returned StyleDifferenceRepaint, eg. if fill changes.
584     // If eg. the font-size changed at the same time, we're not allowed to return StyleDifferenceRepaint,
585     // but have to return StyleDifferenceLayout, that's why  this if branch comes after all branches
586     // that are relevant for SVG and might return StyleDifferenceLayout.
587     if (svgChange != StyleDifferenceEqual)
588         return svgChange;
589 #endif
590
591     // Make sure these left/top/right/bottom checks stay below all layout checks and above
592     // all visible checks.
593     if (position() != StaticPosition) {
594         if (surround->offset != other->surround->offset) {
595              // Optimize for the case where a positioned layer is moving but not changing size.
596             if (position() == AbsolutePosition && positionedObjectMoved(surround->offset, other->surround->offset))
597                 return StyleDifferenceLayoutPositionedMovementOnly;
598
599             // FIXME: We would like to use SimplifiedLayout for relative positioning, but we can't quite do that yet.
600             // We need to make sure SimplifiedLayout can operate correctly on RenderInlines (we will need
601             // to add a selfNeedsSimplifiedLayout bit in order to not get confused and taint every line).
602             return StyleDifferenceLayout;
603         } else if (m_box->zIndex() != other->m_box->zIndex() || m_box->hasAutoZIndex() != other->m_box->hasAutoZIndex()
604                  || visual->clip != other->visual->clip || visual->hasClip != other->visual->hasClip)
605             return StyleDifferenceRepaintLayer;
606     }
607
608     if (rareNonInheritedData->opacity != other->rareNonInheritedData->opacity) {
609 #if USE(ACCELERATED_COMPOSITING)
610         changedContextSensitiveProperties |= ContextSensitivePropertyOpacity;
611         // Don't return; keep looking for another change.
612 #else
613         return StyleDifferenceRepaintLayer;
614 #endif
615     }
616
617 #if ENABLE(CSS_FILTERS)
618     if (rareNonInheritedData->m_filter.get() != other->rareNonInheritedData->m_filter.get()
619         && *rareNonInheritedData->m_filter.get() != *other->rareNonInheritedData->m_filter.get()) {
620 #if USE(ACCELERATED_COMPOSITING)
621         changedContextSensitiveProperties |= ContextSensitivePropertyFilter;
622         // Don't return; keep looking for another change.
623 #else
624         return StyleDifferenceRepaintLayer;
625 #endif
626     }
627 #endif
628
629     if (rareNonInheritedData->m_mask != other->rareNonInheritedData->m_mask
630         || rareNonInheritedData->m_maskBoxImage != other->rareNonInheritedData->m_maskBoxImage)
631         return StyleDifferenceRepaintLayer;
632
633     if (inherited->color != other->inherited->color
634         || inherited_flags._visibility != other->inherited_flags._visibility
635         || inherited_flags._text_decorations != other->inherited_flags._text_decorations
636         || inherited_flags.m_printColorAdjust != other->inherited_flags.m_printColorAdjust
637         || inherited_flags._insideLink != other->inherited_flags._insideLink
638         || surround->border != other->surround->border
639         || *m_background.get() != *other->m_background.get()
640         || visual->textDecoration != other->visual->textDecoration
641         || rareInheritedData->userModify != other->rareInheritedData->userModify
642         || rareInheritedData->userSelect != other->rareInheritedData->userSelect
643         || rareNonInheritedData->userDrag != other->rareNonInheritedData->userDrag
644         || rareNonInheritedData->m_borderFit != other->rareNonInheritedData->m_borderFit
645         || rareInheritedData->textFillColor != other->rareInheritedData->textFillColor
646         || rareInheritedData->textStrokeColor != other->rareInheritedData->textStrokeColor
647         || rareInheritedData->textEmphasisColor != other->rareInheritedData->textEmphasisColor
648         || rareInheritedData->textEmphasisFill != other->rareInheritedData->textEmphasisFill
649         || rareInheritedData->m_imageRendering != other->rareInheritedData->m_imageRendering)
650         return StyleDifferenceRepaint;
651         
652         // FIXME: The current spec is being reworked to remove dependencies between exclusions and affected 
653         // content. There's a proposal to use floats instead. In that case, wrap-shape should actually relayout 
654         // the parent container. For sure, I will have to revisit this code, but for now I've added this in order 
655         // to avoid having diff() == StyleDifferenceEqual where wrap-shapes actually differ.
656         // Tracking bug: https://bugs.webkit.org/show_bug.cgi?id=62991
657         if (rareNonInheritedData->m_wrapShapeInside != other->rareNonInheritedData->m_wrapShapeInside
658             || rareNonInheritedData->m_wrapShapeOutside != other->rareNonInheritedData->m_wrapShapeOutside)
659             return StyleDifferenceRepaint;
660
661 #if USE(ACCELERATED_COMPOSITING)
662     if (rareNonInheritedData.get() != other->rareNonInheritedData.get()) {
663         if (rareNonInheritedData->m_transformStyle3D != other->rareNonInheritedData->m_transformStyle3D
664             || rareNonInheritedData->m_backfaceVisibility != other->rareNonInheritedData->m_backfaceVisibility
665             || rareNonInheritedData->m_perspective != other->rareNonInheritedData->m_perspective
666             || rareNonInheritedData->m_perspectiveOriginX != other->rareNonInheritedData->m_perspectiveOriginX
667             || rareNonInheritedData->m_perspectiveOriginY != other->rareNonInheritedData->m_perspectiveOriginY)
668             return StyleDifferenceRecompositeLayer;
669     }
670 #endif
671
672     // Cursors are not checked, since they will be set appropriately in response to mouse events,
673     // so they don't need to cause any repaint or layout.
674
675     // 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
676     // the resulting transition properly.
677     return StyleDifferenceEqual;
678 }
679
680 void RenderStyle::setClip(Length top, Length right, Length bottom, Length left)
681 {
682     StyleVisualData* data = visual.access();
683     data->clip.m_top = top;
684     data->clip.m_right = right;
685     data->clip.m_bottom = bottom;
686     data->clip.m_left = left;
687 }
688
689 void RenderStyle::addCursor(PassRefPtr<StyleImage> image, const IntPoint& hotSpot)
690 {
691     if (!rareInheritedData.access()->cursorData)
692         rareInheritedData.access()->cursorData = CursorList::create();
693     rareInheritedData.access()->cursorData->append(CursorData(image, hotSpot));
694 }
695
696 void RenderStyle::setCursorList(PassRefPtr<CursorList> other)
697 {
698     rareInheritedData.access()->cursorData = other;
699 }
700
701 void RenderStyle::setQuotes(PassRefPtr<QuotesData> q)
702 {
703     if (QuotesData::equals(rareInheritedData->quotes.get(), q.get()))
704         return;
705     rareInheritedData.access()->quotes = q;
706 }
707
708 void RenderStyle::clearCursorList()
709 {
710     if (rareInheritedData->cursorData)
711         rareInheritedData.access()->cursorData = 0;
712 }
713
714 void RenderStyle::clearContent()
715 {
716     if (rareNonInheritedData->m_content)
717         rareNonInheritedData.access()->m_content = nullptr;
718 }
719
720 void RenderStyle::appendContent(PassOwnPtr<ContentData> contentData)
721 {
722     OwnPtr<ContentData>& content = rareNonInheritedData.access()->m_content;
723     ContentData* lastContent = content.get();
724     while (lastContent && lastContent->next())
725         lastContent = lastContent->next();
726
727     if (lastContent)
728         lastContent->setNext(contentData);
729     else
730         content = contentData;
731 }
732
733 void RenderStyle::setContent(PassRefPtr<StyleImage> image, bool add)
734 {
735     if (!image)
736         return;
737         
738     if (add) {
739         appendContent(ContentData::create(image));
740         return;
741     }
742
743     rareNonInheritedData.access()->m_content = ContentData::create(image);
744 }
745
746 void RenderStyle::setContent(const String& string, bool add)
747 {
748     OwnPtr<ContentData>& content = rareNonInheritedData.access()->m_content;
749     if (add) {
750         ContentData* lastContent = content.get();
751         while (lastContent && lastContent->next())
752             lastContent = lastContent->next();
753
754         if (lastContent) {
755             // We attempt to merge with the last ContentData if possible.
756             if (lastContent->isText()) {
757                 TextContentData* textContent = static_cast<TextContentData*>(lastContent);
758                 String text = textContent->text();
759                 text += string;
760                 textContent->setText(text);
761             } else
762                 lastContent->setNext(ContentData::create(string));
763
764             return;
765         }
766     }
767
768     content = ContentData::create(string);
769 }
770
771 void RenderStyle::setContent(PassOwnPtr<CounterContent> counter, bool add)
772 {
773     if (!counter)
774         return;
775
776     if (add) {
777         appendContent(ContentData::create(counter));
778         return;
779     }
780
781     rareNonInheritedData.access()->m_content = ContentData::create(counter);
782 }
783
784 void RenderStyle::setContent(QuoteType quote, bool add)
785 {
786     if (add) {
787         appendContent(ContentData::create(quote));
788         return;
789     }
790
791     rareNonInheritedData.access()->m_content = ContentData::create(quote);
792 }
793     
794 inline bool requireTransformOrigin(const Vector<RefPtr<TransformOperation> >& transformOperations, RenderStyle::ApplyTransformOrigin applyOrigin)
795 {
796     // transform-origin brackets the transform with translate operations.
797     // Optimize for the case where the only transform is a translation, since the transform-origin is irrelevant
798     // in that case.
799     if (applyOrigin != RenderStyle::IncludeTransformOrigin)
800         return false;
801
802     unsigned size = transformOperations.size();
803     for (unsigned i = 0; i < size; ++i) {
804         TransformOperation::OperationType type = transformOperations[i]->getOperationType();
805         if (type != TransformOperation::TRANSLATE_X
806             && type != TransformOperation::TRANSLATE_Y
807             && type != TransformOperation::TRANSLATE 
808             && type != TransformOperation::TRANSLATE_Z
809             && type != TransformOperation::TRANSLATE_3D)
810             return true;
811     }
812     
813     return false;
814 }
815
816 void RenderStyle::applyTransform(TransformationMatrix& transform, const LayoutSize& borderBoxSize, ApplyTransformOrigin applyOrigin) const
817 {
818     // FIXME: when subpixel layout is supported (bug 71143) the body of this function could be replaced by
819     // applyTransform(transform, FloatRect(FloatPoint(), borderBoxSize), applyOrigin);
820     
821     const Vector<RefPtr<TransformOperation> >& transformOperations = rareNonInheritedData->m_transform->m_operations.operations();
822     bool applyTransformOrigin = requireTransformOrigin(transformOperations, applyOrigin);
823
824     if (applyTransformOrigin)
825         transform.translate3d(floatValueForLength(transformOriginX(), borderBoxSize.width()), floatValueForLength(transformOriginY(), borderBoxSize.height()), transformOriginZ());
826
827     unsigned size = transformOperations.size();
828     for (unsigned i = 0; i < size; ++i)
829         transformOperations[i]->apply(transform, borderBoxSize);
830
831     if (applyTransformOrigin)
832         transform.translate3d(-floatValueForLength(transformOriginX(), borderBoxSize.width()), -floatValueForLength(transformOriginY(), borderBoxSize.height()), -transformOriginZ()); 
833 }
834
835 void RenderStyle::applyTransform(TransformationMatrix& transform, const FloatRect& boundingBox, ApplyTransformOrigin applyOrigin) const
836 {
837     const Vector<RefPtr<TransformOperation> >& transformOperations = rareNonInheritedData->m_transform->m_operations.operations();
838     bool applyTransformOrigin = requireTransformOrigin(transformOperations, applyOrigin);
839     
840     float offsetX = transformOriginX().type() == Percent ? boundingBox.x() : 0;
841     float offsetY = transformOriginY().type() == Percent ? boundingBox.y() : 0;
842     
843     if (applyTransformOrigin) {
844         transform.translate3d(floatValueForLength(transformOriginX(), boundingBox.width()) + offsetX,
845                               floatValueForLength(transformOriginY(), boundingBox.height()) + offsetY,
846                               transformOriginZ());
847     }
848     
849     unsigned size = transformOperations.size();
850     for (unsigned i = 0; i < size; ++i)
851         transformOperations[i]->apply(transform, boundingBox.size());
852     
853     if (applyTransformOrigin) {
854         transform.translate3d(-floatValueForLength(transformOriginX(), boundingBox.width()) - offsetX,
855                               -floatValueForLength(transformOriginY(), boundingBox.height()) - offsetY,
856                               -transformOriginZ());
857     }
858 }
859
860 void RenderStyle::setPageScaleTransform(float scale)
861 {
862     if (scale == 1)
863         return;
864     TransformOperations transform;
865     transform.operations().append(ScaleTransformOperation::create(scale, scale, ScaleTransformOperation::SCALE));
866     setTransform(transform);
867     setTransformOriginX(Length(0, Fixed));
868     setTransformOriginY(Length(0, Fixed));
869 }
870
871 void RenderStyle::setTextShadow(PassOwnPtr<ShadowData> shadowData, bool add)
872 {
873     ASSERT(!shadowData || (!shadowData->spread() && shadowData->style() == Normal));
874
875     StyleRareInheritedData* rareData = rareInheritedData.access();
876     if (!add) {
877         rareData->textShadow = shadowData;
878         return;
879     }
880
881     shadowData->setNext(rareData->textShadow.release());
882     rareData->textShadow = shadowData;
883 }
884
885 void RenderStyle::setBoxShadow(PassOwnPtr<ShadowData> shadowData, bool add)
886 {
887     StyleRareNonInheritedData* rareData = rareNonInheritedData.access();
888     if (!add) {
889         rareData->m_boxShadow = shadowData;
890         return;
891     }
892
893     shadowData->setNext(rareData->m_boxShadow.release());
894     rareData->m_boxShadow = shadowData;
895 }
896
897 static RoundedRect::Radii calcRadiiFor(const BorderData& border, IntSize size, RenderView* renderView)
898 {
899     return RoundedRect::Radii(
900         IntSize(valueForLength(border.topLeft().width(), size.width(), renderView), 
901                 valueForLength(border.topLeft().height(), size.height(), renderView)),
902         IntSize(valueForLength(border.topRight().width(), size.width(), renderView),
903                 valueForLength(border.topRight().height(), size.height(), renderView)),
904         IntSize(valueForLength(border.bottomLeft().width(), size.width(), renderView), 
905                 valueForLength(border.bottomLeft().height(), size.height(), renderView)),
906         IntSize(valueForLength(border.bottomRight().width(), size.width(), renderView), 
907                 valueForLength(border.bottomRight().height(), size.height(), renderView)));
908 }
909
910 static float calcConstraintScaleFor(const IntRect& rect, const RoundedRect::Radii& radii)
911 {
912     // Constrain corner radii using CSS3 rules:
913     // http://www.w3.org/TR/css3-background/#the-border-radius
914     
915     float factor = 1;
916     unsigned radiiSum;
917
918     // top
919     radiiSum = static_cast<unsigned>(radii.topLeft().width()) + static_cast<unsigned>(radii.topRight().width()); // Casts to avoid integer overflow.
920     if (radiiSum > static_cast<unsigned>(rect.width()))
921         factor = min(static_cast<float>(rect.width()) / radiiSum, factor);
922
923     // bottom
924     radiiSum = static_cast<unsigned>(radii.bottomLeft().width()) + static_cast<unsigned>(radii.bottomRight().width());
925     if (radiiSum > static_cast<unsigned>(rect.width()))
926         factor = min(static_cast<float>(rect.width()) / radiiSum, factor);
927     
928     // left
929     radiiSum = static_cast<unsigned>(radii.topLeft().height()) + static_cast<unsigned>(radii.bottomLeft().height());
930     if (radiiSum > static_cast<unsigned>(rect.height()))
931         factor = min(static_cast<float>(rect.height()) / radiiSum, factor);
932     
933     // right
934     radiiSum = static_cast<unsigned>(radii.topRight().height()) + static_cast<unsigned>(radii.bottomRight().height());
935     if (radiiSum > static_cast<unsigned>(rect.height()))
936         factor = min(static_cast<float>(rect.height()) / radiiSum, factor);
937     
938     ASSERT(factor <= 1);
939     return factor;
940 }
941
942 RoundedRect RenderStyle::getRoundedBorderFor(const LayoutRect& borderRect, RenderView* renderView, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
943 {
944     IntRect snappedBorderRect(pixelSnappedIntRect(borderRect));
945     RoundedRect roundedRect(snappedBorderRect);
946     if (hasBorderRadius()) {
947         RoundedRect::Radii radii = calcRadiiFor(surround->border, snappedBorderRect.size(), renderView);
948         radii.scale(calcConstraintScaleFor(snappedBorderRect, radii));
949         roundedRect.includeLogicalEdges(radii, isHorizontalWritingMode(), includeLogicalLeftEdge, includeLogicalRightEdge);
950     }
951     return roundedRect;
952 }
953
954 RoundedRect RenderStyle::getRoundedInnerBorderFor(const LayoutRect& borderRect, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
955 {
956     bool horizontal = isHorizontalWritingMode();
957
958     LayoutUnit leftWidth = (!horizontal || includeLogicalLeftEdge) ? borderLeftWidth() : 0;
959     LayoutUnit rightWidth = (!horizontal || includeLogicalRightEdge) ? borderRightWidth() : 0;
960     LayoutUnit topWidth = (horizontal || includeLogicalLeftEdge) ? borderTopWidth() : 0;
961     LayoutUnit bottomWidth = (horizontal || includeLogicalRightEdge) ? borderBottomWidth() : 0;
962
963     return getRoundedInnerBorderFor(borderRect, topWidth, bottomWidth, leftWidth, rightWidth, includeLogicalLeftEdge, includeLogicalRightEdge);
964 }
965
966 RoundedRect RenderStyle::getRoundedInnerBorderFor(const LayoutRect& borderRect,
967     LayoutUnit topWidth, LayoutUnit bottomWidth, LayoutUnit leftWidth, LayoutUnit rightWidth, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
968 {
969     LayoutRect innerRect(borderRect.x() + leftWidth, 
970                borderRect.y() + topWidth, 
971                borderRect.width() - leftWidth - rightWidth, 
972                borderRect.height() - topWidth - bottomWidth);
973
974     RoundedRect roundedRect(pixelSnappedIntRect(innerRect));
975
976     if (hasBorderRadius()) {
977         RoundedRect::Radii radii = getRoundedBorderFor(borderRect).radii();
978         radii.shrink(topWidth, bottomWidth, leftWidth, rightWidth);
979         roundedRect.includeLogicalEdges(radii, isHorizontalWritingMode(), includeLogicalLeftEdge, includeLogicalRightEdge);
980     }
981     return roundedRect;
982 }
983
984 const CounterDirectiveMap* RenderStyle::counterDirectives() const
985 {
986     return rareNonInheritedData->m_counterDirectives.get();
987 }
988
989 CounterDirectiveMap& RenderStyle::accessCounterDirectives()
990 {
991     OwnPtr<CounterDirectiveMap>& map = rareNonInheritedData.access()->m_counterDirectives;
992     if (!map)
993         map = adoptPtr(new CounterDirectiveMap);
994     return *map;
995 }
996
997 const AtomicString& RenderStyle::hyphenString() const
998 {
999     ASSERT(hyphens() != HyphensNone);
1000
1001     const AtomicString& hyphenationString = rareInheritedData.get()->hyphenationString;
1002     if (!hyphenationString.isNull())
1003         return hyphenationString;
1004
1005     // FIXME: This should depend on locale.
1006     DEFINE_STATIC_LOCAL(AtomicString, hyphenMinusString, (&hyphenMinus, 1));
1007     DEFINE_STATIC_LOCAL(AtomicString, hyphenString, (&hyphen, 1));
1008     return font().primaryFontHasGlyphForCharacter(hyphen) ? hyphenString : hyphenMinusString;
1009 }
1010
1011 const AtomicString& RenderStyle::textEmphasisMarkString() const
1012 {
1013     switch (textEmphasisMark()) {
1014     case TextEmphasisMarkNone:
1015         return nullAtom;
1016     case TextEmphasisMarkCustom:
1017         return textEmphasisCustomMark();
1018     case TextEmphasisMarkDot: {
1019         DEFINE_STATIC_LOCAL(AtomicString, filledDotString, (&bullet, 1));
1020         DEFINE_STATIC_LOCAL(AtomicString, openDotString, (&whiteBullet, 1));
1021         return textEmphasisFill() == TextEmphasisFillFilled ? filledDotString : openDotString;
1022     }
1023     case TextEmphasisMarkCircle: {
1024         DEFINE_STATIC_LOCAL(AtomicString, filledCircleString, (&blackCircle, 1));
1025         DEFINE_STATIC_LOCAL(AtomicString, openCircleString, (&whiteCircle, 1));
1026         return textEmphasisFill() == TextEmphasisFillFilled ? filledCircleString : openCircleString;
1027     }
1028     case TextEmphasisMarkDoubleCircle: {
1029         DEFINE_STATIC_LOCAL(AtomicString, filledDoubleCircleString, (&fisheye, 1));
1030         DEFINE_STATIC_LOCAL(AtomicString, openDoubleCircleString, (&bullseye, 1));
1031         return textEmphasisFill() == TextEmphasisFillFilled ? filledDoubleCircleString : openDoubleCircleString;
1032     }
1033     case TextEmphasisMarkTriangle: {
1034         DEFINE_STATIC_LOCAL(AtomicString, filledTriangleString, (&blackUpPointingTriangle, 1));
1035         DEFINE_STATIC_LOCAL(AtomicString, openTriangleString, (&whiteUpPointingTriangle, 1));
1036         return textEmphasisFill() == TextEmphasisFillFilled ? filledTriangleString : openTriangleString;
1037     }
1038     case TextEmphasisMarkSesame: {
1039         DEFINE_STATIC_LOCAL(AtomicString, filledSesameString, (&sesameDot, 1));
1040         DEFINE_STATIC_LOCAL(AtomicString, openSesameString, (&whiteSesameDot, 1));
1041         return textEmphasisFill() == TextEmphasisFillFilled ? filledSesameString : openSesameString;
1042     }
1043     case TextEmphasisMarkAuto:
1044         ASSERT_NOT_REACHED();
1045         return nullAtom;
1046     }
1047
1048     ASSERT_NOT_REACHED();
1049     return nullAtom;
1050 }
1051
1052 #if ENABLE(DASHBOARD_SUPPORT)
1053 const Vector<StyleDashboardRegion>& RenderStyle::initialDashboardRegions()
1054 {
1055     DEFINE_STATIC_LOCAL(Vector<StyleDashboardRegion>, emptyList, ());
1056     return emptyList;
1057 }
1058
1059 const Vector<StyleDashboardRegion>& RenderStyle::noneDashboardRegions()
1060 {
1061     DEFINE_STATIC_LOCAL(Vector<StyleDashboardRegion>, noneList, ());
1062     static bool noneListInitialized = false;
1063
1064     if (!noneListInitialized) {
1065         StyleDashboardRegion region;
1066         region.label = "";
1067         region.offset.m_top  = Length();
1068         region.offset.m_right = Length();
1069         region.offset.m_bottom = Length();
1070         region.offset.m_left = Length();
1071         region.type = StyleDashboardRegion::None;
1072         noneList.append(region);
1073         noneListInitialized = true;
1074     }
1075     return noneList;
1076 }
1077 #endif
1078
1079 void RenderStyle::adjustAnimations()
1080 {
1081     AnimationList* animationList = rareNonInheritedData->m_animations.get();
1082     if (!animationList)
1083         return;
1084
1085     // Get rid of empty animations and anything beyond them
1086     for (size_t i = 0; i < animationList->size(); ++i) {
1087         if (animationList->animation(i)->isEmpty()) {
1088             animationList->resize(i);
1089             break;
1090         }
1091     }
1092
1093     if (animationList->isEmpty()) {
1094         clearAnimations();
1095         return;
1096     }
1097
1098     // Repeat patterns into layers that don't have some properties set.
1099     animationList->fillUnsetProperties();
1100 }
1101
1102 void RenderStyle::adjustTransitions()
1103 {
1104     AnimationList* transitionList = rareNonInheritedData->m_transitions.get();
1105     if (!transitionList)
1106         return;
1107
1108     // Get rid of empty transitions and anything beyond them
1109     for (size_t i = 0; i < transitionList->size(); ++i) {
1110         if (transitionList->animation(i)->isEmpty()) {
1111             transitionList->resize(i);
1112             break;
1113         }
1114     }
1115
1116     if (transitionList->isEmpty()) {
1117         clearTransitions();
1118         return;
1119     }
1120
1121     // Repeat patterns into layers that don't have some properties set.
1122     transitionList->fillUnsetProperties();
1123
1124     // Make sure there are no duplicate properties. This is an O(n^2) algorithm
1125     // but the lists tend to be very short, so it is probably ok
1126     for (size_t i = 0; i < transitionList->size(); ++i) {
1127         for (size_t j = i+1; j < transitionList->size(); ++j) {
1128             if (transitionList->animation(i)->property() == transitionList->animation(j)->property()) {
1129                 // toss i
1130                 transitionList->remove(i);
1131                 j = i;
1132             }
1133         }
1134     }
1135 }
1136
1137 AnimationList* RenderStyle::accessAnimations()
1138 {
1139     if (!rareNonInheritedData.access()->m_animations)
1140         rareNonInheritedData.access()->m_animations = adoptPtr(new AnimationList());
1141     return rareNonInheritedData->m_animations.get();
1142 }
1143
1144 AnimationList* RenderStyle::accessTransitions()
1145 {
1146     if (!rareNonInheritedData.access()->m_transitions)
1147         rareNonInheritedData.access()->m_transitions = adoptPtr(new AnimationList());
1148     return rareNonInheritedData->m_transitions.get();
1149 }
1150
1151 const Animation* RenderStyle::transitionForProperty(CSSPropertyID property) const
1152 {
1153     if (transitions()) {
1154         for (size_t i = 0; i < transitions()->size(); ++i) {
1155             const Animation* p = transitions()->animation(i);
1156             if (p->animationMode() == Animation::AnimateAll || p->property() == property) {
1157                 return p;
1158             }
1159         }
1160     }
1161     return 0;
1162 }
1163
1164 void RenderStyle::setBlendedFontSize(int size)
1165 {
1166     FontSelector* currentFontSelector = font().fontSelector();
1167     FontDescription desc(fontDescription());
1168     desc.setSpecifiedSize(size);
1169     desc.setComputedSize(size);
1170     setFontDescription(desc);
1171     font().update(currentFontSelector);
1172 }
1173
1174 void RenderStyle::getShadowExtent(const ShadowData* shadow, LayoutUnit &top, LayoutUnit &right, LayoutUnit &bottom, LayoutUnit &left) const
1175 {
1176     top = 0;
1177     right = 0;
1178     bottom = 0;
1179     left = 0;
1180
1181     for ( ; shadow; shadow = shadow->next()) {
1182         if (shadow->style() == Inset)
1183             continue;
1184         int blurAndSpread = shadow->blur() + shadow->spread();
1185
1186         top = min<LayoutUnit>(top, shadow->y() - blurAndSpread);
1187         right = max<LayoutUnit>(right, shadow->x() + blurAndSpread);
1188         bottom = max<LayoutUnit>(bottom, shadow->y() + blurAndSpread);
1189         left = min<LayoutUnit>(left, shadow->x() - blurAndSpread);
1190     }
1191 }
1192
1193 void RenderStyle::getShadowHorizontalExtent(const ShadowData* shadow, LayoutUnit &left, LayoutUnit &right) const
1194 {
1195     left = 0;
1196     right = 0;
1197
1198     for ( ; shadow; shadow = shadow->next()) {
1199         if (shadow->style() == Inset)
1200             continue;
1201         int blurAndSpread = shadow->blur() + shadow->spread();
1202
1203         left = min<LayoutUnit>(left, shadow->x() - blurAndSpread);
1204         right = max<LayoutUnit>(right, shadow->x() + blurAndSpread);
1205     }
1206 }
1207
1208 void RenderStyle::getShadowVerticalExtent(const ShadowData* shadow, LayoutUnit &top, LayoutUnit &bottom) const
1209 {
1210     top = 0;
1211     bottom = 0;
1212
1213     for ( ; shadow; shadow = shadow->next()) {
1214         if (shadow->style() == Inset)
1215             continue;
1216         int blurAndSpread = shadow->blur() + shadow->spread();
1217
1218         top = min<LayoutUnit>(top, shadow->y() - blurAndSpread);
1219         bottom = max<LayoutUnit>(bottom, shadow->y() + blurAndSpread);
1220     }
1221 }
1222
1223 Color RenderStyle::colorIncludingFallback(int colorProperty, bool visitedLink) const
1224 {
1225     Color result;
1226     EBorderStyle borderStyle = BNONE;
1227     switch (colorProperty) {
1228     case CSSPropertyBackgroundColor:
1229         return visitedLink ? rareNonInheritedData->m_visitedLinkBackgroundColor : backgroundColor(); // Background color doesn't fall back.
1230     case CSSPropertyBorderLeftColor:
1231         result = visitedLink ? rareNonInheritedData->m_visitedLinkBorderLeftColor : borderLeftColor();
1232         borderStyle = borderLeftStyle();
1233         break;
1234     case CSSPropertyBorderRightColor:
1235         result = visitedLink ? rareNonInheritedData->m_visitedLinkBorderRightColor : borderRightColor();
1236         borderStyle = borderRightStyle();
1237         break;
1238     case CSSPropertyBorderTopColor:
1239         result = visitedLink ? rareNonInheritedData->m_visitedLinkBorderTopColor : borderTopColor();
1240         borderStyle = borderTopStyle();
1241         break;
1242     case CSSPropertyBorderBottomColor:
1243         result = visitedLink ? rareNonInheritedData->m_visitedLinkBorderBottomColor : borderBottomColor();
1244         borderStyle = borderBottomStyle();
1245         break;
1246     case CSSPropertyColor:
1247         result = visitedLink ? inherited->visitedLinkColor : color();
1248         break;
1249     case CSSPropertyOutlineColor:
1250         result = visitedLink ? rareNonInheritedData->m_visitedLinkOutlineColor : outlineColor();
1251         break;
1252     case CSSPropertyWebkitColumnRuleColor:
1253         result = visitedLink ? rareNonInheritedData->m_multiCol->m_visitedLinkColumnRuleColor : columnRuleColor();
1254         break;
1255     case CSSPropertyWebkitTextEmphasisColor:
1256         result = visitedLink ? rareInheritedData->visitedLinkTextEmphasisColor : textEmphasisColor();
1257         break;
1258     case CSSPropertyWebkitTextFillColor:
1259         result = visitedLink ? rareInheritedData->visitedLinkTextFillColor : textFillColor();
1260         break;
1261     case CSSPropertyWebkitTextStrokeColor:
1262         result = visitedLink ? rareInheritedData->visitedLinkTextStrokeColor : textStrokeColor();
1263         break;
1264     default:
1265         ASSERT_NOT_REACHED();
1266         break;
1267     }
1268
1269     if (!result.isValid()) {
1270         if (!visitedLink && (borderStyle == INSET || borderStyle == OUTSET || borderStyle == RIDGE || borderStyle == GROOVE))
1271             result.setRGB(238, 238, 238);
1272         else
1273             result = visitedLink ? inherited->visitedLinkColor : color();
1274     }
1275     return result;
1276 }
1277
1278 Color RenderStyle::visitedDependentColor(int colorProperty) const
1279 {
1280     Color unvisitedColor = colorIncludingFallback(colorProperty, false);
1281     if (insideLink() != InsideVisitedLink)
1282         return unvisitedColor;
1283
1284     Color visitedColor = colorIncludingFallback(colorProperty, true);
1285
1286     // FIXME: Technically someone could explicitly specify the color transparent, but for now we'll just
1287     // assume that if the background color is transparent that it wasn't set. Note that it's weird that
1288     // we're returning unvisited info for a visited link, but given our restriction that the alpha values
1289     // have to match, it makes more sense to return the unvisited background color if specified than it
1290     // does to return black. This behavior matches what Firefox 4 does as well.
1291     if (colorProperty == CSSPropertyBackgroundColor && visitedColor == Color::transparent)
1292         return unvisitedColor;
1293
1294     // Take the alpha from the unvisited color, but get the RGB values from the visited color.
1295     return Color(visitedColor.red(), visitedColor.green(), visitedColor.blue(), unvisitedColor.alpha());
1296 }
1297
1298 Length RenderStyle::logicalWidth() const
1299 {
1300     if (isHorizontalWritingMode())
1301         return width();
1302     return height();
1303 }
1304
1305 Length RenderStyle::logicalHeight() const
1306 {
1307     if (isHorizontalWritingMode())
1308         return height();
1309     return width();
1310 }
1311
1312 Length RenderStyle::logicalMinWidth() const
1313 {
1314     if (isHorizontalWritingMode())
1315         return minWidth();
1316     return minHeight();
1317 }
1318
1319 Length RenderStyle::logicalMaxWidth() const
1320 {
1321     if (isHorizontalWritingMode())
1322         return maxWidth();
1323     return maxHeight();
1324 }
1325
1326 Length RenderStyle::logicalMinHeight() const
1327 {
1328     if (isHorizontalWritingMode())
1329         return minHeight();
1330     return minWidth();
1331 }
1332
1333 Length RenderStyle::logicalMaxHeight() const
1334 {
1335     if (isHorizontalWritingMode())
1336         return maxHeight();
1337     return maxWidth();
1338 }
1339
1340 const BorderValue& RenderStyle::borderBefore() const
1341 {
1342     switch (writingMode()) {
1343     case TopToBottomWritingMode:
1344         return borderTop();
1345     case BottomToTopWritingMode:
1346         return borderBottom();
1347     case LeftToRightWritingMode:
1348         return borderLeft();
1349     case RightToLeftWritingMode:
1350         return borderRight();
1351     }
1352     ASSERT_NOT_REACHED();
1353     return borderTop();
1354 }
1355
1356 const BorderValue& RenderStyle::borderAfter() const
1357 {
1358     switch (writingMode()) {
1359     case TopToBottomWritingMode:
1360         return borderBottom();
1361     case BottomToTopWritingMode:
1362         return borderTop();
1363     case LeftToRightWritingMode:
1364         return borderRight();
1365     case RightToLeftWritingMode:
1366         return borderLeft();
1367     }
1368     ASSERT_NOT_REACHED();
1369     return borderBottom();
1370 }
1371
1372 const BorderValue& RenderStyle::borderStart() const
1373 {
1374     if (isHorizontalWritingMode())
1375         return isLeftToRightDirection() ? borderLeft() : borderRight();
1376     return isLeftToRightDirection() ? borderTop() : borderBottom();
1377 }
1378
1379 const BorderValue& RenderStyle::borderEnd() const
1380 {
1381     if (isHorizontalWritingMode())
1382         return isLeftToRightDirection() ? borderRight() : borderLeft();
1383     return isLeftToRightDirection() ? borderBottom() : borderTop();
1384 }
1385
1386 unsigned short RenderStyle::borderBeforeWidth() const
1387 {
1388     switch (writingMode()) {
1389     case TopToBottomWritingMode:
1390         return borderTopWidth();
1391     case BottomToTopWritingMode:
1392         return borderBottomWidth();
1393     case LeftToRightWritingMode:
1394         return borderLeftWidth();
1395     case RightToLeftWritingMode:
1396         return borderRightWidth();
1397     }
1398     ASSERT_NOT_REACHED();
1399     return borderTopWidth();
1400 }
1401
1402 unsigned short RenderStyle::borderAfterWidth() const
1403 {
1404     switch (writingMode()) {
1405     case TopToBottomWritingMode:
1406         return borderBottomWidth();
1407     case BottomToTopWritingMode:
1408         return borderTopWidth();
1409     case LeftToRightWritingMode:
1410         return borderRightWidth();
1411     case RightToLeftWritingMode:
1412         return borderLeftWidth();
1413     }
1414     ASSERT_NOT_REACHED();
1415     return borderBottomWidth();
1416 }
1417
1418 unsigned short RenderStyle::borderStartWidth() const
1419 {
1420     if (isHorizontalWritingMode())
1421         return isLeftToRightDirection() ? borderLeftWidth() : borderRightWidth();
1422     return isLeftToRightDirection() ? borderTopWidth() : borderBottomWidth();
1423 }
1424
1425 unsigned short RenderStyle::borderEndWidth() const
1426 {
1427     if (isHorizontalWritingMode())
1428         return isLeftToRightDirection() ? borderRightWidth() : borderLeftWidth();
1429     return isLeftToRightDirection() ? borderBottomWidth() : borderTopWidth();
1430 }
1431
1432 void RenderStyle::setMarginStart(Length margin)
1433 {
1434     if (isHorizontalWritingMode()) {
1435         if (isLeftToRightDirection())
1436             setMarginLeft(margin);
1437         else
1438             setMarginRight(margin);
1439     } else {
1440         if (isLeftToRightDirection())
1441             setMarginTop(margin);
1442         else
1443             setMarginBottom(margin);
1444     }
1445 }
1446
1447 void RenderStyle::setMarginEnd(Length margin)
1448 {
1449     if (isHorizontalWritingMode()) {
1450         if (isLeftToRightDirection())
1451             setMarginRight(margin);
1452         else
1453             setMarginLeft(margin);
1454     } else {
1455         if (isLeftToRightDirection())
1456             setMarginBottom(margin);
1457         else
1458             setMarginTop(margin);
1459     }
1460 }
1461
1462 TextEmphasisMark RenderStyle::textEmphasisMark() const
1463 {
1464     TextEmphasisMark mark = static_cast<TextEmphasisMark>(rareInheritedData->textEmphasisMark);
1465     if (mark != TextEmphasisMarkAuto)
1466         return mark;
1467
1468     if (isHorizontalWritingMode())
1469         return TextEmphasisMarkDot;
1470
1471     return TextEmphasisMarkSesame;
1472 }
1473
1474 #if ENABLE(TOUCH_EVENTS)
1475 Color RenderStyle::initialTapHighlightColor()
1476 {
1477     return RenderTheme::tapHighlightColor();
1478 }
1479 #endif
1480
1481 LayoutBoxExtent RenderStyle::imageOutsets(const NinePieceImage& image) const
1482 {
1483     return LayoutBoxExtent(NinePieceImage::computeOutset(image.outset().top(), borderTopWidth()),
1484                            NinePieceImage::computeOutset(image.outset().right(), borderRightWidth()),
1485                            NinePieceImage::computeOutset(image.outset().bottom(), borderBottomWidth()),
1486                            NinePieceImage::computeOutset(image.outset().left(), borderLeftWidth()));
1487 }
1488
1489 } // namespace WebCore