OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CSSLengthValue_h | |
6 #define CSSLengthValue_h | |
7 | |
8 #include "core/css/CSSPrimitiveValue.h" | |
9 #include "core/css/cssom/CSSStyleValue.h" | |
10 | |
11 namespace blink { | |
12 | |
13 class CSSCalcDictionary; | |
14 class ExceptionState; | |
15 | |
16 class CORE_EXPORT CSSLengthValue : public CSSStyleValue { | |
17 WTF_MAKE_NONCOPYABLE(CSSLengthValue); | |
18 DEFINE_WRAPPERTYPEINFO(); | |
19 | |
20 public: | |
21 static const int kNumSupportedUnits = 15; | |
22 | |
23 static CSSLengthValue* from(const String& css_text, ExceptionState&); | |
24 static CSSLengthValue* from(double value, | |
25 const String& type_str, | |
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::kPercentage) && | |
32 unit != CSSPrimitiveValue::UnitType::kQuirkyEms && | |
33 unit != CSSPrimitiveValue::UnitType::kUserUnits; | |
34 } | |
35 static CSSPrimitiveValue::UnitType UnitFromName(const String& name); | |
36 static CSSLengthValue* FromCSSValue(const CSSPrimitiveValue&); | |
37 | |
38 CSSLengthValue* add(const CSSLengthValue* other); | |
39 CSSLengthValue* subtract(const CSSLengthValue* other); | |
40 CSSLengthValue* multiply(double); | |
41 CSSLengthValue* divide(double, ExceptionState&); | |
42 | |
43 virtual bool ContainsPercent() const = 0; | |
44 | |
45 protected: | |
46 CSSLengthValue() {} | |
47 | |
48 virtual CSSLengthValue* AddInternal(const CSSLengthValue* other); | |
49 virtual CSSLengthValue* SubtractInternal(const CSSLengthValue* other); | |
50 virtual CSSLengthValue* MultiplyInternal(double); | |
51 virtual CSSLengthValue* DivideInternal(double); | |
52 }; | |
53 | |
54 DEFINE_TYPE_CASTS(CSSLengthValue, | |
55 CSSStyleValue, | |
56 value, | |
57 (value->GetType() == CSSStyleValue::kSimpleLengthType || | |
58 value->GetType() == CSSStyleValue::kCalcLengthType), | |
59 (value.GetType() == CSSStyleValue::kSimpleLengthType || | |
60 value.GetType() == CSSStyleValue::kCalcLengthType)); | |
61 | |
62 } // namespace blink | |
63 | |
64 #endif | |
OLD | NEW |