Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: third_party/WebKit/Source/core/css/cssom/CSSLengthValue.h

Issue 2371673002: [CSS Typed OM] Implement support for CSSValue -> CSSCalcLength (Closed)
Patch Set: sync to head Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 36
23 CSSLengthValue* add(const CSSLengthValue* other); 37 CSSLengthValue* add(const CSSLengthValue* other);
24 CSSLengthValue* subtract(const CSSLengthValue* other); 38 CSSLengthValue* subtract(const CSSLengthValue* other);
25 CSSLengthValue* multiply(double); 39 CSSLengthValue* multiply(double);
26 CSSLengthValue* divide(double, ExceptionState&); 40 CSSLengthValue* divide(double, ExceptionState&);
27 41
28 virtual bool containsPercent() const = 0; 42 virtual bool containsPercent() const = 0;
29 43
30 static CSSLengthValue* from(const String& cssText, ExceptionState&);
31 static CSSLengthValue* from(double value,
32 const String& typeStr,
33 ExceptionState&);
34 static CSSLengthValue* from(const CSSCalcDictionary&, ExceptionState&);
35
36 protected: 44 protected:
37 static const int kNumSupportedUnits = 15;
38
39 CSSLengthValue() {} 45 CSSLengthValue() {}
40 46
41 virtual CSSLengthValue* addInternal(const CSSLengthValue* other); 47 virtual CSSLengthValue* addInternal(const CSSLengthValue* other);
42 virtual CSSLengthValue* subtractInternal(const CSSLengthValue* other); 48 virtual CSSLengthValue* subtractInternal(const CSSLengthValue* other);
43 virtual CSSLengthValue* multiplyInternal(double); 49 virtual CSSLengthValue* multiplyInternal(double);
44 virtual CSSLengthValue* divideInternal(double); 50 virtual CSSLengthValue* divideInternal(double);
45
46 static bool isSupportedLengthUnit(CSSPrimitiveValue::UnitType unit) {
47 return (CSSPrimitiveValue::isLength(unit) ||
48 unit == CSSPrimitiveValue::UnitType::Percentage) &&
49 unit != CSSPrimitiveValue::UnitType::QuirkyEms &&
50 unit != CSSPrimitiveValue::UnitType::UserUnits;
51 }
52 }; 51 };
53 52
54 DEFINE_TYPE_CASTS(CSSLengthValue, 53 DEFINE_TYPE_CASTS(CSSLengthValue,
55 CSSStyleValue, 54 CSSStyleValue,
56 value, 55 value,
57 (value->type() == CSSStyleValue::SimpleLengthType || 56 (value->type() == CSSStyleValue::SimpleLengthType ||
58 value->type() == CSSStyleValue::CalcLengthType), 57 value->type() == CSSStyleValue::CalcLengthType),
59 (value.type() == CSSStyleValue::SimpleLengthType || 58 (value.type() == CSSStyleValue::SimpleLengthType ||
60 value.type() == CSSStyleValue::CalcLengthType)); 59 value.type() == CSSStyleValue::CalcLengthType));
61 60
62 } // namespace blink 61 } // namespace blink
63 62
64 #endif 63 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698