From 5f1ab04193ad0130ca8204aadaceae083aca9881 Mon Sep 17 00:00:00 2001 From: Feng Qian Date: Wed, 17 Jun 2009 12:12:20 -0700 Subject: Get WebKit r44544. --- WebCore/rendering/style/RenderStyle.cpp | 88 ++++++++++++++++++----- WebCore/rendering/style/RenderStyle.h | 92 ++++++++++++++----------- WebCore/rendering/style/StyleGeneratedImage.cpp | 23 +++++-- 3 files changed, 143 insertions(+), 60 deletions(-) (limited to 'WebCore/rendering/style') diff --git a/WebCore/rendering/style/RenderStyle.cpp b/WebCore/rendering/style/RenderStyle.cpp index fe53d30..f3a2cd9 100644 --- a/WebCore/rendering/style/RenderStyle.cpp +++ b/WebCore/rendering/style/RenderStyle.cpp @@ -32,6 +32,8 @@ #include #include +using namespace std; + namespace WebCore { inline RenderStyle* defaultStyle() @@ -56,14 +58,7 @@ PassRefPtr RenderStyle::clone(const RenderStyle* other) } RenderStyle::RenderStyle() - : box(defaultStyle()->box) - , visual(defaultStyle()->visual) - , background(defaultStyle()->background) - , surround(defaultStyle()->surround) - , rareNonInheritedData(defaultStyle()->rareNonInheritedData) - , rareInheritedData(defaultStyle()->rareInheritedData) - , inherited(defaultStyle()->inherited) - , m_pseudoState(PseudoUnknown) + : m_pseudoState(PseudoUnknown) , m_affectedByAttributeSelectors(false) , m_unique(false) , m_affectedByEmpty(false) @@ -76,6 +71,13 @@ RenderStyle::RenderStyle() , m_firstChildState(false) , m_lastChildState(false) , m_childIndex(0) + , box(defaultStyle()->box) + , visual(defaultStyle()->visual) + , background(defaultStyle()->background) + , surround(defaultStyle()->surround) + , rareNonInheritedData(defaultStyle()->rareNonInheritedData) + , rareInheritedData(defaultStyle()->rareInheritedData) + , inherited(defaultStyle()->inherited) #if ENABLE(SVG) , m_svgStyle(defaultStyle()->m_svgStyle) #endif @@ -119,15 +121,6 @@ RenderStyle::RenderStyle(bool) RenderStyle::RenderStyle(const RenderStyle& o) : RefCounted() - , inherited_flags(o.inherited_flags) - , noninherited_flags(o.noninherited_flags) - , box(o.box) - , visual(o.visual) - , background(o.background) - , surround(o.surround) - , rareNonInheritedData(o.rareNonInheritedData) - , rareInheritedData(o.rareInheritedData) - , inherited(o.inherited) , m_pseudoState(o.m_pseudoState) , m_affectedByAttributeSelectors(false) , m_unique(false) @@ -141,9 +134,18 @@ RenderStyle::RenderStyle(const RenderStyle& o) , m_firstChildState(false) , m_lastChildState(false) , m_childIndex(0) + , box(o.box) + , visual(o.visual) + , background(o.background) + , surround(o.surround) + , rareNonInheritedData(o.rareNonInheritedData) + , rareInheritedData(o.rareInheritedData) + , inherited(o.inherited) #if ENABLE(SVG) , m_svgStyle(o.m_svgStyle) #endif + , inherited_flags(o.inherited_flags) + , noninherited_flags(o.noninherited_flags) { } @@ -709,6 +711,58 @@ void RenderStyle::setBoxShadow(ShadowData* shadowData, bool add) rareData->m_boxShadow.set(shadowData); } +void RenderStyle::getBorderRadiiForRect(const IntRect& r, IntSize& topLeft, IntSize& topRight, IntSize& bottomLeft, IntSize& bottomRight) const +{ + topLeft = surround->border.topLeft; + topRight = surround->border.topRight; + + bottomLeft = surround->border.bottomLeft; + bottomRight = surround->border.bottomRight; + + // Constrain corner radii using CSS3 rules: + // http://www.w3.org/TR/css3-background/#the-border-radius + + float factor = 1; + unsigned radiiSum; + + // top + radiiSum = static_cast(topLeft.width()) + static_cast(topRight.width()); // Casts to avoid integer overflow. + if (radiiSum > static_cast(r.width())) + factor = min(static_cast(r.width()) / radiiSum, factor); + + // bottom + radiiSum = static_cast(bottomLeft.width()) + static_cast(bottomRight.width()); + if (radiiSum > static_cast(r.width())) + factor = min(static_cast(r.width()) / radiiSum, factor); + + // left + radiiSum = static_cast(topLeft.height()) + static_cast(bottomLeft.height()); + if (radiiSum > static_cast(r.height())) + factor = min(static_cast(r.height()) / radiiSum, factor); + + // right + radiiSum = static_cast(topRight.height()) + static_cast(bottomRight.height()); + if (radiiSum > static_cast(r.height())) + factor = min(static_cast(r.height()) / radiiSum, factor); + + // Scale all radii by f if necessary. + if (factor < 1) { + // If either radius on a corner becomes zero, reset both radii on that corner. + topLeft.scale(factor); + if (!topLeft.width() || !topLeft.height()) + topLeft = IntSize(); + topRight.scale(factor); + if (!topRight.width() || !topRight.height()) + topRight = IntSize(); + bottomLeft.scale(factor); + if (!bottomLeft.width() || !bottomLeft.height()) + bottomLeft = IntSize(); + bottomRight.scale(factor); + if (!bottomRight.width() || !bottomRight.height()) + bottomRight = IntSize(); + } +} + const CounterDirectiveMap* RenderStyle::counterDirectives() const { return rareNonInheritedData->m_counterDirectives.get(); diff --git a/WebCore/rendering/style/RenderStyle.h b/WebCore/rendering/style/RenderStyle.h index 32c0cf4..5062596 100644 --- a/WebCore/rendering/style/RenderStyle.h +++ b/WebCore/rendering/style/RenderStyle.h @@ -108,6 +108,45 @@ class RenderStyle: public RefCounted { friend class CSSStyleSelector; protected: + // The following bitfield is 32-bits long, which optimizes padding with the + // int refCount in the base class. Beware when adding more bits. + unsigned m_pseudoState : 3; // PseudoState + bool m_affectedByAttributeSelectors : 1; + bool m_unique : 1; + + // Bits for dynamic child matching. + bool m_affectedByEmpty : 1; + bool m_emptyState : 1; + + // We optimize for :first-child and :last-child. The other positional child selectors like nth-child or + // *-child-of-type, we will just give up and re-evaluate whenever children change at all. + bool m_childrenAffectedByFirstChildRules : 1; + bool m_childrenAffectedByLastChildRules : 1; + bool m_childrenAffectedByDirectAdjacentRules : 1; + bool m_childrenAffectedByForwardPositionalRules : 1; + bool m_childrenAffectedByBackwardPositionalRules : 1; + bool m_firstChildState : 1; + bool m_lastChildState : 1; + unsigned m_childIndex : 18; // Plenty of bits to cache an index. + + // non-inherited attributes + DataRef box; + DataRef visual; + DataRef background; + DataRef surround; + DataRef rareNonInheritedData; + + // inherited attributes + DataRef rareInheritedData; + DataRef inherited; + + // list of associated pseudo styles + RefPtr m_cachedPseudoStyle; + +#if ENABLE(SVG) + DataRef m_svgStyle; +#endif + // !START SYNC!: Keep this in sync with the copy constructor in RenderStyle.cpp // inherit @@ -149,12 +188,14 @@ protected: bool _border_collapse : 1 ; unsigned _white_space : 3; // EWhiteSpace unsigned _box_direction : 1; // EBoxDirection (CSS3 box_direction property, flexible box layout module) - + // 32 bits + // non CSS2 inherited bool _visuallyOrdered : 1; - bool _htmlHacks :1; + bool _htmlHacks : 1; bool _force_backgrounds_to_white : 1; unsigned _pointerEvents : 4; // EPointerEvents + // 39 bits } inherited_flags; // don't inherit @@ -201,45 +242,9 @@ protected: bool _affectedByDrag : 1; unsigned _pseudoBits : 7; unsigned _unicodeBidi : 2; // EUnicodeBidi + // 48 bits } noninherited_flags; - // non-inherited attributes - DataRef box; - DataRef visual; - DataRef background; - DataRef surround; - DataRef rareNonInheritedData; - - // inherited attributes - DataRef rareInheritedData; - DataRef inherited; - - // list of associated pseudo styles - RefPtr m_cachedPseudoStyle; - - unsigned m_pseudoState : 3; // PseudoState - bool m_affectedByAttributeSelectors : 1; - bool m_unique : 1; - - // Bits for dynamic child matching. - bool m_affectedByEmpty : 1; - bool m_emptyState : 1; - - // We optimize for :first-child and :last-child. The other positional child selectors like nth-child or - // *-child-of-type, we will just give up and re-evaluate whenever children change at all. - bool m_childrenAffectedByFirstChildRules : 1; - bool m_childrenAffectedByLastChildRules : 1; - bool m_childrenAffectedByDirectAdjacentRules : 1; - bool m_childrenAffectedByForwardPositionalRules : 1; - bool m_childrenAffectedByBackwardPositionalRules : 1; - bool m_firstChildState : 1; - bool m_lastChildState : 1; - unsigned m_childIndex : 18; // Plenty of bits to cache an index. - -#if ENABLE(SVG) - DataRef m_svgStyle; -#endif - // !END SYNC! protected: @@ -740,6 +745,10 @@ public: void setBackgroundColor(const Color& v) { SET_VAR(background, m_color, v) } + void setBackgroundXPosition(Length l) { SET_VAR(background, m_background.m_xPosition, l) } + void setBackgroundYPosition(Length l) { SET_VAR(background, m_background.m_yPosition, l) } + void setBackgroundSize(LengthSize l) { SET_VAR(background, m_background.m_size, l) } + void setBorderImage(const NinePieceImage& b) { SET_VAR(surround, border.image, b) } void setBorderTopLeftRadius(const IntSize& s) { SET_VAR(surround, border.topLeft, s) } @@ -754,6 +763,8 @@ public: setBorderBottomLeftRadius(s); setBorderBottomRightRadius(s); } + + void getBorderRadiiForRect(const IntRect&, IntSize& topLeft, IntSize& topRight, IntSize& bottomLeft, IntSize& bottomRight) const; void setBorderLeftWidth(unsigned short v) { SET_VAR(surround, border.left.width, v) } void setBorderLeftStyle(EBorderStyle v) { SET_VAR(surround, border.left.m_style, v) } @@ -847,6 +858,9 @@ public: } void setMaskBoxImage(const NinePieceImage& b) { SET_VAR(rareNonInheritedData, m_maskBoxImage, b) } + void setMaskXPosition(Length l) { SET_VAR(rareNonInheritedData, m_mask.m_xPosition, l) } + void setMaskYPosition(Length l) { SET_VAR(rareNonInheritedData, m_mask.m_yPosition, l) } + void setMaskSize(LengthSize l) { SET_VAR(rareNonInheritedData, m_mask.m_size, l) } void setBorderCollapse(bool collapse) { inherited_flags._border_collapse = collapse; } void setHorizontalBorderSpacing(short v) { SET_VAR(inherited, horizontal_border_spacing, v) } diff --git a/WebCore/rendering/style/StyleGeneratedImage.cpp b/WebCore/rendering/style/StyleGeneratedImage.cpp index fa361e8..610e73d 100644 --- a/WebCore/rendering/style/StyleGeneratedImage.cpp +++ b/WebCore/rendering/style/StyleGeneratedImage.cpp @@ -34,11 +34,26 @@ PassRefPtr StyleGeneratedImage::cssValue() return m_generator; } -IntSize StyleGeneratedImage::imageSize(const RenderObject* renderer, float /* multiplier */) const +IntSize StyleGeneratedImage::imageSize(const RenderObject* renderer, float multiplier) const { - // We can ignore the multiplier, since we always store a raw zoomed size. - if (m_fixedSize) - return m_generator->fixedSize(renderer); + if (m_fixedSize) { + IntSize fixedSize = m_generator->fixedSize(renderer); + if (multiplier == 1.0f) + return fixedSize; + + int width = fixedSize.width() * multiplier; + int height = fixedSize.height() * multiplier; + + // Don't let images that have a width/height >= 1 shrink below 1 when zoomed. + if (fixedSize.width() > 0) + width = max(1, width); + + if (fixedSize.height() > 0) + height = max(1, height); + + return IntSize(width, height); + } + return m_containerSize; } -- cgit v1.1