Bug 502567. Get rid of the silly ShouldBuildChildFrames check. r=neil
[mozilla-central.git] / content / xbl / src / nsXBLBinding.h
blob492c9757ee5df40e30b476c1df8d22e1717cbd28
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
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/
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.
15 * The Original Code is Mozilla Communicator client code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Original Author: David W. Hyatt (hyatt@netscape.com)
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef nsXBLBinding_h_
40 #define nsXBLBinding_h_
42 #include "nsCOMPtr.h"
43 #include "nsAutoPtr.h"
44 #include "nsINodeList.h"
45 #include "nsIStyleRuleProcessor.h"
46 #include "nsClassHashtable.h"
47 #include "nsTArray.h"
48 #include "nsCycleCollectionParticipant.h"
50 class nsXBLPrototypeBinding;
51 class nsIContent;
52 class nsIAtom;
53 class nsIDocument;
54 class nsIScriptContext;
55 class nsObjectHashtable;
56 class nsXBLInsertionPoint;
57 typedef nsTArray<nsRefPtr<nsXBLInsertionPoint> > nsInsertionPointList;
58 struct JSContext;
59 struct JSObject;
61 // *********************************************************************/
62 // The XBLBinding class
64 class nsXBLBinding
66 public:
67 nsXBLBinding(nsXBLPrototypeBinding* aProtoBinding);
68 ~nsXBLBinding();
70 /**
71 * XBLBindings are refcounted. They are held onto in 3 ways:
72 * 1. The binding manager's binding table holds onto all bindings that are
73 * currently attached to a content node.
74 * 2. Bindings hold onto their base binding. This is important since
75 * the base binding itself may not be attached to anything.
76 * 3. The binding manager holds an additional reference to bindings
77 * which are queued to fire their constructors.
80 nsrefcnt AddRef()
82 ++mRefCnt;
83 NS_LOG_ADDREF(this, mRefCnt, "nsXBLBinding", sizeof(nsXBLBinding));
84 return mRefCnt;
87 nsrefcnt Release()
89 --mRefCnt;
90 NS_LOG_RELEASE(this, mRefCnt, "nsXBLBinding");
91 if (mRefCnt == 0) {
92 mRefCnt = 1;
93 delete this;
94 return 0;
96 return mRefCnt;
99 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsXBLBinding)
101 nsXBLPrototypeBinding* PrototypeBinding() { return mPrototypeBinding; }
102 nsIContent* GetAnonymousContent() { return mContent.get(); }
104 nsXBLBinding* GetBaseBinding() { return mNextBinding; }
105 void SetBaseBinding(nsXBLBinding *aBinding);
107 nsIContent* GetBoundElement() { return mBoundElement; }
108 void SetBoundElement(nsIContent *aElement);
110 PRBool IsStyleBinding() const { return mIsStyleBinding; }
111 void SetIsStyleBinding(PRBool aIsStyle) { mIsStyleBinding = aIsStyle; }
113 void MarkForDeath();
114 PRBool MarkedForDeath() const { return mMarkedForDeath; }
116 PRBool HasStyleSheets() const;
117 PRBool InheritsStyle() const;
118 PRBool ImplementsInterface(REFNSIID aIID) const;
120 void GenerateAnonymousContent();
121 void InstallAnonymousContent(nsIContent* aAnonParent, nsIContent* aElement);
122 static void UninstallAnonymousContent(nsIDocument* aDocument,
123 nsIContent* aAnonParent);
124 void InstallEventHandlers();
125 nsresult InstallImplementation();
127 void ExecuteAttachedHandler();
128 void ExecuteDetachedHandler();
129 void UnhookEventHandlers();
131 nsIAtom* GetBaseTag(PRInt32* aNameSpaceID);
132 nsXBLBinding* RootBinding();
133 nsXBLBinding* GetFirstStyleBinding();
135 // Resolve all the fields for this binding and all ancestor bindings on the
136 // object |obj|. False return means a JS exception was set.
137 PRBool ResolveAllFields(JSContext *cx, JSObject *obj) const;
139 // Get the list of insertion points for aParent. The nsInsertionPointList
140 // is owned by the binding, you should not delete it.
141 nsresult GetInsertionPointsFor(nsIContent* aParent,
142 nsInsertionPointList** aResult);
144 nsInsertionPointList* GetExistingInsertionPointsFor(nsIContent* aParent);
146 // XXXbz this aIndex has nothing to do with an index into the child
147 // list of the insertion parent or anything.
148 nsIContent* GetInsertionPoint(nsIContent* aChild, PRUint32* aIndex);
150 nsIContent* GetSingleInsertionPoint(PRUint32* aIndex,
151 PRBool* aMultipleInsertionPoints);
153 void AttributeChanged(nsIAtom* aAttribute, PRInt32 aNameSpaceID,
154 PRBool aRemoveFlag, PRBool aNotify);
156 void ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocument);
158 void WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, void* aData);
160 nsINodeList* GetAnonymousNodes();
162 static nsresult DoInitJSClass(JSContext *cx, JSObject *global, JSObject *obj,
163 const nsAFlatCString& aClassName,
164 nsXBLPrototypeBinding* aProtoBinding,
165 void **aClassObject);
167 PRBool AllowScripts(); // XXX make const
169 void RemoveInsertionParent(nsIContent* aParent);
170 PRBool HasInsertionParent(nsIContent* aParent);
172 // MEMBER VARIABLES
173 protected:
175 nsAutoRefCnt mRefCnt;
176 nsXBLPrototypeBinding* mPrototypeBinding; // Weak, but we're holding a ref to the docinfo
177 nsCOMPtr<nsIContent> mContent; // Strong. Our anonymous content stays around with us.
178 nsRefPtr<nsXBLBinding> mNextBinding; // Strong. The derived binding owns the base class bindings.
180 nsIContent* mBoundElement; // [WEAK] We have a reference, but we don't own it.
182 // A hash from nsIContent* -> (a sorted array of nsXBLInsertionPoint)
183 nsClassHashtable<nsISupportsHashKey, nsInsertionPointList>* mInsertionPointTable;
185 PRPackedBool mIsStyleBinding;
186 PRPackedBool mMarkedForDeath;
189 #endif // nsXBLBinding_h_