OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/CSSSimpleLength.h" | 5 #include "core/css/cssom/CSSSimpleLength.h" |
6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" |
7 #include "core/css/CSSPrimitiveValue.h" | 8 #include "core/css/CSSPrimitiveValue.h" |
8 #include "core/css/cssom/CSSCalcLength.h" | 9 #include "core/css/cssom/CSSCalcLength.h" |
9 #include "wtf/text/StringBuilder.h" | 10 #include "wtf/text/StringBuilder.h" |
10 | 11 |
11 namespace blink { | 12 namespace blink { |
12 | 13 |
13 CSSValue* CSSSimpleLength::toCSSValue() const | 14 CSSSimpleLength* CSSSimpleLength::create(double value, const String& type, Excep
tionState& exceptionState) |
14 { | 15 { |
15 return CSSPrimitiveValue::create(m_value, m_unit); | 16 CSSPrimitiveValue::UnitType unit = CSSLengthValue::unitFromName(type); |
| 17 if (!CSSLengthValue::isSupportedLengthUnit(unit)) { |
| 18 exceptionState.throwTypeError("Invalid unit for CSSSimpleLength: " + typ
e); |
| 19 return nullptr; |
| 20 } |
| 21 return new CSSSimpleLength(value, unit); |
| 22 } |
| 23 |
| 24 CSSSimpleLength* CSSSimpleLength::fromCSSValue(const CSSPrimitiveValue& value) |
| 25 { |
| 26 DCHECK(value.isLength()); |
| 27 return new CSSSimpleLength(value.getDoubleValue(), value.typeWithCalcResolve
d()); |
16 } | 28 } |
17 | 29 |
18 bool CSSSimpleLength::containsPercent() const | 30 bool CSSSimpleLength::containsPercent() const |
19 { | 31 { |
20 return lengthUnit() == CSSPrimitiveValue::UnitType::Percentage; | 32 return lengthUnit() == CSSPrimitiveValue::UnitType::Percentage; |
21 } | 33 } |
22 | 34 |
23 CSSLengthValue* CSSSimpleLength::addInternal(const CSSLengthValue* other) | 35 CSSLengthValue* CSSSimpleLength::addInternal(const CSSLengthValue* other) |
24 { | 36 { |
25 const CSSSimpleLength* o = toCSSSimpleLength(other); | 37 const CSSSimpleLength* o = toCSSSimpleLength(other); |
(...skipping 12 matching lines...) Expand all Loading... |
38 { | 50 { |
39 return create(m_value * x, m_unit); | 51 return create(m_value * x, m_unit); |
40 } | 52 } |
41 | 53 |
42 CSSLengthValue* CSSSimpleLength::divideInternal(double x) | 54 CSSLengthValue* CSSSimpleLength::divideInternal(double x) |
43 { | 55 { |
44 DCHECK_NE(x, 0); | 56 DCHECK_NE(x, 0); |
45 return create(m_value / x, m_unit); | 57 return create(m_value / x, m_unit); |
46 } | 58 } |
47 | 59 |
| 60 CSSValue* CSSSimpleLength::toCSSValue() const |
| 61 { |
| 62 return CSSPrimitiveValue::create(m_value, m_unit); |
| 63 } |
| 64 |
48 } // namespace blink | 65 } // namespace blink |
OLD | NEW |