2 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
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.
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.
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.
22 #if ENABLE(SVG) && ENABLE(SVG_ANIMATION)
23 #include "SVGAnimatedBoolean.h"
25 #include "SVGAnimateElement.h"
29 SVGAnimatedBooleanAnimator::SVGAnimatedBooleanAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
30 : SVGAnimatedTypeAnimator(AnimatedBoolean, animationElement, contextElement)
34 PassOwnPtr<SVGAnimatedType> SVGAnimatedBooleanAnimator::constructFromString(const String& string)
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();
42 void SVGAnimatedBooleanAnimator::calculateFromAndToValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& toString)
44 ASSERT(m_contextElement);
45 ASSERT(m_animationElement);
47 from = constructFromString(fromString);
48 to = constructFromString(toString);
51 void SVGAnimatedBooleanAnimator::calculateFromAndByValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& byString)
53 ASSERT(m_contextElement);
54 ASSERT(m_animationElement);
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);
61 void SVGAnimatedBooleanAnimator::calculateAnimatedValue(float percentage, unsigned,
62 OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, OwnPtr<SVGAnimatedType>& animated)
64 ASSERT(m_animationElement);
65 ASSERT(m_contextElement);
66 SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement);
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();
73 animateString = from->boolean();
76 float SVGAnimatedBooleanAnimator::calculateDistance(const String&, const String&)
78 // No paced animations for boolean.
84 #endif // ENABLE(SVG) && ENABLE(SVG_ANIMATION)