Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / 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 "core/rendering/style/RenderStyle.h"
25
26 #include <algorithm>
27 #include "core/css/resolver/StyleResolver.h"
28 #include "core/rendering/RenderTheme.h"
29 #include "core/rendering/TextAutosizer.h"
30 #include "core/rendering/style/AppliedTextDecoration.h"
31 #include "core/rendering/style/ContentData.h"
32 #include "core/rendering/style/QuotesData.h"
33 #include "core/rendering/style/ShadowList.h"
34 #include "core/rendering/style/StyleImage.h"
35 #include "core/rendering/style/StyleInheritedData.h"
36 #include "platform/LengthFunctions.h"
37 #include "platform/RuntimeEnabledFeatures.h"
38 #include "platform/fonts/Font.h"
39 #include "platform/fonts/FontSelector.h"
40 #include "platform/geometry/FloatRoundedRect.h"
41 #include "wtf/MathExtras.h"
42
43 namespace blink {
44
45 struct SameSizeAsBorderValue {
46     RGBA32 m_color;
47     unsigned m_width;
48 };
49
50 COMPILE_ASSERT(sizeof(BorderValue) == sizeof(SameSizeAsBorderValue), BorderValue_should_not_grow);
51
52 struct SameSizeAsRenderStyle : public RefCounted<SameSizeAsRenderStyle> {
53     void* dataRefs[7];
54     void* ownPtrs[1];
55     void* dataRefSvgStyle;
56
57     struct InheritedFlags {
58         unsigned m_bitfields[2];
59     } inherited_flags;
60
61     struct NonInheritedFlags {
62         unsigned m_bitfields[2];
63     } noninherited_flags;
64 };
65
66 COMPILE_ASSERT(sizeof(RenderStyle) == sizeof(SameSizeAsRenderStyle), RenderStyle_should_stay_small);
67
68 inline RenderStyle* defaultStyle()
69 {
70     DEFINE_STATIC_REF(RenderStyle, s_defaultStyle, (RenderStyle::createDefaultStyle()));
71     return s_defaultStyle;
72 }
73
74 PassRefPtr<RenderStyle> RenderStyle::create()
75 {
76     return adoptRef(new RenderStyle());
77 }
78
79 PassRefPtr<RenderStyle> RenderStyle::createDefaultStyle()
80 {
81     return adoptRef(new RenderStyle(DefaultStyle));
82 }
83
84 PassRefPtr<RenderStyle> RenderStyle::createAnonymousStyleWithDisplay(const RenderStyle* parentStyle, EDisplay display)
85 {
86     RefPtr<RenderStyle> newStyle = RenderStyle::create();
87     newStyle->inheritFrom(parentStyle);
88     newStyle->inheritUnicodeBidiFrom(parentStyle);
89     newStyle->setDisplay(display);
90     return newStyle;
91 }
92
93 PassRefPtr<RenderStyle> RenderStyle::clone(const RenderStyle* other)
94 {
95     return adoptRef(new RenderStyle(*other));
96 }
97
98 ALWAYS_INLINE RenderStyle::RenderStyle()
99     : m_box(defaultStyle()->m_box)
100     , visual(defaultStyle()->visual)
101     , m_background(defaultStyle()->m_background)
102     , surround(defaultStyle()->surround)
103     , rareNonInheritedData(defaultStyle()->rareNonInheritedData)
104     , rareInheritedData(defaultStyle()->rareInheritedData)
105     , inherited(defaultStyle()->inherited)
106     , m_svgStyle(defaultStyle()->m_svgStyle)
107 {
108     setBitDefaults(); // Would it be faster to copy this from the default style?
109     COMPILE_ASSERT((sizeof(InheritedFlags) <= 8), InheritedFlags_does_not_grow);
110     COMPILE_ASSERT((sizeof(NonInheritedFlags) <= 8), NonInheritedFlags_does_not_grow);
111 }
112
113 ALWAYS_INLINE RenderStyle::RenderStyle(DefaultStyleTag)
114 {
115     setBitDefaults();
116
117     m_box.init();
118     visual.init();
119     m_background.init();
120     surround.init();
121     rareNonInheritedData.init();
122     rareNonInheritedData.access()->m_deprecatedFlexibleBox.init();
123     rareNonInheritedData.access()->m_flexibleBox.init();
124     rareNonInheritedData.access()->m_marquee.init();
125     rareNonInheritedData.access()->m_multiCol.init();
126     rareNonInheritedData.access()->m_transform.init();
127     rareNonInheritedData.access()->m_willChange.init();
128     rareNonInheritedData.access()->m_filter.init();
129     rareNonInheritedData.access()->m_grid.init();
130     rareNonInheritedData.access()->m_gridItem.init();
131     rareInheritedData.init();
132     inherited.init();
133     m_svgStyle.init();
134 }
135
136 ALWAYS_INLINE RenderStyle::RenderStyle(const RenderStyle& o)
137     : RefCounted<RenderStyle>()
138     , m_box(o.m_box)
139     , visual(o.visual)
140     , m_background(o.m_background)
141     , surround(o.surround)
142     , rareNonInheritedData(o.rareNonInheritedData)
143     , rareInheritedData(o.rareInheritedData)
144     , inherited(o.inherited)
145     , m_svgStyle(o.m_svgStyle)
146     , inherited_flags(o.inherited_flags)
147     , noninherited_flags(o.noninherited_flags)
148 {
149 }
150
151 static StyleRecalcChange diffPseudoStyles(const RenderStyle* oldStyle, const RenderStyle* newStyle)
152 {
153     // If the pseudoStyles have changed, we want any StyleRecalcChange that is not NoChange
154     // because setStyle will do the right thing with anything else.
155     if (!oldStyle->hasAnyPublicPseudoStyles())
156         return NoChange;
157     for (PseudoId pseudoId = FIRST_PUBLIC_PSEUDOID; pseudoId < FIRST_INTERNAL_PSEUDOID; pseudoId = static_cast<PseudoId>(pseudoId + 1)) {
158         if (!oldStyle->hasPseudoStyle(pseudoId))
159             continue;
160         RenderStyle* newPseudoStyle = newStyle->getCachedPseudoStyle(pseudoId);
161         if (!newPseudoStyle)
162             return NoInherit;
163         RenderStyle* oldPseudoStyle = oldStyle->getCachedPseudoStyle(pseudoId);
164         if (oldPseudoStyle && *oldPseudoStyle != *newPseudoStyle)
165             return NoInherit;
166     }
167     return NoChange;
168 }
169
170 StyleRecalcChange RenderStyle::stylePropagationDiff(const RenderStyle* oldStyle, const RenderStyle* newStyle)
171 {
172     if ((!oldStyle && newStyle) || (oldStyle && !newStyle))
173         return Reattach;
174
175     if (!oldStyle && !newStyle)
176         return NoChange;
177
178     if (oldStyle->display() != newStyle->display()
179         || oldStyle->hasPseudoStyle(FIRST_LETTER) != newStyle->hasPseudoStyle(FIRST_LETTER)
180         || oldStyle->columnSpan() != newStyle->columnSpan()
181         || !oldStyle->contentDataEquivalent(newStyle)
182         || oldStyle->hasTextCombine() != newStyle->hasTextCombine()
183         || oldStyle->justifyItems() != newStyle->justifyItems()
184         || oldStyle->alignItems() != newStyle->alignItems())
185         return Reattach;
186
187     if (*oldStyle == *newStyle)
188         return diffPseudoStyles(oldStyle, newStyle);
189
190     if (oldStyle->inheritedNotEqual(newStyle)
191         || oldStyle->hasExplicitlyInheritedProperties()
192         || newStyle->hasExplicitlyInheritedProperties())
193         return Inherit;
194
195     return NoInherit;
196 }
197
198 void RenderStyle::inheritFrom(const RenderStyle* inheritParent, IsAtShadowBoundary isAtShadowBoundary)
199 {
200     if (isAtShadowBoundary == AtShadowBoundary) {
201         // Even if surrounding content is user-editable, shadow DOM should act as a single unit, and not necessarily be editable
202         EUserModify currentUserModify = userModify();
203         rareInheritedData = inheritParent->rareInheritedData;
204         setUserModify(currentUserModify);
205     } else
206         rareInheritedData = inheritParent->rareInheritedData;
207     inherited = inheritParent->inherited;
208     inherited_flags = inheritParent->inherited_flags;
209     if (m_svgStyle != inheritParent->m_svgStyle)
210         m_svgStyle.access()->inheritFrom(inheritParent->m_svgStyle.get());
211 }
212
213 void RenderStyle::copyNonInheritedFrom(const RenderStyle* other)
214 {
215     m_box = other->m_box;
216     visual = other->visual;
217     m_background = other->m_background;
218     surround = other->surround;
219     rareNonInheritedData = other->rareNonInheritedData;
220     // The flags are copied one-by-one because noninherited_flags contains a bunch of stuff other than real style data.
221     noninherited_flags.effectiveDisplay = other->noninherited_flags.effectiveDisplay;
222     noninherited_flags.originalDisplay = other->noninherited_flags.originalDisplay;
223     noninherited_flags.overflowX = other->noninherited_flags.overflowX;
224     noninherited_flags.overflowY = other->noninherited_flags.overflowY;
225     noninherited_flags.verticalAlign = other->noninherited_flags.verticalAlign;
226     noninherited_flags.clear = other->noninherited_flags.clear;
227     noninherited_flags.position = other->noninherited_flags.position;
228     noninherited_flags.floating = other->noninherited_flags.floating;
229     noninherited_flags.tableLayout = other->noninherited_flags.tableLayout;
230     noninherited_flags.unicodeBidi = other->noninherited_flags.unicodeBidi;
231     noninherited_flags.pageBreakBefore = other->noninherited_flags.pageBreakBefore;
232     noninherited_flags.pageBreakAfter = other->noninherited_flags.pageBreakAfter;
233     noninherited_flags.pageBreakInside = other->noninherited_flags.pageBreakInside;
234     noninherited_flags.explicitInheritance = other->noninherited_flags.explicitInheritance;
235     noninherited_flags.currentColor = other->noninherited_flags.currentColor;
236     noninherited_flags.hasViewportUnits = other->noninherited_flags.hasViewportUnits;
237     if (m_svgStyle != other->m_svgStyle)
238         m_svgStyle.access()->copyNonInheritedFrom(other->m_svgStyle.get());
239     ASSERT(zoom() == initialZoom());
240 }
241
242 bool RenderStyle::operator==(const RenderStyle& o) const
243 {
244     // compare everything except the pseudoStyle pointer
245     return inherited_flags == o.inherited_flags
246         && noninherited_flags == o.noninherited_flags
247         && m_box == o.m_box
248         && visual == o.visual
249         && m_background == o.m_background
250         && surround == o.surround
251         && rareNonInheritedData == o.rareNonInheritedData
252         && rareInheritedData == o.rareInheritedData
253         && inherited == o.inherited
254         && m_svgStyle == o.m_svgStyle;
255 }
256
257 bool RenderStyle::isStyleAvailable() const
258 {
259     return this != StyleResolver::styleNotYetAvailable();
260 }
261
262 bool RenderStyle::hasUniquePseudoStyle() const
263 {
264     if (!m_cachedPseudoStyles || styleType() != NOPSEUDO)
265         return false;
266
267     for (size_t i = 0; i < m_cachedPseudoStyles->size(); ++i) {
268         RenderStyle* pseudoStyle = m_cachedPseudoStyles->at(i).get();
269         if (pseudoStyle->unique())
270             return true;
271     }
272
273     return false;
274 }
275
276 RenderStyle* RenderStyle::getCachedPseudoStyle(PseudoId pid) const
277 {
278     if (!m_cachedPseudoStyles || !m_cachedPseudoStyles->size())
279         return 0;
280
281     if (styleType() != NOPSEUDO)
282         return 0;
283
284     for (size_t i = 0; i < m_cachedPseudoStyles->size(); ++i) {
285         RenderStyle* pseudoStyle = m_cachedPseudoStyles->at(i).get();
286         if (pseudoStyle->styleType() == pid)
287             return pseudoStyle;
288     }
289
290     return 0;
291 }
292
293 RenderStyle* RenderStyle::addCachedPseudoStyle(PassRefPtr<RenderStyle> pseudo)
294 {
295     if (!pseudo)
296         return 0;
297
298     ASSERT(pseudo->styleType() > NOPSEUDO);
299
300     RenderStyle* result = pseudo.get();
301
302     if (!m_cachedPseudoStyles)
303         m_cachedPseudoStyles = adoptPtr(new PseudoStyleCache);
304
305     m_cachedPseudoStyles->append(pseudo);
306
307     return result;
308 }
309
310 void RenderStyle::removeCachedPseudoStyle(PseudoId pid)
311 {
312     if (!m_cachedPseudoStyles)
313         return;
314     for (size_t i = 0; i < m_cachedPseudoStyles->size(); ++i) {
315         RenderStyle* pseudoStyle = m_cachedPseudoStyles->at(i).get();
316         if (pseudoStyle->styleType() == pid) {
317             m_cachedPseudoStyles->remove(i);
318             return;
319         }
320     }
321 }
322
323 bool RenderStyle::inheritedNotEqual(const RenderStyle* other) const
324 {
325     return inherited_flags != other->inherited_flags
326            || inherited != other->inherited
327            || m_svgStyle->inheritedNotEqual(other->m_svgStyle.get())
328            || rareInheritedData != other->rareInheritedData;
329 }
330
331 bool RenderStyle::inheritedDataShared(const RenderStyle* other) const
332 {
333     // This is a fast check that only looks if the data structures are shared.
334     return inherited_flags == other->inherited_flags
335         && inherited.get() == other->inherited.get()
336         && m_svgStyle.get() == other->m_svgStyle.get()
337         && rareInheritedData.get() == other->rareInheritedData.get();
338 }
339
340 static bool positionedObjectMovedOnly(const LengthBox& a, const LengthBox& b, const Length& width)
341 {
342     // If any unit types are different, then we can't guarantee
343     // that this was just a movement.
344     if (a.left().type() != b.left().type()
345         || a.right().type() != b.right().type()
346         || a.top().type() != b.top().type()
347         || a.bottom().type() != b.bottom().type())
348         return false;
349
350     // Only one unit can be non-auto in the horizontal direction and
351     // in the vertical direction.  Otherwise the adjustment of values
352     // is changing the size of the box.
353     if (!a.left().isIntrinsicOrAuto() && !a.right().isIntrinsicOrAuto())
354         return false;
355     if (!a.top().isIntrinsicOrAuto() && !a.bottom().isIntrinsicOrAuto())
356         return false;
357     // If our width is auto and left or right is specified and changed then this
358     // is not just a movement - we need to resize to our container.
359     if (width.isIntrinsicOrAuto()
360         && ((!a.left().isIntrinsicOrAuto() && a.left() != b.left())
361             || (!a.right().isIntrinsicOrAuto() && a.right() != b.right())))
362         return false;
363
364     // One of the units is fixed or percent in both directions and stayed
365     // that way in the new style.  Therefore all we are doing is moving.
366     return true;
367 }
368
369 StyleDifference RenderStyle::visualInvalidationDiff(const RenderStyle& other) const
370 {
371     // Note, we use .get() on each DataRef below because DataRef::operator== will do a deep
372     // compare, which is duplicate work when we're going to compare each property inside
373     // this function anyway.
374
375     StyleDifference diff;
376     if (m_svgStyle.get() != other.m_svgStyle.get())
377         diff = m_svgStyle->diff(other.m_svgStyle.get());
378
379     if ((!diff.needsFullLayout() || !diff.needsPaintInvalidation()) && diffNeedsFullLayoutAndPaintInvalidation(other)) {
380         diff.setNeedsFullLayout();
381         diff.setNeedsPaintInvalidationObject();
382     }
383
384     if (!diff.needsFullLayout() && diffNeedsFullLayout(other))
385         diff.setNeedsFullLayout();
386
387     if (!diff.needsFullLayout() && position() != StaticPosition && surround->offset != other.surround->offset) {
388         // Optimize for the case where a positioned layer is moving but not changing size.
389         if ((position() == AbsolutePosition || position() == FixedPosition)
390             && positionedObjectMovedOnly(surround->offset, other.surround->offset, m_box->width())) {
391             diff.setNeedsPositionedMovementLayout();
392         } else {
393             // FIXME: We would like to use SimplifiedLayout for relative positioning, but we can't quite do that yet.
394             // We need to make sure SimplifiedLayout can operate correctly on RenderInlines (we will need
395             // to add a selfNeedsSimplifiedLayout bit in order to not get confused and taint every line).
396             diff.setNeedsFullLayout();
397         }
398     }
399
400     if (diffNeedsPaintInvalidationLayer(other))
401         diff.setNeedsPaintInvalidationLayer();
402     else if (diffNeedsPaintInvalidationObject(other))
403         diff.setNeedsPaintInvalidationObject();
404
405     updatePropertySpecificDifferences(other, diff);
406
407     // Cursors are not checked, since they will be set appropriately in response to mouse events,
408     // so they don't need to cause any paint invalidation or layout.
409
410     // 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
411     // the resulting transition properly.
412
413     return diff;
414 }
415
416 bool RenderStyle::diffNeedsFullLayoutAndPaintInvalidation(const RenderStyle& other) const
417 {
418     // FIXME: Not all cases in this method need both full layout and paint invalidation.
419     // Should move cases into diffNeedsFullLayout() if
420     // - don't need paint invalidation at all;
421     // - or the renderer knows how to exactly invalidate paints caused by the layout change
422     //   instead of forced full paint invalidation.
423
424     if (surround.get() != other.surround.get()) {
425         // If our border widths change, then we need to layout. Other changes to borders only necessitate a paint invalidation.
426         if (borderLeftWidth() != other.borderLeftWidth()
427             || borderTopWidth() != other.borderTopWidth()
428             || borderBottomWidth() != other.borderBottomWidth()
429             || borderRightWidth() != other.borderRightWidth())
430             return true;
431     }
432
433     if (rareNonInheritedData.get() != other.rareNonInheritedData.get()) {
434         if (rareNonInheritedData->m_appearance != other.rareNonInheritedData->m_appearance
435             || rareNonInheritedData->marginBeforeCollapse != other.rareNonInheritedData->marginBeforeCollapse
436             || rareNonInheritedData->marginAfterCollapse != other.rareNonInheritedData->marginAfterCollapse
437             || rareNonInheritedData->lineClamp != other.rareNonInheritedData->lineClamp
438             || rareNonInheritedData->textOverflow != other.rareNonInheritedData->textOverflow
439             || rareNonInheritedData->m_wrapFlow != other.rareNonInheritedData->m_wrapFlow
440             || rareNonInheritedData->m_wrapThrough != other.rareNonInheritedData->m_wrapThrough
441             || rareNonInheritedData->m_shapeMargin != other.rareNonInheritedData->m_shapeMargin
442             || rareNonInheritedData->m_order != other.rareNonInheritedData->m_order
443             || rareNonInheritedData->m_alignContent != other.rareNonInheritedData->m_alignContent
444             || rareNonInheritedData->m_alignItems != other.rareNonInheritedData->m_alignItems
445             || rareNonInheritedData->m_alignSelf != other.rareNonInheritedData->m_alignSelf
446             || rareNonInheritedData->m_justifyContent != other.rareNonInheritedData->m_justifyContent
447             || rareNonInheritedData->m_grid.get() != other.rareNonInheritedData->m_grid.get()
448             || rareNonInheritedData->m_gridItem.get() != other.rareNonInheritedData->m_gridItem.get()
449             || rareNonInheritedData->m_textCombine != other.rareNonInheritedData->m_textCombine
450             || rareNonInheritedData->hasFilters() != other.rareNonInheritedData->hasFilters())
451             return true;
452
453         if (rareNonInheritedData->m_deprecatedFlexibleBox.get() != other.rareNonInheritedData->m_deprecatedFlexibleBox.get()
454             && *rareNonInheritedData->m_deprecatedFlexibleBox.get() != *other.rareNonInheritedData->m_deprecatedFlexibleBox.get())
455             return true;
456
457         if (rareNonInheritedData->m_flexibleBox.get() != other.rareNonInheritedData->m_flexibleBox.get()
458             && *rareNonInheritedData->m_flexibleBox.get() != *other.rareNonInheritedData->m_flexibleBox.get())
459             return true;
460
461         // FIXME: We should add an optimized form of layout that just recomputes visual overflow.
462         if (!rareNonInheritedData->shadowDataEquivalent(*other.rareNonInheritedData.get()))
463             return true;
464
465         if (!rareNonInheritedData->reflectionDataEquivalent(*other.rareNonInheritedData.get()))
466             return true;
467
468         if (rareNonInheritedData->m_multiCol.get() != other.rareNonInheritedData->m_multiCol.get()
469             && *rareNonInheritedData->m_multiCol.get() != *other.rareNonInheritedData->m_multiCol.get())
470             return true;
471
472         // If the counter directives change, trigger a relayout to re-calculate counter values and rebuild the counter node tree.
473         const CounterDirectiveMap* mapA = rareNonInheritedData->m_counterDirectives.get();
474         const CounterDirectiveMap* mapB = other.rareNonInheritedData->m_counterDirectives.get();
475         if (!(mapA == mapB || (mapA && mapB && *mapA == *mapB)))
476             return true;
477
478         // We only need do layout for opacity changes if adding or losing opacity could trigger a change
479         // in us being a stacking context.
480         if (hasAutoZIndex() != other.hasAutoZIndex() && rareNonInheritedData->hasOpacity() != other.rareNonInheritedData->hasOpacity()) {
481             // FIXME: We would like to use SimplifiedLayout here, but we can't quite do that yet.
482             // We need to make sure SimplifiedLayout can operate correctly on RenderInlines (we will need
483             // to add a selfNeedsSimplifiedLayout bit in order to not get confused and taint every line).
484             // In addition we need to solve the floating object issue when layers come and go. Right now
485             // a full layout is necessary to keep floating object lists sane.
486             return true;
487         }
488     }
489
490     if (rareInheritedData.get() != other.rareInheritedData.get()) {
491         if (rareInheritedData->highlight != other.rareInheritedData->highlight
492             || rareInheritedData->indent != other.rareInheritedData->indent
493             || rareInheritedData->m_textAlignLast != other.rareInheritedData->m_textAlignLast
494             || rareInheritedData->m_textIndentLine != other.rareInheritedData->m_textIndentLine
495             || rareInheritedData->m_effectiveZoom != other.rareInheritedData->m_effectiveZoom
496             || rareInheritedData->wordBreak != other.rareInheritedData->wordBreak
497             || rareInheritedData->overflowWrap != other.rareInheritedData->overflowWrap
498             || rareInheritedData->lineBreak != other.rareInheritedData->lineBreak
499             || rareInheritedData->textSecurity != other.rareInheritedData->textSecurity
500             || rareInheritedData->hyphens != other.rareInheritedData->hyphens
501             || rareInheritedData->hyphenationLimitBefore != other.rareInheritedData->hyphenationLimitBefore
502             || rareInheritedData->hyphenationLimitAfter != other.rareInheritedData->hyphenationLimitAfter
503             || rareInheritedData->hyphenationString != other.rareInheritedData->hyphenationString
504             || rareInheritedData->locale != other.rareInheritedData->locale
505             || rareInheritedData->m_rubyPosition != other.rareInheritedData->m_rubyPosition
506             || rareInheritedData->textEmphasisMark != other.rareInheritedData->textEmphasisMark
507             || rareInheritedData->textEmphasisPosition != other.rareInheritedData->textEmphasisPosition
508             || rareInheritedData->textEmphasisCustomMark != other.rareInheritedData->textEmphasisCustomMark
509             || rareInheritedData->m_textJustify != other.rareInheritedData->m_textJustify
510             || rareInheritedData->m_textOrientation != other.rareInheritedData->m_textOrientation
511             || rareInheritedData->m_tabSize != other.rareInheritedData->m_tabSize
512             || rareInheritedData->m_lineBoxContain != other.rareInheritedData->m_lineBoxContain
513             || rareInheritedData->listStyleImage != other.rareInheritedData->listStyleImage
514             || rareInheritedData->textStrokeWidth != other.rareInheritedData->textStrokeWidth)
515             return true;
516
517         if (!rareInheritedData->shadowDataEquivalent(*other.rareInheritedData.get()))
518             return true;
519
520         if (!rareInheritedData->quotesDataEquivalent(*other.rareInheritedData.get()))
521             return true;
522     }
523
524     if (inherited->textAutosizingMultiplier != other.inherited->textAutosizingMultiplier)
525         return true;
526
527     if (inherited.get() != other.inherited.get()) {
528         if (inherited->line_height != other.inherited->line_height
529             || inherited->font != other.inherited->font
530             || inherited->horizontal_border_spacing != other.inherited->horizontal_border_spacing
531             || inherited->vertical_border_spacing != other.inherited->vertical_border_spacing)
532             return true;
533     }
534
535     if (inherited_flags._box_direction != other.inherited_flags._box_direction
536         || inherited_flags.m_rtlOrdering != other.inherited_flags.m_rtlOrdering
537         || inherited_flags._text_align != other.inherited_flags._text_align
538         || inherited_flags._text_transform != other.inherited_flags._text_transform
539         || inherited_flags._direction != other.inherited_flags._direction
540         || inherited_flags._white_space != other.inherited_flags._white_space
541         || inherited_flags.m_writingMode != other.inherited_flags.m_writingMode)
542         return true;
543
544     if (noninherited_flags.overflowX != other.noninherited_flags.overflowX
545         || noninherited_flags.overflowY != other.noninherited_flags.overflowY
546         || noninherited_flags.clear != other.noninherited_flags.clear
547         || noninherited_flags.unicodeBidi != other.noninherited_flags.unicodeBidi
548         || noninherited_flags.position != other.noninherited_flags.position
549         || noninherited_flags.floating != other.noninherited_flags.floating
550         || noninherited_flags.originalDisplay != other.noninherited_flags.originalDisplay)
551         return true;
552
553     if (noninherited_flags.effectiveDisplay >= FIRST_TABLE_DISPLAY && noninherited_flags.effectiveDisplay <= LAST_TABLE_DISPLAY) {
554         if (inherited_flags._border_collapse != other.inherited_flags._border_collapse
555             || inherited_flags._empty_cells != other.inherited_flags._empty_cells
556             || inherited_flags._caption_side != other.inherited_flags._caption_side
557             || noninherited_flags.tableLayout != other.noninherited_flags.tableLayout)
558             return true;
559
560         // In the collapsing border model, 'hidden' suppresses other borders, while 'none'
561         // does not, so these style differences can be width differences.
562         if (inherited_flags._border_collapse
563             && ((borderTopStyle() == BHIDDEN && other.borderTopStyle() == BNONE)
564                 || (borderTopStyle() == BNONE && other.borderTopStyle() == BHIDDEN)
565                 || (borderBottomStyle() == BHIDDEN && other.borderBottomStyle() == BNONE)
566                 || (borderBottomStyle() == BNONE && other.borderBottomStyle() == BHIDDEN)
567                 || (borderLeftStyle() == BHIDDEN && other.borderLeftStyle() == BNONE)
568                 || (borderLeftStyle() == BNONE && other.borderLeftStyle() == BHIDDEN)
569                 || (borderRightStyle() == BHIDDEN && other.borderRightStyle() == BNONE)
570                 || (borderRightStyle() == BNONE && other.borderRightStyle() == BHIDDEN)))
571             return true;
572     } else if (noninherited_flags.effectiveDisplay == LIST_ITEM) {
573         if (inherited_flags._list_style_type != other.inherited_flags._list_style_type
574             || inherited_flags._list_style_position != other.inherited_flags._list_style_position)
575             return true;
576     }
577
578     if ((visibility() == COLLAPSE) != (other.visibility() == COLLAPSE))
579         return true;
580
581     if (!m_background->outline().visuallyEqual(other.m_background->outline())) {
582         // FIXME: We only really need to recompute the overflow but we don't have an optimized layout for it.
583         return true;
584     }
585
586     // Movement of non-static-positioned object is special cased in RenderStyle::visualInvalidationDiff().
587
588     return false;
589 }
590
591 bool RenderStyle::diffNeedsFullLayout(const RenderStyle& other) const
592 {
593     if (m_box.get() != other.m_box.get()) {
594         if (m_box->width() != other.m_box->width()
595             || m_box->minWidth() != other.m_box->minWidth()
596             || m_box->maxWidth() != other.m_box->maxWidth()
597             || m_box->height() != other.m_box->height()
598             || m_box->minHeight() != other.m_box->minHeight()
599             || m_box->maxHeight() != other.m_box->maxHeight())
600             return true;
601
602         if (m_box->verticalAlign() != other.m_box->verticalAlign())
603             return true;
604
605         if (m_box->boxSizing() != other.m_box->boxSizing())
606             return true;
607     }
608
609     if (noninherited_flags.verticalAlign != other.noninherited_flags.verticalAlign)
610         return true;
611
612     if (surround.get() != other.surround.get()) {
613         if (surround->margin != other.surround->margin)
614             return true;
615
616         if (surround->padding != other.surround->padding)
617             return true;
618     }
619
620     return false;
621 }
622
623 bool RenderStyle::diffNeedsPaintInvalidationLayer(const RenderStyle& other) const
624 {
625     if (position() != StaticPosition && (visual->clip != other.visual->clip || visual->hasClip != other.visual->hasClip))
626         return true;
627
628     if (rareNonInheritedData.get() != other.rareNonInheritedData.get()) {
629         if (RuntimeEnabledFeatures::cssCompositingEnabled()
630             && (rareNonInheritedData->m_effectiveBlendMode != other.rareNonInheritedData->m_effectiveBlendMode
631                 || rareNonInheritedData->m_isolation != other.rareNonInheritedData->m_isolation))
632             return true;
633
634         if (rareNonInheritedData->m_mask != other.rareNonInheritedData->m_mask
635             || rareNonInheritedData->m_maskBoxImage != other.rareNonInheritedData->m_maskBoxImage)
636             return true;
637     }
638
639     return false;
640 }
641
642 bool RenderStyle::diffNeedsPaintInvalidationObject(const RenderStyle& other) const
643 {
644     if (inherited_flags._visibility != other.inherited_flags._visibility
645         || inherited_flags.m_printColorAdjust != other.inherited_flags.m_printColorAdjust
646         || inherited_flags._insideLink != other.inherited_flags._insideLink
647         || !surround->border.visuallyEqual(other.surround->border)
648         || !m_background->visuallyEqual(*other.m_background))
649         return true;
650
651     if (rareInheritedData.get() != other.rareInheritedData.get()) {
652         if (rareInheritedData->userModify != other.rareInheritedData->userModify
653             || rareInheritedData->userSelect != other.rareInheritedData->userSelect
654             || rareInheritedData->m_imageRendering != other.rareInheritedData->m_imageRendering)
655             return true;
656     }
657
658     if (rareNonInheritedData.get() != other.rareNonInheritedData.get()) {
659         if (rareNonInheritedData->userDrag != other.rareNonInheritedData->userDrag
660             || rareNonInheritedData->m_borderFit != other.rareNonInheritedData->m_borderFit
661             || rareNonInheritedData->m_objectFit != other.rareNonInheritedData->m_objectFit
662             || rareNonInheritedData->m_objectPosition != other.rareNonInheritedData->m_objectPosition
663             || rareNonInheritedData->m_shapeOutside != other.rareNonInheritedData->m_shapeOutside
664             || rareNonInheritedData->m_clipPath != other.rareNonInheritedData->m_clipPath)
665             return true;
666     }
667
668     return false;
669 }
670
671 void RenderStyle::updatePropertySpecificDifferences(const RenderStyle& other, StyleDifference& diff) const
672 {
673     // StyleAdjuster has ensured that zIndex is non-auto only if it's applicable.
674     if (m_box->zIndex() != other.m_box->zIndex() || m_box->hasAutoZIndex() != other.m_box->hasAutoZIndex())
675         diff.setZIndexChanged();
676
677     if (rareNonInheritedData.get() != other.rareNonInheritedData.get()) {
678         if (!transformDataEquivalent(other))
679             diff.setTransformChanged();
680
681         if (rareNonInheritedData->opacity != other.rareNonInheritedData->opacity)
682             diff.setOpacityChanged();
683
684         if (rareNonInheritedData->m_filter != other.rareNonInheritedData->m_filter)
685             diff.setFilterChanged();
686     }
687
688     if (!diff.needsPaintInvalidation()) {
689         if (inherited->color != other.inherited->color
690             || inherited_flags.m_textUnderline != other.inherited_flags.m_textUnderline
691             || visual->textDecoration != other.visual->textDecoration) {
692             diff.setTextOrColorChanged();
693         } else if (rareNonInheritedData.get() != other.rareNonInheritedData.get()) {
694             if (rareNonInheritedData->m_textDecorationStyle != other.rareNonInheritedData->m_textDecorationStyle
695                 || rareNonInheritedData->m_textDecorationColor != other.rareNonInheritedData->m_textDecorationColor)
696                 diff.setTextOrColorChanged();
697         } else if (rareInheritedData.get() != other.rareInheritedData.get()) {
698             if (rareInheritedData->textFillColor() != other.rareInheritedData->textFillColor()
699                 || rareInheritedData->textStrokeColor() != other.rareInheritedData->textStrokeColor()
700                 || rareInheritedData->textEmphasisColor() != other.rareInheritedData->textEmphasisColor()
701                 || rareInheritedData->textEmphasisFill != other.rareInheritedData->textEmphasisFill
702                 || rareInheritedData->appliedTextDecorations != other.rareInheritedData->appliedTextDecorations)
703                 diff.setTextOrColorChanged();
704         }
705     }
706 }
707
708 void RenderStyle::setClip(const Length& top, const Length& right, const Length& bottom, const Length& left)
709 {
710     StyleVisualData* data = visual.access();
711     data->clip.m_top = top;
712     data->clip.m_right = right;
713     data->clip.m_bottom = bottom;
714     data->clip.m_left = left;
715 }
716
717 void RenderStyle::addCursor(PassRefPtr<StyleImage> image, const IntPoint& hotSpot)
718 {
719     if (!rareInheritedData.access()->cursorData)
720         rareInheritedData.access()->cursorData = CursorList::create();
721     rareInheritedData.access()->cursorData->append(CursorData(image, hotSpot));
722 }
723
724 void RenderStyle::setCursorList(PassRefPtr<CursorList> other)
725 {
726     rareInheritedData.access()->cursorData = other;
727 }
728
729 void RenderStyle::setQuotes(PassRefPtr<QuotesData> q)
730 {
731     rareInheritedData.access()->quotes = q;
732 }
733
734 void RenderStyle::clearCursorList()
735 {
736     if (rareInheritedData->cursorData)
737         rareInheritedData.access()->cursorData = nullptr;
738 }
739
740 void RenderStyle::addCallbackSelector(const String& selector)
741 {
742     if (!rareNonInheritedData->m_callbackSelectors.contains(selector))
743         rareNonInheritedData.access()->m_callbackSelectors.append(selector);
744 }
745
746 void RenderStyle::clearContent()
747 {
748     if (rareNonInheritedData->m_content)
749         rareNonInheritedData.access()->m_content = nullptr;
750 }
751
752 void RenderStyle::appendContent(PassOwnPtr<ContentData> contentData)
753 {
754     OwnPtr<ContentData>& content = rareNonInheritedData.access()->m_content;
755     ContentData* lastContent = content.get();
756     while (lastContent && lastContent->next())
757         lastContent = lastContent->next();
758
759     if (lastContent)
760         lastContent->setNext(contentData);
761     else
762         content = contentData;
763 }
764
765 void RenderStyle::setContent(PassRefPtr<StyleImage> image, bool add)
766 {
767     if (!image)
768         return;
769
770     if (add) {
771         appendContent(ContentData::create(image));
772         return;
773     }
774
775     rareNonInheritedData.access()->m_content = ContentData::create(image);
776 }
777
778 void RenderStyle::setContent(const String& string, bool add)
779 {
780     OwnPtr<ContentData>& content = rareNonInheritedData.access()->m_content;
781     if (add) {
782         ContentData* lastContent = content.get();
783         while (lastContent && lastContent->next())
784             lastContent = lastContent->next();
785
786         if (lastContent) {
787             // We attempt to merge with the last ContentData if possible.
788             if (lastContent->isText()) {
789                 TextContentData* textContent = toTextContentData(lastContent);
790                 textContent->setText(textContent->text() + string);
791             } else
792                 lastContent->setNext(ContentData::create(string));
793
794             return;
795         }
796     }
797
798     content = ContentData::create(string);
799 }
800
801 void RenderStyle::setContent(PassOwnPtr<CounterContent> counter, bool add)
802 {
803     if (!counter)
804         return;
805
806     if (add) {
807         appendContent(ContentData::create(counter));
808         return;
809     }
810
811     rareNonInheritedData.access()->m_content = ContentData::create(counter);
812 }
813
814 void RenderStyle::setContent(QuoteType quote, bool add)
815 {
816     if (add) {
817         appendContent(ContentData::create(quote));
818         return;
819     }
820
821     rareNonInheritedData.access()->m_content = ContentData::create(quote);
822 }
823
824 WebBlendMode RenderStyle::blendMode() const
825 {
826     if (RuntimeEnabledFeatures::cssCompositingEnabled())
827         return static_cast<WebBlendMode>(rareNonInheritedData->m_effectiveBlendMode);
828     return WebBlendModeNormal;
829 }
830
831 void RenderStyle::setBlendMode(WebBlendMode v)
832 {
833     if (RuntimeEnabledFeatures::cssCompositingEnabled())
834         rareNonInheritedData.access()->m_effectiveBlendMode = v;
835 }
836
837 bool RenderStyle::hasBlendMode() const
838 {
839     if (RuntimeEnabledFeatures::cssCompositingEnabled())
840         return static_cast<WebBlendMode>(rareNonInheritedData->m_effectiveBlendMode) != WebBlendModeNormal;
841     return false;
842 }
843
844 EIsolation RenderStyle::isolation() const
845 {
846     if (RuntimeEnabledFeatures::cssCompositingEnabled())
847         return static_cast<EIsolation>(rareNonInheritedData->m_isolation);
848     return IsolationAuto;
849 }
850
851 void RenderStyle::setIsolation(EIsolation v)
852 {
853     if (RuntimeEnabledFeatures::cssCompositingEnabled())
854         rareNonInheritedData.access()->m_isolation = v;
855 }
856
857 bool RenderStyle::hasIsolation() const
858 {
859     if (RuntimeEnabledFeatures::cssCompositingEnabled())
860         return rareNonInheritedData->m_isolation != IsolationAuto;
861     return false;
862 }
863
864 bool RenderStyle::hasWillChangeCompositingHint() const
865 {
866     for (size_t i = 0; i < rareNonInheritedData->m_willChange->m_properties.size(); ++i) {
867         switch (rareNonInheritedData->m_willChange->m_properties[i]) {
868         case CSSPropertyOpacity:
869         case CSSPropertyTransform:
870         case CSSPropertyWebkitTransform:
871         case CSSPropertyTop:
872         case CSSPropertyLeft:
873         case CSSPropertyBottom:
874         case CSSPropertyRight:
875             return true;
876         default:
877             break;
878         }
879     }
880     return false;
881 }
882
883 inline bool requireTransformOrigin(const Vector<RefPtr<TransformOperation> >& transformOperations, RenderStyle::ApplyTransformOrigin applyOrigin)
884 {
885     // transform-origin brackets the transform with translate operations.
886     // Optimize for the case where the only transform is a translation, since the transform-origin is irrelevant
887     // in that case.
888     if (applyOrigin != RenderStyle::IncludeTransformOrigin)
889         return false;
890
891     unsigned size = transformOperations.size();
892     for (unsigned i = 0; i < size; ++i) {
893         TransformOperation::OperationType type = transformOperations[i]->type();
894         if (type != TransformOperation::TranslateX
895             && type != TransformOperation::TranslateY
896             && type != TransformOperation::Translate
897             && type != TransformOperation::TranslateZ
898             && type != TransformOperation::Translate3D)
899             return true;
900     }
901
902     return false;
903 }
904
905 void RenderStyle::applyTransform(TransformationMatrix& transform, const LayoutSize& borderBoxSize, ApplyTransformOrigin applyOrigin) const
906 {
907     applyTransform(transform, FloatRect(FloatPoint(), borderBoxSize), applyOrigin);
908 }
909
910 void RenderStyle::applyTransform(TransformationMatrix& transform, const FloatRect& boundingBox, ApplyTransformOrigin applyOrigin) const
911 {
912     const Vector<RefPtr<TransformOperation> >& transformOperations = rareNonInheritedData->m_transform->m_operations.operations();
913     bool applyTransformOrigin = requireTransformOrigin(transformOperations, applyOrigin);
914
915     float offsetX = transformOriginX().type() == Percent ? boundingBox.x() : 0;
916     float offsetY = transformOriginY().type() == Percent ? boundingBox.y() : 0;
917
918     if (applyTransformOrigin) {
919         transform.translate3d(floatValueForLength(transformOriginX(), boundingBox.width()) + offsetX,
920             floatValueForLength(transformOriginY(), boundingBox.height()) + offsetY,
921             transformOriginZ());
922     }
923
924     unsigned size = transformOperations.size();
925     for (unsigned i = 0; i < size; ++i)
926         transformOperations[i]->apply(transform, boundingBox.size());
927
928     if (applyTransformOrigin) {
929         transform.translate3d(-floatValueForLength(transformOriginX(), boundingBox.width()) - offsetX,
930             -floatValueForLength(transformOriginY(), boundingBox.height()) - offsetY,
931             -transformOriginZ());
932     }
933 }
934
935 void RenderStyle::setTextShadow(PassRefPtr<ShadowList> s)
936 {
937     rareInheritedData.access()->textShadow = s;
938 }
939
940 void RenderStyle::setBoxShadow(PassRefPtr<ShadowList> s)
941 {
942     rareNonInheritedData.access()->m_boxShadow = s;
943 }
944
945 static RoundedRect::Radii calcRadiiFor(const BorderData& border, IntSize size)
946 {
947     return RoundedRect::Radii(
948         IntSize(valueForLength(border.topLeft().width(), size.width()),
949             valueForLength(border.topLeft().height(), size.height())),
950         IntSize(valueForLength(border.topRight().width(), size.width()),
951             valueForLength(border.topRight().height(), size.height())),
952         IntSize(valueForLength(border.bottomLeft().width(), size.width()),
953             valueForLength(border.bottomLeft().height(), size.height())),
954         IntSize(valueForLength(border.bottomRight().width(), size.width()),
955             valueForLength(border.bottomRight().height(), size.height())));
956 }
957
958 StyleImage* RenderStyle::listStyleImage() const { return rareInheritedData->listStyleImage.get(); }
959 void RenderStyle::setListStyleImage(PassRefPtr<StyleImage> v)
960 {
961     if (rareInheritedData->listStyleImage != v)
962         rareInheritedData.access()->listStyleImage = 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, 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());
981         radii.scale(calcBorderRadiiConstraintScaleFor(borderRect, 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     int leftWidth = (!horizontal || includeLogicalLeftEdge) ? borderLeftWidth() : 0;
992     int rightWidth = (!horizontal || includeLogicalRightEdge) ? borderRightWidth() : 0;
993     int topWidth = (horizontal || includeLogicalLeftEdge) ? borderTopWidth() : 0;
994     int 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     int topWidth, int bottomWidth, int leftWidth, int 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 static bool allLayersAreFixed(const FillLayer& layer)
1018 {
1019     for (const FillLayer* currLayer = &layer; currLayer; currLayer = currLayer->next()) {
1020         if (!currLayer->image() || currLayer->attachment() != FixedBackgroundAttachment)
1021             return false;
1022     }
1023
1024     return true;
1025 }
1026
1027 bool RenderStyle::hasEntirelyFixedBackground() const
1028 {
1029     return allLayersAreFixed(backgroundLayers());
1030 }
1031
1032 const CounterDirectiveMap* RenderStyle::counterDirectives() const
1033 {
1034     return rareNonInheritedData->m_counterDirectives.get();
1035 }
1036
1037 CounterDirectiveMap& RenderStyle::accessCounterDirectives()
1038 {
1039     OwnPtr<CounterDirectiveMap>& map = rareNonInheritedData.access()->m_counterDirectives;
1040     if (!map)
1041         map = adoptPtr(new CounterDirectiveMap);
1042     return *map;
1043 }
1044
1045 const CounterDirectives RenderStyle::getCounterDirectives(const AtomicString& identifier) const
1046 {
1047     if (const CounterDirectiveMap* directives = counterDirectives())
1048         return directives->get(identifier);
1049     return CounterDirectives();
1050 }
1051
1052 const AtomicString& RenderStyle::hyphenString() const
1053 {
1054     const AtomicString& hyphenationString = rareInheritedData.get()->hyphenationString;
1055     if (!hyphenationString.isNull())
1056         return hyphenationString;
1057
1058     // FIXME: This should depend on locale.
1059     DEFINE_STATIC_LOCAL(AtomicString, hyphenMinusString, (&hyphenMinus, 1));
1060     DEFINE_STATIC_LOCAL(AtomicString, hyphenString, (&hyphen, 1));
1061     return font().primaryFontHasGlyphForCharacter(hyphen) ? hyphenString : hyphenMinusString;
1062 }
1063
1064 const AtomicString& RenderStyle::textEmphasisMarkString() const
1065 {
1066     switch (textEmphasisMark()) {
1067     case TextEmphasisMarkNone:
1068         return nullAtom;
1069     case TextEmphasisMarkCustom:
1070         return textEmphasisCustomMark();
1071     case TextEmphasisMarkDot: {
1072         DEFINE_STATIC_LOCAL(AtomicString, filledDotString, (&bullet, 1));
1073         DEFINE_STATIC_LOCAL(AtomicString, openDotString, (&whiteBullet, 1));
1074         return textEmphasisFill() == TextEmphasisFillFilled ? filledDotString : openDotString;
1075     }
1076     case TextEmphasisMarkCircle: {
1077         DEFINE_STATIC_LOCAL(AtomicString, filledCircleString, (&blackCircle, 1));
1078         DEFINE_STATIC_LOCAL(AtomicString, openCircleString, (&whiteCircle, 1));
1079         return textEmphasisFill() == TextEmphasisFillFilled ? filledCircleString : openCircleString;
1080     }
1081     case TextEmphasisMarkDoubleCircle: {
1082         DEFINE_STATIC_LOCAL(AtomicString, filledDoubleCircleString, (&fisheye, 1));
1083         DEFINE_STATIC_LOCAL(AtomicString, openDoubleCircleString, (&bullseye, 1));
1084         return textEmphasisFill() == TextEmphasisFillFilled ? filledDoubleCircleString : openDoubleCircleString;
1085     }
1086     case TextEmphasisMarkTriangle: {
1087         DEFINE_STATIC_LOCAL(AtomicString, filledTriangleString, (&blackUpPointingTriangle, 1));
1088         DEFINE_STATIC_LOCAL(AtomicString, openTriangleString, (&whiteUpPointingTriangle, 1));
1089         return textEmphasisFill() == TextEmphasisFillFilled ? filledTriangleString : openTriangleString;
1090     }
1091     case TextEmphasisMarkSesame: {
1092         DEFINE_STATIC_LOCAL(AtomicString, filledSesameString, (&sesameDot, 1));
1093         DEFINE_STATIC_LOCAL(AtomicString, openSesameString, (&whiteSesameDot, 1));
1094         return textEmphasisFill() == TextEmphasisFillFilled ? filledSesameString : openSesameString;
1095     }
1096     case TextEmphasisMarkAuto:
1097         ASSERT_NOT_REACHED();
1098         return nullAtom;
1099     }
1100
1101     ASSERT_NOT_REACHED();
1102     return nullAtom;
1103 }
1104
1105 CSSAnimationData& RenderStyle::accessAnimations()
1106 {
1107     if (!rareNonInheritedData.access()->m_animations)
1108         rareNonInheritedData.access()->m_animations = CSSAnimationData::create();
1109     return *rareNonInheritedData->m_animations;
1110 }
1111
1112 CSSTransitionData& RenderStyle::accessTransitions()
1113 {
1114     if (!rareNonInheritedData.access()->m_transitions)
1115         rareNonInheritedData.access()->m_transitions = CSSTransitionData::create();
1116     return *rareNonInheritedData->m_transitions;
1117 }
1118
1119 const Font& RenderStyle::font() const { return inherited->font; }
1120 const FontMetrics& RenderStyle::fontMetrics() const { return inherited->font.fontMetrics(); }
1121 const FontDescription& RenderStyle::fontDescription() const { return inherited->font.fontDescription(); }
1122 float RenderStyle::specifiedFontSize() const { return fontDescription().specifiedSize(); }
1123 float RenderStyle::computedFontSize() const { return fontDescription().computedSize(); }
1124 int RenderStyle::fontSize() const { return fontDescription().computedPixelSize(); }
1125 FontWeight RenderStyle::fontWeight() const { return fontDescription().weight(); }
1126 FontStretch RenderStyle::fontStretch() const { return fontDescription().stretch(); }
1127
1128 TextDecoration RenderStyle::textDecorationsInEffect() const
1129 {
1130     int decorations = 0;
1131
1132     const Vector<AppliedTextDecoration>& applied = appliedTextDecorations();
1133
1134     for (size_t i = 0; i < applied.size(); ++i)
1135         decorations |= applied[i].line();
1136
1137     return static_cast<TextDecoration>(decorations);
1138 }
1139
1140 const Vector<AppliedTextDecoration>& RenderStyle::appliedTextDecorations() const
1141 {
1142     if (!inherited_flags.m_textUnderline && !rareInheritedData->appliedTextDecorations) {
1143         DEFINE_STATIC_LOCAL(Vector<AppliedTextDecoration>, empty, ());
1144         return empty;
1145     }
1146     if (inherited_flags.m_textUnderline) {
1147         DEFINE_STATIC_LOCAL(Vector<AppliedTextDecoration>, underline, (1, AppliedTextDecoration(TextDecorationUnderline)));
1148         return underline;
1149     }
1150
1151     return rareInheritedData->appliedTextDecorations->vector();
1152 }
1153
1154 float RenderStyle::wordSpacing() const { return fontDescription().wordSpacing(); }
1155 float RenderStyle::letterSpacing() const { return fontDescription().letterSpacing(); }
1156
1157 bool RenderStyle::setFontDescription(const FontDescription& v)
1158 {
1159     if (inherited->font.fontDescription() != v) {
1160         inherited.access()->font = Font(v);
1161         return true;
1162     }
1163     return false;
1164 }
1165
1166 const Length& RenderStyle::specifiedLineHeight() const { return inherited->line_height; }
1167 Length RenderStyle::lineHeight() const
1168 {
1169     const Length& lh = inherited->line_height;
1170     // Unlike fontDescription().computedSize() and hence fontSize(), this is
1171     // recalculated on demand as we only store the specified line height.
1172     // FIXME: Should consider scaling the fixed part of any calc expressions
1173     // too, though this involves messily poking into CalcExpressionLength.
1174     float multiplier = textAutosizingMultiplier();
1175     if (multiplier > 1 && lh.isFixed())
1176         return Length(TextAutosizer::computeAutosizedFontSize(lh.value(), multiplier), Fixed);
1177
1178     return lh;
1179 }
1180
1181 void RenderStyle::setLineHeight(const Length& specifiedLineHeight) { SET_VAR(inherited, line_height, specifiedLineHeight); }
1182
1183 int RenderStyle::computedLineHeight() const
1184 {
1185     const Length& lh = lineHeight();
1186
1187     // Negative value means the line height is not set. Use the font's built-in spacing.
1188     if (lh.isNegative())
1189         return fontMetrics().lineSpacing();
1190
1191     if (lh.isPercent())
1192         return minimumValueForLength(lh, fontSize());
1193
1194     return lh.value();
1195 }
1196
1197 void RenderStyle::setWordSpacing(float wordSpacing)
1198 {
1199     FontSelector* currentFontSelector = font().fontSelector();
1200     FontDescription desc(fontDescription());
1201     desc.setWordSpacing(wordSpacing);
1202     setFontDescription(desc);
1203     font().update(currentFontSelector);
1204 }
1205
1206 void RenderStyle::setLetterSpacing(float letterSpacing)
1207 {
1208     FontSelector* currentFontSelector = font().fontSelector();
1209     FontDescription desc(fontDescription());
1210     desc.setLetterSpacing(letterSpacing);
1211     setFontDescription(desc);
1212     font().update(currentFontSelector);
1213 }
1214
1215 void RenderStyle::setFontSize(float size)
1216 {
1217     // size must be specifiedSize if Text Autosizing is enabled, but computedSize if text
1218     // zoom is enabled (if neither is enabled it's irrelevant as they're probably the same).
1219
1220     ASSERT(std::isfinite(size));
1221     if (!std::isfinite(size) || size < 0)
1222         size = 0;
1223     else
1224         size = std::min(maximumAllowedFontSize, size);
1225
1226     FontSelector* currentFontSelector = font().fontSelector();
1227     FontDescription desc(fontDescription());
1228     desc.setSpecifiedSize(size);
1229     desc.setComputedSize(size);
1230
1231     float multiplier = textAutosizingMultiplier();
1232     if (multiplier > 1) {
1233         float autosizedFontSize = TextAutosizer::computeAutosizedFontSize(size, multiplier);
1234         desc.setComputedSize(std::min(maximumAllowedFontSize, autosizedFontSize));
1235     }
1236
1237     setFontDescription(desc);
1238     font().update(currentFontSelector);
1239 }
1240
1241 void RenderStyle::setFontWeight(FontWeight weight)
1242 {
1243     FontSelector* currentFontSelector = font().fontSelector();
1244     FontDescription desc(fontDescription());
1245     desc.setWeight(weight);
1246     setFontDescription(desc);
1247     font().update(currentFontSelector);
1248 }
1249
1250 void RenderStyle::addAppliedTextDecoration(const AppliedTextDecoration& decoration)
1251 {
1252     RefPtr<AppliedTextDecorationList>& list = rareInheritedData.access()->appliedTextDecorations;
1253
1254     if (!list)
1255         list = AppliedTextDecorationList::create();
1256     else if (!list->hasOneRef())
1257         list = list->copy();
1258
1259     if (inherited_flags.m_textUnderline) {
1260         inherited_flags.m_textUnderline = false;
1261         list->append(AppliedTextDecoration(TextDecorationUnderline));
1262     }
1263
1264     list->append(decoration);
1265 }
1266
1267 void RenderStyle::applyTextDecorations()
1268 {
1269     if (textDecoration() == TextDecorationNone)
1270         return;
1271
1272     TextDecorationStyle style = textDecorationStyle();
1273     StyleColor styleColor = visitedDependentDecorationStyleColor();
1274
1275     int decorations = textDecoration();
1276
1277     if (decorations & TextDecorationUnderline) {
1278         // To save memory, we don't use AppliedTextDecoration objects in the
1279         // common case of a single simple underline.
1280         AppliedTextDecoration underline(TextDecorationUnderline, style, styleColor);
1281
1282         if (!rareInheritedData->appliedTextDecorations && underline.isSimpleUnderline())
1283             inherited_flags.m_textUnderline = true;
1284         else
1285             addAppliedTextDecoration(underline);
1286     }
1287     if (decorations & TextDecorationOverline)
1288         addAppliedTextDecoration(AppliedTextDecoration(TextDecorationOverline, style, styleColor));
1289     if (decorations & TextDecorationLineThrough)
1290         addAppliedTextDecoration(AppliedTextDecoration(TextDecorationLineThrough, style, styleColor));
1291 }
1292
1293 void RenderStyle::clearAppliedTextDecorations()
1294 {
1295     inherited_flags.m_textUnderline = false;
1296
1297     if (rareInheritedData->appliedTextDecorations)
1298         rareInheritedData.access()->appliedTextDecorations = nullptr;
1299 }
1300
1301 void RenderStyle::setFontStretch(FontStretch stretch)
1302 {
1303     FontSelector* currentFontSelector = font().fontSelector();
1304     FontDescription desc(fontDescription());
1305     desc.setStretch(stretch);
1306     setFontDescription(desc);
1307     font().update(currentFontSelector);
1308 }
1309
1310 void RenderStyle::getShadowExtent(const ShadowList* shadowList, LayoutUnit &top, LayoutUnit &right, LayoutUnit &bottom, LayoutUnit &left) const
1311 {
1312     top = 0;
1313     right = 0;
1314     bottom = 0;
1315     left = 0;
1316
1317     size_t shadowCount = shadowList ? shadowList->shadows().size() : 0;
1318     for (size_t i = 0; i < shadowCount; ++i) {
1319         const ShadowData& shadow = shadowList->shadows()[i];
1320         if (shadow.style() == Inset)
1321             continue;
1322         float blurAndSpread = shadow.blur() + shadow.spread();
1323
1324         top = std::min<LayoutUnit>(top, shadow.y() - blurAndSpread);
1325         right = std::max<LayoutUnit>(right, shadow.x() + blurAndSpread);
1326         bottom = std::max<LayoutUnit>(bottom, shadow.y() + blurAndSpread);
1327         left = std::min<LayoutUnit>(left, shadow.x() - blurAndSpread);
1328     }
1329 }
1330
1331 LayoutBoxExtent RenderStyle::getShadowInsetExtent(const ShadowList* shadowList) const
1332 {
1333     LayoutUnit top = 0;
1334     LayoutUnit right = 0;
1335     LayoutUnit bottom = 0;
1336     LayoutUnit left = 0;
1337
1338     size_t shadowCount = shadowList ? shadowList->shadows().size() : 0;
1339     for (size_t i = 0; i < shadowCount; ++i) {
1340         const ShadowData& shadow = shadowList->shadows()[i];
1341         if (shadow.style() == Normal)
1342             continue;
1343         float blurAndSpread = shadow.blur() + shadow.spread();
1344         top = std::max<LayoutUnit>(top, shadow.y() + blurAndSpread);
1345         right = std::min<LayoutUnit>(right, shadow.x() - blurAndSpread);
1346         bottom = std::min<LayoutUnit>(bottom, shadow.y() - blurAndSpread);
1347         left = std::max<LayoutUnit>(left, shadow.x() + blurAndSpread);
1348     }
1349
1350     return LayoutBoxExtent(top, right, bottom, left);
1351 }
1352
1353 void RenderStyle::getShadowHorizontalExtent(const ShadowList* shadowList, LayoutUnit &left, LayoutUnit &right) const
1354 {
1355     left = 0;
1356     right = 0;
1357
1358     size_t shadowCount = shadowList ? shadowList->shadows().size() : 0;
1359     for (size_t i = 0; i < shadowCount; ++i) {
1360         const ShadowData& shadow = shadowList->shadows()[i];
1361         if (shadow.style() == Inset)
1362             continue;
1363         float blurAndSpread = shadow.blur() + shadow.spread();
1364
1365         left = std::min<LayoutUnit>(left, shadow.x() - blurAndSpread);
1366         right = std::max<LayoutUnit>(right, shadow.x() + blurAndSpread);
1367     }
1368 }
1369
1370 void RenderStyle::getShadowVerticalExtent(const ShadowList* shadowList, LayoutUnit &top, LayoutUnit &bottom) const
1371 {
1372     top = 0;
1373     bottom = 0;
1374
1375     size_t shadowCount = shadowList ? shadowList->shadows().size() : 0;
1376     for (size_t i = 0; i < shadowCount; ++i) {
1377         const ShadowData& shadow = shadowList->shadows()[i];
1378         if (shadow.style() == Inset)
1379             continue;
1380         float blurAndSpread = shadow.blur() + shadow.spread();
1381
1382         top = std::min<LayoutUnit>(top, shadow.y() - blurAndSpread);
1383         bottom = std::max<LayoutUnit>(bottom, shadow.y() + blurAndSpread);
1384     }
1385 }
1386
1387 StyleColor RenderStyle::visitedDependentDecorationStyleColor() const
1388 {
1389     bool isVisited = insideLink() == InsideVisitedLink;
1390
1391     StyleColor styleColor = isVisited ? visitedLinkTextDecorationColor() : textDecorationColor();
1392
1393     if (!styleColor.isCurrentColor())
1394         return styleColor;
1395
1396     if (textStrokeWidth()) {
1397         // Prefer stroke color if possible, but not if it's fully transparent.
1398         StyleColor textStrokeStyleColor = isVisited ? visitedLinkTextStrokeColor() : textStrokeColor();
1399         if (!textStrokeStyleColor.isCurrentColor() && textStrokeStyleColor.color().alpha())
1400             return textStrokeStyleColor;
1401     }
1402
1403     return isVisited ? visitedLinkTextFillColor() : textFillColor();
1404 }
1405
1406 Color RenderStyle::visitedDependentDecorationColor() const
1407 {
1408     bool isVisited = insideLink() == InsideVisitedLink;
1409     return visitedDependentDecorationStyleColor().resolve(isVisited ? visitedLinkColor() : color());
1410 }
1411
1412 Color RenderStyle::colorIncludingFallback(int colorProperty, bool visitedLink) const
1413 {
1414     StyleColor result(StyleColor::currentColor());
1415     EBorderStyle borderStyle = BNONE;
1416     switch (colorProperty) {
1417     case CSSPropertyBackgroundColor:
1418         result = visitedLink ? visitedLinkBackgroundColor() : backgroundColor();
1419         break;
1420     case CSSPropertyBorderLeftColor:
1421         result = visitedLink ? visitedLinkBorderLeftColor() : borderLeftColor();
1422         borderStyle = borderLeftStyle();
1423         break;
1424     case CSSPropertyBorderRightColor:
1425         result = visitedLink ? visitedLinkBorderRightColor() : borderRightColor();
1426         borderStyle = borderRightStyle();
1427         break;
1428     case CSSPropertyBorderTopColor:
1429         result = visitedLink ? visitedLinkBorderTopColor() : borderTopColor();
1430         borderStyle = borderTopStyle();
1431         break;
1432     case CSSPropertyBorderBottomColor:
1433         result = visitedLink ? visitedLinkBorderBottomColor() : borderBottomColor();
1434         borderStyle = borderBottomStyle();
1435         break;
1436     case CSSPropertyColor:
1437         result = visitedLink ? visitedLinkColor() : color();
1438         break;
1439     case CSSPropertyOutlineColor:
1440         result = visitedLink ? visitedLinkOutlineColor() : outlineColor();
1441         break;
1442     case CSSPropertyWebkitColumnRuleColor:
1443         result = visitedLink ? visitedLinkColumnRuleColor() : columnRuleColor();
1444         break;
1445     case CSSPropertyWebkitTextEmphasisColor:
1446         result = visitedLink ? visitedLinkTextEmphasisColor() : textEmphasisColor();
1447         break;
1448     case CSSPropertyWebkitTextFillColor:
1449         result = visitedLink ? visitedLinkTextFillColor() : textFillColor();
1450         break;
1451     case CSSPropertyWebkitTextStrokeColor:
1452         result = visitedLink ? visitedLinkTextStrokeColor() : textStrokeColor();
1453         break;
1454     case CSSPropertyFloodColor:
1455         result = floodColor();
1456         break;
1457     case CSSPropertyLightingColor:
1458         result = lightingColor();
1459         break;
1460     case CSSPropertyStopColor:
1461         result = stopColor();
1462         break;
1463     case CSSPropertyWebkitTapHighlightColor:
1464         result = tapHighlightColor();
1465         break;
1466     default:
1467         ASSERT_NOT_REACHED();
1468         break;
1469     }
1470
1471     if (!result.isCurrentColor())
1472         return result.color();
1473
1474     // FIXME: Treating styled borders with initial color differently causes problems
1475     // See crbug.com/316559, crbug.com/276231
1476     if (!visitedLink && (borderStyle == INSET || borderStyle == OUTSET || borderStyle == RIDGE || borderStyle == GROOVE))
1477         return Color(238, 238, 238);
1478     return visitedLink ? visitedLinkColor() : color();
1479 }
1480
1481 Color RenderStyle::visitedDependentColor(int colorProperty) const
1482 {
1483     Color unvisitedColor = colorIncludingFallback(colorProperty, false);
1484     if (insideLink() != InsideVisitedLink)
1485         return unvisitedColor;
1486
1487     Color visitedColor = colorIncludingFallback(colorProperty, true);
1488
1489     // FIXME: Technically someone could explicitly specify the color transparent, but for now we'll just
1490     // assume that if the background color is transparent that it wasn't set. Note that it's weird that
1491     // we're returning unvisited info for a visited link, but given our restriction that the alpha values
1492     // have to match, it makes more sense to return the unvisited background color if specified than it
1493     // does to return black. This behavior matches what Firefox 4 does as well.
1494     if (colorProperty == CSSPropertyBackgroundColor && visitedColor == Color::transparent)
1495         return unvisitedColor;
1496
1497     // Take the alpha from the unvisited color, but get the RGB values from the visited color.
1498     return Color(visitedColor.red(), visitedColor.green(), visitedColor.blue(), unvisitedColor.alpha());
1499 }
1500
1501 const BorderValue& RenderStyle::borderBefore() const
1502 {
1503     switch (writingMode()) {
1504     case TopToBottomWritingMode:
1505         return borderTop();
1506     case BottomToTopWritingMode:
1507         return borderBottom();
1508     case LeftToRightWritingMode:
1509         return borderLeft();
1510     case RightToLeftWritingMode:
1511         return borderRight();
1512     }
1513     ASSERT_NOT_REACHED();
1514     return borderTop();
1515 }
1516
1517 const BorderValue& RenderStyle::borderAfter() const
1518 {
1519     switch (writingMode()) {
1520     case TopToBottomWritingMode:
1521         return borderBottom();
1522     case BottomToTopWritingMode:
1523         return borderTop();
1524     case LeftToRightWritingMode:
1525         return borderRight();
1526     case RightToLeftWritingMode:
1527         return borderLeft();
1528     }
1529     ASSERT_NOT_REACHED();
1530     return borderBottom();
1531 }
1532
1533 const BorderValue& RenderStyle::borderStart() const
1534 {
1535     if (isHorizontalWritingMode())
1536         return isLeftToRightDirection() ? borderLeft() : borderRight();
1537     return isLeftToRightDirection() ? borderTop() : borderBottom();
1538 }
1539
1540 const BorderValue& RenderStyle::borderEnd() const
1541 {
1542     if (isHorizontalWritingMode())
1543         return isLeftToRightDirection() ? borderRight() : borderLeft();
1544     return isLeftToRightDirection() ? borderBottom() : borderTop();
1545 }
1546
1547 unsigned short RenderStyle::borderBeforeWidth() const
1548 {
1549     switch (writingMode()) {
1550     case TopToBottomWritingMode:
1551         return borderTopWidth();
1552     case BottomToTopWritingMode:
1553         return borderBottomWidth();
1554     case LeftToRightWritingMode:
1555         return borderLeftWidth();
1556     case RightToLeftWritingMode:
1557         return borderRightWidth();
1558     }
1559     ASSERT_NOT_REACHED();
1560     return borderTopWidth();
1561 }
1562
1563 unsigned short RenderStyle::borderAfterWidth() const
1564 {
1565     switch (writingMode()) {
1566     case TopToBottomWritingMode:
1567         return borderBottomWidth();
1568     case BottomToTopWritingMode:
1569         return borderTopWidth();
1570     case LeftToRightWritingMode:
1571         return borderRightWidth();
1572     case RightToLeftWritingMode:
1573         return borderLeftWidth();
1574     }
1575     ASSERT_NOT_REACHED();
1576     return borderBottomWidth();
1577 }
1578
1579 unsigned short RenderStyle::borderStartWidth() const
1580 {
1581     if (isHorizontalWritingMode())
1582         return isLeftToRightDirection() ? borderLeftWidth() : borderRightWidth();
1583     return isLeftToRightDirection() ? borderTopWidth() : borderBottomWidth();
1584 }
1585
1586 unsigned short RenderStyle::borderEndWidth() const
1587 {
1588     if (isHorizontalWritingMode())
1589         return isLeftToRightDirection() ? borderRightWidth() : borderLeftWidth();
1590     return isLeftToRightDirection() ? borderBottomWidth() : borderTopWidth();
1591 }
1592
1593 void RenderStyle::setMarginStart(const Length& margin)
1594 {
1595     if (isHorizontalWritingMode()) {
1596         if (isLeftToRightDirection())
1597             setMarginLeft(margin);
1598         else
1599             setMarginRight(margin);
1600     } else {
1601         if (isLeftToRightDirection())
1602             setMarginTop(margin);
1603         else
1604             setMarginBottom(margin);
1605     }
1606 }
1607
1608 void RenderStyle::setMarginEnd(const Length& margin)
1609 {
1610     if (isHorizontalWritingMode()) {
1611         if (isLeftToRightDirection())
1612             setMarginRight(margin);
1613         else
1614             setMarginLeft(margin);
1615     } else {
1616         if (isLeftToRightDirection())
1617             setMarginBottom(margin);
1618         else
1619             setMarginTop(margin);
1620     }
1621 }
1622
1623 TextEmphasisMark RenderStyle::textEmphasisMark() const
1624 {
1625     TextEmphasisMark mark = static_cast<TextEmphasisMark>(rareInheritedData->textEmphasisMark);
1626     if (mark != TextEmphasisMarkAuto)
1627         return mark;
1628
1629     if (isHorizontalWritingMode())
1630         return TextEmphasisMarkDot;
1631
1632     return TextEmphasisMarkSesame;
1633 }
1634
1635 Color RenderStyle::initialTapHighlightColor()
1636 {
1637     return RenderTheme::tapHighlightColor();
1638 }
1639
1640 LayoutBoxExtent RenderStyle::imageOutsets(const NinePieceImage& image) const
1641 {
1642     return LayoutBoxExtent(NinePieceImage::computeOutset(image.outset().top(), borderTopWidth()),
1643                            NinePieceImage::computeOutset(image.outset().right(), borderRightWidth()),
1644                            NinePieceImage::computeOutset(image.outset().bottom(), borderBottomWidth()),
1645                            NinePieceImage::computeOutset(image.outset().left(), borderLeftWidth()));
1646 }
1647
1648 void RenderStyle::setBorderImageSource(PassRefPtr<StyleImage> image)
1649 {
1650     if (surround->border.m_image.image() == image.get())
1651         return;
1652     surround.access()->border.m_image.setImage(image);
1653 }
1654
1655 void RenderStyle::setBorderImageSlices(const LengthBox& slices)
1656 {
1657     if (surround->border.m_image.imageSlices() == slices)
1658         return;
1659     surround.access()->border.m_image.setImageSlices(slices);
1660 }
1661
1662 void RenderStyle::setBorderImageWidth(const BorderImageLengthBox& slices)
1663 {
1664     if (surround->border.m_image.borderSlices() == slices)
1665         return;
1666     surround.access()->border.m_image.setBorderSlices(slices);
1667 }
1668
1669 void RenderStyle::setBorderImageOutset(const BorderImageLengthBox& outset)
1670 {
1671     if (surround->border.m_image.outset() == outset)
1672         return;
1673     surround.access()->border.m_image.setOutset(outset);
1674 }
1675
1676 float calcBorderRadiiConstraintScaleFor(const FloatRect& rect, const FloatRoundedRect::Radii& radii)
1677 {
1678     // Constrain corner radii using CSS3 rules:
1679     // http://www.w3.org/TR/css3-background/#the-border-radius
1680
1681     float factor = 1;
1682     float radiiSum;
1683
1684     // top
1685     radiiSum = radii.topLeft().width() + radii.topRight().width(); // Casts to avoid integer overflow.
1686     if (radiiSum > rect.width())
1687         factor = std::min(rect.width() / radiiSum, factor);
1688
1689     // bottom
1690     radiiSum = radii.bottomLeft().width() + radii.bottomRight().width();
1691     if (radiiSum > rect.width())
1692         factor = std::min(rect.width() / radiiSum, factor);
1693
1694     // left
1695     radiiSum = radii.topLeft().height() + radii.bottomLeft().height();
1696     if (radiiSum > rect.height())
1697         factor = std::min(rect.height() / radiiSum, factor);
1698
1699     // right
1700     radiiSum = radii.topRight().height() + radii.bottomRight().height();
1701     if (radiiSum > rect.height())
1702         factor = std::min(rect.height() / radiiSum, factor);
1703
1704     ASSERT(factor <= 1);
1705     return factor;
1706 }
1707
1708 } // namespace blink