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_SVGANIMATEDLENGTHLIST_H_
8 #define DOM_SVG_SVGANIMATEDLENGTHLIST_H_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/SMILAttr.h"
12 #include "mozilla/UniquePtr.h"
13 #include "SVGLengthList.h"
20 class SVGAnimationElement
;
25 * Class SVGAnimatedLengthList
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 * DOMSVGAnimatedLengthList for the heavier DOM class that wraps instances of
30 * this class and implements the SVG specification's SVGAnimatedLengthList 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 * DOMSVGAnimatedLengthList::InternalBaseValListWillChangeTo) so that their
36 * consumers don't need to concern themselves with that.
38 class SVGAnimatedLengthList
{
39 // friends so that they can get write access to mBaseVal
40 friend class dom::DOMSVGLength
;
41 friend class dom::DOMSVGLengthList
;
44 SVGAnimatedLengthList() = default;
46 SVGAnimatedLengthList
& operator=(const SVGAnimatedLengthList
& aOther
) {
47 mBaseVal
= aOther
.mBaseVal
;
48 if (aOther
.mAnimVal
) {
49 mAnimVal
= MakeUnique
<SVGLengthList
>(*aOther
.mAnimVal
);
55 * Because it's so important that mBaseVal and its DOMSVGLengthList wrapper
56 * (if any) be kept in sync (see the comment in
57 * DOMSVGAnimatedLengthList::InternalBaseValListWillChangeTo), this method
58 * returns a const reference. Only our friend classes may get mutable
59 * references to mBaseVal.
61 const SVGLengthList
& GetBaseValue() const { return mBaseVal
; }
63 nsresult
SetBaseValueString(const nsAString
& aValue
);
65 void ClearBaseValue(uint32_t aAttrEnum
);
67 const SVGLengthList
& GetAnimValue() const {
68 return mAnimVal
? *mAnimVal
: mBaseVal
;
71 nsresult
SetAnimValue(const SVGLengthList
& aNewAnimValue
,
72 dom::SVGElement
* aElement
, uint32_t aAttrEnum
);
74 void ClearAnimValue(dom::SVGElement
* aElement
, uint32_t aAttrEnum
);
76 bool IsAnimating() const { return !!mAnimVal
; }
78 UniquePtr
<SMILAttr
> ToSMILAttr(dom::SVGElement
* aSVGElement
,
79 uint8_t aAttrEnum
, uint8_t aAxis
,
80 bool aCanZeroPadList
);
83 // mAnimVal is a pointer to allow us to determine if we're being animated or
84 // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
85 // if we're animating is not an option, since that would break animation *to*
86 // the empty string (<set to="">).
88 SVGLengthList mBaseVal
;
89 UniquePtr
<SVGLengthList
> mAnimVal
;
91 struct SMILAnimatedLengthList
: public SMILAttr
{
93 SMILAnimatedLengthList(SVGAnimatedLengthList
* aVal
,
94 dom::SVGElement
* aSVGElement
, uint8_t aAttrEnum
,
95 uint8_t aAxis
, bool aCanZeroPadList
)
97 mElement(aSVGElement
),
100 mCanZeroPadList(aCanZeroPadList
) {}
102 // These will stay alive because a SMILAttr only lives as long
103 // as the Compositing step, and DOM elements don't get a chance to
105 SVGAnimatedLengthList
* mVal
;
106 dom::SVGElement
* mElement
;
109 bool mCanZeroPadList
; // See SVGLengthListAndInfo::CanZeroPadList
112 nsresult
ValueFromString(const nsAString
& aStr
,
113 const dom::SVGAnimationElement
* aSrcElement
,
115 bool& aPreventCachingOfSandwich
) const override
;
116 SMILValue
GetBaseValue() const override
;
117 void ClearAnimValue() override
;
118 nsresult
SetAnimValue(const SMILValue
& aValue
) override
;
122 } // namespace mozilla
124 #endif // DOM_SVG_SVGANIMATEDLENGTHLIST_H_