tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsStubMutationObserver.h (2947B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 /*
      8 * nsStubMutationObserver is an implementation of the nsIMutationObserver
      9 * interface (except for the methods on nsISupports) that is intended to be
     10 * used as a base class within the content/layout library.  All methods do
     11 * nothing.
     12 */
     13 
     14 #ifndef nsStubMutationObserver_h_
     15 #define nsStubMutationObserver_h_
     16 
     17 #include "nsIMutationObserver.h"
     18 #include "nsTHashMap.h"
     19 
     20 /**
     21 * There are two advantages to inheriting from nsStubMutationObserver
     22 * rather than directly from nsIMutationObserver:
     23 *  1. smaller compiled code size (since there's no need for the code
     24 *     for the empty virtual function implementations for every
     25 *     nsIMutationObserver implementation)
     26 *  2. the performance of document's loop over observers benefits from
     27 *     the fact that more of the functions called are the same (which
     28 *     can reduce instruction cache misses and perhaps improve branch
     29 *     prediction)
     30 */
     31 class nsStubMutationObserver : public nsIMutationObserver {
     32 public:
     33  NS_DECL_NSIMUTATIONOBSERVER
     34 };
     35 
     36 class MutationObserverWrapper;
     37 
     38 /**
     39 * @brief Base class for MutationObservers that are used by multiple nodes.
     40 *
     41 * Mutation Observers are stored inside of a nsINode using a DoublyLinkedList,
     42 * restricting the number of nodes a mutation observer can be inserted to one.
     43 *
     44 * To allow a mutation observer to be used by several nodes, this class
     45 * provides a MutationObserverWrapper which implements the nsIMutationObserver
     46 * interface and forwards all method calls to this class. For each node this
     47 * mutation observer will be used for, a wrapper object is created.
     48 */
     49 class nsMultiMutationObserver : public nsIMutationObserver {
     50 public:
     51  /**
     52   * Adds the mutation observer to aNode by creating a MutationObserverWrapper
     53   * and inserting it into aNode.
     54   * Does nothing if there already is a mutation observer for aNode.
     55   */
     56  void AddMutationObserverToNode(nsINode* aNode);
     57 
     58  /**
     59   * Removes the mutation observer from aNode.
     60   * Does nothing if there is no mutation observer for aNode.
     61   */
     62  void RemoveMutationObserverFromNode(nsINode* aNode);
     63 
     64  /**
     65   * Returns true if there is already a mutation observer for aNode.
     66   */
     67  bool ContainsNode(const nsINode* aNode) const;
     68 
     69 private:
     70  friend class MutationObserverWrapper;
     71  nsTHashMap<nsINode*, MutationObserverWrapper*> mWrapperForNode;
     72 };
     73 
     74 /**
     75 * Convenience class that provides support for multiple nodes and has
     76 * default implementations for nsIMutationObserver.
     77 */
     78 class nsStubMultiMutationObserver : public nsMultiMutationObserver {
     79 public:
     80  NS_DECL_NSIMUTATIONOBSERVER
     81 };
     82 
     83 #endif /* !defined(nsStubMutationObserver_h_) */