Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) Research In Motion Limited 2011. All rights reserved.
      3  *
      4  * This library is free software; you can redistribute it and/or
      5  * modify it under the terms of the GNU Library General Public
      6  * License as published by the Free Software Foundation; either
      7  * version 2 of the License, or (at your option) any later version.
      8  *
      9  * This library is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  * Library General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Library General Public License
     15  * along with this library; see the file COPYING.LIB.  If not, write to
     16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17  * Boston, MA 02110-1301, USA.
     18  */
     19 
     20 #include "config.h"
     21 
     22 #include "core/svg/SVGAnimatedNumberOptionalNumber.h"
     23 
     24 #include "core/svg/SVGAnimateElement.h"
     25 #include "core/svg/SVGAnimatedNumber.h"
     26 #include "core/svg/SVGParserUtilities.h"
     27 
     28 using namespace std;
     29 
     30 namespace WebCore {
     31 
     32 SVGAnimatedNumberOptionalNumberAnimator::SVGAnimatedNumberOptionalNumberAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
     33     : SVGAnimatedTypeAnimator(AnimatedNumberOptionalNumber, animationElement, contextElement)
     34 {
     35 }
     36 
     37 PassOwnPtr<SVGAnimatedType> SVGAnimatedNumberOptionalNumberAnimator::constructFromString(const String& string)
     38 {
     39     OwnPtr<SVGAnimatedType> animtedType = SVGAnimatedType::createNumberOptionalNumber(new pair<float, float>);
     40     pair<float, float>& animatedNumber = animtedType->numberOptionalNumber();
     41     if (!parseNumberOptionalNumber(string, animatedNumber.first, animatedNumber.second)) {
     42         animatedNumber.first = 0;
     43         animatedNumber.second = 0;
     44     }
     45     return animtedType.release();
     46 }
     47 
     48 PassOwnPtr<SVGAnimatedType> SVGAnimatedNumberOptionalNumberAnimator::startAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
     49 {
     50     return SVGAnimatedType::createNumberOptionalNumber(constructFromBaseValues<SVGAnimatedNumber, SVGAnimatedNumber>(animatedTypes));
     51 }
     52 
     53 void SVGAnimatedNumberOptionalNumberAnimator::stopAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
     54 {
     55     stopAnimValAnimationForTypes<SVGAnimatedNumber, SVGAnimatedNumber>(animatedTypes);
     56 }
     57 
     58 void SVGAnimatedNumberOptionalNumberAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType* type)
     59 {
     60     resetFromBaseValues<SVGAnimatedNumber, SVGAnimatedNumber>(animatedTypes, type, &SVGAnimatedType::numberOptionalNumber);
     61 }
     62 
     63 void SVGAnimatedNumberOptionalNumberAnimator::animValWillChange(const SVGElementAnimatedPropertyList& animatedTypes)
     64 {
     65     animValWillChangeForTypes<SVGAnimatedNumber, SVGAnimatedNumber>(animatedTypes);
     66 }
     67 
     68 void SVGAnimatedNumberOptionalNumberAnimator::animValDidChange(const SVGElementAnimatedPropertyList& animatedTypes)
     69 {
     70     animValDidChangeForTypes<SVGAnimatedNumber, SVGAnimatedNumber>(animatedTypes);
     71 }
     72 
     73 void SVGAnimatedNumberOptionalNumberAnimator::addAnimatedTypes(SVGAnimatedType* from, SVGAnimatedType* to)
     74 {
     75     ASSERT(from->type() == AnimatedNumberOptionalNumber);
     76     ASSERT(from->type() == to->type());
     77 
     78     const pair<float, float>& fromNumberPair = from->numberOptionalNumber();
     79     pair<float, float>& toNumberPair = to->numberOptionalNumber();
     80 
     81     toNumberPair.first += fromNumberPair.first;
     82     toNumberPair.second += fromNumberPair.second;
     83 }
     84 
     85 void SVGAnimatedNumberOptionalNumberAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGAnimatedType* from, SVGAnimatedType* to, SVGAnimatedType* toAtEndOfDuration, SVGAnimatedType* animated)
     86 {
     87     ASSERT(m_animationElement);
     88     ASSERT(m_contextElement);
     89 
     90     const pair<float, float>& fromNumberPair = m_animationElement->animationMode() == ToAnimation ? animated->numberOptionalNumber() :  from->numberOptionalNumber();
     91     const pair<float, float>& toNumberPair = to->numberOptionalNumber();
     92     const pair<float, float>& toAtEndOfDurationNumberPair = toAtEndOfDuration->numberOptionalNumber();
     93     pair<float, float>& animatedNumberPair = animated->numberOptionalNumber();
     94 
     95     m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromNumberPair.first, toNumberPair.first, toAtEndOfDurationNumberPair.first, animatedNumberPair.first);
     96     m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromNumberPair.second, toNumberPair.second, toAtEndOfDurationNumberPair.second, animatedNumberPair.second);
     97 }
     98 
     99 float SVGAnimatedNumberOptionalNumberAnimator::calculateDistance(const String&, const String&)
    100 {
    101     // FIXME: Distance calculation is not possible for SVGNumberOptionalNumber right now. We need the distance for every single value.
    102     return -1;
    103 }
    104 
    105 }
    106