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)
23#include "SVGAnimatedString.h"
24
25#include "SVGAnimateElement.h"
26
27namespace WebCore {
28
29SVGAnimatedStringAnimator::SVGAnimatedStringAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
30    : SVGAnimatedTypeAnimator(AnimatedString, animationElement, contextElement)
31{
32}
33
34PassOwnPtr<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
41PassOwnPtr<SVGAnimatedType> SVGAnimatedStringAnimator::startAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
42{
43    return SVGAnimatedType::createString(constructFromBaseValue<SVGAnimatedString>(animatedTypes));
44}
45
46void SVGAnimatedStringAnimator::stopAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
47{
48    stopAnimValAnimationForType<SVGAnimatedString>(animatedTypes);
49}
50
51void SVGAnimatedStringAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType* type)
52{
53    resetFromBaseValue<SVGAnimatedString>(animatedTypes, type, &SVGAnimatedType::string);
54}
55
56void SVGAnimatedStringAnimator::animValWillChange(const SVGElementAnimatedPropertyList& animatedTypes)
57{
58    animValWillChangeForType<SVGAnimatedString>(animatedTypes);
59}
60
61void SVGAnimatedStringAnimator::animValDidChange(const SVGElementAnimatedPropertyList& animatedTypes)
62{
63    animValDidChangeForType<SVGAnimatedString>(animatedTypes);
64}
65
66void SVGAnimatedStringAnimator::addAnimatedTypes(SVGAnimatedType*, SVGAnimatedType*)
67{
68    ASSERT_NOT_REACHED();
69}
70
71static String parseStringFromString(SVGAnimationElement*, const String& string)
72{
73    return string;
74}
75
76void SVGAnimatedStringAnimator::calculateAnimatedValue(float percentage, unsigned, SVGAnimatedType* from, SVGAnimatedType* to, SVGAnimatedType*, SVGAnimatedType* animated)
77{
78    ASSERT(m_animationElement);
79    ASSERT(m_contextElement);
80
81    String fromString = from->string();
82    String toString = to->string();
83    String& animatedString = animated->string();
84
85    // Apply CSS inheritance rules.
86    m_animationElement->adjustForInheritance<String>(parseStringFromString, m_animationElement->fromPropertyValueType(), fromString, m_contextElement);
87    m_animationElement->adjustForInheritance<String>(parseStringFromString, m_animationElement->toPropertyValueType(), toString, m_contextElement);
88
89    m_animationElement->animateDiscreteType<String>(percentage, fromString, toString, animatedString);
90}
91
92float SVGAnimatedStringAnimator::calculateDistance(const String&, const String&)
93{
94    // No paced animations for strings.
95    return -1;
96}
97
98}
99
100#endif // ENABLE(SVG)
101