Bumping manifests a=b2g-bump
[gecko.git] / dom / svg / nsSVGString.cpp
bloba5232ce5b4297f73a9922048afa602d3ac4cc133
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)
22 NS_INTERFACE_MAP_END
24 static inline
25 nsSVGAttrTearoffTable<nsSVGString, nsSVGString::DOMAnimatedString>&
26 SVGAnimatedStringTearoffTable()
28 static nsSVGAttrTearoffTable<nsSVGString, nsSVGString::DOMAnimatedString>
29 sSVGAnimatedStringTearoffTable;
30 return sSVGAnimatedStringTearoffTable;
33 /* Implementation */
35 void
36 nsSVGString::SetBaseValue(const nsAString& aValue,
37 nsSVGElement *aSVGElement,
38 bool aDoSetAttr)
40 NS_ASSERTION(aSVGElement, "Null element passed to SetBaseValue");
42 mIsBaseSet = true;
43 if (aDoSetAttr) {
44 aSVGElement->SetStringBaseValue(mAttrEnum, aValue);
46 if (mAnimVal) {
47 aSVGElement->AnimationNeedsResample();
50 aSVGElement->DidChangeString(mAttrEnum);
53 void
54 nsSVGString::GetAnimValue(nsAString& aResult, const nsSVGElement *aSVGElement) const
56 if (mAnimVal) {
57 aResult = *mAnimVal;
58 return;
61 aSVGElement->GetStringBaseValue(mAttrEnum, aResult);
64 void
65 nsSVGString::SetAnimValue(const nsAString& aValue, nsSVGElement *aSVGElement)
67 if (aSVGElement->IsStringAnimatable(mAttrEnum)) {
68 if (mAnimVal && mAnimVal->Equals(aValue)) {
69 return;
71 if (!mAnimVal) {
72 mAnimVal = new nsString();
74 *mAnimVal = aValue;
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);
97 nsISMILAttr*
98 nsSVGString::ToSMILAttr(nsSVGElement *aSVGElement)
100 return new SMILString(this, aSVGElement);
103 nsresult
104 nsSVGString::SMILString::ValueFromString(const nsAString& aStr,
105 const dom::SVGAnimationElement* /*aSrcElement*/,
106 nsSMILValue& aValue,
107 bool& aPreventCachingOfSandwich) const
109 nsSMILValue val(SMILStringType::Singleton());
111 *static_cast<nsAString*>(val.mU.mPtr) = aStr;
112 aValue.Swap(val);
113 aPreventCachingOfSandwich = false;
114 return NS_OK;
117 nsSMILValue
118 nsSVGString::SMILString::GetBaseValue() const
120 nsSMILValue val(SMILStringType::Singleton());
121 mSVGElement->GetStringBaseValue(mVal->mAttrEnum, *static_cast<nsAString*>(val.mU.mPtr));
122 return val;
125 void
126 nsSVGString::SMILString::ClearAnimValue()
128 if (mVal->mAnimVal) {
129 mVal->mAnimVal = nullptr;
130 mSVGElement->DidAnimateString(mVal->mAttrEnum);
134 nsresult
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);
142 return NS_OK;