|
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/. */ |
|
5 |
|
6 #ifndef mozilla_BasicEvents_h__ |
|
7 #define mozilla_BasicEvents_h__ |
|
8 |
|
9 #include <stdint.h> |
|
10 |
|
11 #include "mozilla/dom/EventTarget.h" |
|
12 #include "nsCOMPtr.h" |
|
13 #include "nsIAtom.h" |
|
14 #include "nsISupportsImpl.h" |
|
15 #include "nsIWidget.h" |
|
16 #include "nsString.h" |
|
17 #include "Units.h" |
|
18 |
|
19 /****************************************************************************** |
|
20 * Event Struct Types |
|
21 * |
|
22 * TODO: Move it into mozilla namespace. |
|
23 ******************************************************************************/ |
|
24 enum nsEventStructType |
|
25 { |
|
26 // BasicEvents.h |
|
27 NS_EVENT, // WidgetEvent |
|
28 NS_GUI_EVENT, // WidgetGUIEvent |
|
29 NS_INPUT_EVENT, // WidgetInputEvent |
|
30 NS_UI_EVENT, // InternalUIEvent |
|
31 |
|
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 |
|
38 NS_EDITOR_INPUT_EVENT, // InternalEditorInputEvent |
|
39 |
|
40 // MouseEvents.h |
|
41 NS_MOUSE_EVENT, // WidgetMouseEvent |
|
42 NS_DRAG_EVENT, // WidgetDragEvent |
|
43 NS_MOUSE_SCROLL_EVENT, // WidgetMouseScrollEvent |
|
44 NS_WHEEL_EVENT, // WidgetWheelEvent |
|
45 NS_POINTER_EVENT, // PointerEvent |
|
46 |
|
47 // TouchEvents.h |
|
48 NS_GESTURENOTIFY_EVENT, // WidgetGestureNotifyEvent |
|
49 NS_SIMPLE_GESTURE_EVENT, // WidgetSimpleGestureEvent |
|
50 NS_TOUCH_EVENT, // WidgetTouchEvent |
|
51 |
|
52 // ContentEvents.h |
|
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 |
|
60 |
|
61 // MiscEvents.h |
|
62 NS_COMMAND_EVENT, // WidgetCommandEvent |
|
63 NS_CONTENT_COMMAND_EVENT, // WidgetContentCommandEvent |
|
64 NS_PLUGIN_EVENT, // WidgetPluginEvent |
|
65 |
|
66 // InternalMutationEvent.h (dom/events) |
|
67 NS_MUTATION_EVENT, // InternalMutationEvent |
|
68 |
|
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 |
|
74 }; |
|
75 |
|
76 /****************************************************************************** |
|
77 * Messages |
|
78 * |
|
79 * TODO: Make them enum. |
|
80 ******************************************************************************/ |
|
81 |
|
82 #define NS_EVENT_NULL 0 |
|
83 |
|
84 // This is a dummy event message for all event listener implementation in |
|
85 // EventListenerManager. |
|
86 #define NS_EVENT_ALL 1 |
|
87 |
|
88 #define NS_WINDOW_START 100 |
|
89 |
|
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) |
|
98 |
|
99 #define NS_RESIZE_EVENT (NS_WINDOW_START + 60) |
|
100 #define NS_SCROLL_EVENT (NS_WINDOW_START + 61) |
|
101 |
|
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) |
|
108 |
|
109 #define NS_OFFLINE (NS_WINDOW_START + 64) |
|
110 #define NS_ONLINE (NS_WINDOW_START + 65) |
|
111 |
|
112 // NS_BEFORERESIZE_EVENT used to be here (NS_WINDOW_START + 66) |
|
113 |
|
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) |
|
117 |
|
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) |
|
122 |
|
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) |
|
137 |
|
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) |
|
150 |
|
151 #define NS_CONTEXTMENU_MESSAGE_START 500 |
|
152 #define NS_CONTEXTMENU (NS_CONTEXTMENU_MESSAGE_START) |
|
153 |
|
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) |
|
164 |
|
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_INVALID (NS_FORM_EVENT_START + 4) |
|
171 |
|
172 //Need separate focus/blur notifications for non-native widgets |
|
173 #define NS_FOCUS_EVENT_START 1300 |
|
174 #define NS_FOCUS_CONTENT (NS_FOCUS_EVENT_START) |
|
175 #define NS_BLUR_CONTENT (NS_FOCUS_EVENT_START + 1) |
|
176 |
|
177 #define NS_DRAGDROP_EVENT_START 1400 |
|
178 #define NS_DRAGDROP_ENTER (NS_DRAGDROP_EVENT_START) |
|
179 #define NS_DRAGDROP_OVER (NS_DRAGDROP_EVENT_START + 1) |
|
180 #define NS_DRAGDROP_EXIT (NS_DRAGDROP_EVENT_START + 2) |
|
181 #define NS_DRAGDROP_DRAGDROP (NS_DRAGDROP_EVENT_START + 3) |
|
182 #define NS_DRAGDROP_GESTURE (NS_DRAGDROP_EVENT_START + 4) |
|
183 #define NS_DRAGDROP_DRAG (NS_DRAGDROP_EVENT_START + 5) |
|
184 #define NS_DRAGDROP_END (NS_DRAGDROP_EVENT_START + 6) |
|
185 #define NS_DRAGDROP_START (NS_DRAGDROP_EVENT_START + 7) |
|
186 #define NS_DRAGDROP_DROP (NS_DRAGDROP_EVENT_START + 8) |
|
187 #define NS_DRAGDROP_OVER_SYNTH (NS_DRAGDROP_EVENT_START + 1) |
|
188 #define NS_DRAGDROP_EXIT_SYNTH (NS_DRAGDROP_EVENT_START + 2) |
|
189 #define NS_DRAGDROP_LEAVE_SYNTH (NS_DRAGDROP_EVENT_START + 9) |
|
190 |
|
191 // Events for popups |
|
192 #define NS_XUL_EVENT_START 1500 |
|
193 #define NS_XUL_POPUP_SHOWING (NS_XUL_EVENT_START) |
|
194 #define NS_XUL_POPUP_SHOWN (NS_XUL_EVENT_START+1) |
|
195 #define NS_XUL_POPUP_HIDING (NS_XUL_EVENT_START+2) |
|
196 #define NS_XUL_POPUP_HIDDEN (NS_XUL_EVENT_START+3) |
|
197 // NS_XUL_COMMAND used to be here (NS_XUL_EVENT_START+4) |
|
198 #define NS_XUL_BROADCAST (NS_XUL_EVENT_START+5) |
|
199 #define NS_XUL_COMMAND_UPDATE (NS_XUL_EVENT_START+6) |
|
200 //@} |
|
201 |
|
202 // Scroll events |
|
203 #define NS_MOUSE_SCROLL_START 1600 |
|
204 #define NS_MOUSE_SCROLL (NS_MOUSE_SCROLL_START) |
|
205 #define NS_MOUSE_PIXEL_SCROLL (NS_MOUSE_SCROLL_START + 1) |
|
206 |
|
207 #define NS_SCROLLPORT_START 1700 |
|
208 #define NS_SCROLLPORT_UNDERFLOW (NS_SCROLLPORT_START) |
|
209 #define NS_SCROLLPORT_OVERFLOW (NS_SCROLLPORT_START+1) |
|
210 |
|
211 #define NS_MUTATION_START 1800 |
|
212 #define NS_MUTATION_SUBTREEMODIFIED (NS_MUTATION_START) |
|
213 #define NS_MUTATION_NODEINSERTED (NS_MUTATION_START+1) |
|
214 #define NS_MUTATION_NODEREMOVED (NS_MUTATION_START+2) |
|
215 #define NS_MUTATION_NODEREMOVEDFROMDOCUMENT (NS_MUTATION_START+3) |
|
216 #define NS_MUTATION_NODEINSERTEDINTODOCUMENT (NS_MUTATION_START+4) |
|
217 #define NS_MUTATION_ATTRMODIFIED (NS_MUTATION_START+5) |
|
218 #define NS_MUTATION_CHARACTERDATAMODIFIED (NS_MUTATION_START+6) |
|
219 #define NS_MUTATION_END (NS_MUTATION_START+6) |
|
220 |
|
221 #define NS_USER_DEFINED_EVENT 2000 |
|
222 |
|
223 // composition events |
|
224 #define NS_COMPOSITION_EVENT_START 2200 |
|
225 #define NS_COMPOSITION_START (NS_COMPOSITION_EVENT_START) |
|
226 #define NS_COMPOSITION_END (NS_COMPOSITION_EVENT_START + 1) |
|
227 #define NS_COMPOSITION_UPDATE (NS_COMPOSITION_EVENT_START + 2) |
|
228 |
|
229 // text events |
|
230 #define NS_TEXT_START 2400 |
|
231 #define NS_TEXT_TEXT (NS_TEXT_START) |
|
232 |
|
233 // UI events |
|
234 #define NS_UI_EVENT_START 2500 |
|
235 // this is not to be confused with NS_ACTIVATE! |
|
236 #define NS_UI_ACTIVATE (NS_UI_EVENT_START) |
|
237 #define NS_UI_FOCUSIN (NS_UI_EVENT_START + 1) |
|
238 #define NS_UI_FOCUSOUT (NS_UI_EVENT_START + 2) |
|
239 |
|
240 // pagetransition events |
|
241 #define NS_PAGETRANSITION_START 2700 |
|
242 #define NS_PAGE_SHOW (NS_PAGETRANSITION_START + 1) |
|
243 #define NS_PAGE_HIDE (NS_PAGETRANSITION_START + 2) |
|
244 |
|
245 // SVG events |
|
246 #define NS_SVG_EVENT_START 2800 |
|
247 #define NS_SVG_LOAD (NS_SVG_EVENT_START) |
|
248 #define NS_SVG_UNLOAD (NS_SVG_EVENT_START + 1) |
|
249 #define NS_SVG_ABORT (NS_SVG_EVENT_START + 2) |
|
250 #define NS_SVG_ERROR (NS_SVG_EVENT_START + 3) |
|
251 #define NS_SVG_RESIZE (NS_SVG_EVENT_START + 4) |
|
252 #define NS_SVG_SCROLL (NS_SVG_EVENT_START + 5) |
|
253 |
|
254 // SVG Zoom events |
|
255 #define NS_SVGZOOM_EVENT_START 2900 |
|
256 #define NS_SVG_ZOOM (NS_SVGZOOM_EVENT_START) |
|
257 |
|
258 // XUL command events |
|
259 #define NS_XULCOMMAND_EVENT_START 3000 |
|
260 #define NS_XUL_COMMAND (NS_XULCOMMAND_EVENT_START) |
|
261 |
|
262 // Cut, copy, paste events |
|
263 #define NS_CUTCOPYPASTE_EVENT_START 3100 |
|
264 #define NS_COPY (NS_CUTCOPYPASTE_EVENT_START) |
|
265 #define NS_CUT (NS_CUTCOPYPASTE_EVENT_START + 1) |
|
266 #define NS_PASTE (NS_CUTCOPYPASTE_EVENT_START + 2) |
|
267 |
|
268 // Query the content information |
|
269 #define NS_QUERY_CONTENT_EVENT_START 3200 |
|
270 // Query for the selected text information, it return the selection offset, |
|
271 // selection length and selected text. |
|
272 #define NS_QUERY_SELECTED_TEXT (NS_QUERY_CONTENT_EVENT_START) |
|
273 // Query for the text content of specified range, it returns actual lengh (if |
|
274 // the specified range is too long) and the text of the specified range. |
|
275 // Returns the entire text if requested length > actual length. |
|
276 #define NS_QUERY_TEXT_CONTENT (NS_QUERY_CONTENT_EVENT_START + 1) |
|
277 // Query for the caret rect of nth insertion point. The offset of the result is |
|
278 // relative position from the top level widget. |
|
279 #define NS_QUERY_CARET_RECT (NS_QUERY_CONTENT_EVENT_START + 3) |
|
280 // Query for the bounding rect of a range of characters. This works on any |
|
281 // valid character range given offset and length. Result is relative to top |
|
282 // level widget coordinates |
|
283 #define NS_QUERY_TEXT_RECT (NS_QUERY_CONTENT_EVENT_START + 4) |
|
284 // Query for the bounding rect of the current focused frame. Result is relative |
|
285 // to top level widget coordinates |
|
286 #define NS_QUERY_EDITOR_RECT (NS_QUERY_CONTENT_EVENT_START + 5) |
|
287 // Query for the current state of the content. The particular members of |
|
288 // mReply that are set for each query content event will be valid on success. |
|
289 #define NS_QUERY_CONTENT_STATE (NS_QUERY_CONTENT_EVENT_START + 6) |
|
290 // Query for the selection in the form of a nsITransferable. |
|
291 #define NS_QUERY_SELECTION_AS_TRANSFERABLE (NS_QUERY_CONTENT_EVENT_START + 7) |
|
292 // Query for character at a point. This returns the character offset and its |
|
293 // rect. The point is specified by Event::refPoint. |
|
294 #define NS_QUERY_CHARACTER_AT_POINT (NS_QUERY_CONTENT_EVENT_START + 8) |
|
295 // Query if the DOM element under Event::refPoint belongs to our widget |
|
296 // or not. |
|
297 #define NS_QUERY_DOM_WIDGET_HITTEST (NS_QUERY_CONTENT_EVENT_START + 9) |
|
298 |
|
299 // Video events |
|
300 #define NS_MEDIA_EVENT_START 3300 |
|
301 #define NS_LOADSTART (NS_MEDIA_EVENT_START) |
|
302 #define NS_PROGRESS (NS_MEDIA_EVENT_START+1) |
|
303 #define NS_SUSPEND (NS_MEDIA_EVENT_START+2) |
|
304 #define NS_EMPTIED (NS_MEDIA_EVENT_START+3) |
|
305 #define NS_STALLED (NS_MEDIA_EVENT_START+4) |
|
306 #define NS_PLAY (NS_MEDIA_EVENT_START+5) |
|
307 #define NS_PAUSE (NS_MEDIA_EVENT_START+6) |
|
308 #define NS_LOADEDMETADATA (NS_MEDIA_EVENT_START+7) |
|
309 #define NS_LOADEDDATA (NS_MEDIA_EVENT_START+8) |
|
310 #define NS_WAITING (NS_MEDIA_EVENT_START+9) |
|
311 #define NS_PLAYING (NS_MEDIA_EVENT_START+10) |
|
312 #define NS_CANPLAY (NS_MEDIA_EVENT_START+11) |
|
313 #define NS_CANPLAYTHROUGH (NS_MEDIA_EVENT_START+12) |
|
314 #define NS_SEEKING (NS_MEDIA_EVENT_START+13) |
|
315 #define NS_SEEKED (NS_MEDIA_EVENT_START+14) |
|
316 #define NS_TIMEUPDATE (NS_MEDIA_EVENT_START+15) |
|
317 #define NS_ENDED (NS_MEDIA_EVENT_START+16) |
|
318 #define NS_RATECHANGE (NS_MEDIA_EVENT_START+17) |
|
319 #define NS_DURATIONCHANGE (NS_MEDIA_EVENT_START+18) |
|
320 #define NS_VOLUMECHANGE (NS_MEDIA_EVENT_START+19) |
|
321 |
|
322 // paint notification events |
|
323 #define NS_NOTIFYPAINT_START 3400 |
|
324 #define NS_AFTERPAINT (NS_NOTIFYPAINT_START) |
|
325 |
|
326 // Simple gesture events |
|
327 #define NS_SIMPLE_GESTURE_EVENT_START 3500 |
|
328 #define NS_SIMPLE_GESTURE_SWIPE_START (NS_SIMPLE_GESTURE_EVENT_START) |
|
329 #define NS_SIMPLE_GESTURE_SWIPE_UPDATE (NS_SIMPLE_GESTURE_EVENT_START+1) |
|
330 #define NS_SIMPLE_GESTURE_SWIPE_END (NS_SIMPLE_GESTURE_EVENT_START+2) |
|
331 #define NS_SIMPLE_GESTURE_SWIPE (NS_SIMPLE_GESTURE_EVENT_START+3) |
|
332 #define NS_SIMPLE_GESTURE_MAGNIFY_START (NS_SIMPLE_GESTURE_EVENT_START+4) |
|
333 #define NS_SIMPLE_GESTURE_MAGNIFY_UPDATE (NS_SIMPLE_GESTURE_EVENT_START+5) |
|
334 #define NS_SIMPLE_GESTURE_MAGNIFY (NS_SIMPLE_GESTURE_EVENT_START+6) |
|
335 #define NS_SIMPLE_GESTURE_ROTATE_START (NS_SIMPLE_GESTURE_EVENT_START+7) |
|
336 #define NS_SIMPLE_GESTURE_ROTATE_UPDATE (NS_SIMPLE_GESTURE_EVENT_START+8) |
|
337 #define NS_SIMPLE_GESTURE_ROTATE (NS_SIMPLE_GESTURE_EVENT_START+9) |
|
338 #define NS_SIMPLE_GESTURE_TAP (NS_SIMPLE_GESTURE_EVENT_START+10) |
|
339 #define NS_SIMPLE_GESTURE_PRESSTAP (NS_SIMPLE_GESTURE_EVENT_START+11) |
|
340 #define NS_SIMPLE_GESTURE_EDGE_STARTED (NS_SIMPLE_GESTURE_EVENT_START+12) |
|
341 #define NS_SIMPLE_GESTURE_EDGE_CANCELED (NS_SIMPLE_GESTURE_EVENT_START+13) |
|
342 #define NS_SIMPLE_GESTURE_EDGE_COMPLETED (NS_SIMPLE_GESTURE_EVENT_START+14) |
|
343 |
|
344 // These are used to send native events to plugins. |
|
345 #define NS_PLUGIN_EVENT_START 3600 |
|
346 #define NS_PLUGIN_INPUT_EVENT (NS_PLUGIN_EVENT_START) |
|
347 #define NS_PLUGIN_FOCUS_EVENT (NS_PLUGIN_EVENT_START+1) |
|
348 |
|
349 // Events to manipulate selection (WidgetSelectionEvent) |
|
350 #define NS_SELECTION_EVENT_START 3700 |
|
351 // Clear any previous selection and set the given range as the selection |
|
352 #define NS_SELECTION_SET (NS_SELECTION_EVENT_START) |
|
353 |
|
354 // Events of commands for the contents |
|
355 #define NS_CONTENT_COMMAND_EVENT_START 3800 |
|
356 #define NS_CONTENT_COMMAND_CUT (NS_CONTENT_COMMAND_EVENT_START) |
|
357 #define NS_CONTENT_COMMAND_COPY (NS_CONTENT_COMMAND_EVENT_START+1) |
|
358 #define NS_CONTENT_COMMAND_PASTE (NS_CONTENT_COMMAND_EVENT_START+2) |
|
359 #define NS_CONTENT_COMMAND_DELETE (NS_CONTENT_COMMAND_EVENT_START+3) |
|
360 #define NS_CONTENT_COMMAND_UNDO (NS_CONTENT_COMMAND_EVENT_START+4) |
|
361 #define NS_CONTENT_COMMAND_REDO (NS_CONTENT_COMMAND_EVENT_START+5) |
|
362 #define NS_CONTENT_COMMAND_PASTE_TRANSFERABLE (NS_CONTENT_COMMAND_EVENT_START+6) |
|
363 // NS_CONTENT_COMMAND_SCROLL scrolls the nearest scrollable element to the |
|
364 // currently focused content or latest DOM selection. This would normally be |
|
365 // the same element scrolled by keyboard scroll commands, except that this event |
|
366 // will scroll an element scrollable in either direction. I.e., if the nearest |
|
367 // scrollable ancestor element can only be scrolled vertically, and horizontal |
|
368 // scrolling is requested using this event, no scrolling will occur. |
|
369 #define NS_CONTENT_COMMAND_SCROLL (NS_CONTENT_COMMAND_EVENT_START+7) |
|
370 |
|
371 // Event to gesture notification |
|
372 #define NS_GESTURENOTIFY_EVENT_START 3900 |
|
373 |
|
374 #define NS_ORIENTATION_EVENT 4000 |
|
375 |
|
376 #define NS_SCROLLAREA_EVENT_START 4100 |
|
377 #define NS_SCROLLEDAREACHANGED (NS_SCROLLAREA_EVENT_START) |
|
378 |
|
379 #define NS_TRANSITION_EVENT_START 4200 |
|
380 #define NS_TRANSITION_END (NS_TRANSITION_EVENT_START) |
|
381 |
|
382 #define NS_ANIMATION_EVENT_START 4250 |
|
383 #define NS_ANIMATION_START (NS_ANIMATION_EVENT_START) |
|
384 #define NS_ANIMATION_END (NS_ANIMATION_EVENT_START + 1) |
|
385 #define NS_ANIMATION_ITERATION (NS_ANIMATION_EVENT_START + 2) |
|
386 |
|
387 #define NS_SMIL_TIME_EVENT_START 4300 |
|
388 #define NS_SMIL_BEGIN (NS_SMIL_TIME_EVENT_START) |
|
389 #define NS_SMIL_END (NS_SMIL_TIME_EVENT_START + 1) |
|
390 #define NS_SMIL_REPEAT (NS_SMIL_TIME_EVENT_START + 2) |
|
391 |
|
392 #define NS_WEBAUDIO_EVENT_START 4350 |
|
393 #define NS_AUDIO_PROCESS (NS_WEBAUDIO_EVENT_START) |
|
394 #define NS_AUDIO_COMPLETE (NS_WEBAUDIO_EVENT_START + 1) |
|
395 |
|
396 // script notification events |
|
397 #define NS_NOTIFYSCRIPT_START 4500 |
|
398 #define NS_BEFORE_SCRIPT_EXECUTE (NS_NOTIFYSCRIPT_START) |
|
399 #define NS_AFTER_SCRIPT_EXECUTE (NS_NOTIFYSCRIPT_START+1) |
|
400 |
|
401 #define NS_PRINT_EVENT_START 4600 |
|
402 #define NS_BEFOREPRINT (NS_PRINT_EVENT_START) |
|
403 #define NS_AFTERPRINT (NS_PRINT_EVENT_START + 1) |
|
404 |
|
405 #define NS_MESSAGE_EVENT_START 4700 |
|
406 #define NS_MESSAGE (NS_MESSAGE_EVENT_START) |
|
407 |
|
408 // Open and close events |
|
409 #define NS_OPENCLOSE_EVENT_START 4800 |
|
410 #define NS_OPEN (NS_OPENCLOSE_EVENT_START) |
|
411 #define NS_CLOSE (NS_OPENCLOSE_EVENT_START+1) |
|
412 |
|
413 // Device motion and orientation |
|
414 #define NS_DEVICE_ORIENTATION_START 4900 |
|
415 #define NS_DEVICE_ORIENTATION (NS_DEVICE_ORIENTATION_START) |
|
416 #define NS_DEVICE_MOTION (NS_DEVICE_ORIENTATION_START+1) |
|
417 #define NS_DEVICE_PROXIMITY (NS_DEVICE_ORIENTATION_START+2) |
|
418 #define NS_USER_PROXIMITY (NS_DEVICE_ORIENTATION_START+3) |
|
419 #define NS_DEVICE_LIGHT (NS_DEVICE_ORIENTATION_START+4) |
|
420 |
|
421 #define NS_SHOW_EVENT 5000 |
|
422 |
|
423 // Fullscreen DOM API |
|
424 #define NS_FULL_SCREEN_START 5100 |
|
425 #define NS_FULLSCREENCHANGE (NS_FULL_SCREEN_START) |
|
426 #define NS_FULLSCREENERROR (NS_FULL_SCREEN_START + 1) |
|
427 |
|
428 #define NS_TOUCH_EVENT_START 5200 |
|
429 #define NS_TOUCH_START (NS_TOUCH_EVENT_START) |
|
430 #define NS_TOUCH_MOVE (NS_TOUCH_EVENT_START+1) |
|
431 #define NS_TOUCH_END (NS_TOUCH_EVENT_START+2) |
|
432 #define NS_TOUCH_ENTER (NS_TOUCH_EVENT_START+3) |
|
433 #define NS_TOUCH_LEAVE (NS_TOUCH_EVENT_START+4) |
|
434 #define NS_TOUCH_CANCEL (NS_TOUCH_EVENT_START+5) |
|
435 |
|
436 // Pointerlock DOM API |
|
437 #define NS_POINTERLOCK_START 5300 |
|
438 #define NS_POINTERLOCKCHANGE (NS_POINTERLOCK_START) |
|
439 #define NS_POINTERLOCKERROR (NS_POINTERLOCK_START + 1) |
|
440 |
|
441 #define NS_WHEEL_EVENT_START 5400 |
|
442 #define NS_WHEEL_WHEEL (NS_WHEEL_EVENT_START) |
|
443 #define NS_WHEEL_START (NS_WHEEL_EVENT_START + 1) |
|
444 #define NS_WHEEL_STOP (NS_WHEEL_EVENT_START + 2) |
|
445 |
|
446 //System time is changed |
|
447 #define NS_MOZ_TIME_CHANGE_EVENT 5500 |
|
448 |
|
449 // Network packet events. |
|
450 #define NS_NETWORK_EVENT_START 5600 |
|
451 #define NS_NETWORK_UPLOAD_EVENT (NS_NETWORK_EVENT_START + 1) |
|
452 #define NS_NETWORK_DOWNLOAD_EVENT (NS_NETWORK_EVENT_START + 2) |
|
453 |
|
454 // MediaRecorder events. |
|
455 #define NS_MEDIARECORDER_EVENT_START 5700 |
|
456 #define NS_MEDIARECORDER_DATAAVAILABLE (NS_MEDIARECORDER_EVENT_START + 1) |
|
457 #define NS_MEDIARECORDER_WARNING (NS_MEDIARECORDER_EVENT_START + 2) |
|
458 #define NS_MEDIARECORDER_STOP (NS_MEDIARECORDER_EVENT_START + 3) |
|
459 |
|
460 // SpeakerManager events |
|
461 #define NS_SPEAKERMANAGER_EVENT_START 5800 |
|
462 #define NS_SPEAKERMANAGER_SPEAKERFORCEDCHANGE (NS_SPEAKERMANAGER_EVENT_START + 1) |
|
463 |
|
464 #ifdef MOZ_GAMEPAD |
|
465 // Gamepad input events |
|
466 #define NS_GAMEPAD_START 6000 |
|
467 #define NS_GAMEPAD_BUTTONDOWN (NS_GAMEPAD_START) |
|
468 #define NS_GAMEPAD_BUTTONUP (NS_GAMEPAD_START+1) |
|
469 #define NS_GAMEPAD_AXISMOVE (NS_GAMEPAD_START+2) |
|
470 #define NS_GAMEPAD_CONNECTED (NS_GAMEPAD_START+3) |
|
471 #define NS_GAMEPAD_DISCONNECTED (NS_GAMEPAD_START+4) |
|
472 // Keep this defined to the same value as the event above |
|
473 #define NS_GAMEPAD_END (NS_GAMEPAD_START+4) |
|
474 #endif |
|
475 |
|
476 // input and beforeinput events. |
|
477 #define NS_EDITOR_EVENT_START 6100 |
|
478 #define NS_EDITOR_INPUT (NS_EDITOR_EVENT_START) |
|
479 |
|
480 namespace mozilla { |
|
481 |
|
482 /****************************************************************************** |
|
483 * mozilla::BaseEventFlags |
|
484 * |
|
485 * BaseEventFlags must be a POD struct for safe to use memcpy (including |
|
486 * in ParamTraits<BaseEventFlags>). So don't make virtual methods, constructor, |
|
487 * destructor and operators. |
|
488 * This is necessary for VC which is NOT C++0x compiler. |
|
489 ******************************************************************************/ |
|
490 |
|
491 struct BaseEventFlags |
|
492 { |
|
493 public: |
|
494 // If mIsTrusted is true, the event is a trusted event. Otherwise, it's |
|
495 // an untrusted event. |
|
496 bool mIsTrusted : 1; |
|
497 // If mInBubblingPhase is true, the event is in bubbling phase or target |
|
498 // phase. |
|
499 bool mInBubblingPhase : 1; |
|
500 // If mInCapturePhase is true, the event is in capture phase or target phase. |
|
501 bool mInCapturePhase : 1; |
|
502 // If mInSystemGroup is true, the event is being dispatched in system group. |
|
503 bool mInSystemGroup: 1; |
|
504 // If mCancelable is true, the event can be consumed. I.e., calling |
|
505 // dom::Event::PreventDefault() can prevent the default action. |
|
506 bool mCancelable : 1; |
|
507 // If mBubbles is true, the event can bubble. Otherwise, cannot be handled |
|
508 // in bubbling phase. |
|
509 bool mBubbles : 1; |
|
510 // If mPropagationStopped is true, dom::Event::StopPropagation() or |
|
511 // dom::Event::StopImmediatePropagation() has been called. |
|
512 bool mPropagationStopped : 1; |
|
513 // If mImmediatePropagationStopped is true, |
|
514 // dom::Event::StopImmediatePropagation() has been called. |
|
515 // Note that mPropagationStopped must be true when this is true. |
|
516 bool mImmediatePropagationStopped : 1; |
|
517 // If mDefaultPrevented is true, the event has been consumed. |
|
518 // E.g., dom::Event::PreventDefault() has been called or |
|
519 // the default action has been performed. |
|
520 bool mDefaultPrevented : 1; |
|
521 // If mDefaultPreventedByContent is true, the event has been |
|
522 // consumed by content. |
|
523 // Note that mDefaultPrevented must be true when this is true. |
|
524 bool mDefaultPreventedByContent : 1; |
|
525 // mMultipleActionsPrevented may be used when default handling don't want to |
|
526 // be prevented, but only one of the event targets should handle the event. |
|
527 // For example, when a <label> element is in another <label> element and |
|
528 // the first <label> element is clicked, that one may set this true. |
|
529 // Then, the second <label> element won't handle the event. |
|
530 bool mMultipleActionsPrevented : 1; |
|
531 // If mIsBeingDispatched is true, the DOM event created from the event is |
|
532 // dispatching into the DOM tree and not completed. |
|
533 bool mIsBeingDispatched : 1; |
|
534 // If mDispatchedAtLeastOnce is true, the event has been dispatched |
|
535 // as a DOM event and the dispatch has been completed. |
|
536 bool mDispatchedAtLeastOnce : 1; |
|
537 // If mIsSynthesizedForTests is true, the event has been synthesized for |
|
538 // automated tests or something hacky approach of an add-on. |
|
539 bool mIsSynthesizedForTests : 1; |
|
540 // If mExceptionHasBeenRisen is true, one of the event handlers has risen an |
|
541 // exception. |
|
542 bool mExceptionHasBeenRisen : 1; |
|
543 // If mRetargetToNonNativeAnonymous is true and the target is in a non-native |
|
544 // native anonymous subtree, the event target is set to originalTarget. |
|
545 bool mRetargetToNonNativeAnonymous : 1; |
|
546 // If mNoCrossProcessBoundaryForwarding is true, the event is not allowed to |
|
547 // cross process boundary. |
|
548 bool mNoCrossProcessBoundaryForwarding : 1; |
|
549 // If mNoContentDispatch is true, the event is never dispatched to the |
|
550 // event handlers which are added to the contents, onfoo attributes and |
|
551 // properties. Note that this flag is ignored when |
|
552 // EventChainPreVisitor::mForceContentDispatch is set true. For exapmle, |
|
553 // window and document object sets it true. Therefore, web applications |
|
554 // can handle the event if they add event listeners to the window or the |
|
555 // document. |
|
556 bool mNoContentDispatch : 1; |
|
557 // If mOnlyChromeDispatch is true, the event is dispatched to only chrome. |
|
558 bool mOnlyChromeDispatch : 1; |
|
559 // If mWantReplyFromContentProcess is true, the event will be redispatched |
|
560 // in the parent process after the content process has handled it. Useful |
|
561 // for when the parent process need the know first how the event was used |
|
562 // by content before handling it itself. |
|
563 bool mWantReplyFromContentProcess : 1; |
|
564 |
|
565 // If the event is being handled in target phase, returns true. |
|
566 inline bool InTargetPhase() const |
|
567 { |
|
568 return (mInBubblingPhase && mInCapturePhase); |
|
569 } |
|
570 |
|
571 inline void Clear() |
|
572 { |
|
573 SetRawFlags(0); |
|
574 } |
|
575 // Get if either the instance's bit or the aOther's bit is true, the |
|
576 // instance's bit becomes true. In other words, this works like: |
|
577 // eventFlags |= aOther; |
|
578 inline void Union(const BaseEventFlags& aOther) |
|
579 { |
|
580 RawFlags rawFlags = GetRawFlags() | aOther.GetRawFlags(); |
|
581 SetRawFlags(rawFlags); |
|
582 } |
|
583 |
|
584 private: |
|
585 typedef uint32_t RawFlags; |
|
586 |
|
587 inline void SetRawFlags(RawFlags aRawFlags) |
|
588 { |
|
589 static_assert(sizeof(BaseEventFlags) <= sizeof(RawFlags), |
|
590 "mozilla::EventFlags must not be bigger than the RawFlags"); |
|
591 memcpy(this, &aRawFlags, sizeof(BaseEventFlags)); |
|
592 } |
|
593 inline RawFlags GetRawFlags() const |
|
594 { |
|
595 RawFlags result = 0; |
|
596 memcpy(&result, this, sizeof(BaseEventFlags)); |
|
597 return result; |
|
598 } |
|
599 }; |
|
600 |
|
601 /****************************************************************************** |
|
602 * mozilla::EventFlags |
|
603 ******************************************************************************/ |
|
604 |
|
605 struct EventFlags : public BaseEventFlags |
|
606 { |
|
607 EventFlags() |
|
608 { |
|
609 Clear(); |
|
610 } |
|
611 }; |
|
612 |
|
613 /****************************************************************************** |
|
614 * mozilla::WidgetEvent |
|
615 ******************************************************************************/ |
|
616 |
|
617 class WidgetEvent |
|
618 { |
|
619 protected: |
|
620 WidgetEvent(bool aIsTrusted, uint32_t aMessage, |
|
621 nsEventStructType aStructType) : |
|
622 eventStructType(aStructType), message(aMessage), refPoint(0, 0), |
|
623 lastRefPoint(0, 0), time(0), userType(0) |
|
624 { |
|
625 MOZ_COUNT_CTOR(WidgetEvent); |
|
626 mFlags.Clear(); |
|
627 mFlags.mIsTrusted = aIsTrusted; |
|
628 mFlags.mCancelable = true; |
|
629 mFlags.mBubbles = true; |
|
630 } |
|
631 |
|
632 WidgetEvent() |
|
633 { |
|
634 MOZ_COUNT_CTOR(WidgetEvent); |
|
635 } |
|
636 |
|
637 public: |
|
638 WidgetEvent(bool aIsTrusted, uint32_t aMessage) : |
|
639 eventStructType(NS_EVENT), message(aMessage), refPoint(0, 0), |
|
640 lastRefPoint(0, 0), time(0), userType(0) |
|
641 { |
|
642 MOZ_COUNT_CTOR(WidgetEvent); |
|
643 mFlags.Clear(); |
|
644 mFlags.mIsTrusted = aIsTrusted; |
|
645 mFlags.mCancelable = true; |
|
646 mFlags.mBubbles = true; |
|
647 } |
|
648 |
|
649 virtual ~WidgetEvent() |
|
650 { |
|
651 MOZ_COUNT_DTOR(WidgetEvent); |
|
652 } |
|
653 |
|
654 WidgetEvent(const WidgetEvent& aOther) |
|
655 { |
|
656 MOZ_COUNT_CTOR(WidgetEvent); |
|
657 *this = aOther; |
|
658 } |
|
659 |
|
660 virtual WidgetEvent* Duplicate() const |
|
661 { |
|
662 MOZ_ASSERT(eventStructType == NS_EVENT, |
|
663 "Duplicate() must be overridden by sub class"); |
|
664 WidgetEvent* result = new WidgetEvent(false, message); |
|
665 result->AssignEventData(*this, true); |
|
666 result->mFlags = mFlags; |
|
667 return result; |
|
668 } |
|
669 |
|
670 // See event struct types |
|
671 nsEventStructType eventStructType; |
|
672 // See GUI MESSAGES, |
|
673 uint32_t message; |
|
674 // Relative to the widget of the event, or if there is no widget then it is |
|
675 // in screen coordinates. Not modified by layout code. |
|
676 LayoutDeviceIntPoint refPoint; |
|
677 // The previous refPoint, if known, used to calculate mouse movement deltas. |
|
678 LayoutDeviceIntPoint lastRefPoint; |
|
679 // Elapsed time, in milliseconds, from a platform-specific zero time |
|
680 // to the time the message was created |
|
681 uint64_t time; |
|
682 // See BaseEventFlags definition for the detail. |
|
683 BaseEventFlags mFlags; |
|
684 |
|
685 // Additional type info for user defined events |
|
686 nsCOMPtr<nsIAtom> userType; |
|
687 |
|
688 nsString typeString; // always set on non-main-thread events |
|
689 |
|
690 // Event targets, needed by DOM Events |
|
691 nsCOMPtr<dom::EventTarget> target; |
|
692 nsCOMPtr<dom::EventTarget> currentTarget; |
|
693 nsCOMPtr<dom::EventTarget> originalTarget; |
|
694 |
|
695 void AssignEventData(const WidgetEvent& aEvent, bool aCopyTargets) |
|
696 { |
|
697 // eventStructType should be initialized with the constructor. |
|
698 // However, NS_SVGZOOM_EVENT and NS_SMIL_TIME_EVENT are set after that. |
|
699 // Therefore, we need to copy eventStructType here. |
|
700 eventStructType = aEvent.eventStructType; |
|
701 // message should be initialized with the constructor. |
|
702 refPoint = aEvent.refPoint; |
|
703 // lastRefPoint doesn't need to be copied. |
|
704 time = aEvent.time; |
|
705 // mFlags should be copied manually if it's necessary. |
|
706 userType = aEvent.userType; |
|
707 // typeString should be copied manually if it's necessary. |
|
708 target = aCopyTargets ? aEvent.target : nullptr; |
|
709 currentTarget = aCopyTargets ? aEvent.currentTarget : nullptr; |
|
710 originalTarget = aCopyTargets ? aEvent.originalTarget : nullptr; |
|
711 } |
|
712 |
|
713 /** |
|
714 * Utils for checking event types |
|
715 */ |
|
716 |
|
717 /** |
|
718 * As*Event() returns the pointer of the instance only when the instance is |
|
719 * the class or one of its derived class. |
|
720 */ |
|
721 #define NS_ROOT_EVENT_CLASS(aPrefix, aName) |
|
722 #define NS_EVENT_CLASS(aPrefix, aName) \ |
|
723 virtual aPrefix##aName* As##aName(); \ |
|
724 const aPrefix##aName* As##aName() const; |
|
725 |
|
726 #include "mozilla/EventClassList.h" |
|
727 |
|
728 #undef NS_EVENT_CLASS |
|
729 #undef NS_ROOT_EVENT_CLASS |
|
730 |
|
731 /** |
|
732 * Returns true if the event is a query content event. |
|
733 */ |
|
734 bool IsQueryContentEvent() const; |
|
735 /** |
|
736 * Returns true if the event is a selection event. |
|
737 */ |
|
738 bool IsSelectionEvent() const; |
|
739 /** |
|
740 * Returns true if the event is a content command event. |
|
741 */ |
|
742 bool IsContentCommandEvent() const; |
|
743 /** |
|
744 * Returns true if the event is a native event deliverer event for plugin. |
|
745 */ |
|
746 bool IsNativeEventDelivererForPlugin() const; |
|
747 |
|
748 /** |
|
749 * Returns true if the event message is one of mouse events. |
|
750 */ |
|
751 bool HasMouseEventMessage() const; |
|
752 /** |
|
753 * Returns true if the event message is one of drag events. |
|
754 */ |
|
755 bool HasDragEventMessage() const; |
|
756 /** |
|
757 * Returns true if the event message is one of key events. |
|
758 */ |
|
759 bool HasKeyEventMessage() const; |
|
760 /** |
|
761 * Returns true if the event message is one of composition events or text |
|
762 * event. |
|
763 */ |
|
764 bool HasIMEEventMessage() const; |
|
765 /** |
|
766 * Returns true if the event message is one of plugin activation events. |
|
767 */ |
|
768 bool HasPluginActivationEventMessage() const; |
|
769 |
|
770 /** |
|
771 * Returns true if the event is native event deliverer event for plugin and |
|
772 * it should be retarted to focused document. |
|
773 */ |
|
774 bool IsRetargetedNativeEventDelivererForPlugin() const; |
|
775 /** |
|
776 * Returns true if the event is native event deliverer event for plugin and |
|
777 * it should NOT be retarted to focused document. |
|
778 */ |
|
779 bool IsNonRetargetedNativeEventDelivererForPlugin() const; |
|
780 /** |
|
781 * Returns true if the event is related to IME handling. It includes |
|
782 * IME events, query content events and selection events. |
|
783 * Be careful when you use this. |
|
784 */ |
|
785 bool IsIMERelatedEvent() const; |
|
786 |
|
787 /** |
|
788 * Whether the event should be handled by the frame of the mouse cursor |
|
789 * position or not. When it should be handled there (e.g., the mouse events), |
|
790 * this returns true. |
|
791 */ |
|
792 bool IsUsingCoordinates() const; |
|
793 /** |
|
794 * Whether the event should be handled by the focused DOM window in the |
|
795 * same top level window's or not. E.g., key events, IME related events |
|
796 * (including the query content events, they are used in IME transaction) |
|
797 * should be handled by the (last) focused window rather than the dispatched |
|
798 * window. |
|
799 * |
|
800 * NOTE: Even if this returns true, the event isn't going to be handled by the |
|
801 * application level active DOM window which is on another top level window. |
|
802 * So, when the event is fired on a deactive window, the event is going to be |
|
803 * handled by the last focused DOM window in the last focused window. |
|
804 */ |
|
805 bool IsTargetedAtFocusedWindow() const; |
|
806 /** |
|
807 * Whether the event should be handled by the focused content or not. E.g., |
|
808 * key events, IME related events and other input events which are not handled |
|
809 * by the frame of the mouse cursor position. |
|
810 * |
|
811 * NOTE: Even if this returns true, the event isn't going to be handled by the |
|
812 * application level active DOM window which is on another top level window. |
|
813 * So, when the event is fired on a deactive window, the event is going to be |
|
814 * handled by the last focused DOM element of the last focused DOM window in |
|
815 * the last focused window. |
|
816 */ |
|
817 bool IsTargetedAtFocusedContent() const; |
|
818 /** |
|
819 * Whether the event should cause a DOM event. |
|
820 */ |
|
821 bool IsAllowedToDispatchDOMEvent() const; |
|
822 }; |
|
823 |
|
824 /****************************************************************************** |
|
825 * mozilla::WidgetGUIEvent |
|
826 ******************************************************************************/ |
|
827 |
|
828 class WidgetGUIEvent : public WidgetEvent |
|
829 { |
|
830 protected: |
|
831 WidgetGUIEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget, |
|
832 nsEventStructType aStructType) : |
|
833 WidgetEvent(aIsTrusted, aMessage, aStructType), |
|
834 widget(aWidget), pluginEvent(nullptr) |
|
835 { |
|
836 } |
|
837 |
|
838 WidgetGUIEvent() : |
|
839 pluginEvent(nullptr) |
|
840 { |
|
841 } |
|
842 |
|
843 public: |
|
844 virtual WidgetGUIEvent* AsGUIEvent() MOZ_OVERRIDE { return this; } |
|
845 |
|
846 WidgetGUIEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) : |
|
847 WidgetEvent(aIsTrusted, aMessage, NS_GUI_EVENT), |
|
848 widget(aWidget), pluginEvent(nullptr) |
|
849 { |
|
850 } |
|
851 |
|
852 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE |
|
853 { |
|
854 MOZ_ASSERT(eventStructType == NS_GUI_EVENT || |
|
855 eventStructType == NS_SVGZOOM_EVENT, |
|
856 "Duplicate() must be overridden by sub class"); |
|
857 // Not copying widget, it is a weak reference. |
|
858 WidgetGUIEvent* result = new WidgetGUIEvent(false, message, nullptr); |
|
859 result->AssignGUIEventData(*this, true); |
|
860 result->mFlags = mFlags; |
|
861 return result; |
|
862 } |
|
863 |
|
864 /// Originator of the event |
|
865 nsCOMPtr<nsIWidget> widget; |
|
866 |
|
867 /// Event for NPAPI plugin |
|
868 void* pluginEvent; |
|
869 |
|
870 void AssignGUIEventData(const WidgetGUIEvent& aEvent, bool aCopyTargets) |
|
871 { |
|
872 AssignEventData(aEvent, aCopyTargets); |
|
873 |
|
874 // widget should be initialized with the constructor. |
|
875 |
|
876 // pluginEvent shouldn't be copied because it may be referred after its |
|
877 // instance is destroyed. |
|
878 pluginEvent = nullptr; |
|
879 } |
|
880 }; |
|
881 |
|
882 /****************************************************************************** |
|
883 * mozilla::Modifier |
|
884 * |
|
885 * All modifier keys should be defined here. This is used for managing |
|
886 * modifier states for DOM Level 3 or later. |
|
887 ******************************************************************************/ |
|
888 |
|
889 enum Modifier |
|
890 { |
|
891 MODIFIER_ALT = 0x0001, |
|
892 MODIFIER_ALTGRAPH = 0x0002, |
|
893 MODIFIER_CAPSLOCK = 0x0004, |
|
894 MODIFIER_CONTROL = 0x0008, |
|
895 MODIFIER_FN = 0x0010, |
|
896 MODIFIER_META = 0x0020, |
|
897 MODIFIER_NUMLOCK = 0x0040, |
|
898 MODIFIER_SCROLLLOCK = 0x0080, |
|
899 MODIFIER_SHIFT = 0x0100, |
|
900 MODIFIER_SYMBOLLOCK = 0x0200, |
|
901 MODIFIER_OS = 0x0400 |
|
902 }; |
|
903 |
|
904 /****************************************************************************** |
|
905 * Modifier key names. |
|
906 ******************************************************************************/ |
|
907 |
|
908 #define NS_DOM_KEYNAME_ALT "Alt" |
|
909 #define NS_DOM_KEYNAME_ALTGRAPH "AltGraph" |
|
910 #define NS_DOM_KEYNAME_CAPSLOCK "CapsLock" |
|
911 #define NS_DOM_KEYNAME_CONTROL "Control" |
|
912 #define NS_DOM_KEYNAME_FN "Fn" |
|
913 #define NS_DOM_KEYNAME_META "Meta" |
|
914 #define NS_DOM_KEYNAME_NUMLOCK "NumLock" |
|
915 #define NS_DOM_KEYNAME_SCROLLLOCK "ScrollLock" |
|
916 #define NS_DOM_KEYNAME_SHIFT "Shift" |
|
917 #define NS_DOM_KEYNAME_SYMBOLLOCK "SymbolLock" |
|
918 #define NS_DOM_KEYNAME_OS "OS" |
|
919 |
|
920 /****************************************************************************** |
|
921 * mozilla::Modifiers |
|
922 ******************************************************************************/ |
|
923 |
|
924 typedef uint16_t Modifiers; |
|
925 |
|
926 /****************************************************************************** |
|
927 * mozilla::WidgetInputEvent |
|
928 ******************************************************************************/ |
|
929 |
|
930 class WidgetInputEvent : public WidgetGUIEvent |
|
931 { |
|
932 protected: |
|
933 WidgetInputEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget, |
|
934 nsEventStructType aStructType) : |
|
935 WidgetGUIEvent(aIsTrusted, aMessage, aWidget, aStructType), |
|
936 modifiers(0) |
|
937 { |
|
938 } |
|
939 |
|
940 WidgetInputEvent() |
|
941 { |
|
942 } |
|
943 |
|
944 public: |
|
945 virtual WidgetInputEvent* AsInputEvent() MOZ_OVERRIDE { return this; } |
|
946 |
|
947 WidgetInputEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) : |
|
948 WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_INPUT_EVENT), |
|
949 modifiers(0) |
|
950 { |
|
951 } |
|
952 |
|
953 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE |
|
954 { |
|
955 MOZ_ASSERT(eventStructType == NS_INPUT_EVENT, |
|
956 "Duplicate() must be overridden by sub class"); |
|
957 // Not copying widget, it is a weak reference. |
|
958 WidgetInputEvent* result = new WidgetInputEvent(false, message, nullptr); |
|
959 result->AssignInputEventData(*this, true); |
|
960 result->mFlags = mFlags; |
|
961 return result; |
|
962 } |
|
963 |
|
964 // true indicates the shift key is down |
|
965 bool IsShift() const |
|
966 { |
|
967 return ((modifiers & MODIFIER_SHIFT) != 0); |
|
968 } |
|
969 // true indicates the control key is down |
|
970 bool IsControl() const |
|
971 { |
|
972 return ((modifiers & MODIFIER_CONTROL) != 0); |
|
973 } |
|
974 // true indicates the alt key is down |
|
975 bool IsAlt() const |
|
976 { |
|
977 return ((modifiers & MODIFIER_ALT) != 0); |
|
978 } |
|
979 // true indicates the meta key is down (or, on Mac, the Command key) |
|
980 bool IsMeta() const |
|
981 { |
|
982 return ((modifiers & MODIFIER_META) != 0); |
|
983 } |
|
984 // true indicates the win key is down on Windows. Or the Super or Hyper key |
|
985 // is down on Linux. |
|
986 bool IsOS() const |
|
987 { |
|
988 return ((modifiers & MODIFIER_OS) != 0); |
|
989 } |
|
990 // true indicates the alt graph key is down |
|
991 // NOTE: on Mac, the option key press causes both IsAlt() and IsAltGrpah() |
|
992 // return true. |
|
993 bool IsAltGraph() const |
|
994 { |
|
995 return ((modifiers & MODIFIER_ALTGRAPH) != 0); |
|
996 } |
|
997 // true indeicates the CapLock LED is turn on. |
|
998 bool IsCapsLocked() const |
|
999 { |
|
1000 return ((modifiers & MODIFIER_CAPSLOCK) != 0); |
|
1001 } |
|
1002 // true indeicates the NumLock LED is turn on. |
|
1003 bool IsNumLocked() const |
|
1004 { |
|
1005 return ((modifiers & MODIFIER_NUMLOCK) != 0); |
|
1006 } |
|
1007 // true indeicates the ScrollLock LED is turn on. |
|
1008 bool IsScrollLocked() const |
|
1009 { |
|
1010 return ((modifiers & MODIFIER_SCROLLLOCK) != 0); |
|
1011 } |
|
1012 |
|
1013 // true indeicates the Fn key is down, but this is not supported by native |
|
1014 // key event on any platform. |
|
1015 bool IsFn() const |
|
1016 { |
|
1017 return ((modifiers & MODIFIER_FN) != 0); |
|
1018 } |
|
1019 // true indeicates the ScrollLock LED is turn on. |
|
1020 bool IsSymbolLocked() const |
|
1021 { |
|
1022 return ((modifiers & MODIFIER_SYMBOLLOCK) != 0); |
|
1023 } |
|
1024 |
|
1025 void InitBasicModifiers(bool aCtrlKey, |
|
1026 bool aAltKey, |
|
1027 bool aShiftKey, |
|
1028 bool aMetaKey) |
|
1029 { |
|
1030 modifiers = 0; |
|
1031 if (aCtrlKey) { |
|
1032 modifiers |= MODIFIER_CONTROL; |
|
1033 } |
|
1034 if (aAltKey) { |
|
1035 modifiers |= MODIFIER_ALT; |
|
1036 } |
|
1037 if (aShiftKey) { |
|
1038 modifiers |= MODIFIER_SHIFT; |
|
1039 } |
|
1040 if (aMetaKey) { |
|
1041 modifiers |= MODIFIER_META; |
|
1042 } |
|
1043 } |
|
1044 |
|
1045 Modifiers modifiers; |
|
1046 |
|
1047 void AssignInputEventData(const WidgetInputEvent& aEvent, bool aCopyTargets) |
|
1048 { |
|
1049 AssignGUIEventData(aEvent, aCopyTargets); |
|
1050 |
|
1051 modifiers = aEvent.modifiers; |
|
1052 } |
|
1053 }; |
|
1054 |
|
1055 /****************************************************************************** |
|
1056 * mozilla::InternalUIEvent |
|
1057 * |
|
1058 * XXX Why this inherits WidgetGUIEvent rather than WidgetEvent? |
|
1059 ******************************************************************************/ |
|
1060 |
|
1061 class InternalUIEvent : public WidgetGUIEvent |
|
1062 { |
|
1063 protected: |
|
1064 InternalUIEvent() |
|
1065 : detail(0) |
|
1066 { |
|
1067 } |
|
1068 |
|
1069 InternalUIEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget, |
|
1070 nsEventStructType aStructType) |
|
1071 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, aStructType) |
|
1072 , detail(0) |
|
1073 { |
|
1074 } |
|
1075 |
|
1076 InternalUIEvent(bool aIsTrusted, uint32_t aMessage, |
|
1077 nsEventStructType aStructType) |
|
1078 : WidgetGUIEvent(aIsTrusted, aMessage, nullptr, aStructType) |
|
1079 , detail(0) |
|
1080 { |
|
1081 } |
|
1082 |
|
1083 public: |
|
1084 virtual InternalUIEvent* AsUIEvent() MOZ_OVERRIDE { return this; } |
|
1085 |
|
1086 InternalUIEvent(bool aIsTrusted, uint32_t aMessage) |
|
1087 : WidgetGUIEvent(aIsTrusted, aMessage, nullptr, NS_UI_EVENT) |
|
1088 , detail(0) |
|
1089 { |
|
1090 } |
|
1091 |
|
1092 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE |
|
1093 { |
|
1094 MOZ_ASSERT(eventStructType == NS_UI_EVENT || |
|
1095 eventStructType == NS_SMIL_TIME_EVENT, |
|
1096 "Duplicate() must be overridden by sub class"); |
|
1097 InternalUIEvent* result = new InternalUIEvent(false, message); |
|
1098 result->AssignUIEventData(*this, true); |
|
1099 result->mFlags = mFlags; |
|
1100 return result; |
|
1101 } |
|
1102 |
|
1103 int32_t detail; |
|
1104 |
|
1105 void AssignUIEventData(const InternalUIEvent& aEvent, bool aCopyTargets) |
|
1106 { |
|
1107 AssignGUIEventData(aEvent, aCopyTargets); |
|
1108 |
|
1109 detail = aEvent.detail; |
|
1110 } |
|
1111 }; |
|
1112 |
|
1113 } // namespace mozilla |
|
1114 |
|
1115 #endif // mozilla_BasicEvents_h__ |