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__
11 #include "nsISMILAttr.h"
12 #include "mozilla/Attributes.h"
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;
28 class nsSVGOrientType
;
30 class SVGAnimatedAngle
;
31 class SVGAnimationElement
;
37 friend class mozilla::dom::SVGAngle
;
38 friend class mozilla::dom::SVGAnimatedAngle
;
41 void Init(uint8_t aAttrEnum
= 0xff,
43 uint8_t aUnitType
= mozilla::SVG_ANGLETYPE_UNSPECIFIED
) {
44 mAnimVal
= mBaseVal
= aValue
;
45 mAnimValUnit
= mBaseValUnit
= aUnitType
;
46 mAttrEnum
= aAttrEnum
;
50 nsresult
SetBaseValueString(const nsAString
& aValue
,
51 nsSVGElement
*aSVGElement
,
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
);
83 uint8_t mAttrEnum
; // element specified tracking for attribute
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
);
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
102 SMILOrient(mozilla::dom::nsSVGOrientType
* aOrientType
,
104 nsSVGElement
* aSVGElement
)
105 : mOrientType(aOrientType
)
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
113 mozilla::dom::nsSVGOrientType
* mOrientType
;
115 nsSVGElement
* mSVGElement
;
117 // nsISMILAttr methods
118 virtual nsresult
ValueFromString(const nsAString
& aStr
,
119 const mozilla::dom::SVGAnimationElement
* aSrcElement
,
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__