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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 { | 116 { |
117 StyleCalcLength* result = StyleCalcLength::create(this, exceptionState); | 117 StyleCalcLength* result = StyleCalcLength::create(this, exceptionState); |
118 for (unsigned i = 0; i < LengthValue::kNumSupportedUnits; ++i) { | 118 for (unsigned i = 0; i < LengthValue::kNumSupportedUnits; ++i) { |
119 if (hasAtIndex(i)) { | 119 if (hasAtIndex(i)) { |
120 result->setAtIndex(getAtIndex(i) / x, i); | 120 result->setAtIndex(getAtIndex(i) / x, i); |
121 } | 121 } |
122 } | 122 } |
123 return result; | 123 return result; |
124 } | 124 } |
125 | 125 |
126 RawPtr<CSSValue> StyleCalcLength::toCSSValue() const | 126 CSSValue* StyleCalcLength::toCSSValue() const |
127 { | 127 { |
128 // Create a CSS Calc Value, then put it into a CSSPrimitiveValue | 128 // Create a CSS Calc Value, then put it into a CSSPrimitiveValue |
129 RawPtr<CSSCalcExpressionNode> node = nullptr; | 129 CSSCalcExpressionNode* node = nullptr; |
130 for (unsigned i = 0; i < LengthValue::kNumSupportedUnits; ++i) { | 130 for (unsigned i = 0; i < LengthValue::kNumSupportedUnits; ++i) { |
131 if (!hasAtIndex(i)) | 131 if (!hasAtIndex(i)) |
132 continue; | 132 continue; |
133 double value = getAtIndex(i); | 133 double value = getAtIndex(i); |
134 if (node) { | 134 if (node) { |
135 node = CSSCalcValue::createExpressionNode( | 135 node = CSSCalcValue::createExpressionNode( |
136 node, | 136 node, |
137 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(std
::abs(value), unitFromIndex(i))), | 137 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(std
::abs(value), unitFromIndex(i))), |
138 value >= 0 ? CalcAdd : CalcSubtract); | 138 value >= 0 ? CalcAdd : CalcSubtract); |
139 } else { | 139 } else { |
140 node = CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(
value, unitFromIndex(i))); | 140 node = CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(
value, unitFromIndex(i))); |
141 } | 141 } |
142 } | 142 } |
143 return CSSPrimitiveValue::create(CSSCalcValue::create(node)); | 143 return CSSPrimitiveValue::create(CSSCalcValue::create(node)); |
144 } | 144 } |
145 | 145 |
146 int StyleCalcLength::indexForUnit(CSSPrimitiveValue::UnitType unit) | 146 int StyleCalcLength::indexForUnit(CSSPrimitiveValue::UnitType unit) |
147 { | 147 { |
148 return (static_cast<int>(unit) - static_cast<int>(CSSPrimitiveValue::UnitTyp
e::Percentage)); | 148 return (static_cast<int>(unit) - static_cast<int>(CSSPrimitiveValue::UnitTyp
e::Percentage)); |
149 } | 149 } |
150 | 150 |
151 } // namespace blink | 151 } // namespace blink |
OLD | NEW |