summaryrefslogtreecommitdiffstats
path: root/WebCore/rendering/style
diff options
context:
space:
mode:
authorFeng Qian <fqian@google.com>2009-06-17 12:12:20 -0700
committerFeng Qian <fqian@google.com>2009-06-17 12:12:20 -0700
commit5f1ab04193ad0130ca8204aadaceae083aca9881 (patch)
tree5a92cd389e2cfe7fb67197ce14b38469462379f8 /WebCore/rendering/style
parent194315e5a908cc8ed67d597010544803eef1ac59 (diff)
downloadexternal_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.zip
external_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.tar.gz
external_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.tar.bz2
Get WebKit r44544.
Diffstat (limited to 'WebCore/rendering/style')
-rw-r--r--WebCore/rendering/style/RenderStyle.cpp88
-rw-r--r--WebCore/rendering/style/RenderStyle.h92
-rw-r--r--WebCore/rendering/style/StyleGeneratedImage.cpp23
3 files changed, 143 insertions, 60 deletions
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 <wtf/StdLibExtras.h>
#include <algorithm>
+using namespace std;
+
namespace WebCore {
inline RenderStyle* defaultStyle()
@@ -56,14 +58,7 @@ PassRefPtr<RenderStyle> 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<RenderStyle>()
- , 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<unsigned>(topLeft.width()) + static_cast<unsigned>(topRight.width()); // Casts to avoid integer overflow.
+ if (radiiSum > static_cast<unsigned>(r.width()))
+ factor = min(static_cast<float>(r.width()) / radiiSum, factor);
+
+ // bottom
+ radiiSum = static_cast<unsigned>(bottomLeft.width()) + static_cast<unsigned>(bottomRight.width());
+ if (radiiSum > static_cast<unsigned>(r.width()))
+ factor = min(static_cast<float>(r.width()) / radiiSum, factor);
+
+ // left
+ radiiSum = static_cast<unsigned>(topLeft.height()) + static_cast<unsigned>(bottomLeft.height());
+ if (radiiSum > static_cast<unsigned>(r.height()))
+ factor = min(static_cast<float>(r.height()) / radiiSum, factor);
+
+ // right
+ radiiSum = static_cast<unsigned>(topRight.height()) + static_cast<unsigned>(bottomRight.height());
+ if (radiiSum > static_cast<unsigned>(r.height()))
+ factor = min(static_cast<float>(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<RenderStyle> {
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<StyleBoxData> box;
+ DataRef<StyleVisualData> visual;
+ DataRef<StyleBackgroundData> background;
+ DataRef<StyleSurroundData> surround;
+ DataRef<StyleRareNonInheritedData> rareNonInheritedData;
+
+ // inherited attributes
+ DataRef<StyleRareInheritedData> rareInheritedData;
+ DataRef<StyleInheritedData> inherited;
+
+ // list of associated pseudo styles
+ RefPtr<RenderStyle> m_cachedPseudoStyle;
+
+#if ENABLE(SVG)
+ DataRef<SVGRenderStyle> 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<StyleBoxData> box;
- DataRef<StyleVisualData> visual;
- DataRef<StyleBackgroundData> background;
- DataRef<StyleSurroundData> surround;
- DataRef<StyleRareNonInheritedData> rareNonInheritedData;
-
- // inherited attributes
- DataRef<StyleRareInheritedData> rareInheritedData;
- DataRef<StyleInheritedData> inherited;
-
- // list of associated pseudo styles
- RefPtr<RenderStyle> 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<SVGRenderStyle> 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<CSSValue> 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;
}