2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsBindingManager_h_
|
|
|
|
#define nsBindingManager_h_
|
|
|
|
|
2007-12-04 10:37:54 -08:00
|
|
|
#include "nsStubMutationObserver.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "pldhash.h"
|
|
|
|
#include "nsInterfaceHashtable.h"
|
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
#include "nsURIHashKey.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsXBLBinding.h"
|
|
|
|
#include "nsTArray.h"
|
2009-02-17 20:11:09 -08:00
|
|
|
#include "nsThreadUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-19 09:22:27 -08:00
|
|
|
struct ElementDependentRuleProcessorData;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIContent;
|
|
|
|
class nsIXPConnectWrappedJS;
|
|
|
|
class nsIAtom;
|
|
|
|
class nsIDOMNodeList;
|
|
|
|
class nsIDocument;
|
|
|
|
class nsIURI;
|
2010-07-14 18:53:11 -07:00
|
|
|
class nsXBLDocumentInfo;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIStreamListener;
|
|
|
|
class nsStyleSet;
|
|
|
|
class nsXBLBinding;
|
|
|
|
template<class E> class nsRefPtr;
|
|
|
|
typedef nsTArray<nsRefPtr<nsXBLBinding> > nsBindingList;
|
2007-07-18 14:56:57 -07:00
|
|
|
class nsIPrincipal;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-25 12:16:15 -07:00
|
|
|
class nsBindingManager MOZ_FINAL : public nsStubMutationObserver
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2007-12-04 10:37:54 -08:00
|
|
|
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-03 16:38:32 -07:00
|
|
|
nsBindingManager(nsIDocument* aDocument);
|
2007-03-22 10:30:00 -07:00
|
|
|
~nsBindingManager();
|
|
|
|
|
|
|
|
nsXBLBinding* GetBinding(nsIContent* aContent);
|
|
|
|
nsresult SetBinding(nsIContent* aContent, nsXBLBinding* aBinding);
|
|
|
|
|
|
|
|
nsIContent* GetInsertionParent(nsIContent* aContent);
|
|
|
|
nsresult SetInsertionParent(nsIContent* aContent, nsIContent* aResult);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify the binding manager that an element
|
2010-06-03 18:09:08 -07:00
|
|
|
* has been removed from its document,
|
2007-03-22 10:30:00 -07:00
|
|
|
* so that it can update any bindings or
|
|
|
|
* nsIAnonymousContentCreator-created anonymous
|
|
|
|
* content that may depend on the document.
|
|
|
|
* @param aContent the element that's being moved
|
|
|
|
* @param aOldDocument the old document in which the
|
2010-06-03 18:09:08 -07:00
|
|
|
* content resided.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2010-06-03 18:09:08 -07:00
|
|
|
void RemovedFromDocument(nsIContent* aContent, nsIDocument* aOldDocument)
|
|
|
|
{
|
|
|
|
if (aContent->HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
|
2012-06-11 15:22:26 -07:00
|
|
|
RemovedFromDocumentInternal(aContent, aOldDocument,
|
|
|
|
aContent->GetBindingParent());
|
2010-06-03 18:09:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void RemovedFromDocumentInternal(nsIContent* aContent,
|
2012-06-11 15:22:26 -07:00
|
|
|
nsIDocument* aOldDocument,
|
|
|
|
nsIContent* aContentBindingParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsIAtom* ResolveTag(nsIContent* aContent, int32_t* aNameSpaceID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a list of all explicit children, including any children
|
|
|
|
* that may have been inserted via XBL insertion points.
|
|
|
|
*/
|
|
|
|
nsresult GetContentListFor(nsIContent* aContent, nsIDOMNodeList** aResult);
|
|
|
|
|
2010-02-11 09:34:01 -08:00
|
|
|
/**
|
|
|
|
* Non-COMy version of GetContentListFor.
|
|
|
|
*/
|
|
|
|
nsINodeList* GetContentListFor(nsIContent* aContent);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Set the insertion point children for the specified element.
|
|
|
|
* The binding manager assumes ownership of aList.
|
|
|
|
*/
|
|
|
|
nsresult SetContentListFor(nsIContent* aContent,
|
|
|
|
nsInsertionPointList* aList);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether or not the explicit child list has been altered
|
|
|
|
* by XBL insertion points.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasContentListFor(nsIContent* aContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
2009-01-29 11:46:18 -08:00
|
|
|
* Return the nodelist of "anonymous" kids for this node. This might
|
|
|
|
* actually include some of the nodes actual DOM kids, if there are
|
|
|
|
* <children> tags directly as kids of <content>. This will only end up
|
|
|
|
* returning a non-null list for nodes which have a binding attached.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
nsresult GetAnonymousNodesFor(nsIContent* aContent, nsIDOMNodeList** aResult);
|
|
|
|
|
2010-05-14 10:04:51 -07:00
|
|
|
/**
|
|
|
|
* Same as above, but without the XPCOM goop
|
|
|
|
*/
|
|
|
|
nsINodeList* GetAnonymousNodesFor(nsIContent* aContent);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Set the anonymous child content for the specified element.
|
|
|
|
* The binding manager assumes ownership of aList.
|
|
|
|
*/
|
|
|
|
nsresult SetAnonymousNodesFor(nsIContent* aContent,
|
|
|
|
nsInsertionPointList* aList);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the anonymous list of children if the element has one;
|
|
|
|
* otherwise, retrieves the list of explicit children. N.B. that if
|
|
|
|
* the explicit child list has not been altered by XBL insertion
|
|
|
|
* points, then aResult will be null.
|
|
|
|
*/
|
|
|
|
nsresult GetXBLChildNodesFor(nsIContent* aContent, nsIDOMNodeList** aResult);
|
|
|
|
|
2009-01-29 11:46:18 -08:00
|
|
|
/**
|
|
|
|
* Non-COMy version of GetXBLChildNodesFor
|
|
|
|
*/
|
|
|
|
nsINodeList* GetXBLChildNodesFor(nsIContent* aContent);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Given a parent element and a child content, determine where the
|
|
|
|
* child content should be inserted in the parent element's
|
|
|
|
* anonymous content tree. Specifically, aChild should be inserted
|
|
|
|
* beneath aResult at the index specified by aIndex.
|
|
|
|
*/
|
2009-01-29 11:46:20 -08:00
|
|
|
// XXXbz That's false. The aIndex doesn't seem to accurately reflect
|
|
|
|
// anything resembling reality in terms of inserting content. It's really
|
|
|
|
// only used to tell apart two different insertion points with the same
|
|
|
|
// insertion parent when managing our internal data structures. We really
|
|
|
|
// shouldn't be handing it out in our public API, since it's not useful to
|
|
|
|
// anyone.
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent* GetInsertionPoint(nsIContent* aParent,
|
2012-08-22 08:56:38 -07:00
|
|
|
const nsIContent* aChild, uint32_t* aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the unfiltered insertion point for the specified parent
|
|
|
|
* element. If other filtered insertion points exist,
|
|
|
|
* aMultipleInsertionPoints will be set to true.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
nsIContent* GetSingleInsertionPoint(nsIContent* aParent, uint32_t* aIndex,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aMultipleInsertionPoints);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-16 11:15:28 -07:00
|
|
|
nsIContent* GetNestedInsertionPoint(nsIContent* aParent,
|
|
|
|
const nsIContent* aChild);
|
|
|
|
nsIContent* GetNestedSingleInsertionPoint(nsIContent* aParent,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aMultipleInsertionPoints);
|
2010-04-16 11:15:28 -07:00
|
|
|
|
2007-07-18 14:56:57 -07:00
|
|
|
nsresult AddLayeredBinding(nsIContent* aContent, nsIURI* aURL,
|
|
|
|
nsIPrincipal* aOriginPrincipal);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult RemoveLayeredBinding(nsIContent* aContent, nsIURI* aURL);
|
2007-07-18 14:56:57 -07:00
|
|
|
nsresult LoadBindingDocument(nsIDocument* aBoundDoc, nsIURI* aURL,
|
|
|
|
nsIPrincipal* aOriginPrincipal);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult AddToAttachedQueue(nsXBLBinding* aBinding);
|
2012-08-22 08:56:38 -07:00
|
|
|
void ProcessAttachedQueue(uint32_t aSkipSize = 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void ExecuteDetachedHandlers();
|
|
|
|
|
2010-07-14 18:53:11 -07:00
|
|
|
nsresult PutXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo);
|
|
|
|
nsXBLDocumentInfo* GetXBLDocumentInfo(nsIURI* aURI);
|
|
|
|
void RemoveXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult PutLoadingDocListener(nsIURI* aURL, nsIStreamListener* aListener);
|
|
|
|
nsIStreamListener* GetLoadingDocListener(nsIURI* aURL);
|
|
|
|
void RemoveLoadingDocListener(nsIURI* aURL);
|
|
|
|
|
|
|
|
void FlushSkinBindings();
|
|
|
|
|
|
|
|
nsresult GetBindingImplementation(nsIContent* aContent, REFNSIID aIID, void** aResult);
|
|
|
|
|
|
|
|
// Style rule methods
|
2008-07-26 09:14:49 -07:00
|
|
|
nsresult WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc,
|
2012-11-14 11:09:01 -08:00
|
|
|
ElementDependentRuleProcessorData* aData,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aCutOffInheritance);
|
2010-03-25 02:22:58 -07:00
|
|
|
|
|
|
|
void WalkAllRules(nsIStyleRuleProcessor::EnumFunc aFunc,
|
2012-11-14 11:09:01 -08:00
|
|
|
ElementDependentRuleProcessorData* aData);
|
2008-07-26 09:14:49 -07:00
|
|
|
/**
|
|
|
|
* Do any processing that needs to happen as a result of a change in
|
|
|
|
* the characteristics of the medium, and return whether this rule
|
|
|
|
* processor's rules have changed (e.g., because of media queries).
|
|
|
|
*/
|
|
|
|
nsresult MediumFeaturesChanged(nsPresContext* aPresContext,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aRulesChanged);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-16 22:36:34 -07:00
|
|
|
void AppendAllSheets(nsTArray<nsCSSStyleSheet*>& aArray);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_HIDDEN_(void) Traverse(nsIContent *aContent,
|
|
|
|
nsCycleCollectionTraversalCallback &cb);
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS(nsBindingManager)
|
|
|
|
|
2007-05-30 18:36:06 -07:00
|
|
|
// Notify the binding manager when an outermost update begins and
|
|
|
|
// ends. The end method can execute script.
|
|
|
|
void BeginOutermostUpdate();
|
|
|
|
void EndOutermostUpdate();
|
|
|
|
|
2007-12-04 10:37:54 -08:00
|
|
|
// Called when the document is going away
|
|
|
|
void DropDocumentReference();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
|
|
|
nsIXPConnectWrappedJS* GetWrappedJS(nsIContent* aContent);
|
|
|
|
nsresult SetWrappedJS(nsIContent* aContent, nsIXPConnectWrappedJS* aResult);
|
|
|
|
|
2009-01-29 11:46:18 -08:00
|
|
|
nsINodeList* GetXBLChildNodesInternal(nsIContent* aContent,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aIsAnonymousContentList);
|
2009-01-29 11:46:18 -08:00
|
|
|
nsINodeList* GetAnonymousNodesInternal(nsIContent* aContent,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aIsAnonymousContentList);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-15 09:17:46 -08:00
|
|
|
// Called by ContentAppended and ContentInserted to handle a single child
|
|
|
|
// insertion. aChild must not be null. aContainer may be null.
|
|
|
|
// aIndexInContainer is the index of the child in the parent. aAppend is
|
|
|
|
// true if this child is being appended, not inserted.
|
|
|
|
void HandleChildInsertion(nsIContent* aContainer, nsIContent* aChild,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aIndexInContainer, bool aAppend);
|
2007-11-15 09:17:46 -08:00
|
|
|
|
2009-04-08 11:37:15 -07:00
|
|
|
// For the given container under which a child is being added, given
|
|
|
|
// insertion parent and given index of the child being inserted, find the
|
|
|
|
// right nsXBLInsertionPoint and the right index in that insertion point to
|
|
|
|
// insert it at. If null is returned, aInsertionIndex might be garbage.
|
|
|
|
// aAppend controls what should be returned as the aInsertionIndex if the
|
|
|
|
// right index can't be found. If true, the length of the insertion point
|
|
|
|
// will be returned; otherwise 0 will be returned.
|
|
|
|
nsXBLInsertionPoint* FindInsertionPointAndIndex(nsIContent* aContainer,
|
|
|
|
nsIContent* aInsertionParent,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aIndexInContainer,
|
|
|
|
int32_t aAppend,
|
|
|
|
int32_t* aInsertionIndex);
|
2009-04-08 11:37:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Same as ProcessAttachedQueue, but also nulls out
|
|
|
|
// mProcessAttachedQueueEvent
|
|
|
|
void DoProcessAttachedQueue();
|
|
|
|
|
2007-12-04 09:30:07 -08:00
|
|
|
// Post an event to process the attached queue.
|
|
|
|
void PostProcessAttachedQueueEvent();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// MEMBER VARIABLES
|
|
|
|
protected:
|
2007-10-12 04:07:29 -07:00
|
|
|
void RemoveInsertionParent(nsIContent* aParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
// A mapping from nsIContent* to the nsXBLBinding* that is
|
|
|
|
// installed on that element.
|
|
|
|
nsRefPtrHashtable<nsISupportsHashKey,nsXBLBinding> mBindingTable;
|
|
|
|
|
2009-01-29 11:46:18 -08:00
|
|
|
// A mapping from nsIContent* to an nsAnonymousContentList*. This
|
|
|
|
// list contains an accurate reflection of our *explicit* children
|
|
|
|
// (once intermingled with insertion points) in the altered DOM.
|
|
|
|
// There is an entry for a content node in this table only if that
|
|
|
|
// content node has some <children> kids.
|
2007-03-22 10:30:00 -07:00
|
|
|
PLDHashTable mContentListTable;
|
|
|
|
|
2009-01-29 11:46:18 -08:00
|
|
|
// A mapping from nsIContent* to an nsAnonymousContentList*. This
|
|
|
|
// list contains an accurate reflection of our *anonymous* children
|
|
|
|
// (if and only if they are intermingled with insertion points) in
|
|
|
|
// the altered DOM. This table is not used if no insertion points
|
|
|
|
// were defined directly underneath a <content> tag in a binding.
|
|
|
|
// The NodeList from the <content> is used instead as a performance
|
|
|
|
// optimization. There is an entry for a content node in this table
|
|
|
|
// only if that content node has a binding with a <content> attached
|
|
|
|
// and this <content> contains <children> elements directly.
|
2007-03-22 10:30:00 -07:00
|
|
|
PLDHashTable mAnonymousNodesTable;
|
|
|
|
|
|
|
|
// A mapping from nsIContent* to nsIContent*. The insertion parent
|
|
|
|
// is our one true parent in the transformed DOM. This gives us a
|
|
|
|
// more-or-less O(1) way of obtaining our transformed parent.
|
|
|
|
PLDHashTable mInsertionParentTable;
|
|
|
|
|
|
|
|
// A mapping from nsIContent* to nsIXPWrappedJS* (an XPConnect
|
|
|
|
// wrapper for JS objects). For XBL bindings that implement XPIDL
|
|
|
|
// interfaces, and that get referred to from C++, this table caches
|
|
|
|
// the XPConnect wrapper for the binding. By caching it, I control
|
|
|
|
// its lifetime, and I prevent a re-wrap of the same script object
|
|
|
|
// (in the case where multiple bindings in an XBL inheritance chain
|
|
|
|
// both implement an XPIDL interface).
|
|
|
|
PLDHashTable mWrapperTable;
|
|
|
|
|
2010-07-14 18:53:11 -07:00
|
|
|
// A mapping from a URL (a string) to nsXBLDocumentInfo*. This table
|
2007-03-22 10:30:00 -07:00
|
|
|
// is the cache of all binding documents that have been loaded by a
|
|
|
|
// given bound document.
|
2010-07-14 18:53:11 -07:00
|
|
|
nsRefPtrHashtable<nsURIHashKey,nsXBLDocumentInfo> mDocumentTable;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// A mapping from a URL (a string) to a nsIStreamListener. This
|
|
|
|
// table is the currently loading binding docs. If they're in this
|
|
|
|
// table, they have not yet finished loading.
|
|
|
|
nsInterfaceHashtable<nsURIHashKey,nsIStreamListener> mLoadingDocTable;
|
|
|
|
|
|
|
|
// A queue of binding attached event handlers that are awaiting execution.
|
|
|
|
nsBindingList mAttachedStack;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mProcessingAttachedStack;
|
|
|
|
bool mDestroyed;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mAttachedStackSizeOnOutermost;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Our posted event to process the attached queue, if any
|
|
|
|
friend class nsRunnableMethod<nsBindingManager>;
|
2009-02-03 18:58:21 -08:00
|
|
|
nsRefPtr< nsRunnableMethod<nsBindingManager> > mProcessAttachedQueueEvent;
|
2007-10-03 16:38:32 -07:00
|
|
|
|
|
|
|
// Our document. This is a weak ref; the document owns us
|
|
|
|
nsIDocument* mDocument;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|