initial import
[vuplus_webkit] / Source / WebCore / svg / SVGAnimatedNumberList.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 "SVGAnimatedNumberList.h"
24
25 #include "SVGAnimateElement.h"
26 #include "SVGAnimatedNumber.h"
27
28 namespace WebCore {
29
30 SVGAnimatedNumberListAnimator::SVGAnimatedNumberListAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
31     : SVGAnimatedTypeAnimator(AnimatedNumberList, animationElement, contextElement)
32 {
33 }
34
35 PassOwnPtr<SVGAnimatedType> SVGAnimatedNumberListAnimator::constructFromString(const String& string)
36 {
37     OwnPtr<SVGAnimatedType> animtedType = SVGAnimatedType::createNumberList(new SVGNumberList);
38     animtedType->numberList().parse(string);
39     return animtedType.release();
40 }
41
42 void SVGAnimatedNumberListAnimator::calculateFromAndToValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& toString)
43 {
44     ASSERT(m_contextElement);
45     ASSERT(m_animationElement);
46     
47     from = constructFromString(fromString);
48     to = constructFromString(toString);
49 }
50
51 void SVGAnimatedNumberListAnimator::calculateFromAndByValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& byString)
52 {
53     ASSERT(m_contextElement);
54     ASSERT(m_animationElement);
55     
56     from = constructFromString(fromString);
57     to = constructFromString(byString);
58     
59     SVGNumberList& fromNumberList = from->numberList();
60     SVGNumberList& toNumberList = to->numberList();
61     
62     unsigned size = fromNumberList.size();
63     if (size != toNumberList.size())
64         return;
65
66     for (unsigned i = 0; i < size; ++i)
67         toNumberList[i] += fromNumberList[i];
68 }
69
70 void SVGAnimatedNumberListAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount,
71                                                            OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, OwnPtr<SVGAnimatedType>& animated)
72 {
73     ASSERT(m_animationElement);
74     ASSERT(m_contextElement);
75
76     SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement);    
77     AnimationMode animationMode = animationElement->animationMode();
78
79     // To animation uses contributions from the lower priority animations as the base value.
80     SVGNumberList& fromNumberList = from->numberList();
81     SVGNumberList& animatedNumberList = animated->numberList();
82     if (animationMode == ToAnimation)
83         fromNumberList = animatedNumberList;
84
85     SVGNumberList& toNumberList = to->numberList();
86     unsigned itemsCount = fromNumberList.size();
87     if (itemsCount != toNumberList.size()) {
88         if (percentage < 0.5) {
89             if (animationMode != ToAnimation)
90                 animatedNumberList = fromNumberList;
91         } else
92             animatedNumberList = toNumberList;
93         return;
94     }
95     
96     for (unsigned i = 0; i < itemsCount; ++i)
97         SVGAnimatedNumberAnimator::calculateAnimatedNumber(animationElement, percentage, repeatCount, animatedNumberList[i], fromNumberList[i], toNumberList[i]);
98 }
99
100 float SVGAnimatedNumberListAnimator::calculateDistance(const String&, const String&)
101 {
102     // FIXME: Distance calculation is not possible for SVGNumberList right now. We need the distance for every single value.
103     return -1;
104 }
105
106 }
107
108 #endif // ENABLE(SVG) && ENABLE(SVG_ANIMATION)