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 __NS_SVGINTEGER_H__
8 #define __NS_SVGINTEGER_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 typedef mozilla::dom::SVGElement SVGElement
;
30 void Init(uint8_t aAttrEnum
= 0xff, int32_t aValue
= 0) {
31 mAnimVal
= mBaseVal
= aValue
;
32 mAttrEnum
= aAttrEnum
;
37 nsresult
SetBaseValueString(const nsAString
& aValue
, SVGElement
* aSVGElement
);
38 void GetBaseValueString(nsAString
& aValue
);
40 void SetBaseValue(int32_t aValue
, SVGElement
* aSVGElement
);
41 int32_t GetBaseValue() const { return mBaseVal
; }
43 void SetAnimValue(int aValue
, SVGElement
* aSVGElement
);
44 int GetAnimValue() const { return mAnimVal
; }
46 // Returns true if the animated value of this integer has been explicitly
47 // set (either by animation, or by taking on the base value which has been
48 // explicitly set by markup or a DOM call), false otherwise.
49 // If this returns false, the animated value is still valid, that is,
50 // usable, and represents the default base value of the attribute.
51 bool IsExplicitlySet() const { return mIsAnimated
|| mIsBaseSet
; }
53 already_AddRefed
<mozilla::dom::DOMSVGAnimatedInteger
> ToDOMAnimatedInteger(
54 SVGElement
* aSVGElement
);
55 mozilla::UniquePtr
<SMILAttr
> ToSMILAttr(SVGElement
* aSVGElement
);
60 uint8_t mAttrEnum
; // element specified tracking for attribute
65 struct DOMAnimatedInteger final
: public mozilla::dom::DOMSVGAnimatedInteger
{
66 DOMAnimatedInteger(SVGAnimatedInteger
* aVal
, SVGElement
* aSVGElement
)
67 : mozilla::dom::DOMSVGAnimatedInteger(aSVGElement
), mVal(aVal
) {}
68 virtual ~DOMAnimatedInteger();
70 SVGAnimatedInteger
* mVal
; // kept alive because it belongs to content
72 virtual int32_t BaseVal() override
{ return mVal
->GetBaseValue(); }
73 virtual void SetBaseVal(int32_t aValue
) override
{
74 mVal
->SetBaseValue(aValue
, mSVGElement
);
77 // Script may have modified animation parameters or timeline -- DOM getters
78 // need to flush any resample requests to reflect these modifications.
79 virtual int32_t AnimVal() override
{
80 mSVGElement
->FlushAnimations();
81 return mVal
->GetAnimValue();
85 struct SMILInteger
: public SMILAttr
{
87 SMILInteger(SVGAnimatedInteger
* aVal
, SVGElement
* aSVGElement
)
88 : mVal(aVal
), mSVGElement(aSVGElement
) {}
90 // These will stay alive because a SMILAttr only lives as long
91 // as the Compositing step, and DOM elements don't get a chance to
93 SVGAnimatedInteger
* mVal
;
94 SVGElement
* mSVGElement
;
97 virtual nsresult
ValueFromString(
98 const nsAString
& aStr
,
99 const mozilla::dom::SVGAnimationElement
* aSrcElement
, SMILValue
& aValue
,
100 bool& aPreventCachingOfSandwich
) const override
;
101 virtual SMILValue
GetBaseValue() const override
;
102 virtual void ClearAnimValue() override
;
103 virtual nsresult
SetAnimValue(const SMILValue
& aValue
) override
;
107 } // namespace mozilla
109 #endif //__NS_SVGINTEGER_H__