1/*
2    Copyright (C) Research In Motion Limited 2010. All rights reserved.
3    Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
4
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public
7    License as published by the Free Software Foundation; either
8    version 2 of the License, or (at your option) any later version.
9
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Library General Public License for more details.
14
15    You should have received a copy of the GNU Library General Public License
16    along with this library; see the file COPYING.LIB.  If not, write to
17    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18    Boston, MA 02110-1301, USA.
19*/
20
21#ifndef SVGAnimatedPropertyTraits_h
22#define SVGAnimatedPropertyTraits_h
23
24#if ENABLE(SVG)
25#include "FloatRect.h"
26#include "PlatformString.h"
27#include "SVGAngle.h"
28#include "SVGLength.h"
29#include "SVGLengthList.h"
30#include "SVGNumberList.h"
31#include "SVGPreserveAspectRatio.h"
32#include "SVGTransformList.h"
33
34namespace WebCore {
35
36template<typename Type>
37struct SVGAnimatedPropertyTraits : public Noncopyable { };
38
39// SVGAnimatedAngle
40template<>
41struct SVGAnimatedPropertyTraits<SVGAngle> : public Noncopyable {
42    typedef const SVGAngle& PassType;
43    typedef SVGAngle ReturnType;
44    typedef SVGAngle StoredType;
45
46    static ReturnType null() { return SVGAngle(); }
47    static ReturnType toReturnType(const StoredType& type) { return type; }
48    static String toString(PassType type) { return type.valueAsString(); }
49};
50
51// SVGAnimatedBoolean
52template<>
53struct SVGAnimatedPropertyTraits<bool> : public Noncopyable {
54    typedef const bool& PassType;
55    typedef bool ReturnType;
56    typedef bool StoredType;
57
58    static ReturnType null() { return false; }
59    static ReturnType toReturnType(const StoredType& type) { return type; }
60    static String toString(PassType type) { return type ? "true" : "false"; }
61};
62
63// SVGAnimatedEnumeration
64template<>
65struct SVGAnimatedPropertyTraits<int> : public Noncopyable {
66    typedef const int& PassType;
67    typedef int ReturnType;
68    typedef int StoredType;
69
70    static ReturnType null() { return 0; }
71    static ReturnType toReturnType(const StoredType& type) { return type; }
72    static String toString(PassType type) { return String::number(type); }
73};
74
75// SVGAnimatedInteger
76template<>
77struct SVGAnimatedPropertyTraits<long> : public Noncopyable {
78    typedef const long& PassType;
79    typedef long ReturnType;
80    typedef long StoredType;
81
82    static ReturnType null() { return 0l; }
83    static ReturnType toReturnType(const StoredType& type) { return type; }
84    static String toString(PassType type) { return String::number(type); }
85};
86
87// SVGAnimatedLength
88template<>
89struct SVGAnimatedPropertyTraits<SVGLength> : public Noncopyable {
90    typedef const SVGLength& PassType;
91    typedef SVGLength ReturnType;
92    typedef SVGLength StoredType;
93
94    static ReturnType null() { return SVGLength(); }
95    static ReturnType toReturnType(const StoredType& type) { return type; }
96    static String toString(PassType type) { return type.valueAsString(); }
97};
98
99// SVGAnimatedLengthList
100template<>
101struct SVGAnimatedPropertyTraits<SVGLengthList*> : public Noncopyable {
102    typedef SVGLengthList* PassType;
103    typedef SVGLengthList* ReturnType;
104    typedef RefPtr<SVGLengthList> StoredType;
105
106    static ReturnType null() { return 0; }
107    static ReturnType toReturnType(const StoredType& type) { return type.get(); }
108    static String toString(PassType type) { return type ? type->valueAsString() : String(); }
109};
110
111// SVGAnimatedNumber
112template<>
113struct SVGAnimatedPropertyTraits<float> : public Noncopyable {
114    typedef const float& PassType;
115    typedef float ReturnType;
116    typedef float StoredType;
117
118    static ReturnType null() { return 0.0f; }
119    static ReturnType toReturnType(const StoredType& type) { return type; }
120    static String toString(PassType type) { return String::number(type); }
121};
122
123// SVGAnimatedNumberList
124template<>
125struct SVGAnimatedPropertyTraits<SVGNumberList*> : public Noncopyable {
126    typedef SVGNumberList* PassType;
127    typedef SVGNumberList* ReturnType;
128    typedef RefPtr<SVGNumberList> StoredType;
129
130    static ReturnType null() { return 0; }
131    static ReturnType toReturnType(const StoredType& type) { return type.get(); }
132    static String toString(PassType type) { return type ? type->valueAsString() : String(); }
133};
134
135// SVGAnimatedPreserveAspectRatio
136template<>
137struct SVGAnimatedPropertyTraits<SVGPreserveAspectRatio> : public Noncopyable {
138    typedef const SVGPreserveAspectRatio& PassType;
139    typedef SVGPreserveAspectRatio ReturnType;
140    typedef SVGPreserveAspectRatio StoredType;
141
142    static ReturnType null() { return SVGPreserveAspectRatio(); }
143    static ReturnType toReturnType(const StoredType& type) { return type; }
144    static String toString(PassType type) { return type.valueAsString(); }
145};
146
147// SVGAnimatedRect
148template<>
149struct SVGAnimatedPropertyTraits<FloatRect> : public Noncopyable {
150    typedef const FloatRect& PassType;
151    typedef FloatRect ReturnType;
152    typedef FloatRect StoredType;
153
154    static ReturnType null() { return FloatRect(); }
155    static ReturnType toReturnType(const StoredType& type) { return type; }
156    static String toString(PassType type) { return String::format("%f %f %f %f", type.x(), type.y(), type.width(), type.height()); }
157};
158
159// SVGAnimatedString
160template<>
161struct SVGAnimatedPropertyTraits<String> : public Noncopyable {
162    typedef const String& PassType;
163    typedef String ReturnType;
164    typedef String StoredType;
165
166    static ReturnType null() { return String(); }
167    static ReturnType toReturnType(const StoredType& type) { return type; }
168    static String toString(PassType type) { return type; }
169};
170
171// SVGAnimatedTransformList
172template<>
173struct SVGAnimatedPropertyTraits<SVGTransformList*> : public Noncopyable {
174    typedef SVGTransformList* PassType;
175    typedef SVGTransformList* ReturnType;
176    typedef RefPtr<SVGTransformList> StoredType;
177
178    static ReturnType null() { return 0; }
179    static ReturnType toReturnType(const StoredType& type) { return type.get(); }
180    static String toString(PassType type) { return type ? type->valueAsString() : String(); }
181};
182
183}
184
185#endif
186#endif
187