Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGMarkerElement.h
1 /*
2  * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@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 SVGMarkerElement_h
22 #define SVGMarkerElement_h
23
24 #include "bindings/v8/ExceptionState.h"
25 #include "core/svg/SVGAnimatedAngle.h"
26 #include "core/svg/SVGAnimatedBoolean.h"
27 #include "core/svg/SVGAnimatedEnumeration.h"
28 #include "core/svg/SVGAnimatedLength.h"
29 #include "core/svg/SVGAnimatedPreserveAspectRatio.h"
30 #include "core/svg/SVGAnimatedRect.h"
31 #include "core/svg/SVGElement.h"
32 #include "core/svg/SVGFitToViewBox.h"
33
34 namespace WebCore {
35
36 enum SVGMarkerUnitsType {
37     SVGMarkerUnitsUnknown = 0,
38     SVGMarkerUnitsUserSpaceOnUse,
39     SVGMarkerUnitsStrokeWidth
40 };
41
42 enum SVGMarkerOrientType {
43     SVGMarkerOrientUnknown = 0,
44     SVGMarkerOrientAuto,
45     SVGMarkerOrientAngle
46 };
47
48 template<>
49 struct SVGPropertyTraits<SVGMarkerUnitsType> {
50     static unsigned highestEnumValue() { return SVGMarkerUnitsStrokeWidth; }
51
52     static String toString(SVGMarkerUnitsType type)
53     {
54         switch (type) {
55         case SVGMarkerUnitsUnknown:
56             return emptyString();
57         case SVGMarkerUnitsUserSpaceOnUse:
58             return "userSpaceOnUse";
59         case SVGMarkerUnitsStrokeWidth:
60             return "strokeWidth";
61         }
62
63         ASSERT_NOT_REACHED();
64         return emptyString();
65     }
66
67     static SVGMarkerUnitsType fromString(const String& value)
68     {
69         if (value == "userSpaceOnUse")
70             return SVGMarkerUnitsUserSpaceOnUse;
71         if (value == "strokeWidth")
72             return SVGMarkerUnitsStrokeWidth;
73         return SVGMarkerUnitsUnknown;
74     }
75 };
76
77 template<>
78 struct SVGPropertyTraits<SVGMarkerOrientType> {
79     static unsigned highestEnumValue() { return SVGMarkerOrientAngle; }
80
81     // toString is not needed, synchronizeOrientType() handles this on its own.
82
83     static SVGMarkerOrientType fromString(const String& value, SVGAngle& angle)
84     {
85         if (value == "auto")
86             return SVGMarkerOrientAuto;
87
88         TrackExceptionState exceptionState;
89         angle.setValueAsString(value, exceptionState);
90         if (!exceptionState.hadException())
91             return SVGMarkerOrientAngle;
92         return SVGMarkerOrientUnknown;
93     }
94 };
95
96 class SVGMarkerElement FINAL : public SVGElement,
97                                public SVGFitToViewBox {
98 public:
99     // Forward declare enumerations in the W3C naming scheme, for IDL generation.
100     enum {
101         SVG_MARKERUNITS_UNKNOWN = SVGMarkerUnitsUnknown,
102         SVG_MARKERUNITS_USERSPACEONUSE = SVGMarkerUnitsUserSpaceOnUse,
103         SVG_MARKERUNITS_STROKEWIDTH = SVGMarkerUnitsStrokeWidth
104     };
105
106     enum {
107         SVG_MARKER_ORIENT_UNKNOWN = SVGMarkerOrientUnknown,
108         SVG_MARKER_ORIENT_AUTO = SVGMarkerOrientAuto,
109         SVG_MARKER_ORIENT_ANGLE = SVGMarkerOrientAngle
110     };
111
112     static PassRefPtr<SVGMarkerElement> create(Document&);
113
114     AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const;
115
116     void setOrientToAuto();
117     void setOrientToAngle(const SVGAngle&);
118
119     static const SVGPropertyInfo* orientTypePropertyInfo();
120
121     SVGAnimatedLength* refX() const { return m_refX.get(); }
122     SVGAnimatedLength* refY() const { return m_refY.get(); }
123     SVGAnimatedLength* markerWidth() const { return m_markerWidth.get(); }
124     SVGAnimatedLength* markerHeight() const { return m_markerHeight.get(); }
125     SVGAnimatedRect* viewBox() const { return m_viewBox.get(); }
126
127     // Custom 'orientType' property.
128     static void synchronizeOrientType(SVGElement* contextElement);
129     static PassRefPtr<SVGAnimatedProperty> lookupOrCreateOrientTypeWrapper(SVGElement* contextElement);
130     SVGMarkerOrientType& orientTypeCurrentValue() const { return m_orientType.value; }
131     SVGMarkerOrientType& orientTypeBaseValue() const { return m_orientType.value; }
132     void setOrientTypeBaseValue(const SVGMarkerOrientType& type) { m_orientType.value = type; }
133     PassRefPtr<SVGAnimatedEnumerationPropertyTearOff<SVGMarkerOrientType> > orientType();
134     SVGAnimatedPreserveAspectRatio* preserveAspectRatio() { return m_preserveAspectRatio.get(); }
135
136 private:
137     explicit SVGMarkerElement(Document&);
138
139     virtual bool needsPendingResourceHandling() const OVERRIDE { return false; }
140
141     bool isSupportedAttribute(const QualifiedName&);
142     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
143     virtual void svgAttributeChanged(const QualifiedName&) OVERRIDE;
144     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0) OVERRIDE;
145
146     virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
147     virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE { return true; }
148
149     virtual bool selfHasRelativeLengths() const OVERRIDE;
150
151     void synchronizeOrientType();
152
153     static const AtomicString& orientTypeIdentifier();
154     static const AtomicString& orientAngleIdentifier();
155
156     RefPtr<SVGAnimatedLength> m_refX;
157     RefPtr<SVGAnimatedLength> m_refY;
158     RefPtr<SVGAnimatedLength> m_markerWidth;
159     RefPtr<SVGAnimatedLength> m_markerHeight;
160     RefPtr<SVGAnimatedRect> m_viewBox;
161     RefPtr<SVGAnimatedPreserveAspectRatio> m_preserveAspectRatio;
162     mutable SVGSynchronizableAnimatedProperty<SVGMarkerOrientType> m_orientType;
163     BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGMarkerElement)
164         DECLARE_ANIMATED_ENUMERATION(MarkerUnits, markerUnits, SVGMarkerUnitsType)
165         DECLARE_ANIMATED_ANGLE(OrientAngle, orientAngle)
166     END_DECLARE_ANIMATED_PROPERTIES
167 };
168
169 DEFINE_NODE_TYPE_CASTS(SVGMarkerElement, hasTagName(SVGNames::markerTag));
170
171 }
172
173 #endif