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

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

Issue 112003003: [SVG] SVGLength{,List} migration to new SVG property impl. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: revert aggressive svgAttributeChanged, add NeedsRebaseline Created 6 years, 11 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
« no previous file with comments | « Source/core/svg/SVGImageElement.cpp ('k') | Source/core/svg/SVGLength.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public License 15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to 16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA. 18 * Boston, MA 02110-1301, USA.
19 */ 19 */
20 20
21 #ifndef SVGLength_h 21 #ifndef SVGLength_h
22 #define SVGLength_h 22 #define SVGLength_h
23 23
24 #include "bindings/v8/ExceptionState.h" 24 #include "bindings/v8/ExceptionMessages.h"
25 #include "bindings/v8/ExceptionStatePlaceholder.h"
26 #include "bindings/v8/ScriptWrappable.h"
27 #include "core/dom/ExceptionCode.h"
25 #include "core/svg/SVGLengthContext.h" 28 #include "core/svg/SVGLengthContext.h"
26 #include "core/svg/SVGParsingError.h" 29 #include "core/svg/SVGParsingError.h"
27 #include "core/svg/properties/SVGPropertyTraits.h" 30 #include "core/svg/properties/NewSVGProperty.h"
28 #include "platform/animation/AnimationUtilities.h"
29 31
30 namespace WebCore { 32 namespace WebCore {
31 33
32 class CSSPrimitiveValue; 34 class CSSPrimitiveValue;
33 class ExceptionState; 35 class ExceptionState;
34 class QualifiedName; 36 class QualifiedName;
35 37
36 enum SVGLengthNegativeValuesMode { 38 enum SVGLengthNegativeValuesMode {
37 AllowNegativeLengths, 39 AllowNegativeLengths,
38 ForbidNegativeLengths 40 ForbidNegativeLengths
39 }; 41 };
40 42
41 class SVGLength { 43 class SVGLengthTearOff;
42 WTF_MAKE_FAST_ALLOCATED; 44
45 class SVGLength : public NewSVGPropertyBase {
43 public: 46 public:
44 // Forward declare these enums in the w3c naming scheme, for IDL generation 47 typedef SVGLengthTearOff TearOffType;
45 enum {
46 SVG_LENGTHTYPE_UNKNOWN = LengthTypeUnknown,
47 SVG_LENGTHTYPE_NUMBER = LengthTypeNumber,
48 SVG_LENGTHTYPE_PERCENTAGE = LengthTypePercentage,
49 SVG_LENGTHTYPE_EMS = LengthTypeEMS,
50 SVG_LENGTHTYPE_EXS = LengthTypeEXS,
51 SVG_LENGTHTYPE_PX = LengthTypePX,
52 SVG_LENGTHTYPE_CM = LengthTypeCM,
53 SVG_LENGTHTYPE_MM = LengthTypeMM,
54 SVG_LENGTHTYPE_IN = LengthTypeIN,
55 SVG_LENGTHTYPE_PT = LengthTypePT,
56 SVG_LENGTHTYPE_PC = LengthTypePC
57 };
58 48
59 SVGLength(SVGLengthMode = LengthModeOther, const String& valueAsString = Str ing()); 49 static PassRefPtr<SVGLength> create(SVGLengthMode mode = LengthModeOther)
60 SVGLength(const SVGLengthContext&, float, SVGLengthMode = LengthModeOther, S VGLengthType = LengthTypeNumber); 50 {
61 SVGLength(const SVGLength&); 51 return adoptRef(new SVGLength(mode));
52 }
62 53
63 SVGLengthType unitType() const; 54 PassRefPtr<SVGLength> clone() const;
64 SVGLengthMode unitMode() const; 55 virtual PassRefPtr<NewSVGPropertyBase> cloneForAnimation(const String&) cons t OVERRIDE;
56
57 SVGLengthType unitType() const { return static_cast<SVGLengthType>(m_unitTyp e); }
58 void setUnitType(SVGLengthType);
59 SVGLengthMode unitMode() const { return static_cast<SVGLengthMode>(m_unitMod e); }
65 60
66 bool operator==(const SVGLength&) const; 61 bool operator==(const SVGLength&) const;
67 bool operator!=(const SVGLength&) const; 62 bool operator!=(const SVGLength& other) const { return !operator==(other); }
68 63
69 static SVGLength construct(SVGLengthMode, const String&, SVGParsingError&, S VGLengthNegativeValuesMode = AllowNegativeLengths); 64 float value(const SVGLengthContext& context) const
70 65 {
71 float value(const SVGLengthContext&) const; 66 return value(context, IGNORE_EXCEPTION);
67 }
72 float value(const SVGLengthContext&, ExceptionState&) const; 68 float value(const SVGLengthContext&, ExceptionState&) const;
73 void setValue(float, const SVGLengthContext&, ExceptionState&); 69 void setValue(float, const SVGLengthContext&, ExceptionState&);
74 void setValue(const SVGLengthContext&, float, SVGLengthMode, SVGLengthType, ExceptionState&);
75 70
76 float valueInSpecifiedUnits() const { return m_valueInSpecifiedUnits; } 71 float valueInSpecifiedUnits() const { return m_valueInSpecifiedUnits; }
77 void setValueInSpecifiedUnits(float value) { m_valueInSpecifiedUnits = value ; } 72 void setValueInSpecifiedUnits(float value) { m_valueInSpecifiedUnits = value ; }
78 73
79 float valueAsPercentage() const; 74 float valueAsPercentage() const;
80 75
81 String valueAsString() const; 76 virtual String valueAsString() const OVERRIDE;
82 void setValueAsString(const String&, ExceptionState&); 77 void setValueAsString(const String&, ExceptionState&);
83 void setValueAsString(const String&, SVGLengthMode, ExceptionState&);
84 78
85 void newValueSpecifiedUnits(unsigned short, float valueInSpecifiedUnits, Exc eptionState&); 79 void newValueSpecifiedUnits(SVGLengthType, float valueInSpecifiedUnits);
86 void convertToSpecifiedUnits(unsigned short, const SVGLengthContext&, Except ionState&); 80 void convertToSpecifiedUnits(SVGLengthType, const SVGLengthContext&, Excepti onState&);
87 81
88 // Helper functions 82 // Helper functions
89 inline bool isRelative() const 83 inline bool isRelative() const
90 { 84 {
91 SVGLengthType type = unitType(); 85 return m_unitType == LengthTypePercentage
92 return type == LengthTypePercentage || type == LengthTypeEMS || type == LengthTypeEXS; 86 || m_unitType == LengthTypeEMS
87 || m_unitType == LengthTypeEXS;
93 } 88 }
94 89
95 bool isZero() const 90 bool isZero() const
96 { 91 {
97 return !m_valueInSpecifiedUnits; 92 return !m_valueInSpecifiedUnits;
98 } 93 }
99 94
100 static SVGLength fromCSSPrimitiveValue(CSSPrimitiveValue*); 95 static PassRefPtr<SVGLength> fromCSSPrimitiveValue(CSSPrimitiveValue*);
101 static PassRefPtr<CSSPrimitiveValue> toCSSPrimitiveValue(const SVGLength&); 96 static PassRefPtr<CSSPrimitiveValue> toCSSPrimitiveValue(PassRefPtr<SVGLengt h>);
102 static SVGLengthMode lengthModeForAnimatedLengthAttribute(const QualifiedNam e&); 97 static SVGLengthMode lengthModeForAnimatedLengthAttribute(const QualifiedNam e&);
103 98
104 SVGLength blend(const SVGLength& from, float progress) const 99 PassRefPtr<SVGLength> blend(PassRefPtr<SVGLength> from, float progress) cons t;
105 {
106 SVGLengthType toType = unitType();
107 SVGLengthType fromType = from.unitType();
108 if ((from.isZero() && isZero())
109 || fromType == LengthTypeUnknown
110 || toType == LengthTypeUnknown
111 || (!from.isZero() && fromType != LengthTypePercentage && toType == LengthTypePercentage)
112 || (!isZero() && fromType == LengthTypePercentage && toType != Lengt hTypePercentage)
113 || (!from.isZero() && !isZero() && (fromType == LengthTypeEMS || fro mType == LengthTypeEXS) && fromType != toType))
114 return *this;
115 100
116 SVGLength length; 101 virtual void add(PassRefPtr<NewSVGPropertyBase>, SVGElement*) OVERRIDE;
117 TrackExceptionState exceptionState; 102 virtual void calculateAnimatedValue(SVGAnimationElement*, float percentage, unsigned repeatCount, PassRefPtr<NewSVGPropertyBase> from, PassRefPtr<NewSVGProp ertyBase> to, PassRefPtr<NewSVGPropertyBase> toAtEndOfDurationValue, SVGElement* contextElement) OVERRIDE;
103 virtual float calculateDistance(PassRefPtr<NewSVGPropertyBase> to, SVGElemen t* contextElement) OVERRIDE;
118 104
119 if (fromType == LengthTypePercentage || toType == LengthTypePercentage) { 105 static AnimatedPropertyType classType() { return AnimatedLength; }
120 float fromPercent = from.valueAsPercentage() * 100;
121 float toPercent = valueAsPercentage() * 100;
122 length.newValueSpecifiedUnits(LengthTypePercentage, WebCore::blend(f romPercent, toPercent, progress), exceptionState);
123 if (exceptionState.hadException())
124 return SVGLength();
125 return length;
126 }
127
128 if (fromType == toType || from.isZero() || isZero() || fromType == Lengt hTypeEMS || fromType == LengthTypeEXS) {
129 float fromValue = from.valueInSpecifiedUnits();
130 float toValue = valueInSpecifiedUnits();
131 if (isZero())
132 length.newValueSpecifiedUnits(fromType, WebCore::blend(fromValue , toValue, progress), exceptionState);
133 else
134 length.newValueSpecifiedUnits(toType, WebCore::blend(fromValue, toValue, progress), exceptionState);
135 if (exceptionState.hadException())
136 return SVGLength();
137 return length;
138 }
139
140 ASSERT(!isRelative());
141 ASSERT(!from.isRelative());
142
143 SVGLengthContext nonRelativeLengthContext(0);
144 float fromValueInUserUnits = nonRelativeLengthContext.convertValueToUser Units(from.valueInSpecifiedUnits(), from.unitMode(), fromType, exceptionState);
145 if (exceptionState.hadException())
146 return SVGLength();
147
148 float fromValue = nonRelativeLengthContext.convertValueFromUserUnits(fro mValueInUserUnits, unitMode(), toType, exceptionState);
149 if (exceptionState.hadException())
150 return SVGLength();
151
152 float toValue = valueInSpecifiedUnits();
153 length.newValueSpecifiedUnits(toType, WebCore::blend(fromValue, toValue, progress), exceptionState);
154
155 if (exceptionState.hadException())
156 return SVGLength();
157 return length;
158 }
159 106
160 private: 107 private:
108 SVGLength(SVGLengthMode);
109 SVGLength(const SVGLength&);
110
161 float m_valueInSpecifiedUnits; 111 float m_valueInSpecifiedUnits;
162 unsigned int m_unit; 112 unsigned m_unitMode : 2;
113 unsigned m_unitType : 4;
163 }; 114 };
164 115
165 template<> 116 inline PassRefPtr<SVGLength> toSVGLength(PassRefPtr<NewSVGPropertyBase> passBase )
166 struct SVGPropertyTraits<SVGLength> { 117 {
167 static SVGLength initialValue() { return SVGLength(); } 118 RefPtr<NewSVGPropertyBase> base = passBase;
168 static String toString(const SVGLength& type) { return type.valueAsString(); } 119 ASSERT(base->type() == SVGLength::classType());
169 }; 120 return static_pointer_cast<SVGLength>(base.release());
170 121 }
171 122
172 } // namespace WebCore 123 } // namespace WebCore
173 124
174 #endif // SVGLength_h 125 #endif // SVGLength_h
OLDNEW
« no previous file with comments | « Source/core/svg/SVGImageElement.cpp ('k') | Source/core/svg/SVGLength.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698