initial import
[vuplus_webkit] / Source / WebCore / svg / SVGAnimatedNumberOptionalNumber.cpp
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 "SVGAnimatedNumberOptionalNumber.h"
24
25 #include "SVGAnimateElement.h"
26 #include "SVGAnimatedNumber.h"
27 #include "SVGParserUtilities.h"
28
29 using namespace std;
30
31 namespace WebCore {
32
33 SVGAnimatedNumberOptionalNumberAnimator::SVGAnimatedNumberOptionalNumberAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
34     : SVGAnimatedTypeAnimator(AnimatedNumberOptionalNumber, animationElement, contextElement)
35 {
36 }
37
38 PassOwnPtr<SVGAnimatedType> SVGAnimatedNumberOptionalNumberAnimator::constructFromString(const String& string)
39 {
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;
45     }
46     return animtedType.release();
47 }
48
49 void SVGAnimatedNumberOptionalNumberAnimator::calculateFromAndToValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& toString)
50 {
51     ASSERT(m_contextElement);
52     ASSERT(m_animationElement);
53     SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement);
54     animationElement->determinePropertyValueTypes(fromString, toString);
55     
56     from = constructFromString(fromString);
57     to = constructFromString(toString);
58 }
59
60 void SVGAnimatedNumberOptionalNumberAnimator::calculateFromAndByValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& byString)
61 {
62     ASSERT(m_contextElement);
63     ASSERT(m_animationElement);
64     SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement);
65     animationElement->determinePropertyValueTypes(fromString, byString);
66     
67     from = constructFromString(fromString);
68     to = constructFromString(byString);
69
70     pair<float, float>& fromNumberPair = from->numberOptionalNumber();
71     pair<float, float>& toNumberPair = to->numberOptionalNumber();
72     
73     toNumberPair.first += fromNumberPair.first;
74     toNumberPair.second += fromNumberPair.second;
75 }
76
77 void SVGAnimatedNumberOptionalNumberAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount,
78                                                        OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, OwnPtr<SVGAnimatedType>& animated)
79 {
80     ASSERT(m_animationElement);
81     ASSERT(m_contextElement);
82
83     SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement);
84     AnimationMode animationMode = animationElement->animationMode();
85
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;
91
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);
95 }
96
97 float SVGAnimatedNumberOptionalNumberAnimator::calculateDistance(const String&, const String&)
98 {
99     // FIXME: Distance calculation is not possible for SVGNumberOptionalNumber right now. We need the distance for every single value.
100     return -1;
101 }
102
103 }
104
105 #endif // ENABLE(SVG) && ENABLE(SVG_ANIMATION)