Backed out changeset 47837dce0006 (bug 951146) for mochitest-bc orange. a=backout
[gecko.git] / widget / BasicEvents.h
blobc312d873b8764e2d280e07235c4c128cedb53199
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_BasicEvents_h__
7 #define mozilla_BasicEvents_h__
9 #include <stdint.h>
11 #include "mozilla/dom/EventTarget.h"
12 #include "nsCOMPtr.h"
13 #include "nsIAtom.h"
14 #include "nsIWidget.h"
15 #include "nsString.h"
16 #include "nsTraceRefcnt.h"
17 #include "Units.h"
19 /******************************************************************************
20 * Event Struct Types
22 * TODO: Move it into mozilla namespace.
23 ******************************************************************************/
24 enum nsEventStructType
26 // BasicEvents.h
27 NS_EVENT, // WidgetEvent
28 NS_GUI_EVENT, // WidgetGUIEvent
29 NS_INPUT_EVENT, // WidgetInputEvent
30 NS_UI_EVENT, // InternalUIEvent
32 // TextEvents.h
33 NS_KEY_EVENT, // WidgetKeyboardEvent
34 NS_COMPOSITION_EVENT, // WidgetCompositionEvent
35 NS_TEXT_EVENT, // WidgetTextEvent
36 NS_QUERY_CONTENT_EVENT, // WidgetQueryContentEvent
37 NS_SELECTION_EVENT, // WidgetSelectionEvent
39 // MouseEvents.h
40 NS_MOUSE_EVENT, // WidgetMouseEvent
41 NS_DRAG_EVENT, // WidgetDragEvent
42 NS_MOUSE_SCROLL_EVENT, // WidgetMouseScrollEvent
43 NS_WHEEL_EVENT, // WidgetWheelEvent
44 NS_POINTER_EVENT, // PointerEvent
46 // TouchEvents.h
47 NS_GESTURENOTIFY_EVENT, // WidgetGestureNotifyEvent
48 NS_SIMPLE_GESTURE_EVENT, // WidgetSimpleGestureEvent
49 NS_TOUCH_EVENT, // WidgetTouchEvent
51 // ContentEvents.h
52 NS_SCRIPT_ERROR_EVENT, // InternalScriptErrorEvent
53 NS_SCROLLPORT_EVENT, // InternalScrollPortEvent
54 NS_SCROLLAREA_EVENT, // InternalScrollAreaEvent
55 NS_FORM_EVENT, // InternalFormEvent
56 NS_FOCUS_EVENT, // InternalFocusEvent
57 NS_CLIPBOARD_EVENT, // InternalClipboardEvent
58 NS_TRANSITION_EVENT, // InternalTransitionEvent
59 NS_ANIMATION_EVENT, // InternalAnimationEvent
61 // MiscEvents.h
62 NS_COMMAND_EVENT, // WidgetCommandEvent
63 NS_CONTENT_COMMAND_EVENT, // WidgetContentCommandEvent
64 NS_PLUGIN_EVENT, // WidgetPluginEvent
66 // MutationEvent.h (content/events/public)
67 NS_MUTATION_EVENT, // InternalMutationEvent
69 // Follwoing struct type values are ugly. They indicate other struct type
70 // actually. However, they are used for distinguishing which DOM event
71 // should be created for the event.
72 NS_SVGZOOM_EVENT, // WidgetGUIEvent
73 NS_SMIL_TIME_EVENT // InternalUIEvent
76 /******************************************************************************
77 * Messages
79 * TODO: Make them enum.
80 ******************************************************************************/
82 #define NS_EVENT_NULL 0
84 // This is a dummy event message for all event listener implementation in
85 // nsEventListenerManager.
86 #define NS_EVENT_ALL 1
88 #define NS_WINDOW_START 100
90 // Widget may be destroyed
91 #define NS_XUL_CLOSE (NS_WINDOW_START + 1)
92 // Key is pressed within a window
93 #define NS_KEY_PRESS (NS_WINDOW_START + 31)
94 // Key is released within a window
95 #define NS_KEY_UP (NS_WINDOW_START + 32)
96 // Key is pressed within a window
97 #define NS_KEY_DOWN (NS_WINDOW_START + 33)
99 #define NS_RESIZE_EVENT (NS_WINDOW_START + 60)
100 #define NS_SCROLL_EVENT (NS_WINDOW_START + 61)
102 // A plugin was clicked or otherwise focused. NS_PLUGIN_ACTIVATE should be
103 // used when the window is not active. NS_PLUGIN_FOCUS should be used when
104 // the window is active. In the latter case, the dispatcher of the event
105 // is expected to ensure that the plugin's widget is focused beforehand.
106 #define NS_PLUGIN_ACTIVATE (NS_WINDOW_START + 62)
107 #define NS_PLUGIN_FOCUS (NS_WINDOW_START + 63)
109 #define NS_OFFLINE (NS_WINDOW_START + 64)
110 #define NS_ONLINE (NS_WINDOW_START + 65)
112 // NS_BEFORERESIZE_EVENT used to be here (NS_WINDOW_START + 66)
114 // Indicates that the user is either idle or active
115 #define NS_MOZ_USER_IDLE (NS_WINDOW_START + 67)
116 #define NS_MOZ_USER_ACTIVE (NS_WINDOW_START + 68)
118 // The resolution at which a plugin should draw has changed, for
119 // example as the result of changing from a HiDPI mode to a non-
120 // HiDPI mode.
121 #define NS_PLUGIN_RESOLUTION_CHANGED (NS_WINDOW_START + 69)
123 #define NS_MOUSE_MESSAGE_START 300
124 #define NS_MOUSE_MOVE (NS_MOUSE_MESSAGE_START)
125 #define NS_MOUSE_BUTTON_UP (NS_MOUSE_MESSAGE_START + 1)
126 #define NS_MOUSE_BUTTON_DOWN (NS_MOUSE_MESSAGE_START + 2)
127 #define NS_MOUSE_ENTER (NS_MOUSE_MESSAGE_START + 22)
128 #define NS_MOUSE_EXIT (NS_MOUSE_MESSAGE_START + 23)
129 #define NS_MOUSE_DOUBLECLICK (NS_MOUSE_MESSAGE_START + 24)
130 #define NS_MOUSE_CLICK (NS_MOUSE_MESSAGE_START + 27)
131 #define NS_MOUSE_ACTIVATE (NS_MOUSE_MESSAGE_START + 30)
132 #define NS_MOUSE_ENTER_SYNTH (NS_MOUSE_MESSAGE_START + 31)
133 #define NS_MOUSE_EXIT_SYNTH (NS_MOUSE_MESSAGE_START + 32)
134 #define NS_MOUSE_MOZHITTEST (NS_MOUSE_MESSAGE_START + 33)
135 #define NS_MOUSEENTER (NS_MOUSE_MESSAGE_START + 34)
136 #define NS_MOUSELEAVE (NS_MOUSE_MESSAGE_START + 35)
138 // Pointer spec events
139 #define NS_POINTER_EVENT_START 4400
140 #define NS_POINTER_MOVE (NS_POINTER_EVENT_START)
141 #define NS_POINTER_UP (NS_POINTER_EVENT_START + 1)
142 #define NS_POINTER_DOWN (NS_POINTER_EVENT_START + 2)
143 #define NS_POINTER_OVER (NS_POINTER_EVENT_START + 22)
144 #define NS_POINTER_OUT (NS_POINTER_EVENT_START + 23)
145 #define NS_POINTER_ENTER (NS_POINTER_EVENT_START + 24)
146 #define NS_POINTER_LEAVE (NS_POINTER_EVENT_START + 25)
147 #define NS_POINTER_CANCEL (NS_POINTER_EVENT_START + 26)
148 #define NS_POINTER_GOT_CAPTURE (NS_POINTER_EVENT_START + 27)
149 #define NS_POINTER_LOST_CAPTURE (NS_POINTER_EVENT_START + 28)
151 #define NS_CONTEXTMENU_MESSAGE_START 500
152 #define NS_CONTEXTMENU (NS_CONTEXTMENU_MESSAGE_START)
154 #define NS_STREAM_EVENT_START 1100
155 #define NS_LOAD (NS_STREAM_EVENT_START)
156 #define NS_PAGE_UNLOAD (NS_STREAM_EVENT_START + 1)
157 #define NS_HASHCHANGE (NS_STREAM_EVENT_START + 2)
158 #define NS_IMAGE_ABORT (NS_STREAM_EVENT_START + 3)
159 #define NS_LOAD_ERROR (NS_STREAM_EVENT_START + 4)
160 #define NS_POPSTATE (NS_STREAM_EVENT_START + 5)
161 #define NS_BEFORE_PAGE_UNLOAD (NS_STREAM_EVENT_START + 6)
162 #define NS_PAGE_RESTORE (NS_STREAM_EVENT_START + 7)
163 #define NS_READYSTATECHANGE (NS_STREAM_EVENT_START + 8)
165 #define NS_FORM_EVENT_START 1200
166 #define NS_FORM_SUBMIT (NS_FORM_EVENT_START)
167 #define NS_FORM_RESET (NS_FORM_EVENT_START + 1)
168 #define NS_FORM_CHANGE (NS_FORM_EVENT_START + 2)
169 #define NS_FORM_SELECTED (NS_FORM_EVENT_START + 3)
170 #define NS_FORM_INPUT (NS_FORM_EVENT_START + 4)
171 #define NS_FORM_INVALID (NS_FORM_EVENT_START + 5)
173 //Need separate focus/blur notifications for non-native widgets
174 #define NS_FOCUS_EVENT_START 1300
175 #define NS_FOCUS_CONTENT (NS_FOCUS_EVENT_START)
176 #define NS_BLUR_CONTENT (NS_FOCUS_EVENT_START + 1)
178 #define NS_DRAGDROP_EVENT_START 1400
179 #define NS_DRAGDROP_ENTER (NS_DRAGDROP_EVENT_START)
180 #define NS_DRAGDROP_OVER (NS_DRAGDROP_EVENT_START + 1)
181 #define NS_DRAGDROP_EXIT (NS_DRAGDROP_EVENT_START + 2)
182 #define NS_DRAGDROP_DRAGDROP (NS_DRAGDROP_EVENT_START + 3)
183 #define NS_DRAGDROP_GESTURE (NS_DRAGDROP_EVENT_START + 4)
184 #define NS_DRAGDROP_DRAG (NS_DRAGDROP_EVENT_START + 5)
185 #define NS_DRAGDROP_END (NS_DRAGDROP_EVENT_START + 6)
186 #define NS_DRAGDROP_START (NS_DRAGDROP_EVENT_START + 7)
187 #define NS_DRAGDROP_DROP (NS_DRAGDROP_EVENT_START + 8)
188 #define NS_DRAGDROP_OVER_SYNTH (NS_DRAGDROP_EVENT_START + 1)
189 #define NS_DRAGDROP_EXIT_SYNTH (NS_DRAGDROP_EVENT_START + 2)
190 #define NS_DRAGDROP_LEAVE_SYNTH (NS_DRAGDROP_EVENT_START + 9)
192 // Events for popups
193 #define NS_XUL_EVENT_START 1500
194 #define NS_XUL_POPUP_SHOWING (NS_XUL_EVENT_START)
195 #define NS_XUL_POPUP_SHOWN (NS_XUL_EVENT_START+1)
196 #define NS_XUL_POPUP_HIDING (NS_XUL_EVENT_START+2)
197 #define NS_XUL_POPUP_HIDDEN (NS_XUL_EVENT_START+3)
198 // NS_XUL_COMMAND used to be here (NS_XUL_EVENT_START+4)
199 #define NS_XUL_BROADCAST (NS_XUL_EVENT_START+5)
200 #define NS_XUL_COMMAND_UPDATE (NS_XUL_EVENT_START+6)
201 //@}
203 // Scroll events
204 #define NS_MOUSE_SCROLL_START 1600
205 #define NS_MOUSE_SCROLL (NS_MOUSE_SCROLL_START)
206 #define NS_MOUSE_PIXEL_SCROLL (NS_MOUSE_SCROLL_START + 1)
208 #define NS_SCROLLPORT_START 1700
209 #define NS_SCROLLPORT_UNDERFLOW (NS_SCROLLPORT_START)
210 #define NS_SCROLLPORT_OVERFLOW (NS_SCROLLPORT_START+1)
212 #define NS_MUTATION_START 1800
213 #define NS_MUTATION_SUBTREEMODIFIED (NS_MUTATION_START)
214 #define NS_MUTATION_NODEINSERTED (NS_MUTATION_START+1)
215 #define NS_MUTATION_NODEREMOVED (NS_MUTATION_START+2)
216 #define NS_MUTATION_NODEREMOVEDFROMDOCUMENT (NS_MUTATION_START+3)
217 #define NS_MUTATION_NODEINSERTEDINTODOCUMENT (NS_MUTATION_START+4)
218 #define NS_MUTATION_ATTRMODIFIED (NS_MUTATION_START+5)
219 #define NS_MUTATION_CHARACTERDATAMODIFIED (NS_MUTATION_START+6)
220 #define NS_MUTATION_END (NS_MUTATION_START+6)
222 #define NS_USER_DEFINED_EVENT 2000
224 // composition events
225 #define NS_COMPOSITION_EVENT_START 2200
226 #define NS_COMPOSITION_START (NS_COMPOSITION_EVENT_START)
227 #define NS_COMPOSITION_END (NS_COMPOSITION_EVENT_START + 1)
228 #define NS_COMPOSITION_UPDATE (NS_COMPOSITION_EVENT_START + 2)
230 // text events
231 #define NS_TEXT_START 2400
232 #define NS_TEXT_TEXT (NS_TEXT_START)
234 // UI events
235 #define NS_UI_EVENT_START 2500
236 // this is not to be confused with NS_ACTIVATE!
237 #define NS_UI_ACTIVATE (NS_UI_EVENT_START)
238 #define NS_UI_FOCUSIN (NS_UI_EVENT_START + 1)
239 #define NS_UI_FOCUSOUT (NS_UI_EVENT_START + 2)
241 // pagetransition events
242 #define NS_PAGETRANSITION_START 2700
243 #define NS_PAGE_SHOW (NS_PAGETRANSITION_START + 1)
244 #define NS_PAGE_HIDE (NS_PAGETRANSITION_START + 2)
246 // SVG events
247 #define NS_SVG_EVENT_START 2800
248 #define NS_SVG_LOAD (NS_SVG_EVENT_START)
249 #define NS_SVG_UNLOAD (NS_SVG_EVENT_START + 1)
250 #define NS_SVG_ABORT (NS_SVG_EVENT_START + 2)
251 #define NS_SVG_ERROR (NS_SVG_EVENT_START + 3)
252 #define NS_SVG_RESIZE (NS_SVG_EVENT_START + 4)
253 #define NS_SVG_SCROLL (NS_SVG_EVENT_START + 5)
255 // SVG Zoom events
256 #define NS_SVGZOOM_EVENT_START 2900
257 #define NS_SVG_ZOOM (NS_SVGZOOM_EVENT_START)
259 // XUL command events
260 #define NS_XULCOMMAND_EVENT_START 3000
261 #define NS_XUL_COMMAND (NS_XULCOMMAND_EVENT_START)
263 // Cut, copy, paste events
264 #define NS_CUTCOPYPASTE_EVENT_START 3100
265 #define NS_COPY (NS_CUTCOPYPASTE_EVENT_START)
266 #define NS_CUT (NS_CUTCOPYPASTE_EVENT_START + 1)
267 #define NS_PASTE (NS_CUTCOPYPASTE_EVENT_START + 2)
269 // Query the content information
270 #define NS_QUERY_CONTENT_EVENT_START 3200
271 // Query for the selected text information, it return the selection offset,
272 // selection length and selected text.
273 #define NS_QUERY_SELECTED_TEXT (NS_QUERY_CONTENT_EVENT_START)
274 // Query for the text content of specified range, it returns actual lengh (if
275 // the specified range is too long) and the text of the specified range.
276 // Returns the entire text if requested length > actual length.
277 #define NS_QUERY_TEXT_CONTENT (NS_QUERY_CONTENT_EVENT_START + 1)
278 // Query for the caret rect of nth insertion point. The offset of the result is
279 // relative position from the top level widget.
280 #define NS_QUERY_CARET_RECT (NS_QUERY_CONTENT_EVENT_START + 3)
281 // Query for the bounding rect of a range of characters. This works on any
282 // valid character range given offset and length. Result is relative to top
283 // level widget coordinates
284 #define NS_QUERY_TEXT_RECT (NS_QUERY_CONTENT_EVENT_START + 4)
285 // Query for the bounding rect of the current focused frame. Result is relative
286 // to top level widget coordinates
287 #define NS_QUERY_EDITOR_RECT (NS_QUERY_CONTENT_EVENT_START + 5)
288 // Query for the current state of the content. The particular members of
289 // mReply that are set for each query content event will be valid on success.
290 #define NS_QUERY_CONTENT_STATE (NS_QUERY_CONTENT_EVENT_START + 6)
291 // Query for the selection in the form of a nsITransferable.
292 #define NS_QUERY_SELECTION_AS_TRANSFERABLE (NS_QUERY_CONTENT_EVENT_START + 7)
293 // Query for character at a point. This returns the character offset and its
294 // rect. The point is specified by Event::refPoint.
295 #define NS_QUERY_CHARACTER_AT_POINT (NS_QUERY_CONTENT_EVENT_START + 8)
296 // Query if the DOM element under Event::refPoint belongs to our widget
297 // or not.
298 #define NS_QUERY_DOM_WIDGET_HITTEST (NS_QUERY_CONTENT_EVENT_START + 9)
300 // Video events
301 #define NS_MEDIA_EVENT_START 3300
302 #define NS_LOADSTART (NS_MEDIA_EVENT_START)
303 #define NS_PROGRESS (NS_MEDIA_EVENT_START+1)
304 #define NS_SUSPEND (NS_MEDIA_EVENT_START+2)
305 #define NS_EMPTIED (NS_MEDIA_EVENT_START+3)
306 #define NS_STALLED (NS_MEDIA_EVENT_START+4)
307 #define NS_PLAY (NS_MEDIA_EVENT_START+5)
308 #define NS_PAUSE (NS_MEDIA_EVENT_START+6)
309 #define NS_LOADEDMETADATA (NS_MEDIA_EVENT_START+7)
310 #define NS_LOADEDDATA (NS_MEDIA_EVENT_START+8)
311 #define NS_WAITING (NS_MEDIA_EVENT_START+9)
312 #define NS_PLAYING (NS_MEDIA_EVENT_START+10)
313 #define NS_CANPLAY (NS_MEDIA_EVENT_START+11)
314 #define NS_CANPLAYTHROUGH (NS_MEDIA_EVENT_START+12)
315 #define NS_SEEKING (NS_MEDIA_EVENT_START+13)
316 #define NS_SEEKED (NS_MEDIA_EVENT_START+14)
317 #define NS_TIMEUPDATE (NS_MEDIA_EVENT_START+15)
318 #define NS_ENDED (NS_MEDIA_EVENT_START+16)
319 #define NS_RATECHANGE (NS_MEDIA_EVENT_START+17)
320 #define NS_DURATIONCHANGE (NS_MEDIA_EVENT_START+18)
321 #define NS_VOLUMECHANGE (NS_MEDIA_EVENT_START+19)
322 #define NS_MOZAUDIOAVAILABLE (NS_MEDIA_EVENT_START+20)
324 // paint notification events
325 #define NS_NOTIFYPAINT_START 3400
326 #define NS_AFTERPAINT (NS_NOTIFYPAINT_START)
328 // Simple gesture events
329 #define NS_SIMPLE_GESTURE_EVENT_START 3500
330 #define NS_SIMPLE_GESTURE_SWIPE_START (NS_SIMPLE_GESTURE_EVENT_START)
331 #define NS_SIMPLE_GESTURE_SWIPE_UPDATE (NS_SIMPLE_GESTURE_EVENT_START+1)
332 #define NS_SIMPLE_GESTURE_SWIPE_END (NS_SIMPLE_GESTURE_EVENT_START+2)
333 #define NS_SIMPLE_GESTURE_SWIPE (NS_SIMPLE_GESTURE_EVENT_START+3)
334 #define NS_SIMPLE_GESTURE_MAGNIFY_START (NS_SIMPLE_GESTURE_EVENT_START+4)
335 #define NS_SIMPLE_GESTURE_MAGNIFY_UPDATE (NS_SIMPLE_GESTURE_EVENT_START+5)
336 #define NS_SIMPLE_GESTURE_MAGNIFY (NS_SIMPLE_GESTURE_EVENT_START+6)
337 #define NS_SIMPLE_GESTURE_ROTATE_START (NS_SIMPLE_GESTURE_EVENT_START+7)
338 #define NS_SIMPLE_GESTURE_ROTATE_UPDATE (NS_SIMPLE_GESTURE_EVENT_START+8)
339 #define NS_SIMPLE_GESTURE_ROTATE (NS_SIMPLE_GESTURE_EVENT_START+9)
340 #define NS_SIMPLE_GESTURE_TAP (NS_SIMPLE_GESTURE_EVENT_START+10)
341 #define NS_SIMPLE_GESTURE_PRESSTAP (NS_SIMPLE_GESTURE_EVENT_START+11)
342 #define NS_SIMPLE_GESTURE_EDGE_STARTED (NS_SIMPLE_GESTURE_EVENT_START+12)
343 #define NS_SIMPLE_GESTURE_EDGE_CANCELED (NS_SIMPLE_GESTURE_EVENT_START+13)
344 #define NS_SIMPLE_GESTURE_EDGE_COMPLETED (NS_SIMPLE_GESTURE_EVENT_START+14)
346 // These are used to send native events to plugins.
347 #define NS_PLUGIN_EVENT_START 3600
348 #define NS_PLUGIN_INPUT_EVENT (NS_PLUGIN_EVENT_START)
349 #define NS_PLUGIN_FOCUS_EVENT (NS_PLUGIN_EVENT_START+1)
351 // Events to manipulate selection (WidgetSelectionEvent)
352 #define NS_SELECTION_EVENT_START 3700
353 // Clear any previous selection and set the given range as the selection
354 #define NS_SELECTION_SET (NS_SELECTION_EVENT_START)
356 // Events of commands for the contents
357 #define NS_CONTENT_COMMAND_EVENT_START 3800
358 #define NS_CONTENT_COMMAND_CUT (NS_CONTENT_COMMAND_EVENT_START)
359 #define NS_CONTENT_COMMAND_COPY (NS_CONTENT_COMMAND_EVENT_START+1)
360 #define NS_CONTENT_COMMAND_PASTE (NS_CONTENT_COMMAND_EVENT_START+2)
361 #define NS_CONTENT_COMMAND_DELETE (NS_CONTENT_COMMAND_EVENT_START+3)
362 #define NS_CONTENT_COMMAND_UNDO (NS_CONTENT_COMMAND_EVENT_START+4)
363 #define NS_CONTENT_COMMAND_REDO (NS_CONTENT_COMMAND_EVENT_START+5)
364 #define NS_CONTENT_COMMAND_PASTE_TRANSFERABLE (NS_CONTENT_COMMAND_EVENT_START+6)
365 // NS_CONTENT_COMMAND_SCROLL scrolls the nearest scrollable element to the
366 // currently focused content or latest DOM selection. This would normally be
367 // the same element scrolled by keyboard scroll commands, except that this event
368 // will scroll an element scrollable in either direction. I.e., if the nearest
369 // scrollable ancestor element can only be scrolled vertically, and horizontal
370 // scrolling is requested using this event, no scrolling will occur.
371 #define NS_CONTENT_COMMAND_SCROLL (NS_CONTENT_COMMAND_EVENT_START+7)
373 // Event to gesture notification
374 #define NS_GESTURENOTIFY_EVENT_START 3900
376 #define NS_ORIENTATION_EVENT 4000
378 #define NS_SCROLLAREA_EVENT_START 4100
379 #define NS_SCROLLEDAREACHANGED (NS_SCROLLAREA_EVENT_START)
381 #define NS_TRANSITION_EVENT_START 4200
382 #define NS_TRANSITION_END (NS_TRANSITION_EVENT_START)
384 #define NS_ANIMATION_EVENT_START 4250
385 #define NS_ANIMATION_START (NS_ANIMATION_EVENT_START)
386 #define NS_ANIMATION_END (NS_ANIMATION_EVENT_START + 1)
387 #define NS_ANIMATION_ITERATION (NS_ANIMATION_EVENT_START + 2)
389 #define NS_SMIL_TIME_EVENT_START 4300
390 #define NS_SMIL_BEGIN (NS_SMIL_TIME_EVENT_START)
391 #define NS_SMIL_END (NS_SMIL_TIME_EVENT_START + 1)
392 #define NS_SMIL_REPEAT (NS_SMIL_TIME_EVENT_START + 2)
394 #define NS_WEBAUDIO_EVENT_START 4350
395 #define NS_AUDIO_PROCESS (NS_WEBAUDIO_EVENT_START)
396 #define NS_AUDIO_COMPLETE (NS_WEBAUDIO_EVENT_START + 1)
398 // script notification events
399 #define NS_NOTIFYSCRIPT_START 4500
400 #define NS_BEFORE_SCRIPT_EXECUTE (NS_NOTIFYSCRIPT_START)
401 #define NS_AFTER_SCRIPT_EXECUTE (NS_NOTIFYSCRIPT_START+1)
403 #define NS_PRINT_EVENT_START 4600
404 #define NS_BEFOREPRINT (NS_PRINT_EVENT_START)
405 #define NS_AFTERPRINT (NS_PRINT_EVENT_START + 1)
407 #define NS_MESSAGE_EVENT_START 4700
408 #define NS_MESSAGE (NS_MESSAGE_EVENT_START)
410 // Open and close events
411 #define NS_OPENCLOSE_EVENT_START 4800
412 #define NS_OPEN (NS_OPENCLOSE_EVENT_START)
413 #define NS_CLOSE (NS_OPENCLOSE_EVENT_START+1)
415 // Device motion and orientation
416 #define NS_DEVICE_ORIENTATION_START 4900
417 #define NS_DEVICE_ORIENTATION (NS_DEVICE_ORIENTATION_START)
418 #define NS_DEVICE_MOTION (NS_DEVICE_ORIENTATION_START+1)
419 #define NS_DEVICE_PROXIMITY (NS_DEVICE_ORIENTATION_START+2)
420 #define NS_USER_PROXIMITY (NS_DEVICE_ORIENTATION_START+3)
421 #define NS_DEVICE_LIGHT (NS_DEVICE_ORIENTATION_START+4)
423 #define NS_SHOW_EVENT 5000
425 // Fullscreen DOM API
426 #define NS_FULL_SCREEN_START 5100
427 #define NS_FULLSCREENCHANGE (NS_FULL_SCREEN_START)
428 #define NS_FULLSCREENERROR (NS_FULL_SCREEN_START + 1)
430 #define NS_TOUCH_EVENT_START 5200
431 #define NS_TOUCH_START (NS_TOUCH_EVENT_START)
432 #define NS_TOUCH_MOVE (NS_TOUCH_EVENT_START+1)
433 #define NS_TOUCH_END (NS_TOUCH_EVENT_START+2)
434 #define NS_TOUCH_ENTER (NS_TOUCH_EVENT_START+3)
435 #define NS_TOUCH_LEAVE (NS_TOUCH_EVENT_START+4)
436 #define NS_TOUCH_CANCEL (NS_TOUCH_EVENT_START+5)
438 // Pointerlock DOM API
439 #define NS_POINTERLOCK_START 5300
440 #define NS_POINTERLOCKCHANGE (NS_POINTERLOCK_START)
441 #define NS_POINTERLOCKERROR (NS_POINTERLOCK_START + 1)
443 #define NS_WHEEL_EVENT_START 5400
444 #define NS_WHEEL_WHEEL (NS_WHEEL_EVENT_START)
445 #define NS_WHEEL_START (NS_WHEEL_EVENT_START + 1)
446 #define NS_WHEEL_STOP (NS_WHEEL_EVENT_START + 2)
448 //System time is changed
449 #define NS_MOZ_TIME_CHANGE_EVENT 5500
451 // Network packet events.
452 #define NS_NETWORK_EVENT_START 5600
453 #define NS_NETWORK_UPLOAD_EVENT (NS_NETWORK_EVENT_START + 1)
454 #define NS_NETWORK_DOWNLOAD_EVENT (NS_NETWORK_EVENT_START + 2)
456 // MediaRecorder events.
457 #define NS_MEDIARECORDER_EVENT_START 5700
458 #define NS_MEDIARECORDER_DATAAVAILABLE (NS_MEDIARECORDER_EVENT_START + 1)
459 #define NS_MEDIARECORDER_WARNING (NS_MEDIARECORDER_EVENT_START + 2)
460 #define NS_MEDIARECORDER_STOP (NS_MEDIARECORDER_EVENT_START + 3)
462 // SpeakerManager events
463 #define NS_SPEAKERMANAGER_EVENT_START 5800
464 #define NS_SPEAKERMANAGER_SPEAKERFORCEDCHANGE (NS_SPEAKERMANAGER_EVENT_START + 1)
466 #ifdef MOZ_GAMEPAD
467 // Gamepad input events
468 #define NS_GAMEPAD_START 6000
469 #define NS_GAMEPAD_BUTTONDOWN (NS_GAMEPAD_START)
470 #define NS_GAMEPAD_BUTTONUP (NS_GAMEPAD_START+1)
471 #define NS_GAMEPAD_AXISMOVE (NS_GAMEPAD_START+2)
472 #define NS_GAMEPAD_CONNECTED (NS_GAMEPAD_START+3)
473 #define NS_GAMEPAD_DISCONNECTED (NS_GAMEPAD_START+4)
474 // Keep this defined to the same value as the event above
475 #define NS_GAMEPAD_END (NS_GAMEPAD_START+4)
476 #endif
478 namespace mozilla {
480 /******************************************************************************
481 * mozilla::BaseEventFlags
483 * BaseEventFlags must be a POD struct for safe to use memcpy (including
484 * in ParamTraits<BaseEventFlags>). So don't make virtual methods, constructor,
485 * destructor and operators.
486 * This is necessary for VC which is NOT C++0x compiler.
487 ******************************************************************************/
489 struct BaseEventFlags
491 public:
492 // If mIsTrusted is true, the event is a trusted event. Otherwise, it's
493 // an untrusted event.
494 bool mIsTrusted : 1;
495 // If mInBubblingPhase is true, the event is in bubbling phase or target
496 // phase.
497 bool mInBubblingPhase : 1;
498 // If mInCapturePhase is true, the event is in capture phase or target phase.
499 bool mInCapturePhase : 1;
500 // If mInSystemGroup is true, the event is being dispatched in system group.
501 bool mInSystemGroup: 1;
502 // If mCancelable is true, the event can be consumed. I.e., calling
503 // nsDOMEvent::PreventDefault() can prevent the default action.
504 bool mCancelable : 1;
505 // If mBubbles is true, the event can bubble. Otherwise, cannot be handled
506 // in bubbling phase.
507 bool mBubbles : 1;
508 // If mPropagationStopped is true, nsDOMEvent::StopPropagation() or
509 // nsDOMEvent::StopImmediatePropagation() has been called.
510 bool mPropagationStopped : 1;
511 // If mImmediatePropagationStopped is true,
512 // nsDOMEvent::StopImmediatePropagation() has been called.
513 // Note that mPropagationStopped must be true when this is true.
514 bool mImmediatePropagationStopped : 1;
515 // If mDefaultPrevented is true, the event has been consumed.
516 // E.g., nsDOMEvent::PreventDefault() has been called or
517 // the default action has been performed.
518 bool mDefaultPrevented : 1;
519 // If mDefaultPreventedByContent is true, the event has been
520 // consumed by content.
521 // Note that mDefaultPrevented must be true when this is true.
522 bool mDefaultPreventedByContent : 1;
523 // mMultipleActionsPrevented may be used when default handling don't want to
524 // be prevented, but only one of the event targets should handle the event.
525 // For example, when a <label> element is in another <label> element and
526 // the first <label> element is clicked, that one may set this true.
527 // Then, the second <label> element won't handle the event.
528 bool mMultipleActionsPrevented : 1;
529 // If mIsBeingDispatched is true, the DOM event created from the event is
530 // dispatching into the DOM tree and not completed.
531 bool mIsBeingDispatched : 1;
532 // If mDispatchedAtLeastOnce is true, the event has been dispatched
533 // as a DOM event and the dispatch has been completed.
534 bool mDispatchedAtLeastOnce : 1;
535 // If mIsSynthesizedForTests is true, the event has been synthesized for
536 // automated tests or something hacky approach of an add-on.
537 bool mIsSynthesizedForTests : 1;
538 // If mExceptionHasBeenRisen is true, one of the event handlers has risen an
539 // exception.
540 bool mExceptionHasBeenRisen : 1;
541 // If mRetargetToNonNativeAnonymous is true and the target is in a non-native
542 // native anonymous subtree, the event target is set to originalTarget.
543 bool mRetargetToNonNativeAnonymous : 1;
544 // If mNoCrossProcessBoundaryForwarding is true, the event is not allowed to
545 // cross process boundary.
546 bool mNoCrossProcessBoundaryForwarding : 1;
547 // If mNoContentDispatch is true, the event is never dispatched to the
548 // event handlers which are added to the contents, onfoo attributes and
549 // properties. Note that this flag is ignored when
550 // nsEventChainPreVisitor::mForceContentDispatch is set true. For exapmle,
551 // window and document object sets it true. Therefore, web applications
552 // can handle the event if they add event listeners to the window or the
553 // document.
554 bool mNoContentDispatch : 1;
555 // If mOnlyChromeDispatch is true, the event is dispatched to only chrome.
556 bool mOnlyChromeDispatch : 1;
558 // If the event is being handled in target phase, returns true.
559 inline bool InTargetPhase() const
561 return (mInBubblingPhase && mInCapturePhase);
564 inline void Clear()
566 SetRawFlags(0);
568 // Get if either the instance's bit or the aOther's bit is true, the
569 // instance's bit becomes true. In other words, this works like:
570 // eventFlags |= aOther;
571 inline void Union(const BaseEventFlags& aOther)
573 RawFlags rawFlags = GetRawFlags() | aOther.GetRawFlags();
574 SetRawFlags(rawFlags);
577 private:
578 typedef uint32_t RawFlags;
580 inline void SetRawFlags(RawFlags aRawFlags)
582 static_assert(sizeof(BaseEventFlags) <= sizeof(RawFlags),
583 "mozilla::EventFlags must not be bigger than the RawFlags");
584 memcpy(this, &aRawFlags, sizeof(BaseEventFlags));
586 inline RawFlags GetRawFlags() const
588 RawFlags result = 0;
589 memcpy(&result, this, sizeof(BaseEventFlags));
590 return result;
594 /******************************************************************************
595 * mozilla::EventFlags
596 ******************************************************************************/
598 struct EventFlags : public BaseEventFlags
600 EventFlags()
602 Clear();
606 /******************************************************************************
607 * mozilla::WidgetEvent
608 ******************************************************************************/
610 class WidgetEvent
612 protected:
613 WidgetEvent(bool aIsTrusted, uint32_t aMessage,
614 nsEventStructType aStructType) :
615 eventStructType(aStructType), message(aMessage), refPoint(0, 0),
616 lastRefPoint(0, 0), time(0), userType(0)
618 MOZ_COUNT_CTOR(WidgetEvent);
619 mFlags.Clear();
620 mFlags.mIsTrusted = aIsTrusted;
621 mFlags.mCancelable = true;
622 mFlags.mBubbles = true;
625 WidgetEvent()
627 MOZ_COUNT_CTOR(WidgetEvent);
630 public:
631 WidgetEvent(bool aIsTrusted, uint32_t aMessage) :
632 eventStructType(NS_EVENT), message(aMessage), refPoint(0, 0),
633 lastRefPoint(0, 0), time(0), userType(0)
635 MOZ_COUNT_CTOR(WidgetEvent);
636 mFlags.Clear();
637 mFlags.mIsTrusted = aIsTrusted;
638 mFlags.mCancelable = true;
639 mFlags.mBubbles = true;
642 virtual ~WidgetEvent()
644 MOZ_COUNT_DTOR(WidgetEvent);
647 WidgetEvent(const WidgetEvent& aOther)
649 MOZ_COUNT_CTOR(WidgetEvent);
650 *this = aOther;
653 // See event struct types
654 nsEventStructType eventStructType;
655 // See GUI MESSAGES,
656 uint32_t message;
657 // Relative to the widget of the event, or if there is no widget then it is
658 // in screen coordinates. Not modified by layout code.
659 LayoutDeviceIntPoint refPoint;
660 // The previous refPoint, if known, used to calculate mouse movement deltas.
661 LayoutDeviceIntPoint lastRefPoint;
662 // Elapsed time, in milliseconds, from a platform-specific zero time
663 // to the time the message was created
664 uint64_t time;
665 // See BaseEventFlags definition for the detail.
666 BaseEventFlags mFlags;
668 // Additional type info for user defined events
669 nsCOMPtr<nsIAtom> userType;
671 nsString typeString; // always set on non-main-thread events
673 // Event targets, needed by DOM Events
674 nsCOMPtr<dom::EventTarget> target;
675 nsCOMPtr<dom::EventTarget> currentTarget;
676 nsCOMPtr<dom::EventTarget> originalTarget;
678 void AssignEventData(const WidgetEvent& aEvent, bool aCopyTargets)
680 // eventStructType, message should be initialized with the constructor.
681 refPoint = aEvent.refPoint;
682 // lastRefPoint doesn't need to be copied.
683 time = aEvent.time;
684 // mFlags should be copied manually if it's necessary.
685 userType = aEvent.userType;
686 // typeString should be copied manually if it's necessary.
687 target = aCopyTargets ? aEvent.target : nullptr;
688 currentTarget = aCopyTargets ? aEvent.currentTarget : nullptr;
689 originalTarget = aCopyTargets ? aEvent.originalTarget : nullptr;
693 * Utils for checking event types
697 * As*Event() returns the pointer of the instance only when the instance is
698 * the class or one of its derived class.
700 #define NS_ROOT_EVENT_CLASS(aPrefix, aName)
701 #define NS_EVENT_CLASS(aPrefix, aName) \
702 virtual aPrefix##aName* As##aName(); \
703 const aPrefix##aName* As##aName() const;
705 #include "mozilla/EventClassList.h"
707 #undef NS_EVENT_CLASS
708 #undef NS_ROOT_EVENT_CLASS
711 * Returns true if the event is a query content event.
713 bool IsQueryContentEvent() const;
715 * Returns true if the event is a selection event.
717 bool IsSelectionEvent() const;
719 * Returns true if the event is a content command event.
721 bool IsContentCommandEvent() const;
723 * Returns true if the event is a native event deliverer event for plugin.
725 bool IsNativeEventDelivererForPlugin() const;
728 * Returns true if the event message is one of mouse events.
730 bool HasMouseEventMessage() const;
732 * Returns true if the event message is one of drag events.
734 bool HasDragEventMessage() const;
736 * Returns true if the event message is one of key events.
738 bool HasKeyEventMessage() const;
740 * Returns true if the event message is one of composition events or text
741 * event.
743 bool HasIMEEventMessage() const;
745 * Returns true if the event message is one of plugin activation events.
747 bool HasPluginActivationEventMessage() const;
750 * Returns true if the event is native event deliverer event for plugin and
751 * it should be retarted to focused document.
753 bool IsRetargetedNativeEventDelivererForPlugin() const;
755 * Returns true if the event is native event deliverer event for plugin and
756 * it should NOT be retarted to focused document.
758 bool IsNonRetargetedNativeEventDelivererForPlugin() const;
760 * Returns true if the event is related to IME handling. It includes
761 * IME events, query content events and selection events.
762 * Be careful when you use this.
764 bool IsIMERelatedEvent() const;
767 * Whether the event should be handled by the frame of the mouse cursor
768 * position or not. When it should be handled there (e.g., the mouse events),
769 * this returns true.
771 bool IsUsingCoordinates() const;
773 * Whether the event should be handled by the focused DOM window in the
774 * same top level window's or not. E.g., key events, IME related events
775 * (including the query content events, they are used in IME transaction)
776 * should be handled by the (last) focused window rather than the dispatched
777 * window.
779 * NOTE: Even if this returns true, the event isn't going to be handled by the
780 * application level active DOM window which is on another top level window.
781 * So, when the event is fired on a deactive window, the event is going to be
782 * handled by the last focused DOM window in the last focused window.
784 bool IsTargetedAtFocusedWindow() const;
786 * Whether the event should be handled by the focused content or not. E.g.,
787 * key events, IME related events and other input events which are not handled
788 * by the frame of the mouse cursor position.
790 * NOTE: Even if this returns true, the event isn't going to be handled by the
791 * application level active DOM window which is on another top level window.
792 * So, when the event is fired on a deactive window, the event is going to be
793 * handled by the last focused DOM element of the last focused DOM window in
794 * the last focused window.
796 bool IsTargetedAtFocusedContent() const;
798 * Whether the event should cause a DOM event.
800 bool IsAllowedToDispatchDOMEvent() const;
803 /******************************************************************************
804 * mozilla::WidgetGUIEvent
805 ******************************************************************************/
807 class WidgetGUIEvent : public WidgetEvent
809 protected:
810 WidgetGUIEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget,
811 nsEventStructType aStructType) :
812 WidgetEvent(aIsTrusted, aMessage, aStructType),
813 widget(aWidget), pluginEvent(nullptr)
817 WidgetGUIEvent() :
818 pluginEvent(nullptr)
822 public:
823 virtual WidgetGUIEvent* AsGUIEvent() MOZ_OVERRIDE { return this; }
825 WidgetGUIEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
826 WidgetEvent(aIsTrusted, aMessage, NS_GUI_EVENT),
827 widget(aWidget), pluginEvent(nullptr)
831 /// Originator of the event
832 nsCOMPtr<nsIWidget> widget;
834 /// Event for NPAPI plugin
835 void* pluginEvent;
837 void AssignGUIEventData(const WidgetGUIEvent& aEvent, bool aCopyTargets)
839 AssignEventData(aEvent, aCopyTargets);
841 // widget should be initialized with the constructor.
843 // pluginEvent shouldn't be copied because it may be referred after its
844 // instance is destroyed.
845 pluginEvent = nullptr;
849 /******************************************************************************
850 * mozilla::Modifier
852 * All modifier keys should be defined here. This is used for managing
853 * modifier states for DOM Level 3 or later.
854 ******************************************************************************/
856 enum Modifier
858 MODIFIER_ALT = 0x0001,
859 MODIFIER_ALTGRAPH = 0x0002,
860 MODIFIER_CAPSLOCK = 0x0004,
861 MODIFIER_CONTROL = 0x0008,
862 MODIFIER_FN = 0x0010,
863 MODIFIER_META = 0x0020,
864 MODIFIER_NUMLOCK = 0x0040,
865 MODIFIER_SCROLLLOCK = 0x0080,
866 MODIFIER_SHIFT = 0x0100,
867 MODIFIER_SYMBOLLOCK = 0x0200,
868 MODIFIER_OS = 0x0400
871 /******************************************************************************
872 * Modifier key names.
873 ******************************************************************************/
875 #define NS_DOM_KEYNAME_ALT "Alt"
876 #define NS_DOM_KEYNAME_ALTGRAPH "AltGraph"
877 #define NS_DOM_KEYNAME_CAPSLOCK "CapsLock"
878 #define NS_DOM_KEYNAME_CONTROL "Control"
879 #define NS_DOM_KEYNAME_FN "Fn"
880 #define NS_DOM_KEYNAME_META "Meta"
881 #define NS_DOM_KEYNAME_NUMLOCK "NumLock"
882 #define NS_DOM_KEYNAME_SCROLLLOCK "ScrollLock"
883 #define NS_DOM_KEYNAME_SHIFT "Shift"
884 #define NS_DOM_KEYNAME_SYMBOLLOCK "SymbolLock"
885 #define NS_DOM_KEYNAME_OS "OS"
887 /******************************************************************************
888 * mozilla::Modifiers
889 ******************************************************************************/
891 typedef uint16_t Modifiers;
893 /******************************************************************************
894 * mozilla::WidgetInputEvent
895 ******************************************************************************/
897 class WidgetInputEvent : public WidgetGUIEvent
899 protected:
900 WidgetInputEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget,
901 nsEventStructType aStructType) :
902 WidgetGUIEvent(aIsTrusted, aMessage, aWidget, aStructType),
903 modifiers(0)
907 WidgetInputEvent()
911 public:
912 virtual WidgetInputEvent* AsInputEvent() MOZ_OVERRIDE { return this; }
914 WidgetInputEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
915 WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_INPUT_EVENT),
916 modifiers(0)
920 // true indicates the shift key is down
921 bool IsShift() const
923 return ((modifiers & MODIFIER_SHIFT) != 0);
925 // true indicates the control key is down
926 bool IsControl() const
928 return ((modifiers & MODIFIER_CONTROL) != 0);
930 // true indicates the alt key is down
931 bool IsAlt() const
933 return ((modifiers & MODIFIER_ALT) != 0);
935 // true indicates the meta key is down (or, on Mac, the Command key)
936 bool IsMeta() const
938 return ((modifiers & MODIFIER_META) != 0);
940 // true indicates the win key is down on Windows. Or the Super or Hyper key
941 // is down on Linux.
942 bool IsOS() const
944 return ((modifiers & MODIFIER_OS) != 0);
946 // true indicates the alt graph key is down
947 // NOTE: on Mac, the option key press causes both IsAlt() and IsAltGrpah()
948 // return true.
949 bool IsAltGraph() const
951 return ((modifiers & MODIFIER_ALTGRAPH) != 0);
953 // true indeicates the CapLock LED is turn on.
954 bool IsCapsLocked() const
956 return ((modifiers & MODIFIER_CAPSLOCK) != 0);
958 // true indeicates the NumLock LED is turn on.
959 bool IsNumLocked() const
961 return ((modifiers & MODIFIER_NUMLOCK) != 0);
963 // true indeicates the ScrollLock LED is turn on.
964 bool IsScrollLocked() const
966 return ((modifiers & MODIFIER_SCROLLLOCK) != 0);
969 // true indeicates the Fn key is down, but this is not supported by native
970 // key event on any platform.
971 bool IsFn() const
973 return ((modifiers & MODIFIER_FN) != 0);
975 // true indeicates the ScrollLock LED is turn on.
976 bool IsSymbolLocked() const
978 return ((modifiers & MODIFIER_SYMBOLLOCK) != 0);
981 void InitBasicModifiers(bool aCtrlKey,
982 bool aAltKey,
983 bool aShiftKey,
984 bool aMetaKey)
986 modifiers = 0;
987 if (aCtrlKey) {
988 modifiers |= MODIFIER_CONTROL;
990 if (aAltKey) {
991 modifiers |= MODIFIER_ALT;
993 if (aShiftKey) {
994 modifiers |= MODIFIER_SHIFT;
996 if (aMetaKey) {
997 modifiers |= MODIFIER_META;
1001 Modifiers modifiers;
1003 void AssignInputEventData(const WidgetInputEvent& aEvent, bool aCopyTargets)
1005 AssignGUIEventData(aEvent, aCopyTargets);
1007 modifiers = aEvent.modifiers;
1011 /******************************************************************************
1012 * mozilla::InternalUIEvent
1014 * XXX Why this inherits WidgetGUIEvent rather than WidgetEvent?
1015 ******************************************************************************/
1017 class InternalUIEvent : public WidgetGUIEvent
1019 protected:
1020 InternalUIEvent(bool aIsTrusted, uint32_t aMessage,
1021 nsEventStructType aStructType, int32_t aDetail) :
1022 WidgetGUIEvent(aIsTrusted, aMessage, nullptr, aStructType),
1023 detail(aDetail)
1027 public:
1028 virtual InternalUIEvent* AsUIEvent() MOZ_OVERRIDE { return this; }
1030 InternalUIEvent(bool aIsTrusted, uint32_t aMessage, int32_t aDetail) :
1031 WidgetGUIEvent(aIsTrusted, aMessage, nullptr, NS_UI_EVENT),
1032 detail(aDetail)
1036 int32_t detail;
1038 void AssignUIEventData(const InternalUIEvent& aEvent, bool aCopyTargets)
1040 AssignGUIEventData(aEvent, aCopyTargets);
1042 // detail must have been initialized with the constructor.
1046 } // namespace mozilla
1048 #endif // mozilla_BasicEvents_h__