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/SVGAnimatedNumberList.h"
     23 
     24 #include "core/svg/SVGAnimateElement.h"
     25 #include "core/svg/SVGAnimatedNumber.h"
     26 
     27 namespace WebCore {
     28 
     29 SVGAnimatedNumberListAnimator::SVGAnimatedNumberListAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
     30     : SVGAnimatedTypeAnimator(AnimatedNumberList, animationElement, contextElement)
     31 {
     32 }
     33 
     34 PassOwnPtr<SVGAnimatedType> SVGAnimatedNumberListAnimator::constructFromString(const String& string)
     35 {
     36     OwnPtr<SVGAnimatedType> animtedType = SVGAnimatedType::createNumberList(new SVGNumberList);
     37     animtedType->numberList().parse(string);
     38     return animtedType.release();
     39 }
     40 
     41 PassOwnPtr<SVGAnimatedType> SVGAnimatedNumberListAnimator::startAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
     42 {
     43     return SVGAnimatedType::createNumberList(constructFromBaseValue<SVGAnimatedNumberList>(animatedTypes));
     44 }
     45 
     46 void SVGAnimatedNumberListAnimator::stopAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
     47 {
     48     stopAnimValAnimationForType<SVGAnimatedNumberList>(animatedTypes);
     49 }
     50 
     51 void SVGAnimatedNumberListAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType* type)
     52 {
     53     resetFromBaseValue<SVGAnimatedNumberList>(animatedTypes, type, &SVGAnimatedType::numberList);
     54 }
     55 
     56 void SVGAnimatedNumberListAnimator::animValWillChange(const SVGElementAnimatedPropertyList& animatedTypes)
     57 {
     58     animValWillChangeForType<SVGAnimatedNumberList>(animatedTypes);
     59 }
     60 
     61 void SVGAnimatedNumberListAnimator::animValDidChange(const SVGElementAnimatedPropertyList& animatedTypes)
     62 {
     63     animValDidChangeForType<SVGAnimatedNumberList>(animatedTypes);
     64 }
     65 
     66 void SVGAnimatedNumberListAnimator::addAnimatedTypes(SVGAnimatedType* from, SVGAnimatedType* to)
     67 {
     68     ASSERT(from->type() == AnimatedNumberList);
     69     ASSERT(from->type() == to->type());
     70 
     71     const SVGNumberList& fromNumberList = from->numberList();
     72     SVGNumberList& toNumberList = to->numberList();
     73 
     74     unsigned fromNumberListSize = fromNumberList.size();
     75     if (!fromNumberListSize || fromNumberListSize != toNumberList.size())
     76         return;
     77 
     78     for (unsigned i = 0; i < fromNumberListSize; ++i)
     79         toNumberList[i] += fromNumberList[i];
     80 }
     81 
     82 void SVGAnimatedNumberListAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGAnimatedType* from, SVGAnimatedType* to, SVGAnimatedType* toAtEndOfDuration, SVGAnimatedType* animated)
     83 {
     84     ASSERT(m_animationElement);
     85 
     86     const SVGNumberList& fromNumberList = m_animationElement->animationMode() == ToAnimation ? animated->numberList() : from->numberList();
     87     const SVGNumberList& toNumberList = to->numberList();
     88     const SVGNumberList& toAtEndOfDurationNumberList = toAtEndOfDuration->numberList();
     89     SVGNumberList& animatedNumberList = animated->numberList();
     90     if (!m_animationElement->adjustFromToListValues<SVGNumberList>(fromNumberList, toNumberList, animatedNumberList, percentage))
     91         return;
     92 
     93     unsigned fromNumberListSize = fromNumberList.size();
     94     unsigned toNumberListSize = toNumberList.size();
     95     unsigned toAtEndOfDurationSize = toAtEndOfDurationNumberList.size();
     96 
     97     for (unsigned i = 0; i < toNumberListSize; ++i) {
     98         float effectiveFrom = fromNumberListSize ? fromNumberList[i].value() : 0;
     99         float effectiveToAtEnd = i < toAtEndOfDurationSize ? toAtEndOfDurationNumberList[i].value() : 0;
    100         m_animationElement->animateAdditiveNumber(percentage, repeatCount, effectiveFrom, toNumberList[i].value(), effectiveToAtEnd, animatedNumberList[i].valueRef());
    101     }
    102 }
    103 
    104 float SVGAnimatedNumberListAnimator::calculateDistance(const String&, const String&)
    105 {
    106     // FIXME: Distance calculation is not possible for SVGNumberList right now. We need the distance for every single value.
    107     return -1;
    108 }
    109 
    110 }
    111