1 /*
2  * Copyright (C) 2001 Peter Kelly (pmk@post.com)
3  * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
4  * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
5  * Copyright (C) 2003, 2005, 2006, 2008 Apple Inc. All rights reserved.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #include "config.h"
24 #include "Event.h"
25 #include "EventDispatcher.h"
26 #include "EventTarget.h"
27 
28 #include "UserGestureIndicator.h"
29 #include <wtf/CurrentTime.h>
30 #include <wtf/text/AtomicString.h>
31 
32 namespace WebCore {
33 
Event()34 Event::Event()
35     : m_canBubble(false)
36     , m_cancelable(false)
37     , m_propagationStopped(false)
38     , m_immediatePropagationStopped(false)
39     , m_defaultPrevented(false)
40     , m_defaultHandled(false)
41     , m_cancelBubble(false)
42     , m_eventPhase(0)
43     , m_currentTarget(0)
44     , m_createTime(convertSecondsToDOMTimeStamp(currentTime()))
45 {
46 }
47 
Event(const AtomicString & eventType,bool canBubbleArg,bool cancelableArg)48 Event::Event(const AtomicString& eventType, bool canBubbleArg, bool cancelableArg)
49     : m_type(eventType)
50     , m_canBubble(canBubbleArg)
51     , m_cancelable(cancelableArg)
52     , m_propagationStopped(false)
53     , m_immediatePropagationStopped(false)
54     , m_defaultPrevented(false)
55     , m_defaultHandled(false)
56     , m_cancelBubble(false)
57     , m_eventPhase(0)
58     , m_currentTarget(0)
59     , m_createTime(convertSecondsToDOMTimeStamp(currentTime()))
60 {
61 }
62 
~Event()63 Event::~Event()
64 {
65 }
66 
initEvent(const AtomicString & eventTypeArg,bool canBubbleArg,bool cancelableArg)67 void Event::initEvent(const AtomicString& eventTypeArg, bool canBubbleArg, bool cancelableArg)
68 {
69     if (dispatched())
70         return;
71 
72     m_type = eventTypeArg;
73     m_canBubble = canBubbleArg;
74     m_cancelable = cancelableArg;
75 }
76 
isCustomEvent() const77 bool Event::isCustomEvent() const
78 {
79     return false;
80 }
81 
isUIEvent() const82 bool Event::isUIEvent() const
83 {
84     return false;
85 }
86 
isMouseEvent() const87 bool Event::isMouseEvent() const
88 {
89     return false;
90 }
91 
isMutationEvent() const92 bool Event::isMutationEvent() const
93 {
94     return false;
95 }
96 
isKeyboardEvent() const97 bool Event::isKeyboardEvent() const
98 {
99     return false;
100 }
101 
isTextEvent() const102 bool Event::isTextEvent() const
103 {
104     return false;
105 }
106 
isCompositionEvent() const107 bool Event::isCompositionEvent() const
108 {
109     return false;
110 }
111 
isDragEvent() const112 bool Event::isDragEvent() const
113 {
114     return false;
115 }
116 
isClipboardEvent() const117 bool Event::isClipboardEvent() const
118 {
119     return false;
120 }
121 
isWheelEvent() const122 bool Event::isWheelEvent() const
123 {
124     return false;
125 }
126 
isMessageEvent() const127 bool Event::isMessageEvent() const
128 {
129     return false;
130 }
131 
isBeforeTextInsertedEvent() const132 bool Event::isBeforeTextInsertedEvent() const
133 {
134     return false;
135 }
136 
isOverflowEvent() const137 bool Event::isOverflowEvent() const
138 {
139     return false;
140 }
141 
isPageTransitionEvent() const142 bool Event::isPageTransitionEvent() const
143 {
144     return false;
145 }
146 
isPopStateEvent() const147 bool Event::isPopStateEvent() const
148 {
149     return false;
150 }
151 
isProgressEvent() const152 bool Event::isProgressEvent() const
153 {
154     return false;
155 }
156 
isWebKitAnimationEvent() const157 bool Event::isWebKitAnimationEvent() const
158 {
159     return false;
160 }
161 
isWebKitTransitionEvent() const162 bool Event::isWebKitTransitionEvent() const
163 {
164     return false;
165 }
166 
isXMLHttpRequestProgressEvent() const167 bool Event::isXMLHttpRequestProgressEvent() const
168 {
169     return false;
170 }
171 
isBeforeLoadEvent() const172 bool Event::isBeforeLoadEvent() const
173 {
174     return false;
175 }
176 
isHashChangeEvent() const177 bool Event::isHashChangeEvent() const
178 {
179     return false;
180 }
181 
182 #if ENABLE(SVG)
isSVGZoomEvent() const183 bool Event::isSVGZoomEvent() const
184 {
185     return false;
186 }
187 #endif
188 
189 #if ENABLE(DOM_STORAGE)
isStorageEvent() const190 bool Event::isStorageEvent() const
191 {
192     return false;
193 }
194 #endif
195 
196 #if ENABLE(INDEXED_DATABASE)
isIDBVersionChangeEvent() const197 bool Event::isIDBVersionChangeEvent() const
198 {
199     return false;
200 }
201 #endif
202 
isErrorEvent() const203 bool Event::isErrorEvent() const
204 {
205     return false;
206 }
207 
208 #if ENABLE(TOUCH_EVENTS)
isTouchEvent() const209 bool Event::isTouchEvent() const
210 {
211     return false;
212 }
213 #endif
214 
215 #if ENABLE(DEVICE_ORIENTATION)
isDeviceMotionEvent() const216 bool Event::isDeviceMotionEvent() const
217 {
218     return false;
219 }
220 
isDeviceOrientationEvent() const221 bool Event::isDeviceOrientationEvent() const
222 {
223     return false;
224 }
225 #endif
226 
227 #if ENABLE(WEB_AUDIO)
isAudioProcessingEvent() const228 bool Event::isAudioProcessingEvent() const
229 {
230     return false;
231 }
232 
isOfflineAudioCompletionEvent() const233 bool Event::isOfflineAudioCompletionEvent() const
234 {
235     return false;
236 }
237 #endif
238 
239 #if ENABLE(INPUT_SPEECH)
isSpeechInputEvent() const240 bool Event::isSpeechInputEvent() const
241 {
242     return false;
243 }
244 #endif
245 
fromUserGesture()246 bool Event::fromUserGesture()
247 {
248     if (!UserGestureIndicator::processingUserGesture())
249         return false;
250 
251     const AtomicString& type = this->type();
252     return
253         // mouse events
254         type == eventNames().clickEvent || type == eventNames().mousedownEvent
255         || type == eventNames().mouseupEvent || type == eventNames().dblclickEvent
256         // keyboard events
257         || type == eventNames().keydownEvent || type == eventNames().keypressEvent
258         || type == eventNames().keyupEvent
259 #if ENABLE(TOUCH_EVENTS)
260         // touch events
261         || type == eventNames().touchstartEvent || type == eventNames().touchmoveEvent
262         || type == eventNames().touchendEvent || type == eventNames().touchcancelEvent
263 #endif
264         // other accepted events
265         || type == eventNames().selectEvent || type == eventNames().changeEvent
266         || type == eventNames().focusEvent || type == eventNames().blurEvent
267         || type == eventNames().submitEvent;
268 }
269 
storesResultAsString() const270 bool Event::storesResultAsString() const
271 {
272     return false;
273 }
274 
storeResult(const String &)275 void Event::storeResult(const String&)
276 {
277 }
278 
setTarget(PassRefPtr<EventTarget> target)279 void Event::setTarget(PassRefPtr<EventTarget> target)
280 {
281     if (m_target == target)
282         return;
283 
284     m_target = target;
285     if (m_target)
286         receivedTarget();
287 }
288 
receivedTarget()289 void Event::receivedTarget()
290 {
291 }
292 
setUnderlyingEvent(PassRefPtr<Event> ue)293 void Event::setUnderlyingEvent(PassRefPtr<Event> ue)
294 {
295     // Prohibit creation of a cycle -- just do nothing in that case.
296     for (Event* e = ue.get(); e; e = e->underlyingEvent())
297         if (e == this)
298             return;
299     m_underlyingEvent = ue;
300 }
301 
EventDispatchMediator(PassRefPtr<Event> event)302 EventDispatchMediator::EventDispatchMediator(PassRefPtr<Event> event)
303     : m_event(event)
304 {
305 }
306 
~EventDispatchMediator()307 EventDispatchMediator::~EventDispatchMediator()
308 {
309 }
310 
dispatchEvent(EventDispatcher * dispatcher) const311 bool EventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
312 {
313     return dispatcher->dispatchEvent(m_event.get());
314 }
315 
316 } // namespace WebCore
317