Bumping manifests a=b2g-bump
[gecko.git] / dom / svg / nsSVGAngle.h
blobb68fa8c623eddeecceb414beb6ea82ae536f6d6d
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef __NS_SVGANGLE_H__
7 #define __NS_SVGANGLE_H__
9 #include "nsCOMPtr.h"
10 #include "nsError.h"
11 #include "nsISMILAttr.h"
12 #include "mozilla/Attributes.h"
14 class nsISupports;
15 class nsSMILValue;
16 class nsSVGElement;
18 namespace mozilla {
20 // Angle Unit Types
21 static const unsigned short SVG_ANGLETYPE_UNKNOWN = 0;
22 static const unsigned short SVG_ANGLETYPE_UNSPECIFIED = 1;
23 static const unsigned short SVG_ANGLETYPE_DEG = 2;
24 static const unsigned short SVG_ANGLETYPE_RAD = 3;
25 static const unsigned short SVG_ANGLETYPE_GRAD = 4;
27 namespace dom {
28 class nsSVGOrientType;
29 class SVGAngle;
30 class SVGAnimatedAngle;
31 class SVGAnimationElement;
35 class nsSVGAngle
37 friend class mozilla::dom::SVGAngle;
38 friend class mozilla::dom::SVGAnimatedAngle;
40 public:
41 void Init(uint8_t aAttrEnum = 0xff,
42 float aValue = 0,
43 uint8_t aUnitType = mozilla::SVG_ANGLETYPE_UNSPECIFIED) {
44 mAnimVal = mBaseVal = aValue;
45 mAnimValUnit = mBaseValUnit = aUnitType;
46 mAttrEnum = aAttrEnum;
47 mIsAnimated = false;
50 nsresult SetBaseValueString(const nsAString& aValue,
51 nsSVGElement *aSVGElement,
52 bool aDoSetAttr);
53 void GetBaseValueString(nsAString& aValue) const;
54 void GetAnimValueString(nsAString& aValue) const;
56 float GetBaseValue() const
57 { return mBaseVal * GetDegreesPerUnit(mBaseValUnit); }
58 float GetAnimValue() const
59 { return mAnimVal * GetDegreesPerUnit(mAnimValUnit); }
61 void SetBaseValue(float aValue, nsSVGElement *aSVGElement, bool aDoSetAttr);
62 void SetAnimValue(float aValue, uint8_t aUnit, nsSVGElement *aSVGElement);
64 uint8_t GetBaseValueUnit() const { return mBaseValUnit; }
65 uint8_t GetAnimValueUnit() const { return mAnimValUnit; }
66 float GetBaseValInSpecifiedUnits() const { return mBaseVal; }
67 float GetAnimValInSpecifiedUnits() const { return mAnimVal; }
69 static nsresult ToDOMSVGAngle(nsISupports **aResult);
70 already_AddRefed<mozilla::dom::SVGAnimatedAngle>
71 ToDOMAnimatedAngle(nsSVGElement* aSVGElement);
72 // Returns a new nsISMILAttr object that the caller must delete
73 nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
75 static float GetDegreesPerUnit(uint8_t aUnit);
77 private:
79 float mAnimVal;
80 float mBaseVal;
81 uint8_t mAnimValUnit;
82 uint8_t mBaseValUnit;
83 uint8_t mAttrEnum; // element specified tracking for attribute
84 bool mIsAnimated;
86 void SetBaseValueInSpecifiedUnits(float aValue, nsSVGElement *aSVGElement);
87 nsresult NewValueSpecifiedUnits(uint16_t aUnitType, float aValue,
88 nsSVGElement *aSVGElement);
89 nsresult ConvertToSpecifiedUnits(uint16_t aUnitType, nsSVGElement *aSVGElement);
90 already_AddRefed<mozilla::dom::SVGAngle> ToDOMBaseVal(nsSVGElement* aSVGElement);
91 already_AddRefed<mozilla::dom::SVGAngle> ToDOMAnimVal(nsSVGElement* aSVGElement);
93 public:
94 // We do not currently implemente a SMILAngle struct because in SVG 1.1 the
95 // only *animatable* attribute that takes an <angle> is 'orient', on the
96 // 'marker' element, and 'orient' must be special cased since it can also
97 // take the value 'auto', making it a more complex type.
99 struct SMILOrient MOZ_FINAL : public nsISMILAttr
101 public:
102 SMILOrient(mozilla::dom::nsSVGOrientType* aOrientType,
103 nsSVGAngle* aAngle,
104 nsSVGElement* aSVGElement)
105 : mOrientType(aOrientType)
106 , mAngle(aAngle)
107 , mSVGElement(aSVGElement)
110 // These will stay alive because a nsISMILAttr only lives as long
111 // as the Compositing step, and DOM elements don't get a chance to
112 // die during that.
113 mozilla::dom::nsSVGOrientType* mOrientType;
114 nsSVGAngle* mAngle;
115 nsSVGElement* mSVGElement;
117 // nsISMILAttr methods
118 virtual nsresult ValueFromString(const nsAString& aStr,
119 const mozilla::dom::SVGAnimationElement* aSrcElement,
120 nsSMILValue& aValue,
121 bool& aPreventCachingOfSandwich) const MOZ_OVERRIDE;
122 virtual nsSMILValue GetBaseValue() const MOZ_OVERRIDE;
123 virtual void ClearAnimValue() MOZ_OVERRIDE;
124 virtual nsresult SetAnimValue(const nsSMILValue& aValue) MOZ_OVERRIDE;
128 #endif //__NS_SVGANGLE_H__