Bug 1835710 - Cancel off-thread JIT compilation before changing nursery allocation...
[gecko.git] / dom / base / nsStubMutationObserver.h
bloba58b1c6713ab983dccd3551add2760679b38b541
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/. */
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.
14 #ifndef nsStubMutationObserver_h_
15 #define nsStubMutationObserver_h_
17 #include "nsTHashMap.h"
18 #include "nsIMutationObserver.h"
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)
31 class nsStubMutationObserver : public nsIMutationObserver {
32 public:
33 NS_DECL_NSIMUTATIONOBSERVER
36 class MutationObserverWrapper;
38 /**
39 * @brief Base class for MutationObservers that are used by multiple nodes.
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.
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.
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.
56 void AddMutationObserverToNode(nsINode* aNode);
58 /**
59 * Removes the mutation observer from aNode.
60 * Does nothing if there is no mutation observer for aNode.
62 void RemoveMutationObserverFromNode(nsINode* aNode);
64 /**
65 * Returns true if there is already a mutation observer for aNode.
67 bool ContainsNode(const nsINode* aNode) const;
69 private:
70 friend class MutationObserverWrapper;
71 nsTHashMap<nsINode*, MutationObserverWrapper*> mWrapperForNode;
74 /**
75 * Convenience class that provides support for multiple nodes and has
76 * default implementations for nsIMutationObserver.
78 class nsStubMultiMutationObserver : public nsMultiMutationObserver {
79 public:
80 NS_DECL_NSIMUTATIONOBSERVER
83 #endif /* !defined(nsStubMutationObserver_h_) */