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 "SVGAnimatedInteger.h"
25 #include "SVGAnimateElement.h"
26 #include "SVGAnimatedNumber.h"
27 #include <wtf/MathExtras.h>
31 SVGAnimatedIntegerAnimator::SVGAnimatedIntegerAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
32 : SVGAnimatedTypeAnimator(AnimatedInteger, animationElement, contextElement)
36 PassOwnPtr<SVGAnimatedType> SVGAnimatedIntegerAnimator::constructFromString(const String& string)
38 OwnPtr<SVGAnimatedType> animtedType = SVGAnimatedType::createInteger(new int);
39 animtedType->integer() = string.toIntStrict();
40 return animtedType.release();
43 void SVGAnimatedIntegerAnimator::calculateFromAndToValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& toString)
45 ASSERT(m_contextElement);
46 ASSERT(m_animationElement);
47 SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement);
48 animationElement->determinePropertyValueTypes(fromString, toString);
50 from = constructFromString(fromString);
51 to = constructFromString(toString);
54 void SVGAnimatedIntegerAnimator::calculateFromAndByValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& byString)
56 ASSERT(m_contextElement);
57 ASSERT(m_animationElement);
58 SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement);
59 animationElement->determinePropertyValueTypes(fromString, byString);
61 from = constructFromString(fromString);
62 to = constructFromString(byString);
64 to->integer() += from->integer();
67 void SVGAnimatedIntegerAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount,
68 OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, OwnPtr<SVGAnimatedType>& animated)
70 ASSERT(m_animationElement);
71 ASSERT(m_contextElement);
73 SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement);
74 AnimationMode animationMode = animationElement->animationMode();
76 // To animation uses contributions from the lower priority animations as the base value.
77 int& animatedInt = animated->integer();
78 if (animationMode == ToAnimation)
79 from->integer() = animatedInt;
81 float result = animatedInt;
82 SVGAnimatedNumberAnimator::calculateAnimatedNumber(animationElement, percentage, repeatCount, result, from->integer(), to->integer());
83 animatedInt = static_cast<int>(roundf(result));
86 float SVGAnimatedIntegerAnimator::calculateDistance(const String& fromString, const String& toString)
88 ASSERT(m_contextElement);
89 int from = fromString.toIntStrict();
90 int to = toString.toIntStrict();
91 return abs(to - from);
96 #endif // ENABLE(SVG) && ENABLE(SVG_ANIMATION)