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