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