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