Changeset 115305 in webkit
- Timestamp:
- Apr 26, 2012 6:14:34 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r115302 r115305 1 2012-04-26 Nikolas Zimmermann <nzimmermann@rim.com> 2 3 Share code used to animate numbers types between all animators 4 https://bugs.webkit.org/show_bug.cgi?id=84945 5 6 Reviewed by Antti Koivisto. 7 8 Refactor animateAdditiveNumber() from SVGAnimatedNumberAnimator into SVGAnimationElement, 9 to reuse it for all primitives. Converted most primitives to use the new code. Lists, paths, 10 colors are still todo. 11 12 Doesn't affect any tests. 13 14 * svg/SVGAnimatedAngle.cpp: 15 (WebCore::SVGAnimatedAngleAnimator::calculateAnimatedValue): 16 * svg/SVGAnimatedInteger.cpp: 17 (WebCore::SVGAnimatedIntegerAnimator::calculateAnimatedInteger): 18 (WebCore::SVGAnimatedIntegerAnimator::calculateAnimatedValue): 19 * svg/SVGAnimatedInteger.h: 20 (SVGAnimatedIntegerAnimator): 21 * svg/SVGAnimatedIntegerOptionalInteger.cpp: 22 (WebCore::SVGAnimatedIntegerOptionalIntegerAnimator::addAnimatedTypes): 23 (WebCore::SVGAnimatedIntegerOptionalIntegerAnimator::calculateAnimatedValue): 24 * svg/SVGAnimatedLength.cpp: 25 (WebCore::SVGAnimatedLengthAnimator::calculateAnimatedValue): 26 * svg/SVGAnimatedLengthList.cpp: 27 (WebCore::SVGAnimatedLengthListAnimator::calculateAnimatedValue): 28 * svg/SVGAnimatedNumber.cpp: 29 (WebCore::SVGAnimatedNumberAnimator::calculateAnimatedValue): 30 * svg/SVGAnimatedNumber.h: 31 * svg/SVGAnimatedNumberList.cpp: 32 (WebCore::SVGAnimatedNumberListAnimator::calculateAnimatedValue): 33 * svg/SVGAnimatedNumberOptionalNumber.cpp: 34 (WebCore::SVGAnimatedNumberOptionalNumberAnimator::addAnimatedTypes): 35 (WebCore::SVGAnimatedNumberOptionalNumberAnimator::calculateAnimatedValue): 36 * svg/SVGAnimatedNumberOptionalNumber.h: 37 * svg/SVGAnimatedRect.cpp: 38 (WebCore::SVGAnimatedRectAnimator::calculateAnimatedValue): 39 * svg/SVGAnimationElement.h: 40 (WebCore::SVGAnimationElement::animateAdditiveNumber): 41 (SVGAnimationElement): 42 1 43 2012-04-26 Ryosuke Niwa <rniwa@webkit.org> 2 44 -
trunk/Source/WebCore/svg/SVGAnimatedAngle.cpp
r115187 r115305 142 142 animatedAngleAndEnumeration.second = SVGMarkerOrientAngle; 143 143 144 // Replace 'inherit' by their computed property values.145 float number;146 147 float fromAngle = fromAngleAndEnumeration.first.value();148 float toAngle = toAngleAndEnumeration.first.value();149 150 if (m_animationElement->calcMode() == CalcModeDiscrete)151 number = percentage < 0.5f ? fromAngle : toAngle;152 else153 number = (toAngle - fromAngle) * percentage + fromAngle;154 155 // FIXME: This is not correct for values animation.156 if (m_animationElement->isAccumulated() && repeatCount)157 number += toAngle * repeatCount;158 144 SVGAngle& animatedSVGAngle = animatedAngleAndEnumeration.first; 159 if (m_animationElement->isAdditive() && m_animationElement->animationMode() != ToAnimation) { 160 float animatedSVGAngleValue = animatedSVGAngle.value(); 161 animatedSVGAngleValue += number; 162 animatedSVGAngle.setValue(animatedSVGAngleValue); 163 } else 164 animatedSVGAngle.setValue(number); 145 float animatedAngle = animatedSVGAngle.value(); 146 m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromAngleAndEnumeration.first.value(), toAngleAndEnumeration.first.value(), animatedAngle); 147 animatedSVGAngle.setValue(animatedAngle); 165 148 } 166 149 -
trunk/Source/WebCore/svg/SVGAnimatedInteger.cpp
r115187 r115305 74 74 } 75 75 76 void SVGAnimatedIntegerAnimator::calculateAnimatedInteger(SVGAnimationElement* animationElement, float percentage, unsigned repeatCount, int & animatedInteger, int fromInteger, int toInteger)76 void SVGAnimatedIntegerAnimator::calculateAnimatedInteger(SVGAnimationElement* animationElement, float percentage, unsigned repeatCount, int fromInteger, int toInteger, int& animatedInteger) 77 77 { 78 78 float animatedNumber = animatedInteger; 79 SVGAnimatedNumberAnimator::calculateAnimatedNumber(animationElement, percentage, repeatCount, animatedNumber, fromInteger, toInteger);79 animationElement->animateAdditiveNumber(percentage, repeatCount, fromInteger, toInteger, animatedNumber); 80 80 animatedInteger = static_cast<int>(roundf(animatedNumber)); 81 81 } … … 91 91 m_animationElement->adjustFromToValues<int>(0, fromInteger, toInteger, animatedInteger, percentage, m_contextElement); 92 92 93 calculateAnimatedInteger(m_animationElement, percentage, repeatCount, animatedInteger, fromInteger, toInteger);93 calculateAnimatedInteger(m_animationElement, percentage, repeatCount, fromInteger, toInteger, animatedInteger); 94 94 } 95 95 -
trunk/Source/WebCore/svg/SVGAnimatedInteger.h
r115178 r115305 46 46 SVGAnimatedIntegerAnimator(SVGAnimationElement*, SVGElement*); 47 47 virtual ~SVGAnimatedIntegerAnimator() { } 48 49 static void calculateAnimatedInteger(SVGAnimationElement*, float percentage, unsigned repeatCount, int & animatedNumber, int fromNumber, int toNumber);48 49 static void calculateAnimatedInteger(SVGAnimationElement*, float percentage, unsigned repeatCount, int fromInteger, int toInteger, int& animatedInteger); 50 50 51 51 virtual PassOwnPtr<SVGAnimatedType> constructFromString(const String&); -
trunk/Source/WebCore/svg/SVGAnimatedIntegerOptionalInteger.cpp
r115187 r115305 80 80 ASSERT(from->type() == to->type()); 81 81 82 pair<int, int>& from NumberPair = from->integerOptionalInteger();83 pair<int, int>& to NumberPair = to->integerOptionalInteger();82 pair<int, int>& fromIntegerPair = from->integerOptionalInteger(); 83 pair<int, int>& toIntegerPair = to->integerOptionalInteger(); 84 84 85 to NumberPair.first += fromNumberPair.first;86 to NumberPair.second += fromNumberPair.second;85 toIntegerPair.first += fromIntegerPair.first; 86 toIntegerPair.second += fromIntegerPair.second; 87 87 } 88 88 … … 97 97 m_animationElement->adjustFromToValues<pair<int, int> >(0, fromIntegerPair, toIntegerPair, animatedIntegerPair, percentage, m_contextElement); 98 98 99 SVGAnimatedIntegerAnimator::calculateAnimatedInteger(m_animationElement, percentage, repeatCount, animatedIntegerPair.first, fromIntegerPair.first, toIntegerPair.first);100 SVGAnimatedIntegerAnimator::calculateAnimatedInteger(m_animationElement, percentage, repeatCount, animatedIntegerPair.second, fromIntegerPair.second, toIntegerPair.second);99 SVGAnimatedIntegerAnimator::calculateAnimatedInteger(m_animationElement, percentage, repeatCount, fromIntegerPair.first, toIntegerPair.first, animatedIntegerPair.first); 100 SVGAnimatedIntegerAnimator::calculateAnimatedInteger(m_animationElement, percentage, repeatCount, fromIntegerPair.second, toIntegerPair.second, animatedIntegerPair.second); 101 101 } 102 102 -
trunk/Source/WebCore/svg/SVGAnimatedLength.cpp
r115187 r115305 103 103 104 104 SVGLengthContext lengthContext(m_contextElement); 105 float result= animatedSVGLength.value(lengthContext);105 float animatedNumber = animatedSVGLength.value(lengthContext); 106 106 SVGLengthType unitType = percentage < 0.5 ? fromSVGLength.unitType() : toSVGLength.unitType(); 107 SVGAnimatedNumberAnimator::calculateAnimatedNumber(m_animationElement, percentage, repeatCount, result, fromSVGLength.value(lengthContext), toSVGLength.value(lengthContext));107 m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromSVGLength.value(lengthContext), toSVGLength.value(lengthContext), animatedNumber); 108 108 109 109 ExceptionCode ec = 0; 110 animatedSVGLength.setValue(lengthContext, result, m_lengthMode, unitType, ec);110 animatedSVGLength.setValue(lengthContext, animatedNumber, m_lengthMode, unitType, ec); 111 111 ASSERT(!ec); 112 112 } -
trunk/Source/WebCore/svg/SVGAnimatedLengthList.cpp
r115187 r115305 109 109 ExceptionCode ec = 0; 110 110 for (unsigned i = 0; i < itemsCount; ++i) { 111 float result= animatedListSizeEqual ? animatedLengthList[i].value(lengthContext) : 0;111 float animatedNumber = animatedListSizeEqual ? animatedLengthList[i].value(lengthContext) : 0; 112 112 SVGLengthType unitType = percentage < 0.5 ? fromLengthList[i].unitType() : toLengthList[i].unitType(); 113 SVGAnimatedNumberAnimator::calculateAnimatedNumber(m_animationElement, percentage, repeatCount, result, fromLengthList[i].value(lengthContext), toLengthList[i].value(lengthContext)); 113 m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromLengthList[i].value(lengthContext), toLengthList[i].value(lengthContext), animatedNumber); 114 114 115 if (!animatedListSizeEqual) 115 animatedLengthList.append(SVGLength(lengthContext, result, m_lengthMode, unitType));116 animatedLengthList.append(SVGLength(lengthContext, animatedNumber, m_lengthMode, unitType)); 116 117 else { 117 animatedLengthList[i].setValue(lengthContext, result, m_lengthMode, unitType, ec);118 animatedLengthList[i].setValue(lengthContext, animatedNumber, m_lengthMode, unitType, ec); 118 119 ASSERT(!ec); 119 120 } -
trunk/Source/WebCore/svg/SVGAnimatedNumber.cpp
r115187 r115305 77 77 } 78 78 79 void SVGAnimatedNumberAnimator::calculateAnimatedNumber(SVGAnimationElement* animationElement, float percentage, unsigned repeatCount, float& animatedNumber, float fromNumber, float toNumber)80 {81 float number;82 if (animationElement->calcMode() == CalcModeDiscrete)83 number = percentage < 0.5 ? fromNumber : toNumber;84 else85 number = (toNumber - fromNumber) * percentage + fromNumber;86 87 // FIXME: This is not correct for values animation. Right now we transform values-animation to multiple from-to-animations and88 // accumulate every single value to the previous one. But accumulation should just take into account after a complete cycle89 // of values-animaiton. See example at: http://www.w3.org/TR/2001/REC-smil-animation-20010904/#RepeatingAnim90 if (animationElement->isAccumulated() && repeatCount)91 number += toNumber * repeatCount;92 if (animationElement->isAdditive() && animationElement->animationMode() != ToAnimation)93 animatedNumber += number;94 else95 animatedNumber = number;96 }97 98 79 static float parseNumberFromString(SVGAnimationElement*, const String& string) 99 80 { … … 113 94 m_animationElement->adjustFromToValues<float>(parseNumberFromString, fromNumber, toNumber, animatedNumber, percentage, m_contextElement); 114 95 115 calculateAnimatedNumber(m_animationElement, percentage, repeatCount, animatedNumber, fromNumber, toNumber);96 m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromNumber, toNumber, animatedNumber); 116 97 } 117 98 -
trunk/Source/WebCore/svg/SVGAnimatedNumber.h
r115178 r115305 47 47 virtual ~SVGAnimatedNumberAnimator() { } 48 48 49 static void calculateAnimatedNumber(SVGAnimationElement*, float percentage, unsigned repeatCount, float& animatedNumber, float fromNumber, float toNumber);50 51 49 virtual PassOwnPtr<SVGAnimatedType> constructFromString(const String&); 52 50 virtual PassOwnPtr<SVGAnimatedType> startAnimValAnimation(const Vector<SVGAnimatedProperty*>&); -
trunk/Source/WebCore/svg/SVGAnimatedNumberList.cpp
r115187 r115305 97 97 98 98 for (unsigned i = 0; i < itemsCount; ++i) 99 SVGAnimatedNumberAnimator::calculateAnimatedNumber(m_animationElement, percentage, repeatCount, animatedNumberList[i], fromNumberList[i], toNumberList[i]);99 m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromNumberList[i], toNumberList[i], animatedNumberList[i]); 100 100 } 101 101 -
trunk/Source/WebCore/svg/SVGAnimatedNumberOptionalNumber.cpp
r115187 r115305 79 79 pair<float, float>& fromNumberPair = from->numberOptionalNumber(); 80 80 pair<float, float>& toNumberPair = to->numberOptionalNumber(); 81 81 82 82 toNumberPair.first += fromNumberPair.first; 83 83 toNumberPair.second += fromNumberPair.second; … … 94 94 m_animationElement->adjustFromToValues<pair<float, float> >(0, fromNumberPair, toNumberPair, animatedNumberPair, percentage, m_contextElement); 95 95 96 SVGAnimatedNumberAnimator::calculateAnimatedNumber(m_animationElement, percentage, repeatCount, animatedNumberPair.first, fromNumberPair.first, toNumberPair.first);97 SVGAnimatedNumberAnimator::calculateAnimatedNumber(m_animationElement, percentage, repeatCount, animatedNumberPair.second, fromNumberPair.second, toNumberPair.second);96 m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromNumberPair.first, toNumberPair.first, animatedNumberPair.first); 97 m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromNumberPair.second, toNumberPair.second, animatedNumberPair.second); 98 98 } 99 99 -
trunk/Source/WebCore/svg/SVGAnimatedNumberOptionalNumber.h
r115178 r115305 33 33 virtual ~SVGAnimatedNumberOptionalNumberAnimator() { } 34 34 35 static void calculateAnimatedNumberOptionalNumber(SVGAnimationElement*, float percentage, unsigned repeatCount, float& animatedNumber, float fromNumber, float toNumber);36 37 35 virtual PassOwnPtr<SVGAnimatedType> constructFromString(const String&); 38 36 virtual PassOwnPtr<SVGAnimatedType> startAnimValAnimation(const Vector<SVGAnimatedProperty*>&); -
trunk/Source/WebCore/svg/SVGAnimatedRect.cpp
r115187 r115305 83 83 m_animationElement->adjustFromToValues<FloatRect>(0, fromRect, toRect, animatedRect, percentage, m_contextElement); 84 84 85 FloatRect newRect;86 if (m_animationElement->calcMode() == CalcModeDiscrete)87 newRect = percentage < 0.5 ? fromRect : toRect;88 else89 newRect = FloatRect((toRect.x() - fromRect.x()) * percentage + fromRect.x(),90 (toRect.y() - fromRect.y()) * percentage + fromRect.y(),91 (toRect.width() - fromRect.width()) * percentage + fromRect.width(),92 (toRect.height() - fromRect.height()) * percentage + fromRect.height());85 float animatedX = animatedRect.x(); 86 float animatedY = animatedRect.y(); 87 float animatedWidth = animatedRect.width(); 88 float animatedHeight = animatedRect.height(); 89 m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromRect.x(), toRect.x(), animatedX); 90 m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromRect.y(), toRect.y(), animatedY); 91 m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromRect.width(), toRect.width(), animatedWidth); 92 m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromRect.height(), toRect.height(), animatedHeight); 93 93 94 // FIXME: This is not correct for values animation. Right now we transform values-animation to multiple from-to-animations and 95 // accumulate every single value to the previous one. But accumulation should just take into account after a complete cycle 96 // of values-animaiton. See example at: http://www.w3.org/TR/2001/REC-smil-animation-20010904/#RepeatingAnim 97 if (m_animationElement->isAccumulated() && repeatCount) { 98 newRect += toRect; 99 newRect.scale(repeatCount); 100 } 101 102 if (m_animationElement->isAdditive() && m_animationElement->animationMode() != ToAnimation) 103 animatedRect += newRect; 104 else 105 animatedRect = newRect; 94 animatedRect = FloatRect(animatedX, animatedY, animatedWidth, animatedHeight); 106 95 } 107 96 -
trunk/Source/WebCore/svg/SVGAnimationElement.h
r115296 r115305 166 166 } 167 167 168 void animateAdditiveNumber(float percentage, unsigned repeatCount, float fromNumber, float toNumber, float& animatedNumber) 169 { 170 float number; 171 if (calcMode() == CalcModeDiscrete) 172 number = percentage < 0.5 ? fromNumber : toNumber; 173 else 174 number = (toNumber - fromNumber) * percentage + fromNumber; 175 176 // FIXME: This is not correct for values animation. Right now we transform values-animation to multiple from-to-animations and 177 // accumulate every single value to the previous one. But accumulation should just take into account after a complete cycle 178 // of values-animaiton. See example at: http://www.w3.org/TR/2001/REC-smil-animation-20010904/#RepeatingAnim 179 if (isAccumulated() && repeatCount) 180 number += toNumber * repeatCount; 181 182 if (isAdditive() && animationMode() != ToAnimation) 183 animatedNumber += number; 184 else 185 animatedNumber = number; 186 } 187 168 188 protected: 169 189 SVGAnimationElement(const QualifiedName&, Document*);
Note: See TracChangeset
for help on using the changeset viewer.