/src/mozilla-central/dom/svg/nsSVGString.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "nsSVGString.h" |
8 | | |
9 | | #include "mozilla/Move.h" |
10 | | #include "nsSVGAttrTearoffTable.h" |
11 | | #include "nsSMILValue.h" |
12 | | #include "SMILStringType.h" |
13 | | |
14 | | using namespace mozilla; |
15 | | using namespace mozilla::dom; |
16 | | |
17 | | NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(nsSVGString::DOMAnimatedString, mSVGElement) |
18 | | |
19 | | NS_IMPL_CYCLE_COLLECTING_ADDREF(nsSVGString::DOMAnimatedString) |
20 | | NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGString::DOMAnimatedString) |
21 | | |
22 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsSVGString::DOMAnimatedString) |
23 | 0 | NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
24 | 0 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
25 | 0 | NS_INTERFACE_MAP_END |
26 | | |
27 | | static inline |
28 | | nsSVGAttrTearoffTable<nsSVGString, nsSVGString::DOMAnimatedString>& |
29 | | SVGAnimatedStringTearoffTable() |
30 | 0 | { |
31 | 0 | static nsSVGAttrTearoffTable<nsSVGString, nsSVGString::DOMAnimatedString> |
32 | 0 | sSVGAnimatedStringTearoffTable; |
33 | 0 | return sSVGAnimatedStringTearoffTable; |
34 | 0 | } |
35 | | |
36 | | /* Implementation */ |
37 | | |
38 | | void |
39 | | nsSVGString::SetBaseValue(const nsAString& aValue, |
40 | | nsSVGElement *aSVGElement, |
41 | | bool aDoSetAttr) |
42 | 0 | { |
43 | 0 | NS_ASSERTION(aSVGElement, "Null element passed to SetBaseValue"); |
44 | 0 |
|
45 | 0 | mIsBaseSet = true; |
46 | 0 | if (aDoSetAttr) { |
47 | 0 | aSVGElement->SetStringBaseValue(mAttrEnum, aValue); |
48 | 0 | } |
49 | 0 | if (mAnimVal) { |
50 | 0 | aSVGElement->AnimationNeedsResample(); |
51 | 0 | } |
52 | 0 |
|
53 | 0 | aSVGElement->DidChangeString(mAttrEnum); |
54 | 0 | } |
55 | | |
56 | | void |
57 | | nsSVGString::GetAnimValue(nsAString& aResult, const nsSVGElement *aSVGElement) const |
58 | 0 | { |
59 | 0 | if (mAnimVal) { |
60 | 0 | aResult = *mAnimVal; |
61 | 0 | return; |
62 | 0 | } |
63 | 0 | |
64 | 0 | aSVGElement->GetStringBaseValue(mAttrEnum, aResult); |
65 | 0 | } |
66 | | |
67 | | void |
68 | | nsSVGString::SetAnimValue(const nsAString& aValue, nsSVGElement *aSVGElement) |
69 | 0 | { |
70 | 0 | if (aSVGElement->IsStringAnimatable(mAttrEnum)) { |
71 | 0 | if (mAnimVal && mAnimVal->Equals(aValue)) { |
72 | 0 | return; |
73 | 0 | } |
74 | 0 | if (!mAnimVal) { |
75 | 0 | mAnimVal = new nsString(); |
76 | 0 | } |
77 | 0 | *mAnimVal = aValue; |
78 | 0 | aSVGElement->DidAnimateString(mAttrEnum); |
79 | 0 | } |
80 | 0 | } |
81 | | |
82 | | already_AddRefed<SVGAnimatedString> |
83 | | nsSVGString::ToDOMAnimatedString(nsSVGElement* aSVGElement) |
84 | 0 | { |
85 | 0 | RefPtr<DOMAnimatedString> domAnimatedString = |
86 | 0 | SVGAnimatedStringTearoffTable().GetTearoff(this); |
87 | 0 | if (!domAnimatedString) { |
88 | 0 | domAnimatedString = new DOMAnimatedString(this, aSVGElement); |
89 | 0 | SVGAnimatedStringTearoffTable().AddTearoff(this, domAnimatedString); |
90 | 0 | } |
91 | 0 |
|
92 | 0 | return domAnimatedString.forget(); |
93 | 0 | } |
94 | | |
95 | | nsSVGString::DOMAnimatedString::~DOMAnimatedString() |
96 | 0 | { |
97 | 0 | SVGAnimatedStringTearoffTable().RemoveTearoff(mVal); |
98 | 0 | } |
99 | | |
100 | | UniquePtr<nsISMILAttr> |
101 | | nsSVGString::ToSMILAttr(nsSVGElement *aSVGElement) |
102 | 0 | { |
103 | 0 | return MakeUnique<SMILString>(this, aSVGElement); |
104 | 0 | } |
105 | | |
106 | | nsresult |
107 | | nsSVGString::SMILString::ValueFromString(const nsAString& aStr, |
108 | | const dom::SVGAnimationElement* /*aSrcElement*/, |
109 | | nsSMILValue& aValue, |
110 | | bool& aPreventCachingOfSandwich) const |
111 | 0 | { |
112 | 0 | nsSMILValue val(SMILStringType::Singleton()); |
113 | 0 |
|
114 | 0 | *static_cast<nsAString*>(val.mU.mPtr) = aStr; |
115 | 0 | aValue = std::move(val); |
116 | 0 | aPreventCachingOfSandwich = false; |
117 | 0 | return NS_OK; |
118 | 0 | } |
119 | | |
120 | | nsSMILValue |
121 | | nsSVGString::SMILString::GetBaseValue() const |
122 | 0 | { |
123 | 0 | nsSMILValue val(SMILStringType::Singleton()); |
124 | 0 | mSVGElement->GetStringBaseValue(mVal->mAttrEnum, *static_cast<nsAString*>(val.mU.mPtr)); |
125 | 0 | return val; |
126 | 0 | } |
127 | | |
128 | | void |
129 | | nsSVGString::SMILString::ClearAnimValue() |
130 | 0 | { |
131 | 0 | if (mVal->mAnimVal) { |
132 | 0 | mVal->mAnimVal = nullptr; |
133 | 0 | mSVGElement->DidAnimateString(mVal->mAttrEnum); |
134 | 0 | } |
135 | 0 | } |
136 | | |
137 | | nsresult |
138 | | nsSVGString::SMILString::SetAnimValue(const nsSMILValue& aValue) |
139 | 0 | { |
140 | 0 | NS_ASSERTION(aValue.mType == SMILStringType::Singleton(), |
141 | 0 | "Unexpected type to assign animated value"); |
142 | 0 | if (aValue.mType == SMILStringType::Singleton()) { |
143 | 0 | mVal->SetAnimValue(*static_cast<nsAString*>(aValue.mU.mPtr), mSVGElement); |
144 | 0 | } |
145 | 0 | return NS_OK; |
146 | 0 | } |