Strange Result for getComputedStyle on borderWidth set in em

https://bugs.webkit.org/show_bug.cgi?id=18294

Reviewed by Tony Chang.

Source/WebCore:

BorderValue stores its width on a 12 bits unsigned. This patch
increase it to 27. The patch also modify the way to set the
width or to get it, we now use a unsigned rather than a short.

Test: fast/css/border-width-large.html

* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::computeLength):
* css/CSSStyleApplyProperty.cpp:
(WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
* page/animation/AnimationBase.cpp:
(WebCore::blendFunc):
(WebCore::AnimationBase::ensurePropertyMap):
* platform/animation/AnimationUtilities.h:
(WebCore::blend):
* rendering/RenderTheme.cpp:
(WebCore::RenderTheme::adjustStyle):
* rendering/style/BorderData.h:
(WebCore::BorderData::borderLeftWidth):
(WebCore::BorderData::borderRightWidth):
(WebCore::BorderData::borderTopWidth):
(WebCore::BorderData::borderBottomWidth):
* rendering/style/BorderValue.h:
(WebCore::BorderValue::width):
* rendering/style/RenderStyle.cpp:
* rendering/style/RenderStyle.h:
(WebCore::RenderStyleBitfields::borderLeftWidth):
(WebCore::RenderStyleBitfields::borderRightWidth):
(WebCore::RenderStyleBitfields::borderTopWidth):
(WebCore::RenderStyleBitfields::borderBottomWidth):
(WebCore::RenderStyleBitfields::setBorderLeftWidth):
(WebCore::RenderStyleBitfields::setBorderRightWidth):
(WebCore::RenderStyleBitfields::setBorderTopWidth):
(WebCore::RenderStyleBitfields::setBorderBottomWidth):
(WebCore::RenderStyleBitfields::initialBorderWidth):
(WebCore::RenderStyleBitfields::initialColumnRuleWidth):
(WebCore::RenderStyleBitfields::initialOutlineWidth):

LayoutTests:

This test covers that setting big values to border-width will
return correct values.

* fast/css/border-width-large-expected.txt: Added.
* fast/css/border-width-large.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@105403 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 220c2dbf
2012-01-19 Alexis Menard <alexis.menard@openbossa.org>
Strange Result for getComputedStyle on borderWidth set in em
https://bugs.webkit.org/show_bug.cgi?id=18294
Reviewed by Tony Chang.
This test covers that setting big values to border-width will
return correct values.
* fast/css/border-width-large-expected.txt: Added.
* fast/css/border-width-large.html: Added.
2012-01-18 Nikolas Zimmermann <nzimmermann@rim.com>
Differentiate between SVG/CSS width/height attributes/properties
Test for WebKit bug 18294 : Strange Result for getComputedStyle on borderWidth set in em
PASS computedStyle.getPropertyValue('border-width') is '12000px 11000px 10000px 9010px'
PASS computedStyle.getPropertyCSSValue('border-top-width').cssText is '12000px'
PASS computedStyle.getPropertyCSSValue('border-right-width').cssText is '11000px'
PASS computedStyle.getPropertyCSSValue('border-bottom-width').cssText is '10000px'
PASS computedStyle.getPropertyCSSValue('border-left-width').cssText is '9010px'
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML>
<html>
<head>
<title>Test for WebKit bug 18294 : Strange Result for getComputedStyle on borderWidth set in em</title>
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<p id="description">Test for WebKit bug <a href="https://bugs.webkit.org/show_bug.cgi?id=18294">18294</a> : Strange Result for getComputedStyle on borderWidth set in em</p>
<div id="console"></div>
<div id="tests_container">
<div id="test" style="border-style:solid;font-size:100px;"></div>
</div>
<script>
var test = document.getElementById("test");
test.style.borderWidth = "120em 110em 100em 90.1em";
var computedStyle = window.getComputedStyle(test, null);
shouldBe("computedStyle.getPropertyValue('border-width')", "'12000px 11000px 10000px 9010px'");
shouldBe("computedStyle.getPropertyCSSValue('border-top-width').cssText","'12000px'");
shouldBe("computedStyle.getPropertyCSSValue('border-right-width').cssText","'11000px'");
shouldBe("computedStyle.getPropertyCSSValue('border-bottom-width').cssText","'10000px'");
shouldBe("computedStyle.getPropertyCSSValue('border-left-width').cssText","'9010px'");
// clean up after ourselves
var tests_container = document.getElementById("tests_container");
tests_container.parentNode.removeChild(tests_container);
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
2012-01-19 Alexis Menard <alexis.menard@openbossa.org>
Strange Result for getComputedStyle on borderWidth set in em
https://bugs.webkit.org/show_bug.cgi?id=18294
Reviewed by Tony Chang.
BorderValue stores its width on a 12 bits unsigned. This patch
increase it to 27. The patch also modify the way to set the
width or to get it, we now use a unsigned rather than a short.
Test: fast/css/border-width-large.html
* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::computeLength):
* css/CSSStyleApplyProperty.cpp:
(WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
* page/animation/AnimationBase.cpp:
(WebCore::blendFunc):
(WebCore::AnimationBase::ensurePropertyMap):
* platform/animation/AnimationUtilities.h:
(WebCore::blend):
* rendering/RenderTheme.cpp:
(WebCore::RenderTheme::adjustStyle):
* rendering/style/BorderData.h:
(WebCore::BorderData::borderLeftWidth):
(WebCore::BorderData::borderRightWidth):
(WebCore::BorderData::borderTopWidth):
(WebCore::BorderData::borderBottomWidth):
* rendering/style/BorderValue.h:
(WebCore::BorderValue::width):
* rendering/style/RenderStyle.cpp:
* rendering/style/RenderStyle.h:
(WebCore::RenderStyleBitfields::borderLeftWidth):
(WebCore::RenderStyleBitfields::borderRightWidth):
(WebCore::RenderStyleBitfields::borderTopWidth):
(WebCore::RenderStyleBitfields::borderBottomWidth):
(WebCore::RenderStyleBitfields::setBorderLeftWidth):
(WebCore::RenderStyleBitfields::setBorderRightWidth):
(WebCore::RenderStyleBitfields::setBorderTopWidth):
(WebCore::RenderStyleBitfields::setBorderBottomWidth):
(WebCore::RenderStyleBitfields::initialBorderWidth):
(WebCore::RenderStyleBitfields::initialColumnRuleWidth):
(WebCore::RenderStyleBitfields::initialOutlineWidth):
2012-01-18 Nikolas Zimmermann <nzimmermann@rim.com>
Differentiate between SVG/CSS width/height attributes/properties
......@@ -360,6 +360,11 @@ template<> int CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle*
return roundForImpreciseConversion<int, INT_MAX, INT_MIN>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));
}
template<> unsigned CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
{
return roundForImpreciseConversion<unsigned, UINT_MAX, 0>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));
}
template<> Length CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
{
// FIXME: Length.h no longer expects 28 bit integers, so these bounds should be INT_MAX and INT_MIN
......
......@@ -1698,12 +1698,12 @@ CSSStyleApplyProperty::CSSStyleApplyProperty()
setPropertyHandler(CSSPropertyBorderBottomStyle, ApplyPropertyDefault<EBorderStyle, &RenderStyle::borderBottomStyle, EBorderStyle, &RenderStyle::setBorderBottomStyle, EBorderStyle, &RenderStyle::initialBorderStyle>::createHandler());
setPropertyHandler(CSSPropertyBorderLeftStyle, ApplyPropertyDefault<EBorderStyle, &RenderStyle::borderLeftStyle, EBorderStyle, &RenderStyle::setBorderLeftStyle, EBorderStyle, &RenderStyle::initialBorderStyle>::createHandler());
setPropertyHandler(CSSPropertyBorderTopWidth, ApplyPropertyComputeLength<unsigned short, &RenderStyle::borderTopWidth, &RenderStyle::setBorderTopWidth, &RenderStyle::initialBorderWidth, NormalDisabled, ThicknessEnabled>::createHandler());
setPropertyHandler(CSSPropertyBorderRightWidth, ApplyPropertyComputeLength<unsigned short, &RenderStyle::borderRightWidth, &RenderStyle::setBorderRightWidth, &RenderStyle::initialBorderWidth, NormalDisabled, ThicknessEnabled>::createHandler());
setPropertyHandler(CSSPropertyBorderBottomWidth, ApplyPropertyComputeLength<unsigned short, &RenderStyle::borderBottomWidth, &RenderStyle::setBorderBottomWidth, &RenderStyle::initialBorderWidth, NormalDisabled, ThicknessEnabled>::createHandler());
setPropertyHandler(CSSPropertyBorderLeftWidth, ApplyPropertyComputeLength<unsigned short, &RenderStyle::borderLeftWidth, &RenderStyle::setBorderLeftWidth, &RenderStyle::initialBorderWidth, NormalDisabled, ThicknessEnabled>::createHandler());
setPropertyHandler(CSSPropertyOutlineWidth, ApplyPropertyComputeLength<unsigned short, &RenderStyle::outlineWidth, &RenderStyle::setOutlineWidth, &RenderStyle::initialBorderWidth, NormalDisabled, ThicknessEnabled>::createHandler());
setPropertyHandler(CSSPropertyWebkitColumnRuleWidth, ApplyPropertyComputeLength<unsigned short, &RenderStyle::columnRuleWidth, &RenderStyle::setColumnRuleWidth, &RenderStyle::initialBorderWidth, NormalDisabled, ThicknessEnabled>::createHandler());
setPropertyHandler(CSSPropertyBorderTopWidth, ApplyPropertyComputeLength<unsigned, &RenderStyle::borderTopWidth, &RenderStyle::setBorderTopWidth, &RenderStyle::initialBorderWidth, NormalDisabled, ThicknessEnabled>::createHandler());
setPropertyHandler(CSSPropertyBorderRightWidth, ApplyPropertyComputeLength<unsigned, &RenderStyle::borderRightWidth, &RenderStyle::setBorderRightWidth, &RenderStyle::initialBorderWidth, NormalDisabled, ThicknessEnabled>::createHandler());
setPropertyHandler(CSSPropertyBorderBottomWidth, ApplyPropertyComputeLength<unsigned, &RenderStyle::borderBottomWidth, &RenderStyle::setBorderBottomWidth, &RenderStyle::initialBorderWidth, NormalDisabled, ThicknessEnabled>::createHandler());
setPropertyHandler(CSSPropertyBorderLeftWidth, ApplyPropertyComputeLength<unsigned, &RenderStyle::borderLeftWidth, &RenderStyle::setBorderLeftWidth, &RenderStyle::initialBorderWidth, NormalDisabled, ThicknessEnabled>::createHandler());
setPropertyHandler(CSSPropertyOutlineWidth, ApplyPropertyComputeLength<unsigned short, &RenderStyle::outlineWidth, &RenderStyle::setOutlineWidth, &RenderStyle::initialOutlineWidth, NormalDisabled, ThicknessEnabled>::createHandler());
setPropertyHandler(CSSPropertyWebkitColumnRuleWidth, ApplyPropertyComputeLength<unsigned short, &RenderStyle::columnRuleWidth, &RenderStyle::setColumnRuleWidth, &RenderStyle::initialColumnRuleWidth, NormalDisabled, ThicknessEnabled>::createHandler());
setPropertyHandler(CSSPropertyBorderTop, ApplyPropertyExpanding<SuppressValue, CSSPropertyBorderTopColor, CSSPropertyBorderTopStyle, CSSPropertyBorderTopWidth>::createHandler());
setPropertyHandler(CSSPropertyBorderRight, ApplyPropertyExpanding<SuppressValue, CSSPropertyBorderRightColor, CSSPropertyBorderRightStyle, CSSPropertyBorderRightWidth>::createHandler());
......
......@@ -84,6 +84,11 @@ static inline int blendFunc(const AnimationBase*, int from, int to, double progr
return blend(from, to, progress);
}
static inline unsigned blendFunc(const AnimationBase*, unsigned from, unsigned to, double progress)
{
return blend(from, to, progress);
}
static inline double blendFunc(const AnimationBase*, double from, double to, double progress)
{
return blend(from, to, progress);
......@@ -950,10 +955,10 @@ void AnimationBase::ensurePropertyMap()
gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyMinHeight, &RenderStyle::minHeight, &RenderStyle::setMinHeight));
gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyMaxHeight, &RenderStyle::maxHeight, &RenderStyle::setMaxHeight));
gPropertyWrappers->append(new PropertyWrapper<unsigned short>(CSSPropertyBorderLeftWidth, &RenderStyle::borderLeftWidth, &RenderStyle::setBorderLeftWidth));
gPropertyWrappers->append(new PropertyWrapper<unsigned short>(CSSPropertyBorderRightWidth, &RenderStyle::borderRightWidth, &RenderStyle::setBorderRightWidth));
gPropertyWrappers->append(new PropertyWrapper<unsigned short>(CSSPropertyBorderTopWidth, &RenderStyle::borderTopWidth, &RenderStyle::setBorderTopWidth));
gPropertyWrappers->append(new PropertyWrapper<unsigned short>(CSSPropertyBorderBottomWidth, &RenderStyle::borderBottomWidth, &RenderStyle::setBorderBottomWidth));
gPropertyWrappers->append(new PropertyWrapper<unsigned>(CSSPropertyBorderLeftWidth, &RenderStyle::borderLeftWidth, &RenderStyle::setBorderLeftWidth));
gPropertyWrappers->append(new PropertyWrapper<unsigned>(CSSPropertyBorderRightWidth, &RenderStyle::borderRightWidth, &RenderStyle::setBorderRightWidth));
gPropertyWrappers->append(new PropertyWrapper<unsigned>(CSSPropertyBorderTopWidth, &RenderStyle::borderTopWidth, &RenderStyle::setBorderTopWidth));
gPropertyWrappers->append(new PropertyWrapper<unsigned>(CSSPropertyBorderBottomWidth, &RenderStyle::borderBottomWidth, &RenderStyle::setBorderBottomWidth));
gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyMarginLeft, &RenderStyle::marginLeft, &RenderStyle::setMarginLeft));
gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyMarginRight, &RenderStyle::marginRight, &RenderStyle::setMarginRight));
gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyMarginTop, &RenderStyle::marginTop, &RenderStyle::setMarginTop));
......
......@@ -35,6 +35,11 @@ inline int blend(int from, int to, double progress)
return static_cast<int>(lround(static_cast<double>(from) + static_cast<double>(to - from) * progress));
}
inline unsigned blend(unsigned from, unsigned to, double progress)
{
return static_cast<unsigned>(lround(static_cast<double>(from) + static_cast<double>(to - from) * progress));
}
inline double blend(double from, double to, double progress)
{
return from + (to - from) * progress;
......
......@@ -111,26 +111,26 @@ void RenderTheme::adjustStyle(CSSStyleSelector* selector, RenderStyle* style, El
// Border
LengthBox borderBox(style->borderTopWidth(), style->borderRightWidth(), style->borderBottomWidth(), style->borderLeftWidth());
borderBox = m_theme->controlBorder(part, style->font(), borderBox, style->effectiveZoom());
if (borderBox.top().value() != style->borderTopWidth()) {
if (borderBox.top().value() != static_cast<int>(style->borderTopWidth())) {
if (borderBox.top().value())
style->setBorderTopWidth(borderBox.top().value());
else
style->resetBorderTop();
}
if (borderBox.right().value() != style->borderRightWidth()) {
if (borderBox.right().value() != static_cast<int>(style->borderRightWidth())) {
if (borderBox.right().value())
style->setBorderRightWidth(borderBox.right().value());
else
style->resetBorderRight();
}
if (borderBox.bottom().value() != style->borderBottomWidth()) {
if (borderBox.bottom().value() != static_cast<int>(style->borderBottomWidth())) {
style->setBorderBottomWidth(borderBox.bottom().value());
if (borderBox.bottom().value())
style->setBorderBottomWidth(borderBox.bottom().value());
else
style->resetBorderBottom();
}
if (borderBox.left().value() != style->borderLeftWidth()) {
if (borderBox.left().value() != static_cast<int>(style->borderLeftWidth())) {
style->setBorderLeftWidth(borderBox.left().value());
if (borderBox.left().value())
style->setBorderLeftWidth(borderBox.left().value());
......
......@@ -60,28 +60,28 @@ public:
return false;
}
unsigned short borderLeftWidth() const
unsigned borderLeftWidth() const
{
if (!m_image.hasImage() && (m_left.style() == BNONE || m_left.style() == BHIDDEN))
return 0;
return m_left.width();
}
unsigned short borderRightWidth() const
unsigned borderRightWidth() const
{
if (!m_image.hasImage() && (m_right.style() == BNONE || m_right.style() == BHIDDEN))
return 0;
return m_right.width();
}
unsigned short borderTopWidth() const
unsigned borderTopWidth() const
{
if (!m_image.hasImage() && (m_top.style() == BNONE || m_top.style() == BHIDDEN))
return 0;
return m_top.width();
}
unsigned short borderBottomWidth() const
unsigned borderBottomWidth() const
{
if (!m_image.hasImage() && (m_bottom.style() == BNONE || m_bottom.style() == BHIDDEN))
return 0;
......
......@@ -66,12 +66,12 @@ public:
}
const Color& color() const { return m_color; }
unsigned short width() const { return m_width; }
unsigned width() const { return m_width; }
EBorderStyle style() const { return static_cast<EBorderStyle>(m_style); }
protected:
Color m_color;
unsigned m_width : 12;
unsigned m_width : 27;
unsigned m_style : 4; // EBorderStyle
// This is only used by OutlineValue but moved here to keep the bits packed.
......
......@@ -44,6 +44,13 @@ using namespace std;
namespace WebCore {
struct SameSizeAsBorderValue {
Color m_color;
unsigned m_width;
};
COMPILE_ASSERT(sizeof(BorderValue) == sizeof(SameSizeAsBorderValue), BorderValue_should_not_grow);
struct SameSizeAsRenderStyle : public RefCounted<SameSizeAsRenderStyle> {
unsigned m_bitfields;
......
......@@ -545,16 +545,16 @@ public:
LengthSize borderBottomRightRadius() const { return surround->border.bottomRight(); }
bool hasBorderRadius() const { return surround->border.hasBorderRadius(); }
unsigned short borderLeftWidth() const { return surround->border.borderLeftWidth(); }
unsigned borderLeftWidth() const { return surround->border.borderLeftWidth(); }
EBorderStyle borderLeftStyle() const { return surround->border.left().style(); }
bool borderLeftIsTransparent() const { return surround->border.left().isTransparent(); }
unsigned short borderRightWidth() const { return surround->border.borderRightWidth(); }
unsigned borderRightWidth() const { return surround->border.borderRightWidth(); }
EBorderStyle borderRightStyle() const { return surround->border.right().style(); }
bool borderRightIsTransparent() const { return surround->border.right().isTransparent(); }
unsigned short borderTopWidth() const { return surround->border.borderTopWidth(); }
unsigned borderTopWidth() const { return surround->border.borderTopWidth(); }
EBorderStyle borderTopStyle() const { return surround->border.top().style(); }
bool borderTopIsTransparent() const { return surround->border.top().isTransparent(); }
unsigned short borderBottomWidth() const { return surround->border.borderBottomWidth(); }
unsigned borderBottomWidth() const { return surround->border.borderBottomWidth(); }
EBorderStyle borderBottomStyle() const { return surround->border.bottom().style(); }
bool borderBottomIsTransparent() const { return surround->border.bottom().isTransparent(); }
......@@ -1043,16 +1043,16 @@ public:
RoundedRect getRoundedInnerBorderFor(const LayoutRect& borderRect,
LayoutUnit topWidth, LayoutUnit bottomWidth, LayoutUnit leftWidth, LayoutUnit rightWidth, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const;
void setBorderLeftWidth(unsigned short v) { SET_VAR(surround, border.m_left.m_width, v) }
void setBorderLeftWidth(unsigned v) { SET_VAR(surround, border.m_left.m_width, v) }
void setBorderLeftStyle(EBorderStyle v) { SET_VAR(surround, border.m_left.m_style, v) }
void setBorderLeftColor(const Color& v) { SET_VAR(surround, border.m_left.m_color, v) }
void setBorderRightWidth(unsigned short v) { SET_VAR(surround, border.m_right.m_width, v) }
void setBorderRightWidth(unsigned v) { SET_VAR(surround, border.m_right.m_width, v) }
void setBorderRightStyle(EBorderStyle v) { SET_VAR(surround, border.m_right.m_style, v) }
void setBorderRightColor(const Color& v) { SET_VAR(surround, border.m_right.m_color, v) }
void setBorderTopWidth(unsigned short v) { SET_VAR(surround, border.m_top.m_width, v) }
void setBorderTopWidth(unsigned v) { SET_VAR(surround, border.m_top.m_width, v) }
void setBorderTopStyle(EBorderStyle v) { SET_VAR(surround, border.m_top.m_style, v) }
void setBorderTopColor(const Color& v) { SET_VAR(surround, border.m_top.m_color, v) }
void setBorderBottomWidth(unsigned short v) { SET_VAR(surround, border.m_bottom.m_width, v) }
void setBorderBottomWidth(unsigned v) { SET_VAR(surround, border.m_bottom.m_width, v) }
void setBorderBottomStyle(EBorderStyle v) { SET_VAR(surround, border.m_bottom.m_style, v) }
void setBorderBottomColor(const Color& v) { SET_VAR(surround, border.m_bottom.m_color, v) }
......@@ -1513,7 +1513,9 @@ public:
static ECursor initialCursor() { return CURSOR_AUTO; }
static Color initialColor() { return Color::black; }
static StyleImage* initialListStyleImage() { return 0; }
static unsigned short initialBorderWidth() { return 3; }
static unsigned initialBorderWidth() { return 3; }
static unsigned short initialColumnRuleWidth() { return 3; }
static unsigned short initialOutlineWidth() { return 3; }
static int initialLetterWordSpacing() { return 0; }
static Length initialSize() { return Length(); }
static Length initialMinSize() { return Length(0, Fixed); }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment