1/*
2 * Copyright (C) 2005, 2007, 2015 Apple Inc. All rights reserved.
3 * Copyright (C) 2006 Jon Shier (jshier@iastate.edu)
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 */
21
22#pragma once
23
24#include "Document.h"
25#include "Quirks.h"
26#include "ThreadGlobalData.h"
27#include <array>
28#include <functional>
29#include <wtf/text/AtomString.h>
30
31#if ENABLE(TOUCH_EVENTS)
32#include "RuntimeEnabledFeatures.h"
33#endif
34
35namespace WebCore {
36
37#if !defined(ADDITIONAL_DOM_EVENT_NAMES_FOR_EACH)
38#define ADDITIONAL_DOM_EVENT_NAMES_FOR_EACH(macro)
39#endif
40
41#define DOM_EVENT_NAMES_FOR_EACH(macro) \
42 ADDITIONAL_DOM_EVENT_NAMES_FOR_EACH(macro) \
43 macro(DOMActivate) \
44 macro(DOMCharacterDataModified) \
45 macro(DOMContentLoaded) \
46 macro(DOMFocusIn) \
47 macro(DOMFocusOut) \
48 macro(DOMNodeInserted) \
49 macro(DOMNodeInsertedIntoDocument) \
50 macro(DOMNodeRemoved) \
51 macro(DOMNodeRemovedFromDocument) \
52 macro(DOMSubtreeModified) \
53 macro(abort) \
54 macro(activate) \
55 macro(active) \
56 macro(addsourcebuffer) \
57 macro(addstream) \
58 macro(addtrack) \
59 macro(afterprint) \
60 macro(animationcancel) \
61 macro(animationend) \
62 macro(animationiteration) \
63 macro(animationstart) \
64 macro(audioend) \
65 macro(audioprocess) \
66 macro(audiostart) \
67 macro(autocomplete) \
68 macro(autocompleteerror) \
69 macro(beforecopy) \
70 macro(beforecut) \
71 macro(beforeinput) \
72 macro(beforeload) \
73 macro(beforepaste) \
74 macro(beforeprint) \
75 macro(beforeunload) \
76 macro(beginEvent) \
77 macro(blocked) \
78 macro(blur) \
79 macro(boundary) \
80 macro(bufferedamountlow) \
81 macro(cached) \
82 macro(cancel) \
83 macro(canplay) \
84 macro(canplaythrough) \
85 macro(change) \
86 macro(chargingchange) \
87 macro(chargingtimechange) \
88 macro(checking) \
89 macro(click) \
90 macro(close) \
91 macro(complete) \
92 macro(compositionend) \
93 macro(compositionstart) \
94 macro(compositionupdate) \
95 macro(connect) \
96 macro(connectionstatechange) \
97 macro(connecting) \
98 macro(contextmenu) \
99 macro(controllerchange) \
100 macro(copy) \
101 macro(cuechange) \
102 macro(cut) \
103 macro(dataavailable) \
104 macro(datachannel) \
105 macro(dblclick) \
106 macro(devicechange) \
107 macro(devicemotion) \
108 macro(deviceorientation) \
109 macro(dischargingtimechange) \
110 macro(downloading) \
111 macro(drag) \
112 macro(dragend) \
113 macro(dragenter) \
114 macro(dragleave) \
115 macro(dragover) \
116 macro(dragstart) \
117 macro(drop) \
118 macro(durationchange) \
119 macro(emptied) \
120 macro(encrypted) \
121 macro(end) \
122 macro(endEvent) \
123 macro(ended) \
124 macro(enter) \
125 macro(error) \
126 macro(exit) \
127 macro(fetch) \
128 macro(finish) \
129 macro(focus) \
130 macro(focusin) \
131 macro(focusout) \
132 macro(gamepadconnected) \
133 macro(gamepaddisconnected) \
134 macro(gesturechange) \
135 macro(gestureend) \
136 macro(gesturescrollend) \
137 macro(gesturescrollstart) \
138 macro(gesturescrollupdate) \
139 macro(gesturestart) \
140 macro(gesturetap) \
141 macro(gesturetapdown) \
142 macro(gotpointercapture) \
143 macro(hashchange) \
144 macro(icecandidate) \
145 macro(iceconnectionstatechange) \
146 macro(icegatheringstatechange) \
147 macro(inactive) \
148 macro(input) \
149 macro(install) \
150 macro(invalid) \
151 macro(keydown) \
152 macro(keypress) \
153 macro(keystatuseschange) \
154 macro(keyup) \
155 macro(languagechange) \
156 macro(levelchange) \
157 macro(load) \
158 macro(loadeddata) \
159 macro(loadedmetadata) \
160 macro(loadend) \
161 macro(loading) \
162 macro(loadingdone) \
163 macro(loadingerror) \
164 macro(loadstart) \
165 macro(lostpointercapture) \
166 macro(mark) \
167 macro(merchantvalidation) \
168 macro(message) \
169 macro(messageerror) \
170 macro(mousedown) \
171 macro(mouseenter) \
172 macro(mouseleave) \
173 macro(mousemove) \
174 macro(mouseout) \
175 macro(mouseover) \
176 macro(mouseup) \
177 macro(mousewheel) \
178 macro(mute) \
179 macro(negotiationneeded) \
180 macro(nexttrack) \
181 macro(nomatch) \
182 macro(noupdate) \
183 macro(obsolete) \
184 macro(offline) \
185 macro(online) \
186 macro(open) \
187 macro(orientationchange) \
188 macro(overconstrained) \
189 macro(overflowchanged) \
190 macro(pagehide) \
191 macro(pageshow) \
192 macro(paste) \
193 macro(pause) \
194 macro(payerdetailchange) \
195 macro(paymentauthorized) \
196 macro(paymentmethodchange) \
197 macro(paymentmethodselected) \
198 macro(play) \
199 macro(playing) \
200 macro(pointerlockchange) \
201 macro(pointerlockerror) \
202 macro(pointercancel) \
203 macro(pointerdown) \
204 macro(pointerenter) \
205 macro(pointerleave) \
206 macro(pointermove) \
207 macro(pointerout) \
208 macro(pointerover) \
209 macro(pointerup) \
210 macro(popstate) \
211 macro(previoustrack) \
212 macro(progress) \
213 macro(ratechange) \
214 macro(readystatechange) \
215 macro(rejectionhandled) \
216 macro(removesourcebuffer) \
217 macro(removestream) \
218 macro(removetrack) \
219 macro(reset) \
220 macro(resize) \
221 macro(resourcetimingbufferfull) \
222 macro(result) \
223 macro(resume) \
224 macro(scroll) \
225 macro(search) \
226 macro(securitypolicyviolation) \
227 macro(seeked) \
228 macro(seeking) \
229 macro(select) \
230 macro(selectionchange) \
231 macro(selectstart) \
232 macro(shippingaddresschange) \
233 macro(shippingcontactselected) \
234 macro(shippingmethodselected) \
235 macro(shippingoptionchange) \
236 macro(show) \
237 macro(signalingstatechange) \
238 macro(slotchange) \
239 macro(soundend) \
240 macro(soundstart) \
241 macro(sourceclose) \
242 macro(sourceended) \
243 macro(sourceopen) \
244 macro(speechend) \
245 macro(speechstart) \
246 macro(stalled) \
247 macro(start) \
248 macro(started) \
249 macro(statechange) \
250 macro(stop) \
251 macro(storage) \
252 macro(submit) \
253 macro(success) \
254 macro(suspend) \
255 macro(textInput) \
256 macro(timeout) \
257 macro(timeupdate) \
258 macro(toggle) \
259 macro(tonechange) \
260 macro(touchcancel) \
261 macro(touchend) \
262 macro(touchforcechange) \
263 macro(touchmove) \
264 macro(touchstart) \
265 macro(track) \
266 macro(transitioncancel) \
267 macro(transitionend) \
268 macro(transitionrun) \
269 macro(transitionstart) \
270 macro(unhandledrejection) \
271 macro(unload) \
272 macro(unmute) \
273 macro(update) \
274 macro(updateend) \
275 macro(updatefound) \
276 macro(updateready) \
277 macro(updatestart) \
278 macro(upgradeneeded) \
279 macro(validatemerchant) \
280 macro(versionchange) \
281 macro(visibilitychange) \
282 macro(volumechange) \
283 macro(vrdisplayactivate) \
284 macro(vrdisplayblur) \
285 macro(vrdisplayconnect) \
286 macro(vrdisplaydeactivate) \
287 macro(vrdisplaydisconnect) \
288 macro(vrdisplayfocus) \
289 macro(vrdisplaypresentchange) \
290 macro(waiting) \
291 macro(waitingforkey) \
292 macro(webglcontextchanged) \
293 macro(webglcontextcreationerror) \
294 macro(webglcontextlost) \
295 macro(webglcontextrestored) \
296 macro(webkitAnimationEnd) \
297 macro(webkitAnimationIteration) \
298 macro(webkitAnimationStart) \
299 macro(webkitBeforeTextInserted) \
300 macro(webkitTransitionEnd) \
301 macro(webkitbeginfullscreen) \
302 macro(webkitcurrentplaybacktargetiswirelesschanged) \
303 macro(webkitendfullscreen) \
304 macro(webkitfullscreenchange) \
305 macro(webkitfullscreenerror) \
306 macro(webkitkeyadded) \
307 macro(webkitkeyerror) \
308 macro(webkitkeymessage) \
309 macro(webkitmouseforcechanged) \
310 macro(webkitmouseforcedown) \
311 macro(webkitmouseforcewillbegin) \
312 macro(webkitmouseforceup) \
313 macro(webkitneedkey) \
314 macro(webkitnetworkinfochange) \
315 macro(webkitplaybacktargetavailabilitychanged) \
316 macro(webkitpresentationmodechanged) \
317 macro(webkitregionoversetchange) \
318 macro(webkitremovesourcebuffer) \
319 macro(webkitsourceclose) \
320 macro(webkitsourceended) \
321 macro(webkitsourceopen) \
322 macro(webkitspeechchange) \
323 macro(webkitwillrevealbottom) \
324 macro(webkitwillrevealleft) \
325 macro(webkitwillrevealright) \
326 macro(webkitwillrevealtop) \
327 macro(wheel) \
328 macro(write) \
329 macro(writeend) \
330 macro(writestart) \
331 macro(zoom) \
332// end of DOM_EVENT_NAMES_FOR_EACH
333
334struct EventNames {
335 WTF_MAKE_NONCOPYABLE(EventNames); WTF_MAKE_FAST_ALLOCATED;
336
337public:
338#define DOM_EVENT_NAMES_DECLARE(name) const AtomString name##Event;
339 DOM_EVENT_NAMES_FOR_EACH(DOM_EVENT_NAMES_DECLARE)
340#undef DOM_EVENT_NAMES_DECLARE
341
342 // FIXME: The friend declaration to std::make_unique below does not work in windows port.
343 //
344 // template<class T, class... Args>
345 // friend typename std::_Unique_if<T>::_Single_object std::make_unique(Args&&...);
346 //
347 // This create function should be deleted later and is only for keeping EventNames as private.
348 // std::make_unique should be used instead.
349 //
350 template<class... Args>
351 static std::unique_ptr<EventNames> create(Args&&... args)
352 {
353 return std::unique_ptr<EventNames>(new EventNames(std::forward<Args>(args)...));
354 }
355
356 // FIXME: Inelegant to call these both event names and event types.
357 // We should choose one term and stick to it.
358 bool isWheelEventType(const AtomString& eventType) const;
359 bool isGestureEventType(const AtomString& eventType) const;
360 bool isTouchRelatedEventType(const Document&, const AtomString& eventType) const;
361 bool isTouchScrollBlockingEventType(const AtomString& eventType) const;
362#if ENABLE(GAMEPAD)
363 bool isGamepadEventType(const AtomString& eventType) const;
364#endif
365
366 std::array<std::reference_wrapper<const AtomString>, 13> touchRelatedEventNames() const;
367 std::array<std::reference_wrapper<const AtomString>, 16> extendedTouchRelatedEventNames() const;
368 std::array<std::reference_wrapper<const AtomString>, 3> gestureEventNames() const;
369
370private:
371 EventNames(); // Private to prevent accidental call to EventNames() instead of eventNames().
372 friend class ThreadGlobalData; // Allow ThreadGlobalData to create the per-thread EventNames object.
373
374 int dummy; // Needed to make initialization macro work.
375};
376
377const EventNames& eventNames();
378
379inline const EventNames& eventNames()
380{
381 return threadGlobalData().eventNames();
382}
383
384inline bool EventNames::isGestureEventType(const AtomString& eventType) const
385{
386 return eventType == gesturestartEvent || eventType == gesturechangeEvent || eventType == gestureendEvent;
387}
388
389inline bool EventNames::isTouchScrollBlockingEventType(const AtomString& eventType) const
390{
391 return eventType == touchstartEvent
392 || eventType == touchmoveEvent;
393}
394
395inline bool EventNames::isTouchRelatedEventType(const Document& document, const AtomString& eventType) const
396{
397#if ENABLE(TOUCH_EVENTS)
398 if (document.quirks().shouldDispatchSimulatedMouseEvents() || RuntimeEnabledFeatures::sharedFeatures().mouseEventsSimulationEnabled()) {
399 if (eventType == mousedownEvent || eventType == mousemoveEvent || eventType == mouseupEvent)
400 return true;
401 }
402#endif
403 UNUSED_PARAM(document);
404 return eventType == touchstartEvent
405 || eventType == touchmoveEvent
406 || eventType == touchendEvent
407 || eventType == touchcancelEvent
408 || eventType == touchforcechangeEvent
409 || eventType == pointeroverEvent
410 || eventType == pointerenterEvent
411 || eventType == pointerdownEvent
412 || eventType == pointermoveEvent
413 || eventType == pointerupEvent
414 || eventType == pointeroutEvent
415 || eventType == pointerleaveEvent
416 || eventType == pointercancelEvent;
417}
418
419inline bool EventNames::isWheelEventType(const AtomString& eventType) const
420{
421 return eventType == wheelEvent
422 || eventType == mousewheelEvent;
423}
424
425inline std::array<std::reference_wrapper<const AtomString>, 13> EventNames::touchRelatedEventNames() const
426{
427 return { { touchstartEvent, touchmoveEvent, touchendEvent, touchcancelEvent, touchforcechangeEvent, pointeroverEvent, pointerenterEvent, pointerdownEvent, pointermoveEvent, pointerupEvent, pointeroutEvent, pointerleaveEvent, pointercancelEvent } };
428}
429
430inline std::array<std::reference_wrapper<const AtomString>, 16> EventNames::extendedTouchRelatedEventNames() const
431{
432 return { { touchstartEvent, touchmoveEvent, touchendEvent, touchcancelEvent, touchforcechangeEvent, pointeroverEvent, pointerenterEvent, pointerdownEvent, pointermoveEvent, pointerupEvent, pointeroutEvent, pointerleaveEvent, pointercancelEvent, mousedownEvent, mousemoveEvent, mouseupEvent } };
433}
434
435inline std::array<std::reference_wrapper<const AtomString>, 3> EventNames::gestureEventNames() const
436{
437 return { { gesturestartEvent, gesturechangeEvent, gestureendEvent } };
438}
439
440#if ENABLE(GAMEPAD)
441
442inline bool EventNames::isGamepadEventType(const AtomString& eventType) const
443{
444 return eventType == gamepadconnectedEvent
445 || eventType == gamepaddisconnectedEvent;
446}
447
448#endif
449
450} // namespace WebCore
451