Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/base/nsIMutationObserver.h
Line
Count
Source (jump to first uncovered line)
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
#ifndef nsIMutationObserver_h
8
#define nsIMutationObserver_h
9
10
#include "nsISupports.h"
11
12
class nsAttrValue;
13
class nsAtom;
14
class nsIContent;
15
class nsIDocument;
16
class nsINode;
17
18
namespace mozilla {
19
namespace dom {
20
class Element;
21
} // namespace dom
22
} // namespace mozilla
23
24
#define NS_IMUTATION_OBSERVER_IID \
25
{ 0x6d674c17, 0x0fbc, 0x4633, \
26
  { 0x8f, 0x46, 0x73, 0x4e, 0x87, 0xeb, 0xf0, 0xc7 } }
27
28
/**
29
 * Information details about a characterdata change.  Basically, we
30
 * view all changes as replacements of a length of text at some offset
31
 * with some other text (of possibly some other length).
32
 */
33
struct CharacterDataChangeInfo
34
{
35
  /**
36
   * True if this character data change is just an append.
37
   */
38
  bool mAppend;
39
40
  /**
41
   * The offset in the text where the change occurred.
42
   */
43
  uint32_t mChangeStart;
44
45
  /**
46
   * The offset such that mChangeEnd - mChangeStart is equal to the length of
47
   * the text we removed. If this was a pure insert or append, this is equal to
48
   * mChangeStart.
49
   */
50
  uint32_t mChangeEnd;
51
52
  /**
53
   * The length of the text that was inserted in place of the removed text.  If
54
   * this was a pure text removal, this is 0.
55
   */
56
  uint32_t mReplaceLength;
57
58
  /**
59
   * The net result is that mChangeStart characters at the beginning of the
60
   * text remained as they were.  The next mChangeEnd - mChangeStart characters
61
   * were removed, and mReplaceLength characters were inserted in their place.
62
   * The text that used to begin at mChangeEnd now begins at
63
   * mChangeStart + mReplaceLength.
64
   */
65
66
  struct MOZ_STACK_CLASS Details {
67
    enum {
68
      eMerge,  // two text nodes are merged as a result of normalize()
69
      eSplit   // a text node is split as a result of splitText()
70
    } mType;
71
    /**
72
     * For eMerge it's the text node that will be removed, for eSplit it's the
73
     * new text node.
74
     */
75
    nsIContent* MOZ_NON_OWNING_REF mNextSibling;
76
  };
77
78
  /**
79
   * Used for splitText() and normalize(), otherwise null.
80
   */
81
  Details* mDetails;
82
};
83
84
/**
85
 * Mutation observer interface
86
 *
87
 * See nsINode::AddMutationObserver, nsINode::RemoveMutationObserver for how to
88
 * attach or remove your observers.
89
 *
90
 * WARNING: During these notifications, you are not allowed to perform
91
 * any mutations to the current or any other document, or start a
92
 * network load.  If you need to perform such operations do that
93
 * during the _last_ nsIDocumentObserver::EndUpdate notification.  The
94
 * expection for this is ParentChainChanged, where mutations should be
95
 * done from an async event, as the notification might not be
96
 * surrounded by BeginUpdate/EndUpdate calls.
97
 */
98
class nsIMutationObserver : public nsISupports
99
{
100
public:
101
  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMUTATION_OBSERVER_IID)
102
103
  /**
104
   * Notification that the node value of a data node (text, cdata, pi, comment)
105
   * will be changed.
106
   *
107
   * This notification is not sent when a piece of content is
108
   * added/removed from the document (the other notifications are used
109
   * for that).
110
   *
111
   * @param aContent  The piece of content that changed. Is never null.
112
   * @param aInfo     The structure with information details about the change.
113
   *
114
   * @note Callers of this method might not hold a strong reference to the
115
   *       observer.  The observer is responsible for making sure it stays
116
   *       alive for the duration of the call as needed.  The observer may
117
   *       assume that this call will happen when there are script blockers on
118
   *       the stack.
119
   */
120
  virtual void CharacterDataWillChange(nsIContent* aContent,
121
                                       const CharacterDataChangeInfo&) = 0;
122
123
  /**
124
   * Notification that the node value of a data node (text, cdata, pi, comment)
125
   * has changed.
126
   *
127
   * This notification is not sent when a piece of content is
128
   * added/removed from the document (the other notifications are used
129
   * for that).
130
   *
131
   * @param aContent  The piece of content that changed. Is never null.
132
   * @param aInfo     The structure with information details about the change.
133
   *
134
   * @note Callers of this method might not hold a strong reference to the
135
   *       observer.  The observer is responsible for making sure it stays
136
   *       alive for the duration of the call as needed.  The observer may
137
   *       assume that this call will happen when there are script blockers on
138
   *       the stack.
139
   */
140
  virtual void CharacterDataChanged(nsIContent* aContent,
141
                                    const CharacterDataChangeInfo&) = 0;
142
143
  /**
144
   * Notification that an attribute of an element will change.  This
145
   * can happen before the BeginUpdate for the change and may not
146
   * always be followed by an AttributeChanged (in particular, if the
147
   * attribute doesn't actually change there will be no corresponding
148
   * AttributeChanged).
149
   *
150
   * @param aContent     The element whose attribute will change
151
   * @param aNameSpaceID The namespace id of the changing attribute
152
   * @param aAttribute   The name of the changing attribute
153
   * @param aModType     Whether or not the attribute will be added, changed, or
154
   *                     removed. The constants are defined in
155
   *                     MutationEvent.webidl.
156
   * @param aNewValue    The new value, IF it has been preparsed by
157
   *                     BeforeSetAttr, otherwise null.
158
   *
159
   * @note Callers of this method might not hold a strong reference to the
160
   *       observer.  The observer is responsible for making sure it stays
161
   *       alive for the duration of the call as needed.  The observer may
162
   *       assume that this call will happen when there are script blockers on
163
   *       the stack.
164
   */
165
  virtual void AttributeWillChange(mozilla::dom::Element* aElement,
166
                                   int32_t aNameSpaceID,
167
                                   nsAtom* aAttribute,
168
                                   int32_t aModType,
169
                                   const nsAttrValue* aNewValue) = 0;
170
171
  /**
172
   * Notification that an attribute of an element has changed.
173
   *
174
   * @param aElement     The element whose attribute changed
175
   * @param aNameSpaceID The namespace id of the changed attribute
176
   * @param aAttribute   The name of the changed attribute
177
   * @param aModType     Whether or not the attribute was added, changed, or
178
   *                     removed. The constants are defined in
179
   *                     MutationEvent.webidl.
180
   * @param aOldValue    The old value, if either the old value or the new
181
   *                     value are StoresOwnData() (or absent); null otherwise.
182
   *
183
   * @note Callers of this method might not hold a strong reference to the
184
   *       observer.  The observer is responsible for making sure it stays
185
   *       alive for the duration of the call as needed.  The observer may
186
   *       assume that this call will happen when there are script blockers on
187
   *       the stack.
188
   */
189
  virtual void AttributeChanged(mozilla::dom::Element* aElement,
190
                                int32_t aNameSpaceID,
191
                                nsAtom* aAttribute,
192
                                int32_t aModType,
193
                                const nsAttrValue* aOldValue) = 0;
194
195
  /**
196
   * Notification that the root of a native anonymous has been added
197
   * or removed.
198
   *
199
   * @param aContent     Anonymous node that's been added or removed
200
   * @param aIsRemove    True if it's a removal, false if an addition
201
   */
202
  virtual void NativeAnonymousChildListChange(nsIContent* aContent,
203
                                              bool aIsRemove) {}
204
205
  /**
206
   * Notification that an attribute of an element has been
207
   * set to the value it already had.
208
   *
209
   * @param aElement     The element whose attribute changed
210
   * @param aNameSpaceID The namespace id of the changed attribute
211
   * @param aAttribute   The name of the changed attribute
212
   */
213
  virtual void AttributeSetToCurrentValue(mozilla::dom::Element* aElement,
214
                                          int32_t aNameSpaceID,
215
0
                                          nsAtom* aAttribute) {}
216
217
  /**
218
   * Notification that one or more content nodes have been appended to the
219
   * child list of another node in the tree.
220
   *
221
   * @param aFirstNewContent the first node appended.
222
   *
223
   * @note Callers of this method might not hold a strong reference to the
224
   *       observer.  The observer is responsible for making sure it stays
225
   *       alive for the duration of the call as needed.  The observer may
226
   *       assume that this call will happen when there are script blockers on
227
   *       the stack.
228
   */
229
  virtual void ContentAppended(nsIContent* aFirstNewContent) = 0;
230
231
  /**
232
   * Notification that a content node has been inserted as child to another
233
   * node in the tree.
234
   *
235
   * @param aChild The newly inserted child.
236
   *
237
   * @note Callers of this method might not hold a strong reference to the
238
   *       observer.  The observer is responsible for making sure it stays
239
   *       alive for the duration of the call as needed.  The observer may
240
   *       assume that this call will happen when there are script blockers on
241
   *       the stack.
242
   */
243
  virtual void ContentInserted(nsIContent* aChild) = 0;
244
245
  /**
246
   * Notification that a content node has been removed from the child list of
247
   * another node in the tree.
248
   *
249
   * @param aChild     The child that was removed.
250
   * @param aPreviousSibling The previous sibling to the child that was removed.
251
   *                         Can be null if there was no previous sibling.
252
   *
253
   * @note Callers of this method might not hold a strong reference to the
254
   *       observer.  The observer is responsible for making sure it stays
255
   *       alive for the duration of the call as needed.  The observer may
256
   *       assume that this call will happen when there are script blockers on
257
   *       the stack.
258
   */
259
  virtual void ContentRemoved(nsIContent* aChild,
260
                              nsIContent* aPreviousSibling) = 0;
261
262
 /**
263
   * The node is in the process of being destroyed. Calling QI on the node is
264
   * not supported, however it is possible to get children and flags through
265
   * nsINode as well as calling IsContent and casting to nsIContent to get
266
   * attributes.
267
   *
268
   * NOTE: This notification is only called on observers registered directly
269
   * on the node. This is because when the node is destroyed it can not have
270
   * any ancestors. If you want to know when a descendant node is being
271
   * removed from the observed node, use the ContentRemoved notification.
272
   *
273
   * @param aNode The node being destroyed.
274
   *
275
   * @note Callers of this method might not hold a strong reference to
276
   *       the observer.  The observer is responsible for making sure it
277
   *       stays alive for the duration of the call as needed.
278
   */
279
  virtual void NodeWillBeDestroyed(const nsINode *aNode) = 0;
280
281
  /**
282
   * Notification that the node's parent chain has changed. This
283
   * happens when either the node or one of its ancestors is inserted
284
   * or removed as a child of another node.
285
   *
286
   * Note that when a node is inserted this notification is sent to
287
   * all descendants of that node, since all such nodes have their
288
   * parent chain changed.
289
   *
290
   * @param aContent  The piece of content that had its parent changed.
291
   *
292
   * @note Callers of this method might not hold a strong reference to
293
   *       the observer.  The observer is responsible for making sure it
294
   *       stays alive for the duration of the call as needed.
295
   */
296
297
  virtual void ParentChainChanged(nsIContent *aContent) = 0;
298
};
299
300
NS_DEFINE_STATIC_IID_ACCESSOR(nsIMutationObserver, NS_IMUTATION_OBSERVER_IID)
301
302
#define NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATAWILLCHANGE                  \
303
    virtual void CharacterDataWillChange(nsIContent* aContent,               \
304
                                         const CharacterDataChangeInfo& aInfo) override;
305
306
#define NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED                     \
307
    virtual void CharacterDataChanged(nsIContent* aContent,                  \
308
                                      const CharacterDataChangeInfo& aInfo) override;
309
310
#define NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE                      \
311
    virtual void AttributeWillChange(mozilla::dom::Element* aElement,        \
312
                                     int32_t aNameSpaceID,                   \
313
                                     nsAtom* aAttribute,                    \
314
                                     int32_t aModType,                       \
315
                                     const nsAttrValue* aNewValue) override;
316
317
#define NS_DECL_NSIMUTATIONOBSERVER_NATIVEANONYMOUSCHILDLISTCHANGE           \
318
    virtual void NativeAnonymousChildListChange(nsIContent* aContent,        \
319
                                                bool aIsRemove) override;
320
321
#define NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED                         \
322
    virtual void AttributeChanged(mozilla::dom::Element* aElement,           \
323
                                  int32_t aNameSpaceID,                      \
324
                                  nsAtom* aAttribute,                        \
325
                                  int32_t aModType,                          \
326
                                  const nsAttrValue* aOldValue) override;
327
328
#define NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED                          \
329
    virtual void ContentAppended(nsIContent* aFirstNewContent) override;
330
331
#define NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED                          \
332
    virtual void ContentInserted(nsIContent* aChild) override;
333
334
#define NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED                           \
335
    virtual void ContentRemoved(nsIContent* aChild,                          \
336
                                nsIContent* aPreviousSibling) override;
337
338
#define NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED                      \
339
    virtual void NodeWillBeDestroyed(const nsINode* aNode) override;
340
341
#define NS_DECL_NSIMUTATIONOBSERVER_PARENTCHAINCHANGED                       \
342
    virtual void ParentChainChanged(nsIContent *aContent) override;
343
344
#define NS_DECL_NSIMUTATIONOBSERVER                                          \
345
    NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATAWILLCHANGE                      \
346
    NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED                         \
347
    NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE                          \
348
    NS_DECL_NSIMUTATIONOBSERVER_NATIVEANONYMOUSCHILDLISTCHANGE               \
349
    NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED                             \
350
    NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED                              \
351
    NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED                              \
352
    NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED                               \
353
    NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED                          \
354
    NS_DECL_NSIMUTATIONOBSERVER_PARENTCHAINCHANGED
355
356
#define NS_IMPL_NSIMUTATIONOBSERVER_CORE_STUB(_class)                     \
357
void                                                                      \
358
0
_class::NodeWillBeDestroyed(const nsINode* aNode)                         \
359
0
{                                                                         \
360
0
}
Unexecuted instantiation: nsStubAnimationObserver::NodeWillBeDestroyed(nsINode const*)
Unexecuted instantiation: nsStubDocumentObserver::NodeWillBeDestroyed(nsINode const*)
Unexecuted instantiation: nsStubMutationObserver::NodeWillBeDestroyed(nsINode const*)
Unexecuted instantiation: mozilla::a11y::DocAccessible::NodeWillBeDestroyed(nsINode const*)
361
362
#define NS_IMPL_NSIMUTATIONOBSERVER_CONTENT(_class)                       \
363
void                                                                      \
364
_class::CharacterDataWillChange(nsIContent* aContent,                     \
365
0
                                const CharacterDataChangeInfo& aInfo)     \
366
0
{                                                                         \
367
0
}                                                                         \
Unexecuted instantiation: nsStubAnimationObserver::CharacterDataWillChange(nsIContent*, CharacterDataChangeInfo const&)
Unexecuted instantiation: nsStubDocumentObserver::CharacterDataWillChange(nsIContent*, CharacterDataChangeInfo const&)
Unexecuted instantiation: nsStubMutationObserver::CharacterDataWillChange(nsIContent*, CharacterDataChangeInfo const&)
368
void                                                                      \
369
_class::CharacterDataChanged(nsIContent* aContent,                        \
370
0
                             const CharacterDataChangeInfo& aInfo)        \
371
0
{                                                                         \
372
0
}                                                                         \
Unexecuted instantiation: nsStubAnimationObserver::CharacterDataChanged(nsIContent*, CharacterDataChangeInfo const&)
Unexecuted instantiation: nsStubDocumentObserver::CharacterDataChanged(nsIContent*, CharacterDataChangeInfo const&)
Unexecuted instantiation: nsStubMutationObserver::CharacterDataChanged(nsIContent*, CharacterDataChangeInfo const&)
373
void                                                                      \
374
_class::AttributeWillChange(mozilla::dom::Element* aElement,              \
375
                            int32_t aNameSpaceID,                         \
376
                            nsAtom* aAttribute,                          \
377
                            int32_t aModType,                             \
378
0
                            const nsAttrValue* aNewValue)                 \
379
0
{                                                                         \
380
0
}                                                                         \
Unexecuted instantiation: nsStubAnimationObserver::AttributeWillChange(mozilla::dom::Element*, int, nsAtom*, int, nsAttrValue const*)
Unexecuted instantiation: nsStubDocumentObserver::AttributeWillChange(mozilla::dom::Element*, int, nsAtom*, int, nsAttrValue const*)
Unexecuted instantiation: nsStubMutationObserver::AttributeWillChange(mozilla::dom::Element*, int, nsAtom*, int, nsAttrValue const*)
381
void                                                                      \
382
_class::NativeAnonymousChildListChange(nsIContent* aContent,              \
383
0
                                       bool aIsRemove)                    \
384
0
{                                                                         \
385
0
}                                                                         \
Unexecuted instantiation: nsStubAnimationObserver::NativeAnonymousChildListChange(nsIContent*, bool)
Unexecuted instantiation: nsStubDocumentObserver::NativeAnonymousChildListChange(nsIContent*, bool)
Unexecuted instantiation: nsStubMutationObserver::NativeAnonymousChildListChange(nsIContent*, bool)
386
void                                                                      \
387
_class::AttributeChanged(mozilla::dom::Element* aElement,                 \
388
                         int32_t aNameSpaceID,                            \
389
                         nsAtom* aAttribute,                             \
390
                         int32_t aModType,                                \
391
0
                         const nsAttrValue* aOldValue)                    \
392
0
{                                                                         \
393
0
}                                                                         \
Unexecuted instantiation: nsStubAnimationObserver::AttributeChanged(mozilla::dom::Element*, int, nsAtom*, int, nsAttrValue const*)
Unexecuted instantiation: nsStubDocumentObserver::AttributeChanged(mozilla::dom::Element*, int, nsAtom*, int, nsAttrValue const*)
Unexecuted instantiation: nsStubMutationObserver::AttributeChanged(mozilla::dom::Element*, int, nsAtom*, int, nsAttrValue const*)
394
void                                                                      \
395
0
_class::ContentAppended(nsIContent* aFirstNewContent)                     \
396
0
{                                                                         \
397
0
}                                                                         \
Unexecuted instantiation: nsStubAnimationObserver::ContentAppended(nsIContent*)
Unexecuted instantiation: nsStubDocumentObserver::ContentAppended(nsIContent*)
Unexecuted instantiation: nsStubMutationObserver::ContentAppended(nsIContent*)
398
void                                                                      \
399
0
_class::ContentInserted(nsIContent* aChild)                               \
400
0
{                                                                         \
401
0
}                                                                         \
Unexecuted instantiation: nsStubAnimationObserver::ContentInserted(nsIContent*)
Unexecuted instantiation: nsStubDocumentObserver::ContentInserted(nsIContent*)
Unexecuted instantiation: nsStubMutationObserver::ContentInserted(nsIContent*)
402
void                                                                      \
403
0
_class::ContentRemoved(nsIContent* aChild, nsIContent* aPreviousSibling)  \
404
0
{                                                                         \
405
0
}                                                                         \
Unexecuted instantiation: nsStubAnimationObserver::ContentRemoved(nsIContent*, nsIContent*)
Unexecuted instantiation: nsStubDocumentObserver::ContentRemoved(nsIContent*, nsIContent*)
Unexecuted instantiation: nsStubMutationObserver::ContentRemoved(nsIContent*, nsIContent*)
406
void                                                                      \
407
0
_class::ParentChainChanged(nsIContent *aContent)                          \
408
0
{                                                                         \
409
0
}
Unexecuted instantiation: nsStubAnimationObserver::ParentChainChanged(nsIContent*)
Unexecuted instantiation: nsStubDocumentObserver::ParentChainChanged(nsIContent*)
Unexecuted instantiation: nsStubMutationObserver::ParentChainChanged(nsIContent*)
410
411
412
#endif /* nsIMutationObserver_h */