Event.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. //
  2. // Event.h
  3. //
  4. // Library: XML
  5. // Package: DOM
  6. // Module: DOMEvents
  7. //
  8. // Definition of the DOM Event 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_Event_INCLUDED
  16. #define DOM_Event_INCLUDED
  17. #include "Poco/XML/XML.h"
  18. #include "Poco/XML/XMLString.h"
  19. #include "Poco/DOM/DOMObject.h"
  20. namespace Poco {
  21. namespace XML {
  22. class EventTarget;
  23. class Document;
  24. class XML_API Event: public DOMObject
  25. /// The Event interface is used to provide contextual information about an event
  26. /// to the handler processing the event. An object which implements the Event
  27. /// interface is generally passed as the first parameter to an event handler.
  28. /// More specific context information is passed to event handlers by deriving
  29. /// additional interfaces from Event which contain information directly relating
  30. /// to the type of event they accompany. These derived interfaces are also implemented
  31. /// by the object passed to the event listener.
  32. {
  33. public:
  34. enum PhaseType
  35. {
  36. CAPTURING_PHASE = 1, /// The event is currently being evaluated at the target EventTarget.
  37. AT_TARGET = 2, /// The current event phase is the bubbling phase.
  38. BUBBLING_PHASE = 3 /// The current event phase is the capturing phase.
  39. };
  40. const XMLString& type() const;
  41. /// The name of the event (case-insensitive). The name must be an XML name.
  42. EventTarget* target() const;
  43. /// Used to indicate the EventTarget to which the event was originally dispatched.
  44. EventTarget* currentTarget() const;
  45. /// Used to indicate the EventTarget whose EventListeners are currently being
  46. /// processed. This is particularly useful during capturing and bubbling.
  47. PhaseType eventPhase() const;
  48. /// Used to indicate which phase of event flow is currently being evaluated.
  49. bool bubbles() const;
  50. /// Used to indicate whether or not an event is a bubbling event.
  51. /// If the event can bubble the value is true, else the value is false.
  52. bool cancelable() const;
  53. /// Used to indicate whether or not an event can have its default action
  54. /// prevented. If the default action can be prevented the value is
  55. /// true, else the value is false.
  56. Poco::UInt64 timeStamp() const;
  57. /// Used to specify the time (in milliseconds relative to the epoch) at
  58. /// which the event was created. Due to the fact that some
  59. /// systems may not provide this information the value of timeStamp may
  60. /// be not available for all events. When not available, a
  61. /// value of 0 will be returned. Examples of epoch time are the time of the
  62. /// system start or 0:0:0 UTC 1st January 1970.
  63. /// This implementation always returns 0.
  64. void stopPropagation();
  65. /// The stopPropagation method is used prevent further propagation of an
  66. /// event during event flow. If this method is called by
  67. /// any EventListener the event will cease propagating through the tree.
  68. /// The event will complete dispatch to all listeners on the
  69. /// current EventTarget before event flow stops. This method may be used
  70. /// during any stage of event flow.
  71. void preventDefault();
  72. /// If an event is cancelable, the preventDefault method is used to signify
  73. /// that the event is to be canceled, meaning any default
  74. /// action normally taken by the implementation as a result of
  75. /// the event will not occur. If, during any stage of event flow, the
  76. /// preventDefault method is called the event is canceled. Any default
  77. /// action associated with the event will not occur. Calling
  78. /// this method for a non-cancelable event has no effect. Once
  79. /// preventDefault has been called it will remain in effect throughout
  80. /// the remainder of the event's propagation. This method may be
  81. /// used during any stage of event flow.
  82. void initEvent(const XMLString& eventType, bool canBubble, bool isCancelable);
  83. /// The initEvent method is used to initialize the value of an
  84. /// Event created through the DocumentEvent interface. This method
  85. /// may only be called before the Event has been dispatched via the
  86. /// dispatchEvent method, though it may be called multiple
  87. /// times during that phase if necessary. If called multiple
  88. /// times the final invocation takes precedence. If called from
  89. /// a subclass of Event interface only the values specified in the
  90. /// initEvent method are modified, all other attributes are left unchanged.
  91. void autoRelease();
  92. protected:
  93. Event(Document* pOwnerDocument, const XMLString& type);
  94. Event(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool isCancelable);
  95. ~Event();
  96. bool isCanceled() const;
  97. /// returns true if and only if the event has been cancelled.
  98. bool isStopped() const;
  99. /// returns true if and only if propagation of the event has been stopped.
  100. void setTarget(EventTarget* pTarget);
  101. /// sets the target
  102. void setCurrentPhase(PhaseType phase);
  103. /// sets the current phase
  104. void setCurrentTarget(EventTarget* pTarget);
  105. /// sets the current target
  106. private:
  107. Document* _pOwner;
  108. XMLString _type;
  109. EventTarget* _pTarget;
  110. EventTarget* _pCurrentTarget;
  111. PhaseType _currentPhase;
  112. bool _bubbles;
  113. bool _cancelable;
  114. bool _canceled;
  115. bool _stopped;
  116. friend class AbstractNode;
  117. };
  118. //
  119. // inlines
  120. //
  121. inline const XMLString& Event::type() const
  122. {
  123. return _type;
  124. }
  125. inline EventTarget* Event::target() const
  126. {
  127. return _pTarget;
  128. }
  129. inline EventTarget* Event::currentTarget() const
  130. {
  131. return _pCurrentTarget;
  132. }
  133. inline Event::PhaseType Event::eventPhase() const
  134. {
  135. return _currentPhase;
  136. }
  137. inline bool Event::bubbles() const
  138. {
  139. return _bubbles;
  140. }
  141. inline bool Event::cancelable() const
  142. {
  143. return _cancelable;
  144. }
  145. inline Poco::UInt64 Event::timeStamp() const
  146. {
  147. return 0;
  148. }
  149. inline bool Event::isCanceled() const
  150. {
  151. return _canceled;
  152. }
  153. inline bool Event::isStopped() const
  154. {
  155. return _stopped;
  156. }
  157. } } // namespace Poco::XML
  158. #endif // DOM_Event_INCLUDED