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