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
25namespace Poco {
26namespace XML {
27
28
29class Node;
30
31
32class XML_API MutationEvent: public Event
33 /// The MutationEvent interface provides specific contextual
34 /// information associated with Mutation events.
35{
36public:
37 enum AttrChangeType
38 {
39 MODIFICATION = 1, /// The Attr was modified in place.
40 ADDITION = 2, /// The Attr was just added.
41 REMOVAL = 3 /// The Attr was just removed.
42 };
43
44 Node* relatedNode() const;
45 /// relatedNode is used to identify a secondary node related to a mutation
46 /// event. For example, if a mutation event is dispatched
47 /// to a node indicating that its parent has changed, the relatedNode is the
48 /// changed parent. If an event is instead dispatched to a
49 /// subtree indicating a node was changed within it, the relatedNode is
50 /// the changed node. In the case of the DOMAttrModified
51 /// event it indicates the Attr node which was modified, added, or removed.
52
53 const XMLString& prevValue() const;
54 /// prevValue indicates the previous value of the Attr node in DOMAttrModified
55 /// events, and of the CharacterData node in DOMCharDataModified events.
56
57 const XMLString& newValue() const;
58 /// newValue indicates the new value of the Attr node in DOMAttrModified
59 /// events, and of the CharacterData node in DOMCharDataModified events.
60
61 const XMLString& attrName() const;
62 /// attrName indicates the name of the changed Attr node in a DOMAttrModified event.
63
64 AttrChangeType attrChange() const;
65 /// attrChange indicates the type of change which triggered the
66 /// DOMAttrModified event. The values can be MODIFICATION,
67 /// ADDITION, or REMOVAL.
68
69 void initMutationEvent(const XMLString& type, bool canBubble, bool cancelable, Node* relatedNode,
70 const XMLString& prevValue, const XMLString& newValue, const XMLString& attrName, AttrChangeType change);
71 /// The initMutationEvent method is used to initialize the value of a
72 /// MutationEvent created through the DocumentEvent
73 /// interface. This method may only be called before the MutationEvent
74 /// has been dispatched via the dispatchEvent method,
75 /// though it may be called multiple times during that phase if
76 /// necessary. If called multiple times, the final invocation takes
77 /// precedence.
78
79 // Event Types
80 static const XMLString DOMSubtreeModified;
81 static const XMLString DOMNodeInserted;
82 static const XMLString DOMNodeRemoved;
83 static const XMLString DOMNodeRemovedFromDocument;
84 static const XMLString DOMNodeInsertedIntoDocument;
85 static const XMLString DOMAttrModified;
86 static const XMLString DOMCharacterDataModified;
87
88protected:
89 MutationEvent(Document* pOwnerDocument, const XMLString& type);
90 MutationEvent(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool cancelable, Node* relatedNode);
91 MutationEvent(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool cancelable, Node* relatedNode,
92 const XMLString& prevValue, const XMLString& newValue, const XMLString& attrName, AttrChangeType change);
93 ~MutationEvent();
94
95private:
96 XMLString _prevValue;
97 XMLString _newValue;
98 XMLString _attrName;
99 AttrChangeType _change;
100 Node* _pRelatedNode;
101
102 friend class AbstractNode;
103 friend class Document;
104};
105
106
107//
108// inlines
109//
110inline Node* MutationEvent::relatedNode() const
111{
112 return _pRelatedNode;
113}
114
115
116inline const XMLString& MutationEvent::prevValue() const
117{
118 return _prevValue;
119}
120
121
122inline const XMLString& MutationEvent::newValue() const
123{
124 return _newValue;
125}
126
127
128inline const XMLString& MutationEvent::attrName() const
129{
130 return _attrName;
131}
132
133
134inline MutationEvent::AttrChangeType MutationEvent::attrChange() const
135{
136 return _change;
137}
138
139
140} } // namespace Poco::XML
141
142
143#endif // DOM_MutationEvent_INCLUDED
144