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 nsBindingManager_h_
7 #define nsBindingManager_h_
9 #include "nsIContent.h"
10 #include "nsStubMutationObserver.h"
11 #include "nsHashKeys.h"
12 #include "nsInterfaceHashtable.h"
13 #include "nsRefPtrHashtable.h"
14 #include "nsURIHashKey.h"
15 #include "nsCycleCollectionParticipant.h"
16 #include "nsXBLBinding.h"
18 #include "nsThreadUtils.h"
20 struct ElementDependentRuleProcessorData
;
21 class nsIXPConnectWrappedJS
;
26 class nsXBLDocumentInfo
;
27 class nsIStreamListener
;
30 template<class E
> class nsRefPtr
;
31 typedef nsTArray
<nsRefPtr
<nsXBLBinding
> > nsBindingList
;
37 } // namespace mozilla
39 class nsBindingManager MOZ_FINAL
: public nsStubMutationObserver
44 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
46 NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
47 NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
48 NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
50 explicit nsBindingManager(nsIDocument
* aDocument
);
52 nsXBLBinding
* GetBindingWithContent(nsIContent
* aContent
);
54 void AddBoundContent(nsIContent
* aContent
);
55 void RemoveBoundContent(nsIContent
* aContent
);
58 * Notify the binding manager that an element
59 * has been removed from its document,
60 * so that it can update any bindings or
61 * nsIAnonymousContentCreator-created anonymous
62 * content that may depend on the document.
63 * @param aContent the element that's being moved
64 * @param aOldDocument the old document in which the
67 void RemovedFromDocument(nsIContent
* aContent
, nsIDocument
* aOldDocument
)
69 if (aContent
->HasFlag(NODE_MAY_BE_IN_BINDING_MNGR
)) {
70 RemovedFromDocumentInternal(aContent
, aOldDocument
);
73 void RemovedFromDocumentInternal(nsIContent
* aContent
,
74 nsIDocument
* aOldDocument
);
76 nsIAtom
* ResolveTag(nsIContent
* aContent
, int32_t* aNameSpaceID
);
79 * Return the nodelist of "anonymous" kids for this node. This might
80 * actually include some of the nodes actual DOM kids, if there are
81 * <children> tags directly as kids of <content>. This will only end up
82 * returning a non-null list for nodes which have a binding attached.
84 nsresult
GetAnonymousNodesFor(nsIContent
* aContent
, nsIDOMNodeList
** aResult
);
85 nsINodeList
* GetAnonymousNodesFor(nsIContent
* aContent
);
87 nsresult
ClearBinding(nsIContent
* aContent
);
88 nsresult
LoadBindingDocument(nsIDocument
* aBoundDoc
, nsIURI
* aURL
,
89 nsIPrincipal
* aOriginPrincipal
);
91 nsresult
AddToAttachedQueue(nsXBLBinding
* aBinding
);
92 void RemoveFromAttachedQueue(nsXBLBinding
* aBinding
);
93 void ProcessAttachedQueue(uint32_t aSkipSize
= 0);
95 void ExecuteDetachedHandlers();
97 nsresult
PutXBLDocumentInfo(nsXBLDocumentInfo
* aDocumentInfo
);
98 nsXBLDocumentInfo
* GetXBLDocumentInfo(nsIURI
* aURI
);
99 void RemoveXBLDocumentInfo(nsXBLDocumentInfo
* aDocumentInfo
);
101 nsresult
PutLoadingDocListener(nsIURI
* aURL
, nsIStreamListener
* aListener
);
102 nsIStreamListener
* GetLoadingDocListener(nsIURI
* aURL
);
103 void RemoveLoadingDocListener(nsIURI
* aURL
);
105 void FlushSkinBindings();
107 nsresult
GetBindingImplementation(nsIContent
* aContent
, REFNSIID aIID
, void** aResult
);
109 // Style rule methods
110 nsresult
WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc
,
111 ElementDependentRuleProcessorData
* aData
,
112 bool* aCutOffInheritance
);
114 void WalkAllRules(nsIStyleRuleProcessor::EnumFunc aFunc
,
115 ElementDependentRuleProcessorData
* aData
);
117 * Do any processing that needs to happen as a result of a change in
118 * the characteristics of the medium, and return whether this rule
119 * processor's rules have changed (e.g., because of media queries).
121 nsresult
MediumFeaturesChanged(nsPresContext
* aPresContext
,
122 bool* aRulesChanged
);
124 void AppendAllSheets(nsTArray
<mozilla::CSSStyleSheet
*>& aArray
);
126 void Traverse(nsIContent
*aContent
,
127 nsCycleCollectionTraversalCallback
&cb
);
129 NS_DECL_CYCLE_COLLECTION_CLASS(nsBindingManager
)
131 // Notify the binding manager when an outermost update begins and
132 // ends. The end method can execute script.
133 void BeginOutermostUpdate();
134 void EndOutermostUpdate();
136 // When removing an insertion point or a parent of one, clear the insertion
137 // points and their insertion parents.
138 void ClearInsertionPointsRecursively(nsIContent
* aContent
);
140 // Called when the document is going away
141 void DropDocumentReference();
143 nsIContent
* FindNestedInsertionPoint(nsIContent
* aContainer
,
146 nsIContent
* FindNestedSingleInsertionPoint(nsIContent
* aContainer
, bool* aMulti
);
149 nsIXPConnectWrappedJS
* GetWrappedJS(nsIContent
* aContent
);
150 nsresult
SetWrappedJS(nsIContent
* aContent
, nsIXPConnectWrappedJS
* aResult
);
152 // Called by ContentAppended and ContentInserted to handle a single child
153 // insertion. aChild must not be null. aContainer may be null.
154 // aIndexInContainer is the index of the child in the parent. aAppend is
155 // true if this child is being appended, not inserted.
156 void HandleChildInsertion(nsIContent
* aContainer
, nsIContent
* aChild
,
157 uint32_t aIndexInContainer
, bool aAppend
);
159 // Same as ProcessAttachedQueue, but also nulls out
160 // mProcessAttachedQueueEvent
161 void DoProcessAttachedQueue();
163 // Post an event to process the attached queue.
164 void PostProcessAttachedQueueEvent();
166 // Call PostProcessAttachedQueueEvent() on a timer.
167 static void PostPAQEventCallback(nsITimer
* aTimer
, void* aClosure
);
171 // A set of nsIContent that currently have a binding installed.
172 nsAutoPtr
<nsTHashtable
<nsRefPtrHashKey
<nsIContent
> > > mBoundContentSet
;
174 // A mapping from nsIContent* to nsIXPWrappedJS* (an XPConnect
175 // wrapper for JS objects). For XBL bindings that implement XPIDL
176 // interfaces, and that get referred to from C++, this table caches
177 // the XPConnect wrapper for the binding. By caching it, I control
178 // its lifetime, and I prevent a re-wrap of the same script object
179 // (in the case where multiple bindings in an XBL inheritance chain
180 // both implement an XPIDL interface).
181 typedef nsInterfaceHashtable
<nsISupportsHashKey
, nsIXPConnectWrappedJS
> WrapperHashtable
;
182 nsAutoPtr
<WrapperHashtable
> mWrapperTable
;
184 // A mapping from a URL (a string) to nsXBLDocumentInfo*. This table
185 // is the cache of all binding documents that have been loaded by a
186 // given bound document.
187 nsAutoPtr
<nsRefPtrHashtable
<nsURIHashKey
,nsXBLDocumentInfo
> > mDocumentTable
;
189 // A mapping from a URL (a string) to a nsIStreamListener. This
190 // table is the currently loading binding docs. If they're in this
191 // table, they have not yet finished loading.
192 nsAutoPtr
<nsInterfaceHashtable
<nsURIHashKey
,nsIStreamListener
> > mLoadingDocTable
;
194 // A queue of binding attached event handlers that are awaiting execution.
195 nsBindingList mAttachedStack
;
196 bool mProcessingAttachedStack
;
198 uint32_t mAttachedStackSizeOnOutermost
;
200 // Our posted event to process the attached queue, if any
201 friend class nsRunnableMethod
<nsBindingManager
>;
202 nsRefPtr
< nsRunnableMethod
<nsBindingManager
> > mProcessAttachedQueueEvent
;
204 // Our document. This is a weak ref; the document owns us
205 nsIDocument
* mDocument
;