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 #include "SVGAnimatedString.h"
11 #include "SMILStringType.h"
12 #include "SVGAttrTearoffTable.h"
13 #include "mozilla/SMILValue.h"
15 using namespace mozilla::dom
;
21 void SVGAnimatedString::SetBaseValue(const nsAString
& aValue
,
22 SVGElement
* aSVGElement
, bool aDoSetAttr
) {
23 NS_ASSERTION(aSVGElement
, "Null element passed to SetBaseValue");
27 aSVGElement
->SetStringBaseValue(mAttrEnum
, aValue
);
30 aSVGElement
->AnimationNeedsResample();
33 aSVGElement
->DidChangeString(mAttrEnum
);
36 void SVGAnimatedString::GetAnimValue(nsAString
& aResult
,
37 const SVGElement
* aSVGElement
) const {
43 aSVGElement
->GetStringBaseValue(mAttrEnum
, aResult
);
46 void SVGAnimatedString::SetAnimValue(const nsAString
& aValue
,
47 SVGElement
* aSVGElement
) {
48 if (aSVGElement
->IsStringAnimatable(mAttrEnum
)) {
49 if (mAnimVal
&& mAnimVal
->Equals(aValue
)) {
53 mAnimVal
= MakeUnique
<nsString
>();
56 aSVGElement
->DidAnimateString(mAttrEnum
);
60 UniquePtr
<SMILAttr
> SVGAnimatedString::ToSMILAttr(SVGElement
* aSVGElement
) {
61 return MakeUnique
<SMILString
>(this, aSVGElement
);
64 nsresult
SVGAnimatedString::SMILString::ValueFromString(
65 const nsAString
& aStr
, const dom::SVGAnimationElement
* /*aSrcElement*/,
66 SMILValue
& aValue
, bool& aPreventCachingOfSandwich
) const {
67 SMILValue
val(SMILStringType::Singleton());
69 *static_cast<nsAString
*>(val
.mU
.mPtr
) = aStr
;
70 aValue
= std::move(val
);
74 SMILValue
SVGAnimatedString::SMILString::GetBaseValue() const {
75 SMILValue
val(SMILStringType::Singleton());
76 mSVGElement
->GetStringBaseValue(mVal
->mAttrEnum
,
77 *static_cast<nsAString
*>(val
.mU
.mPtr
));
81 void SVGAnimatedString::SMILString::ClearAnimValue() {
83 mVal
->mAnimVal
= nullptr;
84 mSVGElement
->DidAnimateString(mVal
->mAttrEnum
);
88 nsresult
SVGAnimatedString::SMILString::SetAnimValue(const SMILValue
& aValue
) {
89 NS_ASSERTION(aValue
.mType
== SMILStringType::Singleton(),
90 "Unexpected type to assign animated value");
91 if (aValue
.mType
== SMILStringType::Singleton()) {
92 mVal
->SetAnimValue(*static_cast<nsAString
*>(aValue
.mU
.mPtr
), mSVGElement
);
97 } // namespace mozilla