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_SVGANIMATEDSTRING_H_
8 #define DOM_SVG_SVGANIMATEDSTRING_H_
11 #include "mozilla/Attributes.h"
12 #include "mozilla/SMILAttr.h"
13 #include "mozilla/SVGAnimatedClassOrString.h"
14 #include "mozilla/dom/SVGElement.h"
15 #include "mozilla/UniquePtr.h"
25 class SVGAnimatedString final
: public SVGAnimatedClassOrString
{
27 using SVGElement
= dom::SVGElement
;
29 void Init(uint8_t aAttrEnum
) {
31 mAttrEnum
= aAttrEnum
;
35 void SetBaseValue(const nsAString
& aValue
, SVGElement
* aSVGElement
,
36 bool aDoSetAttr
) override
;
37 void GetBaseValue(nsAString
& aValue
,
38 const SVGElement
* aSVGElement
) const override
{
39 aSVGElement
->GetStringBaseValue(mAttrEnum
, aValue
);
42 void SetAnimValue(const nsAString
& aValue
, SVGElement
* aSVGElement
);
43 void GetAnimValue(nsAString
& aResult
,
44 const SVGElement
* aSVGElement
) const override
;
46 // Returns true if the animated value of this string 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 !!mAnimVal
|| mIsBaseSet
; }
53 UniquePtr
<SMILAttr
> ToSMILAttr(SVGElement
* aSVGElement
);
55 SVGAnimatedString() = default;
57 SVGAnimatedString
& operator=(const SVGAnimatedString
& aOther
) {
58 mAttrEnum
= aOther
.mAttrEnum
;
59 mIsBaseSet
= aOther
.mIsBaseSet
;
60 if (aOther
.mAnimVal
) {
61 mAnimVal
= MakeUnique
<nsString
>(*aOther
.mAnimVal
);
66 SVGAnimatedString(const SVGAnimatedString
& aOther
) : SVGAnimatedString() {
71 // FIXME: Should probably use void string rather than UniquePtr<nsString>.
72 UniquePtr
<nsString
> mAnimVal
;
73 uint8_t mAttrEnum
= 0; // element specified tracking for attribute
74 bool mIsBaseSet
= false;
77 struct SMILString
: public SMILAttr
{
79 SMILString(SVGAnimatedString
* aVal
, SVGElement
* aSVGElement
)
80 : mVal(aVal
), mSVGElement(aSVGElement
) {}
82 // These will stay alive because a SMILAttr only lives as long
83 // as the Compositing step, and DOM elements don't get a chance to
85 SVGAnimatedString
* mVal
;
86 SVGElement
* mSVGElement
;
89 nsresult
ValueFromString(const nsAString
& aStr
,
90 const dom::SVGAnimationElement
* aSrcElement
,
92 bool& aPreventCachingOfSandwich
) const override
;
93 SMILValue
GetBaseValue() const override
;
94 void ClearAnimValue() override
;
95 nsresult
SetAnimValue(const SMILValue
& aValue
) override
;
99 } // namespace mozilla
101 #endif // DOM_SVG_SVGANIMATEDSTRING_H_