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

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

Issue 1602843003: Update StyleValue.cssString() to use existing methods instead of rolling our own. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revert TransformValue.html 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/css/cssom/StyleCalcLength.h" 5 #include "core/css/cssom/StyleCalcLength.h"
6 6
7 #include "core/css/CSSCalculationValue.h" 7 #include "core/css/CSSCalculationValue.h"
8 #include "core/css/CSSPrimitiveValue.h" 8 #include "core/css/CSSPrimitiveValue.h"
9 #include "core/css/cssom/CalcDictionary.h" 9 #include "core/css/cssom/CalcDictionary.h"
10 #include "core/css/cssom/SimpleLength.h" 10 #include "core/css/cssom/SimpleLength.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 StyleCalcLength* result = StyleCalcLength::create(this, exceptionState); 117 StyleCalcLength* result = StyleCalcLength::create(this, exceptionState);
118 for (unsigned i = 0; i < LengthUnit::Count; ++i) { 118 for (unsigned i = 0; i < LengthUnit::Count; ++i) {
119 LengthUnit lengthUnit = static_cast<LengthUnit>(i); 119 LengthUnit lengthUnit = static_cast<LengthUnit>(i);
120 if (has(lengthUnit)) { 120 if (has(lengthUnit)) {
121 result->set(m_values[i] / x, lengthUnit); 121 result->set(m_values[i] / x, lengthUnit);
122 } 122 }
123 } 123 }
124 return result; 124 return result;
125 } 125 }
126 126
127 String StyleCalcLength::cssString() const
128 {
129 StringBuilder builder;
130 builder.appendLiteral("calc(");
131 for (unsigned i = 0; i < LengthUnit::Count; ++i) {
132 LengthUnit lengthUnit = static_cast<LengthUnit>(i);
133 if (has(lengthUnit)) {
134 double value = get(lengthUnit);
135 if (value >= 0 && i > 0) {
136 builder.appendLiteral(" + ");
137 } else if (value < 0 && i > 0) {
138 builder.appendLiteral(" - ");
139 } else if (value < 0) {
140 builder.append('-');
141 }
142 builder.appendNumber(std::abs(get(lengthUnit)));
143 builder.append(lengthTypeToString(lengthUnit));
144 }
145 }
146 builder.append(')');
147 return builder.toString();
148 }
149
150 PassRefPtrWillBeRawPtr<CSSValue> StyleCalcLength::toCSSValue() const 127 PassRefPtrWillBeRawPtr<CSSValue> StyleCalcLength::toCSSValue() const
151 { 128 {
152 // Create a CSS Calc Value, then put it into a CSSPrimitiveValue 129 // Create a CSS Calc Value, then put it into a CSSPrimitiveValue
153 RefPtrWillBeRawPtr<CSSCalcExpressionNode> node; 130 RefPtrWillBeRawPtr<CSSCalcExpressionNode> node;
154 for (unsigned i = 0; i < LengthUnit::Count; ++i) { 131 for (unsigned i = 0; i < LengthUnit::Count; ++i) {
155 LengthUnit lengthUnit = static_cast<LengthUnit>(i); 132 LengthUnit lengthUnit = static_cast<LengthUnit>(i);
156 if (!has(lengthUnit)) 133 if (!has(lengthUnit))
157 break; 134 continue;
158 double value = get(lengthUnit); 135 double value = get(lengthUnit);
159 CSSPrimitiveValue::UnitType primitiveUnit; 136 CSSPrimitiveValue::UnitType primitiveUnit = lengthTypeToPrimitiveType(le ngthUnit);
160 if (lengthUnit == LengthUnit::Percent) {
161 primitiveUnit = CSSPrimitiveValue::UnitType::Percentage;
162 } else {
163 // TODO: Don't re-parse the unit here.
164 primitiveUnit = CSSPrimitiveValue::fromName(lengthTypeToString(lengt hUnit));
165 }
166 if (node) { 137 if (node) {
167 node = CSSCalcValue::createExpressionNode( 138 node = CSSCalcValue::createExpressionNode(
168 node, 139 node,
169 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(val ue, primitiveUnit)), 140 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(std ::abs(value), primitiveUnit)),
170 CalcAdd); 141 value >= 0 ? CalcAdd : CalcSubtract);
171 } else { 142 } else {
172 node = CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create( value, primitiveUnit)); 143 node = CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create( value, primitiveUnit));
173 } 144 }
174 } 145 }
175 return CSSPrimitiveValue::create(CSSCalcValue::create(node)); 146 return CSSPrimitiveValue::create(CSSCalcValue::create(node));
176 } 147 }
177 148
178 } // namespace blink 149 } // namespace blink
OLDNEW
« 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