Commit 3ed7ab51 authored by meade's avatar meade Committed by Commit bot

Revert "Update StyleValue.cssString() to use existing methods instead of rolling our own."

This reverts commit 13eeea65.

The original CL was suspected of causing an 18.4% regression in
dromaeo.domcoreattr at 370280:370316 on Android Galaxy s5, so reverting
this to see if the bots recover.

reverts: https://codereview.chromium.org/1602843003

BUG=580981

Review URL: https://codereview.chromium.org/1642473002

Cr-Commit-Position: refs/heads/master@{#372056}
parent 8507a3e6
...@@ -36,40 +36,23 @@ test(function() { ...@@ -36,40 +36,23 @@ test(function() {
}, 'Test that subtracting two CalcLengths produces a new CalcLength with the correct values.'); }, 'Test that subtracting two CalcLengths produces a new CalcLength with the correct values.');
test(function() { test(function() {
var calcLength = new CalcLength({px: 1, percent: 5.2}); var calcLength = new CalcLength({px: 1, percent: 5.2});
var result = calcLength.multiply(3); var result = calcLength.multiply(3);
assert_not_equals(calcLength, result); assert_not_equals(calcLength, result);
assert_equals(result.px, 3); assert_equals(result.px, 3);
assert_approx_equals(result.percent, 15.6, 0.000001); assert_approx_equals(result.percent, 15.6, 0.000001);
}, 'Test that multiplying a CalcLength produces a new CalcLength with the correct values.'); }, 'Test that multiplying a CalcLength produces a new CalcLength with the correct values.');
test(function() { test(function() {
var calcLength = new CalcLength({px: 3, percent: 15.6}); var calcLength = new CalcLength({px: 3, percent: 15.6});
var result = calcLength.divide(3); var result = calcLength.divide(3);
assert_not_equals(calcLength, result); assert_not_equals(calcLength, result);
assert_equals(result.px, 1); assert_equals(result.px, 1);
assert_equals(result.percent, 5.2); assert_equals(result.percent, 5.2);
}, 'Test that dividing a CalcLength produces a new CalcLength with the correct values.'); }, 'Test that dividing a CalcLength produces a new CalcLength with the correct values.');
test(function() {
var values = [
{input: new CalcLength({px: 1}), cssString: 'calc(1px)'},
{input: new CalcLength({px: -1}), cssString: 'calc(-1px)'},
{input: new CalcLength({px: 1, percent: 15.6}), cssString: 'calc(1px + 15.6%)'},
{input: new CalcLength({px: 1, percent: -15.6}), cssString: 'calc(1px - 15.6%)'},
{input: new CalcLength({px: -1, percent: -15.6}), cssString: 'calc(-1px - 15.6%)'},
{input: new CalcLength({px: -1, percent: -15.6, vw: 5}), cssString: 'calc((-1px - 15.6%) + 5vw)'},
{input: new CalcLength({px: -1, percent: -15.6, vw: -5}), cssString: 'calc((-1px - 15.6%) - 5vw)'},
];
for (var i = 0; i < values.length; ++i) {
assert_equals(values[i].input.cssString, values[i].cssString);
}
}, 'Test that the CSS string method for a CalcLength produces the correct result');
</script> </script>
<body> <body>
......
...@@ -30,6 +30,11 @@ KeywordTable& keywordTable() ...@@ -30,6 +30,11 @@ KeywordTable& keywordTable()
} // namespace } // namespace
String KeywordValue::cssString() const
{
return m_keywordValue;
}
const String& KeywordValue::keywordValue() const const String& KeywordValue::keywordValue() const
{ {
return m_keywordValue; return m_keywordValue;
......
...@@ -27,6 +27,7 @@ public: ...@@ -27,6 +27,7 @@ public:
const String& keywordValue() const; const String& keywordValue() const;
String cssString() const override;
PassRefPtrWillBeRawPtr<CSSValue> toCSSValue() const override; PassRefPtrWillBeRawPtr<CSSValue> toCSSValue() const override;
private: private:
......
...@@ -161,45 +161,6 @@ const String& LengthValue::lengthTypeToString(LengthValue::LengthUnit unit) ...@@ -161,45 +161,6 @@ const String& LengthValue::lengthTypeToString(LengthValue::LengthUnit unit)
} }
} }
CSSPrimitiveValue::UnitType LengthValue::lengthTypeToPrimitiveType(LengthValue::LengthUnit unit)
{
switch (unit) {
case Px:
return CSSPrimitiveValue::UnitType::Pixels;
case Percent:
return CSSPrimitiveValue::UnitType::Percentage;
case Em:
return CSSPrimitiveValue::UnitType::Ems;
case Ex:
return CSSPrimitiveValue::UnitType::Exs;
case Ch:
return CSSPrimitiveValue::UnitType::Chs;
case Rem:
return CSSPrimitiveValue::UnitType::Rems;
case Vw:
return CSSPrimitiveValue::UnitType::ViewportWidth;
case Vh:
return CSSPrimitiveValue::UnitType::ViewportHeight;
case Vmin:
return CSSPrimitiveValue::UnitType::ViewportMin;
case Vmax:
return CSSPrimitiveValue::UnitType::ViewportMax;
case Cm:
return CSSPrimitiveValue::UnitType::Centimeters;
case Mm:
return CSSPrimitiveValue::UnitType::Millimeters;
case In:
return CSSPrimitiveValue::UnitType::Inches;
case Pc:
return CSSPrimitiveValue::UnitType::Picas;
case Pt:
return CSSPrimitiveValue::UnitType::Points;
default:
ASSERT_NOT_REACHED();
return CSSPrimitiveValue::UnitType::Pixels;
}
}
LengthValue* LengthValue::addInternal(const LengthValue*, ExceptionState&) LengthValue* LengthValue::addInternal(const LengthValue*, ExceptionState&)
{ {
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
......
...@@ -50,8 +50,7 @@ protected: ...@@ -50,8 +50,7 @@ protected:
LengthValue() {} LengthValue() {}
static LengthUnit lengthUnitFromName(const String&); static LengthUnit lengthUnitFromName(const String&);
static const String& lengthTypeToString(LengthUnit); static const String& lengthTypeToString(LengthUnit type);
static CSSPrimitiveValue::UnitType lengthTypeToPrimitiveType(LengthUnit);
virtual LengthValue* addInternal(const LengthValue* other, ExceptionState&); virtual LengthValue* addInternal(const LengthValue* other, ExceptionState&);
virtual LengthValue* subtractInternal(const LengthValue* other, ExceptionState&); virtual LengthValue* subtractInternal(const LengthValue* other, ExceptionState&);
......
...@@ -28,6 +28,8 @@ public: ...@@ -28,6 +28,8 @@ public:
m_value = value; m_value = value;
} }
String cssString() const override { return String::number(m_value); }
PassRefPtrWillBeRawPtr<CSSValue> toCSSValue() const override PassRefPtrWillBeRawPtr<CSSValue> toCSSValue() const override
{ {
return cssValuePool().createValue(m_value, CSSPrimitiveValue::UnitType:: return cssValuePool().createValue(m_value, CSSPrimitiveValue::UnitType::
......
...@@ -10,9 +10,18 @@ ...@@ -10,9 +10,18 @@
namespace blink { namespace blink {
String SimpleLength::cssString() const
{
StringBuilder s;
s.appendNumber(m_value);
s.append(unit());
return s.toString();
}
PassRefPtrWillBeRawPtr<CSSValue> SimpleLength::toCSSValue() const PassRefPtrWillBeRawPtr<CSSValue> SimpleLength::toCSSValue() const
{ {
return cssValuePool().createValue(m_value, LengthValue::lengthTypeToPrimitiveType(m_unit)); // TODO: Don't re-parse the unit.
return cssValuePool().createValue(m_value, CSSPrimitiveValue::fromName(unit()));
} }
LengthValue* SimpleLength::addInternal(const LengthValue* other, ExceptionState& exceptionState) LengthValue* SimpleLength::addInternal(const LengthValue* other, ExceptionState& exceptionState)
......
...@@ -39,6 +39,7 @@ public: ...@@ -39,6 +39,7 @@ public:
StyleValueType type() const override { return StyleValueType::SimpleLengthType; } StyleValueType type() const override { return StyleValueType::SimpleLengthType; }
String cssString() const override;
PassRefPtrWillBeRawPtr<CSSValue> toCSSValue() const override; PassRefPtrWillBeRawPtr<CSSValue> toCSSValue() const override;
protected: protected:
......
...@@ -124,6 +124,29 @@ LengthValue* StyleCalcLength::divideInternal(double x, ExceptionState& exception ...@@ -124,6 +124,29 @@ LengthValue* StyleCalcLength::divideInternal(double x, ExceptionState& exception
return result; return result;
} }
String StyleCalcLength::cssString() const
{
StringBuilder builder;
builder.appendLiteral("calc(");
for (unsigned i = 0; i < LengthUnit::Count; ++i) {
LengthUnit lengthUnit = static_cast<LengthUnit>(i);
if (has(lengthUnit)) {
double value = get(lengthUnit);
if (value >= 0 && i > 0) {
builder.appendLiteral(" + ");
} else if (value < 0 && i > 0) {
builder.appendLiteral(" - ");
} else if (value < 0) {
builder.append('-');
}
builder.appendNumber(std::abs(get(lengthUnit)));
builder.append(lengthTypeToString(lengthUnit));
}
}
builder.append(')');
return builder.toString();
}
PassRefPtrWillBeRawPtr<CSSValue> StyleCalcLength::toCSSValue() const PassRefPtrWillBeRawPtr<CSSValue> StyleCalcLength::toCSSValue() const
{ {
// Create a CSS Calc Value, then put it into a CSSPrimitiveValue // Create a CSS Calc Value, then put it into a CSSPrimitiveValue
...@@ -131,14 +154,20 @@ PassRefPtrWillBeRawPtr<CSSValue> StyleCalcLength::toCSSValue() const ...@@ -131,14 +154,20 @@ PassRefPtrWillBeRawPtr<CSSValue> StyleCalcLength::toCSSValue() const
for (unsigned i = 0; i < LengthUnit::Count; ++i) { for (unsigned i = 0; i < LengthUnit::Count; ++i) {
LengthUnit lengthUnit = static_cast<LengthUnit>(i); LengthUnit lengthUnit = static_cast<LengthUnit>(i);
if (!has(lengthUnit)) if (!has(lengthUnit))
continue; break;
double value = get(lengthUnit); double value = get(lengthUnit);
CSSPrimitiveValue::UnitType primitiveUnit = lengthTypeToPrimitiveType(lengthUnit); CSSPrimitiveValue::UnitType primitiveUnit;
if (lengthUnit == LengthUnit::Percent) {
primitiveUnit = CSSPrimitiveValue::UnitType::Percentage;
} else {
// TODO: Don't re-parse the unit here.
primitiveUnit = CSSPrimitiveValue::fromName(lengthTypeToString(lengthUnit));
}
if (node) { if (node) {
node = CSSCalcValue::createExpressionNode( node = CSSCalcValue::createExpressionNode(
node, node,
CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(std::abs(value), primitiveUnit)), CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(value, primitiveUnit)),
value >= 0 ? CalcAdd : CalcSubtract); CalcAdd);
} else { } else {
node = CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(value, primitiveUnit)); node = CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(value, primitiveUnit));
} }
......
...@@ -44,6 +44,7 @@ public: ...@@ -44,6 +44,7 @@ public:
#undef GETTER_MACRO #undef GETTER_MACRO
String cssString() const override;
PassRefPtrWillBeRawPtr<CSSValue> toCSSValue() const override; PassRefPtrWillBeRawPtr<CSSValue> toCSSValue() const override;
StyleValueType type() const override { return CalcLengthType; } StyleValueType type() const override { return CalcLengthType; }
......
...@@ -30,11 +30,8 @@ public: ...@@ -30,11 +30,8 @@ public:
static StyleValue* create(const CSSValue&); static StyleValue* create(const CSSValue&);
static ScriptValue parse(ScriptState*, const String& property, const String& cssText); static ScriptValue parse(ScriptState*, const String& property, const String& cssText);
virtual String cssString() const = 0;
virtual PassRefPtrWillBeRawPtr<CSSValue> toCSSValue() const = 0; virtual PassRefPtrWillBeRawPtr<CSSValue> toCSSValue() const = 0;
virtual String cssString() const
{
return toCSSValue()->cssText();
}
DEFINE_INLINE_VIRTUAL_TRACE() { } DEFINE_INLINE_VIRTUAL_TRACE() { }
......
...@@ -39,6 +39,8 @@ public: ...@@ -39,6 +39,8 @@ public:
size_t size() { return m_transformComponents.size(); } size_t size() { return m_transformComponents.size(); }
String cssString() const override { return String(); }
DEFINE_INLINE_VIRTUAL_TRACE() DEFINE_INLINE_VIRTUAL_TRACE()
{ {
visitor->trace(m_transformComponents); visitor->trace(m_transformComponents);
......
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