Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: third_party/WebKit/Source/core/svg/SVGLength.h

Issue 1421533006: Make SVGLength wrap a CSSPrimitiveValue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added expectation Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 return m_value->typeWithCalcResolved();
57 return CSSPrimitiveValue::UnitType::Pixels;
58
59 if (m_unitType == LengthTypeREMS)
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 } 59 }
66 void setUnitType(SVGLengthType); 60 void setUnitType(CSSPrimitiveValue::UnitType);
67 SVGLengthMode unitMode() const { return static_cast<SVGLengthMode>(m_unitMod e); } 61 SVGLengthMode unitMode() const { return static_cast<SVGLengthMode>(m_unitMod e); }
68 62
69 bool operator==(const SVGLength&) const; 63 bool operator==(const SVGLength&) const;
70 bool operator!=(const SVGLength& other) const { return !operator==(other); } 64 bool operator!=(const SVGLength& other) const { return !operator==(other); }
71 65
72 float value(const SVGLengthContext&) const; 66 float value(const SVGLengthContext&) const;
73 void setValue(float, const SVGLengthContext&); 67 void setValue(float, const SVGLengthContext&);
74 68
75 float valueInSpecifiedUnits() const { return m_valueInSpecifiedUnits; } 69 float valueInSpecifiedUnits() const { return m_value->getFloatValue(); }
76 void setValueInSpecifiedUnits(float value) { m_valueInSpecifiedUnits = value ; } 70 void setValueInSpecifiedUnits(float value)
71 {
72 m_value = CSSPrimitiveValue::create(value, m_value->typeWithCalcResolved ());
73 }
77 74
78 // Resolves LengthTypePercentage into a normalized floating point number (fu ll value is 1.0). 75 // Resolves LengthTypePercentage into a normalized floating point number (fu ll value is 1.0).
79 float valueAsPercentage() const; 76 float valueAsPercentage() const;
80 77
81 // Returns a number to be used as percentage (so full value is 100) 78 // Returns a number to be used as percentage (so full value is 100)
82 float valueAsPercentage100() const; 79 float valueAsPercentage100() const;
83 80
84 // Scale the input value by this SVGLength. Higher precision than input * va lueAsPercentage(). 81 // Scale the input value by this SVGLength. Higher precision than input * va lueAsPercentage().
85 float scaleByPercentage(float) const; 82 float scaleByPercentage(float) const;
86 83
87 String valueAsString() const override; 84 String valueAsString() const override;
88 void setValueAsString(const String&, ExceptionState&); 85 void setValueAsString(const String&, ExceptionState&);
89 86
90 void newValueSpecifiedUnits(SVGLengthType, float valueInSpecifiedUnits); 87 void newValueSpecifiedUnits(CSSPrimitiveValue::UnitType, float valueInSpecif iedUnits);
91 void convertToSpecifiedUnits(SVGLengthType, const SVGLengthContext&); 88 void convertToSpecifiedUnits(CSSPrimitiveValue::UnitType, const SVGLengthCon text&);
92 89
93 // Helper functions 90 // Helper functions
94 static inline bool isRelativeUnit(SVGLengthType unitType) 91 static inline bool isRelativeUnit(CSSPrimitiveValue::UnitType unitType)
95 { 92 {
96 return unitType == LengthTypePercentage 93 return unitType == CSSPrimitiveValue::UnitType::Percentage
97 || unitType == LengthTypeEMS 94 || unitType == CSSPrimitiveValue::UnitType::Ems
98 || unitType == LengthTypeEXS 95 || unitType == CSSPrimitiveValue::UnitType::Exs
99 || unitType == LengthTypeREMS 96 || unitType == CSSPrimitiveValue::UnitType::Rems
100 || unitType == LengthTypeCHS; 97 || unitType == CSSPrimitiveValue::UnitType::Chs;
101 } 98 }
102 inline bool isRelative() const { return isRelativeUnit(unitType()); } 99 inline bool isRelative() const { return isRelativeUnit(m_value->typeWithCalc Resolved()); }
103 100
104 bool isZero() const 101 bool isZero() const
105 { 102 {
106 return !m_valueInSpecifiedUnits; 103 return m_value->getFloatValue() == 0;
107 } 104 }
108 105
109 static SVGLengthMode lengthModeForAnimatedLengthAttribute(const QualifiedNam e&); 106 static SVGLengthMode lengthModeForAnimatedLengthAttribute(const QualifiedNam e&);
110 107
111 void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) override; 108 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; 109 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; 110 float calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to, SVGEleme nt* contextElement) override;
114 111
115 static AnimatedPropertyType classType() { return AnimatedLength; } 112 static AnimatedPropertyType classType() { return AnimatedLength; }
116 113
117 private: 114 private:
118 SVGLength(SVGLengthMode); 115 SVGLength(SVGLengthMode);
119 SVGLength(const SVGLength&); 116 SVGLength(const SVGLength&);
120 117
121 float m_valueInSpecifiedUnits; 118 RefPtrWillBeMember<CSSPrimitiveValue> m_value;
122 unsigned m_unitMode : 2; 119 unsigned m_unitMode : 2;
123 unsigned m_unitType : 4;
124 }; 120 };
125 121
126 DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGLength); 122 DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGLength);
127 123
128 } // namespace blink 124 } // namespace blink
129 125
130 #endif // SVGLength_h 126 #endif // SVGLength_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGAnimatedLength.cpp ('k') | third_party/WebKit/Source/core/svg/SVGLength.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698