OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 29 matching lines...) Expand all Loading... | |
40 | 40 |
41 class SVGLength final : public SVGPropertyBase { | 41 class SVGLength final : public SVGPropertyBase { |
42 public: | 42 public: |
43 typedef SVGLengthTearOff TearOffType; | 43 typedef SVGLengthTearOff TearOffType; |
44 | 44 |
45 static PassRefPtrWillBeRawPtr<SVGLength> create(SVGLengthMode mode = SVGLeng thMode::Other) | 45 static PassRefPtrWillBeRawPtr<SVGLength> create(SVGLengthMode mode = SVGLeng thMode::Other) |
46 { | 46 { |
47 return adoptRefWillBeNoop(new SVGLength(mode)); | 47 return adoptRefWillBeNoop(new SVGLength(mode)); |
48 } | 48 } |
49 | 49 |
50 DECLARE_VIRTUAL_TRACE(); | |
51 | |
50 PassRefPtrWillBeRawPtr<SVGLength> clone() const; | 52 PassRefPtrWillBeRawPtr<SVGLength> clone() const; |
51 PassRefPtrWillBeRawPtr<SVGPropertyBase> cloneForAnimation(const String&) con st override; | 53 PassRefPtrWillBeRawPtr<SVGPropertyBase> cloneForAnimation(const String&) con st override; |
52 | 54 |
53 SVGLengthType unitType() const { return static_cast<SVGLengthType>(m_unitTyp e); } | 55 CSSPrimitiveValue::UnitType typeWithCalcResolved() const { return m_value->t ypeWithCalcResolved(); } |
54 CSSPrimitiveValue::UnitType cssUnitTypeQuirk() const | 56 CSSPrimitiveValue::UnitType cssUnitTypeQuirk() const |
55 { | 57 { |
56 if (m_unitType == LengthTypeNumber) | 58 if (m_value->typeWithCalcResolved() == CSSPrimitiveValue::UnitType::Numb er) |
fs
2015/10/30 19:50:00
Can we still get Number here?
Stephen Chennney
2015/11/03 21:59:41
Running tests to find out.
| |
57 return CSSPrimitiveValue::UnitType::Pixels; | 59 return CSSPrimitiveValue::UnitType::Pixels; |
58 | 60 |
59 if (m_unitType == LengthTypeREMS) | 61 return m_value->typeWithCalcResolved(); |
60 return CSSPrimitiveValue::UnitType::Rems; | |
61 if (m_unitType == LengthTypeCHS) | |
62 return CSSPrimitiveValue::UnitType::Chs; | |
63 | |
64 return static_cast<CSSPrimitiveValue::UnitType>(m_unitType); | |
65 } | 62 } |
66 void setUnitType(SVGLengthType); | 63 void setUnitType(CSSPrimitiveValue::UnitType); |
67 SVGLengthMode unitMode() const { return static_cast<SVGLengthMode>(m_unitMod e); } | 64 SVGLengthMode unitMode() const { return static_cast<SVGLengthMode>(m_unitMod e); } |
68 | 65 |
69 bool operator==(const SVGLength&) const; | 66 bool operator==(const SVGLength&) const; |
70 bool operator!=(const SVGLength& other) const { return !operator==(other); } | 67 bool operator!=(const SVGLength& other) const { return !operator==(other); } |
71 | 68 |
72 float value(const SVGLengthContext&) const; | 69 float value(const SVGLengthContext&) const; |
73 void setValue(float, const SVGLengthContext&); | 70 void setValue(float, const SVGLengthContext&); |
74 | 71 |
75 float valueInSpecifiedUnits() const { return m_valueInSpecifiedUnits; } | 72 float valueInSpecifiedUnits() const { return m_value->getFloatValue(); } |
76 void setValueInSpecifiedUnits(float value) { m_valueInSpecifiedUnits = value ; } | 73 void setValueInSpecifiedUnits(float value) |
74 { | |
75 m_value = CSSPrimitiveValue::create(value, m_value->typeWithCalcResolved ()); | |
76 } | |
77 | 77 |
78 // Resolves LengthTypePercentage into a normalized floating point number (fu ll value is 1.0). | 78 // Resolves LengthTypePercentage into a normalized floating point number (fu ll value is 1.0). |
79 float valueAsPercentage() const; | 79 float valueAsPercentage() const; |
80 | 80 |
81 // Returns a number to be used as percentage (so full value is 100) | 81 // Returns a number to be used as percentage (so full value is 100) |
82 float valueAsPercentage100() const; | 82 float valueAsPercentage100() const; |
83 | 83 |
84 // Scale the input value by this SVGLength. Higher precision than input * va lueAsPercentage(). | 84 // Scale the input value by this SVGLength. Higher precision than input * va lueAsPercentage(). |
85 float scaleByPercentage(float) const; | 85 float scaleByPercentage(float) const; |
86 | 86 |
87 String valueAsString() const override; | 87 String valueAsString() const override; |
88 void setValueAsString(const String&, ExceptionState&); | 88 void setValueAsString(const String&, ExceptionState&); |
89 | 89 |
90 void newValueSpecifiedUnits(SVGLengthType, float valueInSpecifiedUnits); | 90 void newValueSpecifiedUnits(CSSPrimitiveValue::UnitType, float valueInSpecif iedUnits); |
91 void convertToSpecifiedUnits(SVGLengthType, const SVGLengthContext&); | 91 void convertToSpecifiedUnits(CSSPrimitiveValue::UnitType, const SVGLengthCon text&); |
92 | 92 |
93 // Helper functions | 93 // Helper functions |
94 static inline bool isRelativeUnit(SVGLengthType unitType) | 94 static inline bool isRelativeUnit(CSSPrimitiveValue::UnitType unitType) |
95 { | 95 { |
96 return unitType == LengthTypePercentage | 96 return unitType == CSSPrimitiveValue::UnitType::Percentage |
97 || unitType == LengthTypeEMS | 97 || unitType == CSSPrimitiveValue::UnitType::Ems |
98 || unitType == LengthTypeEXS | 98 || unitType == CSSPrimitiveValue::UnitType::Exs |
99 || unitType == LengthTypeREMS | 99 || unitType == CSSPrimitiveValue::UnitType::Rems |
100 || unitType == LengthTypeCHS; | 100 || unitType == CSSPrimitiveValue::UnitType::Chs; |
101 } | 101 } |
102 inline bool isRelative() const { return isRelativeUnit(unitType()); } | 102 inline bool isRelative() const { return isRelativeUnit(m_value->typeWithCalc Resolved()); } |
103 | 103 |
104 bool isZero() const | 104 bool isZero() const |
105 { | 105 { |
106 return !m_valueInSpecifiedUnits; | 106 return m_value->getFloatValue() == 0; |
107 } | 107 } |
108 | 108 |
109 static SVGLengthMode lengthModeForAnimatedLengthAttribute(const QualifiedNam e&); | 109 static SVGLengthMode lengthModeForAnimatedLengthAttribute(const QualifiedNam e&); |
110 | 110 |
111 void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) override; | 111 void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) override; |
112 void calculateAnimatedValue(SVGAnimationElement*, float percentage, unsigned repeatCount, PassRefPtrWillBeRawPtr<SVGPropertyBase> from, PassRefPtrWillBeRawP tr<SVGPropertyBase> to, PassRefPtrWillBeRawPtr<SVGPropertyBase> toAtEndOfDuratio nValue, SVGElement* contextElement) override; | 112 void calculateAnimatedValue(SVGAnimationElement*, float percentage, unsigned repeatCount, PassRefPtrWillBeRawPtr<SVGPropertyBase> from, PassRefPtrWillBeRawP tr<SVGPropertyBase> to, PassRefPtrWillBeRawPtr<SVGPropertyBase> toAtEndOfDuratio nValue, SVGElement* contextElement) override; |
113 float calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to, SVGEleme nt* contextElement) override; | 113 float calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to, SVGEleme nt* contextElement) override; |
114 | 114 |
115 static AnimatedPropertyType classType() { return AnimatedLength; } | 115 static AnimatedPropertyType classType() { return AnimatedLength; } |
116 | 116 |
117 private: | 117 private: |
118 SVGLength(SVGLengthMode); | 118 SVGLength(SVGLengthMode); |
119 SVGLength(const SVGLength&); | 119 SVGLength(const SVGLength&); |
120 | 120 |
121 float m_valueInSpecifiedUnits; | 121 RefPtrWillBeMember<CSSPrimitiveValue> m_value; |
122 unsigned m_unitMode : 2; | 122 unsigned m_unitMode : 2; |
123 unsigned m_unitType : 4; | |
124 }; | 123 }; |
125 | 124 |
126 inline PassRefPtrWillBeRawPtr<SVGLength> toSVGLength(PassRefPtrWillBeRawPtr<SVGP ropertyBase> passBase) | 125 inline PassRefPtrWillBeRawPtr<SVGLength> toSVGLength(PassRefPtrWillBeRawPtr<SVGP ropertyBase> passBase) |
127 { | 126 { |
128 RefPtrWillBeRawPtr<SVGPropertyBase> base = passBase; | 127 RefPtrWillBeRawPtr<SVGPropertyBase> base = passBase; |
129 ASSERT(base->type() == SVGLength::classType()); | 128 ASSERT(base->type() == SVGLength::classType()); |
130 return static_pointer_cast<SVGLength>(base.release()); | 129 return static_pointer_cast<SVGLength>(base.release()); |
131 } | 130 } |
132 | 131 |
133 } // namespace blink | 132 } // namespace blink |
134 | 133 |
135 #endif // SVGLength_h | 134 #endif // SVGLength_h |
OLD | NEW |