dom/xbl/nsXBLBinding.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:c5903b2f4e92
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #ifndef nsXBLBinding_h_
7 #define nsXBLBinding_h_
8
9 #include "nsXBLService.h"
10 #include "nsCOMPtr.h"
11 #include "nsAutoPtr.h"
12 #include "nsINodeList.h"
13 #include "nsIStyleRuleProcessor.h"
14 #include "nsClassHashtable.h"
15 #include "nsTArray.h"
16 #include "nsCycleCollectionParticipant.h"
17 #include "nsISupportsImpl.h"
18 #include "js/TypeDecls.h"
19
20 class nsXBLPrototypeBinding;
21 class nsIContent;
22 class nsIAtom;
23 class nsIDocument;
24 class nsIScriptContext;
25
26 namespace mozilla {
27 namespace dom {
28
29 class ShadowRoot;
30 class XBLChildrenElement;
31
32 } // namespace dom
33 } // namespace mozilla
34
35 class nsAnonymousContentList;
36
37 // *********************************************************************/
38 // The XBLBinding class
39
40 class nsXBLBinding MOZ_FINAL
41 {
42 public:
43 nsXBLBinding(nsXBLPrototypeBinding* aProtoBinding);
44 nsXBLBinding(mozilla::dom::ShadowRoot* aShadowRoot, nsXBLPrototypeBinding* aProtoBinding);
45 ~nsXBLBinding();
46
47 /**
48 * XBLBindings are refcounted. They are held onto in 3 ways:
49 * 1. The binding manager's binding table holds onto all bindings that are
50 * currently attached to a content node.
51 * 2. Bindings hold onto their base binding. This is important since
52 * the base binding itself may not be attached to anything.
53 * 3. The binding manager holds an additional reference to bindings
54 * which are queued to fire their constructors.
55 */
56
57 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsXBLBinding)
58
59 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsXBLBinding)
60
61 nsXBLPrototypeBinding* PrototypeBinding() const { return mPrototypeBinding; }
62 nsIContent* GetAnonymousContent() { return mContent.get(); }
63 nsXBLBinding* GetBindingWithContent();
64
65 nsXBLBinding* GetBaseBinding() const { return mNextBinding; }
66 void SetBaseBinding(nsXBLBinding *aBinding);
67
68 nsIContent* GetBoundElement() { return mBoundElement; }
69 void SetBoundElement(nsIContent *aElement);
70
71 /*
72 * Does a lookup for a method or attribute provided by one of the bindings'
73 * prototype implementation. If found, |desc| will be set up appropriately,
74 * and wrapped into cx->compartment.
75 *
76 * May only be called when XBL code is being run in a separate scope, because
77 * otherwise we don't have untainted data with which to do a proper lookup.
78 */
79 bool LookupMember(JSContext* aCx, JS::Handle<jsid> aId,
80 JS::MutableHandle<JSPropertyDescriptor> aDesc);
81
82 /*
83 * Determines whether the binding has a field with the given name.
84 */
85 bool HasField(nsString& aName);
86
87 protected:
88
89 /*
90 * Internal version. Requires that aCx is in appropriate xbl scope.
91 */
92 bool LookupMemberInternal(JSContext* aCx, nsString& aName,
93 JS::Handle<jsid> aNameAsId,
94 JS::MutableHandle<JSPropertyDescriptor> aDesc,
95 JS::Handle<JSObject*> aXBLScope);
96
97 public:
98
99 void MarkForDeath();
100 bool MarkedForDeath() const { return mMarkedForDeath; }
101
102 bool HasStyleSheets() const;
103 bool InheritsStyle() const;
104 bool ImplementsInterface(REFNSIID aIID) const;
105
106 void GenerateAnonymousContent();
107 void InstallAnonymousContent(nsIContent* aAnonParent, nsIContent* aElement,
108 bool aNativeAnon);
109 static void UninstallAnonymousContent(nsIDocument* aDocument,
110 nsIContent* aAnonParent);
111 void InstallEventHandlers();
112 nsresult InstallImplementation();
113
114 void ExecuteAttachedHandler();
115 void ExecuteDetachedHandler();
116 void UnhookEventHandlers();
117
118 nsIAtom* GetBaseTag(int32_t* aNameSpaceID);
119 nsXBLBinding* RootBinding();
120
121 // Resolve all the fields for this binding and all ancestor bindings on the
122 // object |obj|. False return means a JS exception was set.
123 bool ResolveAllFields(JSContext *cx, JS::Handle<JSObject*> obj) const;
124
125 void AttributeChanged(nsIAtom* aAttribute, int32_t aNameSpaceID,
126 bool aRemoveFlag, bool aNotify);
127
128 void ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocument);
129
130 void WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, void* aData);
131
132 static nsresult DoInitJSClass(JSContext *cx, JS::Handle<JSObject*> obj,
133 const nsAFlatCString& aClassName,
134 nsXBLPrototypeBinding* aProtoBinding,
135 JS::MutableHandle<JSObject*> aClassObject,
136 bool* aNew);
137
138 bool AllowScripts();
139
140 mozilla::dom::XBLChildrenElement* FindInsertionPointFor(nsIContent* aChild);
141
142 bool HasFilteredInsertionPoints()
143 {
144 return !mInsertionPoints.IsEmpty();
145 }
146
147 mozilla::dom::XBLChildrenElement* GetDefaultInsertionPoint()
148 {
149 return mDefaultInsertionPoint;
150 }
151
152 // Removes all inserted node from <xbl:children> insertion points under us.
153 void ClearInsertionPoints();
154
155 // Returns a live node list that iterates over the anonymous nodes generated
156 // by this binding.
157 nsAnonymousContentList* GetAnonymousNodeList();
158
159 // MEMBER VARIABLES
160 protected:
161
162 bool mMarkedForDeath;
163 bool mUsingXBLScope;
164
165 nsXBLPrototypeBinding* mPrototypeBinding; // Weak, but we're holding a ref to the docinfo
166 nsCOMPtr<nsIContent> mContent; // Strong. Our anonymous content stays around with us.
167 nsRefPtr<nsXBLBinding> mNextBinding; // Strong. The derived binding owns the base class bindings.
168
169 nsIContent* mBoundElement; // [WEAK] We have a reference, but we don't own it.
170
171 // The <xbl:children> elements that we found in our <xbl:content> when we
172 // processed this binding. The default insertion point has no includes
173 // attribute and all other insertion points must have at least one includes
174 // attribute. These points must be up-to-date with respect to their parent's
175 // children, even if their parent has another binding attached to it,
176 // preventing us from rendering their contents directly.
177 nsRefPtr<mozilla::dom::XBLChildrenElement> mDefaultInsertionPoint;
178 nsTArray<nsRefPtr<mozilla::dom::XBLChildrenElement> > mInsertionPoints;
179 nsRefPtr<nsAnonymousContentList> mAnonymousContentList;
180
181 mozilla::dom::XBLChildrenElement* FindInsertionPointForInternal(nsIContent* aChild);
182 };
183
184 #endif // nsXBLBinding_h_

mercurial