/src/mozilla-central/dom/svg/nsSVGNumber2.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_SVGNUMBER2_H__ |
8 | | #define __NS_SVGNUMBER2_H__ |
9 | | |
10 | | #include "nsCycleCollectionParticipant.h" |
11 | | #include "nsError.h" |
12 | | #include "nsISMILAttr.h" |
13 | | #include "nsMathUtils.h" |
14 | | #include "nsSVGElement.h" |
15 | | #include "mozilla/Attributes.h" |
16 | | #include "mozilla/FloatingPoint.h" |
17 | | #include "mozilla/dom/SVGAnimatedNumber.h" |
18 | | #include "mozilla/UniquePtr.h" |
19 | | |
20 | | class nsSMILValue; |
21 | | |
22 | | namespace mozilla { |
23 | | namespace dom { |
24 | | class SVGAnimationElement; |
25 | | } // namespace dom |
26 | | } // namespace mozilla |
27 | | |
28 | | class nsSVGNumber2 |
29 | | { |
30 | | |
31 | | public: |
32 | 0 | void Init(uint8_t aAttrEnum = 0xff, float aValue = 0) { |
33 | 0 | mAnimVal = mBaseVal = aValue; |
34 | 0 | mAttrEnum = aAttrEnum; |
35 | 0 | mIsAnimated = false; |
36 | 0 | mIsBaseSet = false; |
37 | 0 | } |
38 | | |
39 | | nsresult SetBaseValueString(const nsAString& aValue, |
40 | | nsSVGElement *aSVGElement); |
41 | | void GetBaseValueString(nsAString& aValue); |
42 | | |
43 | | void SetBaseValue(float aValue, nsSVGElement *aSVGElement); |
44 | | float GetBaseValue() const |
45 | 0 | { return mBaseVal; } |
46 | | void SetAnimValue(float aValue, nsSVGElement *aSVGElement); |
47 | | float GetAnimValue() const |
48 | 0 | { return mAnimVal; } |
49 | | |
50 | | // Returns true if the animated value of this number has been explicitly |
51 | | // set (either by animation, or by taking on the base value which has been |
52 | | // explicitly set by markup or a DOM call), false otherwise. |
53 | | // If this returns false, the animated value is still valid, that is, |
54 | | // usable, and represents the default base value of the attribute. |
55 | | bool IsExplicitlySet() const |
56 | 0 | { return mIsAnimated || mIsBaseSet; } |
57 | | |
58 | | already_AddRefed<mozilla::dom::SVGAnimatedNumber> |
59 | | ToDOMAnimatedNumber(nsSVGElement* aSVGElement); |
60 | | mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement); |
61 | | |
62 | | private: |
63 | | float mAnimVal; |
64 | | float mBaseVal; |
65 | | uint8_t mAttrEnum; // element specified tracking for attribute |
66 | | bool mIsAnimated; |
67 | | bool mIsBaseSet; |
68 | | |
69 | | public: |
70 | | struct DOMAnimatedNumber final : public mozilla::dom::SVGAnimatedNumber |
71 | | { |
72 | | DOMAnimatedNumber(nsSVGNumber2* aVal, nsSVGElement* aSVGElement) |
73 | | : mozilla::dom::SVGAnimatedNumber(aSVGElement) |
74 | | , mVal(aVal) |
75 | 0 | {} |
76 | | virtual ~DOMAnimatedNumber(); |
77 | | |
78 | | nsSVGNumber2* mVal; // kept alive because it belongs to content |
79 | | |
80 | | virtual float BaseVal() override |
81 | 0 | { |
82 | 0 | return mVal->GetBaseValue(); |
83 | 0 | } |
84 | | virtual void SetBaseVal(float aValue) override |
85 | 0 | { |
86 | 0 | MOZ_ASSERT(mozilla::IsFinite(aValue)); |
87 | 0 | mVal->SetBaseValue(aValue, mSVGElement); |
88 | 0 | } |
89 | | |
90 | | // Script may have modified animation parameters or timeline -- DOM getters |
91 | | // need to flush any resample requests to reflect these modifications. |
92 | | virtual float AnimVal() override |
93 | 0 | { |
94 | 0 | mSVGElement->FlushAnimations(); |
95 | 0 | return mVal->GetAnimValue(); |
96 | 0 | } |
97 | | }; |
98 | | |
99 | | struct SMILNumber : public nsISMILAttr |
100 | | { |
101 | | public: |
102 | | SMILNumber(nsSVGNumber2* aVal, nsSVGElement* aSVGElement) |
103 | 0 | : mVal(aVal), mSVGElement(aSVGElement) {} |
104 | | |
105 | | // These will stay alive because a nsISMILAttr only lives as long |
106 | | // as the Compositing step, and DOM elements don't get a chance to |
107 | | // die during that. |
108 | | nsSVGNumber2* mVal; |
109 | | nsSVGElement* mSVGElement; |
110 | | |
111 | | // nsISMILAttr methods |
112 | | virtual nsresult ValueFromString(const nsAString& aStr, |
113 | | const mozilla::dom::SVGAnimationElement* aSrcElement, |
114 | | nsSMILValue& aValue, |
115 | | bool& aPreventCachingOfSandwich) const override; |
116 | | virtual nsSMILValue GetBaseValue() const override; |
117 | | virtual void ClearAnimValue() override; |
118 | | virtual nsresult SetAnimValue(const nsSMILValue& aValue) override; |
119 | | }; |
120 | | }; |
121 | | |
122 | | #endif //__NS_SVGNUMBER2_H__ |