2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
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.
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.
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.
21 #ifndef SVGMarkerElement_h
22 #define SVGMarkerElement_h
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"
36 enum SVGMarkerUnitsType {
37 SVGMarkerUnitsUnknown = 0,
38 SVGMarkerUnitsUserSpaceOnUse,
39 SVGMarkerUnitsStrokeWidth
42 enum SVGMarkerOrientType {
43 SVGMarkerOrientUnknown = 0,
49 struct SVGPropertyTraits<SVGMarkerUnitsType> {
50 static unsigned highestEnumValue() { return SVGMarkerUnitsStrokeWidth; }
52 static String toString(SVGMarkerUnitsType type)
55 case SVGMarkerUnitsUnknown:
57 case SVGMarkerUnitsUserSpaceOnUse:
58 return "userSpaceOnUse";
59 case SVGMarkerUnitsStrokeWidth:
67 static SVGMarkerUnitsType fromString(const String& value)
69 if (value == "userSpaceOnUse")
70 return SVGMarkerUnitsUserSpaceOnUse;
71 if (value == "strokeWidth")
72 return SVGMarkerUnitsStrokeWidth;
73 return SVGMarkerUnitsUnknown;
78 struct SVGPropertyTraits<SVGMarkerOrientType> {
79 static unsigned highestEnumValue() { return SVGMarkerOrientAngle; }
81 // toString is not needed, synchronizeOrientType() handles this on its own.
83 static SVGMarkerOrientType fromString(const String& value, SVGAngle& angle)
86 return SVGMarkerOrientAuto;
88 TrackExceptionState exceptionState;
89 angle.setValueAsString(value, exceptionState);
90 if (!exceptionState.hadException())
91 return SVGMarkerOrientAngle;
92 return SVGMarkerOrientUnknown;
96 class SVGMarkerElement FINAL : public SVGElement,
97 public SVGFitToViewBox {
99 // Forward declare enumerations in the W3C naming scheme, for IDL generation.
101 SVG_MARKERUNITS_UNKNOWN = SVGMarkerUnitsUnknown,
102 SVG_MARKERUNITS_USERSPACEONUSE = SVGMarkerUnitsUserSpaceOnUse,
103 SVG_MARKERUNITS_STROKEWIDTH = SVGMarkerUnitsStrokeWidth
107 SVG_MARKER_ORIENT_UNKNOWN = SVGMarkerOrientUnknown,
108 SVG_MARKER_ORIENT_AUTO = SVGMarkerOrientAuto,
109 SVG_MARKER_ORIENT_ANGLE = SVGMarkerOrientAngle
112 static PassRefPtr<SVGMarkerElement> create(Document&);
114 AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const;
116 void setOrientToAuto();
117 void setOrientToAngle(const SVGAngle&);
119 static const SVGPropertyInfo* orientTypePropertyInfo();
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(); }
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(); }
137 explicit SVGMarkerElement(Document&);
139 virtual bool needsPendingResourceHandling() const OVERRIDE { return false; }
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;
146 virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
147 virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE { return true; }
149 virtual bool selfHasRelativeLengths() const OVERRIDE;
151 void synchronizeOrientType();
153 static const AtomicString& orientTypeIdentifier();
154 static const AtomicString& orientAngleIdentifier();
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
169 DEFINE_NODE_TYPE_CASTS(SVGMarkerElement, hasTagName(SVGNames::markerTag));