initial import
[vuplus_webkit] / Source / WebCore / svg / SVGAnimatedString.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 "SVGAnimatedString.h"
24
25 #include "SVGAnimateElement.h"
26
27 namespace WebCore {
28
29 SVGAnimatedStringAnimator::SVGAnimatedStringAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
30     : SVGAnimatedTypeAnimator(AnimatedString, animationElement, contextElement)
31 {
32 }
33
34 PassOwnPtr<SVGAnimatedType> SVGAnimatedStringAnimator::constructFromString(const String& string)
35 {
36     OwnPtr<SVGAnimatedType> animatedType = SVGAnimatedType::createString(new String);
37     animatedType->string() = string;
38     return animatedType.release();
39 }
40
41 void SVGAnimatedStringAnimator::calculateFromAndToValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& toString)
42 {
43     ASSERT(m_contextElement);
44     ASSERT(m_animationElement);
45
46     from = constructFromString(fromString);
47     to = constructFromString(toString);
48 }
49
50 void SVGAnimatedStringAnimator::calculateFromAndByValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& byString)
51 {
52     ASSERT(m_contextElement);
53     ASSERT(m_animationElement);
54     
55     // Not specified what to do on 'by'-animations with string. Fallback to 'to'-animation right now. 
56     from = constructFromString(fromString);
57     to = constructFromString(byString);
58 }
59
60 void SVGAnimatedStringAnimator::calculateAnimatedValue(float percentage, unsigned,
61                                                        OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, OwnPtr<SVGAnimatedType>& animated)
62 {
63     ASSERT(m_animationElement);
64     ASSERT(m_contextElement);
65     SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement);
66     
67     AnimationMode animationMode = animationElement->animationMode();
68     String& animateString = animated->string();
69     if ((animationMode == FromToAnimation && percentage > 0.5) || animationMode == ToAnimation || percentage == 1)
70         animateString = to->string();
71     else
72         animateString = from->string();
73 }
74
75 float SVGAnimatedStringAnimator::calculateDistance(const String&, const String&)
76 {
77     // No paced animations for strings.
78     return -1;
79 }
80
81 }
82
83 #endif // ENABLE(SVG) && ENABLE(SVG_ANIMATION)