MutationEvent.h 4.1 KB

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