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_
|
|
|
|
|
2013-03-21 17:05:20 -07:00
|
|
|
#include "nsIContent.h"
|
2007-12-04 10:37:54 -08:00
|
|
|
#include "nsStubMutationObserver.h"
|
2014-04-10 07:05:19 -07:00
|
|
|
#include "nsHashKeys.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#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 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;
|
2014-07-01 11:30:13 -07:00
|
|
|
class nsITimer;
|
2014-06-20 03:32:49 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
class CSSStyleSheet;
|
|
|
|
} // namespace mozilla
|
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
|
|
|
{
|
2014-06-23 12:56:07 -07:00
|
|
|
~nsBindingManager();
|
|
|
|
|
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
|
|
|
|
2013-05-01 15:50:08 -07:00
|
|
|
nsXBLBinding* GetBindingWithContent(nsIContent* aContent);
|
2013-07-17 09:05:03 -07:00
|
|
|
|
|
|
|
void AddBoundContent(nsIContent* aContent);
|
|
|
|
void RemoveBoundContent(nsIContent* aContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)) {
|
2013-05-01 15:50:08 -07:00
|
|
|
RemovedFromDocumentInternal(aContent, aOldDocument);
|
2010-06-03 18:09:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void RemovedFromDocumentInternal(nsIContent* aContent,
|
2013-05-01 15:50:08 -07:00
|
|
|
nsIDocument* aOldDocument);
|
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
|
|
|
|
|
|
|
/**
|
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
|
|
|
nsINodeList* GetAnonymousNodesFor(nsIContent* aContent);
|
|
|
|
|
2013-01-24 09:45:50 -08:00
|
|
|
nsresult ClearBinding(nsIContent* aContent);
|
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);
|
2013-07-17 09:05:03 -07:00
|
|
|
void RemoveFromAttachedQueue(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
|
|
|
|
2014-06-20 03:32:49 -07:00
|
|
|
void AppendAllSheets(nsTArray<mozilla::CSSStyleSheet*>& aArray);
|
2010-07-16 22:36:34 -07:00
|
|
|
|
2014-06-02 05:08:21 -07:00
|
|
|
void Traverse(nsIContent *aContent,
|
2007-03-22 10:30:00 -07:00
|
|
|
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();
|
|
|
|
|
2013-05-01 15:50:08 -07:00
|
|
|
// When removing an insertion point or a parent of one, clear the insertion
|
|
|
|
// points and their insertion parents.
|
|
|
|
void ClearInsertionPointsRecursively(nsIContent* aContent);
|
|
|
|
|
2007-12-04 10:37:54 -08:00
|
|
|
// Called when the document is going away
|
|
|
|
void DropDocumentReference();
|
|
|
|
|
2013-05-01 15:50:08 -07:00
|
|
|
nsIContent* FindNestedInsertionPoint(nsIContent* aContainer,
|
|
|
|
nsIContent* aChild);
|
|
|
|
|
|
|
|
nsIContent* FindNestedSingleInsertionPoint(nsIContent* aContainer, bool* aMulti);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
|
|
|
nsIXPConnectWrappedJS* GetWrappedJS(nsIContent* aContent);
|
|
|
|
nsresult SetWrappedJS(nsIContent* aContent, nsIXPConnectWrappedJS* aResult);
|
|
|
|
|
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
|
|
|
|
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();
|
|
|
|
|
2014-07-01 11:30:13 -07:00
|
|
|
// Call PostProcessAttachedQueueEvent() on a timer.
|
|
|
|
static void PostPAQEventCallback(nsITimer* aTimer, void* aClosure);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// MEMBER VARIABLES
|
2014-04-10 07:05:18 -07:00
|
|
|
protected:
|
2013-07-17 09:05:03 -07:00
|
|
|
// A set of nsIContent that currently have a binding installed.
|
2013-09-02 01:41:57 -07:00
|
|
|
nsAutoPtr<nsTHashtable<nsRefPtrHashKey<nsIContent> > > mBoundContentSet;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// 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).
|
2014-04-10 07:05:19 -07:00
|
|
|
typedef nsInterfaceHashtable<nsISupportsHashKey, nsIXPConnectWrappedJS> WrapperHashtable;
|
|
|
|
nsAutoPtr<WrapperHashtable> mWrapperTable;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
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.
|
2013-09-02 01:41:57 -07:00
|
|
|
nsAutoPtr<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.
|
2013-09-02 01:41:57 -07:00
|
|
|
nsAutoPtr<nsInterfaceHashtable<nsURIHashKey,nsIStreamListener> > mLoadingDocTable;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// 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
|
2014-04-10 07:05:18 -07:00
|
|
|
nsIDocument* mDocument;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|