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 Communicator client code.
16 : *
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.
21 : *
22 : * Contributor(s):
23 : * Original Author: David W. Hyatt (hyatt@netscape.com)
24 : *
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.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef nsXBLBinding_h_
40 : #define nsXBLBinding_h_
41 :
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"
49 : #include "nsISupportsImpl.h"
50 :
51 : class nsXBLPrototypeBinding;
52 : class nsIContent;
53 : class nsIAtom;
54 : class nsIDocument;
55 : class nsIScriptContext;
56 : class nsObjectHashtable;
57 : class nsXBLInsertionPoint;
58 : typedef nsTArray<nsRefPtr<nsXBLInsertionPoint> > nsInsertionPointList;
59 : struct JSContext;
60 : struct JSObject;
61 :
62 : // *********************************************************************/
63 : // The XBLBinding class
64 :
65 : class nsXBLBinding
66 : {
67 : public:
68 : nsXBLBinding(nsXBLPrototypeBinding* aProtoBinding);
69 : ~nsXBLBinding();
70 :
71 : /**
72 : * XBLBindings are refcounted. They are held onto in 3 ways:
73 : * 1. The binding manager's binding table holds onto all bindings that are
74 : * currently attached to a content node.
75 : * 2. Bindings hold onto their base binding. This is important since
76 : * the base binding itself may not be attached to anything.
77 : * 3. The binding manager holds an additional reference to bindings
78 : * which are queued to fire their constructors.
79 : */
80 :
81 0 : NS_INLINE_DECL_REFCOUNTING(nsXBLBinding)
82 :
83 : NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsXBLBinding)
84 :
85 0 : nsXBLPrototypeBinding* PrototypeBinding() { return mPrototypeBinding; }
86 0 : nsIContent* GetAnonymousContent() { return mContent.get(); }
87 :
88 0 : nsXBLBinding* GetBaseBinding() { return mNextBinding; }
89 : void SetBaseBinding(nsXBLBinding *aBinding);
90 :
91 0 : nsIContent* GetBoundElement() { return mBoundElement; }
92 : void SetBoundElement(nsIContent *aElement);
93 :
94 : bool IsStyleBinding() const { return mIsStyleBinding; }
95 : void SetIsStyleBinding(bool aIsStyle) { mIsStyleBinding = aIsStyle; }
96 :
97 : void MarkForDeath();
98 : bool MarkedForDeath() const { return mMarkedForDeath; }
99 :
100 : bool HasStyleSheets() const;
101 : bool InheritsStyle() const;
102 : bool ImplementsInterface(REFNSIID aIID) const;
103 :
104 : void GenerateAnonymousContent();
105 : void InstallAnonymousContent(nsIContent* aAnonParent, nsIContent* aElement);
106 : static void UninstallAnonymousContent(nsIDocument* aDocument,
107 : nsIContent* aAnonParent);
108 : void InstallEventHandlers();
109 : nsresult InstallImplementation();
110 :
111 : void ExecuteAttachedHandler();
112 : void ExecuteDetachedHandler();
113 : void UnhookEventHandlers();
114 :
115 : nsIAtom* GetBaseTag(PRInt32* aNameSpaceID);
116 : nsXBLBinding* RootBinding();
117 : nsXBLBinding* GetFirstStyleBinding();
118 :
119 : // Resolve all the fields for this binding and all ancestor bindings on the
120 : // object |obj|. False return means a JS exception was set.
121 : bool ResolveAllFields(JSContext *cx, JSObject *obj) const;
122 :
123 : // Get the list of insertion points for aParent. The nsInsertionPointList
124 : // is owned by the binding, you should not delete it.
125 : nsresult GetInsertionPointsFor(nsIContent* aParent,
126 : nsInsertionPointList** aResult);
127 :
128 : nsInsertionPointList* GetExistingInsertionPointsFor(nsIContent* aParent);
129 :
130 : // XXXbz this aIndex has nothing to do with an index into the child
131 : // list of the insertion parent or anything.
132 : nsIContent* GetInsertionPoint(const nsIContent* aChild, PRUint32* aIndex);
133 :
134 : nsIContent* GetSingleInsertionPoint(PRUint32* aIndex,
135 : bool* aMultipleInsertionPoints);
136 :
137 : void AttributeChanged(nsIAtom* aAttribute, PRInt32 aNameSpaceID,
138 : bool aRemoveFlag, bool aNotify);
139 :
140 : void ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocument);
141 :
142 : void WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, void* aData);
143 :
144 : nsINodeList* GetAnonymousNodes();
145 :
146 : static nsresult DoInitJSClass(JSContext *cx, JSObject *global, JSObject *obj,
147 : const nsAFlatCString& aClassName,
148 : nsXBLPrototypeBinding* aProtoBinding,
149 : JSObject** aClassObject);
150 :
151 : bool AllowScripts(); // XXX make const
152 :
153 : void RemoveInsertionParent(nsIContent* aParent);
154 : bool HasInsertionParent(nsIContent* aParent);
155 :
156 : // MEMBER VARIABLES
157 : protected:
158 :
159 : nsXBLPrototypeBinding* mPrototypeBinding; // Weak, but we're holding a ref to the docinfo
160 : nsCOMPtr<nsIContent> mContent; // Strong. Our anonymous content stays around with us.
161 : nsRefPtr<nsXBLBinding> mNextBinding; // Strong. The derived binding owns the base class bindings.
162 :
163 : nsIContent* mBoundElement; // [WEAK] We have a reference, but we don't own it.
164 :
165 : // A hash from nsIContent* -> (a sorted array of nsXBLInsertionPoint)
166 : nsClassHashtable<nsISupportsHashKey, nsInsertionPointList>* mInsertionPointTable;
167 :
168 : bool mIsStyleBinding;
169 : bool mMarkedForDeath;
170 : };
171 :
172 : #endif // nsXBLBinding_h_
|