initial import
[vuplus_webkit] / Source / WebCore / svg / SVGTextPathElement.h
1 /*
2  * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
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 SVGTextPathElement_h
21 #define SVGTextPathElement_h
22
23 #if ENABLE(SVG)
24 #include "SVGTextContentElement.h"
25
26 #include "SVGURIReference.h"
27
28 namespace WebCore {
29
30 enum SVGTextPathMethodType {
31     SVGTextPathMethodUnknown = 0,
32     SVGTextPathMethodAlign,
33     SVGTextPathMethodStretch
34 };
35
36 enum SVGTextPathSpacingType {
37     SVGTextPathSpacingUnknown = 0,
38     SVGTextPathSpacingAuto,
39     SVGTextPathSpacingExact
40 };
41
42 template<>
43 struct SVGPropertyTraits<SVGTextPathMethodType> {
44     static SVGTextPathMethodType highestEnumValue() { return SVGTextPathMethodStretch; }
45
46     static String toString(SVGTextPathMethodType type)
47     {
48         switch (type) {
49         case SVGTextPathMethodUnknown:
50             return emptyString();
51         case SVGTextPathMethodAlign:
52             return "align";
53         case SVGTextPathMethodStretch:
54             return "stretch";
55         }
56     
57         ASSERT_NOT_REACHED();
58         return emptyString();
59     }
60
61     static SVGTextPathMethodType fromString(const String& value)
62     {
63         if (value == "align")
64             return SVGTextPathMethodAlign;
65         if (value == "stretch")
66             return SVGTextPathMethodStretch;
67         return SVGTextPathMethodUnknown;
68     }
69 };
70
71 template<>
72 struct SVGPropertyTraits<SVGTextPathSpacingType> {
73     static SVGTextPathSpacingType highestEnumValue() { return SVGTextPathSpacingExact; }
74
75     static String toString(SVGTextPathSpacingType type)
76     {
77         switch (type) {
78         case SVGTextPathSpacingUnknown:
79             return emptyString();
80         case SVGTextPathSpacingAuto:
81             return "auto";
82         case SVGTextPathSpacingExact:
83             return "exact";
84         }
85
86         ASSERT_NOT_REACHED();
87         return emptyString();
88     }
89
90     static SVGTextPathSpacingType fromString(const String& value)
91     {
92         if (value == "auto")
93             return SVGTextPathSpacingAuto;
94         if (value == "exact")
95             return SVGTextPathSpacingExact;
96         return SVGTextPathSpacingUnknown;
97     }
98 };
99
100 class SVGTextPathElement : public SVGTextContentElement,
101                            public SVGURIReference {
102 public:
103     // Forward declare enumerations in the W3C naming scheme, for IDL generation.
104     enum {
105         TEXTPATH_METHODTYPE_UNKNOWN = SVGTextPathMethodUnknown,
106         TEXTPATH_METHODTYPE_ALIGN = SVGTextPathMethodAlign,
107         TEXTPATH_METHODTYPE_STRETCH = SVGTextPathMethodStretch,
108         TEXTPATH_SPACINGTYPE_UNKNOWN = SVGTextPathSpacingUnknown,
109         TEXTPATH_SPACINGTYPE_AUTO = SVGTextPathSpacingAuto,
110         TEXTPATH_SPACINGTYPE_EXACT = SVGTextPathSpacingExact
111     };
112
113     static PassRefPtr<SVGTextPathElement> create(const QualifiedName&, Document*);
114  
115 private:
116     SVGTextPathElement(const QualifiedName&, Document*);
117
118     virtual void insertedIntoDocument();
119
120     bool isSupportedAttribute(const QualifiedName&);
121     virtual void parseMappedAttribute(Attribute*);
122     virtual void svgAttributeChanged(const QualifiedName&);
123
124     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
125     virtual bool childShouldCreateRenderer(Node*) const;
126     virtual bool rendererIsNeeded(const NodeRenderingContext&);
127
128     virtual bool selfHasRelativeLengths() const;
129  
130     BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGTextPathElement)
131         DECLARE_ANIMATED_LENGTH(StartOffset, startOffset)
132         DECLARE_ANIMATED_ENUMERATION(Method, method, SVGTextPathMethodType)
133         DECLARE_ANIMATED_ENUMERATION(Spacing, spacing, SVGTextPathSpacingType)
134         DECLARE_ANIMATED_STRING(Href, href)
135     END_DECLARE_ANIMATED_PROPERTIES
136 };
137
138 } // namespace WebCore
139
140 #endif // ENABLE(SVG)
141 #endif