• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "SVGNames.h"
24 #include "core/svg/SVGTextContentElement.h"
25 #include "core/svg/SVGURIReference.h"
26 
27 namespace WebCore {
28 
29 enum SVGTextPathMethodType {
30     SVGTextPathMethodUnknown = 0,
31     SVGTextPathMethodAlign,
32     SVGTextPathMethodStretch
33 };
34 
35 enum SVGTextPathSpacingType {
36     SVGTextPathSpacingUnknown = 0,
37     SVGTextPathSpacingAuto,
38     SVGTextPathSpacingExact
39 };
40 
41 template<>
42 struct SVGPropertyTraits<SVGTextPathMethodType> {
43     static unsigned highestEnumValue() { return SVGTextPathMethodStretch; }
44 
45     static String toString(SVGTextPathMethodType type)
46     {
47         switch (type) {
48         case SVGTextPathMethodUnknown:
49             return emptyString();
50         case SVGTextPathMethodAlign:
51             return "align";
52         case SVGTextPathMethodStretch:
53             return "stretch";
54         }
55 
56         ASSERT_NOT_REACHED();
57         return emptyString();
58     }
59 
60     static SVGTextPathMethodType fromString(const String& value)
61     {
62         if (value == "align")
63             return SVGTextPathMethodAlign;
64         if (value == "stretch")
65             return SVGTextPathMethodStretch;
66         return SVGTextPathMethodUnknown;
67     }
68 };
69 
70 template<>
71 struct SVGPropertyTraits<SVGTextPathSpacingType> {
72     static unsigned highestEnumValue() { return SVGTextPathSpacingExact; }
73 
74     static String toString(SVGTextPathSpacingType type)
75     {
76         switch (type) {
77         case SVGTextPathSpacingUnknown:
78             return emptyString();
79         case SVGTextPathSpacingAuto:
80             return "auto";
81         case SVGTextPathSpacingExact:
82             return "exact";
83         }
84 
85         ASSERT_NOT_REACHED();
86         return emptyString();
87     }
88 
89     static SVGTextPathSpacingType fromString(const String& value)
90     {
91         if (value == "auto")
92             return SVGTextPathSpacingAuto;
93         if (value == "exact")
94             return SVGTextPathSpacingExact;
95         return SVGTextPathSpacingUnknown;
96     }
97 };
98 
99 class SVGTextPathElement FINAL : public SVGTextContentElement,
100                                  public SVGURIReference {
101 public:
102     // Forward declare enumerations in the W3C naming scheme, for IDL generation.
103     enum {
104         TEXTPATH_METHODTYPE_UNKNOWN = SVGTextPathMethodUnknown,
105         TEXTPATH_METHODTYPE_ALIGN = SVGTextPathMethodAlign,
106         TEXTPATH_METHODTYPE_STRETCH = SVGTextPathMethodStretch,
107         TEXTPATH_SPACINGTYPE_UNKNOWN = SVGTextPathSpacingUnknown,
108         TEXTPATH_SPACINGTYPE_AUTO = SVGTextPathSpacingAuto,
109         TEXTPATH_SPACINGTYPE_EXACT = SVGTextPathSpacingExact
110     };
111 
112     static PassRefPtr<SVGTextPathElement> create(Document&);
113 
114 private:
115     explicit SVGTextPathElement(Document&);
116 
117     virtual ~SVGTextPathElement();
118 
119     void clearResourceReferences();
120 
121     virtual void buildPendingResource();
122     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
123     virtual void removedFrom(ContainerNode*) OVERRIDE;
124 
125     bool isSupportedAttribute(const QualifiedName&);
126     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
127     virtual void svgAttributeChanged(const QualifiedName&);
128 
129     virtual RenderObject* createRenderer(RenderStyle*);
130     virtual bool childShouldCreateRenderer(const Node& child) const;
131     virtual bool rendererIsNeeded(const RenderStyle&);
132 
133     virtual bool selfHasRelativeLengths() const;
134 
135     BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGTextPathElement)
136         DECLARE_ANIMATED_LENGTH(StartOffset, startOffset)
137         DECLARE_ANIMATED_ENUMERATION(Method, method, SVGTextPathMethodType)
138         DECLARE_ANIMATED_ENUMERATION(Spacing, spacing, SVGTextPathSpacingType)
139         DECLARE_ANIMATED_STRING(Href, href)
140     END_DECLARE_ANIMATED_PROPERTIES
141 };
142 
143 DEFINE_NODE_TYPE_CASTS(SVGTextPathElement, hasTagName(SVGNames::textPathTag));
144 
145 } // namespace WebCore
146 
147 #endif
148