Coverage Report

Created: 2026-09-14 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/poco/XML/include/Poco/DOM/MutationEvent.h
Line
Count
Source
1
//
2
// MutationEvent.h
3
//
4
// Library: XML
5
// Package: DOM
6
// Module:  DOMEvents
7
//
8
// Definition of the DOM MutationEvent class.
9
//
10
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
11
// and Contributors.
12
//
13
// SPDX-License-Identifier: BSL-1.0
14
//
15
16
17
#ifndef DOM_MutationEvent_INCLUDED
18
#define DOM_MutationEvent_INCLUDED
19
20
21
#include "Poco/XML/XML.h"
22
#include "Poco/DOM/Event.h"
23
24
25
namespace Poco::XML {
26
27
28
class Node;
29
30
31
class XML_API MutationEvent: public Event
32
  /// The MutationEvent interface provides specific contextual
33
  /// information associated with Mutation events.
34
{
35
public:
36
  enum AttrChangeType
37
  {
38
    MODIFICATION = 1, /// The Attr was modified in place.
39
    ADDITION     = 2, /// The Attr was just added.
40
    REMOVAL      = 3  /// The Attr was just removed.
41
  };
42
43
  Node* relatedNode() const;
44
    /// relatedNode is used to identify a secondary node related to a mutation
45
    /// event. For example, if a mutation event is dispatched
46
    /// to a node indicating that its parent has changed, the relatedNode is the
47
    /// changed parent. If an event is instead dispatched to a
48
    /// subtree indicating a node was changed within it, the relatedNode is
49
    /// the changed node. In the case of the DOMAttrModified
50
    /// event it indicates the Attr node which was modified, added, or removed.
51
52
  [[nodiscard]] const XMLString& prevValue() const;
53
    /// prevValue indicates the previous value of the Attr node in DOMAttrModified
54
    /// events, and of the CharacterData node in DOMCharDataModified events.
55
56
  [[nodiscard]] const XMLString& newValue() const;
57
    /// newValue indicates the new value of the Attr node in DOMAttrModified
58
    /// events, and of the CharacterData node in DOMCharDataModified events.
59
60
  [[nodiscard]] const XMLString& attrName() const;
61
    /// attrName indicates the name of the changed Attr node in a DOMAttrModified event.
62
63
  [[nodiscard]] AttrChangeType attrChange() const;
64
    /// attrChange indicates the type of change which triggered the
65
    /// DOMAttrModified event. The values can be MODIFICATION,
66
    /// ADDITION, or REMOVAL.
67
68
  void initMutationEvent(const XMLString& type, bool canBubble, bool cancelable, Node* relatedNode,
69
                         const XMLString& prevValue, const XMLString& newValue, const XMLString& attrName, AttrChangeType change);
70
    /// The initMutationEvent method is used to initialize the value of a
71
    /// MutationEvent created through the DocumentEvent
72
    /// interface. This method may only be called before the MutationEvent
73
    /// has been dispatched via the dispatchEvent method,
74
    /// though it may be called multiple times during that phase if
75
    /// necessary. If called multiple times, the final invocation takes
76
    /// precedence.
77
78
  // Event Types
79
  static const XMLString DOMSubtreeModified;
80
  static const XMLString DOMNodeInserted;
81
  static const XMLString DOMNodeRemoved;
82
  static const XMLString DOMNodeRemovedFromDocument;
83
  static const XMLString DOMNodeInsertedIntoDocument;
84
  static const XMLString DOMAttrModified;
85
  static const XMLString DOMCharacterDataModified;
86
87
protected:
88
  MutationEvent(Document* pOwnerDocument, const XMLString& type);
89
  MutationEvent(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool cancelable, Node* relatedNode);
90
  MutationEvent(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool cancelable, Node* relatedNode,
91
          const XMLString& prevValue, const XMLString& newValue, const XMLString& attrName, AttrChangeType change);
92
  ~MutationEvent();
93
94
private:
95
  XMLString      _prevValue;
96
  XMLString      _newValue;
97
  XMLString      _attrName;
98
  AttrChangeType _change;
99
  Node*          _pRelatedNode;
100
101
  friend class AbstractNode;
102
  friend class Document;
103
};
104
105
106
//
107
// inlines
108
//
109
inline Node* MutationEvent::relatedNode() const
110
0
{
111
0
  return _pRelatedNode;
112
0
}
113
114
115
inline const XMLString& MutationEvent::prevValue() const
116
0
{
117
0
  return _prevValue;
118
0
}
119
120
121
inline const XMLString& MutationEvent::newValue() const
122
0
{
123
0
  return _newValue;
124
0
}
125
126
127
inline const XMLString& MutationEvent::attrName() const
128
0
{
129
0
  return _attrName;
130
0
}
131
132
133
inline MutationEvent::AttrChangeType MutationEvent::attrChange() const
134
0
{
135
0
  return _change;
136
0
}
137
138
139
} // namespace Poco::XML
140
141
142
#endif // DOM_MutationEvent_INCLUDED