| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005 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 Eric Seidel <eric@webkit.org> | 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> |
| 5 * Copyright (C) 2008 Apple Inc. All rights reserved. | 5 * Copyright (C) 2008 Apple Inc. All rights reserved. |
| 6 * Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> | 6 * Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> |
| 7 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 7 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 // Use key times calculated based on pacing instead of the user provided one
s. | 408 // Use key times calculated based on pacing instead of the user provided one
s. |
| 409 m_keyTimes = keyTimesForPaced; | 409 m_keyTimes = keyTimesForPaced; |
| 410 } | 410 } |
| 411 | 411 |
| 412 static inline double solveEpsilon(double duration) { return 1 / (200 * duration)
; } | 412 static inline double solveEpsilon(double duration) { return 1 / (200 * duration)
; } |
| 413 | 413 |
| 414 unsigned SVGAnimationElement::calculateKeyTimesIndex(float percent) const | 414 unsigned SVGAnimationElement::calculateKeyTimesIndex(float percent) const |
| 415 { | 415 { |
| 416 unsigned index; | 416 unsigned index; |
| 417 unsigned keyTimesCount = m_keyTimes.size(); | 417 unsigned keyTimesCount = m_keyTimes.size(); |
| 418 // Compare index + 1 to keyTimesCount because the last keyTimes entry is | 418 // For linear and spline animations, the last value must be '1'. In those |
| 419 // required to be 1, and percent can never exceed 1; i.e., the second last | 419 // cases we don't need to consider the last value, since |percent| is never |
| 420 // keyTimes entry defines the beginning of the final interval | 420 // greater than one. |
| 421 for (index = 1; index + 1 < keyTimesCount; ++index) { | 421 if (keyTimesCount && calcMode() != CalcModeDiscrete) |
| 422 keyTimesCount--; |
| 423 for (index = 1; index < keyTimesCount; ++index) { |
| 422 if (m_keyTimes[index] > percent) | 424 if (m_keyTimes[index] > percent) |
| 423 break; | 425 break; |
| 424 } | 426 } |
| 425 return --index; | 427 return --index; |
| 426 } | 428 } |
| 427 | 429 |
| 428 float SVGAnimationElement::calculatePercentForSpline(float percent, unsigned spl
ineIndex) const | 430 float SVGAnimationElement::calculatePercentForSpline(float percent, unsigned spl
ineIndex) const |
| 429 { | 431 { |
| 430 ASSERT(calcMode() == CalcModeSpline); | 432 ASSERT(calcMode() == CalcModeSpline); |
| 431 ASSERT_WITH_SECURITY_IMPLICATION(splineIndex < m_keySplines.size()); | 433 ASSERT_WITH_SECURITY_IMPLICATION(splineIndex < m_keySplines.size()); |
| 432 UnitBezier bezier = m_keySplines[splineIndex]; | 434 UnitBezier bezier = m_keySplines[splineIndex]; |
| 433 SMILTime duration = simpleDuration(); | 435 SMILTime duration = simpleDuration(); |
| 434 if (!duration.isFinite()) | 436 if (!duration.isFinite()) |
| 435 duration = 100.0; | 437 duration = 100.0; |
| 436 return narrowPrecisionToFloat(bezier.solve(percent, solveEpsilon(duration.va
lue()))); | 438 return narrowPrecisionToFloat(bezier.solve(percent, solveEpsilon(duration.va
lue()))); |
| 437 } | 439 } |
| 438 | 440 |
| 439 float SVGAnimationElement::calculatePercentFromKeyPoints(float percent) const | 441 float SVGAnimationElement::calculatePercentFromKeyPoints(float percent) const |
| 440 { | 442 { |
| 441 ASSERT(!m_keyPoints.isEmpty()); | 443 ASSERT(!m_keyPoints.isEmpty()); |
| 442 ASSERT(calcMode() != CalcModePaced); | 444 ASSERT(calcMode() != CalcModePaced); |
| 443 ASSERT(m_keyTimes.size() > 1); | 445 ASSERT(m_keyTimes.size() > 1); |
| 444 ASSERT(m_keyPoints.size() == m_keyTimes.size()); | 446 ASSERT(m_keyPoints.size() == m_keyTimes.size()); |
| 445 | 447 |
| 446 if (percent == 1) | 448 if (percent == 1) |
| 447 return m_keyPoints[m_keyPoints.size() - 1]; | 449 return m_keyPoints[m_keyPoints.size() - 1]; |
| 448 | 450 |
| 449 unsigned index = calculateKeyTimesIndex(percent); | 451 unsigned index = calculateKeyTimesIndex(percent); |
| 450 float fromPercent = m_keyTimes[index]; | |
| 451 float toPercent = m_keyTimes[index + 1]; | |
| 452 float fromKeyPoint = m_keyPoints[index]; | 452 float fromKeyPoint = m_keyPoints[index]; |
| 453 float toKeyPoint = m_keyPoints[index + 1]; | |
| 454 | 453 |
| 455 if (calcMode() == CalcModeDiscrete) | 454 if (calcMode() == CalcModeDiscrete) |
| 456 return fromKeyPoint; | 455 return fromKeyPoint; |
| 457 | 456 |
| 457 ASSERT(index + 1 < m_keyTimes.size()); |
| 458 float fromPercent = m_keyTimes[index]; |
| 459 float toPercent = m_keyTimes[index + 1]; |
| 460 float toKeyPoint = m_keyPoints[index + 1]; |
| 458 float keyPointPercent = (percent - fromPercent) / (toPercent - fromPercent); | 461 float keyPointPercent = (percent - fromPercent) / (toPercent - fromPercent); |
| 459 | 462 |
| 460 if (calcMode() == CalcModeSpline) { | 463 if (calcMode() == CalcModeSpline) { |
| 461 ASSERT(m_keySplines.size() == m_keyPoints.size() - 1); | 464 ASSERT(m_keySplines.size() == m_keyPoints.size() - 1); |
| 462 keyPointPercent = calculatePercentForSpline(keyPointPercent, index); | 465 keyPointPercent = calculatePercentForSpline(keyPointPercent, index); |
| 463 } | 466 } |
| 464 return (toKeyPoint - fromKeyPoint) * keyPointPercent + fromKeyPoint; | 467 return (toKeyPoint - fromKeyPoint) * keyPointPercent + fromKeyPoint; |
| 465 } | 468 } |
| 466 | 469 |
| 467 float SVGAnimationElement::calculatePercentForFromTo(float percent) const | 470 float SVGAnimationElement::calculatePercentForFromTo(float percent) const |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 SVGSMILElement::setAttributeName(attributeName); | 709 SVGSMILElement::setAttributeName(attributeName); |
| 707 checkInvalidCSSAttributeType(targetElement()); | 710 checkInvalidCSSAttributeType(targetElement()); |
| 708 } | 711 } |
| 709 | 712 |
| 710 void SVGAnimationElement::checkInvalidCSSAttributeType(SVGElement* target) | 713 void SVGAnimationElement::checkInvalidCSSAttributeType(SVGElement* target) |
| 711 { | 714 { |
| 712 m_hasInvalidCSSAttributeType = target && hasValidAttributeName() && attribut
eType() == AttributeTypeCSS && !isTargetAttributeCSSProperty(target, attributeNa
me()); | 715 m_hasInvalidCSSAttributeType = target && hasValidAttributeName() && attribut
eType() == AttributeTypeCSS && !isTargetAttributeCSSProperty(target, attributeNa
me()); |
| 713 } | 716 } |
| 714 | 717 |
| 715 } | 718 } |
| OLD | NEW |