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

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

Issue 1421533006: Make SVGLength wrap a CSSPrimitiveValue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 * Copyright (C) 2007 Apple Inc. All rights reserved. 4 * Copyright (C) 2007 Apple Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
11 * This library is distributed in the hope that it will be useful, 11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details. 14 * Library General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU Library General Public License 16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to 17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA. 19 * Boston, MA 02110-1301, USA.
20 */ 20 */
21 21
22 #include "config.h" 22 #include "config.h"
23 23
24 #include "core/svg/SVGLength.h" 24 #include "core/svg/SVGLength.h"
25 25
26 #include "bindings/core/v8/ExceptionState.h" 26 #include "bindings/core/v8/ExceptionState.h"
27 #include "core/SVGNames.h" 27 #include "core/SVGNames.h"
28 #include "core/css/CSSPrimitiveValue.h" 28 #include "core/css/CSSPrimitiveValue.h"
29 #include "core/css/CSSValue.h"
30 #include "core/css/CSSValuePool.h"
31 #include "core/css/parser/CSSParser.h"
29 #include "core/dom/ExceptionCode.h" 32 #include "core/dom/ExceptionCode.h"
30 #include "core/svg/SVGAnimationElement.h" 33 #include "core/svg/SVGAnimationElement.h"
31 #include "core/svg/SVGParserUtilities.h" 34 #include "core/svg/SVGParserUtilities.h"
32 #include "platform/animation/AnimationUtilities.h" 35 #include "platform/animation/AnimationUtilities.h"
33 #include "wtf/MathExtras.h" 36 #include "wtf/MathExtras.h"
34 #include "wtf/text/WTFString.h" 37 #include "wtf/text/WTFString.h"
35 38
36 namespace blink { 39 namespace blink {
37 40
38 namespace {
39
40 inline const char* lengthTypeToString(SVGLengthType type)
41 {
42 switch (type) {
43 case LengthTypeUnknown:
44 case LengthTypeNumber:
45 return "";
46 case LengthTypePercentage:
47 return "%";
48 case LengthTypeEMS:
49 return "em";
50 case LengthTypeEXS:
51 return "ex";
52 case LengthTypePX:
53 return "px";
54 case LengthTypeCM:
55 return "cm";
56 case LengthTypeMM:
57 return "mm";
58 case LengthTypeIN:
59 return "in";
60 case LengthTypePT:
61 return "pt";
62 case LengthTypePC:
63 return "pc";
64 case LengthTypeREMS:
65 return "rem";
66 case LengthTypeCHS:
67 return "ch";
68 }
69
70 ASSERT_NOT_REACHED();
71 return "";
72 }
73
74 template<typename CharType>
75 SVGLengthType stringToLengthType(const CharType*& ptr, const CharType* end)
76 {
77 if (ptr == end)
78 return LengthTypeNumber;
79
80 SVGLengthType type = LengthTypeUnknown;
81 const CharType firstChar = *ptr++;
82
83 if (firstChar == '%') {
84 type = LengthTypePercentage;
85 } else if (isHTMLSpace<CharType>(firstChar)) {
86 type = LengthTypeNumber;
87 } else if (ptr < end) {
88 const CharType secondChar = *ptr++;
89
90 if (firstChar == 'p') {
91 if (secondChar == 'x')
92 type = LengthTypePX;
93 if (secondChar == 't')
94 type = LengthTypePT;
95 if (secondChar == 'c')
96 type = LengthTypePC;
97 } else if (firstChar == 'e') {
98 if (secondChar == 'm')
99 type = LengthTypeEMS;
100 if (secondChar == 'x')
101 type = LengthTypeEXS;
102 } else if (firstChar == 'r') {
103 if (secondChar == 'e' && ptr < end) {
104 const CharType thirdChar = *ptr++;
105 if (thirdChar == 'm')
106 type = LengthTypeREMS;
107 }
108 } else if (firstChar == 'c') {
109 if (secondChar == 'h')
110 type = LengthTypeCHS;
111 if (secondChar == 'm')
112 type = LengthTypeCM;
113 } else if (firstChar == 'm' && secondChar == 'm') {
114 type = LengthTypeMM;
115 } else if (firstChar == 'i' && secondChar == 'n') {
116 type = LengthTypeIN;
117 } else if (isHTMLSpace<CharType>(firstChar) && isHTMLSpace<CharType>(sec ondChar)) {
118 type = LengthTypeNumber;
119 }
120 }
121
122 if (!skipOptionalSVGSpaces(ptr, end))
123 return type;
124
125 return LengthTypeUnknown;
126 }
127
128 } // namespace
129
130 SVGLength::SVGLength(SVGLengthMode mode) 41 SVGLength::SVGLength(SVGLengthMode mode)
131 : SVGPropertyBase(classType()) 42 : SVGPropertyBase(classType())
132 , m_valueInSpecifiedUnits(0) 43 , m_value(cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::Number) )
133 , m_unitMode(static_cast<unsigned>(mode)) 44 , m_unitMode(static_cast<unsigned>(mode))
134 , m_unitType(LengthTypeNumber)
135 { 45 {
136 ASSERT(unitMode() == mode); 46 ASSERT(unitMode() == mode);
137 } 47 }
138 48
139 SVGLength::SVGLength(const SVGLength& o) 49 SVGLength::SVGLength(const SVGLength& o)
140 : SVGPropertyBase(classType()) 50 : SVGPropertyBase(classType())
141 , m_valueInSpecifiedUnits(o.m_valueInSpecifiedUnits) 51 , m_value(o.m_value)
142 , m_unitMode(o.m_unitMode) 52 , m_unitMode(o.m_unitMode)
143 , m_unitType(o.m_unitType)
144 { 53 {
145 } 54 }
146 55
56 DEFINE_TRACE(SVGLength)
57 {
58 visitor->trace(m_value);
59 SVGPropertyBase::trace(visitor);
60 }
61
147 PassRefPtrWillBeRawPtr<SVGLength> SVGLength::clone() const 62 PassRefPtrWillBeRawPtr<SVGLength> SVGLength::clone() const
148 { 63 {
149 return adoptRefWillBeNoop(new SVGLength(*this)); 64 return adoptRefWillBeNoop(new SVGLength(*this));
150 } 65 }
151 66
152 PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGLength::cloneForAnimation(const Strin g& value) const 67 PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGLength::cloneForAnimation(const Strin g& value) const
153 { 68 {
154 RefPtrWillBeRawPtr<SVGLength> length = create(); 69 RefPtrWillBeRawPtr<SVGLength> length = create();
155 70
156 length->m_unitMode = m_unitMode; 71 length->m_unitMode = m_unitMode;
157 length->m_unitType = m_unitType;
158 72
159 TrackExceptionState exceptionState; 73 TrackExceptionState exceptionState;
160 length->setValueAsString(value, exceptionState); 74 length->setValueAsString(value, exceptionState);
161 if (exceptionState.hadException()) { 75 if (exceptionState.hadException()) {
162 length->m_unitType = LengthTypeNumber; 76 length->m_value = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitTy pe::Number);
163 length->m_valueInSpecifiedUnits = 0;
164 } 77 }
165 78
166 return length.release(); 79 return length.release();
167 } 80 }
168 81
169 bool SVGLength::operator==(const SVGLength& other) const 82 bool SVGLength::operator==(const SVGLength& other) const
170 { 83 {
171 return m_unitMode == other.m_unitMode 84 return m_unitMode == other.m_unitMode && m_value == other.m_value;
172 && m_unitType == other.m_unitType
173 && m_valueInSpecifiedUnits == other.m_valueInSpecifiedUnits;
174 } 85 }
175 86
176 float SVGLength::value(const SVGLengthContext& context) const 87 float SVGLength::value(const SVGLengthContext& context) const
177 { 88 {
178 return context.convertValueToUserUnits(m_valueInSpecifiedUnits, unitMode(), unitType()); 89 return context.convertValueToUserUnits(
90 m_value->getFloatValue(), unitMode(), m_value->typeWithCalcResolved());
179 } 91 }
180 92
181 void SVGLength::setValue(float value, const SVGLengthContext& context) 93 void SVGLength::setValue(float value, const SVGLengthContext& context)
182 { 94 {
183 m_valueInSpecifiedUnits = context.convertValueFromUserUnits(value, unitMode( ), unitType()); 95 m_value = CSSPrimitiveValue::create(
96 context.convertValueFromUserUnits(value, unitMode(), m_value->typeWithCa lcResolved()),
97 m_value->typeWithCalcResolved());
184 } 98 }
185 99
186 void SVGLength::setUnitType(SVGLengthType type) 100 void SVGLength::setUnitType(CSSPrimitiveValue::UnitType type)
187 { 101 {
188 ASSERT(type != LengthTypeUnknown && type <= LengthTypeCHS); 102 ASSERT(type != CSSPrimitiveValue::UnitType::Unknown
189 m_unitType = type; 103 && (type <= CSSPrimitiveValue::UnitType::Picas
104 || type == CSSPrimitiveValue::UnitType::Chs
105 || type == CSSPrimitiveValue::UnitType::Rems));
106 m_value = CSSPrimitiveValue::create(m_value->getFloatValue(), type);
190 } 107 }
191 108
192 float SVGLength::valueAsPercentage() const 109 float SVGLength::valueAsPercentage() const
193 { 110 {
194 // LengthTypePercentage is represented with 100% = 100.0. Good for accuracy but could eventually be changed. 111 // LengthTypePercentage is represented with 100% = 100.0. Good for accuracy but could eventually be changed.
195 if (m_unitType == LengthTypePercentage) { 112 if (m_value->typeWithCalcResolved() == CSSPrimitiveValue::UnitType::Percenta ge) {
196 // Note: This division is a source of floating point inaccuracy. 113 // Note: This division is a source of floating point inaccuracy.
197 return m_valueInSpecifiedUnits / 100; 114 return m_value->getFloatValue() / 100;
198 } 115 }
199 116
200 return m_valueInSpecifiedUnits; 117 return m_value->getFloatValue();
201 } 118 }
202 119
203 float SVGLength::valueAsPercentage100() const 120 float SVGLength::valueAsPercentage100() const
204 { 121 {
205 // LengthTypePercentage is represented with 100% = 100.0. Good for accuracy but could eventually be changed. 122 // LengthTypePercentage is represented with 100% = 100.0. Good for accuracy but could eventually be changed.
206 if (m_unitType == LengthTypePercentage) 123 if (m_value->typeWithCalcResolved() == CSSPrimitiveValue::UnitType::Percenta ge)
207 return m_valueInSpecifiedUnits; 124 return m_value->getFloatValue();
208 125
209 return m_valueInSpecifiedUnits * 100; 126 return m_value->getFloatValue() * 100;
210 } 127 }
211 128
212 float SVGLength::scaleByPercentage(float input) const 129 float SVGLength::scaleByPercentage(float input) const
213 { 130 {
214 float result = input * m_valueInSpecifiedUnits; 131 float result = input * m_value->getFloatValue();
215 if (m_unitType == LengthTypePercentage) { 132 if (m_value->typeWithCalcResolved() == CSSPrimitiveValue::UnitType::Percenta ge) {
216 // Delaying division by 100 as long as possible since it introduces floa ting point errors. 133 // Delaying division by 100 as long as possible since it introduces floa ting point errors.
217 result = result / 100; 134 result = result / 100;
218 } 135 }
219 return result; 136 return result;
220 } 137 }
221 138
222 template<typename CharType>
223 static bool parseValueInternal(const String& string, float& convertedNumber, SVG LengthType& type)
224 {
225 const CharType* ptr = string.getCharacters<CharType>();
226 const CharType* end = ptr + string.length();
227
228 if (!parseNumber(ptr, end, convertedNumber, AllowLeadingWhitespace))
229 return false;
230
231 type = stringToLengthType(ptr, end);
232 ASSERT(ptr <= end);
233 if (type == LengthTypeUnknown)
234 return false;
235
236 return true;
237 }
238
239 void SVGLength::setValueAsString(const String& string, ExceptionState& exception State) 139 void SVGLength::setValueAsString(const String& string, ExceptionState& exception State)
240 { 140 {
241 if (string.isEmpty()) { 141 if (string.isEmpty()) {
242 m_unitType = LengthTypeNumber; 142 m_value = cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::Num ber);
243 m_valueInSpecifiedUnits = 0;
244 return; 143 return;
245 } 144 }
246 145
247 float convertedNumber = 0; 146 CSSParserContext svgParserContext(SVGAttributeMode, 0);
248 SVGLengthType type = LengthTypeUnknown; 147 RefPtrWillBeRawPtr<CSSValue> parsed = CSSParser::parseSingleValue(CSSPropert yX, string, svgParserContext);
249 148 if (!parsed || !parsed->isPrimitiveValue()) {
250 bool success = string.is8Bit() ?
251 parseValueInternal<LChar>(string, convertedNumber, type) :
252 parseValueInternal<UChar>(string, convertedNumber, type);
253
254 if (!success) {
255 exceptionState.throwDOMException(SyntaxError, "The value provided ('" + string + "') is invalid."); 149 exceptionState.throwDOMException(SyntaxError, "The value provided ('" + string + "') is invalid.");
256 return; 150 return;
257 } 151 }
258 152
259 m_unitType = type; 153 ASSERT(parsed->isPrimitiveValue());
260 m_valueInSpecifiedUnits = convertedNumber; 154 m_value = toCSSPrimitiveValue(parsed.get());
261 } 155 }
262 156
263 String SVGLength::valueAsString() const 157 String SVGLength::valueAsString() const
264 { 158 {
265 return String::number(m_valueInSpecifiedUnits) + lengthTypeToString(unitType ()); 159 return m_value->customCSSText();
266 } 160 }
267 161
268 void SVGLength::newValueSpecifiedUnits(SVGLengthType type, float value) 162 void SVGLength::newValueSpecifiedUnits(CSSPrimitiveValue::UnitType type, float v alue)
269 { 163 {
270 setUnitType(type); 164 m_value = CSSPrimitiveValue::create(value, type);
271 m_valueInSpecifiedUnits = value;
272 } 165 }
273 166
274 void SVGLength::convertToSpecifiedUnits(SVGLengthType type, const SVGLengthConte xt& context) 167 void SVGLength::convertToSpecifiedUnits(CSSPrimitiveValue::UnitType type, const SVGLengthContext& context)
275 { 168 {
276 ASSERT(type != LengthTypeUnknown && type <= LengthTypeCHS); 169 ASSERT(type != CSSPrimitiveValue::UnitType::Unknown
170 && (type <= CSSPrimitiveValue::UnitType::Picas
171 || type == CSSPrimitiveValue::UnitType::Chs
172 || type == CSSPrimitiveValue::UnitType::Rems));
277 173
278 float valueInUserUnits = value(context); 174 float valueInUserUnits = value(context);
279 m_unitType = type; 175 m_value = CSSPrimitiveValue::create(
280 setValue(valueInUserUnits, context); 176 context.convertValueFromUserUnits(valueInUserUnits, unitMode(), type),
177 type);
281 } 178 }
282 179
283 SVGLengthMode SVGLength::lengthModeForAnimatedLengthAttribute(const QualifiedNam e& attrName) 180 SVGLengthMode SVGLength::lengthModeForAnimatedLengthAttribute(const QualifiedNam e& attrName)
284 { 181 {
285 typedef HashMap<QualifiedName, SVGLengthMode> LengthModeForLengthAttributeMa p; 182 typedef HashMap<QualifiedName, SVGLengthMode> LengthModeForLengthAttributeMa p;
286 DEFINE_STATIC_LOCAL(LengthModeForLengthAttributeMap, s_lengthModeMap, ()); 183 DEFINE_STATIC_LOCAL(LengthModeForLengthAttributeMap, s_lengthModeMap, ());
287 184
288 if (s_lengthModeMap.isEmpty()) { 185 if (s_lengthModeMap.isEmpty()) {
289 s_lengthModeMap.set(SVGNames::xAttr, SVGLengthMode::Width); 186 s_lengthModeMap.set(SVGNames::xAttr, SVGLengthMode::Width);
290 s_lengthModeMap.set(SVGNames::yAttr, SVGLengthMode::Height); 187 s_lengthModeMap.set(SVGNames::yAttr, SVGLengthMode::Height);
(...skipping 23 matching lines...) Expand all
314 if (s_lengthModeMap.contains(attrName)) 211 if (s_lengthModeMap.contains(attrName))
315 return s_lengthModeMap.get(attrName); 212 return s_lengthModeMap.get(attrName);
316 213
317 return SVGLengthMode::Other; 214 return SVGLengthMode::Other;
318 } 215 }
319 216
320 PassRefPtrWillBeRawPtr<SVGLength> SVGLength::blend(PassRefPtrWillBeRawPtr<SVGLen gth> passFrom, float progress) const 217 PassRefPtrWillBeRawPtr<SVGLength> SVGLength::blend(PassRefPtrWillBeRawPtr<SVGLen gth> passFrom, float progress) const
321 { 218 {
322 RefPtrWillBeRawPtr<SVGLength> from = passFrom; 219 RefPtrWillBeRawPtr<SVGLength> from = passFrom;
323 220
324 SVGLengthType toType = unitType(); 221 CSSPrimitiveValue::UnitType toType = m_value->typeWithCalcResolved();
325 SVGLengthType fromType = from->unitType(); 222 CSSPrimitiveValue::UnitType fromType = from->typeWithCalcResolved();
326 if ((from->isZero() && isZero()) 223 if ((from->isZero() && isZero())
327 || fromType == LengthTypeUnknown 224 || fromType == CSSPrimitiveValue::UnitType::Unknown
328 || toType == LengthTypeUnknown 225 || toType == CSSPrimitiveValue::UnitType::Unknown
329 || (!from->isZero() && fromType != LengthTypePercentage && toType == Len gthTypePercentage) 226 || (!from->isZero() && fromType != CSSPrimitiveValue::UnitType::Percenta ge && toType == CSSPrimitiveValue::UnitType::Percentage)
330 || (!isZero() && fromType == LengthTypePercentage && toType != LengthTyp ePercentage) 227 || (!isZero() && fromType == CSSPrimitiveValue::UnitType::Percentage && toType != CSSPrimitiveValue::UnitType::Percentage)
331 || (!from->isZero() && !isZero() && (fromType == LengthTypeEMS || fromTy pe == LengthTypeEXS || fromType == LengthTypeREMS || fromType == LengthTypeCHS) && fromType != toType)) 228 || (!from->isZero() && !isZero()
229 && (fromType == CSSPrimitiveValue::UnitType::Ems
230 || fromType == CSSPrimitiveValue::UnitType::Exs
231 || fromType == CSSPrimitiveValue::UnitType::Rems
232 || fromType == CSSPrimitiveValue::UnitType::Chs)
233 && fromType != toType))
332 return clone(); 234 return clone();
333 235
334 RefPtrWillBeRawPtr<SVGLength> length = create(); 236 RefPtrWillBeRawPtr<SVGLength> length = create();
335 237
336 if (fromType == LengthTypePercentage || toType == LengthTypePercentage) { 238 if (fromType == CSSPrimitiveValue::UnitType::Percentage || toType == CSSPrim itiveValue::UnitType::Percentage) {
337 float fromPercent = from->valueAsPercentage100(); 239 float fromPercent = from->valueAsPercentage100();
338 float toPercent = valueAsPercentage100(); 240 float toPercent = valueAsPercentage100();
339 length->newValueSpecifiedUnits(LengthTypePercentage, blink::blend(fromPe rcent, toPercent, progress)); 241 length->newValueSpecifiedUnits(CSSPrimitiveValue::UnitType::Percentage, blink::blend(fromPercent, toPercent, progress));
340 return length; 242 return length;
341 } 243 }
342 244
343 if (fromType == toType || from->isZero() || isZero() || fromType == LengthTy peEMS || fromType == LengthTypeEXS || fromType == LengthTypeREMS || fromType == LengthTypeCHS) { 245 if (fromType == toType
246 || from->isZero()
247 || isZero()
248 || fromType == CSSPrimitiveValue::UnitType::Ems
249 || fromType == CSSPrimitiveValue::UnitType::Exs
250 || fromType == CSSPrimitiveValue::UnitType::Rems
251 || fromType == CSSPrimitiveValue::UnitType::Chs) {
344 float fromValue = from->valueInSpecifiedUnits(); 252 float fromValue = from->valueInSpecifiedUnits();
345 float toValue = valueInSpecifiedUnits(); 253 float toValue = valueInSpecifiedUnits();
346 if (isZero()) 254 if (isZero())
347 length->newValueSpecifiedUnits(fromType, blink::blend(fromValue, toV alue, progress)); 255 length->newValueSpecifiedUnits(fromType, blink::blend(fromValue, toV alue, progress));
348 else 256 else
349 length->newValueSpecifiedUnits(toType, blink::blend(fromValue, toVal ue, progress)); 257 length->newValueSpecifiedUnits(toType, blink::blend(fromValue, toVal ue, progress));
350 return length; 258 return length;
351 } 259 }
352 260
353 ASSERT(!isRelative()); 261 ASSERT(!isRelative());
354 ASSERT(!from->isRelative()); 262 ASSERT(!from->isRelative());
355 263
356 SVGLengthContext nonRelativeLengthContext(0); 264 SVGLengthContext nonRelativeLengthContext(0);
357 float fromValueInUserUnits = nonRelativeLengthContext.convertValueToUserUnit s(from->valueInSpecifiedUnits(), from->unitMode(), fromType); 265 float fromValueInUserUnits = nonRelativeLengthContext.convertValueToUserUnit s(from->valueInSpecifiedUnits(), from->unitMode(), fromType);
358 float fromValue = nonRelativeLengthContext.convertValueFromUserUnits(fromVal ueInUserUnits, unitMode(), toType); 266 float fromValue = nonRelativeLengthContext.convertValueFromUserUnits(fromVal ueInUserUnits, unitMode(), toType);
359 267
360 float toValue = valueInSpecifiedUnits(); 268 float toValue = valueInSpecifiedUnits();
361 length->newValueSpecifiedUnits(toType, blink::blend(fromValue, toValue, prog ress)); 269 length->newValueSpecifiedUnits(toType, blink::blend(fromValue, toValue, prog ress));
362 return length; 270 return length;
363 } 271 }
364 272
365 void SVGLength::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElement* c ontextElement) 273 void SVGLength::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElement* c ontextElement)
366 { 274 {
367 SVGLengthContext lengthContext(contextElement); 275 SVGLengthContext lengthContext(contextElement);
368 setValue(value(lengthContext) + toSVGLength(other)->value(lengthContext), le ngthContext); 276 setValue(value(lengthContext) + toSVGLength(other)->value(lengthContext), le ngthContext);
369 } 277 }
370 278
371 void SVGLength::calculateAnimatedValue(SVGAnimationElement* animationElement, fl oat percentage, unsigned repeatCount, PassRefPtrWillBeRawPtr<SVGPropertyBase> fr omValue, PassRefPtrWillBeRawPtr<SVGPropertyBase> toValue, PassRefPtrWillBeRawPtr <SVGPropertyBase> toAtEndOfDurationValue, SVGElement* contextElement) 279 void SVGLength::calculateAnimatedValue(SVGAnimationElement* animationElement,
280 float percentage,
281 unsigned repeatCount,
282 PassRefPtrWillBeRawPtr<SVGPropertyBase> fromValue,
283 PassRefPtrWillBeRawPtr<SVGPropertyBase> toValue,
284 PassRefPtrWillBeRawPtr<SVGPropertyBase> toAtEndOfDurationValue,
285 SVGElement* contextElement)
372 { 286 {
373 RefPtrWillBeRawPtr<SVGLength> fromLength = toSVGLength(fromValue); 287 RefPtrWillBeRawPtr<SVGLength> fromLength = toSVGLength(fromValue);
374 RefPtrWillBeRawPtr<SVGLength> toLength = toSVGLength(toValue); 288 RefPtrWillBeRawPtr<SVGLength> toLength = toSVGLength(toValue);
375 RefPtrWillBeRawPtr<SVGLength> toAtEndOfDurationLength = toSVGLength(toAtEndO fDurationValue); 289 RefPtrWillBeRawPtr<SVGLength> toAtEndOfDurationLength = toSVGLength(toAtEndO fDurationValue);
376 290
377 SVGLengthContext lengthContext(contextElement); 291 SVGLengthContext lengthContext(contextElement);
378 float animatedNumber = value(lengthContext); 292 float animatedNumber = value(lengthContext);
379 animationElement->animateAdditiveNumber(percentage, repeatCount, fromLength- >value(lengthContext), toLength->value(lengthContext), toAtEndOfDurationLength-> value(lengthContext), animatedNumber); 293 animationElement->animateAdditiveNumber(percentage, repeatCount, fromLength- >value(lengthContext),
294 toLength->value(lengthContext), toAtEndOfDurationLength->value(lengthCon text), animatedNumber);
380 295
381 ASSERT(unitMode() == lengthModeForAnimatedLengthAttribute(animationElement-> attributeName())); 296 ASSERT(unitMode() == lengthModeForAnimatedLengthAttribute(animationElement-> attributeName()));
382 m_unitType = percentage < 0.5 ? fromLength->unitType() : toLength->unitType( ); 297
383 setValue(animatedNumber, lengthContext); 298 CSSPrimitiveValue::UnitType newUnit = percentage < 0.5 ? fromLength->typeWit hCalcResolved() : toLength->typeWithCalcResolved();
299 animatedNumber = lengthContext.convertValueFromUserUnits(animatedNumber, uni tMode(), newUnit);
300 m_value = CSSPrimitiveValue::create(animatedNumber, newUnit);
384 } 301 }
385 302
386 float SVGLength::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> toVal ue, SVGElement* contextElement) 303 float SVGLength::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> toVal ue, SVGElement* contextElement)
387 { 304 {
388 SVGLengthContext lengthContext(contextElement); 305 SVGLengthContext lengthContext(contextElement);
389 RefPtrWillBeRawPtr<SVGLength> toLength = toSVGLength(toValue); 306 RefPtrWillBeRawPtr<SVGLength> toLength = toSVGLength(toValue);
390 307
391 return fabsf(toLength->value(lengthContext) - value(lengthContext)); 308 return fabsf(toLength->value(lengthContext) - value(lengthContext));
392 } 309 }
393 310
394 } 311 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698