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/SVGExternalResourcesRequired.h"
33 #include "core/svg/SVGFitToViewBox.h"
37 enum SVGMarkerUnitsType {
38 SVGMarkerUnitsUnknown = 0,
39 SVGMarkerUnitsUserSpaceOnUse,
40 SVGMarkerUnitsStrokeWidth
43 enum SVGMarkerOrientType {
44 SVGMarkerOrientUnknown = 0,
50 struct SVGPropertyTraits<SVGMarkerUnitsType> {
51 static unsigned highestEnumValue() { return SVGMarkerUnitsStrokeWidth; }
53 static String toString(SVGMarkerUnitsType type)
56 case SVGMarkerUnitsUnknown:
58 case SVGMarkerUnitsUserSpaceOnUse:
59 return "userSpaceOnUse";
60 case SVGMarkerUnitsStrokeWidth:
68 static SVGMarkerUnitsType fromString(const String& value)
70 if (value == "userSpaceOnUse")
71 return SVGMarkerUnitsUserSpaceOnUse;
72 if (value == "strokeWidth")
73 return SVGMarkerUnitsStrokeWidth;
74 return SVGMarkerUnitsUnknown;
79 struct SVGPropertyTraits<SVGMarkerOrientType> {
80 static unsigned highestEnumValue() { return SVGMarkerOrientAngle; }
82 // toString is not needed, synchronizeOrientType() handles this on its own.
84 static SVGMarkerOrientType fromString(const String& value, SVGAngle& angle)
87 return SVGMarkerOrientAuto;
89 TrackExceptionState es;
90 angle.setValueAsString(value, es);
91 if (!es.hadException())
92 return SVGMarkerOrientAngle;
93 return SVGMarkerOrientUnknown;
97 class SVGMarkerElement FINAL : public SVGElement,
98 public SVGExternalResourcesRequired,
99 public SVGFitToViewBox {
101 // Forward declare enumerations in the W3C naming scheme, for IDL generation.
103 SVG_MARKERUNITS_UNKNOWN = SVGMarkerUnitsUnknown,
104 SVG_MARKERUNITS_USERSPACEONUSE = SVGMarkerUnitsUserSpaceOnUse,
105 SVG_MARKERUNITS_STROKEWIDTH = SVGMarkerUnitsStrokeWidth
109 SVG_MARKER_ORIENT_UNKNOWN = SVGMarkerOrientUnknown,
110 SVG_MARKER_ORIENT_AUTO = SVGMarkerOrientAuto,
111 SVG_MARKER_ORIENT_ANGLE = SVGMarkerOrientAngle
114 static PassRefPtr<SVGMarkerElement> create(const QualifiedName&, Document&);
116 AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const;
118 void setOrientToAuto();
119 void setOrientToAngle(const SVGAngle&);
121 static const SVGPropertyInfo* orientTypePropertyInfo();
124 SVGMarkerElement(const QualifiedName&, Document&);
126 virtual bool needsPendingResourceHandling() const { return false; }
128 bool isSupportedAttribute(const QualifiedName&);
129 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
130 virtual void svgAttributeChanged(const QualifiedName&);
131 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
133 virtual RenderObject* createRenderer(RenderStyle*);
134 virtual bool rendererIsNeeded(const RenderStyle&) { return true; }
136 virtual bool selfHasRelativeLengths() const;
138 void synchronizeOrientType();
140 static const AtomicString& orientTypeIdentifier();
141 static const AtomicString& orientAngleIdentifier();
143 BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGMarkerElement)
144 DECLARE_ANIMATED_LENGTH(RefX, refX)
145 DECLARE_ANIMATED_LENGTH(RefY, refY)
146 DECLARE_ANIMATED_LENGTH(MarkerWidth, markerWidth)
147 DECLARE_ANIMATED_LENGTH(MarkerHeight, markerHeight)
148 DECLARE_ANIMATED_ENUMERATION(MarkerUnits, markerUnits, SVGMarkerUnitsType)
149 DECLARE_ANIMATED_ANGLE(OrientAngle, orientAngle)
150 DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired)
151 DECLARE_ANIMATED_RECT(ViewBox, viewBox)
152 DECLARE_ANIMATED_PRESERVEASPECTRATIO(PreserveAspectRatio, preserveAspectRatio)
153 END_DECLARE_ANIMATED_PROPERTIES
156 // Custom 'orientType' property.
157 static void synchronizeOrientType(SVGElement* contextElement);
158 static PassRefPtr<SVGAnimatedProperty> lookupOrCreateOrientTypeWrapper(SVGElement* contextElement);
159 SVGMarkerOrientType& orientTypeCurrentValue() const { return m_orientType.value; }
160 SVGMarkerOrientType& orientTypeBaseValue() const { return m_orientType.value; }
161 void setOrientTypeBaseValue(const SVGMarkerOrientType& type) { m_orientType.value = type; }
162 PassRefPtr<SVGAnimatedEnumerationPropertyTearOff<SVGMarkerOrientType> > orientType();
165 mutable SVGSynchronizableAnimatedProperty<SVGMarkerOrientType> m_orientType;
168 DEFINE_NODE_TYPE_CASTS(SVGMarkerElement, hasTagName(SVGNames::markerTag));