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)
18 namespace mozilla::dom
{
22 class MutationObservers
{
25 * Send CharacterDataWillChange notifications to nsIMutationObservers.
26 * @param aContent Node whose data changed
27 * @param aInfo Struct with information details about the change
28 * @see nsIMutationObserver::CharacterDataWillChange
30 static void NotifyCharacterDataWillChange(nsIContent
* aContent
,
31 const CharacterDataChangeInfo
&);
34 * Send CharacterDataChanged notifications to nsIMutationObservers.
35 * @param aContent Node whose data changed
36 * @param aInfo Struct with information details about the change
37 * @see nsIMutationObserver::CharacterDataChanged
39 static void NotifyCharacterDataChanged(nsIContent
* aContent
,
40 const CharacterDataChangeInfo
&);
43 * Send AttributeWillChange notifications to nsIMutationObservers.
44 * @param aElement Element whose data will change
45 * @param aNameSpaceID Namespace of changing attribute
46 * @param aAttribute Local-name of changing attribute
47 * @param aModType Type of change (add/change/removal)
48 * @see nsIMutationObserver::AttributeWillChange
50 static void NotifyAttributeWillChange(mozilla::dom::Element
* aElement
,
52 nsAtom
* aAttribute
, int32_t aModType
);
55 * Send AttributeChanged notifications to nsIMutationObservers.
56 * @param aElement Element whose data changed
57 * @param aNameSpaceID Namespace of changed attribute
58 * @param aAttribute Local-name of changed attribute
59 * @param aModType Type of change (add/change/removal)
60 * @param aOldValue If the old value was StoresOwnData() (or absent),
61 * that value, otherwise null
62 * @see nsIMutationObserver::AttributeChanged
64 static void NotifyAttributeChanged(mozilla::dom::Element
* aElement
,
65 int32_t aNameSpaceID
, nsAtom
* aAttribute
,
67 const nsAttrValue
* aOldValue
);
70 * Send AttributeSetToCurrentValue notifications to nsIMutationObservers.
71 * @param aElement Element whose data changed
72 * @param aNameSpaceID Namespace of the attribute
73 * @param aAttribute Local-name of the attribute
74 * @see nsIMutationObserver::AttributeSetToCurrentValue
76 static void NotifyAttributeSetToCurrentValue(mozilla::dom::Element
* aElement
,
81 * Send ContentAppended notifications to nsIMutationObservers
82 * @param aContainer Node into which new child/children were added
83 * @param aFirstNewContent First new child
84 * @see nsIMutationObserver::ContentAppended
86 static void NotifyContentAppended(nsIContent
* aContainer
,
87 nsIContent
* aFirstNewContent
);
90 * Send ContentInserted notifications to nsIMutationObservers
91 * @param aContainer Node into which new child was inserted
92 * @param aChild Newly inserted child
93 * @see nsIMutationObserver::ContentInserted
95 static void NotifyContentInserted(nsINode
* aContainer
, nsIContent
* aChild
);
97 * Send ContentRemoved notifications to nsIMutationObservers
98 * @param aContainer Node from which child was removed
99 * @param aChild Removed child
100 * @param aPreviousSibling Previous sibling of the removed child
101 * @see nsIMutationObserver::ContentRemoved
103 static void NotifyContentRemoved(nsINode
* aContainer
, nsIContent
* aChild
,
104 nsIContent
* aPreviousSibling
);
107 * Send ParentChainChanged notifications to nsIMutationObservers
108 * @param aContent The piece of content that had its parent changed.
109 * @see nsIMutationObserver::ParentChainChanged
111 static inline void NotifyParentChainChanged(nsIContent
* aContent
) {
112 mozilla::SafeDoublyLinkedList
<nsIMutationObserver
>* observers
=
113 aContent
->GetMutationObservers();
115 for (auto iter
= observers
->begin(); iter
!= observers
->end(); ++iter
) {
116 if (iter
->IsCallbackEnabled(nsIMutationObserver::kParentChainChanged
)) {
117 iter
->ParentChainChanged(aContent
);
123 static void NotifyARIAAttributeDefaultWillChange(
124 mozilla::dom::Element
* aElement
, nsAtom
* aAttribute
, int32_t aModType
);
125 static void NotifyARIAAttributeDefaultChanged(mozilla::dom::Element
* aElement
,
130 * Notify that an animation is added/changed/removed.
131 * @param aAnimation The animation we added/changed/removed.
133 static void NotifyAnimationAdded(mozilla::dom::Animation
* aAnimation
);
134 static void NotifyAnimationChanged(mozilla::dom::Animation
* aAnimation
);
135 static void NotifyAnimationRemoved(mozilla::dom::Animation
* aAnimation
);
138 enum class AnimationMutationType
{ Added
, Changed
, Removed
};
140 * Notify the observers of the target of an animation
141 * @param aAnimation The mutated animation.
142 * @param aMutationType The mutation type of this animation. It could be
143 * Added, Changed, or Removed.
145 static void NotifyAnimationMutated(mozilla::dom::Animation
* aAnimation
,
146 AnimationMutationType aMutatedType
);
148 } // namespace mozilla::dom
150 #endif // DOM_BASE_MUTATIONOBSERVERS_H_