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 "SVGTextContentElement.h"
25#include "SVGURIReference.h"
26
27namespace WebCore {
28
29enum SVGTextPathMethodType {
30    SVGTextPathMethodUnknown = 0,
31    SVGTextPathMethodAlign,
32    SVGTextPathMethodStretch
33};
34
35enum SVGTextPathSpacingType {
36    SVGTextPathSpacingUnknown = 0,
37    SVGTextPathSpacingAuto,
38    SVGTextPathSpacingExact
39};
40
41template<>
42struct 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
70template<>
71struct 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
99class SVGTextPathElement final : public SVGTextContentElement,
100                                 public SVGURIReference {
101public:
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(const QualifiedName&, Document&);
113
114protected:
115    virtual void didNotifySubtreeInsertions(ContainerNode*) override;
116
117private:
118    SVGTextPathElement(const QualifiedName&, Document&);
119
120    virtual ~SVGTextPathElement();
121
122    void clearResourceReferences();
123
124    virtual void buildPendingResource() override;
125    virtual InsertionNotificationRequest insertedInto(ContainerNode&) override;
126    virtual void removedFrom(ContainerNode&) override;
127
128    bool isSupportedAttribute(const QualifiedName&);
129    virtual void parseAttribute(const QualifiedName&, const AtomicString&) override;
130    virtual void svgAttributeChanged(const QualifiedName&) override;
131
132    virtual RenderPtr<RenderElement> createElementRenderer(PassRef<RenderStyle>) override;
133    virtual bool childShouldCreateRenderer(const Node&) const override;
134    virtual bool rendererIsNeeded(const RenderStyle&) override;
135
136    virtual bool selfHasRelativeLengths() const override;
137
138    BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGTextPathElement)
139        DECLARE_ANIMATED_LENGTH(StartOffset, startOffset)
140        DECLARE_ANIMATED_ENUMERATION(Method, method, SVGTextPathMethodType)
141        DECLARE_ANIMATED_ENUMERATION(Spacing, spacing, SVGTextPathSpacingType)
142        DECLARE_ANIMATED_STRING(Href, href)
143    END_DECLARE_ANIMATED_PROPERTIES
144};
145
146NODE_TYPE_CASTS(SVGTextPathElement)
147
148} // namespace WebCore
149
150#endif
151