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_SVGINTEGERPAIR_H__
8 #define __NS_SVGINTEGERPAIR_H__
10 #include "DOMSVGAnimatedInteger.h"
11 #include "nsCycleCollectionParticipant.h"
13 #include "mozilla/Attributes.h"
14 #include "mozilla/SMILAttr.h"
15 #include "mozilla/UniquePtr.h"
22 class SVGAnimationElement
;
26 class SVGAnimatedIntegerPair
{
28 typedef mozilla::dom::SVGElement SVGElement
;
30 enum PairIndex
{ eFirst
, eSecond
};
32 void Init(uint8_t aAttrEnum
= 0xff, int32_t aValue1
= 0,
33 int32_t aValue2
= 0) {
34 mAnimVal
[0] = mBaseVal
[0] = aValue1
;
35 mAnimVal
[1] = mBaseVal
[1] = aValue2
;
36 mAttrEnum
= aAttrEnum
;
41 nsresult
SetBaseValueString(const nsAString
& aValue
, SVGElement
* aSVGElement
);
42 void GetBaseValueString(nsAString
& aValue
) const;
44 void SetBaseValue(int32_t aValue
, PairIndex aPairIndex
,
45 SVGElement
* aSVGElement
);
46 void SetBaseValues(int32_t aValue1
, int32_t aValue2
, SVGElement
* aSVGElement
);
47 int32_t GetBaseValue(PairIndex aIndex
) const {
48 return mBaseVal
[aIndex
== eFirst
? 0 : 1];
50 void SetAnimValue(const int32_t aValue
[2], SVGElement
* aSVGElement
);
51 int32_t GetAnimValue(PairIndex aIndex
) const {
52 return mAnimVal
[aIndex
== eFirst
? 0 : 1];
55 // Returns true if the animated value of this integer has been explicitly
56 // set (either by animation, or by taking on the base value which has been
57 // explicitly set by markup or a DOM call), false otherwise.
58 // If this returns false, the animated value is still valid, that is,
59 // usable, and represents the default base value of the attribute.
60 bool IsExplicitlySet() const { return mIsAnimated
|| mIsBaseSet
; }
62 already_AddRefed
<mozilla::dom::DOMSVGAnimatedInteger
> ToDOMAnimatedInteger(
63 PairIndex aIndex
, SVGElement
* aSVGElement
);
64 mozilla::UniquePtr
<SMILAttr
> ToSMILAttr(SVGElement
* aSVGElement
);
69 uint8_t mAttrEnum
; // element specified tracking for attribute
74 struct DOMAnimatedInteger final
: public mozilla::dom::DOMSVGAnimatedInteger
{
75 DOMAnimatedInteger(SVGAnimatedIntegerPair
* aVal
, PairIndex aIndex
,
76 SVGElement
* aSVGElement
)
77 : mozilla::dom::DOMSVGAnimatedInteger(aSVGElement
),
80 virtual ~DOMAnimatedInteger();
82 SVGAnimatedIntegerPair
* mVal
; // kept alive because it belongs to content
83 PairIndex mIndex
; // are we the first or second integer
85 virtual int32_t BaseVal() override
{ return mVal
->GetBaseValue(mIndex
); }
86 virtual void SetBaseVal(int32_t aValue
) override
{
87 mVal
->SetBaseValue(aValue
, mIndex
, mSVGElement
);
90 // Script may have modified animation parameters or timeline -- DOM getters
91 // need to flush any resample requests to reflect these modifications.
92 virtual int32_t AnimVal() override
{
93 mSVGElement
->FlushAnimations();
94 return mVal
->GetAnimValue(mIndex
);
98 struct SMILIntegerPair
: public SMILAttr
{
100 SMILIntegerPair(SVGAnimatedIntegerPair
* aVal
, SVGElement
* aSVGElement
)
101 : mVal(aVal
), mSVGElement(aSVGElement
) {}
103 // These will stay alive because a SMILAttr only lives as long
104 // as the Compositing step, and DOM elements don't get a chance to
106 SVGAnimatedIntegerPair
* mVal
;
107 SVGElement
* mSVGElement
;
110 virtual nsresult
ValueFromString(
111 const nsAString
& aStr
,
112 const mozilla::dom::SVGAnimationElement
* aSrcElement
, SMILValue
& aValue
,
113 bool& aPreventCachingOfSandwich
) const override
;
114 virtual SMILValue
GetBaseValue() const override
;
115 virtual void ClearAnimValue() override
;
116 virtual nsresult
SetAnimValue(const SMILValue
& aValue
) override
;
120 } // namespace mozilla
122 #endif //__NS_SVGINTEGERPAIR_H__