OSDN Git Service

Merge Webkit at r70949: Initial merge by git.
[android-x86/external-webkit.git] / WebCore / svg / properties / SVGPropertyTraits.h
1 /*
2  * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
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 SVGPropertyTraits_h
22 #define SVGPropertyTraits_h
23
24 #if ENABLE(SVG)
25 #include "FloatRect.h"
26 #include "SVGAngle.h"
27 #include "SVGLength.h"
28 #include "SVGLengthList.h"
29 #include "SVGPreserveAspectRatio.h"
30 #include <wtf/text/StringBuilder.h>
31
32 namespace WebCore {
33
34 template<typename PropertyType>
35 struct SVGPropertyTraits { };
36
37 template<>
38 struct SVGPropertyTraits<SVGAngle> {
39     static SVGAngle initialValue() { return SVGAngle(); }
40     static String toString(const SVGAngle& type) { return type.valueAsString(); }
41 };
42
43 template<>
44 struct SVGPropertyTraits<bool> {
45     static bool initialValue() { return false; }
46     static String toString(bool type) { return type ? "true" : "false"; }
47 };
48
49 template<>
50 struct SVGPropertyTraits<int> {
51     static int initialValue() { return 0; }
52     static String toString(int type) { return String::number(type); }
53 };
54
55 template<>
56 struct SVGPropertyTraits<long> {
57     static long initialValue() { return 0; }
58     static String toString(long type) { return String::number(type); }
59 };
60
61 template<>
62 struct SVGPropertyTraits<SVGLength> {
63     static SVGLength initialValue() { return SVGLength(); }
64     static String toString(const SVGLength& type) { return type.valueAsString(); }
65 };
66
67 template<>
68 struct SVGPropertyTraits<SVGLengthList> {
69     typedef SVGLength ListItemType;
70
71     static SVGLengthList initialValue() { return SVGLengthList(); }
72     static String toString(const SVGLengthList& type) { return type.valueAsString(); }
73 };
74
75 template<>
76 struct SVGPropertyTraits<float> {
77     static float initialValue() { return 0; }
78     static String toString(float type) { return String::number(type); }
79 };
80
81 template<>
82 struct SVGPropertyTraits<SVGPreserveAspectRatio> {
83     static SVGPreserveAspectRatio initialValue() { return SVGPreserveAspectRatio(); }
84     static String toString(const SVGPreserveAspectRatio& type) { return type.valueAsString(); }
85 };
86
87 template<>
88 struct SVGPropertyTraits<FloatRect> {
89     static FloatRect initialValue() { return FloatRect(); }
90     static String toString(const FloatRect& type)
91     {
92         StringBuilder builder;
93         builder.append(String::number(type.x()));
94         builder.append(' ');
95         builder.append(String::number(type.y()));
96         builder.append(' ');
97         builder.append(String::number(type.width()));
98         builder.append(' ');
99         builder.append(String::number(type.height()));
100         builder.append(' ');
101         return builder.toString();
102     }
103 };
104
105 template<>
106 struct SVGPropertyTraits<String> {
107     static String initialValue() { return String(); }
108     static String toString(const String& type) { return type; }
109 };
110
111 }
112
113 #endif
114 #endif