1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsSVGString.h"
7 #include "nsSVGAttrTearoffTable.h"
8 #include "nsSMILValue.h"
9 #include "SMILStringType.h"
11 using namespace mozilla
;
12 using namespace mozilla::dom
;
14 NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(nsSVGString::DOMAnimatedString
, mSVGElement
)
16 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsSVGString::DOMAnimatedString
)
17 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGString::DOMAnimatedString
)
19 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsSVGString::DOMAnimatedString
)
20 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
21 NS_INTERFACE_MAP_ENTRY(nsISupports
)
25 nsSVGAttrTearoffTable
<nsSVGString
, nsSVGString::DOMAnimatedString
>&
26 SVGAnimatedStringTearoffTable()
28 static nsSVGAttrTearoffTable
<nsSVGString
, nsSVGString::DOMAnimatedString
>
29 sSVGAnimatedStringTearoffTable
;
30 return sSVGAnimatedStringTearoffTable
;
36 nsSVGString::SetBaseValue(const nsAString
& aValue
,
37 nsSVGElement
*aSVGElement
,
40 NS_ASSERTION(aSVGElement
, "Null element passed to SetBaseValue");
44 aSVGElement
->SetStringBaseValue(mAttrEnum
, aValue
);
47 aSVGElement
->AnimationNeedsResample();
50 aSVGElement
->DidChangeString(mAttrEnum
);
54 nsSVGString::GetAnimValue(nsAString
& aResult
, const nsSVGElement
*aSVGElement
) const
61 aSVGElement
->GetStringBaseValue(mAttrEnum
, aResult
);
65 nsSVGString::SetAnimValue(const nsAString
& aValue
, nsSVGElement
*aSVGElement
)
67 if (aSVGElement
->IsStringAnimatable(mAttrEnum
)) {
68 if (mAnimVal
&& mAnimVal
->Equals(aValue
)) {
72 mAnimVal
= new nsString();
75 aSVGElement
->DidAnimateString(mAttrEnum
);
79 already_AddRefed
<SVGAnimatedString
>
80 nsSVGString::ToDOMAnimatedString(nsSVGElement
* aSVGElement
)
82 nsRefPtr
<DOMAnimatedString
> domAnimatedString
=
83 SVGAnimatedStringTearoffTable().GetTearoff(this);
84 if (!domAnimatedString
) {
85 domAnimatedString
= new DOMAnimatedString(this, aSVGElement
);
86 SVGAnimatedStringTearoffTable().AddTearoff(this, domAnimatedString
);
89 return domAnimatedString
.forget();
92 nsSVGString::DOMAnimatedString::~DOMAnimatedString()
94 SVGAnimatedStringTearoffTable().RemoveTearoff(mVal
);
98 nsSVGString::ToSMILAttr(nsSVGElement
*aSVGElement
)
100 return new SMILString(this, aSVGElement
);
104 nsSVGString::SMILString::ValueFromString(const nsAString
& aStr
,
105 const dom::SVGAnimationElement
* /*aSrcElement*/,
107 bool& aPreventCachingOfSandwich
) const
109 nsSMILValue
val(SMILStringType::Singleton());
111 *static_cast<nsAString
*>(val
.mU
.mPtr
) = aStr
;
113 aPreventCachingOfSandwich
= false;
118 nsSVGString::SMILString::GetBaseValue() const
120 nsSMILValue
val(SMILStringType::Singleton());
121 mSVGElement
->GetStringBaseValue(mVal
->mAttrEnum
, *static_cast<nsAString
*>(val
.mU
.mPtr
));
126 nsSVGString::SMILString::ClearAnimValue()
128 if (mVal
->mAnimVal
) {
129 mVal
->mAnimVal
= nullptr;
130 mSVGElement
->DidAnimateString(mVal
->mAttrEnum
);
135 nsSVGString::SMILString::SetAnimValue(const nsSMILValue
& aValue
)
137 NS_ASSERTION(aValue
.mType
== SMILStringType::Singleton(),
138 "Unexpected type to assign animated value");
139 if (aValue
.mType
== SMILStringType::Singleton()) {
140 mVal
->SetAnimValue(*static_cast<nsAString
*>(aValue
.mU
.mPtr
), mSVGElement
);