1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Mozilla SVG Project code.
16 : *
17 : * The Initial Developer of the Original Code is the Mozilla Foundation.
18 : * Portions created by the Initial Developer are Copyright (C) 2010
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : *
23 : * Alternatively, the contents of this file may be used under the terms of
24 : * either the GNU General Public License Version 2 or later (the "GPL"), or
25 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 : * in which case the provisions of the GPL or the LGPL are applicable instead
27 : * of those above. If you wish to allow use of your version of this file only
28 : * under the terms of either the GPL or the LGPL, and not to allow others to
29 : * use your version of this file under the terms of the MPL, indicate your
30 : * decision by deleting the provisions above and replace them with the notice
31 : * and other provisions required by the GPL or the LGPL. If you do not delete
32 : * the provisions above, a recipient may use your version of this file under
33 : * the terms of any one of the MPL, the GPL or the LGPL.
34 : *
35 : * ***** END LICENSE BLOCK ***** */
36 :
37 : #include "DOMSVGAnimatedNumberList.h"
38 : #include "DOMSVGNumberList.h"
39 : #include "SVGAnimatedNumberList.h"
40 : #include "nsSVGElement.h"
41 : #include "nsCOMPtr.h"
42 : #include "nsSVGAttrTearoffTable.h"
43 :
44 : // See the architecture comment in this file's header.
45 :
46 : namespace mozilla {
47 :
48 : static nsSVGAttrTearoffTable<SVGAnimatedNumberList, DOMSVGAnimatedNumberList>
49 1464 : sSVGAnimatedNumberListTearoffTable;
50 :
51 1464 : NS_SVG_VAL_IMPL_CYCLE_COLLECTION(DOMSVGAnimatedNumberList, mElement)
52 :
53 0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMSVGAnimatedNumberList)
54 0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMSVGAnimatedNumberList)
55 :
56 : } // namespace mozilla
57 : DOMCI_DATA(SVGAnimatedNumberList, mozilla::DOMSVGAnimatedNumberList)
58 : namespace mozilla {
59 :
60 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGAnimatedNumberList)
61 0 : NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedNumberList)
62 0 : NS_INTERFACE_MAP_ENTRY(nsISupports)
63 0 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGAnimatedNumberList)
64 0 : NS_INTERFACE_MAP_END
65 :
66 : NS_IMETHODIMP
67 0 : DOMSVGAnimatedNumberList::GetBaseVal(nsIDOMSVGNumberList **_retval)
68 : {
69 0 : if (!mBaseVal) {
70 0 : mBaseVal = new DOMSVGNumberList(this, InternalAList().GetBaseValue());
71 : }
72 0 : NS_ADDREF(*_retval = mBaseVal);
73 0 : return NS_OK;
74 : }
75 :
76 : NS_IMETHODIMP
77 0 : DOMSVGAnimatedNumberList::GetAnimVal(nsIDOMSVGNumberList **_retval)
78 : {
79 0 : if (!mAnimVal) {
80 0 : mAnimVal = new DOMSVGNumberList(this, InternalAList().GetAnimValue());
81 : }
82 0 : NS_ADDREF(*_retval = mAnimVal);
83 0 : return NS_OK;
84 : }
85 :
86 : /* static */ already_AddRefed<DOMSVGAnimatedNumberList>
87 0 : DOMSVGAnimatedNumberList::GetDOMWrapper(SVGAnimatedNumberList *aList,
88 : nsSVGElement *aElement,
89 : PRUint8 aAttrEnum)
90 : {
91 : DOMSVGAnimatedNumberList *wrapper =
92 0 : sSVGAnimatedNumberListTearoffTable.GetTearoff(aList);
93 0 : if (!wrapper) {
94 0 : wrapper = new DOMSVGAnimatedNumberList(aElement, aAttrEnum);
95 0 : sSVGAnimatedNumberListTearoffTable.AddTearoff(aList, wrapper);
96 : }
97 0 : NS_ADDREF(wrapper);
98 0 : return wrapper;
99 : }
100 :
101 : /* static */ DOMSVGAnimatedNumberList*
102 0 : DOMSVGAnimatedNumberList::GetDOMWrapperIfExists(SVGAnimatedNumberList *aList)
103 : {
104 0 : return sSVGAnimatedNumberListTearoffTable.GetTearoff(aList);
105 : }
106 :
107 0 : DOMSVGAnimatedNumberList::~DOMSVGAnimatedNumberList()
108 : {
109 : // Script no longer has any references to us, to our base/animVal objects, or
110 : // to any of their list items.
111 0 : sSVGAnimatedNumberListTearoffTable.RemoveTearoff(&InternalAList());
112 0 : }
113 :
114 : void
115 0 : DOMSVGAnimatedNumberList::InternalBaseValListWillChangeTo(const SVGNumberList& aNewValue)
116 : {
117 : // When the number of items in our internal counterpart's baseVal changes,
118 : // we MUST keep our baseVal in sync. If we don't, script will either see a
119 : // list that is too short and be unable to access indexes that should be
120 : // valid, or else, MUCH WORSE, script will see a list that is too long and be
121 : // able to access "items" at indexes that are out of bounds (read/write to
122 : // bad memory)!!
123 :
124 0 : nsRefPtr<DOMSVGAnimatedNumberList> kungFuDeathGrip;
125 0 : if (mBaseVal) {
126 0 : if (aNewValue.Length() < mBaseVal->Length()) {
127 : // InternalListLengthWillChange might clear last reference to |this|.
128 : // Retain a temporary reference to keep from dying before returning.
129 0 : kungFuDeathGrip = this;
130 : }
131 0 : mBaseVal->InternalListLengthWillChange(aNewValue.Length());
132 : }
133 :
134 : // If our attribute is not animating, then our animVal mirrors our baseVal
135 : // and we must sync its length too. (If our attribute is animating, then the
136 : // SMIL engine takes care of calling InternalAnimValListWillChangeTo() if
137 : // necessary.)
138 :
139 0 : if (!IsAnimating()) {
140 0 : InternalAnimValListWillChangeTo(aNewValue);
141 : }
142 0 : }
143 :
144 : void
145 0 : DOMSVGAnimatedNumberList::InternalAnimValListWillChangeTo(const SVGNumberList& aNewValue)
146 : {
147 0 : if (mAnimVal) {
148 0 : mAnimVal->InternalListLengthWillChange(aNewValue.Length());
149 : }
150 0 : }
151 :
152 : bool
153 0 : DOMSVGAnimatedNumberList::IsAnimating() const
154 : {
155 0 : return InternalAList().IsAnimating();
156 : }
157 :
158 : SVGAnimatedNumberList&
159 0 : DOMSVGAnimatedNumberList::InternalAList()
160 : {
161 0 : return *mElement->GetAnimatedNumberList(mAttrEnum);
162 : }
163 :
164 : const SVGAnimatedNumberList&
165 0 : DOMSVGAnimatedNumberList::InternalAList() const
166 : {
167 0 : return *mElement->GetAnimatedNumberList(mAttrEnum);
168 : }
169 :
170 4392 : } // namespace mozilla
|