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

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

Issue 901193002: De-ExceptionState-ify SVGLengthContext (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase. Created 5 years, 10 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/SVGLength.h ('k') | Source/core/svg/SVGLengthContext.h » ('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 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 *
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 return length.release(); 152 return length.release();
153 } 153 }
154 154
155 bool SVGLength::operator==(const SVGLength& other) const 155 bool SVGLength::operator==(const SVGLength& other) const
156 { 156 {
157 return m_unitMode == other.m_unitMode 157 return m_unitMode == other.m_unitMode
158 && m_unitType == other.m_unitType 158 && m_unitType == other.m_unitType
159 && m_valueInSpecifiedUnits == other.m_valueInSpecifiedUnits; 159 && m_valueInSpecifiedUnits == other.m_valueInSpecifiedUnits;
160 } 160 }
161 161
162 float SVGLength::value(const SVGLengthContext& context, ExceptionState& es) cons t 162 float SVGLength::value(const SVGLengthContext& context) const
163 { 163 {
164 return context.convertValueToUserUnits(m_valueInSpecifiedUnits, unitMode(), unitType(), es); 164 return context.convertValueToUserUnits(m_valueInSpecifiedUnits, unitMode(), unitType());
165 } 165 }
166 166
167 void SVGLength::setValue(float value, const SVGLengthContext& context, Exception State& es) 167 void SVGLength::setValue(float value, const SVGLengthContext& context)
168 { 168 {
169 // LengthTypePercentage is represented with 100% = 100.0. Good for accuracy but could eventually be changed. 169 // LengthTypePercentage is represented with 100% = 100.0. Good for accuracy but could eventually be changed.
170 if (m_unitType == LengthTypePercentage) 170 if (m_unitType == LengthTypePercentage)
171 value = value / 100; 171 value = value / 100;
172 172
173 float convertedValue = context.convertValueFromUserUnits(value, unitMode(), unitType(), es); 173 m_valueInSpecifiedUnits = context.convertValueFromUserUnits(value, unitMode( ), unitType());
174 if (es.hadException())
175 return;
176
177 m_valueInSpecifiedUnits = convertedValue;
178 } 174 }
179 175
180 void SVGLength::setUnitType(SVGLengthType type) 176 void SVGLength::setUnitType(SVGLengthType type)
181 { 177 {
182 ASSERT(type != LengthTypeUnknown && type <= LengthTypePC); 178 ASSERT(type != LengthTypeUnknown && type <= LengthTypePC);
183 m_unitType = type; 179 m_unitType = type;
184 } 180 }
185 181
186 float SVGLength::valueAsPercentage() const 182 float SVGLength::valueAsPercentage() const
187 { 183 {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 { 254 {
259 return String::number(m_valueInSpecifiedUnits) + lengthTypeToString(unitType ()); 255 return String::number(m_valueInSpecifiedUnits) + lengthTypeToString(unitType ());
260 } 256 }
261 257
262 void SVGLength::newValueSpecifiedUnits(SVGLengthType type, float value) 258 void SVGLength::newValueSpecifiedUnits(SVGLengthType type, float value)
263 { 259 {
264 setUnitType(type); 260 setUnitType(type);
265 m_valueInSpecifiedUnits = value; 261 m_valueInSpecifiedUnits = value;
266 } 262 }
267 263
268 void SVGLength::convertToSpecifiedUnits(SVGLengthType type, const SVGLengthConte xt& context, ExceptionState& exceptionState) 264 void SVGLength::convertToSpecifiedUnits(SVGLengthType type, const SVGLengthConte xt& context)
269 { 265 {
270 ASSERT(type != LengthTypeUnknown && type <= LengthTypePC); 266 ASSERT(type != LengthTypeUnknown && type <= LengthTypePC);
271 267
272 float valueInUserUnits = value(context, exceptionState); 268 float valueInUserUnits = value(context);
273 if (exceptionState.hadException())
274 return;
275
276 SVGLengthType originalType = unitType();
277 m_unitType = type; 269 m_unitType = type;
278 setValue(valueInUserUnits, context, exceptionState); 270 setValue(valueInUserUnits, context);
279 if (!exceptionState.hadException())
280 return;
281
282 // Eventually restore old unit and type
283 m_unitType = originalType;
284 } 271 }
285 272
286 PassRefPtrWillBeRawPtr<SVGLength> SVGLength::fromCSSPrimitiveValue(CSSPrimitiveV alue* value) 273 PassRefPtrWillBeRawPtr<SVGLength> SVGLength::fromCSSPrimitiveValue(CSSPrimitiveV alue* value)
287 { 274 {
288 ASSERT(value); 275 ASSERT(value);
289 276
290 SVGLengthType svgType; 277 SVGLengthType svgType;
291 switch (value->primitiveType()) { 278 switch (value->primitiveType()) {
292 case CSSPrimitiveValue::CSS_NUMBER: 279 case CSSPrimitiveValue::CSS_NUMBER:
293 svgType = LengthTypeNumber; 280 svgType = LengthTypeNumber;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 if (isZero()) 423 if (isZero())
437 length->newValueSpecifiedUnits(fromType, blink::blend(fromValue, toV alue, progress)); 424 length->newValueSpecifiedUnits(fromType, blink::blend(fromValue, toV alue, progress));
438 else 425 else
439 length->newValueSpecifiedUnits(toType, blink::blend(fromValue, toVal ue, progress)); 426 length->newValueSpecifiedUnits(toType, blink::blend(fromValue, toVal ue, progress));
440 return length; 427 return length;
441 } 428 }
442 429
443 ASSERT(!isRelative()); 430 ASSERT(!isRelative());
444 ASSERT(!from->isRelative()); 431 ASSERT(!from->isRelative());
445 432
446 TrackExceptionState es;
447 SVGLengthContext nonRelativeLengthContext(0); 433 SVGLengthContext nonRelativeLengthContext(0);
448 float fromValueInUserUnits = nonRelativeLengthContext.convertValueToUserUnit s(from->valueInSpecifiedUnits(), from->unitMode(), fromType, es); 434 float fromValueInUserUnits = nonRelativeLengthContext.convertValueToUserUnit s(from->valueInSpecifiedUnits(), from->unitMode(), fromType);
449 if (es.hadException()) 435 float fromValue = nonRelativeLengthContext.convertValueFromUserUnits(fromVal ueInUserUnits, unitMode(), toType);
450 return create();
451
452 float fromValue = nonRelativeLengthContext.convertValueFromUserUnits(fromVal ueInUserUnits, unitMode(), toType, es);
453 if (es.hadException())
454 return create();
455 436
456 float toValue = valueInSpecifiedUnits(); 437 float toValue = valueInSpecifiedUnits();
457 length->newValueSpecifiedUnits(toType, blink::blend(fromValue, toValue, prog ress)); 438 length->newValueSpecifiedUnits(toType, blink::blend(fromValue, toValue, prog ress));
458 return length; 439 return length;
459 } 440 }
460 441
461 void SVGLength::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElement* c ontextElement) 442 void SVGLength::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElement* c ontextElement)
462 { 443 {
463 SVGLengthContext lengthContext(contextElement); 444 SVGLengthContext lengthContext(contextElement);
464 445 setValue(value(lengthContext) + toSVGLength(other)->value(lengthContext), le ngthContext);
465 setValue(value(lengthContext) + toSVGLength(other)->value(lengthContext), le ngthContext, ASSERT_NO_EXCEPTION);
466 } 446 }
467 447
468 void SVGLength::calculateAnimatedValue(SVGAnimationElement* animationElement, fl oat percentage, unsigned repeatCount, PassRefPtrWillBeRawPtr<SVGPropertyBase> fr omValue, PassRefPtrWillBeRawPtr<SVGPropertyBase> toValue, PassRefPtrWillBeRawPtr <SVGPropertyBase> toAtEndOfDurationValue, SVGElement* contextElement) 448 void SVGLength::calculateAnimatedValue(SVGAnimationElement* animationElement, fl oat percentage, unsigned repeatCount, PassRefPtrWillBeRawPtr<SVGPropertyBase> fr omValue, PassRefPtrWillBeRawPtr<SVGPropertyBase> toValue, PassRefPtrWillBeRawPtr <SVGPropertyBase> toAtEndOfDurationValue, SVGElement* contextElement)
469 { 449 {
470 RefPtrWillBeRawPtr<SVGLength> fromLength = toSVGLength(fromValue); 450 RefPtrWillBeRawPtr<SVGLength> fromLength = toSVGLength(fromValue);
471 RefPtrWillBeRawPtr<SVGLength> toLength = toSVGLength(toValue); 451 RefPtrWillBeRawPtr<SVGLength> toLength = toSVGLength(toValue);
472 RefPtrWillBeRawPtr<SVGLength> toAtEndOfDurationLength = toSVGLength(toAtEndO fDurationValue); 452 RefPtrWillBeRawPtr<SVGLength> toAtEndOfDurationLength = toSVGLength(toAtEndO fDurationValue);
473 453
474 SVGLengthContext lengthContext(contextElement); 454 SVGLengthContext lengthContext(contextElement);
475 float animatedNumber = value(lengthContext, IGNORE_EXCEPTION); 455 float animatedNumber = value(lengthContext);
476 animationElement->animateAdditiveNumber(percentage, repeatCount, fromLength- >value(lengthContext, IGNORE_EXCEPTION), toLength->value(lengthContext, IGNORE_E XCEPTION), toAtEndOfDurationLength->value(lengthContext, IGNORE_EXCEPTION), anim atedNumber); 456 animationElement->animateAdditiveNumber(percentage, repeatCount, fromLength- >value(lengthContext), toLength->value(lengthContext), toAtEndOfDurationLength-> value(lengthContext), animatedNumber);
477 457
478 ASSERT(unitMode() == lengthModeForAnimatedLengthAttribute(animationElement-> attributeName())); 458 ASSERT(unitMode() == lengthModeForAnimatedLengthAttribute(animationElement-> attributeName()));
479 m_unitType = percentage < 0.5 ? fromLength->unitType() : toLength->unitType( ); 459 m_unitType = percentage < 0.5 ? fromLength->unitType() : toLength->unitType( );
480 setValue(animatedNumber, lengthContext, ASSERT_NO_EXCEPTION); 460 setValue(animatedNumber, lengthContext);
481 } 461 }
482 462
483 float SVGLength::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> toVal ue, SVGElement* contextElement) 463 float SVGLength::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> toVal ue, SVGElement* contextElement)
484 { 464 {
485 SVGLengthContext lengthContext(contextElement); 465 SVGLengthContext lengthContext(contextElement);
486 RefPtrWillBeRawPtr<SVGLength> toLength = toSVGLength(toValue); 466 RefPtrWillBeRawPtr<SVGLength> toLength = toSVGLength(toValue);
487 467
488 return fabsf(toLength->value(lengthContext, IGNORE_EXCEPTION) - value(length Context, IGNORE_EXCEPTION)); 468 return fabsf(toLength->value(lengthContext) - value(lengthContext));
489 } 469 }
490 470
491 } 471 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGLength.h ('k') | Source/core/svg/SVGLengthContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698