Index: third_party/WebKit/Source/core/css/cssom/StyleCalcLength.cpp |
diff --git a/third_party/WebKit/Source/core/css/cssom/StyleCalcLength.cpp b/third_party/WebKit/Source/core/css/cssom/StyleCalcLength.cpp |
index de71cd92dcf8f47a3c8afac6eef6df2824e74b85..cbcf1718382479764f50feddc534712c23b2f0dc 100644 |
--- a/third_party/WebKit/Source/core/css/cssom/StyleCalcLength.cpp |
+++ b/third_party/WebKit/Source/core/css/cssom/StyleCalcLength.cpp |
@@ -124,6 +124,29 @@ LengthValue* StyleCalcLength::divideInternal(double x, ExceptionState& exception |
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 |
{ |
// Create a CSS Calc Value, then put it into a CSSPrimitiveValue |
@@ -131,14 +154,20 @@ PassRefPtrWillBeRawPtr<CSSValue> StyleCalcLength::toCSSValue() const |
for (unsigned i = 0; i < LengthUnit::Count; ++i) { |
LengthUnit lengthUnit = static_cast<LengthUnit>(i); |
if (!has(lengthUnit)) |
- continue; |
+ break; |
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) { |
node = CSSCalcValue::createExpressionNode( |
node, |
- CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(std::abs(value), primitiveUnit)), |
- value >= 0 ? CalcAdd : CalcSubtract); |
+ CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(value, primitiveUnit)), |
+ CalcAdd); |
} else { |
node = CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(value, primitiveUnit)); |
} |