1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef MOZILLA_SVGANIMATEDNUMBERLIST_H__
7 #define MOZILLA_SVGANIMATEDNUMBERLIST_H__
9 #include "mozilla/Attributes.h"
10 #include "nsAutoPtr.h"
11 #include "nsISMILAttr.h"
12 #include "SVGNumberList.h"
20 class SVGAnimationElement
;
24 * Class SVGAnimatedNumberList
26 * This class is very different to the SVG DOM interface of the same name found
27 * in the SVG specification. This is a lightweight internal class - see
28 * DOMSVGAnimatedNumberList for the heavier DOM class that wraps instances of
29 * this class and implements the SVG specification's SVGAnimatedNumberList DOM
32 * Except where noted otherwise, this class' methods take care of keeping the
33 * appropriate DOM wrappers in sync (see the comment in
34 * DOMSVGAnimatedNumberList::InternalBaseValListWillChangeTo) so that their
35 * consumers don't need to concern themselves with that.
37 class SVGAnimatedNumberList
39 // friends so that they can get write access to mBaseVal
40 friend class DOMSVGNumber
;
41 friend class DOMSVGNumberList
;
44 SVGAnimatedNumberList() {}
47 * Because it's so important that mBaseVal and its DOMSVGNumberList wrapper
48 * (if any) be kept in sync (see the comment in
49 * DOMSVGAnimatedNumberList::InternalBaseValListWillChangeTo), this method
50 * returns a const reference. Only our friend classes may get mutable
51 * references to mBaseVal.
53 const SVGNumberList
& GetBaseValue() const {
57 nsresult
SetBaseValueString(const nsAString
& aValue
);
59 void ClearBaseValue(uint32_t aAttrEnum
);
61 const SVGNumberList
& GetAnimValue() const {
62 return mAnimVal
? *mAnimVal
: mBaseVal
;
65 nsresult
SetAnimValue(const SVGNumberList
& aValue
,
66 nsSVGElement
*aElement
,
69 void ClearAnimValue(nsSVGElement
*aElement
,
72 // Returns true if the animated value of this list has been explicitly
73 // set (either by animation, or by taking on the base value which has been
74 // explicitly set by markup or a DOM call), false otherwise.
75 // If this returns false, the animated value is still valid, that is,
76 // useable, and represents the default base value of the attribute.
77 bool IsExplicitlySet() const
78 { return !!mAnimVal
|| mIsBaseSet
; }
80 bool IsAnimating() const {
84 /// Callers own the returned nsISMILAttr
85 nsISMILAttr
* ToSMILAttr(nsSVGElement
* aSVGElement
, uint8_t aAttrEnum
);
89 // mAnimVal is a pointer to allow us to determine if we're being animated or
90 // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
91 // if we're animating is not an option, since that would break animation *to*
92 // the empty string (<set to="">).
94 SVGNumberList mBaseVal
;
95 nsAutoPtr
<SVGNumberList
> mAnimVal
;
98 struct SMILAnimatedNumberList
: public nsISMILAttr
101 SMILAnimatedNumberList(SVGAnimatedNumberList
* aVal
,
102 nsSVGElement
* aSVGElement
,
105 , mElement(aSVGElement
)
106 , mAttrEnum(aAttrEnum
)
109 // These will stay alive because a nsISMILAttr only lives as long
110 // as the Compositing step, and DOM elements don't get a chance to
112 SVGAnimatedNumberList
* mVal
;
113 nsSVGElement
* mElement
;
116 // nsISMILAttr methods
117 virtual nsresult
ValueFromString(const nsAString
& aStr
,
118 const dom::SVGAnimationElement
* aSrcElement
,
120 bool& aPreventCachingOfSandwich
) const MOZ_OVERRIDE
;
121 virtual nsSMILValue
GetBaseValue() const MOZ_OVERRIDE
;
122 virtual void ClearAnimValue() MOZ_OVERRIDE
;
123 virtual nsresult
SetAnimValue(const nsSMILValue
& aValue
) MOZ_OVERRIDE
;
127 } // namespace mozilla
129 #endif // MOZILLA_SVGANIMATEDNUMBERLIST_H__