Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Unified Diff: third_party/WebKit/Source/core/css/cssom/StyleCalcLength.cpp

Issue 1642473002: Revert "Update StyleValue.cssString() to use existing methods instead of rolling our… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make sure it compiles Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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));
}
« no previous file with comments | « third_party/WebKit/Source/core/css/cssom/StyleCalcLength.h ('k') | third_party/WebKit/Source/core/css/cssom/StyleValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698