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#include "SVGAnimatedInteger.h" 22 23#include "SVGAnimateElement.h" 24#include "SVGAnimatedNumber.h" 25#include <wtf/MathExtras.h> 26 27namespace WebCore { 28 29SVGAnimatedIntegerAnimator::SVGAnimatedIntegerAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement) 30 : SVGAnimatedTypeAnimator(AnimatedInteger, animationElement, contextElement) 31{ 32} 33 34std::unique_ptr<SVGAnimatedType> SVGAnimatedIntegerAnimator::constructFromString(const String& string) 35{ 36 auto animatedType = SVGAnimatedType::createInteger(std::make_unique<int>()); 37 animatedType->integer() = string.toIntStrict(); 38 return animatedType; 39} 40 41std::unique_ptr<SVGAnimatedType> SVGAnimatedIntegerAnimator::startAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes) 42{ 43 return SVGAnimatedType::createInteger(constructFromBaseValue<SVGAnimatedInteger>(animatedTypes)); 44} 45 46void SVGAnimatedIntegerAnimator::stopAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes) 47{ 48 stopAnimValAnimationForType<SVGAnimatedInteger>(animatedTypes); 49} 50 51void SVGAnimatedIntegerAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType* type) 52{ 53 resetFromBaseValue<SVGAnimatedInteger>(animatedTypes, type, &SVGAnimatedType::integer); 54} 55 56void SVGAnimatedIntegerAnimator::animValWillChange(const SVGElementAnimatedPropertyList& animatedTypes) 57{ 58 animValWillChangeForType<SVGAnimatedInteger>(animatedTypes); 59} 60 61void SVGAnimatedIntegerAnimator::animValDidChange(const SVGElementAnimatedPropertyList& animatedTypes) 62{ 63 animValDidChangeForType<SVGAnimatedInteger>(animatedTypes); 64} 65 66void SVGAnimatedIntegerAnimator::addAnimatedTypes(SVGAnimatedType* from, SVGAnimatedType* to) 67{ 68 ASSERT(from->type() == AnimatedInteger); 69 ASSERT(from->type() == to->type()); 70 71 to->integer() += from->integer(); 72} 73 74void SVGAnimatedIntegerAnimator::calculateAnimatedInteger(SVGAnimationElement* animationElement, float percentage, unsigned repeatCount, int fromInteger, int toInteger, int toAtEndOfDurationInteger, int& animatedInteger) 75{ 76 float animatedNumber = animatedInteger; 77 animationElement->animateAdditiveNumber(percentage, repeatCount, fromInteger, toInteger, toAtEndOfDurationInteger, animatedNumber); 78 animatedInteger = static_cast<int>(roundf(animatedNumber)); 79} 80 81void SVGAnimatedIntegerAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGAnimatedType* from, SVGAnimatedType* to, SVGAnimatedType* toAtEndOfDuration, SVGAnimatedType* animated) 82{ 83 ASSERT(m_animationElement); 84 ASSERT(m_contextElement); 85 86 int fromInteger = m_animationElement->animationMode() == ToAnimation ? animated->integer() : from->integer(); 87 int toInteger = to->integer(); 88 int toAtEndOfDurationInteger = toAtEndOfDuration->integer(); 89 int& animatedInteger = animated->integer(); 90 91 calculateAnimatedInteger(m_animationElement, percentage, repeatCount, fromInteger, toInteger, toAtEndOfDurationInteger, animatedInteger); 92} 93 94float SVGAnimatedIntegerAnimator::calculateDistance(const String& fromString, const String& toString) 95{ 96 ASSERT(m_contextElement); 97 int from = fromString.toIntStrict(); 98 int to = toString.toIntStrict(); 99 return abs(to - from); 100} 101 102} 103