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
22#if ENABLE(SVG) && ENABLE(SVG_ANIMATION)
23#include "SVGAnimatedIntegerOptionalInteger.h"
24
25#include "SVGAnimateElement.h"
26#include "SVGAnimatedNumber.h"
27#include "SVGParserUtilities.h"
28
29using namespace std;
30
31namespace WebCore {
32
33SVGAnimatedIntegerOptionalIntegerAnimator::SVGAnimatedIntegerOptionalIntegerAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
34 : SVGAnimatedTypeAnimator(AnimatedIntegerOptionalInteger, animationElement, contextElement)
35{
36}
37
38PassOwnPtr<SVGAnimatedType> SVGAnimatedIntegerOptionalIntegerAnimator::constructFromString(const String& string)
39{
40 OwnPtr<SVGAnimatedType> animtedType = SVGAnimatedType::createIntegerOptionalInteger(new pair<int, int>);
41 pair<int, int>& animatedIntegerPair = animtedType->integerOptionalInteger();
42 float value1 = 0;
43 float value2 = 0;
44 parseNumberOptionalNumber(string, value1, value1);
45 animatedIntegerPair.first = static_cast<int>(roundf(value1));
46 animatedIntegerPair.second = static_cast<int>(roundf(value2));
47 return animtedType.release();
48}
49
50void SVGAnimatedIntegerOptionalIntegerAnimator::calculateFromAndToValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& toString)
51{
52 ASSERT(m_contextElement);
53 ASSERT(m_animationElement);
54 SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement);
55 animationElement->determinePropertyValueTypes(fromString, toString);
56
57 from = constructFromString(fromString);
58 to = constructFromString(toString);
59}
60
61void SVGAnimatedIntegerOptionalIntegerAnimator::calculateFromAndByValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& byString)
62{
63 ASSERT(m_contextElement);
64 ASSERT(m_animationElement);
65 SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement);
66 animationElement->determinePropertyValueTypes(fromString, byString);
67
68 from = constructFromString(fromString);
69 to = constructFromString(byString);
70
71 pair<int, int>& fromIntegerPair = from->integerOptionalInteger();
72 pair<int, int>& toIntegerPair = to->integerOptionalInteger();
73
74 toIntegerPair.first += fromIntegerPair.first;
75 toIntegerPair.second += fromIntegerPair.second;
76}
77
78void SVGAnimatedIntegerOptionalIntegerAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount,
79 OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, OwnPtr<SVGAnimatedType>& animated)
80{
81 ASSERT(m_animationElement);
82 ASSERT(m_contextElement);
83
84 SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement);
85 AnimationMode animationMode = animationElement->animationMode();
86
87 // To animation uses contributions from the lower priority animations as the base value.
88 pair<int, int>& fromIntegerPair = from->integerOptionalInteger();
89 pair<int, int>& animatedIntegerPair = animated->integerOptionalInteger();
90 if (animationMode == ToAnimation)
91 fromIntegerPair = animatedIntegerPair;
92
93 pair<int, int>& toIntegerPair = to->integerOptionalInteger();
94 float value1 = animatedIntegerPair.first;
95 float value2 = animatedIntegerPair.second;
96 SVGAnimatedNumberAnimator::calculateAnimatedNumber(animationElement, percentage, repeatCount, value1, fromIntegerPair.first, toIntegerPair.first);
97 SVGAnimatedNumberAnimator::calculateAnimatedNumber(animationElement, percentage, repeatCount, value2, fromIntegerPair.second, toIntegerPair.second);
98 animatedIntegerPair.first = static_cast<int>(roundf(value1));
99 animatedIntegerPair.second = static_cast<int>(roundf(value2));
100}
101
102float SVGAnimatedIntegerOptionalIntegerAnimator::calculateDistance(const String&, const String&)
103{
104 // FIXME: Distance calculation is not possible for SVGIntegerOptionalInteger right now. We need the distance for every single value.
105 return -1;
106}
107
108}
109
110#endif // ENABLE(SVG) && ENABLE(SVG_ANIMATION)