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 DOM_SVG_SVGANIMATEDNUMBER_H_
8 #define DOM_SVG_SVGANIMATEDNUMBER_H_
10 #include "nsCycleCollectionParticipant.h"
12 #include "nsMathUtils.h"
13 #include "mozilla/Attributes.h"
14 #include "mozilla/FloatingPoint.h"
15 #include "mozilla/SMILAttr.h"
16 #include "mozilla/UniquePtr.h"
17 #include "mozilla/dom/DOMSVGAnimatedNumber.h"
18 #include "mozilla/dom/SVGElement.h"
25 class SVGAnimationElement
;
28 class SVGAnimatedNumber
{
30 friend class AutoChangeNumberNotifier
;
31 using SVGElement
= dom::SVGElement
;
33 void Init(uint8_t aAttrEnum
= 0xff, float aValue
= 0) {
34 mAnimVal
= mBaseVal
= aValue
;
35 mAttrEnum
= aAttrEnum
;
40 nsresult
SetBaseValueString(const nsAString
& aValue
, SVGElement
* aSVGElement
);
41 void GetBaseValueString(nsAString
& aValue
);
43 void SetBaseValue(float aValue
, SVGElement
* aSVGElement
);
44 float GetBaseValue() const { return mBaseVal
; }
45 void SetAnimValue(float aValue
, SVGElement
* aSVGElement
);
46 float GetAnimValue() const { return mAnimVal
; }
48 // Returns true if the animated value of this number has been explicitly
49 // set (either by animation, or by taking on the base value which has been
50 // explicitly set by markup or a DOM call), false otherwise.
51 // If this returns false, the animated value is still valid, that is,
52 // usable, and represents the default base value of the attribute.
53 bool IsExplicitlySet() const { return mIsAnimated
|| mIsBaseSet
; }
55 already_AddRefed
<dom::DOMSVGAnimatedNumber
> ToDOMAnimatedNumber(
56 SVGElement
* aSVGElement
);
57 UniquePtr
<SMILAttr
> ToSMILAttr(SVGElement
* aSVGElement
);
62 uint8_t mAttrEnum
; // element specified tracking for attribute
67 // DOM wrapper class for the (DOM)SVGAnimatedNumber interface where the
68 // wrapped class is SVGAnimatedNumber.
69 struct DOMAnimatedNumber final
: public dom::DOMSVGAnimatedNumber
{
70 DOMAnimatedNumber(SVGAnimatedNumber
* aVal
, SVGElement
* aSVGElement
)
71 : dom::DOMSVGAnimatedNumber(aSVGElement
), mVal(aVal
) {}
72 virtual ~DOMAnimatedNumber();
74 SVGAnimatedNumber
* mVal
; // kept alive because it belongs to content
76 float BaseVal() override
{ return mVal
->GetBaseValue(); }
77 void SetBaseVal(float aValue
) override
{
78 MOZ_ASSERT(std::isfinite(aValue
));
79 mVal
->SetBaseValue(aValue
, mSVGElement
);
82 // Script may have modified animation parameters or timeline -- DOM getters
83 // need to flush any resample requests to reflect these modifications.
84 float AnimVal() override
{
85 mSVGElement
->FlushAnimations();
86 return mVal
->GetAnimValue();
90 struct SMILNumber
: public SMILAttr
{
92 SMILNumber(SVGAnimatedNumber
* aVal
, SVGElement
* aSVGElement
)
93 : mVal(aVal
), mSVGElement(aSVGElement
) {}
95 // These will stay alive because a SMILAttr only lives as long
96 // as the Compositing step, and DOM elements don't get a chance to
98 SVGAnimatedNumber
* mVal
;
99 SVGElement
* mSVGElement
;
102 virtual nsresult
ValueFromString(
103 const nsAString
& aStr
, const dom::SVGAnimationElement
* aSrcElement
,
104 SMILValue
& aValue
, bool& aPreventCachingOfSandwich
) const override
;
105 SMILValue
GetBaseValue() const override
;
106 void ClearAnimValue() override
;
107 nsresult
SetAnimValue(const SMILValue
& aValue
) override
;
111 } // namespace mozilla
113 #endif // DOM_SVG_SVGANIMATEDNUMBER_H_