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

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

Issue 1162453002: [svg2] Make SVGLength wrap a CSSPrimitiveValue (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: tweak TE Created 5 years, 6 months 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 | Annotate | Revision Log
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 PassRefPtrWillBeRawPtr<SVGLength> clone() const; 50 PassRefPtrWillBeRawPtr<SVGLength> clone() const;
51 virtual PassRefPtrWillBeRawPtr<SVGPropertyBase> cloneForAnimation(const Stri ng&) const override; 51 virtual PassRefPtrWillBeRawPtr<SVGPropertyBase> cloneForAnimation(const Stri ng&) const override;
52 52
53 SVGLengthType unitType() const { return static_cast<SVGLengthType>(m_unitTyp e); } 53 CSSPrimitiveValue* getCSSPrimitiveValue() { return m_value.get(); }
pdr. 2015/05/28 21:28:19 It looks like this is only used to access the prim
Erik Dahlström 2015/06/02 11:57:44 Sure.
54
55 static CSSPrimitiveValue::UnitType toCSSUnit(SVGLengthType type)
56 {
57 switch (type) {
58 case LengthTypeUnknown:
59 return CSSPrimitiveValue::UnitType::CSS_UNKNOWN;
60 case LengthTypeNumber:
61 return CSSPrimitiveValue::UnitType::CSS_NUMBER;
62 case LengthTypePercentage:
63 return CSSPrimitiveValue::UnitType::CSS_PERCENTAGE;
64 case LengthTypeEMS:
65 return CSSPrimitiveValue::UnitType::CSS_EMS;
66 case LengthTypeEXS:
67 return CSSPrimitiveValue::UnitType::CSS_EXS;
68 case LengthTypePX:
69 return CSSPrimitiveValue::UnitType::CSS_PX;
70 case LengthTypeCM:
71 return CSSPrimitiveValue::UnitType::CSS_CM;
72 case LengthTypeMM:
73 return CSSPrimitiveValue::UnitType::CSS_MM;
74 case LengthTypeIN:
75 return CSSPrimitiveValue::UnitType::CSS_IN;
76 case LengthTypePT:
77 return CSSPrimitiveValue::UnitType::CSS_PT;
78 case LengthTypePC:
79 return CSSPrimitiveValue::UnitType::CSS_PC;
80 default:
81 return CSSPrimitiveValue::UnitType::CSS_UNKNOWN;
82 }
83 }
84
54 CSSPrimitiveValue::UnitType cssUnitTypeQuirk() const 85 CSSPrimitiveValue::UnitType cssUnitTypeQuirk() const
55 { 86 {
56 if (m_unitType == LengthTypeNumber) 87 if (m_value->primitiveType() == CSSPrimitiveValue::UnitType::CSS_NUMBER)
57 return CSSPrimitiveValue::UnitType::CSS_PX; 88 return CSSPrimitiveValue::UnitType::CSS_PX;
58 89
59 if (m_unitType == LengthTypeREMS) 90 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 } 91 }
66 void setUnitType(SVGLengthType); 92 void setUnitType(CSSPrimitiveValue::UnitType);
67 SVGLengthMode unitMode() const { return static_cast<SVGLengthMode>(m_unitMod e); } 93 SVGLengthMode unitMode() const { return static_cast<SVGLengthMode>(m_unitMod e); }
68 94
69 bool operator==(const SVGLength&) const; 95 bool operator==(const SVGLength&) const;
70 bool operator!=(const SVGLength& other) const { return !operator==(other); } 96 bool operator!=(const SVGLength& other) const { return !operator==(other); }
71 97
72 float value(const SVGLengthContext&) const; 98 float value(const SVGLengthContext&) const;
73 void setValue(float, const SVGLengthContext&); 99 void setValue(float, const SVGLengthContext&);
74 100
75 float valueInSpecifiedUnits() const { return m_valueInSpecifiedUnits; } 101 float valueInSpecifiedUnits() const { return m_value->getFloatValue(); }
76 void setValueInSpecifiedUnits(float value) { m_valueInSpecifiedUnits = value ; } 102 void setValueInSpecifiedUnits(float value)
103 {
104 m_value = CSSPrimitiveValue::create(value, m_value->primitiveType());
105 }
77 106
78 // Resolves LengthTypePercentage into a normalized floating point number (fu ll value is 1.0). 107 // Resolves LengthTypePercentage into a normalized floating point number (fu ll value is 1.0).
79 float valueAsPercentage() const; 108 float valueAsPercentage() const;
80 109
81 // Returns a number to be used as percentage (so full value is 100) 110 // Returns a number to be used as percentage (so full value is 100)
82 float valueAsPercentage100() const; 111 float valueAsPercentage100() const;
83 112
84 // Scale the input value by this SVGLength. Higher precision than input * va lueAsPercentage(). 113 // Scale the input value by this SVGLength. Higher precision than input * va lueAsPercentage().
85 float scaleByPercentage(float) const; 114 float scaleByPercentage(float) const;
86 115
87 virtual String valueAsString() const override; 116 virtual String valueAsString() const override;
88 void setValueAsString(const String&, ExceptionState&); 117 void setValueAsString(const String&, ExceptionState&);
89 118
90 void newValueSpecifiedUnits(SVGLengthType, float valueInSpecifiedUnits); 119 void newValueSpecifiedUnits(CSSPrimitiveValue::UnitType, float valueInSpecif iedUnits);
91 void convertToSpecifiedUnits(SVGLengthType, const SVGLengthContext&); 120 void convertToSpecifiedUnits(CSSPrimitiveValue::UnitType, const SVGLengthCon text&);
92 121
93 // Helper functions 122 // Helper functions
94 static inline bool isRelativeUnit(SVGLengthType unitType) 123 static inline bool isRelativeUnit(CSSPrimitiveValue::UnitType unitType)
95 { 124 {
96 return unitType == LengthTypePercentage 125 return unitType == CSSPrimitiveValue::CSS_PERCENTAGE
97 || unitType == LengthTypeEMS 126 || unitType == CSSPrimitiveValue::CSS_EMS
98 || unitType == LengthTypeEXS 127 || unitType == CSSPrimitiveValue::CSS_EXS
99 || unitType == LengthTypeREMS 128 || unitType == CSSPrimitiveValue::CSS_REMS
100 || unitType == LengthTypeCHS; 129 || unitType == CSSPrimitiveValue::CSS_CHS;
101 } 130 }
102 inline bool isRelative() const { return isRelativeUnit(unitType()); } 131 inline bool isRelative() const { return isRelativeUnit(m_value->primitiveTyp e()); }
103 132
104 bool isZero() const 133 bool isZero() const
105 { 134 {
106 return !m_valueInSpecifiedUnits; 135 return m_value->getFloatValue() == 0;
107 } 136 }
108 137
109 static PassRefPtrWillBeRawPtr<SVGLength> fromCSSPrimitiveValue(CSSPrimitiveV alue*); 138 static PassRefPtrWillBeRawPtr<SVGLength> fromCSSPrimitiveValue(CSSPrimitiveV alue*);
110 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> toCSSPrimitiveValue(PassRef PtrWillBeRawPtr<SVGLength>); 139
111 static SVGLengthMode lengthModeForAnimatedLengthAttribute(const QualifiedNam e&); 140 static SVGLengthMode lengthModeForAnimatedLengthAttribute(const QualifiedNam e&);
112 141
113 PassRefPtrWillBeRawPtr<SVGLength> blend(PassRefPtrWillBeRawPtr<SVGLength> fr om, float progress) const; 142 PassRefPtrWillBeRawPtr<SVGLength> blend(PassRefPtrWillBeRawPtr<SVGLength> fr om, float progress) const;
114 143
115 virtual void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) overr ide; 144 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; 145 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; 146 virtual float calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to, SVGElement* contextElement) override;
118 147
119 static AnimatedPropertyType classType() { return AnimatedLength; } 148 static AnimatedPropertyType classType() { return AnimatedLength; }
120 149
121 private: 150 private:
122 SVGLength(SVGLengthMode); 151 SVGLength(SVGLengthMode);
123 SVGLength(const SVGLength&); 152 SVGLength(const SVGLength&);
124 153
125 float m_valueInSpecifiedUnits; 154 RefPtrWillBeMember<CSSPrimitiveValue> m_value;
pdr. 2015/05/28 21:28:18 Does this need to be a pointer? I wonder if it can
fs 2015/05/29 08:09:42 Then it'd need to be copied when it's used as a pr
fs 2015/05/29 13:49:06 Oh, yeah, almost forgot, Oilpan. That also means t
Erik Dahlström 2015/06/02 11:57:44 Ok, will add that.
Erik Dahlström 2015/06/02 11:57:44 It can't be a simple member, since CSSPrimitiveVal
126 unsigned m_unitMode : 2; 155 unsigned m_unitMode : 2;
pdr. 2015/05/28 21:28:18 Can we use CSSPrimitiveValue's LengthUnitType and
fs 2015/05/29 08:09:42 That's a different thing. In most cases it should
Erik Dahlström 2015/06/02 11:57:44 Yes, it's not quite the same as LengthUnitType I t
127 unsigned m_unitType : 4;
128 }; 156 };
129 157
130 inline PassRefPtrWillBeRawPtr<SVGLength> toSVGLength(PassRefPtrWillBeRawPtr<SVGP ropertyBase> passBase) 158 inline PassRefPtrWillBeRawPtr<SVGLength> toSVGLength(PassRefPtrWillBeRawPtr<SVGP ropertyBase> passBase)
131 { 159 {
132 RefPtrWillBeRawPtr<SVGPropertyBase> base = passBase; 160 RefPtrWillBeRawPtr<SVGPropertyBase> base = passBase;
133 ASSERT(base->type() == SVGLength::classType()); 161 ASSERT(base->type() == SVGLength::classType());
134 return static_pointer_cast<SVGLength>(base.release()); 162 return static_pointer_cast<SVGLength>(base.release());
135 } 163 }
136 164
137 } // namespace blink 165 } // namespace blink
138 166
139 #endif // SVGLength_h 167 #endif // SVGLength_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698