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 virtual PassRefPtrWillBeRawPtr<SVGPropertyBase> cloneForAnimation(const Stri
ng&) const override; | 53 virtual PassRefPtrWillBeRawPtr<SVGPropertyBase> cloneForAnimation(const Stri
ng&) const override; |
52 | 54 |
53 SVGLengthType unitType() const { return static_cast<SVGLengthType>(m_unitTyp
e); } | 55 CSSPrimitiveValue::UnitType primitiveType() const { return m_value->primitiv
eType(); } |
| 56 |
54 CSSPrimitiveValue::UnitType cssUnitTypeQuirk() const | 57 CSSPrimitiveValue::UnitType cssUnitTypeQuirk() const |
55 { | 58 { |
56 if (m_unitType == LengthTypeNumber) | 59 if (m_value->primitiveType() == CSSPrimitiveValue::UnitType::CSS_NUMBER) |
57 return CSSPrimitiveValue::UnitType::CSS_PX; | 60 return CSSPrimitiveValue::UnitType::CSS_PX; |
58 | 61 |
59 if (m_unitType == LengthTypeREMS) | 62 return m_value->primitiveType(); |
60 return CSSPrimitiveValue::UnitType::CSS_REMS; | |
61 if (m_unitType == LengthTypeCHS) | |
62 return CSSPrimitiveValue::UnitType::CSS_CHS; | |
63 | |
64 return static_cast<CSSPrimitiveValue::UnitType>(m_unitType); | |
65 } | 63 } |
66 void setUnitType(SVGLengthType); | 64 void setUnitType(CSSPrimitiveValue::UnitType); |
67 SVGLengthMode unitMode() const { return static_cast<SVGLengthMode>(m_unitMod
e); } | 65 SVGLengthMode unitMode() const { return static_cast<SVGLengthMode>(m_unitMod
e); } |
68 | 66 |
69 bool operator==(const SVGLength&) const; | 67 bool operator==(const SVGLength&) const; |
70 bool operator!=(const SVGLength& other) const { return !operator==(other); } | 68 bool operator!=(const SVGLength& other) const { return !operator==(other); } |
71 | 69 |
72 float value(const SVGLengthContext&) const; | 70 float value(const SVGLengthContext&) const; |
73 void setValue(float, const SVGLengthContext&); | 71 void setValue(float, const SVGLengthContext&); |
74 | 72 |
75 float valueInSpecifiedUnits() const { return m_valueInSpecifiedUnits; } | 73 float valueInSpecifiedUnits() const { return m_value->getFloatValue(); } |
76 void setValueInSpecifiedUnits(float value) { m_valueInSpecifiedUnits = value
; } | 74 void setValueInSpecifiedUnits(float value) |
| 75 { |
| 76 m_value = CSSPrimitiveValue::create(value, m_value->primitiveType()); |
| 77 } |
77 | 78 |
78 // Resolves LengthTypePercentage into a normalized floating point number (fu
ll value is 1.0). | 79 // Resolves LengthTypePercentage into a normalized floating point number (fu
ll value is 1.0). |
79 float valueAsPercentage() const; | 80 float valueAsPercentage() const; |
80 | 81 |
81 // Returns a number to be used as percentage (so full value is 100) | 82 // Returns a number to be used as percentage (so full value is 100) |
82 float valueAsPercentage100() const; | 83 float valueAsPercentage100() const; |
83 | 84 |
84 // Scale the input value by this SVGLength. Higher precision than input * va
lueAsPercentage(). | 85 // Scale the input value by this SVGLength. Higher precision than input * va
lueAsPercentage(). |
85 float scaleByPercentage(float) const; | 86 float scaleByPercentage(float) const; |
86 | 87 |
87 virtual String valueAsString() const override; | 88 virtual String valueAsString() const override; |
88 void setValueAsString(const String&, ExceptionState&); | 89 void setValueAsString(const String&, ExceptionState&); |
89 | 90 |
90 void newValueSpecifiedUnits(SVGLengthType, float valueInSpecifiedUnits); | 91 void newValueSpecifiedUnits(CSSPrimitiveValue::UnitType, float valueInSpecif
iedUnits); |
91 void convertToSpecifiedUnits(SVGLengthType, const SVGLengthContext&); | 92 void convertToSpecifiedUnits(CSSPrimitiveValue::UnitType, const SVGLengthCon
text&); |
92 | 93 |
93 // Helper functions | 94 // Helper functions |
94 static inline bool isRelativeUnit(SVGLengthType unitType) | 95 static inline bool isRelativeUnit(CSSPrimitiveValue::UnitType unitType) |
95 { | 96 { |
96 return unitType == LengthTypePercentage | 97 return unitType == CSSPrimitiveValue::CSS_PERCENTAGE |
97 || unitType == LengthTypeEMS | 98 || unitType == CSSPrimitiveValue::CSS_EMS |
98 || unitType == LengthTypeEXS | 99 || unitType == CSSPrimitiveValue::CSS_EXS |
99 || unitType == LengthTypeREMS | 100 || unitType == CSSPrimitiveValue::CSS_REMS |
100 || unitType == LengthTypeCHS; | 101 || unitType == CSSPrimitiveValue::CSS_CHS; |
101 } | 102 } |
102 inline bool isRelative() const { return isRelativeUnit(unitType()); } | 103 inline bool isRelative() const { return isRelativeUnit(m_value->primitiveTyp
e()); } |
103 | 104 |
104 bool isZero() const | 105 bool isZero() const |
105 { | 106 { |
106 return !m_valueInSpecifiedUnits; | 107 return m_value->getFloatValue() == 0; |
107 } | 108 } |
108 | 109 |
109 static PassRefPtrWillBeRawPtr<SVGLength> fromCSSPrimitiveValue(CSSPrimitiveV
alue*); | 110 static PassRefPtrWillBeRawPtr<SVGLength> fromCSSPrimitiveValue(CSSPrimitiveV
alue*); |
110 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> toCSSPrimitiveValue(PassRef
PtrWillBeRawPtr<SVGLength>); | 111 |
111 static SVGLengthMode lengthModeForAnimatedLengthAttribute(const QualifiedNam
e&); | 112 static SVGLengthMode lengthModeForAnimatedLengthAttribute(const QualifiedNam
e&); |
112 | 113 |
113 PassRefPtrWillBeRawPtr<SVGLength> blend(PassRefPtrWillBeRawPtr<SVGLength> fr
om, float progress) const; | 114 PassRefPtrWillBeRawPtr<SVGLength> blend(PassRefPtrWillBeRawPtr<SVGLength> fr
om, float progress) const; |
114 | 115 |
115 virtual void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) overr
ide; | 116 virtual void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) overr
ide; |
116 virtual void calculateAnimatedValue(SVGAnimationElement*, float percentage,
unsigned repeatCount, PassRefPtrWillBeRawPtr<SVGPropertyBase> from, PassRefPtrWi
llBeRawPtr<SVGPropertyBase> to, PassRefPtrWillBeRawPtr<SVGPropertyBase> toAtEndO
fDurationValue, SVGElement* contextElement) override; | 117 virtual void calculateAnimatedValue(SVGAnimationElement*, float percentage,
unsigned repeatCount, PassRefPtrWillBeRawPtr<SVGPropertyBase> from, PassRefPtrWi
llBeRawPtr<SVGPropertyBase> to, PassRefPtrWillBeRawPtr<SVGPropertyBase> toAtEndO
fDurationValue, SVGElement* contextElement) override; |
117 virtual float calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to,
SVGElement* contextElement) override; | 118 virtual float calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to,
SVGElement* contextElement) override; |
118 | 119 |
119 static AnimatedPropertyType classType() { return AnimatedLength; } | 120 static AnimatedPropertyType classType() { return AnimatedLength; } |
120 | 121 |
121 private: | 122 private: |
122 SVGLength(SVGLengthMode); | 123 SVGLength(SVGLengthMode); |
123 SVGLength(const SVGLength&); | 124 SVGLength(const SVGLength&); |
124 | 125 |
125 float m_valueInSpecifiedUnits; | 126 RefPtrWillBeMember<CSSPrimitiveValue> m_value; |
126 unsigned m_unitMode : 2; | 127 unsigned m_unitMode : 2; |
127 unsigned m_unitType : 4; | |
128 }; | 128 }; |
129 | 129 |
130 inline PassRefPtrWillBeRawPtr<SVGLength> toSVGLength(PassRefPtrWillBeRawPtr<SVGP
ropertyBase> passBase) | 130 inline PassRefPtrWillBeRawPtr<SVGLength> toSVGLength(PassRefPtrWillBeRawPtr<SVGP
ropertyBase> passBase) |
131 { | 131 { |
132 RefPtrWillBeRawPtr<SVGPropertyBase> base = passBase; | 132 RefPtrWillBeRawPtr<SVGPropertyBase> base = passBase; |
133 ASSERT(base->type() == SVGLength::classType()); | 133 ASSERT(base->type() == SVGLength::classType()); |
134 return static_pointer_cast<SVGLength>(base.release()); | 134 return static_pointer_cast<SVGLength>(base.release()); |
135 } | 135 } |
136 | 136 |
137 } // namespace blink | 137 } // namespace blink |
138 | 138 |
139 #endif // SVGLength_h | 139 #endif // SVGLength_h |
OLD | NEW |