2 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
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.
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.
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.
22 #if ENABLE(SVG) && ENABLE(SVG_ANIMATION)
23 #include "SVGAnimatedNumberList.h"
25 #include "SVGAnimateElement.h"
26 #include "SVGAnimatedNumber.h"
30 SVGAnimatedNumberListAnimator::SVGAnimatedNumberListAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
31 : SVGAnimatedTypeAnimator(AnimatedNumberList, animationElement, contextElement)
35 PassOwnPtr<SVGAnimatedType> SVGAnimatedNumberListAnimator::constructFromString(const String& string)
37 OwnPtr<SVGAnimatedType> animtedType = SVGAnimatedType::createNumberList(new SVGNumberList);
38 animtedType->numberList().parse(string);
39 return animtedType.release();
42 void SVGAnimatedNumberListAnimator::calculateFromAndToValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& toString)
44 ASSERT(m_contextElement);
45 ASSERT(m_animationElement);
47 from = constructFromString(fromString);
48 to = constructFromString(toString);
51 void SVGAnimatedNumberListAnimator::calculateFromAndByValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& byString)
53 ASSERT(m_contextElement);
54 ASSERT(m_animationElement);
56 from = constructFromString(fromString);
57 to = constructFromString(byString);
59 SVGNumberList& fromNumberList = from->numberList();
60 SVGNumberList& toNumberList = to->numberList();
62 unsigned size = fromNumberList.size();
63 if (size != toNumberList.size())
66 for (unsigned i = 0; i < size; ++i)
67 toNumberList[i] += fromNumberList[i];
70 void SVGAnimatedNumberListAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount,
71 OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, OwnPtr<SVGAnimatedType>& animated)
73 ASSERT(m_animationElement);
74 ASSERT(m_contextElement);
76 SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement);
77 AnimationMode animationMode = animationElement->animationMode();
79 // To animation uses contributions from the lower priority animations as the base value.
80 SVGNumberList& fromNumberList = from->numberList();
81 SVGNumberList& animatedNumberList = animated->numberList();
82 if (animationMode == ToAnimation)
83 fromNumberList = animatedNumberList;
85 SVGNumberList& toNumberList = to->numberList();
86 unsigned itemsCount = fromNumberList.size();
87 if (itemsCount != toNumberList.size()) {
88 if (percentage < 0.5) {
89 if (animationMode != ToAnimation)
90 animatedNumberList = fromNumberList;
92 animatedNumberList = toNumberList;
96 for (unsigned i = 0; i < itemsCount; ++i)
97 SVGAnimatedNumberAnimator::calculateAnimatedNumber(animationElement, percentage, repeatCount, animatedNumberList[i], fromNumberList[i], toNumberList[i]);
100 float SVGAnimatedNumberListAnimator::calculateDistance(const String&, const String&)
102 // FIXME: Distance calculation is not possible for SVGNumberList right now. We need the distance for every single value.
108 #endif // ENABLE(SVG) && ENABLE(SVG_ANIMATION)