Debian Codegraph @

closure-library/closure/goog/events/eventtype.js

raw
1 // Copyright 2010 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 /**
16 * @fileoverview Event Types.
17 *
18 * @author [email protected] (Erik Arvidsson)
19 */
20
21
22 goog.provide('goog.events.EventType');
23 goog.provide('goog.events.PointerFallbackEventType');
24
25 goog.require('goog.events.BrowserFeature');
26 goog.require('goog.userAgent');
27
28
29 /**
30 * Returns a prefixed event name for the current browser.
31 * @param {string} eventName The name of the event.
32 * @return {string} The prefixed event name.
33 * @suppress {missingRequire|missingProvide}
34 * @private
35 */
36 goog.events.getVendorPrefixedName_ = function(eventName) {
37 return goog.userAgent.WEBKIT ?
38 'webkit' + eventName :
39 (goog.userAgent.OPERA ? 'o' + eventName.toLowerCase() :
40 eventName.toLowerCase());
41 };
42
43
44 /**
45 * Constants for event names.
46 * @enum {string}
47 */
48 goog.events.EventType = {
49 // Mouse events
50 CLICK: 'click',
51 RIGHTCLICK: 'rightclick',
52 DBLCLICK: 'dblclick',
53 MOUSEDOWN: 'mousedown',
54 MOUSEUP: 'mouseup',
55 MOUSEOVER: 'mouseover',
56 MOUSEOUT: 'mouseout',
57 MOUSEMOVE: 'mousemove',
58 MOUSEENTER: 'mouseenter',
59 MOUSELEAVE: 'mouseleave',
60
61 // Selection events.
62 // https://www.w3.org/TR/selection-api/
63 SELECTIONCHANGE: 'selectionchange',
64 SELECTSTART: 'selectstart', // IE, Safari, Chrome
65
66 // Wheel events
67 // http://www.w3.org/TR/DOM-Level-3-Events/#events-wheelevents
68 WHEEL: 'wheel',
69
70 // Key events
71 KEYPRESS: 'keypress',
72 KEYDOWN: 'keydown',
73 KEYUP: 'keyup',
74
75 // Focus
76 BLUR: 'blur',
77 FOCUS: 'focus',
78 DEACTIVATE: 'deactivate', // IE only
79 FOCUSIN: 'focusin',
80 FOCUSOUT: 'focusout',
81
82 // Forms
83 CHANGE: 'change',
84 RESET: 'reset',
85 SELECT: 'select',
86 SUBMIT: 'submit',
87 INPUT: 'input',
88 PROPERTYCHANGE: 'propertychange', // IE only
89
90 // Drag and drop
91 DRAGSTART: 'dragstart',
92 DRAG: 'drag',
93 DRAGENTER: 'dragenter',
94 DRAGOVER: 'dragover',
95 DRAGLEAVE: 'dragleave',
96 DROP: 'drop',
97 DRAGEND: 'dragend',
98
99 // Touch events
100 // Note that other touch events exist, but we should follow the W3C list here.
101 // http://www.w3.org/TR/touch-events/#list-of-touchevent-types
102 TOUCHSTART: 'touchstart',
103 TOUCHMOVE: 'touchmove',
104 TOUCHEND: 'touchend',
105 TOUCHCANCEL: 'touchcancel',
106
107 // Misc
108 BEFOREUNLOAD: 'beforeunload',
109 CONSOLEMESSAGE: 'consolemessage',
110 CONTEXTMENU: 'contextmenu',
111 DEVICEMOTION: 'devicemotion',
112 DEVICEORIENTATION: 'deviceorientation',
113 DOMCONTENTLOADED: 'DOMContentLoaded',
114 ERROR: 'error',
115 HELP: 'help',
116 LOAD: 'load',
117 LOSECAPTURE: 'losecapture',
118 ORIENTATIONCHANGE: 'orientationchange',
119 READYSTATECHANGE: 'readystatechange',
120 RESIZE: 'resize',
121 SCROLL: 'scroll',
122 UNLOAD: 'unload',
123
124 // Media events
125 CANPLAY: 'canplay',
126 CANPLAYTHROUGH: 'canplaythrough',
127 DURATIONCHANGE: 'durationchange',
128 EMPTIED: 'emptied',
129 ENDED: 'ended',
130 LOADEDDATA: 'loadeddata',
131 LOADEDMETADATA: 'loadedmetadata',
132 PAUSE: 'pause',
133 PLAY: 'play',
134 PLAYING: 'playing',
135 RATECHANGE: 'ratechange',
136 SEEKED: 'seeked',
137 SEEKING: 'seeking',
138 STALLED: 'stalled',
139 SUSPEND: 'suspend',
140 TIMEUPDATE: 'timeupdate',
141 VOLUMECHANGE: 'volumechange',
142 WAITING: 'waiting',
143
144 // Media Source Extensions events
145 // https://www.w3.org/TR/media-source/#mediasource-events
146 SOURCEOPEN: 'sourceopen',
147 SOURCEENDED: 'sourceended',
148 SOURCECLOSED: 'sourceclosed',
149 // https://www.w3.org/TR/media-source/#sourcebuffer-events
150 ABORT: 'abort',
151 UPDATE: 'update',
152 UPDATESTART: 'updatestart',
153 UPDATEEND: 'updateend',
154
155 // HTML 5 History events
156 // See http://www.w3.org/TR/html5/browsers.html#event-definitions-0
157 HASHCHANGE: 'hashchange',
158 PAGEHIDE: 'pagehide',
159 PAGESHOW: 'pageshow',
160 POPSTATE: 'popstate',
161
162 // Copy and Paste
163 // Support is limited. Make sure it works on your favorite browser
164 // before using.
165 // http://www.quirksmode.org/dom/events/cutcopypaste.html
166 COPY: 'copy',
167 PASTE: 'paste',
168 CUT: 'cut',
169 BEFORECOPY: 'beforecopy',
170 BEFORECUT: 'beforecut',
171 BEFOREPASTE: 'beforepaste',
172
173 // HTML5 online/offline events.
174 // http://www.w3.org/TR/offline-webapps/#related
175 ONLINE: 'online',
176 OFFLINE: 'offline',
177
178 // HTML 5 worker events
179 MESSAGE: 'message',
180 CONNECT: 'connect',
181
182 // Service Worker Events - ServiceWorkerGlobalScope context
183 // See https://w3c.github.io/ServiceWorker/#execution-context-events
184 // Note: message event defined in worker events section
185 INSTALL: 'install',
186 ACTIVATE: 'activate',
187 FETCH: 'fetch',
188 FOREIGNFETCH: 'foreignfetch',
189 MESSAGEERROR: 'messageerror',
190
191 // Service Worker Events - Document context
192 // See https://w3c.github.io/ServiceWorker/#document-context-events
193 STATECHANGE: 'statechange',
194 UPDATEFOUND: 'updatefound',
195 CONTROLLERCHANGE: 'controllerchange',
196
197 // CSS animation events.
198 /** @suppress {missingRequire} */
199 ANIMATIONSTART: goog.events.getVendorPrefixedName_('AnimationStart'),
200 /** @suppress {missingRequire} */
201 ANIMATIONEND: goog.events.getVendorPrefixedName_('AnimationEnd'),
202 /** @suppress {missingRequire} */
203 ANIMATIONITERATION: goog.events.getVendorPrefixedName_('AnimationIteration'),
204
205 // CSS transition events. Based on the browser support described at:
206 // https://developer.mozilla.org/en/css/css_transitions#Browser_compatibility
207 /** @suppress {missingRequire} */
208 TRANSITIONEND: goog.events.getVendorPrefixedName_('TransitionEnd'),
209
210 // W3C Pointer Events
211 // http://www.w3.org/TR/pointerevents/
212 POINTERDOWN: 'pointerdown',
213 POINTERUP: 'pointerup',
214 POINTERCANCEL: 'pointercancel',
215 POINTERMOVE: 'pointermove',
216 POINTEROVER: 'pointerover',
217 POINTEROUT: 'pointerout',
218 POINTERENTER: 'pointerenter',
219 POINTERLEAVE: 'pointerleave',
220 GOTPOINTERCAPTURE: 'gotpointercapture',
221 LOSTPOINTERCAPTURE: 'lostpointercapture',
222
223 // IE specific events.
224 // See http://msdn.microsoft.com/en-us/library/ie/hh772103(v=vs.85).aspx
225 // Note: these events will be supplanted in IE11.
226 MSGESTURECHANGE: 'MSGestureChange',
227 MSGESTUREEND: 'MSGestureEnd',
228 MSGESTUREHOLD: 'MSGestureHold',
229 MSGESTURESTART: 'MSGestureStart',
230 MSGESTURETAP: 'MSGestureTap',
231 MSGOTPOINTERCAPTURE: 'MSGotPointerCapture',
232 MSINERTIASTART: 'MSInertiaStart',
233 MSLOSTPOINTERCAPTURE: 'MSLostPointerCapture',
234 MSPOINTERCANCEL: 'MSPointerCancel',
235 MSPOINTERDOWN: 'MSPointerDown',
236 MSPOINTERENTER: 'MSPointerEnter',
237 MSPOINTERHOVER: 'MSPointerHover',
238 MSPOINTERLEAVE: 'MSPointerLeave',
239 MSPOINTERMOVE: 'MSPointerMove',
240 MSPOINTEROUT: 'MSPointerOut',
241 MSPOINTEROVER: 'MSPointerOver',
242 MSPOINTERUP: 'MSPointerUp',
243
244 // Native IMEs/input tools events.
245 TEXT: 'text',
246 // The textInput event is supported in IE9+, but only in lower case. All other
247 // browsers use the camel-case event name.
248 TEXTINPUT: goog.userAgent.IE ? 'textinput' : 'textInput',
249 COMPOSITIONSTART: 'compositionstart',
250 COMPOSITIONUPDATE: 'compositionupdate',
251 COMPOSITIONEND: 'compositionend',
252
253 // The beforeinput event is initially only supported in Safari. See
254 // https://bugs.chromium.org/p/chromium/issues/detail?id=342670 for Chrome
255 // implementation tracking.
256 BEFOREINPUT: 'beforeinput',
257
258 // Webview tag events
259 // See http://developer.chrome.com/dev/apps/webview_tag.html
260 EXIT: 'exit',
261 LOADABORT: 'loadabort',
262 LOADCOMMIT: 'loadcommit',
263 LOADREDIRECT: 'loadredirect',
264 LOADSTART: 'loadstart',
265 LOADSTOP: 'loadstop',
266 RESPONSIVE: 'responsive',
267 SIZECHANGED: 'sizechanged',
268 UNRESPONSIVE: 'unresponsive',
269
270 // HTML5 Page Visibility API. See details at
271 // {@code goog.labs.dom.PageVisibilityMonitor}.
272 VISIBILITYCHANGE: 'visibilitychange',
273
274 // LocalStorage event.
275 STORAGE: 'storage',
276
277 // DOM Level 2 mutation events (deprecated).
278 DOMSUBTREEMODIFIED: 'DOMSubtreeModified',
279 DOMNODEINSERTED: 'DOMNodeInserted',
280 DOMNODEREMOVED: 'DOMNodeRemoved',
281 DOMNODEREMOVEDFROMDOCUMENT: 'DOMNodeRemovedFromDocument',
282 DOMNODEINSERTEDINTODOCUMENT: 'DOMNodeInsertedIntoDocument',
283 DOMATTRMODIFIED: 'DOMAttrModified',
284 DOMCHARACTERDATAMODIFIED: 'DOMCharacterDataModified',
285
286 // Print events.
287 BEFOREPRINT: 'beforeprint',
288 AFTERPRINT: 'afterprint',
289
290 // Web app manifest events.
291 BEFOREINSTALLPROMPT: 'beforeinstallprompt',
292 APPINSTALLED: 'appinstalled'
293 };
294
295
296 /**
297 * Returns one of the given pointer fallback event names in order of preference:
298 * 1. pointerEventName
299 * 2. msPointerEventName
300 * 3. mouseEventName
301 * @param {string} pointerEventName
302 * @param {string} msPointerEventName
303 * @param {string} mouseEventName
304 * @return {string} The supported pointer or mouse event name.
305 * @private
306 */
307 goog.events.getPointerFallbackEventName_ = function(
308 pointerEventName, msPointerEventName, mouseEventName) {
309 if (goog.events.BrowserFeature.POINTER_EVENTS) {
310 return pointerEventName;
311 }
312 if (goog.events.BrowserFeature.MSPOINTER_EVENTS) {
313 return msPointerEventName;
314 }
315 return mouseEventName;
316 };
317
318
319 /**
320 * Constants for pointer event names that fall back to corresponding mouse event
321 * names on unsupported platforms. These are intended to be drop-in replacements
322 * for corresponding values in {@code goog.events.EventType}.
323 * @enum {string}
324 */
325 goog.events.PointerFallbackEventType = {
326 POINTERDOWN: goog.events.getPointerFallbackEventName_(
327 goog.events.EventType.POINTERDOWN, goog.events.EventType.MSPOINTERDOWN,
328 goog.events.EventType.MOUSEDOWN),
329 POINTERUP: goog.events.getPointerFallbackEventName_(
330 goog.events.EventType.POINTERUP, goog.events.EventType.MSPOINTERUP,
331 goog.events.EventType.MOUSEUP),
332 POINTERCANCEL: goog.events.getPointerFallbackEventName_(
333 goog.events.EventType.POINTERCANCEL,
334 goog.events.EventType.MSPOINTERCANCEL,
335 // When falling back to mouse events, there is no MOUSECANCEL equivalent
336 // of POINTERCANCEL. In this case POINTERUP already falls back to MOUSEUP
337 // which represents both UP and CANCEL. POINTERCANCEL does not fall back
338 // to MOUSEUP to prevent listening twice on the same event.
339 'mousecancel'), // non-existent event; will never fire
340 POINTERMOVE: goog.events.getPointerFallbackEventName_(
341 goog.events.EventType.POINTERMOVE, goog.events.EventType.MSPOINTERMOVE,
342 goog.events.EventType.MOUSEMOVE),
343 POINTEROVER: goog.events.getPointerFallbackEventName_(
344 goog.events.EventType.POINTEROVER, goog.events.EventType.MSPOINTEROVER,
345 goog.events.EventType.MOUSEOVER),
346 POINTEROUT: goog.events.getPointerFallbackEventName_(
347 goog.events.EventType.POINTEROUT, goog.events.EventType.MSPOINTEROUT,
348 goog.events.EventType.MOUSEOUT),
349 POINTERENTER: goog.events.getPointerFallbackEventName_(
350 goog.events.EventType.POINTERENTER, goog.events.EventType.MSPOINTERENTER,
351 goog.events.EventType.MOUSEENTER),
352 POINTERLEAVE: goog.events.getPointerFallbackEventName_(
353 goog.events.EventType.POINTERLEAVE, goog.events.EventType.MSPOINTERLEAVE,
354 goog.events.EventType.MOUSELEAVE)
355 };