| 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 CSSLengthValue_h | 5 #ifndef CSSLengthValue_h |
| 6 #define CSSLengthValue_h | 6 #define CSSLengthValue_h |
| 7 | 7 |
| 8 #include "core/css/CSSPrimitiveValue.h" | 8 #include "core/css/CSSPrimitiveValue.h" |
| 9 #include "core/css/cssom/CSSStyleValue.h" | 9 #include "core/css/cssom/CSSStyleValue.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 class CSSCalcDictionary; | 13 class CSSCalcDictionary; |
| 14 class ExceptionState; | 14 class ExceptionState; |
| 15 | 15 |
| 16 class CORE_EXPORT CSSLengthValue : public CSSStyleValue { | 16 class CORE_EXPORT CSSLengthValue : public CSSStyleValue { |
| 17 WTF_MAKE_NONCOPYABLE(CSSLengthValue); | 17 WTF_MAKE_NONCOPYABLE(CSSLengthValue); |
| 18 DEFINE_WRAPPERTYPEINFO(); | 18 DEFINE_WRAPPERTYPEINFO(); |
| 19 | 19 |
| 20 public: | 20 public: |
| 21 static const int kNumSupportedUnits = 15; |
| 22 |
| 23 static CSSLengthValue* from(const String& cssText, ExceptionState&); |
| 24 static CSSLengthValue* from(double value, |
| 25 const String& typeStr, |
| 26 ExceptionState&); |
| 27 static CSSLengthValue* from(const CSSCalcDictionary&, ExceptionState&); |
| 28 |
| 29 static bool isSupportedLengthUnit(CSSPrimitiveValue::UnitType unit) { |
| 30 return (CSSPrimitiveValue::isLength(unit) || |
| 31 unit == CSSPrimitiveValue::UnitType::Percentage) && |
| 32 unit != CSSPrimitiveValue::UnitType::QuirkyEms && |
| 33 unit != CSSPrimitiveValue::UnitType::UserUnits; |
| 34 } |
| 21 static CSSPrimitiveValue::UnitType unitFromName(const String& name); | 35 static CSSPrimitiveValue::UnitType unitFromName(const String& name); |
| 22 static CSSLengthValue* fromCSSValue(const CSSPrimitiveValue&); | 36 static CSSLengthValue* fromCSSValue(const CSSPrimitiveValue&); |
| 23 | 37 |
| 24 CSSLengthValue* add(const CSSLengthValue* other); | 38 CSSLengthValue* add(const CSSLengthValue* other); |
| 25 CSSLengthValue* subtract(const CSSLengthValue* other); | 39 CSSLengthValue* subtract(const CSSLengthValue* other); |
| 26 CSSLengthValue* multiply(double); | 40 CSSLengthValue* multiply(double); |
| 27 CSSLengthValue* divide(double, ExceptionState&); | 41 CSSLengthValue* divide(double, ExceptionState&); |
| 28 | 42 |
| 29 virtual bool containsPercent() const = 0; | 43 virtual bool containsPercent() const = 0; |
| 30 | 44 |
| 31 static CSSLengthValue* from(const String& cssText, ExceptionState&); | |
| 32 static CSSLengthValue* from(double value, | |
| 33 const String& typeStr, | |
| 34 ExceptionState&); | |
| 35 static CSSLengthValue* from(const CSSCalcDictionary&, ExceptionState&); | |
| 36 | |
| 37 protected: | 45 protected: |
| 38 static const int kNumSupportedUnits = 15; | |
| 39 | |
| 40 CSSLengthValue() {} | 46 CSSLengthValue() {} |
| 41 | 47 |
| 42 virtual CSSLengthValue* addInternal(const CSSLengthValue* other); | 48 virtual CSSLengthValue* addInternal(const CSSLengthValue* other); |
| 43 virtual CSSLengthValue* subtractInternal(const CSSLengthValue* other); | 49 virtual CSSLengthValue* subtractInternal(const CSSLengthValue* other); |
| 44 virtual CSSLengthValue* multiplyInternal(double); | 50 virtual CSSLengthValue* multiplyInternal(double); |
| 45 virtual CSSLengthValue* divideInternal(double); | 51 virtual CSSLengthValue* divideInternal(double); |
| 46 | |
| 47 static bool isSupportedLengthUnit(CSSPrimitiveValue::UnitType unit) { | |
| 48 return (CSSPrimitiveValue::isLength(unit) || | |
| 49 unit == CSSPrimitiveValue::UnitType::Percentage) && | |
| 50 unit != CSSPrimitiveValue::UnitType::QuirkyEms && | |
| 51 unit != CSSPrimitiveValue::UnitType::UserUnits; | |
| 52 } | |
| 53 }; | 52 }; |
| 54 | 53 |
| 55 DEFINE_TYPE_CASTS(CSSLengthValue, | 54 DEFINE_TYPE_CASTS(CSSLengthValue, |
| 56 CSSStyleValue, | 55 CSSStyleValue, |
| 57 value, | 56 value, |
| 58 (value->type() == CSSStyleValue::SimpleLengthType || | 57 (value->type() == CSSStyleValue::SimpleLengthType || |
| 59 value->type() == CSSStyleValue::CalcLengthType), | 58 value->type() == CSSStyleValue::CalcLengthType), |
| 60 (value.type() == CSSStyleValue::SimpleLengthType || | 59 (value.type() == CSSStyleValue::SimpleLengthType || |
| 61 value.type() == CSSStyleValue::CalcLengthType)); | 60 value.type() == CSSStyleValue::CalcLengthType)); |
| 62 | 61 |
| 63 } // namespace blink | 62 } // namespace blink |
| 64 | 63 |
| 65 #endif | 64 #endif |
| OLD | NEW |