summaryrefslogtreecommitdiffstats
path: root/WebCore/svg/DeprecatedSVGAnimatedProperty.h
blob: e2f2af728cfffed1a1a024cd62b9737c85e1be46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef DeprecatedSVGAnimatedProperty_h
#define DeprecatedSVGAnimatedProperty_h

#if ENABLE(SVG)
#include "SVGAnimatedPropertySynchronizer.h"
#include "DeprecatedSVGAnimatedPropertyTraits.h"
#include "DeprecatedSVGAnimatedTemplate.h"

namespace WebCore {

template<typename AnimatedType>
class DeprecatedSVGAnimatedProperty;

template<typename AnimatedType>
class DeprecatedSVGAnimatedPropertyTearOff : public DeprecatedSVGAnimatedTemplate<AnimatedType> {
public:
    typedef typename DeprecatedSVGAnimatedPropertyTraits<AnimatedType>::PassType PassType;
    typedef typename DeprecatedSVGAnimatedPropertyTraits<AnimatedType>::ReturnType ReturnType;

    typedef DeprecatedSVGAnimatedPropertyTearOff<AnimatedType> Self;
    typedef DeprecatedSVGAnimatedProperty<AnimatedType> Creator;

    static PassRefPtr<Self> create(Creator& creator, SVGElement* contextElement)
    {
        return adoptRef(new Self(creator, contextElement));
    }

    virtual void setBaseVal(PassType type)
    {
        m_creator.setBaseValue(type);
        m_contextElement->invalidateSVGAttributes();
    }

    virtual void setAnimVal(PassType type)
    {
        m_creator.setValue(type);
        m_contextElement->invalidateSVGAttributes();
    }

    virtual ReturnType baseVal() const { return m_creator.baseValue(); }
    virtual ReturnType animVal() const { return m_creator.value(); }
    virtual const QualifiedName& associatedAttributeName() const { return m_creator.associatedAttributeName(); }

private:
    DeprecatedSVGAnimatedPropertyTearOff(Creator& creator, SVGElement* contextElement)
        : m_creator(creator)
        , m_contextElement(contextElement)
    {
        m_creator.setShouldSynchronize(true);
    }

    virtual ~DeprecatedSVGAnimatedPropertyTearOff()
    {
        m_creator.setShouldSynchronize(false);
    }

    Creator& m_creator;
    RefPtr<SVGElement> m_contextElement;
};

template<typename AnimatedType>
class DeprecatedSVGAnimatedProperty {
public:
    virtual ~DeprecatedSVGAnimatedProperty() { }

    typedef typename DeprecatedSVGAnimatedPropertyTraits<AnimatedType>::PassType PassType;
    typedef typename DeprecatedSVGAnimatedPropertyTraits<AnimatedType>::ReturnType ReturnType;
    typedef typename DeprecatedSVGAnimatedPropertyTraits<AnimatedType>::StoredType StoredType;

    DeprecatedSVGAnimatedProperty()
        : m_value(DeprecatedSVGAnimatedPropertyTraits<AnimatedType>::null())
        , m_shouldSynchronize(false)
    {
    }

    template<typename ConstructorParameterOne>
    DeprecatedSVGAnimatedProperty(const ConstructorParameterOne& value1)
        : m_value(value1)
        , m_shouldSynchronize(false)
    {
    }

    template<typename ConstructorParameterOne, typename ConstructorParameterTwo>
    DeprecatedSVGAnimatedProperty(const ConstructorParameterOne& value1, const ConstructorParameterTwo& value2)
        : m_value(value1, value2)
        , m_shouldSynchronize(false)
    {
    }

    ReturnType value() const { return DeprecatedSVGAnimatedPropertyTraits<AnimatedType>::toReturnType(m_value); }
    ReturnType baseValue() const { return DeprecatedSVGAnimatedPropertyTraits<AnimatedType>::toReturnType(m_value); }

    void setValue(PassType type) { m_value = type; }
    void setBaseValue(PassType type) { m_value = type; }

    bool shouldSynchronize() const { return m_shouldSynchronize; }
    void setShouldSynchronize(bool value) { m_shouldSynchronize = value; }

    virtual const QualifiedName& associatedAttributeName() const = 0;

protected:
    StoredType m_value;
    bool m_shouldSynchronize;
};

};

// Helper macro used within DECLARE_ANIMATED_PROPERTY below
#define DEFINE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, AnimatedType, UpperProperty) \
class DeprecatedSVGAnimatedProperty##UpperProperty : public DeprecatedSVGAnimatedProperty<AnimatedType> { \
public: \
    DeprecatedSVGAnimatedProperty##UpperProperty() \
        : DeprecatedSVGAnimatedProperty<AnimatedType>() \
    { \
    } \
    \
    template<typename ConstructorParameterOne> \
    DeprecatedSVGAnimatedProperty##UpperProperty(const ConstructorParameterOne& value1) \
        : DeprecatedSVGAnimatedProperty<AnimatedType>(value1) \
    { \
    } \
    \
    template<typename ConstructorParameterOne, typename ConstructorParameterTwo> \
    DeprecatedSVGAnimatedProperty##UpperProperty(const ConstructorParameterOne& value1, const ConstructorParameterTwo& value2) \
        : DeprecatedSVGAnimatedProperty<AnimatedType>(value1, value2) \
    { \
    } \
    \
    void synchronize(SVGElement* contextElement) \
    { \
        ASSERT(m_shouldSynchronize); \
        AtomicString value(DeprecatedSVGAnimatedPropertyTraits<AnimatedType>::toString(baseValue())); \
        SVGAnimatedPropertySynchronizer<IsDerivedFromSVGElement<OwnerType>::value>::synchronize(contextElement, DOMAttribute, value); \
    } \
    \
    virtual const QualifiedName& associatedAttributeName() const \
    { \
        return DOMAttribute; \
    } \
}

// Helper macro shared by DECLARE_ANIMATED_PROPERTY / DECLARE_ANIMATED_PROPERTY_MULTIPLE_WRAPPERS
#define DECLARE_ANIMATED_PROPERTY_SHARED(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, AnimatedType, UpperProperty, LowerProperty) \
private: \
    typedef DeprecatedSVGAnimatedPropertyTearOff<AnimatedType> DeprecatedSVGAnimatedPropertyTearOff##UpperProperty; \
    DEFINE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, AnimatedType, UpperProperty); \
    DeprecatedSVGAnimatedProperty##UpperProperty m_##LowerProperty; \
    \
public: \
    DeprecatedSVGAnimatedPropertyTraits<AnimatedType>::ReturnType LowerProperty() const \
    { \
        return m_##LowerProperty.value(); \
    } \
    \
    DeprecatedSVGAnimatedPropertyTraits<AnimatedType>::ReturnType LowerProperty##BaseValue() const \
    { \
        return m_##LowerProperty.baseValue(); \
    } \
    \
    void set##UpperProperty(DeprecatedSVGAnimatedPropertyTraits<AnimatedType>::PassType type) \
    { \
        m_##LowerProperty.setValue(type); \
        SVGElement* contextElement = GetOwnerElementForType<OwnerType, IsDerivedFromSVGElement<OwnerType>::value>::ownerElement(this); \
        contextElement->invalidateSVGAttributes(); \
    } \
    \
    void set##UpperProperty##BaseValue(DeprecatedSVGAnimatedPropertyTraits<AnimatedType>::PassType type) \
    { \
        m_##LowerProperty.setBaseValue(type); \
        SVGElement* contextElement = GetOwnerElementForType<OwnerType, IsDerivedFromSVGElement<OwnerType>::value>::ownerElement(this); \
        contextElement->invalidateSVGAttributes(); \
    } \
    \
    void synchronize##UpperProperty() \
    { \
        if (!m_##LowerProperty.shouldSynchronize()) \
            return; \
        SVGElement* contextElement = GetOwnerElementForType<OwnerType, IsDerivedFromSVGElement<OwnerType>::value>::ownerElement(this); \
        m_##LowerProperty.synchronize(contextElement); \
    } \
    \
    PassRefPtr<DeprecatedSVGAnimatedPropertyTearOff##UpperProperty> LowerProperty##Animated() \
    { \
        SVGElement* contextElement = GetOwnerElementForType<OwnerType, IsDerivedFromSVGElement<OwnerType>::value>::ownerElement(this); \
        return lookupOrCreateWrapper<AnimatedType, DeprecatedSVGAnimatedPropertyTearOff##UpperProperty>(contextElement, m_##LowerProperty, DOMAttribute); \
    }

// Used for SVG DOM properties that map exactly to one XML DOM attribute
#define DECLARE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, AnimatedType, UpperProperty, LowerProperty) \
DECLARE_ANIMATED_PROPERTY_SHARED(OwnerType, DOMAttribute, DOMAttribute.localName(), AnimatedType, UpperProperty, LowerProperty)

// Used for the rare case multiple SVG DOM properties that map to the same XML dom attribute
#define DECLARE_ANIMATED_PROPERTY_MULTIPLE_WRAPPERS(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, AnimatedType, UpperProperty, LowerProperty) \
DECLARE_ANIMATED_PROPERTY_SHARED(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, AnimatedType, UpperProperty, LowerProperty)

#endif
#endif