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