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/. */
6 #ifndef nsXBLBinding_h_
7 #define nsXBLBinding_h_
9 #include "nsXBLService.h"
11 #include "nsAutoPtr.h"
12 #include "nsINodeList.h"
13 #include "nsIStyleRuleProcessor.h"
14 #include "nsClassHashtable.h"
16 #include "nsCycleCollectionParticipant.h"
17 #include "nsISupportsImpl.h"
18 #include "js/TypeDecls.h"
20 class nsXBLPrototypeBinding
;
24 class nsIScriptContext
;
30 class XBLChildrenElement
;
33 } // namespace mozilla
35 class nsAnonymousContentList
;
37 // *********************************************************************/
38 // The XBLBinding class
40 class nsXBLBinding MOZ_FINAL
43 explicit nsXBLBinding(nsXBLPrototypeBinding
* aProtoBinding
);
44 nsXBLBinding(mozilla::dom::ShadowRoot
* aShadowRoot
, nsXBLPrototypeBinding
* aProtoBinding
);
47 * XBLBindings are refcounted. They are held onto in 3 ways:
48 * 1. The binding manager's binding table holds onto all bindings that are
49 * currently attached to a content node.
50 * 2. Bindings hold onto their base binding. This is important since
51 * the base binding itself may not be attached to anything.
52 * 3. The binding manager holds an additional reference to bindings
53 * which are queued to fire their constructors.
56 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsXBLBinding
)
58 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsXBLBinding
)
60 nsXBLPrototypeBinding
* PrototypeBinding() const { return mPrototypeBinding
; }
61 nsIContent
* GetAnonymousContent() { return mContent
.get(); }
62 nsXBLBinding
* GetBindingWithContent();
64 nsXBLBinding
* GetBaseBinding() const { return mNextBinding
; }
65 void SetBaseBinding(nsXBLBinding
*aBinding
);
67 nsIContent
* GetBoundElement() { return mBoundElement
; }
68 void SetBoundElement(nsIContent
*aElement
);
71 * Does a lookup for a method or attribute provided by one of the bindings'
72 * prototype implementation. If found, |desc| will be set up appropriately,
73 * and wrapped into cx->compartment.
75 * May only be called when XBL code is being run in a separate scope, because
76 * otherwise we don't have untainted data with which to do a proper lookup.
78 bool LookupMember(JSContext
* aCx
, JS::Handle
<jsid
> aId
,
79 JS::MutableHandle
<JSPropertyDescriptor
> aDesc
);
82 * Determines whether the binding has a field with the given name.
84 bool HasField(nsString
& aName
);
91 * Internal version. Requires that aCx is in appropriate xbl scope.
93 bool LookupMemberInternal(JSContext
* aCx
, nsString
& aName
,
94 JS::Handle
<jsid
> aNameAsId
,
95 JS::MutableHandle
<JSPropertyDescriptor
> aDesc
,
96 JS::Handle
<JSObject
*> aXBLScope
);
101 bool MarkedForDeath() const { return mMarkedForDeath
; }
103 bool HasStyleSheets() const;
104 bool InheritsStyle() const;
105 bool ImplementsInterface(REFNSIID aIID
) const;
107 void GenerateAnonymousContent();
108 void InstallAnonymousContent(nsIContent
* aAnonParent
, nsIContent
* aElement
,
110 static void UninstallAnonymousContent(nsIDocument
* aDocument
,
111 nsIContent
* aAnonParent
);
112 void InstallEventHandlers();
113 nsresult
InstallImplementation();
115 void ExecuteAttachedHandler();
116 void ExecuteDetachedHandler();
117 void UnhookEventHandlers();
119 nsIAtom
* GetBaseTag(int32_t* aNameSpaceID
);
120 nsXBLBinding
* RootBinding();
122 // Resolve all the fields for this binding and all ancestor bindings on the
123 // object |obj|. False return means a JS exception was set.
124 bool ResolveAllFields(JSContext
*cx
, JS::Handle
<JSObject
*> obj
) const;
126 void AttributeChanged(nsIAtom
* aAttribute
, int32_t aNameSpaceID
,
127 bool aRemoveFlag
, bool aNotify
);
129 void ChangeDocument(nsIDocument
* aOldDocument
, nsIDocument
* aNewDocument
);
131 void WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc
, void* aData
);
133 static nsresult
DoInitJSClass(JSContext
*cx
, JS::Handle
<JSObject
*> obj
,
134 const nsAFlatCString
& aClassName
,
135 nsXBLPrototypeBinding
* aProtoBinding
,
136 JS::MutableHandle
<JSObject
*> aClassObject
,
141 mozilla::dom::XBLChildrenElement
* FindInsertionPointFor(nsIContent
* aChild
);
143 bool HasFilteredInsertionPoints()
145 return !mInsertionPoints
.IsEmpty();
148 mozilla::dom::XBLChildrenElement
* GetDefaultInsertionPoint()
150 return mDefaultInsertionPoint
;
153 // Removes all inserted node from <xbl:children> insertion points under us.
154 void ClearInsertionPoints();
156 // Returns a live node list that iterates over the anonymous nodes generated
158 nsAnonymousContentList
* GetAnonymousNodeList();
163 bool mMarkedForDeath
;
164 bool mUsingContentXBLScope
;
165 bool mIsShadowRootBinding
;
167 nsXBLPrototypeBinding
* mPrototypeBinding
; // Weak, but we're holding a ref to the docinfo
168 nsCOMPtr
<nsIContent
> mContent
; // Strong. Our anonymous content stays around with us.
169 nsRefPtr
<nsXBLBinding
> mNextBinding
; // Strong. The derived binding owns the base class bindings.
171 nsIContent
* mBoundElement
; // [WEAK] We have a reference, but we don't own it.
173 // The <xbl:children> elements that we found in our <xbl:content> when we
174 // processed this binding. The default insertion point has no includes
175 // attribute and all other insertion points must have at least one includes
176 // attribute. These points must be up-to-date with respect to their parent's
177 // children, even if their parent has another binding attached to it,
178 // preventing us from rendering their contents directly.
179 nsRefPtr
<mozilla::dom::XBLChildrenElement
> mDefaultInsertionPoint
;
180 nsTArray
<nsRefPtr
<mozilla::dom::XBLChildrenElement
> > mInsertionPoints
;
181 nsRefPtr
<nsAnonymousContentList
> mAnonymousContentList
;
183 mozilla::dom::XBLChildrenElement
* FindInsertionPointForInternal(nsIContent
* aChild
);
186 #endif // nsXBLBinding_h_