| 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) |
| 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 inline bool isRelative() const { return isRelativeUnit(m_value->typeWithCalc
Resolved()); } |
| 102 inline bool isRelative() const { return isRelativeUnit(unitType()); } | |
| 103 | 102 |
| 104 bool isZero() const | 103 bool isZero() const |
| 105 { | 104 { |
| 106 return !m_valueInSpecifiedUnits; | 105 return m_value->getFloatValue() == 0; |
| 107 } | 106 } |
| 108 | 107 |
| 109 static SVGLengthMode lengthModeForAnimatedLengthAttribute(const QualifiedNam
e&); | 108 static SVGLengthMode lengthModeForAnimatedLengthAttribute(const QualifiedNam
e&); |
| 110 | 109 |
| 111 PassRefPtrWillBeRawPtr<SVGLength> blend(PassRefPtrWillBeRawPtr<SVGLength> fr
om, float progress) const; | 110 PassRefPtrWillBeRawPtr<SVGLength> blend(PassRefPtrWillBeRawPtr<SVGLength> fr
om, float progress) const; |
| 112 | 111 |
| 113 void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) override; | 112 void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) override; |
| 114 void calculateAnimatedValue(SVGAnimationElement*, float percentage, unsigned
repeatCount, PassRefPtrWillBeRawPtr<SVGPropertyBase> from, PassRefPtrWillBeRawP
tr<SVGPropertyBase> to, PassRefPtrWillBeRawPtr<SVGPropertyBase> toAtEndOfDuratio
nValue, SVGElement* contextElement) override; | 113 void calculateAnimatedValue(SVGAnimationElement*, float percentage, unsigned
repeatCount, PassRefPtrWillBeRawPtr<SVGPropertyBase> from, PassRefPtrWillBeRawP
tr<SVGPropertyBase> to, PassRefPtrWillBeRawPtr<SVGPropertyBase> toAtEndOfDuratio
nValue, SVGElement* contextElement) override; |
| 115 float calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to, SVGEleme
nt* contextElement) override; | 114 float calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to, SVGEleme
nt* contextElement) override; |
| 116 | 115 |
| 117 static AnimatedPropertyType classType() { return AnimatedLength; } | 116 static AnimatedPropertyType classType() { return AnimatedLength; } |
| 118 | 117 |
| 119 private: | 118 private: |
| 120 SVGLength(SVGLengthMode); | 119 SVGLength(SVGLengthMode); |
| 121 SVGLength(const SVGLength&); | 120 SVGLength(const SVGLength&); |
| 122 | 121 |
| 123 float m_valueInSpecifiedUnits; | 122 RefPtrWillBeMember<CSSPrimitiveValue> m_value; |
| 124 unsigned m_unitMode : 2; | 123 unsigned m_unitMode : 2; |
| 125 unsigned m_unitType : 4; | |
| 126 }; | 124 }; |
| 127 | 125 |
| 128 inline PassRefPtrWillBeRawPtr<SVGLength> toSVGLength(PassRefPtrWillBeRawPtr<SVGP
ropertyBase> passBase) | 126 inline PassRefPtrWillBeRawPtr<SVGLength> toSVGLength(PassRefPtrWillBeRawPtr<SVGP
ropertyBase> passBase) |
| 129 { | 127 { |
| 130 RefPtrWillBeRawPtr<SVGPropertyBase> base = passBase; | 128 RefPtrWillBeRawPtr<SVGPropertyBase> base = passBase; |
| 131 ASSERT(base->type() == SVGLength::classType()); | 129 ASSERT(base->type() == SVGLength::classType()); |
| 132 return static_pointer_cast<SVGLength>(base.release()); | 130 return static_pointer_cast<SVGLength>(base.release()); |
| 133 } | 131 } |
| 134 | 132 |
| 135 } // namespace blink | 133 } // namespace blink |
| 136 | 134 |
| 137 #endif // SVGLength_h | 135 #endif // SVGLength_h |
| OLD | NEW |