OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 CSSUnitValue_h | 5 #ifndef CSSUnitValue_h |
6 #define CSSUnitValue_h | 6 #define CSSUnitValue_h |
7 | 7 |
8 #include "core/css/CSSPrimitiveValue.h" | 8 #include "core/css/CSSPrimitiveValue.h" |
9 #include "core/css/cssom/CSSNumericValue.h" | 9 #include "core/css/cssom/CSSNumericValue.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 | 12 |
| 13 // Represents numeric values that can be expressed as a single number plus a |
| 14 // unit (or a naked number or percentage). |
| 15 // See CSSUnitValue.idl for more information about this class. |
13 class CORE_EXPORT CSSUnitValue final : public CSSNumericValue { | 16 class CORE_EXPORT CSSUnitValue final : public CSSNumericValue { |
14 WTF_MAKE_NONCOPYABLE(CSSUnitValue); | 17 WTF_MAKE_NONCOPYABLE(CSSUnitValue); |
15 DEFINE_WRAPPERTYPEINFO(); | 18 DEFINE_WRAPPERTYPEINFO(); |
16 | 19 |
17 public: | 20 public: |
18 static CSSPrimitiveValue::UnitType UnitFromName(const String& name); | 21 // The constructor defined in the IDL. |
19 static CSSUnitValue* Create(double value, | 22 static CSSUnitValue* Create(double value, |
20 const String& unit, | 23 const String& unit, |
21 ExceptionState&); | 24 ExceptionState&); |
| 25 // Blink-internal ways of creating CSSUnitValues. |
22 static CSSUnitValue* Create(double value, CSSPrimitiveValue::UnitType); | 26 static CSSUnitValue* Create(double value, CSSPrimitiveValue::UnitType); |
23 static CSSUnitValue* FromCSSValue(const CSSPrimitiveValue&); | 27 static CSSUnitValue* FromCSSValue(const CSSPrimitiveValue&); |
24 | 28 |
| 29 // Setters and getters for attributes defined in the IDL. |
25 void setValue(double new_value) { value_ = new_value; } | 30 void setValue(double new_value) { value_ = new_value; } |
26 double value() const { return value_; } | 31 double value() const { return value_; } |
27 void setUnit(const String& new_unit, ExceptionState&); | 32 void setUnit(const String& new_unit, ExceptionState&); |
28 String unit() const; | 33 String unit() const; |
29 | |
30 String type() const; | 34 String type() const; |
31 | 35 |
32 StyleValueType GetType() const override { return StyleValueType::kUnitType; } | 36 // Gets the Typed OM category, e.g. length, angle, etc. |
33 | 37 StyleValueType GetType() const override; |
| 38 bool ContainsPercent() const override { |
| 39 return unit_ == CSSPrimitiveValue::UnitType::kPercentage; |
| 40 } |
| 41 // Gets the representation that can be applied to an inline style. |
34 const CSSValue* ToCSSValue() const override; | 42 const CSSValue* ToCSSValue() const override; |
35 | 43 |
36 private: | 44 private: |
| 45 static CSSPrimitiveValue::UnitType UnitFromName(const String& name); |
| 46 |
37 CSSUnitValue(double value, CSSPrimitiveValue::UnitType unit) | 47 CSSUnitValue(double value, CSSPrimitiveValue::UnitType unit) |
38 : CSSNumericValue(), value_(value), unit_(unit) {} | 48 : CSSNumericValue(), value_(value), unit_(unit) {} |
39 | 49 |
40 double value_; | 50 double value_; |
41 CSSPrimitiveValue::UnitType unit_; | 51 CSSPrimitiveValue::UnitType unit_; |
42 }; | 52 }; |
43 | 53 |
44 } // namespace blink | 54 } // namespace blink |
45 | 55 |
46 #endif // CSSUnitValue_h | 56 #endif // CSSUnitValue_h |
OLD | NEW |