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 "DOMSVGAnimatedLengthList.h"
38 : #include "DOMSVGLengthList.h"
39 : #include "SVGAnimatedLengthList.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<SVGAnimatedLengthList, DOMSVGAnimatedLengthList>
49 1464 : sSVGAnimatedLengthListTearoffTable;
50 :
51 1464 : NS_SVG_VAL_IMPL_CYCLE_COLLECTION(DOMSVGAnimatedLengthList, mElement)
52 :
53 0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMSVGAnimatedLengthList)
54 0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMSVGAnimatedLengthList)
55 :
56 : } // namespace mozilla
57 : DOMCI_DATA(SVGAnimatedLengthList, mozilla::DOMSVGAnimatedLengthList)
58 : namespace mozilla {
59 :
60 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGAnimatedLengthList)
61 0 : NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedLengthList)
62 0 : NS_INTERFACE_MAP_ENTRY(nsISupports)
63 0 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGAnimatedLengthList)
64 0 : NS_INTERFACE_MAP_END
65 :
66 : NS_IMETHODIMP
67 0 : DOMSVGAnimatedLengthList::GetBaseVal(nsIDOMSVGLengthList **_retval)
68 : {
69 0 : if (!mBaseVal) {
70 0 : mBaseVal = new DOMSVGLengthList(this, InternalAList().GetBaseValue());
71 : }
72 0 : NS_ADDREF(*_retval = mBaseVal);
73 0 : return NS_OK;
74 : }
75 :
76 : NS_IMETHODIMP
77 0 : DOMSVGAnimatedLengthList::GetAnimVal(nsIDOMSVGLengthList **_retval)
78 : {
79 0 : if (!mAnimVal) {
80 0 : mAnimVal = new DOMSVGLengthList(this, InternalAList().GetAnimValue());
81 : }
82 0 : NS_ADDREF(*_retval = mAnimVal);
83 0 : return NS_OK;
84 : }
85 :
86 : /* static */ already_AddRefed<DOMSVGAnimatedLengthList>
87 0 : DOMSVGAnimatedLengthList::GetDOMWrapper(SVGAnimatedLengthList *aList,
88 : nsSVGElement *aElement,
89 : PRUint8 aAttrEnum,
90 : PRUint8 aAxis)
91 : {
92 : DOMSVGAnimatedLengthList *wrapper =
93 0 : sSVGAnimatedLengthListTearoffTable.GetTearoff(aList);
94 0 : if (!wrapper) {
95 0 : wrapper = new DOMSVGAnimatedLengthList(aElement, aAttrEnum, aAxis);
96 0 : sSVGAnimatedLengthListTearoffTable.AddTearoff(aList, wrapper);
97 : }
98 0 : NS_ADDREF(wrapper);
99 0 : return wrapper;
100 : }
101 :
102 : /* static */ DOMSVGAnimatedLengthList*
103 0 : DOMSVGAnimatedLengthList::GetDOMWrapperIfExists(SVGAnimatedLengthList *aList)
104 : {
105 0 : return sSVGAnimatedLengthListTearoffTable.GetTearoff(aList);
106 : }
107 :
108 0 : DOMSVGAnimatedLengthList::~DOMSVGAnimatedLengthList()
109 : {
110 : // Script no longer has any references to us, to our base/animVal objects, or
111 : // to any of their list items.
112 0 : sSVGAnimatedLengthListTearoffTable.RemoveTearoff(&InternalAList());
113 0 : }
114 :
115 : void
116 0 : DOMSVGAnimatedLengthList::InternalBaseValListWillChangeTo(const SVGLengthList& aNewValue)
117 : {
118 : // When the number of items in our internal counterpart's baseVal changes,
119 : // we MUST keep our baseVal in sync. If we don't, script will either see a
120 : // list that is too short and be unable to access indexes that should be
121 : // valid, or else, MUCH WORSE, script will see a list that is too long and be
122 : // able to access "items" at indexes that are out of bounds (read/write to
123 : // bad memory)!!
124 :
125 0 : nsRefPtr<DOMSVGAnimatedLengthList> kungFuDeathGrip;
126 0 : if (mBaseVal) {
127 0 : if (aNewValue.Length() < mBaseVal->Length()) {
128 : // InternalListLengthWillChange might clear last reference to |this|.
129 : // Retain a temporary reference to keep from dying before returning.
130 0 : kungFuDeathGrip = this;
131 : }
132 0 : mBaseVal->InternalListLengthWillChange(aNewValue.Length());
133 : }
134 :
135 : // If our attribute is not animating, then our animVal mirrors our baseVal
136 : // and we must sync its length too. (If our attribute is animating, then the
137 : // SMIL engine takes care of calling InternalAnimValListWillChangeTo() if
138 : // necessary.)
139 :
140 0 : if (!IsAnimating()) {
141 0 : InternalAnimValListWillChangeTo(aNewValue);
142 : }
143 0 : }
144 :
145 : void
146 0 : DOMSVGAnimatedLengthList::InternalAnimValListWillChangeTo(const SVGLengthList& aNewValue)
147 : {
148 0 : if (mAnimVal) {
149 0 : mAnimVal->InternalListLengthWillChange(aNewValue.Length());
150 : }
151 0 : }
152 :
153 : bool
154 0 : DOMSVGAnimatedLengthList::IsAnimating() const
155 : {
156 0 : return InternalAList().IsAnimating();
157 : }
158 :
159 : SVGAnimatedLengthList&
160 0 : DOMSVGAnimatedLengthList::InternalAList()
161 : {
162 0 : return *mElement->GetAnimatedLengthList(mAttrEnum);
163 : }
164 :
165 : const SVGAnimatedLengthList&
166 0 : DOMSVGAnimatedLengthList::InternalAList() const
167 : {
168 0 : return *mElement->GetAnimatedLengthList(mAttrEnum);
169 : }
170 :
171 4392 : } // namespace mozilla
|