OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 CSSCalcLength_h | 5 #ifndef CSSCalcLength_h |
6 #define CSSCalcLength_h | 6 #define CSSCalcLength_h |
7 | 7 |
| 8 #include "core/css/CSSCalculationValue.h" |
8 #include "core/css/cssom/CSSLengthValue.h" | 9 #include "core/css/cssom/CSSLengthValue.h" |
9 #include "wtf/BitVector.h" | 10 #include "wtf/BitVector.h" |
10 | 11 |
11 namespace blink { | 12 namespace blink { |
12 | 13 |
13 class CalcDictionary; | 14 class CalcDictionary; |
14 class CSSSimpleLength; | 15 class CSSSimpleLength; |
| 16 class CSSValue; |
15 | 17 |
16 class CORE_EXPORT CSSCalcLength final : public CSSLengthValue { | 18 class CORE_EXPORT CSSCalcLength final : public CSSLengthValue { |
17 DEFINE_WRAPPERTYPEINFO(); | 19 DEFINE_WRAPPERTYPEINFO(); |
18 public: | 20 public: |
19 static CSSCalcLength* create(const CSSLengthValue*); | 21 static CSSCalcLength* create(const CSSLengthValue*); |
| 22 static CSSCalcLength* create(const CalcDictionary&); |
20 static CSSCalcLength* create(const CalcDictionary&, ExceptionState&); | 23 static CSSCalcLength* create(const CalcDictionary&, ExceptionState&); |
21 static CSSCalcLength* create(const CSSLengthValue* length, ExceptionState&) | 24 static CSSCalcLength* create(const CSSLengthValue* length, ExceptionState&) |
22 { | 25 { |
23 return create(length); | 26 return create(length); |
24 } | 27 } |
25 | 28 |
| 29 static CSSCalcLength* fromCSSValue(const CSSValue&); |
| 30 |
26 #define GETTER_MACRO(name, type) \ | 31 #define GETTER_MACRO(name, type) \ |
27 double name(bool& isNull) \ | 32 double name(bool& isNull) \ |
28 { \ | 33 { \ |
29 isNull = !hasAtIndex(indexForUnit(type)); \ | 34 isNull = !hasAtIndex(indexForUnit(type)); \ |
30 return get(type); \ | 35 return get(type); \ |
31 } | 36 } |
32 | 37 |
33 GETTER_MACRO(px, CSSPrimitiveValue::UnitType::Pixels) | 38 GETTER_MACRO(px, CSSPrimitiveValue::UnitType::Pixels) |
34 GETTER_MACRO(percent, CSSPrimitiveValue::UnitType::Percentage) | 39 GETTER_MACRO(percent, CSSPrimitiveValue::UnitType::Percentage) |
35 GETTER_MACRO(em, CSSPrimitiveValue::UnitType::Ems) | 40 GETTER_MACRO(em, CSSPrimitiveValue::UnitType::Ems) |
(...skipping 13 matching lines...) Expand all Loading... |
49 #undef GETTER_MACRO | 54 #undef GETTER_MACRO |
50 | 55 |
51 bool containsPercent() const override; | 56 bool containsPercent() const override; |
52 | 57 |
53 CSSValue* toCSSValue() const override; | 58 CSSValue* toCSSValue() const override; |
54 | 59 |
55 StyleValueType type() const override { return CalcLengthType; } | 60 StyleValueType type() const override { return CalcLengthType; } |
56 protected: | 61 protected: |
57 CSSLengthValue* addInternal(const CSSLengthValue* other, ExceptionState&) ov
erride; | 62 CSSLengthValue* addInternal(const CSSLengthValue* other, ExceptionState&) ov
erride; |
58 CSSLengthValue* subtractInternal(const CSSLengthValue* other, ExceptionState
&) override; | 63 CSSLengthValue* subtractInternal(const CSSLengthValue* other, ExceptionState
&) override; |
59 CSSLengthValue* multiplyInternal(double, ExceptionState&) override; | 64 CSSLengthValue* multiplyInternal(double) override; |
60 CSSLengthValue* divideInternal(double, ExceptionState&) override; | 65 CSSLengthValue* divideInternal(double) override; |
61 | 66 |
62 private: | 67 private: |
63 CSSCalcLength(); | 68 CSSCalcLength(); |
64 CSSCalcLength(const CSSCalcLength& other); | 69 CSSCalcLength(const CSSCalcLength& other); |
65 CSSCalcLength(const CSSSimpleLength& other); | 70 CSSCalcLength(const CSSSimpleLength& other); |
66 | 71 |
| 72 static CSSCalcLength* populateCalcLengthFromExpressionNode(const CSSCalcExpr
essionNode*); |
| 73 |
67 static int indexForUnit(CSSPrimitiveValue::UnitType); | 74 static int indexForUnit(CSSPrimitiveValue::UnitType); |
68 static CSSPrimitiveValue::UnitType unitFromIndex(int index) | 75 static CSSPrimitiveValue::UnitType unitFromIndex(int index) |
69 { | 76 { |
70 DCHECK(index < CSSLengthValue::kNumSupportedUnits); | 77 DCHECK(index < CSSLengthValue::kNumSupportedUnits); |
71 int lowestValue = static_cast<int>(CSSPrimitiveValue::UnitType::Percenta
ge); | 78 int lowestValue = static_cast<int>(CSSPrimitiveValue::UnitType::Percenta
ge); |
72 return static_cast<CSSPrimitiveValue::UnitType>(index + lowestValue); | 79 return static_cast<CSSPrimitiveValue::UnitType>(index + lowestValue); |
73 } | 80 } |
74 | 81 |
75 bool hasAtIndex(int index) const | 82 bool hasAtIndex(int index) const |
76 { | 83 { |
(...skipping 22 matching lines...) Expand all Loading... |
99 #define DEFINE_CALC_LENGTH_TYPE_CASTS(argumentType) \ | 106 #define DEFINE_CALC_LENGTH_TYPE_CASTS(argumentType) \ |
100 DEFINE_TYPE_CASTS(CSSCalcLength, argumentType, value, \ | 107 DEFINE_TYPE_CASTS(CSSCalcLength, argumentType, value, \ |
101 value->type() == CSSLengthValue::StyleValueType::CalcLengthType, \ | 108 value->type() == CSSLengthValue::StyleValueType::CalcLengthType, \ |
102 value.type() == CSSLengthValue::StyleValueType::CalcLengthType) | 109 value.type() == CSSLengthValue::StyleValueType::CalcLengthType) |
103 | 110 |
104 DEFINE_CALC_LENGTH_TYPE_CASTS(CSSStyleValue); | 111 DEFINE_CALC_LENGTH_TYPE_CASTS(CSSStyleValue); |
105 | 112 |
106 } // namespace blink | 113 } // namespace blink |
107 | 114 |
108 #endif | 115 #endif |
OLD | NEW |