Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / content / xbl / src / nsXBLBinding.h
blobc61f18bb2b1f54749658d9bb98ab199b798b3757
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 "nsIDOMNodeList.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;
119 PRBool ShouldBuildChildFrames() const;
121 void GenerateAnonymousContent();
122 void InstallAnonymousContent(nsIContent* aAnonParent, nsIContent* aElement);
123 void InstallEventHandlers();
124 nsresult InstallImplementation();
126 void ExecuteAttachedHandler();
127 void ExecuteDetachedHandler();
128 void UnhookEventHandlers();
130 nsIAtom* GetBaseTag(PRInt32* aNameSpaceID);
131 nsXBLBinding* RootBinding();
132 nsXBLBinding* GetFirstStyleBinding();
134 // Resolve all the fields for this binding and all ancestor bindings on the
135 // object |obj|. False return means a JS exception was set.
136 PRBool ResolveAllFields(JSContext *cx, JSObject *obj) const;
138 // Get the list of insertion points for aParent. The nsInsertionPointList
139 // is owned by the binding, you should not delete it.
140 nsresult GetInsertionPointsFor(nsIContent* aParent,
141 nsInsertionPointList** aResult);
143 nsInsertionPointList* GetExistingInsertionPointsFor(nsIContent* aParent);
145 nsIContent* GetInsertionPoint(nsIContent* aChild, PRUint32* aIndex);
147 nsIContent* GetSingleInsertionPoint(PRUint32* aIndex,
148 PRBool* aMultipleInsertionPoints);
150 void AttributeChanged(nsIAtom* aAttribute, PRInt32 aNameSpaceID,
151 PRBool aRemoveFlag, PRBool aNotify);
153 void ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocument);
155 void WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, void* aData);
157 already_AddRefed<nsIDOMNodeList> GetAnonymousNodes();
159 static nsresult DoInitJSClass(JSContext *cx, JSObject *global, JSObject *obj,
160 const nsAFlatCString& aClassName,
161 nsXBLPrototypeBinding* aProtoBinding,
162 void **aClassObject);
164 PRBool AllowScripts(); // XXX make const
166 void RemoveInsertionParent(nsIContent* aParent);
167 PRBool HasInsertionParent(nsIContent* aParent);
169 // MEMBER VARIABLES
170 protected:
172 nsAutoRefCnt mRefCnt;
173 nsXBLPrototypeBinding* mPrototypeBinding; // Weak, but we're holding a ref to the docinfo
174 nsCOMPtr<nsIContent> mContent; // Strong. Our anonymous content stays around with us.
175 nsRefPtr<nsXBLBinding> mNextBinding; // Strong. The derived binding owns the base class bindings.
177 nsIContent* mBoundElement; // [WEAK] We have a reference, but we don't own it.
179 // A hash from nsIContent* -> (a sorted array of nsXBLInsertionPoint)
180 nsClassHashtable<nsISupportsHashKey, nsInsertionPointList>* mInsertionPointTable;
182 PRPackedBool mIsStyleBinding;
183 PRPackedBool mMarkedForDeath;
186 #endif // nsXBLBinding_h_