1/*
2 * Copyright (C) Research In Motion Limited 2010-2012. 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#ifndef SVGAnimatedStaticPropertyTearOff_h
21#define SVGAnimatedStaticPropertyTearOff_h
22
23#include "ExceptionCode.h"
24#include "SVGAnimatedProperty.h"
25
26namespace WebCore {
27
28template<typename PropertyType>
29class SVGAnimatedStaticPropertyTearOff : public SVGAnimatedProperty {
30public:
31    typedef PropertyType ContentType;
32
33    PropertyType& baseVal()
34    {
35        return m_property;
36    }
37
38    PropertyType& animVal()
39    {
40        if (m_animatedProperty)
41            return *m_animatedProperty;
42        return m_property;
43    }
44
45    virtual void setBaseVal(const PropertyType& property, ExceptionCode&)
46    {
47        m_property = property;
48        commitChange();
49    }
50
51    static PassRefPtr<SVGAnimatedStaticPropertyTearOff<PropertyType>> create(SVGElement* contextElement, const QualifiedName& attributeName, AnimatedPropertyType animatedPropertyType, PropertyType& property)
52    {
53        ASSERT(contextElement);
54        return adoptRef(new SVGAnimatedStaticPropertyTearOff<PropertyType>(contextElement, attributeName, animatedPropertyType, property));
55    }
56
57    PropertyType& currentAnimatedValue()
58    {
59        ASSERT(m_isAnimating);
60        ASSERT(m_animatedProperty);
61        return *m_animatedProperty;
62    }
63
64    const PropertyType& currentBaseValue() const
65    {
66        return m_property;
67    }
68
69    void animationStarted(PropertyType* newAnimVal)
70    {
71        ASSERT(!m_isAnimating);
72        ASSERT(!m_animatedProperty);
73        ASSERT(newAnimVal);
74        m_animatedProperty = newAnimVal;
75        m_isAnimating = true;
76    }
77
78    void animationEnded()
79    {
80        ASSERT(m_isAnimating);
81        ASSERT(m_animatedProperty);
82        m_animatedProperty = 0;
83        m_isAnimating = false;
84    }
85
86    void animValWillChange()
87    {
88        // no-op for non list types.
89        ASSERT(m_isAnimating);
90        ASSERT(m_animatedProperty);
91    }
92
93    void animValDidChange()
94    {
95        // no-op for non list types.
96        ASSERT(m_isAnimating);
97        ASSERT(m_animatedProperty);
98    }
99
100protected:
101    SVGAnimatedStaticPropertyTearOff(SVGElement* contextElement, const QualifiedName& attributeName, AnimatedPropertyType animatedPropertyType, PropertyType& property)
102        : SVGAnimatedProperty(contextElement, attributeName, animatedPropertyType)
103        , m_property(property)
104        , m_animatedProperty(0)
105    {
106    }
107
108private:
109    PropertyType& m_property;
110    PropertyType* m_animatedProperty;
111};
112
113}
114
115#endif // SVGAnimatedStaticPropertyTearOff_h
116