Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: ppapi/c/ppb_input_event.h

Issue 7285010: Implement an input event resource. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 /* Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6 #ifndef PPAPI_C_PPB_INPUT_EVENT_H_
7 #define PPAPI_C_PPB_INPUT_EVENT_H_
8
9 #include "ppapi/c/pp_instance.h"
10 #include "ppapi/c/pp_macros.h"
11 #include "ppapi/c/pp_point.h"
12 #include "ppapi/c/pp_resource.h"
13 #include "ppapi/c/pp_stdint.h"
14 #include "ppapi/c/pp_time.h"
15 #include "ppapi/c/pp_var.h"
16
17 #define PPB_INPUT_EVENT_INTERFACE_0_1 "PPB_InputEvent;0.1"
18 #define PPB_INPUT_EVENT_INTERFACE PPB_INPUT_EVENT_INTERFACE_0_1
19
20 /**
21 * @addtogroup Enums
22 * @{
23 */
24
25 /**
26 * This enumeration contains the types of input events.
27 */
28 typedef enum {
29 PP_INPUTEVENT_TYPE_UNDEFINED = -1,
30
31 /**
32 * Notification that a mouse button was pressed.
33 *
34 * Register for this event using the PP_INPUTEVENT_CLASS_MOUSE class.
35 */
36 PP_INPUTEVENT_TYPE_MOUSEDOWN = 0,
37
38 /**
39 * Notification that a mouse button was released.
40 *
41 * Register for this event using the PP_INPUTEVENT_CLASS_MOUSE class.
42 */
43 PP_INPUTEVENT_TYPE_MOUSEUP = 1,
44
45 /**
46 * Notification that a mouse button was moved when it is over the instance
47 * or dragged out of it.
48 *
49 * Register for this event using the PP_INPUTEVENT_CLASS_MOUSE class.
50 */
51 PP_INPUTEVENT_TYPE_MOUSEMOVE = 2,
52
53 /**
54 * Notification that the mouse entered the instance's bounds.
55 *
56 * Register for this event using the PP_INPUTEVENT_CLASS_MOUSE class.
57 */
58 PP_INPUTEVENT_TYPE_MOUSEENTER = 3,
59
60 /**
61 * Notification that a mouse left the instance's bounds.
62 *
63 * Register for this event using the PP_INPUTEVENT_CLASS_MOUSE class.
64 */
65 PP_INPUTEVENT_TYPE_MOUSELEAVE = 4,
66
67 /**
68 * Notification that the scroll wheel was used.
69 *
70 * Register for this event using the PP_INPUTEVENT_CLASS_WHEEL class.
71 */
72 PP_INPUTEVENT_TYPE_MOUSEWHEEL = 5,
73
74 /**
75 * Notification that a key transitioned from "up" to "down".
76 * TODO(brettw) differentiate from KEYDOWN.
77 *
78 * Register for this event using the PP_INPUTEVENT_CLASS_KEYBOARD class.
79 */
80 PP_INPUTEVENT_TYPE_RAWKEYDOWN = 6,
81
82 /**
83 * Notification that a key was pressed. This does not necessarily correspond
84 * to a character depending on the key and language. Use the
85 * PP_INPUTEVENT_TYPE_CHAR for character input.
86 *
87 * Register for this event using the PP_INPUTEVENT_CLASS_KEYBOARD class.
88 */
89 PP_INPUTEVENT_TYPE_KEYDOWN = 7,
90
91 /**
92 * Notification that a key was released.
93 *
94 * Register for this event using the PP_INPUTEVENT_CLASS_KEYBOARD class.
95 */
96 PP_INPUTEVENT_TYPE_KEYUP = 8,
97
98 /**
99 * Notification that a character was typed. Use this for text input. Key
100 * down events may generate 0, 1, or more than one character event depending
101 * on the key, locale, and operating system.
102 *
103 * Register for this event using the PP_INPUTEVENT_CLASS_KEYBOARD class.
104 */
105 PP_INPUTEVENT_TYPE_CHAR = 9,
106
107 /**
108 * TODO(brettw) when is this used?
109 *
110 * Register for this event using the PP_INPUTEVENT_CLASS_MOUSE class.
111 */
112 PP_INPUTEVENT_TYPE_CONTEXTMENU = 10
113 } PP_InputEvent_Type;
114 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_Type, 4);
115
116 /**
117 * This enumeration contains event modifier constants. Each modifier is one
118 * bit. Retrieve the modifiers from an input event using the GetEventModifiers
119 * function on PPB_InputEvent.
120 */
121 typedef enum {
122 PP_INPUTEVENT_MODIFIER_SHIFTKEY = 1 << 0,
123 PP_INPUTEVENT_MODIFIER_CONTROLKEY = 1 << 1,
124 PP_INPUTEVENT_MODIFIER_ALTKEY = 1 << 2,
125 PP_INPUTEVENT_MODIFIER_METAKEY = 1 << 3,
126 PP_INPUTEVENT_MODIFIER_ISKEYPAD = 1 << 4,
127 PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT = 1 << 5,
128 PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN = 1 << 6,
129 PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN = 1 << 7,
130 PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN = 1 << 8,
131 PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY = 1 << 9,
132 PP_INPUTEVENT_MODIFIER_NUMLOCKKEY = 1 << 10
133 } PP_InputEvent_Modifier;
134 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_Modifier, 4);
135
136 /**
137 * This enumeration contains constants representing each mouse button. To get
138 * the mouse button for a mouse down or up event, use GetMouseButton on
139 * PPB_InputEvent.
140 */
141 typedef enum {
142 PP_INPUTEVENT_MOUSEBUTTON_NONE = -1,
143 PP_INPUTEVENT_MOUSEBUTTON_LEFT = 0,
144 PP_INPUTEVENT_MOUSEBUTTON_MIDDLE = 1,
145 PP_INPUTEVENT_MOUSEBUTTON_RIGHT = 2
146 } PP_InputEvent_MouseButton;
147 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_MouseButton, 4);
148
149 /**
150 * @}
151 */
152
153 typedef enum {
154 /**
155 * Request mouse input events.
156 *
157 * Normally you will request mouse events by calling RequestInputEvents().
158 * The only use case for filtered events (via RequestFilteringInputEvents())
159 * is for instances that have irregular outlines and you want to perform hit
160 * testing, which is very uncommon. Requesting non-filtered mouse events will
161 * lead to higher performance.
162 */
163 PP_INPUTEVENT_CLASS_MOUSE = 1 << 0,
164
165 /**
166 * Requests keyboard events. Keyboard events must be requested in filtering
167 * mode via RequestFilteringInputEvents(). This is because many commands
168 * should be forwarded to the page.
169 *
170 * A small number of tab and window management commands like Alt-F4 are never
171 * sent to the page. You can not request these keyboard commands since it
172 * would allow pages to trap users on a page.
173 */
174 PP_INPUTEVENT_CLASS_KEYBOARD = 1 << 1,
175
176 /**
177 * Identifies scroll wheel input event. Wheel events must be requested in
178 * filtering mode via RequestFilteringInputEvents(). This is because many
179 * wheel commands should be forwarded to the page.
180 *
181 * Most instances will not need this event. Consuming wheel events by
182 * returning true from your filtered event handler will prevent the user from
183 * scrolling the page when the mouse is over the instance which can be very
184 * annoying.
185 *
186 * If you handle wheel events (for example, you have a document viewer which
187 * the user can scroll), the recommended behavior is to return false only if
188 * the wheel event actually causes your document to scroll. When the user
189 * reaches the end of the document, return false to indicating that the event
190 * was not handled. This will then forward the event to the containing page
191 * for scrolling, producing the nested scrolling behavior users expect from
192 * frames in a page.
193 */
194 PP_INPUTEVENT_CLASS_WHEEL = 1 << 2,
195
196 /**
197 * Identifies touch input events.
198 *
199 * Request touch events only if you intend to handle them. If the browser
200 * knows you do not need to handle touch events, it can handle them at a
201 * higher level and achieve higher performance.
202 */
203 PP_INPUTEVENT_CLASS_TOUCH = 1 << 3,
204
205 /**
206 * Identifies IME composition input events.
207 *
208 * Request this input event class if you allow on-the-spot IME input.
209 */
210 PP_INPUTEVENT_CLASS_IME = 1 << 4
211 } PP_InputEvent_Class;
212 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_Class, 4);
213
214 struct PPB_InputEvent {
215 /**
216 * Request that input events corresponding to the given input events are
217 * delivered to the instance.
218 *
219 * You can not use this function to request keyboard events
220 * (PP_INPUTEVENT_CLASS_KEYBOARD). You must use RequestFilteringInputEvents()
221 * for this class of input.
dmichael (off chromium) 2011/07/01 20:04:19 Just for my own edification... Why this limitation
222 *
223 * By default, no input events are delivered. Call this function with the
224 * classes of events you are interested in to have them be delivered to
225 * the instance. Calling this function will override any previous setting for
226 * each specified class of input events (for example, if you previously
227 * called RequestFilteringInputEvents(), this function will set those events
228 * to non-filtering mode).
229 *
230 * Input events may have high overhead, so you should only request input
231 * events that your plugin will actually handle. For example, the browser may
232 * do optimizations for scroll or touch events that can be processed
233 * substantially faster if it knows there are no non-default receivers for
234 * that message. Requesting that such messages be delivered, even if they are
235 * processed very quickly, may have a noticable effect on the performance of
236 * the page.
237 *
238 * When requesting input events through this function, the events will be
239 * delivered and <i>not</i> bubbled to the page. This means that even if you
240 * aren't interested in the message, no other parts of the page will get
241 * a crack at the message.
242 *
243 * Example:
244 * RequestInputEvents(instance, PP_INPUTEVENT_CLASS_MOUSE);
245 * RequestFilteringInputEvents(instance,
246 * PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD);
247 *
248 * @param instance The <code>PP_Instance</code> of the instance requesting
249 * the given events.
250 *
251 * @param event_classes A combination of flags from PP_InputEvent_Class that
252 * identifies the classes of events the instance is requesting. The flags
253 * are combined by logically ORing their values.
254 *
255 * @return PP_OK if the operation succeeded, PP_ERROR_BADARGUMENT if instance
256 * is invalid, or PP_ERROR_NOTSUPPORTED if one of the event class bits were
257 * illegal. In the case of an invalid bit, all valid bits will be applied
258 * and only the illegal bits will be ignored. The most common cause of a
259 * PP_ERROR_NOTSUPPORTED return value is requesting keyboard events, these
260 * must use RequestFilteringInputEvents().
261 */
262 int32_t (*RequestInputEvents)(PP_Instance instance,
263 uint32_t event_classes);
264
265 /**
266 * Request that input events corresponding to the given input events are
267 * delivered to the instance for filtering.
268 *
269 * By default, no input events are delivered. In most cases you would
270 * register to receive events by calling RequestInputEvents(). In some cases,
271 * however, you may wish to filter events such that they can be bubbled up
272 * to the DOM. In this case, register for those classes of events using
273 * this function instead of RequestInputEvents(). Keyboard events must always
274 * be registered in filtering mode.
275 *
276 * Filtering input events requires significantly more overhead than just
277 * delivering them to the instance. As such, you should only request
278 * filtering in those cases where it's absolutely necessary. The reason is
279 * that it requires the browser to stop and block for the instance to handle
280 * the input event, rather than sending the input event asynchrohously. This
darin (slow to review) 2011/07/01 17:57:37 sp error: asynchrohously
281 * can have significant overhead.
282 *
283 * Example:
284 * RequestInputEvents(instance, PP_INPUTEVENT_CLASS_MOUSE);
285 * RequestFilteringInputEvents(instance,
286 * PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD);
287 *
288 * @return PP_OK if the operation succeeded, PP_ERROR_BADARGUMENT if instance
289 * is invalid, or PP_ERROR_NOTSUPPORTED if one of the event class bits were
290 * illegal. In the case of an invalid bit, all valid bits will be applied
291 * and only the illegal bits will be ignored.
292 */
293 int32_t (*RequestFilteringInputEvents)(PP_Instance instance,
294 uint32_t event_classes);
darin (slow to review) 2011/07/01 17:57:37 nit: indentation
dmichael (off chromium) 2011/07/01 20:04:19 nit: indentation
295
296 /**
297 * Request that input events corresponding to the given input classes no
298 * longer be delivered to the instance.
299 *
300 * By default, no input events are delivered. If you have previously
301 * requested input events via RequestInputEvents() or
302 * RequestFilteringInputEvents(), this function will unregister handling
303 * for the given instance. This will allow greater browser performance for
304 * those events.
305 *
306 * @param instance The <code>PP_Instance</code> of the instance requesting
307 * to no longer receive the given events.
308 *
309 * @param event_classes A combination of flags from PP_InputEvent_Class that
310 * identifies the classes of events the instance is no longer interested in.
311 */
312 void (*ClearInputEventRequest)(PP_Instance instance,
313 uint32_t event_classes);
darin (slow to review) 2011/07/01 17:57:37 do we need this function? can't plugins just call
314
315 /**
316 * Returns true if the given resource is a valid input event resource.
317 */
318 PP_Bool (*IsInputEvent)(PP_Resource resource);
319
320 /**
321 * Returns the type of input event for the given input event resource.
322 * This is valid for all input events. Returns PP_INPUTEVENT_TYPE_UNDEFINED
323 * if the resource is invalid.
324 */
325 PP_InputEvent_Type (*GetEventType)(PP_Resource event);
326
327 /**
328 * Returns the time that the event was generated. This will be before the
329 * current time since processing and dispatching the event has some overhead.
330 * Use this value to compare the times the user generated two events without
331 * being sensitive to variable processing time.
332 *
333 * The return value is in time ticks, which is a monotonically increasing
334 * clock not related to the wall clock time. It will not change if the user
335 * changes their clock or daylight savings time starts, so can be reliably
336 * used to compare events. This means, however, that you can't correlate
337 * event times to a particular time of day on the system clock.
338 */
339 PP_TimeTicks (*GetEventTimeStamp)(PP_Resource event);
340
341 /**
342 * Returns a bitfield indicating which modifiers were down at the time of
343 * the event. This is a combination of the flags in the
344 * PP_InputEvent_Modifier enum.
345 *
346 * @return The modifiers associated with the event, or 0 if the given
347 * resource is not a valid event resource.
348 */
349 uint32_t (*GetEventModifiers)(PP_Resource event);
350
351 /**
352 * Returns the mouse position for a mouse input event.
353 *
354 * @return The mouse button associated with mouse down and up events. This
355 * value will be PP_EVENT_MOUSEBUTTON_NONE for mouse move, enter, and leave
356 * events, and for all non-mouse events.
357 */
358 PP_InputEvent_MouseButton (*GetMouseButton)(PP_Resource mouse_event);
359
360 /**
361 * Returns the pixel location of a mouse input event. This value is in
362 * floating-point units to support high-resolution input events.
363 *
364 * @return The point associated with the mouse event, relative to the upper-
365 * left of the instance receiving the event. These values can be negative for
366 * mouse drags. The return value will be (0, 0) for non-mouse events.
367 */
368 PP_Point (*GetMousePosition)(PP_Resource mouse_event);
dmichael (off chromium) 2011/07/01 20:04:19 I think you meant PP_FloatPoint?
dmichael (off chromium) 2011/07/01 20:05:38 Retracted. I think you just need to update the co
brettw 2011/07/01 21:14:52 Yeah. We get ints and all current plugins expect i
369
370 /**
371 * TODO(brettw) figure out exactly what this means.
372 */
373 int32_t (*GetMouseClickCount)(PP_Resource mouse_event);
darin (slow to review) 2011/07/01 17:57:37 this is used to report double clicks and triple cl
374
375 /**
376 * Indicates the amount vertically and horizontally the user has requested
377 * to scroll by with their mouse wheel. A scroll down or to the right (where
378 * the content moves up or left) is represented as positive values, and
379 * a scroll up or to the left (where the content moves down or right) is
380 * represented as negative values.
381 *
382 * The units are either in pixels (when scroll_by_page is false) or pages
383 * (when scroll_by_page is true). For example, y = -3 means scroll up 3
384 * pixels when scroll_by_page is false, and scroll up 3 pages when
385 * scroll_by_page is true.
386 *
387 * This amount is system dependent and will take into account the user's
388 * preferred scroll sensitivity and potentially also nonlinear acceleration
389 * based on the speed of the scrolling.
390 *
391 * Devices will be of varying resolution. Some mice with large detents will
392 * only generate integer scroll amounts. But fractional values are also
393 * possible, for example, on some trackpads and newer mice that don't have
394 * "clicks".
395 */
396 PP_FloatPoint (*GetWheelDelta)(PP_Resource wheel_event);
397
398 /**
399 * The number of "clicks" of the scroll wheel that have produced the
400 * event. The value may have system-specific acceleration applied to it,
401 * depending on the device. The positive and negative meanings are the same
402 * as for GetWheelDelta().
403 *
404 * If you are scrolling, you probably want to use the delta values. These
405 * tick events can be useful if you aren't doing actual scrolling and don't
406 * want or pixel values. An example may be cycling between different items in
407 * a game.
408 *
409 * You may receive fractional values for the wheel ticks if the mouse wheel
410 * is high resolution or doesn't have "clicks". If your program wants
411 * discrete events (as in the "picking items" example) you should accumulate
412 * fractional click values from multiple messages until the total value
413 * reaches positive or negative one. This should represent a similar amount
414 * of scrolling as for a mouse that has a discrete mouse wheel.
415 */
416 PP_FloatPoint (*GetWheelTicks)(PP_Resource wheel_event);
417
418 /**
419 * Indicates if the scroll delta_x/delta_y indicates pages or lines to
420 * scroll by.
421 *
422 * @return PP_TRUE if the event is a wheel event and the user is scrolling
423 * by pages. PP_FALSE if not or if the resource is not a wheel event.
424 */
425 PP_Bool (*GetWheelScrollByPage)(PP_Resource wheel_event);
426
427 /**
428 * Returns the DOM |keyCode| field for the keyboard event.
429 * Chrome populates this with the Windows-style Virtual Key code of the key.
430 */
431 uint32_t (*GetKeyCode)(PP_Resource key_event);
432
433 /**
434 * Returns the typed character for the given character event.
435 *
436 * @return A string var representing a single typed character for character
437 * input events. For non-character input events the return value will be an
438 * undefined var.
439 */
440 PP_Var (*GetCharacterText)(PP_Resource character_event);
darin (slow to review) 2011/07/01 17:57:37 i'm a little worried that this interface is going
brettw 2011/07/01 17:59:36 What do you imagine the C++ API looking like?
darin (slow to review) 2011/07/01 18:06:24 It could look like this: switch (event.GetEventTy
dmichael (off chromium) 2011/07/01 20:04:19 The return here could reasonably char[5] like the
441 };
442
443 #endif // PPAPI_C_PPB_INPUT_EVENT_H_
OLDNEW
« no previous file with comments | « ppapi/c/pp_point.h ('k') | ppapi/c/ppp_input_event.h » ('j') | ppapi/c/ppp_input_event.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698