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_SVGANIMATEDNUMBERLIST_H_
8 #define DOM_SVG_SVGANIMATEDNUMBERLIST_H_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/SMILAttr.h"
12 #include "mozilla/UniquePtr.h"
13 #include "SVGNumberList.h"
20 class SVGAnimationElement
;
25 * Class SVGAnimatedNumberList
27 * This class is very different to the SVG DOM interface of the same name found
28 * in the SVG specification. This is a lightweight internal class - see
29 * DOMSVGAnimatedNumberList for the heavier DOM class that wraps instances of
30 * this class and implements the SVG specification's SVGAnimatedNumberList DOM
33 * Except where noted otherwise, this class' methods take care of keeping the
34 * appropriate DOM wrappers in sync (see the comment in
35 * DOMSVGAnimatedNumberList::InternalBaseValListWillChangeTo) so that their
36 * consumers don't need to concern themselves with that.
38 class SVGAnimatedNumberList
{
39 // friends so that they can get write access to mBaseVal
40 friend class dom::DOMSVGNumber
;
41 friend class dom::DOMSVGNumberList
;
44 SVGAnimatedNumberList() = default;
46 SVGAnimatedNumberList
& operator=(const SVGAnimatedNumberList
& aOther
) {
47 mIsBaseSet
= aOther
.mIsBaseSet
;
48 mBaseVal
= aOther
.mBaseVal
;
49 if (aOther
.mAnimVal
) {
50 mAnimVal
= MakeUnique
<SVGNumberList
>(*aOther
.mAnimVal
);
56 * Because it's so important that mBaseVal and its DOMSVGNumberList wrapper
57 * (if any) be kept in sync (see the comment in
58 * DOMSVGAnimatedNumberList::InternalBaseValListWillChangeTo), this method
59 * returns a const reference. Only our friend classes may get mutable
60 * references to mBaseVal.
62 const SVGNumberList
& GetBaseValue() const { return mBaseVal
; }
64 nsresult
SetBaseValueString(const nsAString
& aValue
);
66 void ClearBaseValue(uint32_t aAttrEnum
);
68 const SVGNumberList
& GetAnimValue() const {
69 return mAnimVal
? *mAnimVal
: mBaseVal
;
72 nsresult
SetAnimValue(const SVGNumberList
& aNewAnimValue
,
73 dom::SVGElement
* aElement
, uint32_t aAttrEnum
);
75 void ClearAnimValue(dom::SVGElement
* aElement
, uint32_t aAttrEnum
);
77 // Returns true if the animated value of this list has been explicitly
78 // set (either by animation, or by taking on the base value which has been
79 // explicitly set by markup or a DOM call), false otherwise.
80 // If this returns false, the animated value is still valid, that is,
81 // usable, and represents the default base value of the attribute.
82 bool IsExplicitlySet() const { return !!mAnimVal
|| mIsBaseSet
; }
84 bool IsAnimating() const { return !!mAnimVal
; }
86 UniquePtr
<SMILAttr
> ToSMILAttr(dom::SVGElement
* aSVGElement
,
90 // mAnimVal is a pointer to allow us to determine if we're being animated or
91 // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
92 // if we're animating is not an option, since that would break animation *to*
93 // the empty string (<set to="">).
95 SVGNumberList mBaseVal
;
96 UniquePtr
<SVGNumberList
> mAnimVal
;
97 bool mIsBaseSet
= false;
99 struct SMILAnimatedNumberList
: public SMILAttr
{
101 SMILAnimatedNumberList(SVGAnimatedNumberList
* aVal
,
102 dom::SVGElement
* aSVGElement
, uint8_t aAttrEnum
)
103 : mVal(aVal
), mElement(aSVGElement
), mAttrEnum(aAttrEnum
) {}
105 // These will stay alive because a SMILAttr only lives as long
106 // as the Compositing step, and DOM elements don't get a chance to
108 SVGAnimatedNumberList
* mVal
;
109 dom::SVGElement
* mElement
;
113 nsresult
ValueFromString(const nsAString
& aStr
,
114 const dom::SVGAnimationElement
* aSrcElement
,
116 bool& aPreventCachingOfSandwich
) const override
;
117 SMILValue
GetBaseValue() const override
;
118 void ClearAnimValue() override
;
119 nsresult
SetAnimValue(const SMILValue
& aValue
) override
;
123 } // namespace mozilla
125 #endif // DOM_SVG_SVGANIMATEDNUMBERLIST_H_