Bug 1444460 [wpt PR 9948] - gyroscope: Rename LocalCoordinateSystem to GyroscopeLocal...
[gecko.git] / dom / svg / nsSVGAngle.h
blob0f3cfb06a6ccd13817215da0ddb3936548db06d2
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__
10 #include "nsCOMPtr.h"
11 #include "nsError.h"
12 #include "nsISMILAttr.h"
13 #include "mozilla/Attributes.h"
14 #include "mozilla/dom/SVGAngleBinding.h"
15 #include "mozilla/UniquePtr.h"
17 class nsISupports;
18 class nsSMILValue;
19 class nsSVGElement;
21 namespace mozilla {
23 namespace dom {
24 class nsSVGOrientType;
25 class SVGAngle;
26 class SVGAnimatedAngle;
27 class SVGAnimationElement;
28 } // namespace dom
29 } // namespace mozilla
31 class nsSVGAngle
33 friend class mozilla::dom::SVGAngle;
34 friend class mozilla::dom::SVGAnimatedAngle;
36 public:
37 void Init(uint8_t aAttrEnum = 0xff,
38 float aValue = 0,
39 uint8_t aUnitType =
40 mozilla::dom::SVGAngleBinding::SVG_ANGLETYPE_UNSPECIFIED) {
41 mAnimVal = mBaseVal = aValue;
42 mAnimValUnit = mBaseValUnit = aUnitType;
43 mAttrEnum = aAttrEnum;
44 mIsAnimated = false;
47 nsresult SetBaseValueString(const nsAString& aValue,
48 nsSVGElement *aSVGElement,
49 bool aDoSetAttr);
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,
72 float& aValue,
73 uint16_t* aUnitType);
74 static float GetDegreesPerUnit(uint8_t aUnit);
76 private:
78 float mAnimVal;
79 float mBaseVal;
80 uint8_t mAnimValUnit;
81 uint8_t mBaseValUnit;
82 uint8_t mAttrEnum; // element specified tracking for attribute
83 bool mIsAnimated;
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);
92 public:
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
100 public:
101 SMILOrient(mozilla::dom::nsSVGOrientType* aOrientType,
102 nsSVGAngle* aAngle,
103 nsSVGElement* aSVGElement)
104 : mOrientType(aOrientType)
105 , mAngle(aAngle)
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
111 // die during that.
112 mozilla::dom::nsSVGOrientType* mOrientType;
113 nsSVGAngle* mAngle;
114 nsSVGElement* mSVGElement;
116 // nsISMILAttr methods
117 virtual nsresult ValueFromString(const nsAString& aStr,
118 const mozilla::dom::SVGAnimationElement* aSrcElement,
119 nsSMILValue& aValue,
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__