1 /* 2 * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann (at) kde.org> 3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis (at) kde.org> 4 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public License 17 * along with this library; see the file COPYING.LIB. If not, write to 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 */ 21 22 #ifndef SVGAngle_h 23 #define SVGAngle_h 24 25 #include "core/svg/SVGEnumeration.h" 26 27 namespace WebCore { 28 29 class SVGAngle; 30 class SVGAngleTearOff; 31 32 enum SVGMarkerOrientType { 33 SVGMarkerOrientUnknown = 0, 34 SVGMarkerOrientAuto, 35 SVGMarkerOrientAngle 36 }; 37 template<> const SVGEnumerationStringEntries& getStaticStringEntries<SVGMarkerOrientType>(); 38 39 class SVGMarkerOrientEnumeration : public SVGEnumeration<SVGMarkerOrientType> { 40 public: 41 static PassRefPtr<SVGMarkerOrientEnumeration> create(SVGAngle* angle) 42 { 43 return adoptRef(new SVGMarkerOrientEnumeration(angle)); 44 } 45 46 virtual ~SVGMarkerOrientEnumeration(); 47 48 virtual void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) OVERRIDE; 49 virtual void calculateAnimatedValue(SVGAnimationElement*, float, unsigned, PassRefPtr<SVGPropertyBase>, PassRefPtr<SVGPropertyBase>, PassRefPtr<SVGPropertyBase>, SVGElement*) OVERRIDE; 50 virtual float calculateDistance(PassRefPtr<SVGPropertyBase>, SVGElement*) OVERRIDE; 51 52 private: 53 SVGMarkerOrientEnumeration(SVGAngle*); 54 55 virtual void notifyChange() OVERRIDE; 56 57 // FIXME: oilpan: This is kept as raw-ptr to avoid reference cycles. Should be Member in oilpan. 58 SVGAngle* m_angle; 59 }; 60 61 class SVGAngle : public SVGPropertyBase { 62 public: 63 typedef SVGAngleTearOff TearOffType; 64 65 enum SVGAngleType { 66 SVG_ANGLETYPE_UNKNOWN = 0, 67 SVG_ANGLETYPE_UNSPECIFIED = 1, 68 SVG_ANGLETYPE_DEG = 2, 69 SVG_ANGLETYPE_RAD = 3, 70 SVG_ANGLETYPE_GRAD = 4, 71 SVG_ANGLETYPE_TURN = 5 72 }; 73 74 static PassRefPtr<SVGAngle> create() 75 { 76 return adoptRef(new SVGAngle()); 77 } 78 79 virtual ~SVGAngle(); 80 81 SVGAngleType unitType() const { return m_unitType; } 82 83 void setValue(float); 84 float value() const; 85 86 void setValueInSpecifiedUnits(float valueInSpecifiedUnits) { m_valueInSpecifiedUnits = valueInSpecifiedUnits; } 87 float valueInSpecifiedUnits() const { return m_valueInSpecifiedUnits; } 88 89 void newValueSpecifiedUnits(SVGAngleType unitType, float valueInSpecifiedUnits); 90 void convertToSpecifiedUnits(SVGAngleType unitType, ExceptionState&); 91 92 SVGEnumeration<SVGMarkerOrientType>* orientType() { return m_orientType.get(); } 93 void orientTypeChanged(); 94 95 // SVGPropertyBase: 96 97 PassRefPtr<SVGAngle> clone() const; 98 virtual PassRefPtr<SVGPropertyBase> cloneForAnimation(const String&) const OVERRIDE; 99 100 virtual String valueAsString() const OVERRIDE; 101 void setValueAsString(const String&, ExceptionState&); 102 103 virtual void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) OVERRIDE; 104 virtual void calculateAnimatedValue(SVGAnimationElement*, float percentage, unsigned repeatCount, PassRefPtr<SVGPropertyBase> from, PassRefPtr<SVGPropertyBase> to, PassRefPtr<SVGPropertyBase> toAtEndOfDurationValue, SVGElement* contextElement) OVERRIDE; 105 virtual float calculateDistance(PassRefPtr<SVGPropertyBase> to, SVGElement* contextElement) OVERRIDE; 106 107 static AnimatedPropertyType classType() { return AnimatedAngle; } 108 109 private: 110 SVGAngle(); 111 SVGAngle(SVGAngleType, float, SVGMarkerOrientType); 112 113 SVGAngleType m_unitType; 114 float m_valueInSpecifiedUnits; 115 RefPtr<SVGMarkerOrientEnumeration> m_orientType; 116 }; 117 118 inline PassRefPtr<SVGAngle> toSVGAngle(PassRefPtr<SVGPropertyBase> passBase) 119 { 120 RefPtr<SVGPropertyBase> base = passBase; 121 ASSERT(base->type() == SVGAngle::classType()); 122 return static_pointer_cast<SVGAngle>(base.release()); 123 } 124 125 } // namespace WebCore 126 127 #endif // SVGAngle_h 128