/src/mozilla-central/dom/svg/nsSVGClass.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 "nsSVGClass.h" |
8 | | |
9 | | #include "mozilla/dom/SVGAnimatedString.h" |
10 | | #include "mozilla/Move.h" |
11 | | #include "nsSVGElement.h" |
12 | | #include "nsSMILValue.h" |
13 | | #include "SMILStringType.h" |
14 | | |
15 | | using namespace mozilla; |
16 | | using namespace mozilla::dom; |
17 | | |
18 | | struct DOMAnimatedString final : public SVGAnimatedString |
19 | | { |
20 | | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
21 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMAnimatedString) |
22 | | |
23 | | DOMAnimatedString(nsSVGClass* aVal, nsSVGElement* aSVGElement) |
24 | | : SVGAnimatedString(aSVGElement) |
25 | | , mVal(aVal) |
26 | 0 | {} |
27 | | |
28 | | nsSVGClass* mVal; // kept alive because it belongs to content |
29 | | |
30 | | void GetBaseVal(nsAString& aResult) override |
31 | 0 | { |
32 | 0 | mVal->GetBaseValue(aResult, mSVGElement); |
33 | 0 | } |
34 | | |
35 | | void SetBaseVal(const nsAString& aValue) override |
36 | 0 | { |
37 | 0 | mVal->SetBaseValue(aValue, mSVGElement, true); |
38 | 0 | } |
39 | | |
40 | | void GetAnimVal(nsAString& aResult) override; |
41 | | |
42 | | private: |
43 | 0 | ~DOMAnimatedString() {} |
44 | | }; |
45 | | |
46 | | NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(DOMAnimatedString, mSVGElement) |
47 | | |
48 | | NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMAnimatedString) |
49 | | NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMAnimatedString) |
50 | | |
51 | | |
52 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMAnimatedString) |
53 | 0 | NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
54 | 0 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
55 | 0 | NS_INTERFACE_MAP_END |
56 | | |
57 | | already_AddRefed<SVGAnimatedString> |
58 | | nsSVGClass::ToDOMAnimatedString(nsSVGElement* aSVGElement) |
59 | 0 | { |
60 | 0 | RefPtr<DOMAnimatedString> result = new DOMAnimatedString(this, aSVGElement); |
61 | 0 | return result.forget(); |
62 | 0 | } |
63 | | |
64 | | /* Implementation */ |
65 | | |
66 | | void |
67 | | nsSVGClass::SetBaseValue(const nsAString& aValue, |
68 | | nsSVGElement *aSVGElement, |
69 | | bool aDoSetAttr) |
70 | 0 | { |
71 | 0 | NS_ASSERTION(aSVGElement, "Null element passed to SetBaseValue"); |
72 | 0 |
|
73 | 0 | aSVGElement->SetMayHaveClass(); |
74 | 0 | if (aDoSetAttr) { |
75 | 0 | aSVGElement->SetAttr(kNameSpaceID_None, nsGkAtoms::_class, aValue, true); |
76 | 0 | } |
77 | 0 | if (mAnimVal) { |
78 | 0 | aSVGElement->AnimationNeedsResample(); |
79 | 0 | } |
80 | 0 | } |
81 | | |
82 | | void |
83 | | nsSVGClass::GetBaseValue(nsAString& aValue, const nsSVGElement *aSVGElement) const |
84 | 0 | { |
85 | 0 | aSVGElement->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, aValue); |
86 | 0 | } |
87 | | |
88 | | void |
89 | | nsSVGClass::GetAnimValue(nsAString& aResult, const nsSVGElement *aSVGElement) const |
90 | 0 | { |
91 | 0 | if (mAnimVal) { |
92 | 0 | aResult = *mAnimVal; |
93 | 0 | return; |
94 | 0 | } |
95 | 0 | |
96 | 0 | aSVGElement->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, aResult); |
97 | 0 | } |
98 | | |
99 | | void |
100 | | nsSVGClass::SetAnimValue(const nsAString& aValue, nsSVGElement *aSVGElement) |
101 | 0 | { |
102 | 0 | if (mAnimVal && mAnimVal->Equals(aValue)) { |
103 | 0 | return; |
104 | 0 | } |
105 | 0 | if (!mAnimVal) { |
106 | 0 | mAnimVal = new nsString(); |
107 | 0 | } |
108 | 0 | *mAnimVal = aValue; |
109 | 0 | aSVGElement->SetMayHaveClass(); |
110 | 0 | aSVGElement->DidAnimateClass(); |
111 | 0 | } |
112 | | |
113 | | void |
114 | | DOMAnimatedString::GetAnimVal(nsAString& aResult) |
115 | 0 | { |
116 | 0 | mSVGElement->FlushAnimations(); |
117 | 0 | mVal->GetAnimValue(aResult, mSVGElement); |
118 | 0 | } |
119 | | |
120 | | UniquePtr<nsISMILAttr> |
121 | | nsSVGClass::ToSMILAttr(nsSVGElement *aSVGElement) |
122 | 0 | { |
123 | 0 | return MakeUnique<SMILString>(this, aSVGElement); |
124 | 0 | } |
125 | | |
126 | | nsresult |
127 | | nsSVGClass::SMILString::ValueFromString(const nsAString& aStr, |
128 | | const dom::SVGAnimationElement* /*aSrcElement*/, |
129 | | nsSMILValue& aValue, |
130 | | bool& aPreventCachingOfSandwich) const |
131 | 0 | { |
132 | 0 | nsSMILValue val(SMILStringType::Singleton()); |
133 | 0 |
|
134 | 0 | *static_cast<nsAString*>(val.mU.mPtr) = aStr; |
135 | 0 | aValue = std::move(val); |
136 | 0 | aPreventCachingOfSandwich = false; |
137 | 0 | return NS_OK; |
138 | 0 | } |
139 | | |
140 | | nsSMILValue |
141 | | nsSVGClass::SMILString::GetBaseValue() const |
142 | 0 | { |
143 | 0 | nsSMILValue val(SMILStringType::Singleton()); |
144 | 0 | mSVGElement->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, |
145 | 0 | *static_cast<nsAString*>(val.mU.mPtr)); |
146 | 0 | return val; |
147 | 0 | } |
148 | | |
149 | | void |
150 | | nsSVGClass::SMILString::ClearAnimValue() |
151 | 0 | { |
152 | 0 | if (mVal->mAnimVal) { |
153 | 0 | mVal->mAnimVal = nullptr; |
154 | 0 | mSVGElement->DidAnimateClass(); |
155 | 0 | } |
156 | 0 | } |
157 | | |
158 | | nsresult |
159 | | nsSVGClass::SMILString::SetAnimValue(const nsSMILValue& aValue) |
160 | 0 | { |
161 | 0 | NS_ASSERTION(aValue.mType == SMILStringType::Singleton(), |
162 | 0 | "Unexpected type to assign animated value"); |
163 | 0 | if (aValue.mType == SMILStringType::Singleton()) { |
164 | 0 | mVal->SetAnimValue(*static_cast<nsAString*>(aValue.mU.mPtr), mSVGElement); |
165 | 0 | } |
166 | 0 | return NS_OK; |
167 | 0 | } |