summaryrefslogtreecommitdiffstats
path: root/WebCore/svg/SVGAnimatedPropertyTraits.h
blob: 5cc69a9891784b8eab3882fa9abdab2b8c6a43f1 (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
/*
 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
 *
 * 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 SVGAnimatedPropertyTraits_h
#define SVGAnimatedPropertyTraits_h

#if ENABLE(SVG)
#include "FloatRect.h"
#include "PlatformString.h"
#include "SVGAngle.h"
#include "SVGLength.h"
#include "SVGLengthList.h"
#include "SVGNumberList.h"
#include "SVGPreserveAspectRatio.h"
#include "SVGTransformList.h"

namespace WebCore {

template<typename Type>
struct SVGAnimatedPropertyTraits : public Noncopyable { };

// SVGAnimatedAngle
template<>
struct SVGAnimatedPropertyTraits<SVGAngle> : public Noncopyable {
    typedef const SVGAngle& PassType;
    typedef SVGAngle ReturnType;
    typedef SVGAngle StoredType;

    static ReturnType null() { return SVGAngle(); }
    static ReturnType toReturnType(const StoredType& type) { return type; }
    static String toString(PassType type) { return type.valueAsString(); }
};

// SVGAnimatedBoolean
template<>
struct SVGAnimatedPropertyTraits<bool> : public Noncopyable {
    typedef const bool& PassType;
    typedef bool ReturnType;
    typedef bool StoredType;

    static ReturnType null() { return false; }
    static ReturnType toReturnType(const StoredType& type) { return type; }
    static String toString(PassType type) { return type ? "true" : "false"; }
};

// SVGAnimatedEnumeration
template<>
struct SVGAnimatedPropertyTraits<int> : public Noncopyable {
    typedef const int& PassType;
    typedef int ReturnType;
    typedef int StoredType;

    static ReturnType null() { return 0; }
    static ReturnType toReturnType(const StoredType& type) { return type; }
    static String toString(PassType type) { return String::number(type); }
};

// SVGAnimatedInteger
template<>
struct SVGAnimatedPropertyTraits<long> : public Noncopyable {
    typedef const long& PassType;
    typedef long ReturnType;
    typedef long StoredType;

    static ReturnType null() { return 0l; }
    static ReturnType toReturnType(const StoredType& type) { return type; }
    static String toString(PassType type) { return String::number(type); }
};

// SVGAnimatedLength
template<>
struct SVGAnimatedPropertyTraits<SVGLength> : public Noncopyable {
    typedef const SVGLength& PassType;
    typedef SVGLength ReturnType;
    typedef SVGLength StoredType;

    static ReturnType null() { return SVGLength(); }
    static ReturnType toReturnType(const StoredType& type) { return type; }
    static String toString(PassType type) { return type.valueAsString(); }
};

// SVGAnimatedLengthList
template<>
struct SVGAnimatedPropertyTraits<SVGLengthList*> : public Noncopyable {
    typedef SVGLengthList* PassType;
    typedef SVGLengthList* ReturnType;
    typedef RefPtr<SVGLengthList> StoredType;

    static ReturnType null() { return 0; }
    static ReturnType toReturnType(const StoredType& type) { return type.get(); }
    static String toString(PassType type) { return type ? type->valueAsString() : String(); }
};

// SVGAnimatedNumber
template<>
struct SVGAnimatedPropertyTraits<float> : public Noncopyable {
    typedef const float& PassType;
    typedef float ReturnType;
    typedef float StoredType;

    static ReturnType null() { return 0.0f; }
    static ReturnType toReturnType(const StoredType& type) { return type; }
    static String toString(PassType type) { return String::number(type); }
};

// SVGAnimatedNumberList
template<>
struct SVGAnimatedPropertyTraits<SVGNumberList*> : public Noncopyable {
    typedef SVGNumberList* PassType;
    typedef SVGNumberList* ReturnType;
    typedef RefPtr<SVGNumberList> StoredType;

    static ReturnType null() { return 0; }
    static ReturnType toReturnType(const StoredType& type) { return type.get(); }
    static String toString(PassType type) { return type ? type->valueAsString() : String(); }
};

// SVGAnimatedPreserveAspectRatio
template<>
struct SVGAnimatedPropertyTraits<SVGPreserveAspectRatio> : public Noncopyable {
    typedef const SVGPreserveAspectRatio& PassType;
    typedef SVGPreserveAspectRatio ReturnType;
    typedef SVGPreserveAspectRatio StoredType;

    static ReturnType null() { return SVGPreserveAspectRatio(); }
    static ReturnType toReturnType(const StoredType& type) { return type; }
    static String toString(PassType type) { return type.valueAsString(); }
};

// SVGAnimatedRect
template<>
struct SVGAnimatedPropertyTraits<FloatRect> : public Noncopyable {
    typedef const FloatRect& PassType;
    typedef FloatRect ReturnType;
    typedef FloatRect StoredType;

    static ReturnType null() { return FloatRect(); }
    static ReturnType toReturnType(const StoredType& type) { return type; }
    static String toString(PassType type) { return String::format("%f %f %f %f", type.x(), type.y(), type.width(), type.height()); }
};

// SVGAnimatedString
template<>
struct SVGAnimatedPropertyTraits<String> : public Noncopyable {
    typedef const String& PassType;
    typedef String ReturnType;
    typedef String StoredType;

    static ReturnType null() { return String(); }
    static ReturnType toReturnType(const StoredType& type) { return type; }
    static String toString(PassType type) { return type; }
};

// SVGAnimatedTransformList
template<>
struct SVGAnimatedPropertyTraits<SVGTransformList*> : public Noncopyable {
    typedef SVGTransformList* PassType;
    typedef SVGTransformList* ReturnType;
    typedef RefPtr<SVGTransformList> StoredType;

    static ReturnType null() { return 0; }
    static ReturnType toReturnType(const StoredType& type) { return type.get(); }
    static String toString(PassType type) { return type ? type->valueAsString() : String(); }
};

}

#endif
#endif