Changeset 115305 in webkit


Ignore:
Timestamp:
Apr 26, 2012 6:14:34 AM (12 years ago)
Author:
Nikolas Zimmermann
Message:

Share code used to animate numbers types between all animators
https://bugs.webkit.org/show_bug.cgi?id=84945

Reviewed by Antti Koivisto.

Refactor animateAdditiveNumber() from SVGAnimatedNumberAnimator into SVGAnimationElement,
to reuse it for all primitives. Converted most primitives to use the new code. Lists, paths,
colors are still todo.

Doesn't affect any tests.

  • svg/SVGAnimatedAngle.cpp:

(WebCore::SVGAnimatedAngleAnimator::calculateAnimatedValue):

  • svg/SVGAnimatedInteger.cpp:

(WebCore::SVGAnimatedIntegerAnimator::calculateAnimatedInteger):
(WebCore::SVGAnimatedIntegerAnimator::calculateAnimatedValue):

  • svg/SVGAnimatedInteger.h:

(SVGAnimatedIntegerAnimator):

  • svg/SVGAnimatedIntegerOptionalInteger.cpp:

(WebCore::SVGAnimatedIntegerOptionalIntegerAnimator::addAnimatedTypes):
(WebCore::SVGAnimatedIntegerOptionalIntegerAnimator::calculateAnimatedValue):

  • svg/SVGAnimatedLength.cpp:

(WebCore::SVGAnimatedLengthAnimator::calculateAnimatedValue):

  • svg/SVGAnimatedLengthList.cpp:

(WebCore::SVGAnimatedLengthListAnimator::calculateAnimatedValue):

  • svg/SVGAnimatedNumber.cpp:

(WebCore::SVGAnimatedNumberAnimator::calculateAnimatedValue):

  • svg/SVGAnimatedNumber.h:
  • svg/SVGAnimatedNumberList.cpp:

(WebCore::SVGAnimatedNumberListAnimator::calculateAnimatedValue):

  • svg/SVGAnimatedNumberOptionalNumber.cpp:

(WebCore::SVGAnimatedNumberOptionalNumberAnimator::addAnimatedTypes):
(WebCore::SVGAnimatedNumberOptionalNumberAnimator::calculateAnimatedValue):

  • svg/SVGAnimatedNumberOptionalNumber.h:
  • svg/SVGAnimatedRect.cpp:

(WebCore::SVGAnimatedRectAnimator::calculateAnimatedValue):

  • svg/SVGAnimationElement.h:

(WebCore::SVGAnimationElement::animateAdditiveNumber):
(SVGAnimationElement):

Location:
trunk/Source/WebCore
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r115302 r115305  
     12012-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
    1432012-04-26  Ryosuke Niwa  <rniwa@webkit.org>
    244
  • trunk/Source/WebCore/svg/SVGAnimatedAngle.cpp

    r115187 r115305  
    142142    animatedAngleAndEnumeration.second = SVGMarkerOrientAngle;
    143143
    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     else
    153         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;
    158144    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);
    165148}
    166149
  • trunk/Source/WebCore/svg/SVGAnimatedInteger.cpp

    r115187 r115305  
    7474}
    7575
    76 void SVGAnimatedIntegerAnimator::calculateAnimatedInteger(SVGAnimationElement* animationElement, float percentage, unsigned repeatCount, int& animatedInteger, int fromInteger, int toInteger)
     76void SVGAnimatedIntegerAnimator::calculateAnimatedInteger(SVGAnimationElement* animationElement, float percentage, unsigned repeatCount, int fromInteger, int toInteger, int& animatedInteger)
    7777{
    7878    float animatedNumber = animatedInteger;
    79     SVGAnimatedNumberAnimator::calculateAnimatedNumber(animationElement, percentage, repeatCount, animatedNumber, fromInteger, toInteger);
     79    animationElement->animateAdditiveNumber(percentage, repeatCount, fromInteger, toInteger, animatedNumber);
    8080    animatedInteger = static_cast<int>(roundf(animatedNumber));
    8181}
     
    9191    m_animationElement->adjustFromToValues<int>(0, fromInteger, toInteger, animatedInteger, percentage, m_contextElement);
    9292
    93     calculateAnimatedInteger(m_animationElement, percentage, repeatCount, animatedInteger, fromInteger, toInteger);
     93    calculateAnimatedInteger(m_animationElement, percentage, repeatCount, fromInteger, toInteger, animatedInteger);
    9494}
    9595
  • trunk/Source/WebCore/svg/SVGAnimatedInteger.h

    r115178 r115305  
    4646    SVGAnimatedIntegerAnimator(SVGAnimationElement*, SVGElement*);
    4747    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);
    5050
    5151    virtual PassOwnPtr<SVGAnimatedType> constructFromString(const String&);
  • trunk/Source/WebCore/svg/SVGAnimatedIntegerOptionalInteger.cpp

    r115187 r115305  
    8080    ASSERT(from->type() == to->type());
    8181
    82     pair<int, int>& fromNumberPair = from->integerOptionalInteger();
    83     pair<int, int>& toNumberPair = to->integerOptionalInteger();
     82    pair<int, int>& fromIntegerPair = from->integerOptionalInteger();
     83    pair<int, int>& toIntegerPair = to->integerOptionalInteger();
    8484
    85     toNumberPair.first += fromNumberPair.first;
    86     toNumberPair.second += fromNumberPair.second;
     85    toIntegerPair.first += fromIntegerPair.first;
     86    toIntegerPair.second += fromIntegerPair.second;
    8787}
    8888
     
    9797    m_animationElement->adjustFromToValues<pair<int, int> >(0, fromIntegerPair, toIntegerPair, animatedIntegerPair, percentage, m_contextElement);
    9898
    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);
    101101}
    102102
  • trunk/Source/WebCore/svg/SVGAnimatedLength.cpp

    r115187 r115305  
    103103
    104104    SVGLengthContext lengthContext(m_contextElement);
    105     float result = animatedSVGLength.value(lengthContext);
     105    float animatedNumber = animatedSVGLength.value(lengthContext);
    106106    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);
    108108
    109109    ExceptionCode ec = 0;
    110     animatedSVGLength.setValue(lengthContext, result, m_lengthMode, unitType, ec);
     110    animatedSVGLength.setValue(lengthContext, animatedNumber, m_lengthMode, unitType, ec);
    111111    ASSERT(!ec);
    112112}
  • trunk/Source/WebCore/svg/SVGAnimatedLengthList.cpp

    r115187 r115305  
    109109    ExceptionCode ec = 0;
    110110    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;
    112112        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
    114115        if (!animatedListSizeEqual)
    115             animatedLengthList.append(SVGLength(lengthContext, result, m_lengthMode, unitType));
     116            animatedLengthList.append(SVGLength(lengthContext, animatedNumber, m_lengthMode, unitType));
    116117        else {
    117             animatedLengthList[i].setValue(lengthContext, result, m_lengthMode, unitType, ec);
     118            animatedLengthList[i].setValue(lengthContext, animatedNumber, m_lengthMode, unitType, ec);
    118119            ASSERT(!ec);
    119120        }
  • trunk/Source/WebCore/svg/SVGAnimatedNumber.cpp

    r115187 r115305  
    7777}
    7878
    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     else
    85         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 and
    88     // accumulate every single value to the previous one. But accumulation should just take into account after a complete cycle
    89     // of values-animaiton. See example at: http://www.w3.org/TR/2001/REC-smil-animation-20010904/#RepeatingAnim
    90     if (animationElement->isAccumulated() && repeatCount)
    91         number += toNumber * repeatCount;
    92     if (animationElement->isAdditive() && animationElement->animationMode() != ToAnimation)
    93         animatedNumber += number;
    94     else
    95         animatedNumber = number;
    96 }
    97 
    9879static float parseNumberFromString(SVGAnimationElement*, const String& string)
    9980{
     
    11394    m_animationElement->adjustFromToValues<float>(parseNumberFromString, fromNumber, toNumber, animatedNumber, percentage, m_contextElement);
    11495
    115     calculateAnimatedNumber(m_animationElement, percentage, repeatCount, animatedNumber, fromNumber, toNumber);
     96    m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromNumber, toNumber, animatedNumber);
    11697}
    11798
  • trunk/Source/WebCore/svg/SVGAnimatedNumber.h

    r115178 r115305  
    4747    virtual ~SVGAnimatedNumberAnimator() { }
    4848
    49     static void calculateAnimatedNumber(SVGAnimationElement*, float percentage, unsigned repeatCount, float& animatedNumber, float fromNumber, float toNumber);
    50 
    5149    virtual PassOwnPtr<SVGAnimatedType> constructFromString(const String&);
    5250    virtual PassOwnPtr<SVGAnimatedType> startAnimValAnimation(const Vector<SVGAnimatedProperty*>&);
  • trunk/Source/WebCore/svg/SVGAnimatedNumberList.cpp

    r115187 r115305  
    9797
    9898    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]);
    100100}
    101101
  • trunk/Source/WebCore/svg/SVGAnimatedNumberOptionalNumber.cpp

    r115187 r115305  
    7979    pair<float, float>& fromNumberPair = from->numberOptionalNumber();
    8080    pair<float, float>& toNumberPair = to->numberOptionalNumber();
    81    
     81
    8282    toNumberPair.first += fromNumberPair.first;
    8383    toNumberPair.second += fromNumberPair.second;
     
    9494    m_animationElement->adjustFromToValues<pair<float, float> >(0, fromNumberPair, toNumberPair, animatedNumberPair, percentage, m_contextElement);
    9595
    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);
    9898}
    9999
  • trunk/Source/WebCore/svg/SVGAnimatedNumberOptionalNumber.h

    r115178 r115305  
    3333    virtual ~SVGAnimatedNumberOptionalNumberAnimator() { }
    3434   
    35     static void calculateAnimatedNumberOptionalNumber(SVGAnimationElement*, float percentage, unsigned repeatCount, float& animatedNumber, float fromNumber, float toNumber);
    36    
    3735    virtual PassOwnPtr<SVGAnimatedType> constructFromString(const String&);
    3836    virtual PassOwnPtr<SVGAnimatedType> startAnimValAnimation(const Vector<SVGAnimatedProperty*>&);
  • trunk/Source/WebCore/svg/SVGAnimatedRect.cpp

    r115187 r115305  
    8383    m_animationElement->adjustFromToValues<FloatRect>(0, fromRect, toRect, animatedRect, percentage, m_contextElement);
    8484
    85     FloatRect newRect;   
    86     if (m_animationElement->calcMode() == CalcModeDiscrete)
    87         newRect = percentage < 0.5 ? fromRect : toRect;
    88     else
    89         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);
    9393
    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);
    10695}
    10796
  • trunk/Source/WebCore/svg/SVGAnimationElement.h

    r115296 r115305  
    166166    }
    167167
     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
    168188protected:
    169189    SVGAnimationElement(const QualifiedName&, Document*);
Note: See TracChangeset for help on using the changeset viewer.