Source/WebCore: parse CSS attribute -webkit-blend-mode
[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 "FontSelector.h"
30 #include "MemoryInstrumentation.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) || ENABLE(WIDGET_REGION)
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 ENABLE(TEXT_AUTOSIZING)
492     if (visual->m_textAutosizingMultiplier != other->visual->m_textAutosizingMultiplier)
493         return StyleDifferenceLayout;
494 #endif
495
496     if (inherited->line_height != other->inherited->line_height
497         || inherited->list_style_image != other->inherited->list_style_image
498         || inherited->font != other->inherited->font
499         || inherited->horizontal_border_spacing != other->inherited->horizontal_border_spacing
500         || inherited->vertical_border_spacing != other->inherited->vertical_border_spacing
501         || inherited_flags._box_direction != other->inherited_flags._box_direction
502         || inherited_flags.m_rtlOrdering != other->inherited_flags.m_rtlOrdering
503         || noninherited_flags._position != other->noninherited_flags._position
504         || noninherited_flags._floating != other->noninherited_flags._floating
505         || noninherited_flags._originalDisplay != other->noninherited_flags._originalDisplay)
506         return StyleDifferenceLayout;
507
508
509     if (((int)noninherited_flags._effectiveDisplay) >= TABLE) {
510         if (inherited_flags._border_collapse != other->inherited_flags._border_collapse
511             || inherited_flags._empty_cells != other->inherited_flags._empty_cells
512             || inherited_flags._caption_side != other->inherited_flags._caption_side
513             || noninherited_flags._table_layout != other->noninherited_flags._table_layout)
514             return StyleDifferenceLayout;
515
516         // In the collapsing border model, 'hidden' suppresses other borders, while 'none'
517         // does not, so these style differences can be width differences.
518         if (inherited_flags._border_collapse
519             && ((borderTopStyle() == BHIDDEN && other->borderTopStyle() == BNONE)
520                 || (borderTopStyle() == BNONE && other->borderTopStyle() == BHIDDEN)
521                 || (borderBottomStyle() == BHIDDEN && other->borderBottomStyle() == BNONE)
522                 || (borderBottomStyle() == BNONE && other->borderBottomStyle() == BHIDDEN)
523                 || (borderLeftStyle() == BHIDDEN && other->borderLeftStyle() == BNONE)
524                 || (borderLeftStyle() == BNONE && other->borderLeftStyle() == BHIDDEN)
525                 || (borderRightStyle() == BHIDDEN && other->borderRightStyle() == BNONE)
526                 || (borderRightStyle() == BNONE && other->borderRightStyle() == BHIDDEN)))
527             return StyleDifferenceLayout;
528     }
529
530     if (noninherited_flags._effectiveDisplay == LIST_ITEM) {
531         if (inherited_flags._list_style_type != other->inherited_flags._list_style_type
532             || inherited_flags._list_style_position != other->inherited_flags._list_style_position)
533             return StyleDifferenceLayout;
534     }
535
536     if (inherited_flags._text_align != other->inherited_flags._text_align
537         || inherited_flags._text_transform != other->inherited_flags._text_transform
538         || inherited_flags._direction != other->inherited_flags._direction
539         || inherited_flags._white_space != other->inherited_flags._white_space
540         || noninherited_flags._clear != other->noninherited_flags._clear
541         || noninherited_flags._unicodeBidi != other->noninherited_flags._unicodeBidi)
542         return StyleDifferenceLayout;
543
544     // Check block flow direction.
545     if (inherited_flags.m_writingMode != other->inherited_flags.m_writingMode)
546         return StyleDifferenceLayout;
547
548     // Check text combine mode.
549     if (rareNonInheritedData->m_textCombine != other->rareNonInheritedData->m_textCombine)
550         return StyleDifferenceLayout;
551
552     // Overflow returns a layout hint.
553     if (noninherited_flags._overflowX != other->noninherited_flags._overflowX
554         || noninherited_flags._overflowY != other->noninherited_flags._overflowY)
555         return StyleDifferenceLayout;
556
557     // If our border widths change, then we need to layout.  Other changes to borders
558     // only necessitate a repaint.
559     if (borderLeftWidth() != other->borderLeftWidth()
560         || borderTopWidth() != other->borderTopWidth()
561         || borderBottomWidth() != other->borderBottomWidth()
562         || borderRightWidth() != other->borderRightWidth())
563         return StyleDifferenceLayout;
564
565     // If the counter directives change, trigger a relayout to re-calculate counter values and rebuild the counter node tree.
566     const CounterDirectiveMap* mapA = rareNonInheritedData->m_counterDirectives.get();
567     const CounterDirectiveMap* mapB = other->rareNonInheritedData->m_counterDirectives.get();
568     if (!(mapA == mapB || (mapA && mapB && *mapA == *mapB)))
569         return StyleDifferenceLayout;
570     if (rareNonInheritedData->m_counterIncrement != other->rareNonInheritedData->m_counterIncrement
571         || rareNonInheritedData->m_counterReset != other->rareNonInheritedData->m_counterReset)
572         return StyleDifferenceLayout;
573
574     if ((visibility() == COLLAPSE) != (other->visibility() == COLLAPSE))
575         return StyleDifferenceLayout;
576
577     if ((rareNonInheritedData->opacity == 1 && other->rareNonInheritedData->opacity < 1)
578         || (rareNonInheritedData->opacity < 1 && other->rareNonInheritedData->opacity == 1)) {
579         // FIXME: We would like to use SimplifiedLayout here, but we can't quite do that yet.
580         // We need to make sure SimplifiedLayout can operate correctly on RenderInlines (we will need
581         // to add a selfNeedsSimplifiedLayout bit in order to not get confused and taint every line).
582         // In addition we need to solve the floating object issue when layers come and go. Right now
583         // a full layout is necessary to keep floating object lists sane.
584         return StyleDifferenceLayout;
585     }
586
587     if (!QuotesData::equals(rareInheritedData->quotes.get(), other->rareInheritedData->quotes.get()))
588         return StyleDifferenceLayout;
589
590 #if ENABLE(SVG)
591     // SVGRenderStyle::diff() might have returned StyleDifferenceRepaint, eg. if fill changes.
592     // If eg. the font-size changed at the same time, we're not allowed to return StyleDifferenceRepaint,
593     // but have to return StyleDifferenceLayout, that's why  this if branch comes after all branches
594     // that are relevant for SVG and might return StyleDifferenceLayout.
595     if (svgChange != StyleDifferenceEqual)
596         return svgChange;
597 #endif
598
599     // Make sure these left/top/right/bottom checks stay below all layout checks and above
600     // all visible checks.
601     if (position() != StaticPosition) {
602         if (surround->offset != other->surround->offset) {
603              // Optimize for the case where a positioned layer is moving but not changing size.
604             if (position() == AbsolutePosition && positionedObjectMoved(surround->offset, other->surround->offset))
605                 return StyleDifferenceLayoutPositionedMovementOnly;
606
607             // FIXME: We would like to use SimplifiedLayout for relative positioning, but we can't quite do that yet.
608             // We need to make sure SimplifiedLayout can operate correctly on RenderInlines (we will need
609             // to add a selfNeedsSimplifiedLayout bit in order to not get confused and taint every line).
610             return StyleDifferenceLayout;
611         } else if (m_box->zIndex() != other->m_box->zIndex() || m_box->hasAutoZIndex() != other->m_box->hasAutoZIndex()
612                  || visual->clip != other->visual->clip || visual->hasClip != other->visual->hasClip)
613             return StyleDifferenceRepaintLayer;
614     }
615     
616 #if ENABLE(CSS_COMPOSITING)
617     if (rareNonInheritedData->m_effectiveBlendMode != other->rareNonInheritedData->m_effectiveBlendMode)
618         return StyleDifferenceRepaintLayer;
619 #endif
620
621     if (rareNonInheritedData->opacity != other->rareNonInheritedData->opacity) {
622 #if USE(ACCELERATED_COMPOSITING)
623         changedContextSensitiveProperties |= ContextSensitivePropertyOpacity;
624         // Don't return; keep looking for another change.
625 #else
626         return StyleDifferenceRepaintLayer;
627 #endif
628     }
629
630 #if ENABLE(CSS_FILTERS)
631     if (rareNonInheritedData->m_filter.get() != other->rareNonInheritedData->m_filter.get()
632         && *rareNonInheritedData->m_filter.get() != *other->rareNonInheritedData->m_filter.get()) {
633 #if USE(ACCELERATED_COMPOSITING)
634         changedContextSensitiveProperties |= ContextSensitivePropertyFilter;
635         // Don't return; keep looking for another change.
636 #else
637         return StyleDifferenceRepaintLayer;
638 #endif
639     }
640 #endif
641
642     if (rareNonInheritedData->m_mask != other->rareNonInheritedData->m_mask
643         || rareNonInheritedData->m_maskBoxImage != other->rareNonInheritedData->m_maskBoxImage)
644         return StyleDifferenceRepaintLayer;
645
646     if (inherited->color != other->inherited->color
647         || inherited_flags._visibility != other->inherited_flags._visibility
648         || inherited_flags._text_decorations != other->inherited_flags._text_decorations
649         || inherited_flags.m_printColorAdjust != other->inherited_flags.m_printColorAdjust
650         || inherited_flags._insideLink != other->inherited_flags._insideLink
651         || surround->border != other->surround->border
652         || *m_background.get() != *other->m_background.get()
653         || visual->textDecoration != other->visual->textDecoration
654         || rareInheritedData->userModify != other->rareInheritedData->userModify
655         || rareInheritedData->userSelect != other->rareInheritedData->userSelect
656         || rareNonInheritedData->userDrag != other->rareNonInheritedData->userDrag
657         || rareNonInheritedData->m_borderFit != other->rareNonInheritedData->m_borderFit
658 #if ENABLE(CSS3_TEXT_DECORATION)
659         || rareNonInheritedData->m_textDecorationStyle != other->rareNonInheritedData->m_textDecorationStyle
660 #endif // CSS3_TEXT_DECORATION
661         || rareInheritedData->textFillColor != other->rareInheritedData->textFillColor
662         || rareInheritedData->textStrokeColor != other->rareInheritedData->textStrokeColor
663         || rareInheritedData->textEmphasisColor != other->rareInheritedData->textEmphasisColor
664         || rareInheritedData->textEmphasisFill != other->rareInheritedData->textEmphasisFill
665         || rareInheritedData->m_imageRendering != other->rareInheritedData->m_imageRendering)
666         return StyleDifferenceRepaint;
667         
668         // FIXME: The current spec is being reworked to remove dependencies between exclusions and affected 
669         // content. There's a proposal to use floats instead. In that case, wrap-shape should actually relayout 
670         // the parent container. For sure, I will have to revisit this code, but for now I've added this in order 
671         // to avoid having diff() == StyleDifferenceEqual where wrap-shapes actually differ.
672         // Tracking bug: https://bugs.webkit.org/show_bug.cgi?id=62991
673         if (rareNonInheritedData->m_wrapShapeInside != other->rareNonInheritedData->m_wrapShapeInside
674             || rareNonInheritedData->m_wrapShapeOutside != other->rareNonInheritedData->m_wrapShapeOutside)
675             return StyleDifferenceRepaint;
676
677 #if USE(ACCELERATED_COMPOSITING)
678     if (rareNonInheritedData.get() != other->rareNonInheritedData.get()) {
679         if (rareNonInheritedData->m_transformStyle3D != other->rareNonInheritedData->m_transformStyle3D
680             || rareNonInheritedData->m_backfaceVisibility != other->rareNonInheritedData->m_backfaceVisibility
681             || rareNonInheritedData->m_perspective != other->rareNonInheritedData->m_perspective
682             || rareNonInheritedData->m_perspectiveOriginX != other->rareNonInheritedData->m_perspectiveOriginX
683             || rareNonInheritedData->m_perspectiveOriginY != other->rareNonInheritedData->m_perspectiveOriginY)
684             return StyleDifferenceRecompositeLayer;
685     }
686 #endif
687
688     // Cursors are not checked, since they will be set appropriately in response to mouse events,
689     // so they don't need to cause any repaint or layout.
690
691     // 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
692     // the resulting transition properly.
693     return StyleDifferenceEqual;
694 }
695
696 void RenderStyle::setClip(Length top, Length right, Length bottom, Length left)
697 {
698     StyleVisualData* data = visual.access();
699     data->clip.m_top = top;
700     data->clip.m_right = right;
701     data->clip.m_bottom = bottom;
702     data->clip.m_left = left;
703 }
704
705 void RenderStyle::addCursor(PassRefPtr<StyleImage> image, const IntPoint& hotSpot)
706 {
707     if (!rareInheritedData.access()->cursorData)
708         rareInheritedData.access()->cursorData = CursorList::create();
709     rareInheritedData.access()->cursorData->append(CursorData(image, hotSpot));
710 }
711
712 void RenderStyle::setCursorList(PassRefPtr<CursorList> other)
713 {
714     rareInheritedData.access()->cursorData = other;
715 }
716
717 void RenderStyle::setQuotes(PassRefPtr<QuotesData> q)
718 {
719     if (QuotesData::equals(rareInheritedData->quotes.get(), q.get()))
720         return;
721     rareInheritedData.access()->quotes = q;
722 }
723
724 void RenderStyle::clearCursorList()
725 {
726     if (rareInheritedData->cursorData)
727         rareInheritedData.access()->cursorData = 0;
728 }
729
730 void RenderStyle::clearContent()
731 {
732     if (rareNonInheritedData->m_content)
733         rareNonInheritedData.access()->m_content = nullptr;
734 }
735
736 void RenderStyle::appendContent(PassOwnPtr<ContentData> contentData)
737 {
738     OwnPtr<ContentData>& content = rareNonInheritedData.access()->m_content;
739     ContentData* lastContent = content.get();
740     while (lastContent && lastContent->next())
741         lastContent = lastContent->next();
742
743     if (lastContent)
744         lastContent->setNext(contentData);
745     else
746         content = contentData;
747 }
748
749 void RenderStyle::setContent(PassRefPtr<StyleImage> image, bool add)
750 {
751     if (!image)
752         return;
753         
754     if (add) {
755         appendContent(ContentData::create(image));
756         return;
757     }
758
759     rareNonInheritedData.access()->m_content = ContentData::create(image);
760 }
761
762 void RenderStyle::setContent(const String& string, bool add)
763 {
764     OwnPtr<ContentData>& content = rareNonInheritedData.access()->m_content;
765     if (add) {
766         ContentData* lastContent = content.get();
767         while (lastContent && lastContent->next())
768             lastContent = lastContent->next();
769
770         if (lastContent) {
771             // We attempt to merge with the last ContentData if possible.
772             if (lastContent->isText()) {
773                 TextContentData* textContent = static_cast<TextContentData*>(lastContent);
774                 String text = textContent->text();
775                 text += string;
776                 textContent->setText(text);
777             } else
778                 lastContent->setNext(ContentData::create(string));
779
780             return;
781         }
782     }
783
784     content = ContentData::create(string);
785 }
786
787 void RenderStyle::setContent(PassOwnPtr<CounterContent> counter, bool add)
788 {
789     if (!counter)
790         return;
791
792     if (add) {
793         appendContent(ContentData::create(counter));
794         return;
795     }
796
797     rareNonInheritedData.access()->m_content = ContentData::create(counter);
798 }
799
800 void RenderStyle::setContent(QuoteType quote, bool add)
801 {
802     if (add) {
803         appendContent(ContentData::create(quote));
804         return;
805     }
806
807     rareNonInheritedData.access()->m_content = ContentData::create(quote);
808 }
809     
810 inline bool requireTransformOrigin(const Vector<RefPtr<TransformOperation> >& transformOperations, RenderStyle::ApplyTransformOrigin applyOrigin)
811 {
812     // transform-origin brackets the transform with translate operations.
813     // Optimize for the case where the only transform is a translation, since the transform-origin is irrelevant
814     // in that case.
815     if (applyOrigin != RenderStyle::IncludeTransformOrigin)
816         return false;
817
818     unsigned size = transformOperations.size();
819     for (unsigned i = 0; i < size; ++i) {
820         TransformOperation::OperationType type = transformOperations[i]->getOperationType();
821         if (type != TransformOperation::TRANSLATE_X
822             && type != TransformOperation::TRANSLATE_Y
823             && type != TransformOperation::TRANSLATE 
824             && type != TransformOperation::TRANSLATE_Z
825             && type != TransformOperation::TRANSLATE_3D)
826             return true;
827     }
828     
829     return false;
830 }
831
832 void RenderStyle::applyTransform(TransformationMatrix& transform, const LayoutSize& borderBoxSize, ApplyTransformOrigin applyOrigin) const
833 {
834     // FIXME: when subpixel layout is supported (bug 71143) the body of this function could be replaced by
835     // applyTransform(transform, FloatRect(FloatPoint(), borderBoxSize), applyOrigin);
836     
837     const Vector<RefPtr<TransformOperation> >& transformOperations = rareNonInheritedData->m_transform->m_operations.operations();
838     bool applyTransformOrigin = requireTransformOrigin(transformOperations, applyOrigin);
839
840     if (applyTransformOrigin)
841         transform.translate3d(floatValueForLength(transformOriginX(), borderBoxSize.width()), floatValueForLength(transformOriginY(), borderBoxSize.height()), transformOriginZ());
842
843     unsigned size = transformOperations.size();
844     for (unsigned i = 0; i < size; ++i)
845         transformOperations[i]->apply(transform, borderBoxSize);
846
847     if (applyTransformOrigin)
848         transform.translate3d(-floatValueForLength(transformOriginX(), borderBoxSize.width()), -floatValueForLength(transformOriginY(), borderBoxSize.height()), -transformOriginZ()); 
849 }
850
851 void RenderStyle::applyTransform(TransformationMatrix& transform, const FloatRect& boundingBox, ApplyTransformOrigin applyOrigin) const
852 {
853     const Vector<RefPtr<TransformOperation> >& transformOperations = rareNonInheritedData->m_transform->m_operations.operations();
854     bool applyTransformOrigin = requireTransformOrigin(transformOperations, applyOrigin);
855     
856     float offsetX = transformOriginX().type() == Percent ? boundingBox.x() : 0;
857     float offsetY = transformOriginY().type() == Percent ? boundingBox.y() : 0;
858     
859     if (applyTransformOrigin) {
860         transform.translate3d(floatValueForLength(transformOriginX(), boundingBox.width()) + offsetX,
861                               floatValueForLength(transformOriginY(), boundingBox.height()) + offsetY,
862                               transformOriginZ());
863     }
864     
865     unsigned size = transformOperations.size();
866     for (unsigned i = 0; i < size; ++i)
867         transformOperations[i]->apply(transform, boundingBox.size());
868     
869     if (applyTransformOrigin) {
870         transform.translate3d(-floatValueForLength(transformOriginX(), boundingBox.width()) - offsetX,
871                               -floatValueForLength(transformOriginY(), boundingBox.height()) - offsetY,
872                               -transformOriginZ());
873     }
874 }
875
876 void RenderStyle::setPageScaleTransform(float scale)
877 {
878     if (scale == 1)
879         return;
880     TransformOperations transform;
881     transform.operations().append(ScaleTransformOperation::create(scale, scale, ScaleTransformOperation::SCALE));
882     setTransform(transform);
883     setTransformOriginX(Length(0, Fixed));
884     setTransformOriginY(Length(0, Fixed));
885 }
886
887 void RenderStyle::setTextShadow(PassOwnPtr<ShadowData> shadowData, bool add)
888 {
889     ASSERT(!shadowData || (!shadowData->spread() && shadowData->style() == Normal));
890
891     StyleRareInheritedData* rareData = rareInheritedData.access();
892     if (!add) {
893         rareData->textShadow = shadowData;
894         return;
895     }
896
897     shadowData->setNext(rareData->textShadow.release());
898     rareData->textShadow = shadowData;
899 }
900
901 void RenderStyle::setBoxShadow(PassOwnPtr<ShadowData> shadowData, bool add)
902 {
903     StyleRareNonInheritedData* rareData = rareNonInheritedData.access();
904     if (!add) {
905         rareData->m_boxShadow = shadowData;
906         return;
907     }
908
909     shadowData->setNext(rareData->m_boxShadow.release());
910     rareData->m_boxShadow = shadowData;
911 }
912
913 static RoundedRect::Radii calcRadiiFor(const BorderData& border, IntSize size, RenderView* renderView)
914 {
915     return RoundedRect::Radii(
916         IntSize(valueForLength(border.topLeft().width(), size.width(), renderView), 
917                 valueForLength(border.topLeft().height(), size.height(), renderView)),
918         IntSize(valueForLength(border.topRight().width(), size.width(), renderView),
919                 valueForLength(border.topRight().height(), size.height(), renderView)),
920         IntSize(valueForLength(border.bottomLeft().width(), size.width(), renderView), 
921                 valueForLength(border.bottomLeft().height(), size.height(), renderView)),
922         IntSize(valueForLength(border.bottomRight().width(), size.width(), renderView), 
923                 valueForLength(border.bottomRight().height(), size.height(), renderView)));
924 }
925
926 static float calcConstraintScaleFor(const IntRect& rect, const RoundedRect::Radii& radii)
927 {
928     // Constrain corner radii using CSS3 rules:
929     // http://www.w3.org/TR/css3-background/#the-border-radius
930     
931     float factor = 1;
932     unsigned radiiSum;
933
934     // top
935     radiiSum = static_cast<unsigned>(radii.topLeft().width()) + static_cast<unsigned>(radii.topRight().width()); // Casts to avoid integer overflow.
936     if (radiiSum > static_cast<unsigned>(rect.width()))
937         factor = min(static_cast<float>(rect.width()) / radiiSum, factor);
938
939     // bottom
940     radiiSum = static_cast<unsigned>(radii.bottomLeft().width()) + static_cast<unsigned>(radii.bottomRight().width());
941     if (radiiSum > static_cast<unsigned>(rect.width()))
942         factor = min(static_cast<float>(rect.width()) / radiiSum, factor);
943     
944     // left
945     radiiSum = static_cast<unsigned>(radii.topLeft().height()) + static_cast<unsigned>(radii.bottomLeft().height());
946     if (radiiSum > static_cast<unsigned>(rect.height()))
947         factor = min(static_cast<float>(rect.height()) / radiiSum, factor);
948     
949     // right
950     radiiSum = static_cast<unsigned>(radii.topRight().height()) + static_cast<unsigned>(radii.bottomRight().height());
951     if (radiiSum > static_cast<unsigned>(rect.height()))
952         factor = min(static_cast<float>(rect.height()) / radiiSum, factor);
953     
954     ASSERT(factor <= 1);
955     return factor;
956 }
957
958 StyleImage* RenderStyle::listStyleImage() const { return inherited->list_style_image.get(); }
959 void RenderStyle::setListStyleImage(PassRefPtr<StyleImage> v)
960 {
961     if (inherited->list_style_image != v)
962         inherited.access()->list_style_image = v;
963 }
964
965 Color RenderStyle::color() const { return inherited->color; }
966 Color RenderStyle::visitedLinkColor() const { return inherited->visitedLinkColor; }
967 void RenderStyle::setColor(const Color& v) { SET_VAR(inherited, color, v) };
968 void RenderStyle::setVisitedLinkColor(const Color& v) { SET_VAR(inherited, visitedLinkColor, v) }
969
970 short RenderStyle::horizontalBorderSpacing() const { return inherited->horizontal_border_spacing; }
971 short RenderStyle::verticalBorderSpacing() const { return inherited->vertical_border_spacing; }
972 void RenderStyle::setHorizontalBorderSpacing(short v) { SET_VAR(inherited, horizontal_border_spacing, v) }
973 void RenderStyle::setVerticalBorderSpacing(short v) { SET_VAR(inherited, vertical_border_spacing, v) }
974
975 RoundedRect RenderStyle::getRoundedBorderFor(const LayoutRect& borderRect, RenderView* renderView, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
976 {
977     IntRect snappedBorderRect(pixelSnappedIntRect(borderRect));
978     RoundedRect roundedRect(snappedBorderRect);
979     if (hasBorderRadius()) {
980         RoundedRect::Radii radii = calcRadiiFor(surround->border, snappedBorderRect.size(), renderView);
981         radii.scale(calcConstraintScaleFor(snappedBorderRect, radii));
982         roundedRect.includeLogicalEdges(radii, isHorizontalWritingMode(), includeLogicalLeftEdge, includeLogicalRightEdge);
983     }
984     return roundedRect;
985 }
986
987 RoundedRect RenderStyle::getRoundedInnerBorderFor(const LayoutRect& borderRect, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
988 {
989     bool horizontal = isHorizontalWritingMode();
990
991     LayoutUnit leftWidth = (!horizontal || includeLogicalLeftEdge) ? borderLeftWidth() : 0;
992     LayoutUnit rightWidth = (!horizontal || includeLogicalRightEdge) ? borderRightWidth() : 0;
993     LayoutUnit topWidth = (horizontal || includeLogicalLeftEdge) ? borderTopWidth() : 0;
994     LayoutUnit bottomWidth = (horizontal || includeLogicalRightEdge) ? borderBottomWidth() : 0;
995
996     return getRoundedInnerBorderFor(borderRect, topWidth, bottomWidth, leftWidth, rightWidth, includeLogicalLeftEdge, includeLogicalRightEdge);
997 }
998
999 RoundedRect RenderStyle::getRoundedInnerBorderFor(const LayoutRect& borderRect,
1000     LayoutUnit topWidth, LayoutUnit bottomWidth, LayoutUnit leftWidth, LayoutUnit rightWidth, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
1001 {
1002     LayoutRect innerRect(borderRect.x() + leftWidth, 
1003                borderRect.y() + topWidth, 
1004                borderRect.width() - leftWidth - rightWidth, 
1005                borderRect.height() - topWidth - bottomWidth);
1006
1007     RoundedRect roundedRect(pixelSnappedIntRect(innerRect));
1008
1009     if (hasBorderRadius()) {
1010         RoundedRect::Radii radii = getRoundedBorderFor(borderRect).radii();
1011         radii.shrink(topWidth, bottomWidth, leftWidth, rightWidth);
1012         roundedRect.includeLogicalEdges(radii, isHorizontalWritingMode(), includeLogicalLeftEdge, includeLogicalRightEdge);
1013     }
1014     return roundedRect;
1015 }
1016
1017 const CounterDirectiveMap* RenderStyle::counterDirectives() const
1018 {
1019     return rareNonInheritedData->m_counterDirectives.get();
1020 }
1021
1022 CounterDirectiveMap& RenderStyle::accessCounterDirectives()
1023 {
1024     OwnPtr<CounterDirectiveMap>& map = rareNonInheritedData.access()->m_counterDirectives;
1025     if (!map)
1026         map = adoptPtr(new CounterDirectiveMap);
1027     return *map;
1028 }
1029
1030 const AtomicString& RenderStyle::hyphenString() const
1031 {
1032     ASSERT(hyphens() != HyphensNone);
1033
1034     const AtomicString& hyphenationString = rareInheritedData.get()->hyphenationString;
1035     if (!hyphenationString.isNull())
1036         return hyphenationString;
1037
1038     // FIXME: This should depend on locale.
1039     DEFINE_STATIC_LOCAL(AtomicString, hyphenMinusString, (&hyphenMinus, 1));
1040     DEFINE_STATIC_LOCAL(AtomicString, hyphenString, (&hyphen, 1));
1041     return font().primaryFontHasGlyphForCharacter(hyphen) ? hyphenString : hyphenMinusString;
1042 }
1043
1044 const AtomicString& RenderStyle::textEmphasisMarkString() const
1045 {
1046     switch (textEmphasisMark()) {
1047     case TextEmphasisMarkNone:
1048         return nullAtom;
1049     case TextEmphasisMarkCustom:
1050         return textEmphasisCustomMark();
1051     case TextEmphasisMarkDot: {
1052         DEFINE_STATIC_LOCAL(AtomicString, filledDotString, (&bullet, 1));
1053         DEFINE_STATIC_LOCAL(AtomicString, openDotString, (&whiteBullet, 1));
1054         return textEmphasisFill() == TextEmphasisFillFilled ? filledDotString : openDotString;
1055     }
1056     case TextEmphasisMarkCircle: {
1057         DEFINE_STATIC_LOCAL(AtomicString, filledCircleString, (&blackCircle, 1));
1058         DEFINE_STATIC_LOCAL(AtomicString, openCircleString, (&whiteCircle, 1));
1059         return textEmphasisFill() == TextEmphasisFillFilled ? filledCircleString : openCircleString;
1060     }
1061     case TextEmphasisMarkDoubleCircle: {
1062         DEFINE_STATIC_LOCAL(AtomicString, filledDoubleCircleString, (&fisheye, 1));
1063         DEFINE_STATIC_LOCAL(AtomicString, openDoubleCircleString, (&bullseye, 1));
1064         return textEmphasisFill() == TextEmphasisFillFilled ? filledDoubleCircleString : openDoubleCircleString;
1065     }
1066     case TextEmphasisMarkTriangle: {
1067         DEFINE_STATIC_LOCAL(AtomicString, filledTriangleString, (&blackUpPointingTriangle, 1));
1068         DEFINE_STATIC_LOCAL(AtomicString, openTriangleString, (&whiteUpPointingTriangle, 1));
1069         return textEmphasisFill() == TextEmphasisFillFilled ? filledTriangleString : openTriangleString;
1070     }
1071     case TextEmphasisMarkSesame: {
1072         DEFINE_STATIC_LOCAL(AtomicString, filledSesameString, (&sesameDot, 1));
1073         DEFINE_STATIC_LOCAL(AtomicString, openSesameString, (&whiteSesameDot, 1));
1074         return textEmphasisFill() == TextEmphasisFillFilled ? filledSesameString : openSesameString;
1075     }
1076     case TextEmphasisMarkAuto:
1077         ASSERT_NOT_REACHED();
1078         return nullAtom;
1079     }
1080
1081     ASSERT_NOT_REACHED();
1082     return nullAtom;
1083 }
1084
1085 #if ENABLE(DASHBOARD_SUPPORT) || ENABLE(WIDGET_REGION)
1086 const Vector<StyleDashboardRegion>& RenderStyle::initialDashboardRegions()
1087 {
1088     DEFINE_STATIC_LOCAL(Vector<StyleDashboardRegion>, emptyList, ());
1089     return emptyList;
1090 }
1091
1092 const Vector<StyleDashboardRegion>& RenderStyle::noneDashboardRegions()
1093 {
1094     DEFINE_STATIC_LOCAL(Vector<StyleDashboardRegion>, noneList, ());
1095     static bool noneListInitialized = false;
1096
1097     if (!noneListInitialized) {
1098         StyleDashboardRegion region;
1099         region.label = "";
1100         region.offset.m_top  = Length();
1101         region.offset.m_right = Length();
1102         region.offset.m_bottom = Length();
1103         region.offset.m_left = Length();
1104         region.type = StyleDashboardRegion::None;
1105         noneList.append(region);
1106         noneListInitialized = true;
1107     }
1108     return noneList;
1109 }
1110 #endif
1111
1112 void RenderStyle::adjustAnimations()
1113 {
1114     AnimationList* animationList = rareNonInheritedData->m_animations.get();
1115     if (!animationList)
1116         return;
1117
1118     // Get rid of empty animations and anything beyond them
1119     for (size_t i = 0; i < animationList->size(); ++i) {
1120         if (animationList->animation(i)->isEmpty()) {
1121             animationList->resize(i);
1122             break;
1123         }
1124     }
1125
1126     if (animationList->isEmpty()) {
1127         clearAnimations();
1128         return;
1129     }
1130
1131     // Repeat patterns into layers that don't have some properties set.
1132     animationList->fillUnsetProperties();
1133 }
1134
1135 void RenderStyle::adjustTransitions()
1136 {
1137     AnimationList* transitionList = rareNonInheritedData->m_transitions.get();
1138     if (!transitionList)
1139         return;
1140
1141     // Get rid of empty transitions and anything beyond them
1142     for (size_t i = 0; i < transitionList->size(); ++i) {
1143         if (transitionList->animation(i)->isEmpty()) {
1144             transitionList->resize(i);
1145             break;
1146         }
1147     }
1148
1149     if (transitionList->isEmpty()) {
1150         clearTransitions();
1151         return;
1152     }
1153
1154     // Repeat patterns into layers that don't have some properties set.
1155     transitionList->fillUnsetProperties();
1156
1157     // Make sure there are no duplicate properties. This is an O(n^2) algorithm
1158     // but the lists tend to be very short, so it is probably ok
1159     for (size_t i = 0; i < transitionList->size(); ++i) {
1160         for (size_t j = i+1; j < transitionList->size(); ++j) {
1161             if (transitionList->animation(i)->property() == transitionList->animation(j)->property()) {
1162                 // toss i
1163                 transitionList->remove(i);
1164                 j = i;
1165             }
1166         }
1167     }
1168 }
1169
1170 AnimationList* RenderStyle::accessAnimations()
1171 {
1172     if (!rareNonInheritedData.access()->m_animations)
1173         rareNonInheritedData.access()->m_animations = adoptPtr(new AnimationList());
1174     return rareNonInheritedData->m_animations.get();
1175 }
1176
1177 AnimationList* RenderStyle::accessTransitions()
1178 {
1179     if (!rareNonInheritedData.access()->m_transitions)
1180         rareNonInheritedData.access()->m_transitions = adoptPtr(new AnimationList());
1181     return rareNonInheritedData->m_transitions.get();
1182 }
1183
1184 const Animation* RenderStyle::transitionForProperty(CSSPropertyID property) const
1185 {
1186     if (transitions()) {
1187         for (size_t i = 0; i < transitions()->size(); ++i) {
1188             const Animation* p = transitions()->animation(i);
1189             if (p->animationMode() == Animation::AnimateAll || p->property() == property) {
1190                 return p;
1191             }
1192         }
1193     }
1194     return 0;
1195 }
1196
1197 const Font& RenderStyle::font() const { return inherited->font; }
1198 const FontMetrics& RenderStyle::fontMetrics() const { return inherited->font.fontMetrics(); }
1199 const FontDescription& RenderStyle::fontDescription() const { return inherited->font.fontDescription(); }
1200 float RenderStyle::specifiedFontSize() const { return fontDescription().specifiedSize(); }
1201 float RenderStyle::computedFontSize() const { return fontDescription().computedSize(); }
1202 int RenderStyle::fontSize() const { return inherited->font.pixelSize(); }
1203
1204 int RenderStyle::wordSpacing() const { return inherited->font.wordSpacing(); }
1205 int RenderStyle::letterSpacing() const { return inherited->font.letterSpacing(); }
1206
1207 bool RenderStyle::setFontDescription(const FontDescription& v)
1208 {
1209     if (inherited->font.fontDescription() != v) {
1210         inherited.access()->font = Font(v, inherited->font.letterSpacing(), inherited->font.wordSpacing());
1211         return true;
1212     }
1213     return false;
1214 }
1215
1216 Length RenderStyle::specifiedLineHeight() const { return inherited->line_height; }
1217 Length RenderStyle::lineHeight() const
1218 {
1219     const Length& lh = inherited->line_height;
1220 #if ENABLE(TEXT_AUTOSIZING)
1221     // Unlike fontDescription().computedSize() and hence fontSize(), this is
1222     // recalculated on demand as we only store the specified line height.
1223     // FIXME: Should consider scaling the fixed part of any calc expressions
1224     // too, though this involves messily poking into CalcExpressionLength.
1225     float multiplier = textAutosizingMultiplier();
1226     if (multiplier > 1 && lh.isFixed())
1227         return Length(lh.value() * multiplier, Fixed);
1228 #endif
1229     return lh;
1230 }
1231 void RenderStyle::setLineHeight(Length specifiedLineHeight) { SET_VAR(inherited, line_height, specifiedLineHeight); }
1232
1233 int RenderStyle::computedLineHeight(RenderView* renderView) const
1234 {
1235     const Length& lh = lineHeight();
1236
1237     // Negative value means the line height is not set. Use the font's built-in spacing.
1238     if (lh.isNegative())
1239         return fontMetrics().lineSpacing();
1240
1241     if (lh.isPercent())
1242         return minimumValueForLength(lh, fontSize());
1243
1244     if (lh.isViewportPercentage())
1245         return valueForLength(lh, 0, renderView);
1246
1247     return lh.value();
1248 }
1249
1250 void RenderStyle::setWordSpacing(int v) { inherited.access()->font.setWordSpacing(v); }
1251 void RenderStyle::setLetterSpacing(int v) { inherited.access()->font.setLetterSpacing(v); }
1252
1253 void RenderStyle::setFontSize(float size)
1254 {
1255     // size must be specifiedSize if Text Autosizing is enabled, but computedSize if text
1256     // zoom is enabled (if neither is enabled it's irrelevant as they're probably the same).
1257
1258     FontSelector* currentFontSelector = font().fontSelector();
1259     FontDescription desc(fontDescription());
1260     desc.setSpecifiedSize(size);
1261     desc.setComputedSize(size);
1262
1263 #if ENABLE(TEXT_AUTOSIZING)
1264     float multiplier = textAutosizingMultiplier();
1265     if (multiplier > 1) {
1266         // FIXME: Large font sizes needn't be multiplied as much since they are already more legible.
1267         desc.setComputedSize(size * multiplier);
1268     }
1269 #endif
1270
1271     setFontDescription(desc);
1272     font().update(currentFontSelector);
1273 }
1274
1275 void RenderStyle::getShadowExtent(const ShadowData* shadow, LayoutUnit &top, LayoutUnit &right, LayoutUnit &bottom, LayoutUnit &left) const
1276 {
1277     top = 0;
1278     right = 0;
1279     bottom = 0;
1280     left = 0;
1281
1282     for ( ; shadow; shadow = shadow->next()) {
1283         if (shadow->style() == Inset)
1284             continue;
1285         int blurAndSpread = shadow->blur() + shadow->spread();
1286
1287         top = min<LayoutUnit>(top, shadow->y() - blurAndSpread);
1288         right = max<LayoutUnit>(right, shadow->x() + blurAndSpread);
1289         bottom = max<LayoutUnit>(bottom, shadow->y() + blurAndSpread);
1290         left = min<LayoutUnit>(left, shadow->x() - blurAndSpread);
1291     }
1292 }
1293
1294 void RenderStyle::getShadowHorizontalExtent(const ShadowData* shadow, LayoutUnit &left, LayoutUnit &right) const
1295 {
1296     left = 0;
1297     right = 0;
1298
1299     for ( ; shadow; shadow = shadow->next()) {
1300         if (shadow->style() == Inset)
1301             continue;
1302         int blurAndSpread = shadow->blur() + shadow->spread();
1303
1304         left = min<LayoutUnit>(left, shadow->x() - blurAndSpread);
1305         right = max<LayoutUnit>(right, shadow->x() + blurAndSpread);
1306     }
1307 }
1308
1309 void RenderStyle::getShadowVerticalExtent(const ShadowData* shadow, LayoutUnit &top, LayoutUnit &bottom) const
1310 {
1311     top = 0;
1312     bottom = 0;
1313
1314     for ( ; shadow; shadow = shadow->next()) {
1315         if (shadow->style() == Inset)
1316             continue;
1317         int blurAndSpread = shadow->blur() + shadow->spread();
1318
1319         top = min<LayoutUnit>(top, shadow->y() - blurAndSpread);
1320         bottom = max<LayoutUnit>(bottom, shadow->y() + blurAndSpread);
1321     }
1322 }
1323
1324 Color RenderStyle::colorIncludingFallback(int colorProperty, bool visitedLink) const
1325 {
1326     Color result;
1327     EBorderStyle borderStyle = BNONE;
1328     switch (colorProperty) {
1329     case CSSPropertyBackgroundColor:
1330         return visitedLink ? rareNonInheritedData->m_visitedLinkBackgroundColor : backgroundColor(); // Background color doesn't fall back.
1331     case CSSPropertyBorderLeftColor:
1332         result = visitedLink ? rareNonInheritedData->m_visitedLinkBorderLeftColor : borderLeftColor();
1333         borderStyle = borderLeftStyle();
1334         break;
1335     case CSSPropertyBorderRightColor:
1336         result = visitedLink ? rareNonInheritedData->m_visitedLinkBorderRightColor : borderRightColor();
1337         borderStyle = borderRightStyle();
1338         break;
1339     case CSSPropertyBorderTopColor:
1340         result = visitedLink ? rareNonInheritedData->m_visitedLinkBorderTopColor : borderTopColor();
1341         borderStyle = borderTopStyle();
1342         break;
1343     case CSSPropertyBorderBottomColor:
1344         result = visitedLink ? rareNonInheritedData->m_visitedLinkBorderBottomColor : borderBottomColor();
1345         borderStyle = borderBottomStyle();
1346         break;
1347     case CSSPropertyColor:
1348         result = visitedLink ? inherited->visitedLinkColor : color();
1349         break;
1350     case CSSPropertyOutlineColor:
1351         result = visitedLink ? rareNonInheritedData->m_visitedLinkOutlineColor : outlineColor();
1352         break;
1353     case CSSPropertyWebkitColumnRuleColor:
1354         result = visitedLink ? rareNonInheritedData->m_multiCol->m_visitedLinkColumnRuleColor : columnRuleColor();
1355         break;
1356     case CSSPropertyWebkitTextEmphasisColor:
1357         result = visitedLink ? rareInheritedData->visitedLinkTextEmphasisColor : textEmphasisColor();
1358         break;
1359     case CSSPropertyWebkitTextFillColor:
1360         result = visitedLink ? rareInheritedData->visitedLinkTextFillColor : textFillColor();
1361         break;
1362     case CSSPropertyWebkitTextStrokeColor:
1363         result = visitedLink ? rareInheritedData->visitedLinkTextStrokeColor : textStrokeColor();
1364         break;
1365     default:
1366         ASSERT_NOT_REACHED();
1367         break;
1368     }
1369
1370     if (!result.isValid()) {
1371         if (!visitedLink && (borderStyle == INSET || borderStyle == OUTSET || borderStyle == RIDGE || borderStyle == GROOVE))
1372             result.setRGB(238, 238, 238);
1373         else
1374             result = visitedLink ? inherited->visitedLinkColor : color();
1375     }
1376     return result;
1377 }
1378
1379 Color RenderStyle::visitedDependentColor(int colorProperty) const
1380 {
1381     Color unvisitedColor = colorIncludingFallback(colorProperty, false);
1382     if (insideLink() != InsideVisitedLink)
1383         return unvisitedColor;
1384
1385     Color visitedColor = colorIncludingFallback(colorProperty, true);
1386
1387     // FIXME: Technically someone could explicitly specify the color transparent, but for now we'll just
1388     // assume that if the background color is transparent that it wasn't set. Note that it's weird that
1389     // we're returning unvisited info for a visited link, but given our restriction that the alpha values
1390     // have to match, it makes more sense to return the unvisited background color if specified than it
1391     // does to return black. This behavior matches what Firefox 4 does as well.
1392     if (colorProperty == CSSPropertyBackgroundColor && visitedColor == Color::transparent)
1393         return unvisitedColor;
1394
1395     // Take the alpha from the unvisited color, but get the RGB values from the visited color.
1396     return Color(visitedColor.red(), visitedColor.green(), visitedColor.blue(), unvisitedColor.alpha());
1397 }
1398
1399 Length RenderStyle::logicalWidth() const
1400 {
1401     if (isHorizontalWritingMode())
1402         return width();
1403     return height();
1404 }
1405
1406 Length RenderStyle::logicalHeight() const
1407 {
1408     if (isHorizontalWritingMode())
1409         return height();
1410     return width();
1411 }
1412
1413 Length RenderStyle::logicalMinWidth() const
1414 {
1415     if (isHorizontalWritingMode())
1416         return minWidth();
1417     return minHeight();
1418 }
1419
1420 Length RenderStyle::logicalMaxWidth() const
1421 {
1422     if (isHorizontalWritingMode())
1423         return maxWidth();
1424     return maxHeight();
1425 }
1426
1427 Length RenderStyle::logicalMinHeight() const
1428 {
1429     if (isHorizontalWritingMode())
1430         return minHeight();
1431     return minWidth();
1432 }
1433
1434 Length RenderStyle::logicalMaxHeight() const
1435 {
1436     if (isHorizontalWritingMode())
1437         return maxHeight();
1438     return maxWidth();
1439 }
1440
1441 const BorderValue& RenderStyle::borderBefore() const
1442 {
1443     switch (writingMode()) {
1444     case TopToBottomWritingMode:
1445         return borderTop();
1446     case BottomToTopWritingMode:
1447         return borderBottom();
1448     case LeftToRightWritingMode:
1449         return borderLeft();
1450     case RightToLeftWritingMode:
1451         return borderRight();
1452     }
1453     ASSERT_NOT_REACHED();
1454     return borderTop();
1455 }
1456
1457 const BorderValue& RenderStyle::borderAfter() const
1458 {
1459     switch (writingMode()) {
1460     case TopToBottomWritingMode:
1461         return borderBottom();
1462     case BottomToTopWritingMode:
1463         return borderTop();
1464     case LeftToRightWritingMode:
1465         return borderRight();
1466     case RightToLeftWritingMode:
1467         return borderLeft();
1468     }
1469     ASSERT_NOT_REACHED();
1470     return borderBottom();
1471 }
1472
1473 const BorderValue& RenderStyle::borderStart() const
1474 {
1475     if (isHorizontalWritingMode())
1476         return isLeftToRightDirection() ? borderLeft() : borderRight();
1477     return isLeftToRightDirection() ? borderTop() : borderBottom();
1478 }
1479
1480 const BorderValue& RenderStyle::borderEnd() const
1481 {
1482     if (isHorizontalWritingMode())
1483         return isLeftToRightDirection() ? borderRight() : borderLeft();
1484     return isLeftToRightDirection() ? borderBottom() : borderTop();
1485 }
1486
1487 unsigned short RenderStyle::borderBeforeWidth() const
1488 {
1489     switch (writingMode()) {
1490     case TopToBottomWritingMode:
1491         return borderTopWidth();
1492     case BottomToTopWritingMode:
1493         return borderBottomWidth();
1494     case LeftToRightWritingMode:
1495         return borderLeftWidth();
1496     case RightToLeftWritingMode:
1497         return borderRightWidth();
1498     }
1499     ASSERT_NOT_REACHED();
1500     return borderTopWidth();
1501 }
1502
1503 unsigned short RenderStyle::borderAfterWidth() const
1504 {
1505     switch (writingMode()) {
1506     case TopToBottomWritingMode:
1507         return borderBottomWidth();
1508     case BottomToTopWritingMode:
1509         return borderTopWidth();
1510     case LeftToRightWritingMode:
1511         return borderRightWidth();
1512     case RightToLeftWritingMode:
1513         return borderLeftWidth();
1514     }
1515     ASSERT_NOT_REACHED();
1516     return borderBottomWidth();
1517 }
1518
1519 unsigned short RenderStyle::borderStartWidth() const
1520 {
1521     if (isHorizontalWritingMode())
1522         return isLeftToRightDirection() ? borderLeftWidth() : borderRightWidth();
1523     return isLeftToRightDirection() ? borderTopWidth() : borderBottomWidth();
1524 }
1525
1526 unsigned short RenderStyle::borderEndWidth() const
1527 {
1528     if (isHorizontalWritingMode())
1529         return isLeftToRightDirection() ? borderRightWidth() : borderLeftWidth();
1530     return isLeftToRightDirection() ? borderBottomWidth() : borderTopWidth();
1531 }
1532
1533 void RenderStyle::setMarginStart(Length margin)
1534 {
1535     if (isHorizontalWritingMode()) {
1536         if (isLeftToRightDirection())
1537             setMarginLeft(margin);
1538         else
1539             setMarginRight(margin);
1540     } else {
1541         if (isLeftToRightDirection())
1542             setMarginTop(margin);
1543         else
1544             setMarginBottom(margin);
1545     }
1546 }
1547
1548 void RenderStyle::setMarginEnd(Length margin)
1549 {
1550     if (isHorizontalWritingMode()) {
1551         if (isLeftToRightDirection())
1552             setMarginRight(margin);
1553         else
1554             setMarginLeft(margin);
1555     } else {
1556         if (isLeftToRightDirection())
1557             setMarginBottom(margin);
1558         else
1559             setMarginTop(margin);
1560     }
1561 }
1562
1563 TextEmphasisMark RenderStyle::textEmphasisMark() const
1564 {
1565     TextEmphasisMark mark = static_cast<TextEmphasisMark>(rareInheritedData->textEmphasisMark);
1566     if (mark != TextEmphasisMarkAuto)
1567         return mark;
1568
1569     if (isHorizontalWritingMode())
1570         return TextEmphasisMarkDot;
1571
1572     return TextEmphasisMarkSesame;
1573 }
1574
1575 #if ENABLE(TOUCH_EVENTS)
1576 Color RenderStyle::initialTapHighlightColor()
1577 {
1578     return RenderTheme::tapHighlightColor();
1579 }
1580 #endif
1581
1582 LayoutBoxExtent RenderStyle::imageOutsets(const NinePieceImage& image) const
1583 {
1584     return LayoutBoxExtent(NinePieceImage::computeOutset(image.outset().top(), borderTopWidth()),
1585                            NinePieceImage::computeOutset(image.outset().right(), borderRightWidth()),
1586                            NinePieceImage::computeOutset(image.outset().bottom(), borderBottomWidth()),
1587                            NinePieceImage::computeOutset(image.outset().left(), borderLeftWidth()));
1588 }
1589
1590 void RenderStyle::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
1591 {
1592     MemoryClassInfo info(memoryObjectInfo, this, MemoryInstrumentation::CSS);
1593     info.addMember(m_box);
1594     info.addMember(visual);
1595     // FIXME: m_background contains RefPtr<StyleImage> that might need to be instrumented.
1596     info.addMember(m_background);
1597     // FIXME: surrond contains some fields e.g. BorderData that might need to be instrumented.
1598     info.addMember(surround);
1599     info.addInstrumentedMember(rareNonInheritedData);
1600     info.addInstrumentedMember(rareInheritedData);
1601     // FIXME: inherited contains StyleImage and Font fields that might need to be instrumented.
1602     info.addMember(inherited);
1603     if (m_cachedPseudoStyles)
1604         info.addVectorPtr(m_cachedPseudoStyles.get());
1605 #if ENABLE(SVG)
1606     info.addMember(m_svgStyle);
1607 #endif
1608 }
1609
1610 } // namespace WebCore