1/* 2 * Copyright (C) Research In Motion Limited 2012. 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 "SVGAnimatedIntegerOptionalInteger.h" 22 23#include "SVGAnimateElement.h" 24#include "SVGAnimatedInteger.h" 25#include "SVGParserUtilities.h" 26 27namespace WebCore { 28 29SVGAnimatedIntegerOptionalIntegerAnimator::SVGAnimatedIntegerOptionalIntegerAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement) 30 : SVGAnimatedTypeAnimator(AnimatedIntegerOptionalInteger, animationElement, contextElement) 31{ 32} 33 34std::unique_ptr<SVGAnimatedType> SVGAnimatedIntegerOptionalIntegerAnimator::constructFromString(const String& string) 35{ 36 auto animatedType = SVGAnimatedType::createIntegerOptionalInteger(std::make_unique<std::pair<int, int>>()); 37 std::pair<int, int>& animatedInteger = animatedType->integerOptionalInteger(); 38 float firstNumber = 0; 39 float secondNumber = 0; 40 if (!parseNumberOptionalNumber(string, firstNumber, secondNumber)) { 41 animatedInteger.first = 0; 42 animatedInteger.second = 0; 43 } else { 44 animatedInteger.first = static_cast<int>(roundf(firstNumber)); 45 animatedInteger.second = static_cast<int>(roundf(secondNumber)); 46 } 47 return animatedType; 48} 49 50std::unique_ptr<SVGAnimatedType> SVGAnimatedIntegerOptionalIntegerAnimator::startAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes) 51{ 52 return SVGAnimatedType::createIntegerOptionalInteger(constructFromBaseValues<SVGAnimatedInteger, SVGAnimatedInteger>(animatedTypes)); 53} 54 55void SVGAnimatedIntegerOptionalIntegerAnimator::stopAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes) 56{ 57 stopAnimValAnimationForTypes<SVGAnimatedInteger, SVGAnimatedInteger>(animatedTypes); 58} 59 60void SVGAnimatedIntegerOptionalIntegerAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType* type) 61{ 62 resetFromBaseValues<SVGAnimatedInteger, SVGAnimatedInteger>(animatedTypes, type, &SVGAnimatedType::integerOptionalInteger); 63} 64 65void SVGAnimatedIntegerOptionalIntegerAnimator::animValWillChange(const SVGElementAnimatedPropertyList& animatedTypes) 66{ 67 animValWillChangeForTypes<SVGAnimatedInteger, SVGAnimatedInteger>(animatedTypes); 68} 69 70void SVGAnimatedIntegerOptionalIntegerAnimator::animValDidChange(const SVGElementAnimatedPropertyList& animatedTypes) 71{ 72 animValDidChangeForTypes<SVGAnimatedInteger, SVGAnimatedInteger>(animatedTypes); 73} 74 75void SVGAnimatedIntegerOptionalIntegerAnimator::addAnimatedTypes(SVGAnimatedType* from, SVGAnimatedType* to) 76{ 77 ASSERT(from->type() == AnimatedIntegerOptionalInteger); 78 ASSERT(from->type() == to->type()); 79 80 const std::pair<int, int>& fromIntegerPair = from->integerOptionalInteger(); 81 std::pair<int, int>& toIntegerPair = to->integerOptionalInteger(); 82 83 toIntegerPair.first += fromIntegerPair.first; 84 toIntegerPair.second += fromIntegerPair.second; 85} 86 87void SVGAnimatedIntegerOptionalIntegerAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGAnimatedType* from, SVGAnimatedType* to, SVGAnimatedType* toAtEndOfDuration, SVGAnimatedType* animated) 88{ 89 ASSERT(m_animationElement); 90 ASSERT(m_contextElement); 91 92 const std::pair<int, int>& fromIntegerPair = m_animationElement->animationMode() == ToAnimation ? animated->integerOptionalInteger() : from->integerOptionalInteger(); 93 const std::pair<int, int>& toIntegerPair = to->integerOptionalInteger(); 94 const std::pair<int, int>& toAtEndOfDurationIntegerPair = toAtEndOfDuration->integerOptionalInteger(); 95 std::pair<int, int>& animatedIntegerPair = animated->integerOptionalInteger(); 96 97 SVGAnimatedIntegerAnimator::calculateAnimatedInteger(m_animationElement, percentage, repeatCount, fromIntegerPair.first, toIntegerPair.first, toAtEndOfDurationIntegerPair.first, animatedIntegerPair.first); 98 SVGAnimatedIntegerAnimator::calculateAnimatedInteger(m_animationElement, percentage, repeatCount, fromIntegerPair.second, toIntegerPair.second, toAtEndOfDurationIntegerPair.second, animatedIntegerPair.second); 99} 100 101float SVGAnimatedIntegerOptionalIntegerAnimator::calculateDistance(const String&, const String&) 102{ 103 // FIXME: Distance calculation is not possible for SVGIntegerOptionalInteger right now. We need the distance for every single value. 104 return -1; 105} 106 107} 108