OLD | NEW |
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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 PassRefPtrWillBeRawPtr<CSSValue> StyleCalcLength::toCSSValue() const | 127 PassRefPtrWillBeRawPtr<CSSValue> StyleCalcLength::toCSSValue() const |
128 { | 128 { |
129 // Create a CSS Calc Value, then put it into a CSSPrimitiveValue | 129 // Create a CSS Calc Value, then put it into a CSSPrimitiveValue |
130 RefPtrWillBeRawPtr<CSSCalcExpressionNode> node; | 130 RefPtrWillBeRawPtr<CSSCalcExpressionNode> node = nullptr; |
131 for (unsigned i = 0; i < LengthUnit::Count; ++i) { | 131 for (unsigned i = 0; i < LengthUnit::Count; ++i) { |
132 LengthUnit lengthUnit = static_cast<LengthUnit>(i); | 132 LengthUnit lengthUnit = static_cast<LengthUnit>(i); |
133 if (!has(lengthUnit)) | 133 if (!has(lengthUnit)) |
134 continue; | 134 continue; |
135 double value = get(lengthUnit); | 135 double value = get(lengthUnit); |
136 CSSPrimitiveValue::UnitType primitiveUnit = lengthTypeToPrimitiveType(le
ngthUnit); | 136 CSSPrimitiveValue::UnitType primitiveUnit = lengthTypeToPrimitiveType(le
ngthUnit); |
137 if (node) { | 137 if (node) { |
138 node = CSSCalcValue::createExpressionNode( | 138 node = CSSCalcValue::createExpressionNode( |
139 node, | 139 node, |
140 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(std
::abs(value), primitiveUnit)), | 140 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(std
::abs(value), primitiveUnit)), |
141 value >= 0 ? CalcAdd : CalcSubtract); | 141 value >= 0 ? CalcAdd : CalcSubtract); |
142 } else { | 142 } else { |
143 node = CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(
value, primitiveUnit)); | 143 node = CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(
value, primitiveUnit)); |
144 } | 144 } |
145 } | 145 } |
146 return CSSPrimitiveValue::create(CSSCalcValue::create(node)); | 146 return CSSPrimitiveValue::create(CSSCalcValue::create(node)); |
147 } | 147 } |
148 | 148 |
149 } // namespace blink | 149 } // namespace blink |
OLD | NEW |