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 "SVGAnimatedAngle.h" 25#include "SVGAnimatedBoolean.h" 26#include "SVGAnimatedEnumeration.h" 27#include "SVGAnimatedLength.h" 28#include "SVGAnimatedPreserveAspectRatio.h" 29#include "SVGAnimatedRect.h" 30#include "SVGElement.h" 31#include "SVGExternalResourcesRequired.h" 32#include "SVGFitToViewBox.h" 33 34namespace WebCore { 35 36enum SVGMarkerUnitsType { 37 SVGMarkerUnitsUnknown = 0, 38 SVGMarkerUnitsUserSpaceOnUse, 39 SVGMarkerUnitsStrokeWidth 40}; 41 42enum SVGMarkerOrientType { 43 SVGMarkerOrientUnknown = 0, 44 SVGMarkerOrientAuto, 45 SVGMarkerOrientAngle 46}; 47 48template<> 49struct 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 77template<> 78struct 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 ExceptionCode ec = 0; 89 angle.setValueAsString(value, ec); 90 if (!ec) 91 return SVGMarkerOrientAngle; 92 return SVGMarkerOrientUnknown; 93 } 94}; 95 96class SVGMarkerElement final : public SVGElement, 97 public SVGExternalResourcesRequired, 98 public SVGFitToViewBox { 99public: 100 // Forward declare enumerations in the W3C naming scheme, for IDL generation. 101 enum { 102 SVG_MARKERUNITS_UNKNOWN = SVGMarkerUnitsUnknown, 103 SVG_MARKERUNITS_USERSPACEONUSE = SVGMarkerUnitsUserSpaceOnUse, 104 SVG_MARKERUNITS_STROKEWIDTH = SVGMarkerUnitsStrokeWidth 105 }; 106 107 enum { 108 SVG_MARKER_ORIENT_UNKNOWN = SVGMarkerOrientUnknown, 109 SVG_MARKER_ORIENT_AUTO = SVGMarkerOrientAuto, 110 SVG_MARKER_ORIENT_ANGLE = SVGMarkerOrientAngle 111 }; 112 113 static PassRefPtr<SVGMarkerElement> create(const QualifiedName&, Document&); 114 115 AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const; 116 117 void setOrientToAuto(); 118 void setOrientToAngle(const SVGAngle&); 119 120 static const SVGPropertyInfo* orientTypePropertyInfo(); 121 122private: 123 SVGMarkerElement(const QualifiedName&, Document&); 124 125 virtual bool needsPendingResourceHandling() const override { return false; } 126 127 bool isSupportedAttribute(const QualifiedName&); 128 virtual void parseAttribute(const QualifiedName&, const AtomicString&) override; 129 virtual void svgAttributeChanged(const QualifiedName&) override; 130 virtual void childrenChanged(const ChildChange&) override; 131 132 virtual RenderPtr<RenderElement> createElementRenderer(PassRef<RenderStyle>) override; 133 virtual bool rendererIsNeeded(const RenderStyle&) override { return true; } 134 135 virtual bool selfHasRelativeLengths() const override; 136 137 void synchronizeOrientType(); 138 139 static const AtomicString& orientTypeIdentifier(); 140 static const AtomicString& orientAngleIdentifier(); 141 142 BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGMarkerElement) 143 DECLARE_ANIMATED_LENGTH(RefX, refX) 144 DECLARE_ANIMATED_LENGTH(RefY, refY) 145 DECLARE_ANIMATED_LENGTH(MarkerWidth, markerWidth) 146 DECLARE_ANIMATED_LENGTH(MarkerHeight, markerHeight) 147 DECLARE_ANIMATED_ENUMERATION(MarkerUnits, markerUnits, SVGMarkerUnitsType) 148 DECLARE_ANIMATED_ANGLE(OrientAngle, orientAngle) 149 DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) 150 DECLARE_ANIMATED_RECT(ViewBox, viewBox) 151 DECLARE_ANIMATED_PRESERVEASPECTRATIO(PreserveAspectRatio, preserveAspectRatio) 152 END_DECLARE_ANIMATED_PROPERTIES 153 154public: 155 // Custom 'orientType' property. 156 static void synchronizeOrientType(SVGElement* contextElement); 157 static PassRefPtr<SVGAnimatedProperty> lookupOrCreateOrientTypeWrapper(SVGElement* contextElement); 158 SVGMarkerOrientType& orientType() const { return m_orientType.value; } 159 SVGMarkerOrientType& orientTypeBaseValue() const { return m_orientType.value; } 160 void setOrientTypeBaseValue(const SVGMarkerOrientType& type) { m_orientType.value = type; } 161 PassRefPtr<SVGAnimatedEnumerationPropertyTearOff<SVGMarkerOrientType>> orientTypeAnimated(); 162 163private: 164 mutable SVGSynchronizableAnimatedProperty<SVGMarkerOrientType> m_orientType; 165}; 166 167NODE_TYPE_CASTS(SVGMarkerElement) 168 169} 170 171#endif 172