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 "SVGAnimatedClass.h"
11 #include "DOMSVGAnimatedString.h"
12 #include "SMILStringType.h"
13 #include "mozilla/SMILValue.h"
14 #include "mozilla/dom/SVGElement.h"
18 void SVGAnimatedClass::SetBaseValue(const nsAString
& aValue
,
19 SVGElement
* aSVGElement
, bool aDoSetAttr
) {
20 NS_ASSERTION(aSVGElement
, "Null element passed to SetBaseValue");
22 aSVGElement
->SetMayHaveClass();
24 aSVGElement
->SetAttr(kNameSpaceID_None
, nsGkAtoms::_class
, aValue
, true);
27 aSVGElement
->AnimationNeedsResample();
31 void SVGAnimatedClass::GetBaseValue(nsAString
& aValue
,
32 const SVGElement
* aSVGElement
) const {
33 aSVGElement
->GetAttr(nsGkAtoms::_class
, aValue
);
36 void SVGAnimatedClass::GetAnimValue(nsAString
& aResult
,
37 const SVGElement
* aSVGElement
) const {
43 aSVGElement
->GetAttr(nsGkAtoms::_class
, aResult
);
46 void SVGAnimatedClass::SetAnimValue(const nsAString
& aValue
,
47 SVGElement
* aSVGElement
) {
48 if (mAnimVal
&& mAnimVal
->Equals(aValue
)) {
52 mAnimVal
= MakeUnique
<nsString
>();
55 aSVGElement
->SetMayHaveClass();
56 aSVGElement
->DidAnimateClass();
59 UniquePtr
<SMILAttr
> SVGAnimatedClass::ToSMILAttr(SVGElement
* aSVGElement
) {
60 return MakeUnique
<SMILString
>(this, aSVGElement
);
63 nsresult
SVGAnimatedClass::SMILString::ValueFromString(
64 const nsAString
& aStr
, const dom::SVGAnimationElement
* /*aSrcElement*/,
65 SMILValue
& aValue
, bool& aPreventCachingOfSandwich
) const {
66 SMILValue
val(SMILStringType::Singleton());
68 *static_cast<nsAString
*>(val
.mU
.mPtr
) = aStr
;
69 aValue
= std::move(val
);
73 SMILValue
SVGAnimatedClass::SMILString::GetBaseValue() const {
74 SMILValue
val(SMILStringType::Singleton());
75 mSVGElement
->GetAttr(nsGkAtoms::_class
,
76 *static_cast<nsAString
*>(val
.mU
.mPtr
));
80 void SVGAnimatedClass::SMILString::ClearAnimValue() {
82 mVal
->mAnimVal
= nullptr;
83 mSVGElement
->DidAnimateClass();
87 nsresult
SVGAnimatedClass::SMILString::SetAnimValue(const SMILValue
& aValue
) {
88 NS_ASSERTION(aValue
.mType
== SMILStringType::Singleton(),
89 "Unexpected type to assign animated value");
90 if (aValue
.mType
== SMILStringType::Singleton()) {
91 mVal
->SetAnimValue(*static_cast<nsAString
*>(aValue
.mU
.mPtr
), mSVGElement
);
96 } // namespace mozilla