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

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

Issue 2903413002: Restructure type tracking in StyleValues to work better with new numeric types (Closed)
Patch Set: rebase Created 3 years, 6 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 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;
34 String type() const;
nainar 2017/05/30 08:19:17 This change sounds like it belongs in a separate C
meade_UTC10 2017/06/02 04:43:38 Uploaded https://codereview.chromium.org/292166300
29 35
30 String cssType() const; 36 // Gets the Typed OM category, e.g. length, angle, etc.
31 37 StyleValueType GetType() const override;
32 StyleValueType GetType() const override { return StyleValueType::kUnitType; } 38 bool ContainsPercent() const override {
33 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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698