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_SVGANIMATEDINTEGER_H_
8 #define DOM_SVG_SVGANIMATEDINTEGER_H_
10 #include "nsCycleCollectionParticipant.h"
12 #include "DOMSVGAnimatedInteger.h"
13 #include "mozilla/Attributes.h"
14 #include "mozilla/SMILAttr.h"
15 #include "mozilla/UniquePtr.h"
16 #include "mozilla/dom/SVGElement.h"
23 class SVGAnimationElement
;
26 class SVGAnimatedInteger
{
28 friend class AutoChangeIntegerNotifier
;
29 using SVGElement
= dom::SVGElement
;
31 void Init(uint8_t aAttrEnum
= 0xff, int32_t aValue
= 0) {
32 mAnimVal
= mBaseVal
= aValue
;
33 mAttrEnum
= aAttrEnum
;
38 nsresult
SetBaseValueString(const nsAString
& aValue
, SVGElement
* aSVGElement
);
39 void GetBaseValueString(nsAString
& aValue
);
41 void SetBaseValue(int32_t aValue
, SVGElement
* aSVGElement
);
42 int32_t GetBaseValue() const { return mBaseVal
; }
44 void SetAnimValue(int aValue
, SVGElement
* aSVGElement
);
45 int GetAnimValue() const { return mAnimVal
; }
47 // Returns true if the animated value of this integer has been explicitly
48 // set (either by animation, or by taking on the base value which has been
49 // explicitly set by markup or a DOM call), false otherwise.
50 // If this returns false, the animated value is still valid, that is,
51 // usable, and represents the default base value of the attribute.
52 bool IsExplicitlySet() const { return mIsAnimated
|| mIsBaseSet
; }
54 already_AddRefed
<dom::DOMSVGAnimatedInteger
> ToDOMAnimatedInteger(
55 SVGElement
* aSVGElement
);
56 UniquePtr
<SMILAttr
> ToSMILAttr(SVGElement
* aSVGElement
);
61 uint8_t mAttrEnum
; // element specified tracking for attribute
66 struct DOMAnimatedInteger final
: public dom::DOMSVGAnimatedInteger
{
67 DOMAnimatedInteger(SVGAnimatedInteger
* aVal
, SVGElement
* aSVGElement
)
68 : dom::DOMSVGAnimatedInteger(aSVGElement
), mVal(aVal
) {}
69 virtual ~DOMAnimatedInteger();
71 SVGAnimatedInteger
* mVal
; // kept alive because it belongs to content
73 int32_t BaseVal() override
{ return mVal
->GetBaseValue(); }
74 void SetBaseVal(int32_t aValue
) override
{
75 mVal
->SetBaseValue(aValue
, mSVGElement
);
78 // Script may have modified animation parameters or timeline -- DOM getters
79 // need to flush any resample requests to reflect these modifications.
80 int32_t AnimVal() override
{
81 mSVGElement
->FlushAnimations();
82 return mVal
->GetAnimValue();
86 struct SMILInteger
: public SMILAttr
{
88 SMILInteger(SVGAnimatedInteger
* aVal
, SVGElement
* aSVGElement
)
89 : mVal(aVal
), mSVGElement(aSVGElement
) {}
91 // These will stay alive because a SMILAttr only lives as long
92 // as the Compositing step, and DOM elements don't get a chance to
94 SVGAnimatedInteger
* mVal
;
95 SVGElement
* mSVGElement
;
98 nsresult
ValueFromString(const nsAString
& aStr
,
99 const dom::SVGAnimationElement
* aSrcElement
,
101 bool& aPreventCachingOfSandwich
) const override
;
102 SMILValue
GetBaseValue() const override
;
103 void ClearAnimValue() override
;
104 nsresult
SetAnimValue(const SMILValue
& aValue
) override
;
108 } // namespace mozilla
110 #endif // DOM_SVG_SVGANIMATEDINTEGER_H_