2005-02-19 10:31:27 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
2005-02-19 10:31:27 +00:00
|
|
|
|
|
|
|
#ifndef nsBindingManager_h_
|
|
|
|
#define nsBindingManager_h_
|
|
|
|
|
2013-03-22 00:05:20 +00:00
|
|
|
#include "nsIContent.h"
|
2007-12-04 18:37:54 +00:00
|
|
|
#include "nsStubMutationObserver.h"
|
2005-02-19 10:31:27 +00:00
|
|
|
#include "pldhash.h"
|
|
|
|
#include "nsInterfaceHashtable.h"
|
2005-02-25 22:07:01 +00:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2005-02-19 10:31:27 +00:00
|
|
|
#include "nsURIHashKey.h"
|
2007-01-04 22:31:26 +00:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2007-02-16 23:02:08 +00:00
|
|
|
#include "nsXBLBinding.h"
|
|
|
|
#include "nsTArray.h"
|
2009-02-18 04:11:09 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2005-02-19 10:31:27 +00:00
|
|
|
|
2012-11-19 17:22:27 +00:00
|
|
|
struct ElementDependentRuleProcessorData;
|
2005-02-19 10:31:27 +00:00
|
|
|
class nsIXPConnectWrappedJS;
|
|
|
|
class nsIAtom;
|
|
|
|
class nsIDOMNodeList;
|
|
|
|
class nsIDocument;
|
|
|
|
class nsIURI;
|
2010-07-15 01:53:11 +00:00
|
|
|
class nsXBLDocumentInfo;
|
2005-02-19 10:31:27 +00:00
|
|
|
class nsIStreamListener;
|
|
|
|
class nsStyleSet;
|
2007-02-16 23:02:08 +00:00
|
|
|
class nsXBLBinding;
|
2006-12-14 21:32:10 +00:00
|
|
|
template<class E> class nsRefPtr;
|
|
|
|
typedef nsTArray<nsRefPtr<nsXBLBinding> > nsBindingList;
|
2007-07-18 21:56:57 +00:00
|
|
|
class nsIPrincipal;
|
2005-02-19 10:31:27 +00:00
|
|
|
|
2012-10-25 19:16:15 +00:00
|
|
|
class nsBindingManager MOZ_FINAL : public nsStubMutationObserver
|
2005-02-19 10:31:27 +00:00
|
|
|
{
|
2006-08-15 22:41:58 +00:00
|
|
|
public:
|
2007-01-04 22:31:26 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2007-12-04 18:37:54 +00:00
|
|
|
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
2005-02-19 10:31:27 +00:00
|
|
|
|
2007-10-03 23:38:32 +00:00
|
|
|
nsBindingManager(nsIDocument* aDocument);
|
2005-02-19 10:31:27 +00:00
|
|
|
~nsBindingManager();
|
|
|
|
|
2013-05-01 22:50:08 +00:00
|
|
|
nsXBLBinding* GetBindingWithContent(nsIContent* aContent);
|
2013-07-17 16:05:03 +00:00
|
|
|
|
|
|
|
void AddBoundContent(nsIContent* aContent);
|
|
|
|
void RemoveBoundContent(nsIContent* aContent);
|
2007-02-16 23:02:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify the binding manager that an element
|
2010-06-04 01:09:08 +00:00
|
|
|
* has been removed from its document,
|
2007-02-16 23:02:08 +00: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-04 01:09:08 +00:00
|
|
|
* content resided.
|
2007-02-16 23:02:08 +00:00
|
|
|
*/
|
2010-06-04 01:09:08 +00:00
|
|
|
void RemovedFromDocument(nsIContent* aContent, nsIDocument* aOldDocument)
|
|
|
|
{
|
|
|
|
if (aContent->HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
|
2013-05-01 22:50:08 +00:00
|
|
|
RemovedFromDocumentInternal(aContent, aOldDocument);
|
2010-06-04 01:09:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void RemovedFromDocumentInternal(nsIContent* aContent,
|
2013-05-01 22:50:08 +00:00
|
|
|
nsIDocument* aOldDocument);
|
2007-02-16 23:02:08 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
nsIAtom* ResolveTag(nsIContent* aContent, int32_t* aNameSpaceID);
|
2007-02-16 23:02:08 +00:00
|
|
|
|
|
|
|
/**
|
2009-01-29 19:46:18 +00: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-02-16 23:02:08 +00:00
|
|
|
*/
|
|
|
|
nsresult GetAnonymousNodesFor(nsIContent* aContent, nsIDOMNodeList** aResult);
|
2010-05-14 17:04:51 +00:00
|
|
|
nsINodeList* GetAnonymousNodesFor(nsIContent* aContent);
|
|
|
|
|
2013-01-24 17:45:50 +00:00
|
|
|
nsresult ClearBinding(nsIContent* aContent);
|
2007-07-18 21:56:57 +00:00
|
|
|
nsresult LoadBindingDocument(nsIDocument* aBoundDoc, nsIURI* aURL,
|
|
|
|
nsIPrincipal* aOriginPrincipal);
|
2005-02-19 10:31:27 +00:00
|
|
|
|
2007-02-16 23:02:08 +00:00
|
|
|
nsresult AddToAttachedQueue(nsXBLBinding* aBinding);
|
2013-07-17 16:05:03 +00:00
|
|
|
void RemoveFromAttachedQueue(nsXBLBinding* aBinding);
|
2012-08-22 15:56:38 +00:00
|
|
|
void ProcessAttachedQueue(uint32_t aSkipSize = 0);
|
2005-02-19 10:31:27 +00:00
|
|
|
|
2007-02-27 00:14:01 +00:00
|
|
|
void ExecuteDetachedHandlers();
|
2005-02-19 10:31:27 +00:00
|
|
|
|
2010-07-15 01:53:11 +00:00
|
|
|
nsresult PutXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo);
|
|
|
|
nsXBLDocumentInfo* GetXBLDocumentInfo(nsIURI* aURI);
|
|
|
|
void RemoveXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo);
|
2005-02-19 10:31:27 +00:00
|
|
|
|
2007-02-16 23:02:08 +00:00
|
|
|
nsresult PutLoadingDocListener(nsIURI* aURL, nsIStreamListener* aListener);
|
2007-02-27 00:14:01 +00:00
|
|
|
nsIStreamListener* GetLoadingDocListener(nsIURI* aURL);
|
|
|
|
void RemoveLoadingDocListener(nsIURI* aURL);
|
2005-02-19 10:31:27 +00:00
|
|
|
|
2007-02-27 00:14:01 +00:00
|
|
|
void FlushSkinBindings();
|
2005-02-19 10:31:27 +00:00
|
|
|
|
2007-02-16 23:02:08 +00:00
|
|
|
nsresult GetBindingImplementation(nsIContent* aContent, REFNSIID aIID, void** aResult);
|
2005-02-19 10:31:27 +00:00
|
|
|
|
2007-02-16 23:02:08 +00:00
|
|
|
// Style rule methods
|
2008-07-26 16:14:49 +00:00
|
|
|
nsresult WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc,
|
2012-11-14 19:09:01 +00:00
|
|
|
ElementDependentRuleProcessorData* aData,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool* aCutOffInheritance);
|
2010-03-25 09:22:58 +00:00
|
|
|
|
|
|
|
void WalkAllRules(nsIStyleRuleProcessor::EnumFunc aFunc,
|
2012-11-14 19:09:01 +00:00
|
|
|
ElementDependentRuleProcessorData* aData);
|
2008-07-26 16:14:49 +00: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-29 06:19:26 +00:00
|
|
|
bool* aRulesChanged);
|
2005-02-19 10:31:27 +00:00
|
|
|
|
2010-07-17 05:36:34 +00:00
|
|
|
void AppendAllSheets(nsTArray<nsCSSStyleSheet*>& aArray);
|
|
|
|
|
2007-03-08 11:17:16 +00:00
|
|
|
NS_HIDDEN_(void) Traverse(nsIContent *aContent,
|
|
|
|
nsCycleCollectionTraversalCallback &cb);
|
|
|
|
|
2007-01-04 22:31:26 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS(nsBindingManager)
|
|
|
|
|
2007-05-31 01:36:06 +00: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 22:50:08 +00: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 18:37:54 +00:00
|
|
|
// Called when the document is going away
|
|
|
|
void DropDocumentReference();
|
|
|
|
|
2013-05-01 22:50:08 +00:00
|
|
|
nsIContent* FindNestedInsertionPoint(nsIContent* aContainer,
|
|
|
|
nsIContent* aChild);
|
|
|
|
|
|
|
|
nsIContent* FindNestedSingleInsertionPoint(nsIContent* aContainer, bool* aMulti);
|
|
|
|
|
2005-02-19 10:31:27 +00:00
|
|
|
protected:
|
2007-02-27 00:14:01 +00:00
|
|
|
nsIXPConnectWrappedJS* GetWrappedJS(nsIContent* aContent);
|
|
|
|
nsresult SetWrappedJS(nsIContent* aContent, nsIXPConnectWrappedJS* aResult);
|
|
|
|
|
2007-11-15 17:17:46 +00: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 15:56:38 +00:00
|
|
|
uint32_t aIndexInContainer, bool aAppend);
|
2007-11-15 17:17:46 +00:00
|
|
|
|
2007-03-09 23:43:50 +00:00
|
|
|
// Same as ProcessAttachedQueue, but also nulls out
|
|
|
|
// mProcessAttachedQueueEvent
|
|
|
|
void DoProcessAttachedQueue();
|
|
|
|
|
2007-12-04 17:30:07 +00:00
|
|
|
// Post an event to process the attached queue.
|
|
|
|
void PostProcessAttachedQueueEvent();
|
|
|
|
|
2005-02-19 10:31:27 +00:00
|
|
|
// MEMBER VARIABLES
|
|
|
|
protected:
|
2013-07-17 16:05:03 +00:00
|
|
|
// A set of nsIContent that currently have a binding installed.
|
2013-09-02 08:41:57 +00:00
|
|
|
nsAutoPtr<nsTHashtable<nsRefPtrHashKey<nsIContent> > > mBoundContentSet;
|
2005-02-19 10:31:27 +00: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).
|
|
|
|
PLDHashTable mWrapperTable;
|
|
|
|
|
2010-07-15 01:53:11 +00:00
|
|
|
// A mapping from a URL (a string) to nsXBLDocumentInfo*. This table
|
2005-02-19 10:31:27 +00:00
|
|
|
// is the cache of all binding documents that have been loaded by a
|
|
|
|
// given bound document.
|
2013-09-02 08:41:57 +00:00
|
|
|
nsAutoPtr<nsRefPtrHashtable<nsURIHashKey,nsXBLDocumentInfo> > mDocumentTable;
|
2005-02-19 10:31:27 +00: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 08:41:57 +00:00
|
|
|
nsAutoPtr<nsInterfaceHashtable<nsURIHashKey,nsIStreamListener> > mLoadingDocTable;
|
2005-02-19 10:31:27 +00:00
|
|
|
|
2005-02-25 22:07:01 +00:00
|
|
|
// A queue of binding attached event handlers that are awaiting execution.
|
2006-12-14 21:32:10 +00:00
|
|
|
nsBindingList mAttachedStack;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mProcessingAttachedStack;
|
|
|
|
bool mDestroyed;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mAttachedStackSizeOnOutermost;
|
2007-03-09 23:43:50 +00:00
|
|
|
|
|
|
|
// Our posted event to process the attached queue, if any
|
|
|
|
friend class nsRunnableMethod<nsBindingManager>;
|
2009-02-04 02:58:21 +00:00
|
|
|
nsRefPtr< nsRunnableMethod<nsBindingManager> > mProcessAttachedQueueEvent;
|
2007-10-03 23:38:32 +00:00
|
|
|
|
|
|
|
// Our document. This is a weak ref; the document owns us
|
|
|
|
nsIDocument* mDocument;
|
2005-02-19 10:31:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|