2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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 13:31:27 +03:00
|
|
|
|
|
|
|
#ifndef nsBindingManager_h_
|
|
|
|
#define nsBindingManager_h_
|
|
|
|
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2013-03-22 04:05:20 +04:00
|
|
|
#include "nsIContent.h"
|
2007-12-04 21:37:54 +03:00
|
|
|
#include "nsStubMutationObserver.h"
|
2014-04-10 18:05:19 +04:00
|
|
|
#include "nsHashKeys.h"
|
2005-02-19 13:31:27 +03:00
|
|
|
#include "nsInterfaceHashtable.h"
|
2005-02-26 01:07:01 +03:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2005-02-19 13:31:27 +03:00
|
|
|
#include "nsURIHashKey.h"
|
2007-01-05 01:31:26 +03:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2007-02-17 02:02:08 +03:00
|
|
|
#include "nsXBLBinding.h"
|
|
|
|
#include "nsTArray.h"
|
2009-02-18 07:11:09 +03:00
|
|
|
#include "nsThreadUtils.h"
|
2016-09-26 15:03:25 +03:00
|
|
|
#include "mozilla/StyleSheet.h"
|
2005-02-19 13:31:27 +03:00
|
|
|
|
2012-11-19 21:22:27 +04:00
|
|
|
struct ElementDependentRuleProcessorData;
|
2005-02-19 13:31:27 +03:00
|
|
|
class nsIXPConnectWrappedJS;
|
|
|
|
class nsIAtom;
|
|
|
|
class nsIDOMNodeList;
|
|
|
|
class nsIDocument;
|
|
|
|
class nsIURI;
|
2010-07-15 05:53:11 +04:00
|
|
|
class nsXBLDocumentInfo;
|
2005-02-19 13:31:27 +03:00
|
|
|
class nsIStreamListener;
|
2007-02-17 02:02:08 +03:00
|
|
|
class nsXBLBinding;
|
2015-10-18 08:24:48 +03:00
|
|
|
typedef nsTArray<RefPtr<nsXBLBinding> > nsBindingList;
|
2007-07-19 01:56:57 +04:00
|
|
|
class nsIPrincipal;
|
2014-07-01 22:30:13 +04:00
|
|
|
class nsITimer;
|
2014-06-20 14:32:49 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsBindingManager final : public nsStubMutationObserver
|
2005-02-19 13:31:27 +03:00
|
|
|
{
|
2014-06-23 23:56:07 +04:00
|
|
|
~nsBindingManager();
|
|
|
|
|
2006-08-16 02:41:58 +04:00
|
|
|
public:
|
2007-01-05 01:31:26 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2007-12-04 21:37:54 +03:00
|
|
|
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
2005-02-19 13:31:27 +03:00
|
|
|
|
2014-08-05 17:19:51 +04:00
|
|
|
explicit nsBindingManager(nsIDocument* aDocument);
|
2005-02-19 13:31:27 +03:00
|
|
|
|
2013-05-02 02:50:08 +04:00
|
|
|
nsXBLBinding* GetBindingWithContent(nsIContent* aContent);
|
2013-07-17 20:05:03 +04:00
|
|
|
|
|
|
|
void AddBoundContent(nsIContent* aContent);
|
|
|
|
void RemoveBoundContent(nsIContent* aContent);
|
2007-02-17 02:02:08 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify the binding manager that an element
|
2010-06-04 05:09:08 +04:00
|
|
|
* has been removed from its document,
|
2007-02-17 02:02:08 +03: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 05:09:08 +04:00
|
|
|
* content resided.
|
2016-02-19 22:13:42 +03:00
|
|
|
* @param aDestructorHandling whether or not to run the possible XBL
|
|
|
|
* destructor.
|
2007-02-17 02:02:08 +03:00
|
|
|
*/
|
2016-02-19 22:13:42 +03:00
|
|
|
|
|
|
|
enum DestructorHandling {
|
|
|
|
eRunDtor,
|
|
|
|
eDoNotRunDtor
|
|
|
|
};
|
|
|
|
void RemovedFromDocument(nsIContent* aContent, nsIDocument* aOldDocument,
|
|
|
|
DestructorHandling aDestructorHandling)
|
2010-06-04 05:09:08 +04:00
|
|
|
{
|
|
|
|
if (aContent->HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
|
2016-02-19 22:13:42 +03:00
|
|
|
RemovedFromDocumentInternal(aContent, aOldDocument, aDestructorHandling);
|
2010-06-04 05:09:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void RemovedFromDocumentInternal(nsIContent* aContent,
|
2016-02-19 22:13:42 +03:00
|
|
|
nsIDocument* aOldDocument,
|
|
|
|
DestructorHandling aDestructorHandling);
|
2007-02-17 02:02:08 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsIAtom* ResolveTag(nsIContent* aContent, int32_t* aNameSpaceID);
|
2007-02-17 02:02:08 +03:00
|
|
|
|
|
|
|
/**
|
2009-01-29 22:46:18 +03: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-17 02:02:08 +03:00
|
|
|
*/
|
|
|
|
nsresult GetAnonymousNodesFor(nsIContent* aContent, nsIDOMNodeList** aResult);
|
2010-05-14 21:04:51 +04:00
|
|
|
nsINodeList* GetAnonymousNodesFor(nsIContent* aContent);
|
|
|
|
|
2013-01-24 21:45:50 +04:00
|
|
|
nsresult ClearBinding(nsIContent* aContent);
|
2007-07-19 01:56:57 +04:00
|
|
|
nsresult LoadBindingDocument(nsIDocument* aBoundDoc, nsIURI* aURL,
|
|
|
|
nsIPrincipal* aOriginPrincipal);
|
2005-02-19 13:31:27 +03:00
|
|
|
|
2007-02-17 02:02:08 +03:00
|
|
|
nsresult AddToAttachedQueue(nsXBLBinding* aBinding);
|
2013-07-17 20:05:03 +04:00
|
|
|
void RemoveFromAttachedQueue(nsXBLBinding* aBinding);
|
2016-06-01 12:03:45 +03:00
|
|
|
void ProcessAttachedQueue(uint32_t aSkipSize = 0)
|
|
|
|
{
|
|
|
|
if (mProcessingAttachedStack || mAttachedStack.Length() <= aSkipSize) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessAttachedQueueInternal(aSkipSize);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
void ProcessAttachedQueueInternal(uint32_t aSkipSize);
|
|
|
|
|
|
|
|
public:
|
2005-02-19 13:31:27 +03:00
|
|
|
|
2007-02-27 03:14:01 +03:00
|
|
|
void ExecuteDetachedHandlers();
|
2005-02-19 13:31:27 +03:00
|
|
|
|
2010-07-15 05:53:11 +04:00
|
|
|
nsresult PutXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo);
|
|
|
|
nsXBLDocumentInfo* GetXBLDocumentInfo(nsIURI* aURI);
|
|
|
|
void RemoveXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo);
|
2005-02-19 13:31:27 +03:00
|
|
|
|
2007-02-17 02:02:08 +03:00
|
|
|
nsresult PutLoadingDocListener(nsIURI* aURL, nsIStreamListener* aListener);
|
2007-02-27 03:14:01 +03:00
|
|
|
nsIStreamListener* GetLoadingDocListener(nsIURI* aURL);
|
|
|
|
void RemoveLoadingDocListener(nsIURI* aURL);
|
2005-02-19 13:31:27 +03:00
|
|
|
|
2007-02-27 03:14:01 +03:00
|
|
|
void FlushSkinBindings();
|
2005-02-19 13:31:27 +03:00
|
|
|
|
2007-02-17 02:02:08 +03:00
|
|
|
nsresult GetBindingImplementation(nsIContent* aContent, REFNSIID aIID, void** aResult);
|
2005-02-19 13:31:27 +03:00
|
|
|
|
2007-02-17 02:02:08 +03:00
|
|
|
// Style rule methods
|
2008-07-26 20:14:49 +04:00
|
|
|
nsresult WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc,
|
2012-11-14 23:09:01 +04:00
|
|
|
ElementDependentRuleProcessorData* aData,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aCutOffInheritance);
|
2010-03-25 12:22:58 +03:00
|
|
|
|
|
|
|
void WalkAllRules(nsIStyleRuleProcessor::EnumFunc aFunc,
|
2012-11-14 23:09:01 +04:00
|
|
|
ElementDependentRuleProcessorData* aData);
|
2008-07-26 20:14:49 +04: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 10:19:26 +04:00
|
|
|
bool* aRulesChanged);
|
2005-02-19 13:31:27 +03:00
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
void AppendAllSheets(nsTArray<mozilla::StyleSheet*>& aArray);
|
2010-07-17 09:36:34 +04:00
|
|
|
|
2014-06-02 16:08:21 +04:00
|
|
|
void Traverse(nsIContent *aContent,
|
2007-03-08 14:17:16 +03:00
|
|
|
nsCycleCollectionTraversalCallback &cb);
|
|
|
|
|
2007-01-05 01:31:26 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS(nsBindingManager)
|
|
|
|
|
2007-05-31 05:36:06 +04:00
|
|
|
// Notify the binding manager when an outermost update begins and
|
|
|
|
// ends. The end method can execute script.
|
2016-06-01 12:03:45 +03:00
|
|
|
void BeginOutermostUpdate()
|
|
|
|
{
|
|
|
|
mAttachedStackSizeOnOutermost = mAttachedStack.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EndOutermostUpdate()
|
|
|
|
{
|
|
|
|
if (!mProcessingAttachedStack) {
|
|
|
|
ProcessAttachedQueue(mAttachedStackSizeOnOutermost);
|
|
|
|
mAttachedStackSizeOnOutermost = 0;
|
|
|
|
}
|
|
|
|
}
|
2007-05-31 05:36:06 +04:00
|
|
|
|
2013-05-02 02:50:08 +04: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 21:37:54 +03:00
|
|
|
// Called when the document is going away
|
|
|
|
void DropDocumentReference();
|
|
|
|
|
2013-05-02 02:50:08 +04:00
|
|
|
nsIContent* FindNestedInsertionPoint(nsIContent* aContainer,
|
|
|
|
nsIContent* aChild);
|
|
|
|
|
|
|
|
nsIContent* FindNestedSingleInsertionPoint(nsIContent* aContainer, bool* aMulti);
|
|
|
|
|
2005-02-19 13:31:27 +03:00
|
|
|
protected:
|
2007-02-27 03:14:01 +03:00
|
|
|
nsIXPConnectWrappedJS* GetWrappedJS(nsIContent* aContent);
|
|
|
|
nsresult SetWrappedJS(nsIContent* aContent, nsIXPConnectWrappedJS* aResult);
|
|
|
|
|
2007-11-15 20:17:46 +03: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 19:56:38 +04:00
|
|
|
uint32_t aIndexInContainer, bool aAppend);
|
2007-11-15 20:17:46 +03:00
|
|
|
|
2007-03-10 02:43:50 +03:00
|
|
|
// Same as ProcessAttachedQueue, but also nulls out
|
|
|
|
// mProcessAttachedQueueEvent
|
|
|
|
void DoProcessAttachedQueue();
|
|
|
|
|
2007-12-04 20:30:07 +03:00
|
|
|
// Post an event to process the attached queue.
|
|
|
|
void PostProcessAttachedQueueEvent();
|
|
|
|
|
2014-07-01 22:30:13 +04:00
|
|
|
// Call PostProcessAttachedQueueEvent() on a timer.
|
|
|
|
static void PostPAQEventCallback(nsITimer* aTimer, void* aClosure);
|
|
|
|
|
2005-02-19 13:31:27 +03:00
|
|
|
// MEMBER VARIABLES
|
2014-04-10 18:05:18 +04:00
|
|
|
protected:
|
2013-07-17 20:05:03 +04:00
|
|
|
// A set of nsIContent that currently have a binding installed.
|
2013-09-02 12:41:57 +04:00
|
|
|
nsAutoPtr<nsTHashtable<nsRefPtrHashKey<nsIContent> > > mBoundContentSet;
|
2005-02-19 13:31:27 +03: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 18:05:19 +04:00
|
|
|
typedef nsInterfaceHashtable<nsISupportsHashKey, nsIXPConnectWrappedJS> WrapperHashtable;
|
|
|
|
nsAutoPtr<WrapperHashtable> mWrapperTable;
|
2005-02-19 13:31:27 +03:00
|
|
|
|
2010-07-15 05:53:11 +04:00
|
|
|
// A mapping from a URL (a string) to nsXBLDocumentInfo*. This table
|
2005-02-19 13:31:27 +03:00
|
|
|
// is the cache of all binding documents that have been loaded by a
|
|
|
|
// given bound document.
|
2013-09-02 12:41:57 +04:00
|
|
|
nsAutoPtr<nsRefPtrHashtable<nsURIHashKey,nsXBLDocumentInfo> > mDocumentTable;
|
2005-02-19 13:31:27 +03: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 12:41:57 +04:00
|
|
|
nsAutoPtr<nsInterfaceHashtable<nsURIHashKey,nsIStreamListener> > mLoadingDocTable;
|
2005-02-19 13:31:27 +03:00
|
|
|
|
2005-02-26 01:07:01 +03:00
|
|
|
// A queue of binding attached event handlers that are awaiting execution.
|
2006-12-15 00:32:10 +03:00
|
|
|
nsBindingList mAttachedStack;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mProcessingAttachedStack;
|
|
|
|
bool mDestroyed;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mAttachedStackSizeOnOutermost;
|
2007-03-10 02:43:50 +03:00
|
|
|
|
|
|
|
// Our posted event to process the attached queue, if any
|
|
|
|
friend class nsRunnableMethod<nsBindingManager>;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr< nsRunnableMethod<nsBindingManager> > mProcessAttachedQueueEvent;
|
2007-10-04 03:38:32 +04:00
|
|
|
|
|
|
|
// Our document. This is a weak ref; the document owns us
|
2014-04-10 18:05:18 +04:00
|
|
|
nsIDocument* mDocument;
|
2005-02-19 13:31:27 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|