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.
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.
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.
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.
24 #include "core/rendering/style/RenderStyle.h"
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"
45 struct SameSizeAsBorderValue {
50 COMPILE_ASSERT(sizeof(BorderValue) == sizeof(SameSizeAsBorderValue), BorderValue_should_not_grow);
52 struct SameSizeAsRenderStyle : public RefCounted<SameSizeAsRenderStyle> {
55 void* dataRefSvgStyle;
57 struct InheritedFlags {
58 unsigned m_bitfields[2];
61 struct NonInheritedFlags {
62 unsigned m_bitfields[2];
66 COMPILE_ASSERT(sizeof(RenderStyle) == sizeof(SameSizeAsRenderStyle), RenderStyle_should_stay_small);
68 inline RenderStyle* defaultStyle()
70 DEFINE_STATIC_REF(RenderStyle, s_defaultStyle, (RenderStyle::createDefaultStyle()));
71 return s_defaultStyle;
74 PassRefPtr<RenderStyle> RenderStyle::create()
76 return adoptRef(new RenderStyle());
79 PassRefPtr<RenderStyle> RenderStyle::createDefaultStyle()
81 return adoptRef(new RenderStyle(DefaultStyle));
84 PassRefPtr<RenderStyle> RenderStyle::createAnonymousStyleWithDisplay(const RenderStyle* parentStyle, EDisplay display)
86 RefPtr<RenderStyle> newStyle = RenderStyle::create();
87 newStyle->inheritFrom(parentStyle);
88 newStyle->inheritUnicodeBidiFrom(parentStyle);
89 newStyle->setDisplay(display);
93 PassRefPtr<RenderStyle> RenderStyle::clone(const RenderStyle* other)
95 return adoptRef(new RenderStyle(*other));
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)
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);
113 ALWAYS_INLINE RenderStyle::RenderStyle(DefaultStyleTag)
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();
136 ALWAYS_INLINE RenderStyle::RenderStyle(const RenderStyle& o)
137 : RefCounted<RenderStyle>()
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)
151 static StyleRecalcChange diffPseudoStyles(const RenderStyle* oldStyle, const RenderStyle* newStyle)
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())
157 for (PseudoId pseudoId = FIRST_PUBLIC_PSEUDOID; pseudoId < FIRST_INTERNAL_PSEUDOID; pseudoId = static_cast<PseudoId>(pseudoId + 1)) {
158 if (!oldStyle->hasPseudoStyle(pseudoId))
160 RenderStyle* newPseudoStyle = newStyle->getCachedPseudoStyle(pseudoId);
163 RenderStyle* oldPseudoStyle = oldStyle->getCachedPseudoStyle(pseudoId);
164 if (oldPseudoStyle && *oldPseudoStyle != *newPseudoStyle)
170 StyleRecalcChange RenderStyle::stylePropagationDiff(const RenderStyle* oldStyle, const RenderStyle* newStyle)
172 if ((!oldStyle && newStyle) || (oldStyle && !newStyle))
175 if (!oldStyle && !newStyle)
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())
187 if (*oldStyle == *newStyle)
188 return diffPseudoStyles(oldStyle, newStyle);
190 if (oldStyle->inheritedNotEqual(newStyle)
191 || oldStyle->hasExplicitlyInheritedProperties()
192 || newStyle->hasExplicitlyInheritedProperties())
198 void RenderStyle::inheritFrom(const RenderStyle* inheritParent, IsAtShadowBoundary isAtShadowBoundary)
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);
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());
213 void RenderStyle::copyNonInheritedFrom(const RenderStyle* other)
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());
242 bool RenderStyle::operator==(const RenderStyle& o) const
244 // compare everything except the pseudoStyle pointer
245 return inherited_flags == o.inherited_flags
246 && noninherited_flags == o.noninherited_flags
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;
257 bool RenderStyle::isStyleAvailable() const
259 return this != StyleResolver::styleNotYetAvailable();
262 bool RenderStyle::hasUniquePseudoStyle() const
264 if (!m_cachedPseudoStyles || styleType() != NOPSEUDO)
267 for (size_t i = 0; i < m_cachedPseudoStyles->size(); ++i) {
268 RenderStyle* pseudoStyle = m_cachedPseudoStyles->at(i).get();
269 if (pseudoStyle->unique())
276 RenderStyle* RenderStyle::getCachedPseudoStyle(PseudoId pid) const
278 if (!m_cachedPseudoStyles || !m_cachedPseudoStyles->size())
281 if (styleType() != NOPSEUDO)
284 for (size_t i = 0; i < m_cachedPseudoStyles->size(); ++i) {
285 RenderStyle* pseudoStyle = m_cachedPseudoStyles->at(i).get();
286 if (pseudoStyle->styleType() == pid)
293 RenderStyle* RenderStyle::addCachedPseudoStyle(PassRefPtr<RenderStyle> pseudo)
298 ASSERT(pseudo->styleType() > NOPSEUDO);
300 RenderStyle* result = pseudo.get();
302 if (!m_cachedPseudoStyles)
303 m_cachedPseudoStyles = adoptPtr(new PseudoStyleCache);
305 m_cachedPseudoStyles->append(pseudo);
310 void RenderStyle::removeCachedPseudoStyle(PseudoId pid)
312 if (!m_cachedPseudoStyles)
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);
323 bool RenderStyle::inheritedNotEqual(const RenderStyle* other) const
325 return inherited_flags != other->inherited_flags
326 || inherited != other->inherited
327 || m_svgStyle->inheritedNotEqual(other->m_svgStyle.get())
328 || rareInheritedData != other->rareInheritedData;
331 bool RenderStyle::inheritedDataShared(const RenderStyle* other) const
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();
340 static bool positionedObjectMovedOnly(const LengthBox& a, const LengthBox& b, const Length& width)
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())
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())
355 if (!a.top().isIntrinsicOrAuto() && !a.bottom().isIntrinsicOrAuto())
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())))
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.
369 StyleDifference RenderStyle::visualInvalidationDiff(const RenderStyle& other) const
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.
375 StyleDifference diff;
376 if (m_svgStyle.get() != other.m_svgStyle.get())
377 diff = m_svgStyle->diff(other.m_svgStyle.get());
379 if ((!diff.needsFullLayout() || !diff.needsPaintInvalidation()) && diffNeedsFullLayoutAndPaintInvalidation(other)) {
380 diff.setNeedsFullLayout();
381 diff.setNeedsPaintInvalidationObject();
384 if (!diff.needsFullLayout() && diffNeedsFullLayout(other))
385 diff.setNeedsFullLayout();
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();
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();
400 if (diffNeedsPaintInvalidationLayer(other))
401 diff.setNeedsPaintInvalidationLayer();
402 else if (diffNeedsPaintInvalidationObject(other))
403 diff.setNeedsPaintInvalidationObject();
405 updatePropertySpecificDifferences(other, diff);
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.
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.
416 bool RenderStyle::diffNeedsFullLayoutAndPaintInvalidation(const RenderStyle& other) const
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.
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())
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())
453 if (rareNonInheritedData->m_deprecatedFlexibleBox.get() != other.rareNonInheritedData->m_deprecatedFlexibleBox.get()
454 && *rareNonInheritedData->m_deprecatedFlexibleBox.get() != *other.rareNonInheritedData->m_deprecatedFlexibleBox.get())
457 if (rareNonInheritedData->m_flexibleBox.get() != other.rareNonInheritedData->m_flexibleBox.get()
458 && *rareNonInheritedData->m_flexibleBox.get() != *other.rareNonInheritedData->m_flexibleBox.get())
461 // FIXME: We should add an optimized form of layout that just recomputes visual overflow.
462 if (!rareNonInheritedData->shadowDataEquivalent(*other.rareNonInheritedData.get()))
465 if (!rareNonInheritedData->reflectionDataEquivalent(*other.rareNonInheritedData.get()))
468 if (rareNonInheritedData->m_multiCol.get() != other.rareNonInheritedData->m_multiCol.get()
469 && *rareNonInheritedData->m_multiCol.get() != *other.rareNonInheritedData->m_multiCol.get())
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)))
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.
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)
517 if (!rareInheritedData->shadowDataEquivalent(*other.rareInheritedData.get()))
520 if (!rareInheritedData->quotesDataEquivalent(*other.rareInheritedData.get()))
524 if (inherited->textAutosizingMultiplier != other.inherited->textAutosizingMultiplier)
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)
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)
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)
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)
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)))
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)
578 if ((visibility() == COLLAPSE) != (other.visibility() == COLLAPSE))
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.
586 // Movement of non-static-positioned object is special cased in RenderStyle::visualInvalidationDiff().
591 bool RenderStyle::diffNeedsFullLayout(const RenderStyle& other) const
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())
602 if (m_box->verticalAlign() != other.m_box->verticalAlign())
605 if (m_box->boxSizing() != other.m_box->boxSizing())
609 if (noninherited_flags.verticalAlign != other.noninherited_flags.verticalAlign)
612 if (surround.get() != other.surround.get()) {
613 if (surround->margin != other.surround->margin)
616 if (surround->padding != other.surround->padding)
623 bool RenderStyle::diffNeedsPaintInvalidationLayer(const RenderStyle& other) const
625 if (position() != StaticPosition && (visual->clip != other.visual->clip || visual->hasClip != other.visual->hasClip))
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))
634 if (rareNonInheritedData->m_mask != other.rareNonInheritedData->m_mask
635 || rareNonInheritedData->m_maskBoxImage != other.rareNonInheritedData->m_maskBoxImage)
642 bool RenderStyle::diffNeedsPaintInvalidationObject(const RenderStyle& other) const
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))
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)
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)
671 void RenderStyle::updatePropertySpecificDifferences(const RenderStyle& other, StyleDifference& diff) const
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();
677 if (rareNonInheritedData.get() != other.rareNonInheritedData.get()) {
678 if (!transformDataEquivalent(other))
679 diff.setTransformChanged();
681 if (rareNonInheritedData->opacity != other.rareNonInheritedData->opacity)
682 diff.setOpacityChanged();
684 if (rareNonInheritedData->m_filter != other.rareNonInheritedData->m_filter)
685 diff.setFilterChanged();
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();
708 void RenderStyle::setClip(const Length& top, const Length& right, const Length& bottom, const Length& left)
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;
717 void RenderStyle::addCursor(PassRefPtr<StyleImage> image, const IntPoint& hotSpot)
719 if (!rareInheritedData.access()->cursorData)
720 rareInheritedData.access()->cursorData = CursorList::create();
721 rareInheritedData.access()->cursorData->append(CursorData(image, hotSpot));
724 void RenderStyle::setCursorList(PassRefPtr<CursorList> other)
726 rareInheritedData.access()->cursorData = other;
729 void RenderStyle::setQuotes(PassRefPtr<QuotesData> q)
731 rareInheritedData.access()->quotes = q;
734 void RenderStyle::clearCursorList()
736 if (rareInheritedData->cursorData)
737 rareInheritedData.access()->cursorData = nullptr;
740 void RenderStyle::addCallbackSelector(const String& selector)
742 if (!rareNonInheritedData->m_callbackSelectors.contains(selector))
743 rareNonInheritedData.access()->m_callbackSelectors.append(selector);
746 void RenderStyle::clearContent()
748 if (rareNonInheritedData->m_content)
749 rareNonInheritedData.access()->m_content = nullptr;
752 void RenderStyle::appendContent(PassOwnPtr<ContentData> contentData)
754 OwnPtr<ContentData>& content = rareNonInheritedData.access()->m_content;
755 ContentData* lastContent = content.get();
756 while (lastContent && lastContent->next())
757 lastContent = lastContent->next();
760 lastContent->setNext(contentData);
762 content = contentData;
765 void RenderStyle::setContent(PassRefPtr<StyleImage> image, bool add)
771 appendContent(ContentData::create(image));
775 rareNonInheritedData.access()->m_content = ContentData::create(image);
778 void RenderStyle::setContent(const String& string, bool add)
780 OwnPtr<ContentData>& content = rareNonInheritedData.access()->m_content;
782 ContentData* lastContent = content.get();
783 while (lastContent && lastContent->next())
784 lastContent = lastContent->next();
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);
792 lastContent->setNext(ContentData::create(string));
798 content = ContentData::create(string);
801 void RenderStyle::setContent(PassOwnPtr<CounterContent> counter, bool add)
807 appendContent(ContentData::create(counter));
811 rareNonInheritedData.access()->m_content = ContentData::create(counter);
814 void RenderStyle::setContent(QuoteType quote, bool add)
817 appendContent(ContentData::create(quote));
821 rareNonInheritedData.access()->m_content = ContentData::create(quote);
824 WebBlendMode RenderStyle::blendMode() const
826 if (RuntimeEnabledFeatures::cssCompositingEnabled())
827 return static_cast<WebBlendMode>(rareNonInheritedData->m_effectiveBlendMode);
828 return WebBlendModeNormal;
831 void RenderStyle::setBlendMode(WebBlendMode v)
833 if (RuntimeEnabledFeatures::cssCompositingEnabled())
834 rareNonInheritedData.access()->m_effectiveBlendMode = v;
837 bool RenderStyle::hasBlendMode() const
839 if (RuntimeEnabledFeatures::cssCompositingEnabled())
840 return static_cast<WebBlendMode>(rareNonInheritedData->m_effectiveBlendMode) != WebBlendModeNormal;
844 EIsolation RenderStyle::isolation() const
846 if (RuntimeEnabledFeatures::cssCompositingEnabled())
847 return static_cast<EIsolation>(rareNonInheritedData->m_isolation);
848 return IsolationAuto;
851 void RenderStyle::setIsolation(EIsolation v)
853 if (RuntimeEnabledFeatures::cssCompositingEnabled())
854 rareNonInheritedData.access()->m_isolation = v;
857 bool RenderStyle::hasIsolation() const
859 if (RuntimeEnabledFeatures::cssCompositingEnabled())
860 return rareNonInheritedData->m_isolation != IsolationAuto;
864 bool RenderStyle::hasWillChangeCompositingHint() const
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:
872 case CSSPropertyLeft:
873 case CSSPropertyBottom:
874 case CSSPropertyRight:
883 inline bool requireTransformOrigin(const Vector<RefPtr<TransformOperation> >& transformOperations, RenderStyle::ApplyTransformOrigin applyOrigin)
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
888 if (applyOrigin != RenderStyle::IncludeTransformOrigin)
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)
905 void RenderStyle::applyTransform(TransformationMatrix& transform, const LayoutSize& borderBoxSize, ApplyTransformOrigin applyOrigin) const
907 applyTransform(transform, FloatRect(FloatPoint(), borderBoxSize), applyOrigin);
910 void RenderStyle::applyTransform(TransformationMatrix& transform, const FloatRect& boundingBox, ApplyTransformOrigin applyOrigin) const
912 const Vector<RefPtr<TransformOperation> >& transformOperations = rareNonInheritedData->m_transform->m_operations.operations();
913 bool applyTransformOrigin = requireTransformOrigin(transformOperations, applyOrigin);
915 float offsetX = transformOriginX().type() == Percent ? boundingBox.x() : 0;
916 float offsetY = transformOriginY().type() == Percent ? boundingBox.y() : 0;
918 if (applyTransformOrigin) {
919 transform.translate3d(floatValueForLength(transformOriginX(), boundingBox.width()) + offsetX,
920 floatValueForLength(transformOriginY(), boundingBox.height()) + offsetY,
924 unsigned size = transformOperations.size();
925 for (unsigned i = 0; i < size; ++i)
926 transformOperations[i]->apply(transform, boundingBox.size());
928 if (applyTransformOrigin) {
929 transform.translate3d(-floatValueForLength(transformOriginX(), boundingBox.width()) - offsetX,
930 -floatValueForLength(transformOriginY(), boundingBox.height()) - offsetY,
931 -transformOriginZ());
935 void RenderStyle::setTextShadow(PassRefPtr<ShadowList> s)
937 rareInheritedData.access()->textShadow = s;
940 void RenderStyle::setBoxShadow(PassRefPtr<ShadowList> s)
942 rareNonInheritedData.access()->m_boxShadow = s;
945 static RoundedRect::Radii calcRadiiFor(const BorderData& border, IntSize size)
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())));
958 StyleImage* RenderStyle::listStyleImage() const { return rareInheritedData->listStyleImage.get(); }
959 void RenderStyle::setListStyleImage(PassRefPtr<StyleImage> v)
961 if (rareInheritedData->listStyleImage != v)
962 rareInheritedData.access()->listStyleImage = v;
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); }
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); }
975 RoundedRect RenderStyle::getRoundedBorderFor(const LayoutRect& borderRect, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
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);
987 RoundedRect RenderStyle::getRoundedInnerBorderFor(const LayoutRect& borderRect, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
989 bool horizontal = isHorizontalWritingMode();
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;
996 return getRoundedInnerBorderFor(borderRect, topWidth, bottomWidth, leftWidth, rightWidth, includeLogicalLeftEdge, includeLogicalRightEdge);
999 RoundedRect RenderStyle::getRoundedInnerBorderFor(const LayoutRect& borderRect,
1000 int topWidth, int bottomWidth, int leftWidth, int rightWidth, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
1002 LayoutRect innerRect(borderRect.x() + leftWidth,
1003 borderRect.y() + topWidth,
1004 borderRect.width() - leftWidth - rightWidth,
1005 borderRect.height() - topWidth - bottomWidth);
1007 RoundedRect roundedRect(pixelSnappedIntRect(innerRect));
1009 if (hasBorderRadius()) {
1010 RoundedRect::Radii radii = getRoundedBorderFor(borderRect).radii();
1011 radii.shrink(topWidth, bottomWidth, leftWidth, rightWidth);
1012 roundedRect.includeLogicalEdges(radii, isHorizontalWritingMode(), includeLogicalLeftEdge, includeLogicalRightEdge);
1017 static bool allLayersAreFixed(const FillLayer& layer)
1019 for (const FillLayer* currLayer = &layer; currLayer; currLayer = currLayer->next()) {
1020 if (!currLayer->image() || currLayer->attachment() != FixedBackgroundAttachment)
1027 bool RenderStyle::hasEntirelyFixedBackground() const
1029 return allLayersAreFixed(backgroundLayers());
1032 const CounterDirectiveMap* RenderStyle::counterDirectives() const
1034 return rareNonInheritedData->m_counterDirectives.get();
1037 CounterDirectiveMap& RenderStyle::accessCounterDirectives()
1039 OwnPtr<CounterDirectiveMap>& map = rareNonInheritedData.access()->m_counterDirectives;
1041 map = adoptPtr(new CounterDirectiveMap);
1045 const CounterDirectives RenderStyle::getCounterDirectives(const AtomicString& identifier) const
1047 if (const CounterDirectiveMap* directives = counterDirectives())
1048 return directives->get(identifier);
1049 return CounterDirectives();
1052 const AtomicString& RenderStyle::hyphenString() const
1054 const AtomicString& hyphenationString = rareInheritedData.get()->hyphenationString;
1055 if (!hyphenationString.isNull())
1056 return hyphenationString;
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;
1064 const AtomicString& RenderStyle::textEmphasisMarkString() const
1066 switch (textEmphasisMark()) {
1067 case TextEmphasisMarkNone:
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;
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;
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;
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;
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;
1096 case TextEmphasisMarkAuto:
1097 ASSERT_NOT_REACHED();
1101 ASSERT_NOT_REACHED();
1105 CSSAnimationData& RenderStyle::accessAnimations()
1107 if (!rareNonInheritedData.access()->m_animations)
1108 rareNonInheritedData.access()->m_animations = CSSAnimationData::create();
1109 return *rareNonInheritedData->m_animations;
1112 CSSTransitionData& RenderStyle::accessTransitions()
1114 if (!rareNonInheritedData.access()->m_transitions)
1115 rareNonInheritedData.access()->m_transitions = CSSTransitionData::create();
1116 return *rareNonInheritedData->m_transitions;
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(); }
1128 TextDecoration RenderStyle::textDecorationsInEffect() const
1130 int decorations = 0;
1132 const Vector<AppliedTextDecoration>& applied = appliedTextDecorations();
1134 for (size_t i = 0; i < applied.size(); ++i)
1135 decorations |= applied[i].line();
1137 return static_cast<TextDecoration>(decorations);
1140 const Vector<AppliedTextDecoration>& RenderStyle::appliedTextDecorations() const
1142 if (!inherited_flags.m_textUnderline && !rareInheritedData->appliedTextDecorations) {
1143 DEFINE_STATIC_LOCAL(Vector<AppliedTextDecoration>, empty, ());
1146 if (inherited_flags.m_textUnderline) {
1147 DEFINE_STATIC_LOCAL(Vector<AppliedTextDecoration>, underline, (1, AppliedTextDecoration(TextDecorationUnderline)));
1151 return rareInheritedData->appliedTextDecorations->vector();
1154 float RenderStyle::wordSpacing() const { return fontDescription().wordSpacing(); }
1155 float RenderStyle::letterSpacing() const { return fontDescription().letterSpacing(); }
1157 bool RenderStyle::setFontDescription(const FontDescription& v)
1159 if (inherited->font.fontDescription() != v) {
1160 inherited.access()->font = Font(v);
1166 const Length& RenderStyle::specifiedLineHeight() const { return inherited->line_height; }
1167 Length RenderStyle::lineHeight() const
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);
1181 void RenderStyle::setLineHeight(const Length& specifiedLineHeight) { SET_VAR(inherited, line_height, specifiedLineHeight); }
1183 int RenderStyle::computedLineHeight() const
1185 const Length& lh = lineHeight();
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();
1192 return minimumValueForLength(lh, fontSize());
1197 void RenderStyle::setWordSpacing(float wordSpacing)
1199 FontSelector* currentFontSelector = font().fontSelector();
1200 FontDescription desc(fontDescription());
1201 desc.setWordSpacing(wordSpacing);
1202 setFontDescription(desc);
1203 font().update(currentFontSelector);
1206 void RenderStyle::setLetterSpacing(float letterSpacing)
1208 FontSelector* currentFontSelector = font().fontSelector();
1209 FontDescription desc(fontDescription());
1210 desc.setLetterSpacing(letterSpacing);
1211 setFontDescription(desc);
1212 font().update(currentFontSelector);
1215 void RenderStyle::setFontSize(float size)
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).
1220 ASSERT(std::isfinite(size));
1221 if (!std::isfinite(size) || size < 0)
1224 size = std::min(maximumAllowedFontSize, size);
1226 FontSelector* currentFontSelector = font().fontSelector();
1227 FontDescription desc(fontDescription());
1228 desc.setSpecifiedSize(size);
1229 desc.setComputedSize(size);
1231 float multiplier = textAutosizingMultiplier();
1232 if (multiplier > 1) {
1233 float autosizedFontSize = TextAutosizer::computeAutosizedFontSize(size, multiplier);
1234 desc.setComputedSize(std::min(maximumAllowedFontSize, autosizedFontSize));
1237 setFontDescription(desc);
1238 font().update(currentFontSelector);
1241 void RenderStyle::setFontWeight(FontWeight weight)
1243 FontSelector* currentFontSelector = font().fontSelector();
1244 FontDescription desc(fontDescription());
1245 desc.setWeight(weight);
1246 setFontDescription(desc);
1247 font().update(currentFontSelector);
1250 void RenderStyle::addAppliedTextDecoration(const AppliedTextDecoration& decoration)
1252 RefPtr<AppliedTextDecorationList>& list = rareInheritedData.access()->appliedTextDecorations;
1255 list = AppliedTextDecorationList::create();
1256 else if (!list->hasOneRef())
1257 list = list->copy();
1259 if (inherited_flags.m_textUnderline) {
1260 inherited_flags.m_textUnderline = false;
1261 list->append(AppliedTextDecoration(TextDecorationUnderline));
1264 list->append(decoration);
1267 void RenderStyle::applyTextDecorations()
1269 if (textDecoration() == TextDecorationNone)
1272 TextDecorationStyle style = textDecorationStyle();
1273 StyleColor styleColor = visitedDependentDecorationStyleColor();
1275 int decorations = textDecoration();
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);
1282 if (!rareInheritedData->appliedTextDecorations && underline.isSimpleUnderline())
1283 inherited_flags.m_textUnderline = true;
1285 addAppliedTextDecoration(underline);
1287 if (decorations & TextDecorationOverline)
1288 addAppliedTextDecoration(AppliedTextDecoration(TextDecorationOverline, style, styleColor));
1289 if (decorations & TextDecorationLineThrough)
1290 addAppliedTextDecoration(AppliedTextDecoration(TextDecorationLineThrough, style, styleColor));
1293 void RenderStyle::clearAppliedTextDecorations()
1295 inherited_flags.m_textUnderline = false;
1297 if (rareInheritedData->appliedTextDecorations)
1298 rareInheritedData.access()->appliedTextDecorations = nullptr;
1301 void RenderStyle::setFontStretch(FontStretch stretch)
1303 FontSelector* currentFontSelector = font().fontSelector();
1304 FontDescription desc(fontDescription());
1305 desc.setStretch(stretch);
1306 setFontDescription(desc);
1307 font().update(currentFontSelector);
1310 void RenderStyle::getShadowExtent(const ShadowList* shadowList, LayoutUnit &top, LayoutUnit &right, LayoutUnit &bottom, LayoutUnit &left) const
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)
1322 float blurAndSpread = shadow.blur() + shadow.spread();
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);
1331 LayoutBoxExtent RenderStyle::getShadowInsetExtent(const ShadowList* shadowList) const
1334 LayoutUnit right = 0;
1335 LayoutUnit bottom = 0;
1336 LayoutUnit left = 0;
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)
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);
1350 return LayoutBoxExtent(top, right, bottom, left);
1353 void RenderStyle::getShadowHorizontalExtent(const ShadowList* shadowList, LayoutUnit &left, LayoutUnit &right) const
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)
1363 float blurAndSpread = shadow.blur() + shadow.spread();
1365 left = std::min<LayoutUnit>(left, shadow.x() - blurAndSpread);
1366 right = std::max<LayoutUnit>(right, shadow.x() + blurAndSpread);
1370 void RenderStyle::getShadowVerticalExtent(const ShadowList* shadowList, LayoutUnit &top, LayoutUnit &bottom) const
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)
1380 float blurAndSpread = shadow.blur() + shadow.spread();
1382 top = std::min<LayoutUnit>(top, shadow.y() - blurAndSpread);
1383 bottom = std::max<LayoutUnit>(bottom, shadow.y() + blurAndSpread);
1387 StyleColor RenderStyle::visitedDependentDecorationStyleColor() const
1389 bool isVisited = insideLink() == InsideVisitedLink;
1391 StyleColor styleColor = isVisited ? visitedLinkTextDecorationColor() : textDecorationColor();
1393 if (!styleColor.isCurrentColor())
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;
1403 return isVisited ? visitedLinkTextFillColor() : textFillColor();
1406 Color RenderStyle::visitedDependentDecorationColor() const
1408 bool isVisited = insideLink() == InsideVisitedLink;
1409 return visitedDependentDecorationStyleColor().resolve(isVisited ? visitedLinkColor() : color());
1412 Color RenderStyle::colorIncludingFallback(int colorProperty, bool visitedLink) const
1414 StyleColor result(StyleColor::currentColor());
1415 EBorderStyle borderStyle = BNONE;
1416 switch (colorProperty) {
1417 case CSSPropertyBackgroundColor:
1418 result = visitedLink ? visitedLinkBackgroundColor() : backgroundColor();
1420 case CSSPropertyBorderLeftColor:
1421 result = visitedLink ? visitedLinkBorderLeftColor() : borderLeftColor();
1422 borderStyle = borderLeftStyle();
1424 case CSSPropertyBorderRightColor:
1425 result = visitedLink ? visitedLinkBorderRightColor() : borderRightColor();
1426 borderStyle = borderRightStyle();
1428 case CSSPropertyBorderTopColor:
1429 result = visitedLink ? visitedLinkBorderTopColor() : borderTopColor();
1430 borderStyle = borderTopStyle();
1432 case CSSPropertyBorderBottomColor:
1433 result = visitedLink ? visitedLinkBorderBottomColor() : borderBottomColor();
1434 borderStyle = borderBottomStyle();
1436 case CSSPropertyColor:
1437 result = visitedLink ? visitedLinkColor() : color();
1439 case CSSPropertyOutlineColor:
1440 result = visitedLink ? visitedLinkOutlineColor() : outlineColor();
1442 case CSSPropertyWebkitColumnRuleColor:
1443 result = visitedLink ? visitedLinkColumnRuleColor() : columnRuleColor();
1445 case CSSPropertyWebkitTextEmphasisColor:
1446 result = visitedLink ? visitedLinkTextEmphasisColor() : textEmphasisColor();
1448 case CSSPropertyWebkitTextFillColor:
1449 result = visitedLink ? visitedLinkTextFillColor() : textFillColor();
1451 case CSSPropertyWebkitTextStrokeColor:
1452 result = visitedLink ? visitedLinkTextStrokeColor() : textStrokeColor();
1454 case CSSPropertyFloodColor:
1455 result = floodColor();
1457 case CSSPropertyLightingColor:
1458 result = lightingColor();
1460 case CSSPropertyStopColor:
1461 result = stopColor();
1463 case CSSPropertyWebkitTapHighlightColor:
1464 result = tapHighlightColor();
1467 ASSERT_NOT_REACHED();
1471 if (!result.isCurrentColor())
1472 return result.color();
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();
1481 Color RenderStyle::visitedDependentColor(int colorProperty) const
1483 Color unvisitedColor = colorIncludingFallback(colorProperty, false);
1484 if (insideLink() != InsideVisitedLink)
1485 return unvisitedColor;
1487 Color visitedColor = colorIncludingFallback(colorProperty, true);
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;
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());
1501 const BorderValue& RenderStyle::borderBefore() const
1503 switch (writingMode()) {
1504 case TopToBottomWritingMode:
1506 case BottomToTopWritingMode:
1507 return borderBottom();
1508 case LeftToRightWritingMode:
1509 return borderLeft();
1510 case RightToLeftWritingMode:
1511 return borderRight();
1513 ASSERT_NOT_REACHED();
1517 const BorderValue& RenderStyle::borderAfter() const
1519 switch (writingMode()) {
1520 case TopToBottomWritingMode:
1521 return borderBottom();
1522 case BottomToTopWritingMode:
1524 case LeftToRightWritingMode:
1525 return borderRight();
1526 case RightToLeftWritingMode:
1527 return borderLeft();
1529 ASSERT_NOT_REACHED();
1530 return borderBottom();
1533 const BorderValue& RenderStyle::borderStart() const
1535 if (isHorizontalWritingMode())
1536 return isLeftToRightDirection() ? borderLeft() : borderRight();
1537 return isLeftToRightDirection() ? borderTop() : borderBottom();
1540 const BorderValue& RenderStyle::borderEnd() const
1542 if (isHorizontalWritingMode())
1543 return isLeftToRightDirection() ? borderRight() : borderLeft();
1544 return isLeftToRightDirection() ? borderBottom() : borderTop();
1547 unsigned short RenderStyle::borderBeforeWidth() const
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();
1559 ASSERT_NOT_REACHED();
1560 return borderTopWidth();
1563 unsigned short RenderStyle::borderAfterWidth() const
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();
1575 ASSERT_NOT_REACHED();
1576 return borderBottomWidth();
1579 unsigned short RenderStyle::borderStartWidth() const
1581 if (isHorizontalWritingMode())
1582 return isLeftToRightDirection() ? borderLeftWidth() : borderRightWidth();
1583 return isLeftToRightDirection() ? borderTopWidth() : borderBottomWidth();
1586 unsigned short RenderStyle::borderEndWidth() const
1588 if (isHorizontalWritingMode())
1589 return isLeftToRightDirection() ? borderRightWidth() : borderLeftWidth();
1590 return isLeftToRightDirection() ? borderBottomWidth() : borderTopWidth();
1593 void RenderStyle::setMarginStart(const Length& margin)
1595 if (isHorizontalWritingMode()) {
1596 if (isLeftToRightDirection())
1597 setMarginLeft(margin);
1599 setMarginRight(margin);
1601 if (isLeftToRightDirection())
1602 setMarginTop(margin);
1604 setMarginBottom(margin);
1608 void RenderStyle::setMarginEnd(const Length& margin)
1610 if (isHorizontalWritingMode()) {
1611 if (isLeftToRightDirection())
1612 setMarginRight(margin);
1614 setMarginLeft(margin);
1616 if (isLeftToRightDirection())
1617 setMarginBottom(margin);
1619 setMarginTop(margin);
1623 TextEmphasisMark RenderStyle::textEmphasisMark() const
1625 TextEmphasisMark mark = static_cast<TextEmphasisMark>(rareInheritedData->textEmphasisMark);
1626 if (mark != TextEmphasisMarkAuto)
1629 if (isHorizontalWritingMode())
1630 return TextEmphasisMarkDot;
1632 return TextEmphasisMarkSesame;
1635 Color RenderStyle::initialTapHighlightColor()
1637 return RenderTheme::tapHighlightColor();
1640 LayoutBoxExtent RenderStyle::imageOutsets(const NinePieceImage& image) const
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()));
1648 void RenderStyle::setBorderImageSource(PassRefPtr<StyleImage> image)
1650 if (surround->border.m_image.image() == image.get())
1652 surround.access()->border.m_image.setImage(image);
1655 void RenderStyle::setBorderImageSlices(const LengthBox& slices)
1657 if (surround->border.m_image.imageSlices() == slices)
1659 surround.access()->border.m_image.setImageSlices(slices);
1662 void RenderStyle::setBorderImageWidth(const BorderImageLengthBox& slices)
1664 if (surround->border.m_image.borderSlices() == slices)
1666 surround.access()->border.m_image.setBorderSlices(slices);
1669 void RenderStyle::setBorderImageOutset(const BorderImageLengthBox& outset)
1671 if (surround->border.m_image.outset() == outset)
1673 surround.access()->border.m_image.setOutset(outset);
1676 float calcBorderRadiiConstraintScaleFor(const FloatRect& rect, const FloatRoundedRect::Radii& radii)
1678 // Constrain corner radii using CSS3 rules:
1679 // http://www.w3.org/TR/css3-background/#the-border-radius
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);
1690 radiiSum = radii.bottomLeft().width() + radii.bottomRight().width();
1691 if (radiiSum > rect.width())
1692 factor = std::min(rect.width() / radiiSum, factor);
1695 radiiSum = radii.topLeft().height() + radii.bottomLeft().height();
1696 if (radiiSum > rect.height())
1697 factor = std::min(rect.height() / radiiSum, factor);
1700 radiiSum = radii.topRight().height() + radii.bottomRight().height();
1701 if (radiiSum > rect.height())
1702 factor = std::min(rect.height() / radiiSum, factor);
1704 ASSERT(factor <= 1);
1708 } // namespace blink