1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef __NS_SVGANGLE_H__
8 #define __NS_SVGANGLE_H__
12 #include "nsISMILAttr.h"
13 #include "mozilla/Attributes.h"
14 #include "mozilla/dom/SVGAngleBinding.h"
15 #include "mozilla/UniquePtr.h"
24 class nsSVGOrientType
;
26 class SVGAnimatedAngle
;
27 class SVGAnimationElement
;
29 } // namespace mozilla
33 friend class mozilla::dom::SVGAngle
;
34 friend class mozilla::dom::SVGAnimatedAngle
;
37 void Init(uint8_t aAttrEnum
= 0xff,
40 mozilla::dom::SVGAngleBinding::SVG_ANGLETYPE_UNSPECIFIED
) {
41 mAnimVal
= mBaseVal
= aValue
;
42 mAnimValUnit
= mBaseValUnit
= aUnitType
;
43 mAttrEnum
= aAttrEnum
;
47 nsresult
SetBaseValueString(const nsAString
& aValue
,
48 nsSVGElement
*aSVGElement
,
50 void GetBaseValueString(nsAString
& aValue
) const;
51 void GetAnimValueString(nsAString
& aValue
) const;
53 float GetBaseValue() const
54 { return mBaseVal
* GetDegreesPerUnit(mBaseValUnit
); }
55 float GetAnimValue() const
56 { return mAnimVal
* GetDegreesPerUnit(mAnimValUnit
); }
58 void SetBaseValue(float aValue
, nsSVGElement
*aSVGElement
, bool aDoSetAttr
);
59 void SetAnimValue(float aValue
, uint8_t aUnit
, nsSVGElement
*aSVGElement
);
61 uint8_t GetBaseValueUnit() const { return mBaseValUnit
; }
62 uint8_t GetAnimValueUnit() const { return mAnimValUnit
; }
63 float GetBaseValInSpecifiedUnits() const { return mBaseVal
; }
64 float GetAnimValInSpecifiedUnits() const { return mAnimVal
; }
66 static nsresult
ToDOMSVGAngle(nsISupports
**aResult
);
67 already_AddRefed
<mozilla::dom::SVGAnimatedAngle
>
68 ToDOMAnimatedAngle(nsSVGElement
* aSVGElement
);
69 mozilla::UniquePtr
<nsISMILAttr
> ToSMILAttr(nsSVGElement
* aSVGElement
);
71 static bool GetValueFromString(const nsAString
& aString
,
74 static float GetDegreesPerUnit(uint8_t aUnit
);
82 uint8_t mAttrEnum
; // element specified tracking for attribute
85 void SetBaseValueInSpecifiedUnits(float aValue
, nsSVGElement
*aSVGElement
);
86 nsresult
NewValueSpecifiedUnits(uint16_t aUnitType
, float aValue
,
87 nsSVGElement
*aSVGElement
);
88 nsresult
ConvertToSpecifiedUnits(uint16_t aUnitType
, nsSVGElement
*aSVGElement
);
89 already_AddRefed
<mozilla::dom::SVGAngle
> ToDOMBaseVal(nsSVGElement
* aSVGElement
);
90 already_AddRefed
<mozilla::dom::SVGAngle
> ToDOMAnimVal(nsSVGElement
* aSVGElement
);
93 // We do not currently implemente a SMILAngle struct because in SVG 1.1 the
94 // only *animatable* attribute that takes an <angle> is 'orient', on the
95 // 'marker' element, and 'orient' must be special cased since it can also
96 // take the value 'auto', making it a more complex type.
98 struct SMILOrient final
: public nsISMILAttr
101 SMILOrient(mozilla::dom::nsSVGOrientType
* aOrientType
,
103 nsSVGElement
* aSVGElement
)
104 : mOrientType(aOrientType
)
106 , mSVGElement(aSVGElement
)
109 // These will stay alive because a nsISMILAttr only lives as long
110 // as the Compositing step, and DOM elements don't get a chance to
112 mozilla::dom::nsSVGOrientType
* mOrientType
;
114 nsSVGElement
* mSVGElement
;
116 // nsISMILAttr methods
117 virtual nsresult
ValueFromString(const nsAString
& aStr
,
118 const mozilla::dom::SVGAnimationElement
* aSrcElement
,
120 bool& aPreventCachingOfSandwich
) const override
;
121 virtual nsSMILValue
GetBaseValue() const override
;
122 virtual void ClearAnimValue() override
;
123 virtual nsresult
SetAnimValue(const nsSMILValue
& aValue
) override
;
127 #endif //__NS_SVGANGLE_H__