| 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 #ifndef CSSSimpleLength_h | 5 #ifndef CSSSimpleLength_h |
| 6 #define CSSSimpleLength_h | 6 #define CSSSimpleLength_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ExceptionState.h" | |
| 9 #include "core/css/cssom/CSSLengthValue.h" | 8 #include "core/css/cssom/CSSLengthValue.h" |
| 10 | 9 |
| 11 namespace blink { | 10 namespace blink { |
| 12 | 11 |
| 13 class CSSPrimitiveValue; | 12 class CSSPrimitiveValue; |
| 13 class ExceptionState; |
| 14 | 14 |
| 15 class CORE_EXPORT CSSSimpleLength final : public CSSLengthValue { | 15 class CORE_EXPORT CSSSimpleLength final : public CSSLengthValue { |
| 16 WTF_MAKE_NONCOPYABLE(CSSSimpleLength); | 16 WTF_MAKE_NONCOPYABLE(CSSSimpleLength); |
| 17 DEFINE_WRAPPERTYPEINFO(); | 17 DEFINE_WRAPPERTYPEINFO(); |
| 18 public: | 18 public: |
| 19 static CSSSimpleLength* create(double value, const String& type, ExceptionSt
ate& exceptionState) | 19 static CSSSimpleLength* create(double, const String& type, ExceptionState&); |
| 20 { | |
| 21 CSSPrimitiveValue::UnitType unit = unitFromName(type); | |
| 22 if (!isSupportedLengthUnit(unit)) { | |
| 23 exceptionState.throwTypeError("Invalid unit for CSSSimpleLength: " +
type); | |
| 24 return nullptr; | |
| 25 } | |
| 26 return new CSSSimpleLength(value, unit); | |
| 27 } | |
| 28 | |
| 29 static CSSSimpleLength* create(double value, CSSPrimitiveValue::UnitType typ
e) | 20 static CSSSimpleLength* create(double value, CSSPrimitiveValue::UnitType typ
e) |
| 30 { | 21 { |
| 31 return new CSSSimpleLength(value, type); | 22 return new CSSSimpleLength(value, type); |
| 32 } | 23 } |
| 24 static CSSSimpleLength* fromCSSValue(const CSSPrimitiveValue&); |
| 33 | 25 |
| 34 bool containsPercent() const override; | 26 bool containsPercent() const override; |
| 35 | 27 |
| 36 double value() const { return m_value; } | 28 double value() const { return m_value; } |
| 37 String unit() const { return String(CSSPrimitiveValue::unitTypeToString(m_un
it)); } | 29 String unit() const { return String(CSSPrimitiveValue::unitTypeToString(m_un
it)); } |
| 38 CSSPrimitiveValue::UnitType lengthUnit() const { return m_unit; } | 30 CSSPrimitiveValue::UnitType lengthUnit() const { return m_unit; } |
| 39 | 31 |
| 40 void setValue(double value) { m_value = value; } | |
| 41 | |
| 42 StyleValueType type() const override { return StyleValueType::SimpleLengthTy
pe; } | 32 StyleValueType type() const override { return StyleValueType::SimpleLengthTy
pe; } |
| 43 | 33 |
| 44 CSSValue* toCSSValue() const override; | 34 CSSValue* toCSSValue() const override; |
| 45 | 35 |
| 46 protected: | 36 protected: |
| 47 virtual CSSLengthValue* addInternal(const CSSLengthValue* other); | 37 virtual CSSLengthValue* addInternal(const CSSLengthValue* other); |
| 48 virtual CSSLengthValue* subtractInternal(const CSSLengthValue* other); | 38 virtual CSSLengthValue* subtractInternal(const CSSLengthValue* other); |
| 49 virtual CSSLengthValue* multiplyInternal(double); | 39 virtual CSSLengthValue* multiplyInternal(double); |
| 50 virtual CSSLengthValue* divideInternal(double); | 40 virtual CSSLengthValue* divideInternal(double); |
| 51 | 41 |
| 52 private: | 42 private: |
| 53 CSSSimpleLength(double value, CSSPrimitiveValue::UnitType unit) : CSSLengthV
alue(), m_unit(unit), m_value(value) {} | 43 CSSSimpleLength(double value, CSSPrimitiveValue::UnitType unit) : CSSLengthV
alue(), m_unit(unit), m_value(value) {} |
| 54 | 44 |
| 55 CSSPrimitiveValue::UnitType m_unit; | 45 CSSPrimitiveValue::UnitType m_unit; |
| 56 double m_value; | 46 double m_value; |
| 57 }; | 47 }; |
| 58 | 48 |
| 59 #define DEFINE_SIMPLE_LENGTH_TYPE_CASTS(argumentType) \ | 49 #define DEFINE_SIMPLE_LENGTH_TYPE_CASTS(argumentType) \ |
| 60 DEFINE_TYPE_CASTS(CSSSimpleLength, argumentType, value, \ | 50 DEFINE_TYPE_CASTS(CSSSimpleLength, argumentType, value, \ |
| 61 value->type() == CSSLengthValue::StyleValueType::SimpleLengthType, \ | 51 value->type() == CSSLengthValue::StyleValueType::SimpleLengthType, \ |
| 62 value.type() == CSSLengthValue::StyleValueType::SimpleLengthType) | 52 value.type() == CSSLengthValue::StyleValueType::SimpleLengthType) |
| 63 | 53 |
| 64 DEFINE_SIMPLE_LENGTH_TYPE_CASTS(CSSLengthValue); | 54 DEFINE_SIMPLE_LENGTH_TYPE_CASTS(CSSLengthValue); |
| 65 DEFINE_SIMPLE_LENGTH_TYPE_CASTS(CSSStyleValue); | 55 DEFINE_SIMPLE_LENGTH_TYPE_CASTS(CSSStyleValue); |
| 66 | 56 |
| 67 } // namespace blink | 57 } // namespace blink |
| 68 | 58 |
| 69 #endif | 59 #endif |
| OLD | NEW |