| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef StyleCalcLength_h | |
| 6 #define StyleCalcLength_h | |
| 7 | |
| 8 #include "core/css/cssom/LengthValue.h" | |
| 9 #include "wtf/BitVector.h" | |
| 10 | |
| 11 namespace blink { | |
| 12 | |
| 13 class CalcDictionary; | |
| 14 class SimpleLength; | |
| 15 | |
| 16 class CORE_EXPORT StyleCalcLength final : public LengthValue { | |
| 17 DEFINE_WRAPPERTYPEINFO(); | |
| 18 public: | |
| 19 static StyleCalcLength* create(const LengthValue*); | |
| 20 static StyleCalcLength* create(const CalcDictionary&, ExceptionState&); | |
| 21 static StyleCalcLength* create(const LengthValue* length, ExceptionState&) | |
| 22 { | |
| 23 return create(length); | |
| 24 } | |
| 25 | |
| 26 #define GETTER_MACRO(name, type) \ | |
| 27 double name(bool& isNull) \ | |
| 28 { \ | |
| 29 isNull = !hasAtIndex(indexForUnit(type)); \ | |
| 30 return get(type); \ | |
| 31 } | |
| 32 | |
| 33 GETTER_MACRO(px, CSSPrimitiveValue::UnitType::Pixels) | |
| 34 GETTER_MACRO(percent, CSSPrimitiveValue::UnitType::Percentage) | |
| 35 GETTER_MACRO(em, CSSPrimitiveValue::UnitType::Ems) | |
| 36 GETTER_MACRO(ex, CSSPrimitiveValue::UnitType::Exs) | |
| 37 GETTER_MACRO(ch, CSSPrimitiveValue::UnitType::Chs) | |
| 38 GETTER_MACRO(rem, CSSPrimitiveValue::UnitType::Rems) | |
| 39 GETTER_MACRO(vw, CSSPrimitiveValue::UnitType::ViewportWidth) | |
| 40 GETTER_MACRO(vh, CSSPrimitiveValue::UnitType::ViewportHeight) | |
| 41 GETTER_MACRO(vmin, CSSPrimitiveValue::UnitType::ViewportMin) | |
| 42 GETTER_MACRO(vmax, CSSPrimitiveValue::UnitType::ViewportMax) | |
| 43 GETTER_MACRO(cm, CSSPrimitiveValue::UnitType::Centimeters) | |
| 44 GETTER_MACRO(mm, CSSPrimitiveValue::UnitType::Millimeters) | |
| 45 GETTER_MACRO(in, CSSPrimitiveValue::UnitType::Inches) | |
| 46 GETTER_MACRO(pc, CSSPrimitiveValue::UnitType::Picas) | |
| 47 GETTER_MACRO(pt, CSSPrimitiveValue::UnitType::Points) | |
| 48 | |
| 49 #undef GETTER_MACRO | |
| 50 | |
| 51 bool containsPercent() const override; | |
| 52 | |
| 53 CSSValue* toCSSValue() const override; | |
| 54 | |
| 55 StyleValueType type() const override { return CalcLengthType; } | |
| 56 protected: | |
| 57 LengthValue* addInternal(const LengthValue* other, ExceptionState&) override
; | |
| 58 LengthValue* subtractInternal(const LengthValue* other, ExceptionState&) ove
rride; | |
| 59 LengthValue* multiplyInternal(double, ExceptionState&) override; | |
| 60 LengthValue* divideInternal(double, ExceptionState&) override; | |
| 61 | |
| 62 private: | |
| 63 StyleCalcLength(); | |
| 64 StyleCalcLength(const StyleCalcLength& other); | |
| 65 StyleCalcLength(const SimpleLength& other); | |
| 66 | |
| 67 static int indexForUnit(CSSPrimitiveValue::UnitType); | |
| 68 static CSSPrimitiveValue::UnitType unitFromIndex(int index) | |
| 69 { | |
| 70 ASSERT(index < LengthValue::kNumSupportedUnits); | |
| 71 int lowestValue = static_cast<int>(CSSPrimitiveValue::UnitType::Percenta
ge); | |
| 72 return static_cast<CSSPrimitiveValue::UnitType>(index + lowestValue); | |
| 73 } | |
| 74 | |
| 75 bool hasAtIndex(int index) const | |
| 76 { | |
| 77 ASSERT(index < LengthValue::kNumSupportedUnits); | |
| 78 return m_hasValues.quickGet(index); | |
| 79 } | |
| 80 bool has(CSSPrimitiveValue::UnitType unit) const { return hasAtIndex(indexFo
rUnit(unit)); } | |
| 81 void setAtIndex(double value, int index) | |
| 82 { | |
| 83 ASSERT(index < LengthValue::kNumSupportedUnits); | |
| 84 m_hasValues.quickSet(index); | |
| 85 m_values[index] = value; | |
| 86 } | |
| 87 void set(double value, CSSPrimitiveValue::UnitType unit) { setAtIndex(value,
indexForUnit(unit)); } | |
| 88 double getAtIndex(int index) const | |
| 89 { | |
| 90 ASSERT(index < LengthValue::kNumSupportedUnits); | |
| 91 return m_values[index]; | |
| 92 } | |
| 93 double get(CSSPrimitiveValue::UnitType unit) const { return getAtIndex(index
ForUnit(unit)); } | |
| 94 | |
| 95 Vector<double, LengthValue::kNumSupportedUnits> m_values; | |
| 96 BitVector m_hasValues; | |
| 97 }; | |
| 98 | |
| 99 #define DEFINE_CALC_LENGTH_TYPE_CASTS(argumentType) \ | |
| 100 DEFINE_TYPE_CASTS(StyleCalcLength, argumentType, value, \ | |
| 101 value->type() == LengthValue::StyleValueType::CalcLengthType, \ | |
| 102 value.type() == LengthValue::StyleValueType::CalcLengthType) | |
| 103 | |
| 104 DEFINE_CALC_LENGTH_TYPE_CASTS(StyleValue); | |
| 105 | |
| 106 } // namespace blink | |
| 107 | |
| 108 #endif | |
| OLD | NEW |