dom/xbl/nsBindingManager.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/xbl/nsBindingManager.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,200 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsBindingManager_h_
    1.10 +#define nsBindingManager_h_
    1.11 +
    1.12 +#include "nsIContent.h"
    1.13 +#include "nsStubMutationObserver.h"
    1.14 +#include "nsHashKeys.h"
    1.15 +#include "nsInterfaceHashtable.h"
    1.16 +#include "nsRefPtrHashtable.h"
    1.17 +#include "nsURIHashKey.h"
    1.18 +#include "nsCycleCollectionParticipant.h"
    1.19 +#include "nsXBLBinding.h"
    1.20 +#include "nsTArray.h"
    1.21 +#include "nsThreadUtils.h"
    1.22 +
    1.23 +struct ElementDependentRuleProcessorData;
    1.24 +class nsIXPConnectWrappedJS;
    1.25 +class nsIAtom;
    1.26 +class nsIDOMNodeList;
    1.27 +class nsIDocument;
    1.28 +class nsIURI;
    1.29 +class nsXBLDocumentInfo;
    1.30 +class nsIStreamListener;
    1.31 +class nsStyleSet;
    1.32 +class nsXBLBinding;
    1.33 +template<class E> class nsRefPtr;
    1.34 +typedef nsTArray<nsRefPtr<nsXBLBinding> > nsBindingList;
    1.35 +class nsIPrincipal;
    1.36 +class nsCSSStyleSheet;
    1.37 +
    1.38 +class nsBindingManager MOZ_FINAL : public nsStubMutationObserver
    1.39 +{
    1.40 +public:
    1.41 +  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    1.42 +
    1.43 +  NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
    1.44 +  NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
    1.45 +  NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
    1.46 +
    1.47 +  nsBindingManager(nsIDocument* aDocument);
    1.48 +  ~nsBindingManager();
    1.49 +
    1.50 +  nsXBLBinding* GetBindingWithContent(nsIContent* aContent);
    1.51 +
    1.52 +  void AddBoundContent(nsIContent* aContent);
    1.53 +  void RemoveBoundContent(nsIContent* aContent);
    1.54 +
    1.55 +  /**
    1.56 +   * Notify the binding manager that an element
    1.57 +   * has been removed from its document,
    1.58 +   * so that it can update any bindings or
    1.59 +   * nsIAnonymousContentCreator-created anonymous
    1.60 +   * content that may depend on the document.
    1.61 +   * @param aContent the element that's being moved
    1.62 +   * @param aOldDocument the old document in which the
    1.63 +   *   content resided.
    1.64 +   */
    1.65 +  void RemovedFromDocument(nsIContent* aContent, nsIDocument* aOldDocument)
    1.66 +  {
    1.67 +    if (aContent->HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
    1.68 +      RemovedFromDocumentInternal(aContent, aOldDocument);
    1.69 +    }
    1.70 +  }
    1.71 +  void RemovedFromDocumentInternal(nsIContent* aContent,
    1.72 +                                   nsIDocument* aOldDocument);
    1.73 +
    1.74 +  nsIAtom* ResolveTag(nsIContent* aContent, int32_t* aNameSpaceID);
    1.75 +
    1.76 +  /**
    1.77 +   * Return the nodelist of "anonymous" kids for this node.  This might
    1.78 +   * actually include some of the nodes actual DOM kids, if there are
    1.79 +   * <children> tags directly as kids of <content>.  This will only end up
    1.80 +   * returning a non-null list for nodes which have a binding attached.
    1.81 +   */
    1.82 +  nsresult GetAnonymousNodesFor(nsIContent* aContent, nsIDOMNodeList** aResult);
    1.83 +  nsINodeList* GetAnonymousNodesFor(nsIContent* aContent);
    1.84 +
    1.85 +  nsresult ClearBinding(nsIContent* aContent);
    1.86 +  nsresult LoadBindingDocument(nsIDocument* aBoundDoc, nsIURI* aURL,
    1.87 +                               nsIPrincipal* aOriginPrincipal);
    1.88 +
    1.89 +  nsresult AddToAttachedQueue(nsXBLBinding* aBinding);
    1.90 +  void RemoveFromAttachedQueue(nsXBLBinding* aBinding);
    1.91 +  void ProcessAttachedQueue(uint32_t aSkipSize = 0);
    1.92 +
    1.93 +  void ExecuteDetachedHandlers();
    1.94 +
    1.95 +  nsresult PutXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo);
    1.96 +  nsXBLDocumentInfo* GetXBLDocumentInfo(nsIURI* aURI);
    1.97 +  void RemoveXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo);
    1.98 +
    1.99 +  nsresult PutLoadingDocListener(nsIURI* aURL, nsIStreamListener* aListener);
   1.100 +  nsIStreamListener* GetLoadingDocListener(nsIURI* aURL);
   1.101 +  void RemoveLoadingDocListener(nsIURI* aURL);
   1.102 +
   1.103 +  void FlushSkinBindings();
   1.104 +
   1.105 +  nsresult GetBindingImplementation(nsIContent* aContent, REFNSIID aIID, void** aResult);
   1.106 +
   1.107 +  // Style rule methods
   1.108 +  nsresult WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc,
   1.109 +                     ElementDependentRuleProcessorData* aData,
   1.110 +                     bool* aCutOffInheritance);
   1.111 +
   1.112 +  void WalkAllRules(nsIStyleRuleProcessor::EnumFunc aFunc,
   1.113 +                    ElementDependentRuleProcessorData* aData);
   1.114 +  /**
   1.115 +   * Do any processing that needs to happen as a result of a change in
   1.116 +   * the characteristics of the medium, and return whether this rule
   1.117 +   * processor's rules have changed (e.g., because of media queries).
   1.118 +   */
   1.119 +  nsresult MediumFeaturesChanged(nsPresContext* aPresContext,
   1.120 +                                 bool* aRulesChanged);
   1.121 +
   1.122 +  void AppendAllSheets(nsTArray<nsCSSStyleSheet*>& aArray);
   1.123 +
   1.124 +  NS_HIDDEN_(void) Traverse(nsIContent *aContent,
   1.125 +                            nsCycleCollectionTraversalCallback &cb);
   1.126 +
   1.127 +  NS_DECL_CYCLE_COLLECTION_CLASS(nsBindingManager)
   1.128 +
   1.129 +  // Notify the binding manager when an outermost update begins and
   1.130 +  // ends.  The end method can execute script.
   1.131 +  void BeginOutermostUpdate();
   1.132 +  void EndOutermostUpdate();
   1.133 +
   1.134 +  // When removing an insertion point or a parent of one, clear the insertion
   1.135 +  // points and their insertion parents.
   1.136 +  void ClearInsertionPointsRecursively(nsIContent* aContent);
   1.137 +
   1.138 +  // Called when the document is going away
   1.139 +  void DropDocumentReference();
   1.140 +
   1.141 +  nsIContent* FindNestedInsertionPoint(nsIContent* aContainer,
   1.142 +                                       nsIContent* aChild);
   1.143 +
   1.144 +  nsIContent* FindNestedSingleInsertionPoint(nsIContent* aContainer, bool* aMulti);
   1.145 +
   1.146 +protected:
   1.147 +  nsIXPConnectWrappedJS* GetWrappedJS(nsIContent* aContent);
   1.148 +  nsresult SetWrappedJS(nsIContent* aContent, nsIXPConnectWrappedJS* aResult);
   1.149 +
   1.150 +  // Called by ContentAppended and ContentInserted to handle a single child
   1.151 +  // insertion.  aChild must not be null.  aContainer may be null.
   1.152 +  // aIndexInContainer is the index of the child in the parent.  aAppend is
   1.153 +  // true if this child is being appended, not inserted.
   1.154 +  void HandleChildInsertion(nsIContent* aContainer, nsIContent* aChild,
   1.155 +                            uint32_t aIndexInContainer, bool aAppend);
   1.156 +
   1.157 +  // Same as ProcessAttachedQueue, but also nulls out
   1.158 +  // mProcessAttachedQueueEvent
   1.159 +  void DoProcessAttachedQueue();
   1.160 +
   1.161 +  // Post an event to process the attached queue.
   1.162 +  void PostProcessAttachedQueueEvent();
   1.163 +
   1.164 +// MEMBER VARIABLES
   1.165 +protected:
   1.166 +  // A set of nsIContent that currently have a binding installed.
   1.167 +  nsAutoPtr<nsTHashtable<nsRefPtrHashKey<nsIContent> > > mBoundContentSet;
   1.168 +
   1.169 +  // A mapping from nsIContent* to nsIXPWrappedJS* (an XPConnect
   1.170 +  // wrapper for JS objects).  For XBL bindings that implement XPIDL
   1.171 +  // interfaces, and that get referred to from C++, this table caches
   1.172 +  // the XPConnect wrapper for the binding.  By caching it, I control
   1.173 +  // its lifetime, and I prevent a re-wrap of the same script object
   1.174 +  // (in the case where multiple bindings in an XBL inheritance chain
   1.175 +  // both implement an XPIDL interface).
   1.176 +  typedef nsInterfaceHashtable<nsISupportsHashKey, nsIXPConnectWrappedJS> WrapperHashtable;
   1.177 +  nsAutoPtr<WrapperHashtable> mWrapperTable;
   1.178 +
   1.179 +  // A mapping from a URL (a string) to nsXBLDocumentInfo*.  This table
   1.180 +  // is the cache of all binding documents that have been loaded by a
   1.181 +  // given bound document.
   1.182 +  nsAutoPtr<nsRefPtrHashtable<nsURIHashKey,nsXBLDocumentInfo> > mDocumentTable;
   1.183 +
   1.184 +  // A mapping from a URL (a string) to a nsIStreamListener. This
   1.185 +  // table is the currently loading binding docs.  If they're in this
   1.186 +  // table, they have not yet finished loading.
   1.187 +  nsAutoPtr<nsInterfaceHashtable<nsURIHashKey,nsIStreamListener> > mLoadingDocTable;
   1.188 +
   1.189 +  // A queue of binding attached event handlers that are awaiting execution.
   1.190 +  nsBindingList mAttachedStack;
   1.191 +  bool mProcessingAttachedStack;
   1.192 +  bool mDestroyed;
   1.193 +  uint32_t mAttachedStackSizeOnOutermost;
   1.194 +
   1.195 +  // Our posted event to process the attached queue, if any
   1.196 +  friend class nsRunnableMethod<nsBindingManager>;
   1.197 +  nsRefPtr< nsRunnableMethod<nsBindingManager> > mProcessAttachedQueueEvent;
   1.198 +
   1.199 +  // Our document.  This is a weak ref; the document owns us
   1.200 +  nsIDocument* mDocument;
   1.201 +};
   1.202 +
   1.203 +#endif

mercurial