| 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/CSSSimpleLength.h" |
| 9 #include "core/css/cssom/CalcDictionary.h" | 10 #include "core/css/cssom/CalcDictionary.h" |
| 10 #include "core/css/cssom/SimpleLength.h" | |
| 11 #include "wtf/Vector.h" | 11 #include "wtf/Vector.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 StyleCalcLength::StyleCalcLength() : m_values(CSSLengthValue::kNumSupportedUnits
), m_hasValues(CSSLengthValue::kNumSupportedUnits) {} | 15 StyleCalcLength::StyleCalcLength() : m_values(CSSLengthValue::kNumSupportedUnits
), m_hasValues(CSSLengthValue::kNumSupportedUnits) {} |
| 16 | 16 |
| 17 StyleCalcLength::StyleCalcLength(const StyleCalcLength& other) : | 17 StyleCalcLength::StyleCalcLength(const StyleCalcLength& other) : |
| 18 m_values(other.m_values), | 18 m_values(other.m_values), |
| 19 m_hasValues(other.m_hasValues) | 19 m_hasValues(other.m_hasValues) |
| 20 {} | 20 {} |
| 21 | 21 |
| 22 StyleCalcLength::StyleCalcLength(const SimpleLength& other) : | 22 StyleCalcLength::StyleCalcLength(const CSSSimpleLength& other) : |
| 23 m_values(CSSLengthValue::kNumSupportedUnits), m_hasValues(CSSLengthValue::kN
umSupportedUnits) | 23 m_values(CSSLengthValue::kNumSupportedUnits), m_hasValues(CSSLengthValue::kN
umSupportedUnits) |
| 24 { | 24 { |
| 25 set(other.value(), other.lengthUnit()); | 25 set(other.value(), other.lengthUnit()); |
| 26 } | 26 } |
| 27 | 27 |
| 28 StyleCalcLength* StyleCalcLength::create(const CSSLengthValue* length) | 28 StyleCalcLength* StyleCalcLength::create(const CSSLengthValue* length) |
| 29 { | 29 { |
| 30 if (length->type() == SimpleLengthType) { | 30 if (length->type() == SimpleLengthType) { |
| 31 const SimpleLength* simpleLength = toSimpleLength(length); | 31 const CSSSimpleLength* simpleLength = toCSSSimpleLength(length); |
| 32 return new StyleCalcLength(*simpleLength); | 32 return new StyleCalcLength(*simpleLength); |
| 33 } | 33 } |
| 34 | 34 |
| 35 return new StyleCalcLength(*toStyleCalcLength(length)); | 35 return new StyleCalcLength(*toStyleCalcLength(length)); |
| 36 } | 36 } |
| 37 | 37 |
| 38 StyleCalcLength* StyleCalcLength::create(const CalcDictionary& dictionary, Excep
tionState& exceptionState) | 38 StyleCalcLength* StyleCalcLength::create(const CalcDictionary& dictionary, Excep
tionState& exceptionState) |
| 39 { | 39 { |
| 40 StyleCalcLength* result = new StyleCalcLength(); | 40 StyleCalcLength* result = new StyleCalcLength(); |
| 41 int numSet = 0; | 41 int numSet = 0; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 { | 88 { |
| 89 StyleCalcLength* result = StyleCalcLength::create(this, exceptionState); | 89 StyleCalcLength* result = StyleCalcLength::create(this, exceptionState); |
| 90 if (other->type() == CalcLengthType) { | 90 if (other->type() == CalcLengthType) { |
| 91 const StyleCalcLength* o = toStyleCalcLength(other); | 91 const StyleCalcLength* o = toStyleCalcLength(other); |
| 92 for (unsigned i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) { | 92 for (unsigned i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) { |
| 93 if (o->hasAtIndex(i)) { | 93 if (o->hasAtIndex(i)) { |
| 94 result->setAtIndex(getAtIndex(i) - o->getAtIndex(i), i); | 94 result->setAtIndex(getAtIndex(i) - o->getAtIndex(i), i); |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 } else { | 97 } else { |
| 98 const SimpleLength* o = toSimpleLength(other); | 98 const CSSSimpleLength* o = toCSSSimpleLength(other); |
| 99 result->set(get(o->lengthUnit()) - o->value(), o->lengthUnit()); | 99 result->set(get(o->lengthUnit()) - o->value(), o->lengthUnit()); |
| 100 } | 100 } |
| 101 return result; | 101 return result; |
| 102 } | 102 } |
| 103 | 103 |
| 104 CSSLengthValue* StyleCalcLength::multiplyInternal(double x, ExceptionState& exce
ptionState) | 104 CSSLengthValue* StyleCalcLength::multiplyInternal(double x, ExceptionState& exce
ptionState) |
| 105 { | 105 { |
| 106 StyleCalcLength* result = StyleCalcLength::create(this, exceptionState); | 106 StyleCalcLength* result = StyleCalcLength::create(this, exceptionState); |
| 107 for (unsigned i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) { | 107 for (unsigned i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) { |
| 108 if (hasAtIndex(i)) { | 108 if (hasAtIndex(i)) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |