1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is the Mozilla SVG project.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Crocodile Clips Ltd..
20 : * Portions created by the Initial Developer are Copyright (C) 2001
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
25 : * Brian Birtles <birtles@gmail.com>
26 : *
27 : * Alternatively, the contents of this file may be used under the terms of
28 : * either of the GNU General Public License Version 2 or later (the "GPL"),
29 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 : * in which case the provisions of the GPL or the LGPL are applicable instead
31 : * of those above. If you wish to allow use of your version of this file only
32 : * under the terms of either the GPL or the LGPL, and not to allow others to
33 : * use your version of this file under the terms of the MPL, indicate your
34 : * decision by deleting the provisions above and replace them with the notice
35 : * and other provisions required by the GPL or the LGPL. If you do not delete
36 : * the provisions above, a recipient may use your version of this file under
37 : * the terms of any one of the MPL, the GPL or the LGPL.
38 : *
39 : * ***** END LICENSE BLOCK ***** */
40 :
41 : #ifndef MOZILLA_DOMSVGTRANSFORMLIST_H__
42 : #define MOZILLA_DOMSVGTRANSFORMLIST_H__
43 :
44 : #include "DOMSVGAnimatedTransformList.h"
45 : #include "nsAutoPtr.h"
46 : #include "nsCycleCollectionParticipant.h"
47 : #include "nsDebug.h"
48 : #include "nsIDOMSVGTransformList.h"
49 : #include "nsTArray.h"
50 : #include "SVGTransformList.h"
51 :
52 : class nsIDOMSVGTransform;
53 : class nsSVGElement;
54 :
55 : namespace mozilla {
56 :
57 : class DOMSVGTransform;
58 :
59 : /**
60 : * Class DOMSVGTransformList
61 : *
62 : * This class is used to create the DOM tearoff objects that wrap internal
63 : * SVGTransformList objects.
64 : *
65 : * See the architecture comment in DOMSVGAnimatedTransformList.h.
66 : */
67 : class DOMSVGTransformList : public nsIDOMSVGTransformList,
68 : public nsWrapperCache
69 : {
70 : friend class DOMSVGTransform;
71 :
72 : public:
73 0 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
74 1464 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMSVGTransformList)
75 : NS_DECL_NSIDOMSVGTRANSFORMLIST
76 :
77 0 : DOMSVGTransformList(DOMSVGAnimatedTransformList *aAList,
78 : const SVGTransformList &aInternalList)
79 0 : : mAList(aAList)
80 : {
81 0 : SetIsProxy();
82 :
83 : // aInternalList must be passed in explicitly because we can't use
84 : // InternalList() here. (Because it depends on IsAnimValList, which depends
85 : // on this object having been assigned to aAList's mBaseVal or mAnimVal,
86 : // which hasn't happend yet.)
87 :
88 0 : InternalListLengthWillChange(aInternalList.Length()); // Sync mItems
89 0 : }
90 :
91 0 : ~DOMSVGTransformList() {
92 : // Our mAList's weak ref to us must be nulled out when we die. If GC has
93 : // unlinked us using the cycle collector code, then that has already
94 : // happened, and mAList is null.
95 0 : if (mAList) {
96 0 : ( IsAnimValList() ? mAList->mAnimVal : mAList->mBaseVal ) = nsnull;
97 : }
98 0 : }
99 :
100 : virtual JSObject* WrapObject(JSContext *cx, XPCWrappedNativeScope *scope,
101 : bool *triedToWrap);
102 :
103 0 : nsISupports* GetParentObject()
104 : {
105 0 : return static_cast<nsIContent*>(Element());
106 : }
107 :
108 : /**
109 : * This will normally be the same as InternalList().Length(), except if we've
110 : * hit OOM in which case our length will be zero.
111 : */
112 0 : PRUint32 Length() const {
113 0 : NS_ABORT_IF_FALSE(mItems.IsEmpty() ||
114 : mItems.Length() == InternalList().Length(),
115 : "DOM wrapper's list length is out of sync");
116 0 : return mItems.Length();
117 : }
118 :
119 : /// Called to notify us to synchronize our length and detach excess items.
120 : void InternalListLengthWillChange(PRUint32 aNewLength);
121 :
122 : private:
123 :
124 0 : nsSVGElement* Element() const {
125 0 : return mAList->mElement;
126 : }
127 :
128 : /// Used to determine if this list is the baseVal or animVal list.
129 0 : bool IsAnimValList() const {
130 0 : NS_ABORT_IF_FALSE(this == mAList->mBaseVal || this == mAList->mAnimVal,
131 : "Calling IsAnimValList() too early?!");
132 0 : return this == mAList->mAnimVal;
133 : }
134 :
135 : /**
136 : * Get a reference to this object's corresponding internal SVGTransformList.
137 : *
138 : * To simplify the code we just have this one method for obtaining both
139 : * baseVal and animVal internal lists. This means that animVal lists don't
140 : * get const protection, but our setter methods guard against changing
141 : * animVal lists.
142 : */
143 : SVGTransformList& InternalList() const;
144 :
145 : /// Creates a DOMSVGTransform for aIndex, if it doesn't already exist.
146 : void EnsureItemAt(PRUint32 aIndex);
147 :
148 : void MaybeInsertNullInAnimValListAt(PRUint32 aIndex);
149 : void MaybeRemoveItemFromAnimValListAt(PRUint32 aIndex);
150 :
151 : // Weak refs to our DOMSVGTransform items. The items are friends and take care
152 : // of clearing our pointer to them when they die.
153 : nsTArray<DOMSVGTransform*> mItems;
154 :
155 : nsRefPtr<DOMSVGAnimatedTransformList> mAList;
156 : };
157 :
158 : } // namespace mozilla
159 :
160 : #endif // MOZILLA_DOMSVGTRANSFORMLIST_H__
|