Backed out changeset 9d8b4c0b99ed (bug 1945683) for causing btime failures. CLOSED...
[gecko.git] / dom / base / MutationObservers.h
blob367cf7e1899391c3077673a6f224d905e0ff4fb2
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 #ifndef DOM_BASE_MUTATIONOBSERVERS_H_
8 #define DOM_BASE_MUTATIONOBSERVERS_H_
10 #include "mozilla/DoublyLinkedList.h"
11 #include "nsIContent.h" // for use in inline function (NotifyParentChainChanged)
12 #include "nsIMutationObserver.h" // for use in inline function (NotifyParentChainChanged)
13 #include "nsINode.h"
15 class nsAtom;
16 class nsAttrValue;
17 struct BatchRemovalState;
19 namespace mozilla::dom {
20 class Animation;
21 class Element;
23 class MutationObservers {
24 public:
25 /**
26 * Send CharacterDataWillChange notifications to nsIMutationObservers.
27 * @param aContent Node whose data changed
28 * @param aInfo Struct with information details about the change
29 * @see nsIMutationObserver::CharacterDataWillChange
31 static void NotifyCharacterDataWillChange(nsIContent* aContent,
32 const CharacterDataChangeInfo&);
34 /**
35 * Send CharacterDataChanged notifications to nsIMutationObservers.
36 * @param aContent Node whose data changed
37 * @param aInfo Struct with information details about the change
38 * @see nsIMutationObserver::CharacterDataChanged
40 static void NotifyCharacterDataChanged(nsIContent* aContent,
41 const CharacterDataChangeInfo&);
43 /**
44 * Send AttributeWillChange notifications to nsIMutationObservers.
45 * @param aElement Element whose data will change
46 * @param aNameSpaceID Namespace of changing attribute
47 * @param aAttribute Local-name of changing attribute
48 * @param aModType Type of change (add/change/removal)
49 * @see nsIMutationObserver::AttributeWillChange
51 static void NotifyAttributeWillChange(mozilla::dom::Element* aElement,
52 int32_t aNameSpaceID,
53 nsAtom* aAttribute, int32_t aModType);
55 /**
56 * Send AttributeChanged notifications to nsIMutationObservers.
57 * @param aElement Element whose data changed
58 * @param aNameSpaceID Namespace of changed attribute
59 * @param aAttribute Local-name of changed attribute
60 * @param aModType Type of change (add/change/removal)
61 * @param aOldValue If the old value was StoresOwnData() (or absent),
62 * that value, otherwise null
63 * @see nsIMutationObserver::AttributeChanged
65 static void NotifyAttributeChanged(mozilla::dom::Element* aElement,
66 int32_t aNameSpaceID, nsAtom* aAttribute,
67 int32_t aModType,
68 const nsAttrValue* aOldValue);
70 /**
71 * Send AttributeSetToCurrentValue notifications to nsIMutationObservers.
72 * @param aElement Element whose data changed
73 * @param aNameSpaceID Namespace of the attribute
74 * @param aAttribute Local-name of the attribute
75 * @see nsIMutationObserver::AttributeSetToCurrentValue
77 static void NotifyAttributeSetToCurrentValue(mozilla::dom::Element* aElement,
78 int32_t aNameSpaceID,
79 nsAtom* aAttribute);
81 /**
82 * Send ContentAppended notifications to nsIMutationObservers
83 * @param aContainer Node into which new child/children were added
84 * @param aFirstNewContent First new child
85 * @see nsIMutationObserver::ContentAppended
87 static void NotifyContentAppended(nsIContent* aContainer,
88 nsIContent* aFirstNewContent);
90 /**
91 * Send ContentInserted notifications to nsIMutationObservers
92 * @param aContainer Node into which new child was inserted
93 * @param aChild Newly inserted child
94 * @see nsIMutationObserver::ContentInserted
96 static void NotifyContentInserted(nsINode* aContainer, nsIContent* aChild);
97 /**
98 * Send ContentWillBeRemoved notifications to nsIMutationObservers
99 * @param aContainer Node from which child was removed
100 * @param aChild Removed child
101 * @param aBatchRemoving Whether we'll be removing all children of this
102 * container. This is useful to avoid wasteful work.
103 * @see nsIMutationObserver::ContentWillBeRemoved
105 static void NotifyContentWillBeRemoved(nsINode* aContainer,
106 nsIContent* aChild,
107 const BatchRemovalState*);
110 * Send ParentChainChanged notifications to nsIMutationObservers
111 * @param aContent The piece of content that had its parent changed.
112 * @see nsIMutationObserver::ParentChainChanged
114 static inline void NotifyParentChainChanged(nsIContent* aContent) {
115 mozilla::SafeDoublyLinkedList<nsIMutationObserver>* observers =
116 aContent->GetMutationObservers();
117 if (observers) {
118 for (auto iter = observers->begin(); iter != observers->end(); ++iter) {
119 if (iter->IsCallbackEnabled(nsIMutationObserver::kParentChainChanged)) {
120 iter->ParentChainChanged(aContent);
126 static void NotifyARIAAttributeDefaultWillChange(
127 mozilla::dom::Element* aElement, nsAtom* aAttribute, int32_t aModType);
128 static void NotifyARIAAttributeDefaultChanged(mozilla::dom::Element* aElement,
129 nsAtom* aAttribute,
130 int32_t aModType);
133 * Notify that an animation is added/changed/removed.
134 * @param aAnimation The animation we added/changed/removed.
136 static void NotifyAnimationAdded(mozilla::dom::Animation* aAnimation);
137 static void NotifyAnimationChanged(mozilla::dom::Animation* aAnimation);
138 static void NotifyAnimationRemoved(mozilla::dom::Animation* aAnimation);
140 private:
141 enum class AnimationMutationType { Added, Changed, Removed };
143 * Notify the observers of the target of an animation
144 * @param aAnimation The mutated animation.
145 * @param aMutationType The mutation type of this animation. It could be
146 * Added, Changed, or Removed.
148 static void NotifyAnimationMutated(mozilla::dom::Animation* aAnimation,
149 AnimationMutationType aMutatedType);
151 } // namespace mozilla::dom
153 #endif // DOM_BASE_MUTATIONOBSERVERS_H_