/src/mozilla-central/dom/svg/nsSVGAngle.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef __NS_SVGANGLE_H__ |
8 | | #define __NS_SVGANGLE_H__ |
9 | | |
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" |
16 | | |
17 | | class nsISupports; |
18 | | class nsSMILValue; |
19 | | class nsSVGElement; |
20 | | |
21 | | namespace mozilla { |
22 | | |
23 | | namespace dom { |
24 | | class nsSVGOrientType; |
25 | | class SVGAngle; |
26 | | class SVGAnimatedAngle; |
27 | | class SVGAnimationElement; |
28 | | } // namespace dom |
29 | | } // namespace mozilla |
30 | | |
31 | | class nsSVGAngle |
32 | | { |
33 | | friend class mozilla::dom::SVGAngle; |
34 | | friend class mozilla::dom::SVGAnimatedAngle; |
35 | | |
36 | | public: |
37 | | void Init(uint8_t aAttrEnum = 0xff, |
38 | | float aValue = 0, |
39 | | uint8_t aUnitType = |
40 | 0 | mozilla::dom::SVGAngle_Binding::SVG_ANGLETYPE_UNSPECIFIED) { |
41 | 0 | mAnimVal = mBaseVal = aValue; |
42 | 0 | mAnimValUnit = mBaseValUnit = aUnitType; |
43 | 0 | mAttrEnum = aAttrEnum; |
44 | 0 | mIsAnimated = false; |
45 | 0 | } |
46 | | |
47 | | nsresult SetBaseValueString(const nsAString& aValue, |
48 | | nsSVGElement *aSVGElement, |
49 | | bool aDoSetAttr); |
50 | | void GetBaseValueString(nsAString& aValue) const; |
51 | | void GetAnimValueString(nsAString& aValue) const; |
52 | | |
53 | | float GetBaseValue() const |
54 | 0 | { return mBaseVal * GetDegreesPerUnit(mBaseValUnit); } |
55 | | float GetAnimValue() const |
56 | 0 | { return mAnimVal * GetDegreesPerUnit(mAnimValUnit); } |
57 | | |
58 | | void SetBaseValue(float aValue, uint8_t aUnit, nsSVGElement *aSVGElement, |
59 | | bool aDoSetAttr); |
60 | | void SetAnimValue(float aValue, uint8_t aUnit, nsSVGElement *aSVGElement); |
61 | | |
62 | 0 | uint8_t GetBaseValueUnit() const { return mBaseValUnit; } |
63 | 0 | uint8_t GetAnimValueUnit() const { return mAnimValUnit; } |
64 | 0 | float GetBaseValInSpecifiedUnits() const { return mBaseVal; } |
65 | 0 | float GetAnimValInSpecifiedUnits() const { return mAnimVal; } |
66 | | |
67 | | static nsresult ToDOMSVGAngle(nsISupports **aResult); |
68 | | already_AddRefed<mozilla::dom::SVGAnimatedAngle> |
69 | | ToDOMAnimatedAngle(nsSVGElement* aSVGElement); |
70 | | mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement); |
71 | | |
72 | | static bool GetValueFromString(const nsAString& aString, |
73 | | float& aValue, |
74 | | uint16_t* aUnitType); |
75 | | static float GetDegreesPerUnit(uint8_t aUnit); |
76 | | |
77 | | private: |
78 | | |
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; |
85 | | |
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); |
92 | | |
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. |
98 | | |
99 | | struct SMILOrient final : public nsISMILAttr |
100 | | { |
101 | | public: |
102 | | SMILOrient(mozilla::dom::nsSVGOrientType* aOrientType, |
103 | | nsSVGAngle* aAngle, |
104 | | nsSVGElement* aSVGElement) |
105 | | : mOrientType(aOrientType) |
106 | | , mAngle(aAngle) |
107 | | , mSVGElement(aSVGElement) |
108 | 0 | {} |
109 | | |
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; |
116 | | |
117 | | // nsISMILAttr methods |
118 | | virtual nsresult ValueFromString(const nsAString& aStr, |
119 | | const mozilla::dom::SVGAnimationElement* aSrcElement, |
120 | | nsSMILValue& aValue, |
121 | | bool& aPreventCachingOfSandwich) const override; |
122 | | virtual nsSMILValue GetBaseValue() const override; |
123 | | virtual void ClearAnimValue() override; |
124 | | virtual nsresult SetAnimValue(const nsSMILValue& aValue) override; |
125 | | }; |
126 | | }; |
127 | | |
128 | | #endif //__NS_SVGANGLE_H__ |