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 "SVGAnimatedNumberOptionalNumber.h"
25 #include "SVGAnimateElement.h"
26 #include "SVGAnimatedNumber.h"
27 #include "SVGParserUtilities.h"
33 SVGAnimatedNumberOptionalNumberAnimator::SVGAnimatedNumberOptionalNumberAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
34 : SVGAnimatedTypeAnimator(AnimatedNumberOptionalNumber, animationElement, contextElement)
38 PassOwnPtr<SVGAnimatedType> SVGAnimatedNumberOptionalNumberAnimator::constructFromString(const String& string)
40 OwnPtr<SVGAnimatedType> animtedType = SVGAnimatedType::createNumberOptionalNumber(new pair<float, float>);
41 pair<float, float>& animatedNumber = animtedType->numberOptionalNumber();
42 if (!parseNumberOptionalNumber(string, animatedNumber.first, animatedNumber.second)) {
43 animatedNumber.first = 0;
44 animatedNumber.second = 0;
46 return animtedType.release();
49 void SVGAnimatedNumberOptionalNumberAnimator::calculateFromAndToValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& toString)
51 ASSERT(m_contextElement);
52 ASSERT(m_animationElement);
53 SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement);
54 animationElement->determinePropertyValueTypes(fromString, toString);
56 from = constructFromString(fromString);
57 to = constructFromString(toString);
60 void SVGAnimatedNumberOptionalNumberAnimator::calculateFromAndByValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& byString)
62 ASSERT(m_contextElement);
63 ASSERT(m_animationElement);
64 SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement);
65 animationElement->determinePropertyValueTypes(fromString, byString);
67 from = constructFromString(fromString);
68 to = constructFromString(byString);
70 pair<float, float>& fromNumberPair = from->numberOptionalNumber();
71 pair<float, float>& toNumberPair = to->numberOptionalNumber();
73 toNumberPair.first += fromNumberPair.first;
74 toNumberPair.second += fromNumberPair.second;
77 void SVGAnimatedNumberOptionalNumberAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount,
78 OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, OwnPtr<SVGAnimatedType>& animated)
80 ASSERT(m_animationElement);
81 ASSERT(m_contextElement);
83 SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement);
84 AnimationMode animationMode = animationElement->animationMode();
86 // To animation uses contributions from the lower priority animations as the base value.
87 pair<float, float>& fromNumberPair = from->numberOptionalNumber();
88 pair<float, float>& animatedNumberPair = animated->numberOptionalNumber();
89 if (animationMode == ToAnimation)
90 fromNumberPair = animatedNumberPair;
92 pair<float, float>& toNumberPair = to->numberOptionalNumber();
93 SVGAnimatedNumberAnimator::calculateAnimatedNumber(animationElement, percentage, repeatCount, animatedNumberPair.first, fromNumberPair.first, toNumberPair.first);
94 SVGAnimatedNumberAnimator::calculateAnimatedNumber(animationElement, percentage, repeatCount, animatedNumberPair.second, fromNumberPair.second, toNumberPair.second);
97 float SVGAnimatedNumberOptionalNumberAnimator::calculateDistance(const String&, const String&)
99 // FIXME: Distance calculation is not possible for SVGNumberOptionalNumber right now. We need the distance for every single value.
105 #endif // ENABLE(SVG) && ENABLE(SVG_ANIMATION)