/src/mozilla-central/dom/svg/DOMSVGAnimatedNumberList.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 "DOMSVGAnimatedNumberList.h" |
8 | | #include "DOMSVGNumberList.h" |
9 | | #include "SVGAnimatedNumberList.h" |
10 | | #include "nsSVGElement.h" |
11 | | #include "nsCOMPtr.h" |
12 | | #include "nsSVGAttrTearoffTable.h" |
13 | | #include "mozilla/dom/SVGAnimatedNumberListBinding.h" |
14 | | |
15 | | // See the architecture comment in this file's header. |
16 | | |
17 | | namespace mozilla { |
18 | | |
19 | | static inline |
20 | | nsSVGAttrTearoffTable<SVGAnimatedNumberList, DOMSVGAnimatedNumberList>& |
21 | | SVGAnimatedNumberListTearoffTable() |
22 | 0 | { |
23 | 0 | static nsSVGAttrTearoffTable<SVGAnimatedNumberList, DOMSVGAnimatedNumberList> |
24 | 0 | sSVGAnimatedNumberListTearoffTable; |
25 | 0 | return sSVGAnimatedNumberListTearoffTable; |
26 | 0 | } |
27 | | |
28 | | NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(DOMSVGAnimatedNumberList, mElement) |
29 | | |
30 | | NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMSVGAnimatedNumberList) |
31 | | NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMSVGAnimatedNumberList) |
32 | | |
33 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGAnimatedNumberList) |
34 | 0 | NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
35 | 0 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
36 | 0 | NS_INTERFACE_MAP_END |
37 | | |
38 | | JSObject* |
39 | | DOMSVGAnimatedNumberList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
40 | 0 | { |
41 | 0 | return mozilla::dom::SVGAnimatedNumberList_Binding::Wrap(aCx, this, aGivenProto); |
42 | 0 | } |
43 | | |
44 | | already_AddRefed<DOMSVGNumberList> |
45 | | DOMSVGAnimatedNumberList::BaseVal() |
46 | 0 | { |
47 | 0 | if (!mBaseVal) { |
48 | 0 | mBaseVal = new DOMSVGNumberList(this, InternalAList().GetBaseValue()); |
49 | 0 | } |
50 | 0 | RefPtr<DOMSVGNumberList> baseVal = mBaseVal; |
51 | 0 | return baseVal.forget(); |
52 | 0 | } |
53 | | |
54 | | already_AddRefed<DOMSVGNumberList> |
55 | | DOMSVGAnimatedNumberList::AnimVal() |
56 | 0 | { |
57 | 0 | if (!mAnimVal) { |
58 | 0 | mAnimVal = new DOMSVGNumberList(this, InternalAList().GetAnimValue()); |
59 | 0 | } |
60 | 0 | RefPtr<DOMSVGNumberList> animVal = mAnimVal; |
61 | 0 | return animVal.forget(); |
62 | 0 | } |
63 | | |
64 | | /* static */ already_AddRefed<DOMSVGAnimatedNumberList> |
65 | | DOMSVGAnimatedNumberList::GetDOMWrapper(SVGAnimatedNumberList *aList, |
66 | | nsSVGElement *aElement, |
67 | | uint8_t aAttrEnum) |
68 | 0 | { |
69 | 0 | RefPtr<DOMSVGAnimatedNumberList> wrapper = |
70 | 0 | SVGAnimatedNumberListTearoffTable().GetTearoff(aList); |
71 | 0 | if (!wrapper) { |
72 | 0 | wrapper = new DOMSVGAnimatedNumberList(aElement, aAttrEnum); |
73 | 0 | SVGAnimatedNumberListTearoffTable().AddTearoff(aList, wrapper); |
74 | 0 | } |
75 | 0 | return wrapper.forget(); |
76 | 0 | } |
77 | | |
78 | | /* static */ DOMSVGAnimatedNumberList* |
79 | | DOMSVGAnimatedNumberList::GetDOMWrapperIfExists(SVGAnimatedNumberList *aList) |
80 | 0 | { |
81 | 0 | return SVGAnimatedNumberListTearoffTable().GetTearoff(aList); |
82 | 0 | } |
83 | | |
84 | | DOMSVGAnimatedNumberList::~DOMSVGAnimatedNumberList() |
85 | 0 | { |
86 | 0 | // Script no longer has any references to us, to our base/animVal objects, or |
87 | 0 | // to any of their list items. |
88 | 0 | SVGAnimatedNumberListTearoffTable().RemoveTearoff(&InternalAList()); |
89 | 0 | } |
90 | | |
91 | | void |
92 | | DOMSVGAnimatedNumberList::InternalBaseValListWillChangeTo(const SVGNumberList& aNewValue) |
93 | 0 | { |
94 | 0 | // When the number of items in our internal counterpart's baseVal changes, |
95 | 0 | // we MUST keep our baseVal in sync. If we don't, script will either see a |
96 | 0 | // list that is too short and be unable to access indexes that should be |
97 | 0 | // valid, or else, MUCH WORSE, script will see a list that is too long and be |
98 | 0 | // able to access "items" at indexes that are out of bounds (read/write to |
99 | 0 | // bad memory)!! |
100 | 0 |
|
101 | 0 | RefPtr<DOMSVGAnimatedNumberList> kungFuDeathGrip; |
102 | 0 | if (mBaseVal) { |
103 | 0 | if (aNewValue.Length() < mBaseVal->LengthNoFlush()) { |
104 | 0 | // InternalListLengthWillChange might clear last reference to |this|. |
105 | 0 | // Retain a temporary reference to keep from dying before returning. |
106 | 0 | kungFuDeathGrip = this; |
107 | 0 | } |
108 | 0 | mBaseVal->InternalListLengthWillChange(aNewValue.Length()); |
109 | 0 | } |
110 | 0 |
|
111 | 0 | // If our attribute is not animating, then our animVal mirrors our baseVal |
112 | 0 | // and we must sync its length too. (If our attribute is animating, then the |
113 | 0 | // SMIL engine takes care of calling InternalAnimValListWillChangeTo() if |
114 | 0 | // necessary.) |
115 | 0 |
|
116 | 0 | if (!IsAnimating()) { |
117 | 0 | InternalAnimValListWillChangeTo(aNewValue); |
118 | 0 | } |
119 | 0 | } |
120 | | |
121 | | void |
122 | | DOMSVGAnimatedNumberList::InternalAnimValListWillChangeTo(const SVGNumberList& aNewValue) |
123 | 0 | { |
124 | 0 | if (mAnimVal) { |
125 | 0 | mAnimVal->InternalListLengthWillChange(aNewValue.Length()); |
126 | 0 | } |
127 | 0 | } |
128 | | |
129 | | bool |
130 | | DOMSVGAnimatedNumberList::IsAnimating() const |
131 | 0 | { |
132 | 0 | return InternalAList().IsAnimating(); |
133 | 0 | } |
134 | | |
135 | | SVGAnimatedNumberList& |
136 | | DOMSVGAnimatedNumberList::InternalAList() |
137 | 0 | { |
138 | 0 | return *mElement->GetAnimatedNumberList(mAttrEnum); |
139 | 0 | } |
140 | | |
141 | | const SVGAnimatedNumberList& |
142 | | DOMSVGAnimatedNumberList::InternalAList() const |
143 | 0 | { |
144 | 0 | return *mElement->GetAnimatedNumberList(mAttrEnum); |
145 | 0 | } |
146 | | |
147 | | } // namespace mozilla |