ppb_input_event.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1/* Copyright (c) 2012 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/* From ppb_input_event.idl modified Mon Dec 16 15:35:15 2013. */
7
8#ifndef PPAPI_C_PPB_INPUT_EVENT_H_
9#define PPAPI_C_PPB_INPUT_EVENT_H_
10
11#include "ppapi/c/pp_bool.h"
12#include "ppapi/c/pp_instance.h"
13#include "ppapi/c/pp_macros.h"
14#include "ppapi/c/pp_point.h"
15#include "ppapi/c/pp_resource.h"
16#include "ppapi/c/pp_stdint.h"
17#include "ppapi/c/pp_time.h"
18#include "ppapi/c/pp_touch_point.h"
19#include "ppapi/c/pp_var.h"
20
21#define PPB_INPUT_EVENT_INTERFACE_1_0 "PPB_InputEvent;1.0"
22#define PPB_INPUT_EVENT_INTERFACE PPB_INPUT_EVENT_INTERFACE_1_0
23
24#define PPB_MOUSE_INPUT_EVENT_INTERFACE_1_0 "PPB_MouseInputEvent;1.0"
25#define PPB_MOUSE_INPUT_EVENT_INTERFACE_1_1 "PPB_MouseInputEvent;1.1"
26#define PPB_MOUSE_INPUT_EVENT_INTERFACE PPB_MOUSE_INPUT_EVENT_INTERFACE_1_1
27
28#define PPB_WHEEL_INPUT_EVENT_INTERFACE_1_0 "PPB_WheelInputEvent;1.0"
29#define PPB_WHEEL_INPUT_EVENT_INTERFACE PPB_WHEEL_INPUT_EVENT_INTERFACE_1_0
30
31#define PPB_KEYBOARD_INPUT_EVENT_INTERFACE_1_0 "PPB_KeyboardInputEvent;1.0"
32#define PPB_KEYBOARD_INPUT_EVENT_INTERFACE_1_2 "PPB_KeyboardInputEvent;1.2"
33#define PPB_KEYBOARD_INPUT_EVENT_INTERFACE \
34    PPB_KEYBOARD_INPUT_EVENT_INTERFACE_1_2
35
36#define PPB_TOUCH_INPUT_EVENT_INTERFACE_1_0 "PPB_TouchInputEvent;1.0"
37#define PPB_TOUCH_INPUT_EVENT_INTERFACE PPB_TOUCH_INPUT_EVENT_INTERFACE_1_0
38
39#define PPB_IME_INPUT_EVENT_INTERFACE_1_0 "PPB_IMEInputEvent;1.0"
40#define PPB_IME_INPUT_EVENT_INTERFACE PPB_IME_INPUT_EVENT_INTERFACE_1_0
41
42/**
43 * @file
44 * This file defines the Input Event interfaces.
45 */
46
47
48/**
49 * @addtogroup Enums
50 * @{
51 */
52/**
53 * This enumeration contains the types of input events.
54 */
55typedef enum {
56  PP_INPUTEVENT_TYPE_UNDEFINED = -1,
57  /**
58   * Notification that a mouse button was pressed.
59   *
60   * Register for this event using the PP_INPUTEVENT_CLASS_MOUSE class.
61   */
62  PP_INPUTEVENT_TYPE_MOUSEDOWN = 0,
63  /**
64   * Notification that a mouse button was released.
65   *
66   * Register for this event using the PP_INPUTEVENT_CLASS_MOUSE class.
67   */
68  PP_INPUTEVENT_TYPE_MOUSEUP = 1,
69  /**
70   * Notification that a mouse button was moved when it is over the instance
71   * or dragged out of it.
72   *
73   * Register for this event using the PP_INPUTEVENT_CLASS_MOUSE class.
74   */
75  PP_INPUTEVENT_TYPE_MOUSEMOVE = 2,
76  /**
77   * Notification that the mouse entered the instance's bounds.
78   *
79   * Register for this event using the PP_INPUTEVENT_CLASS_MOUSE class.
80   */
81  PP_INPUTEVENT_TYPE_MOUSEENTER = 3,
82  /**
83   * Notification that a mouse left the instance's bounds.
84   *
85   * Register for this event using the PP_INPUTEVENT_CLASS_MOUSE class.
86   */
87  PP_INPUTEVENT_TYPE_MOUSELEAVE = 4,
88  /**
89   * Notification that the scroll wheel was used.
90   *
91   * Register for this event using the PP_INPUTEVENT_CLASS_WHEEL class.
92   */
93  PP_INPUTEVENT_TYPE_WHEEL = 5,
94  /**
95   * Notification that a key transitioned from "up" to "down".
96   *
97   * Register for this event using the PP_INPUTEVENT_CLASS_KEYBOARD class.
98   */
99  /*
100   * TODO(brettw) differentiate from KEYDOWN.
101   */
102  PP_INPUTEVENT_TYPE_RAWKEYDOWN = 6,
103  /**
104   * Notification that a key was pressed. This does not necessarily correspond
105   * to a character depending on the key and language. Use the
106   * PP_INPUTEVENT_TYPE_CHAR for character input.
107   *
108   * Register for this event using the PP_INPUTEVENT_CLASS_KEYBOARD class.
109   */
110  PP_INPUTEVENT_TYPE_KEYDOWN = 7,
111  /**
112   * Notification that a key was released.
113   *
114   * Register for this event using the PP_INPUTEVENT_CLASS_KEYBOARD class.
115   */
116  PP_INPUTEVENT_TYPE_KEYUP = 8,
117  /**
118   * Notification that a character was typed. Use this for text input. Key
119   * down events may generate 0, 1, or more than one character event depending
120   * on the key, locale, and operating system.
121   *
122   * Register for this event using the PP_INPUTEVENT_CLASS_KEYBOARD class.
123   */
124  PP_INPUTEVENT_TYPE_CHAR = 9,
125  /**
126   * Notification that a context menu should be shown.
127   *
128   * This message will be sent when the user right-clicks or performs another
129   * OS-specific mouse command that should open a context menu. When this event
130   * is delivered depends on the system, on some systems (Mac) it will
131   * delivered after the mouse down event, and on others (Windows) it will be
132   * delivered after the mouse up event.
133   *
134   * You will always get the normal mouse events. For example, you may see
135   * MOUSEDOWN,CONTEXTMENU,MOUSEUP or MOUSEDOWN,MOUSEUP,CONTEXTMENU.
136   *
137   * The return value from the event handler determines if the context menu
138   * event will be passed to the page when you are using filtered input events
139   * (via RequestFilteringInputEvents()). In non-filtering mode the event will
140   * never be propagated and no context menu will be displayed. If you are
141   * handling mouse events in filtering mode, you may want to return true from
142   * this event even if you do not support a context menu to suppress the
143   * default one.
144   *
145   * Register for this event using the PP_INPUTEVENT_CLASS_MOUSE class.
146   */
147  PP_INPUTEVENT_TYPE_CONTEXTMENU = 10,
148  /**
149   * Notification that an input method composition process has just started.
150   *
151   * Register for this event using the PP_INPUTEVENT_CLASS_IME class.
152   */
153  PP_INPUTEVENT_TYPE_IME_COMPOSITION_START = 11,
154  /**
155   * Notification that the input method composition string is updated.
156   *
157   * Register for this event using the PP_INPUTEVENT_CLASS_IME class.
158   */
159  PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE = 12,
160  /**
161   * Notification that an input method composition process has completed.
162   *
163   * Register for this event using the PP_INPUTEVENT_CLASS_IME class.
164   */
165  PP_INPUTEVENT_TYPE_IME_COMPOSITION_END = 13,
166  /**
167   * Notification that an input method committed a string.
168   *
169   * Register for this event using the PP_INPUTEVENT_CLASS_IME class.
170   */
171  PP_INPUTEVENT_TYPE_IME_TEXT = 14,
172  /**
173   * Notification that a finger was placed on a touch-enabled device.
174   *
175   * Register for this event using the PP_INPUTEVENT_CLASS_TOUCH class.
176   */
177  PP_INPUTEVENT_TYPE_TOUCHSTART = 15,
178  /**
179   * Notification that a finger was moved on a touch-enabled device.
180   *
181   * Register for this event using the PP_INPUTEVENT_CLASS_TOUCH class.
182   */
183  PP_INPUTEVENT_TYPE_TOUCHMOVE = 16,
184  /**
185   * Notification that a finger was released on a touch-enabled device.
186   *
187   * Register for this event using the PP_INPUTEVENT_CLASS_TOUCH class.
188   */
189  PP_INPUTEVENT_TYPE_TOUCHEND = 17,
190  /**
191   * Notification that a touch event was canceled.
192   *
193   * Register for this event using the PP_INPUTEVENT_CLASS_TOUCH class.
194   */
195  PP_INPUTEVENT_TYPE_TOUCHCANCEL = 18
196} PP_InputEvent_Type;
197PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_Type, 4);
198
199/**
200 * This enumeration contains event modifier constants. Each modifier is one
201 * bit. Retrieve the modifiers from an input event using the GetEventModifiers
202 * function on PPB_InputEvent.
203 */
204typedef enum {
205  PP_INPUTEVENT_MODIFIER_SHIFTKEY = 1 << 0,
206  PP_INPUTEVENT_MODIFIER_CONTROLKEY = 1 << 1,
207  PP_INPUTEVENT_MODIFIER_ALTKEY = 1 << 2,
208  PP_INPUTEVENT_MODIFIER_METAKEY = 1 << 3,
209  PP_INPUTEVENT_MODIFIER_ISKEYPAD = 1 << 4,
210  PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT = 1 << 5,
211  PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN = 1 << 6,
212  PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN = 1 << 7,
213  PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN = 1 << 8,
214  PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY = 1 << 9,
215  PP_INPUTEVENT_MODIFIER_NUMLOCKKEY = 1 << 10,
216  PP_INPUTEVENT_MODIFIER_ISLEFT = 1 << 11,
217  PP_INPUTEVENT_MODIFIER_ISRIGHT = 1 << 12
218} PP_InputEvent_Modifier;
219PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_Modifier, 4);
220
221/**
222 * This enumeration contains constants representing each mouse button. To get
223 * the mouse button for a mouse down or up event, use GetMouseButton on
224 * PPB_InputEvent.
225 */
226typedef enum {
227  PP_INPUTEVENT_MOUSEBUTTON_NONE = -1,
228  PP_INPUTEVENT_MOUSEBUTTON_LEFT = 0,
229  PP_INPUTEVENT_MOUSEBUTTON_MIDDLE = 1,
230  PP_INPUTEVENT_MOUSEBUTTON_RIGHT = 2
231} PP_InputEvent_MouseButton;
232PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_MouseButton, 4);
233
234typedef enum {
235  /**
236   * Request mouse input events.
237   *
238   * Normally you will request mouse events by calling RequestInputEvents().
239   * The only use case for filtered events (via RequestFilteringInputEvents())
240   * is for instances that have irregular outlines and you want to perform hit
241   * testing, which is very uncommon. Requesting non-filtered mouse events will
242   * lead to higher performance.
243   */
244  PP_INPUTEVENT_CLASS_MOUSE = 1 << 0,
245  /**
246   * Requests keyboard events. Often you will want to request filtered mode
247   * (via RequestFilteringInputEvents) for keyboard events so you can pass on
248   * events (by returning false) that you don't handle. For example, if you
249   * don't request filtered mode and the user pressed "Page Down" when your
250   * instance has focus, the page won't scroll which will be a poor experience.
251   *
252   * A small number of tab and window management commands like Alt-F4 are never
253   * sent to the page. You can not request these keyboard commands since it
254   * would allow pages to trap users on a page.
255   */
256  PP_INPUTEVENT_CLASS_KEYBOARD = 1 << 1,
257  /**
258   * Identifies scroll wheel input event. Wheel events must be requested in
259   * filtering mode via RequestFilteringInputEvents(). This is because many
260   * wheel commands should be forwarded to the page.
261   *
262   * Most instances will not need this event. Consuming wheel events by
263   * returning true from your filtered event handler will prevent the user from
264   * scrolling the page when the mouse is over the instance which can be very
265   * annoying.
266   *
267   * If you handle wheel events (for example, you have a document viewer which
268   * the user can scroll), the recommended behavior is to return false only if
269   * the wheel event actually causes your document to scroll. When the user
270   * reaches the end of the document, return false to indicating that the event
271   * was not handled. This will then forward the event to the containing page
272   * for scrolling, producing the nested scrolling behavior users expect from
273   * frames in a page.
274   */
275  PP_INPUTEVENT_CLASS_WHEEL = 1 << 2,
276  /**
277   * Identifies touch input events.
278   *
279   * Request touch events only if you intend to handle them. If the browser
280   * knows you do not need to handle touch events, it can handle them at a
281   * higher level and achieve higher performance. If the plugin does not
282   * register for touch-events, then it will receive synthetic mouse events that
283   * are generated from the touch events (e.g. mouse-down for touch-start,
284   * mouse-move for touch-move (with left-button down), and mouse-up for
285   * touch-end. If the plugin does register for touch events, then the synthetic
286   * mouse events are not created.
287   */
288  PP_INPUTEVENT_CLASS_TOUCH = 1 << 3,
289  /**
290   * Identifies IME composition input events.
291   *
292   * Request this input event class if you allow on-the-spot IME input.
293   */
294  PP_INPUTEVENT_CLASS_IME = 1 << 4
295} PP_InputEvent_Class;
296PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_Class, 4);
297/**
298 * @}
299 */
300
301/**
302 * @addtogroup Interfaces
303 * @{
304 */
305/**
306 * The <code>PPB_InputEvent</code> interface contains pointers to several
307 * functions related to generic input events on the browser.
308 */
309struct PPB_InputEvent_1_0 {
310  /**
311   * RequestInputEvent() requests that input events corresponding to the given
312   * input events are delivered to the instance.
313   *
314   * It's recommended that you use RequestFilteringInputEvents() for keyboard
315   * events instead of this function so that you don't interfere with normal
316   * browser accelerators.
317   *
318   * By default, no input events are delivered. Call this function with the
319   * classes of events you are interested in to have them be delivered to
320   * the instance. Calling this function will override any previous setting for
321   * each specified class of input events (for example, if you previously
322   * called RequestFilteringInputEvents(), this function will set those events
323   * to non-filtering mode).
324   *
325   * Input events may have high overhead, so you should only request input
326   * events that your plugin will actually handle. For example, the browser may
327   * do optimizations for scroll or touch events that can be processed
328   * substantially faster if it knows there are no non-default receivers for
329   * that message. Requesting that such messages be delivered, even if they are
330   * processed very quickly, may have a noticeable effect on the performance of
331   * the page.
332   *
333   * Note that synthetic mouse events will be generated from touch events if
334   * (and only if) you do not request touch events.
335   *
336   * When requesting input events through this function, the events will be
337   * delivered and <i>not</i> bubbled to the page. This means that even if you
338   * aren't interested in the message, no other parts of the page will get
339   * a crack at the message.
340   *
341   * <strong>Example:</strong>
342   * @code
343   *   RequestInputEvents(instance, PP_INPUTEVENT_CLASS_MOUSE);
344   *   RequestFilteringInputEvents(instance,
345   *       PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD);
346   * @endcode
347   *
348   * @param instance The <code>PP_Instance</code> of the instance requesting
349   * the given events.
350   *
351   * @param event_classes A combination of flags from
352   * <code>PP_InputEvent_Class</code> that identifies the classes of events the
353   * instance is requesting. The flags are combined by logically ORing their
354   * values.
355   *
356   * @return <code>PP_OK</code> if the operation succeeded,
357   * <code>PP_ERROR_BADARGUMENT</code> if instance is invalid, or
358   * <code>PP_ERROR_NOTSUPPORTED</code> if one of the event class bits were
359   * illegal. In the case of an invalid bit, all valid bits will be applied
360   * and only the illegal bits will be ignored. The most common cause of a
361   * <code>PP_ERROR_NOTSUPPORTED</code> return value is requesting keyboard
362   * events, these must use RequestFilteringInputEvents().
363   */
364  int32_t (*RequestInputEvents)(PP_Instance instance, uint32_t event_classes);
365  /**
366   * RequestFilteringInputEvents() requests that input events corresponding to
367   * the given input events are delivered to the instance for filtering.
368   *
369   * By default, no input events are delivered. In most cases you would
370   * register to receive events by calling RequestInputEvents(). In some cases,
371   * however, you may wish to filter events such that they can be bubbled up
372   * to the DOM. In this case, register for those classes of events using
373   * this function instead of RequestInputEvents().
374   *
375   * Filtering input events requires significantly more overhead than just
376   * delivering them to the instance. As such, you should only request
377   * filtering in those cases where it's absolutely necessary. The reason is
378   * that it requires the browser to stop and block for the instance to handle
379   * the input event, rather than sending the input event asynchronously. This
380   * can have significant overhead.
381   *
382   * <strong>Example:</strong>
383   * @code
384   *   RequestInputEvents(instance, PP_INPUTEVENT_CLASS_MOUSE);
385   *   RequestFilteringInputEvents(instance,
386   *       PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD);
387   * @endcode
388   *
389   * @return <code>PP_OK</code> if the operation succeeded,
390   * <code>PP_ERROR_BADARGUMENT</code> if instance is invalid, or
391   * <code>PP_ERROR_NOTSUPPORTED</code> if one of the event class bits were
392   * illegal. In the case of an invalid bit, all valid bits will be applied
393   * and only the illegal bits will be ignored.
394   */
395  int32_t (*RequestFilteringInputEvents)(PP_Instance instance,
396                                         uint32_t event_classes);
397  /**
398   * ClearInputEventRequest() requests that input events corresponding to the
399   * given input classes no longer be delivered to the instance.
400   *
401   * By default, no input events are delivered. If you have previously
402   * requested input events via RequestInputEvents() or
403   * RequestFilteringInputEvents(), this function will unregister handling
404   * for the given instance. This will allow greater browser performance for
405   * those events.
406   *
407   * Note that you may still get some input events after clearing the flag if
408   * they were dispatched before the request was cleared. For example, if
409   * there are 3 mouse move events waiting to be delivered, and you clear the
410   * mouse event class during the processing of the first one, you'll still
411   * receive the next two. You just won't get more events generated.
412   *
413   * @param instance The <code>PP_Instance</code> of the instance requesting
414   * to no longer receive the given events.
415   *
416   * @param event_classes A combination of flags from
417   * <code>PP_InputEvent_Class</code> that identify the classes of events the
418   * instance is no longer interested in.
419   */
420  void (*ClearInputEventRequest)(PP_Instance instance, uint32_t event_classes);
421  /**
422   * IsInputEvent() returns true if the given resource is a valid input event
423   * resource.
424   *
425   * @param[in] resource A <code>PP_Resource</code> corresponding to a generic
426   * resource.
427   *
428   * @return <code>PP_TRUE</code> if the given resource is a valid input event
429   * resource.
430   */
431  PP_Bool (*IsInputEvent)(PP_Resource resource);
432  /**
433   * GetType() returns the type of input event for the given input event
434   * resource.
435   *
436   * @param[in] resource A <code>PP_Resource</code> corresponding to an input
437   * event.
438   *
439   * @return A <code>PP_InputEvent_Type</code> if its a valid input event or
440   * <code>PP_INPUTEVENT_TYPE_UNDEFINED</code> if the resource is invalid.
441   */
442  PP_InputEvent_Type (*GetType)(PP_Resource event);
443  /**
444   * GetTimeStamp() Returns the time that the event was generated. This will be
445   *  before the current time since processing and dispatching the event has
446   * some overhead. Use this value to compare the times the user generated two
447   * events without being sensitive to variable processing time.
448   *
449   * @param[in] resource A <code>PP_Resource</code> corresponding to the event.
450   *
451   * @return The return value is in time ticks, which is a monotonically
452   * increasing clock not related to the wall clock time. It will not change
453   * if the user changes their clock or daylight savings time starts, so can
454   * be reliably used to compare events. This means, however, that you can't
455   * correlate event times to a particular time of day on the system clock.
456   */
457  PP_TimeTicks (*GetTimeStamp)(PP_Resource event);
458  /**
459   * GetModifiers() returns a bitfield indicating which modifiers were down
460   * at the time of the event. This is a combination of the flags in the
461   * <code>PP_InputEvent_Modifier</code> enum.
462   *
463   * @param[in] resource A <code>PP_Resource</code> corresponding to an input
464   * event.
465   *
466   * @return The modifiers associated with the event, or 0 if the given
467   * resource is not a valid event resource.
468   */
469  uint32_t (*GetModifiers)(PP_Resource event);
470};
471
472typedef struct PPB_InputEvent_1_0 PPB_InputEvent;
473
474/**
475 * The <code>PPB_MouseInputEvent</code> interface contains pointers to several
476 * functions related to mouse input events.
477 */
478struct PPB_MouseInputEvent_1_1 {
479  /**
480   * Create() creates a mouse input event with the given parameters. Normally
481   * you will get a mouse event passed through the
482   * <code>HandleInputEvent</code> and will not need to create them, but some
483   * applications may want to create their own for internal use. The type must
484   * be one of the mouse event types.
485   *
486   * @param[in] instance The instance for which this event occurred.
487   *
488   * @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of
489   * input event.
490   *
491   * @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time
492   * when the event occurred.
493   *
494   * @param[in] modifiers A bit field combination of the
495   * <code>PP_InputEvent_Modifier</code> flags.
496   *
497   * @param[in] mouse_button The button that changed for mouse down or up
498   * events. This value will be <code>PP_EVENT_MOUSEBUTTON_NONE</code> for
499   * mouse move, enter, and leave events.
500   *
501   * @param[in] mouse_position A <code>Point</code> containing the x and y
502   * position of the mouse when the event occurred.
503   *
504   * @param[in] mouse_movement The change in position of the mouse.
505   *
506   * @return A <code>PP_Resource</code> containing the new mouse input event.
507   */
508  PP_Resource (*Create)(PP_Instance instance,
509                        PP_InputEvent_Type type,
510                        PP_TimeTicks time_stamp,
511                        uint32_t modifiers,
512                        PP_InputEvent_MouseButton mouse_button,
513                        const struct PP_Point* mouse_position,
514                        int32_t click_count,
515                        const struct PP_Point* mouse_movement);
516  /**
517   * IsMouseInputEvent() determines if a resource is a mouse event.
518   *
519   * @param[in] resource A <code>PP_Resource</code> corresponding to an event.
520   *
521   * @return <code>PP_TRUE</code> if the given resource is a valid mouse input
522   * event, otherwise <code>PP_FALSE</code>.
523   */
524  PP_Bool (*IsMouseInputEvent)(PP_Resource resource);
525  /**
526   * GetButton() returns the mouse button that generated a mouse down or up
527   * event.
528   *
529   * @param[in] mouse_event A <code>PP_Resource</code> corresponding to a
530   * mouse event.
531   *
532   * @return The mouse button associated with mouse down and up events. This
533   * value will be <code>PP_EVENT_MOUSEBUTTON_NONE</code> for mouse move,
534   * enter, and leave events, and for all non-mouse events.
535   */
536  PP_InputEvent_MouseButton (*GetButton)(PP_Resource mouse_event);
537  /**
538   * GetPosition() returns the pixel location of a mouse input event. When
539   * the mouse is locked, it returns the last known mouse position just as
540   * mouse lock was entered.
541   *
542   * @param[in] mouse_event A <code>PP_Resource</code> corresponding to a
543   * mouse event.
544   *
545   * @return The point associated with the mouse event, relative to the upper-
546   * left of the instance receiving the event. These values can be negative for
547   * mouse drags. The return value will be (0, 0) for non-mouse events.
548   */
549  struct PP_Point (*GetPosition)(PP_Resource mouse_event);
550  /*
551   * TODO(brettw) figure out exactly what this means.
552   */
553  int32_t (*GetClickCount)(PP_Resource mouse_event);
554  /**
555   * Returns the change in position of the mouse. When the mouse is locked,
556   * although the mouse position doesn't actually change, this function
557   * still provides movement information, which indicates what the change in
558   * position would be had the mouse not been locked.
559   *
560   * @param[in] mouse_event A <code>PP_Resource</code> corresponding to a
561   * mouse event.
562   *
563   * @return The change in position of the mouse, relative to the previous
564   * position.
565   */
566  struct PP_Point (*GetMovement)(PP_Resource mouse_event);
567};
568
569typedef struct PPB_MouseInputEvent_1_1 PPB_MouseInputEvent;
570
571struct PPB_MouseInputEvent_1_0 {
572  PP_Resource (*Create)(PP_Instance instance,
573                        PP_InputEvent_Type type,
574                        PP_TimeTicks time_stamp,
575                        uint32_t modifiers,
576                        PP_InputEvent_MouseButton mouse_button,
577                        const struct PP_Point* mouse_position,
578                        int32_t click_count);
579  PP_Bool (*IsMouseInputEvent)(PP_Resource resource);
580  PP_InputEvent_MouseButton (*GetButton)(PP_Resource mouse_event);
581  struct PP_Point (*GetPosition)(PP_Resource mouse_event);
582  int32_t (*GetClickCount)(PP_Resource mouse_event);
583};
584
585/**
586 * The <code>PPB_WheelIputEvent</code> interface contains pointers to several
587 * functions related to wheel input events.
588 */
589struct PPB_WheelInputEvent_1_0 {
590  /**
591   * Create() creates a wheel input event with the given parameters. Normally
592   * you will get a wheel event passed through the
593   * <code>HandleInputEvent</code> and will not need to create them, but some
594   * applications may want to create their own for internal use.
595   *
596   * @param[in] instance The instance for which this event occurred.
597   *
598   * @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time
599   * when the event occurred.
600   *
601   * @param[in] modifiers A bit field combination of the
602   * <code>PP_InputEvent_Modifier</code> flags.
603   *
604   * @param[in] wheel_delta The scroll wheel's horizontal and vertical scroll
605   * amounts.
606   *
607   * @param[in] wheel_ticks The number of "clicks" of the scroll wheel that
608   * have produced the event.
609   *
610   * @param[in] scroll_by_page When true, the user is requesting to scroll
611   * by pages. When false, the user is requesting to scroll by lines.
612   *
613   * @return A <code>PP_Resource</code> containing the new wheel input event.
614   */
615  PP_Resource (*Create)(PP_Instance instance,
616                        PP_TimeTicks time_stamp,
617                        uint32_t modifiers,
618                        const struct PP_FloatPoint* wheel_delta,
619                        const struct PP_FloatPoint* wheel_ticks,
620                        PP_Bool scroll_by_page);
621  /**
622   * IsWheelInputEvent() determines if a resource is a wheel event.
623   *
624   * @param[in] wheel_event A <code>PP_Resource</code> corresponding to an
625   * event.
626   *
627   * @return <code>PP_TRUE</code> if the given resource is a valid wheel input
628   * event.
629   */
630  PP_Bool (*IsWheelInputEvent)(PP_Resource resource);
631  /**
632   * GetDelta() returns the amount vertically and horizontally the user has
633   * requested to scroll by with their mouse wheel. A scroll down or to the
634   * right (where the content moves up or left) is represented as positive
635   * values, and a scroll up or to the left (where the content moves down or
636   * right) is represented as negative values.
637   *
638   * This amount is system dependent and will take into account the user's
639   * preferred scroll sensitivity and potentially also nonlinear acceleration
640   * based on the speed of the scrolling.
641   *
642   * Devices will be of varying resolution. Some mice with large detents will
643   * only generate integer scroll amounts. But fractional values are also
644   * possible, for example, on some trackpads and newer mice that don't have
645   * "clicks".
646   *
647   * @param[in] wheel_event A <code>PP_Resource</code> corresponding to a wheel
648   * event.
649   *
650   * @return The vertical and horizontal scroll values. The units are either in
651   * pixels (when scroll_by_page is false) or pages (when scroll_by_page is
652   * true). For example, y = -3 means scroll up 3 pixels when scroll_by_page
653   * is false, and scroll up 3 pages when scroll_by_page is true.
654   */
655  struct PP_FloatPoint (*GetDelta)(PP_Resource wheel_event);
656  /**
657   * GetTicks() returns the number of "clicks" of the scroll wheel
658   * that have produced the event. The value may have system-specific
659   * acceleration applied to it, depending on the device. The positive and
660   * negative meanings are the same as for GetDelta().
661   *
662   * If you are scrolling, you probably want to use the delta values.  These
663   * tick events can be useful if you aren't doing actual scrolling and don't
664   * want or pixel values. An example may be cycling between different items in
665   * a game.
666   *
667   * @param[in] wheel_event A <code>PP_Resource</code> corresponding to a wheel
668   * event.
669   *
670   * @return The number of "clicks" of the scroll wheel. You may receive
671   * fractional values for the wheel ticks if the mouse wheel is high
672   * resolution or doesn't have "clicks". If your program wants discrete
673   * events (as in the "picking items" example) you should accumulate
674   * fractional click values from multiple messages until the total value
675   * reaches positive or negative one. This should represent a similar amount
676   * of scrolling as for a mouse that has a discrete mouse wheel.
677   */
678  struct PP_FloatPoint (*GetTicks)(PP_Resource wheel_event);
679  /**
680   * GetScrollByPage() indicates if the scroll delta x/y indicates pages or
681   * lines to scroll by.
682   *
683   * @param[in] wheel_event A <code>PP_Resource</code> corresponding to a wheel
684   * event.
685   *
686   * @return <code>PP_TRUE</code> if the event is a wheel event and the user is
687   * scrolling by pages. <code>PP_FALSE</code> if not or if the resource is not
688   * a wheel event.
689   */
690  PP_Bool (*GetScrollByPage)(PP_Resource wheel_event);
691};
692
693typedef struct PPB_WheelInputEvent_1_0 PPB_WheelInputEvent;
694
695/**
696 * The <code>PPB_KeyboardInputEvent</code> interface contains pointers to
697 * several functions related to keyboard input events.
698 */
699struct PPB_KeyboardInputEvent_1_2 {
700  /**
701   * Creates a keyboard input event with the given parameters. Normally you
702   * will get a keyboard event passed through the HandleInputEvent and will not
703   * need to create them, but some applications may want to create their own
704   * for internal use. The type must be one of the keyboard event types.
705   *
706   * @param[in] instance The instance for which this event occurred.
707   *
708   * @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of
709   * input event.
710   *
711   * @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time
712   * when the event occurred.
713   *
714   * @param[in] modifiers A bit field combination of the
715   * <code>PP_InputEvent_Modifier</code> flags.
716   *
717   * @param[in] key_code This value reflects the DOM KeyboardEvent
718   * <code>keyCode</code> field, which is the Windows-style Virtual Key
719   * code of the key.
720   *
721   * @param[in] character_text This value represents the typed character as a
722   * UTF-8 string.
723   *
724   * @param[in] code This value represents the DOM3 |code| string that
725   * corresponds to the physical key being pressed.
726   *
727   * @return A <code>PP_Resource</code> containing the new keyboard input
728   * event.
729   */
730  PP_Resource (*Create)(PP_Instance instance,
731                        PP_InputEvent_Type type,
732                        PP_TimeTicks time_stamp,
733                        uint32_t modifiers,
734                        uint32_t key_code,
735                        struct PP_Var character_text,
736                        struct PP_Var code);
737  /**
738   * IsKeyboardInputEvent() determines if a resource is a keyboard event.
739   *
740   * @param[in] resource A <code>PP_Resource</code> corresponding to an event.
741   *
742   * @return <code>PP_TRUE</code> if the given resource is a valid input event.
743   */
744  PP_Bool (*IsKeyboardInputEvent)(PP_Resource resource);
745  /**
746   * GetKeyCode() returns the DOM keyCode field for the keyboard event.
747   * Chrome populates this with the Windows-style Virtual Key code of the key.
748   *
749   * @param[in] key_event A <code>PP_Resource</code> corresponding to a
750   * keyboard event.
751   *
752   * @return The DOM keyCode field for the keyboard event.
753   */
754  uint32_t (*GetKeyCode)(PP_Resource key_event);
755  /**
756   * GetCharacterText() returns the typed character as a UTF-8 string for the
757   * given character event.
758   *
759   * @param[in] character_event A <code>PP_Resource</code> corresponding to a
760   * keyboard event.
761   *
762   * @return A string var representing a single typed character for character
763   * input events. For non-character input events the return value will be an
764   * undefined var.
765   */
766  struct PP_Var (*GetCharacterText)(PP_Resource character_event);
767  /**
768   * GetCode() returns the DOM |code| field for this keyboard event, as
769   * defined in the DOM3 Events spec:
770   * http://www.w3.org/TR/DOM-Level-3-Events/
771   *
772   * @param[in] key_event The key event for which to return the key code.
773   *
774   * @return The string that contains the DOM |code| for the keyboard event.
775   */
776  struct PP_Var (*GetCode)(PP_Resource key_event);
777};
778
779typedef struct PPB_KeyboardInputEvent_1_2 PPB_KeyboardInputEvent;
780
781struct PPB_KeyboardInputEvent_1_0 {
782  PP_Resource (*Create)(PP_Instance instance,
783                        PP_InputEvent_Type type,
784                        PP_TimeTicks time_stamp,
785                        uint32_t modifiers,
786                        uint32_t key_code,
787                        struct PP_Var character_text);
788  PP_Bool (*IsKeyboardInputEvent)(PP_Resource resource);
789  uint32_t (*GetKeyCode)(PP_Resource key_event);
790  struct PP_Var (*GetCharacterText)(PP_Resource character_event);
791};
792/**
793 * @}
794 */
795
796/**
797 * @addtogroup Enums
798 * @{
799 */
800typedef enum {
801  /**
802   * The list of all TouchPoints which are currently down.
803   */
804  PP_TOUCHLIST_TYPE_TOUCHES = 0,
805  /**
806   * The list of all TouchPoints whose state has changed since the last
807   * TouchInputEvent.
808   */
809  PP_TOUCHLIST_TYPE_CHANGEDTOUCHES = 1,
810  /**
811   * The list of all TouchPoints which are targeting this plugin.  This is a
812   * subset of Touches.
813   */
814  PP_TOUCHLIST_TYPE_TARGETTOUCHES = 2
815} PP_TouchListType;
816PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TouchListType, 4);
817/**
818 * @}
819 */
820
821/**
822 * @addtogroup Interfaces
823 * @{
824 */
825/**
826 * The <code>PPB_TouchInputEvent</code> interface contains pointers to several
827 * functions related to touch events.
828 */
829struct PPB_TouchInputEvent_1_0 {
830  /**
831   * Creates a touch input event with the given parameters. Normally you
832   * will get a touch event passed through the HandleInputEvent and will not
833   * need to create them, but some applications may want to create their own
834   * for internal use. The type must be one of the touch event types.
835   * This newly created touch input event does not have any touch point in any
836   * of the touch-point lists. <code>AddTouchPoint</code> should be called to
837   * add the touch-points.
838   *
839   * @param[in] instance The instance for which this event occurred.
840   *
841   * @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of
842   * input event.
843   *
844   * @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time
845   * when the event occurred.
846   *
847   * @param[in]  modifiers A bit field combination of the
848   * <code>PP_InputEvent_Modifier</code> flags.
849   *
850   * @return A <code>PP_Resource</code> containing the new touch input event.
851   */
852  PP_Resource (*Create)(PP_Instance instance,
853                        PP_InputEvent_Type type,
854                        PP_TimeTicks time_stamp,
855                        uint32_t modifiers);
856  /**
857   * Adds a touch point to the touch event in the specified touch-list.
858   *
859   * @param[in] touch_event A <code>PP_Resource</code> corresponding to a touch
860   * event.
861   *
862   * @param[in] list The list to add the touch point to.
863   *
864   * @param[in] point The point to add to the list.
865   */
866  void (*AddTouchPoint)(PP_Resource touch_event,
867                        PP_TouchListType list,
868                        const struct PP_TouchPoint* point);
869  /**
870   * IsTouchInputEvent() determines if a resource is a touch event.
871   *
872   * @param[in] resource A <code>PP_Resource</code> corresponding to an event.
873   *
874   * @return <code>PP_TRUE</code> if the given resource is a valid touch input
875   * event, otherwise <code>PP_FALSE</code>.
876   */
877  PP_Bool (*IsTouchInputEvent)(PP_Resource resource);
878  /**
879   * Returns the number of touch-points in the specified list.
880   *
881   * @param[in] resource A <code>PP_Resource</code> corresponding to a touch
882   * event.
883   *
884   * @param[in] list The list.
885   *
886   * @return The number of touch-points in the specified list.
887   */
888  uint32_t (*GetTouchCount)(PP_Resource resource, PP_TouchListType list);
889  /**
890   * Returns the touch-point at the specified index from the specified list.
891   *
892   * @param[in] resource A <code>PP_Resource</code> corresponding to a touch
893   * event.
894   *
895   * @param[in] list The list.
896   *
897   * @param[in] index The index.
898   *
899   * @return A <code>PP_TouchPoint</code> representing the touch-point.
900   */
901  struct PP_TouchPoint (*GetTouchByIndex)(PP_Resource resource,
902                                          PP_TouchListType list,
903                                          uint32_t index);
904  /**
905   * Returns the touch-point with the specified touch-id in the specified list.
906   *
907   * @param[in] resource A <code>PP_Resource</code> corresponding to a touch
908   * event.
909   *
910   * @param[in] list The list.
911   *
912   * @param[in] touch_id The id of the touch-point.
913   *
914   * @return A <code>PP_TouchPoint</code> representing the touch-point.
915   */
916  struct PP_TouchPoint (*GetTouchById)(PP_Resource resource,
917                                       PP_TouchListType list,
918                                       uint32_t touch_id);
919};
920
921typedef struct PPB_TouchInputEvent_1_0 PPB_TouchInputEvent;
922
923struct PPB_IMEInputEvent_1_0 {
924  /**
925   * Create() creates an IME input event with the given parameters. Normally
926   * you will get an IME event passed through the <code>HandleInputEvent</code>
927   * and will not need to create them, but some applications may want to create
928   * their own for internal use.
929   *
930   * @param[in] instance The instance for which this event occurred.
931   *
932   * @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of
933   * input event. The type must be one of the IME event types.
934   *
935   * @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time
936   * when the event occurred.
937   *
938   * @param[in] text The string returned by <code>GetText</code>.
939   *
940   * @param[in] segment_number The number returned by
941   * <code>GetSegmentNumber</code>.
942   *
943   * @param[in] segment_offsets The array of numbers returned by
944   * <code>GetSegmentOffset</code>. If <code>segment_number</code> is zero,
945   * the number of elements of the array should be zero. If
946   * <code>segment_number</code> is non-zero, the length of the array must be
947   * <code>segment_number</code> + 1.
948   *
949   * @param[in] target_segment The number returned by
950   * <code>GetTargetSegment</code>.
951   *
952   * @param[in] selection_start The start index returned by
953   * <code>GetSelection</code>.
954   *
955   * @param[in] selection_end The end index returned by
956   * <code>GetSelection</code>.
957   *
958   * @return A <code>PP_Resource</code> containing the new IME input event.
959   */
960  PP_Resource (*Create)(PP_Instance instance,
961                        PP_InputEvent_Type type,
962                        PP_TimeTicks time_stamp,
963                        struct PP_Var text,
964                        uint32_t segment_number,
965                        const uint32_t segment_offsets[],
966                        int32_t target_segment,
967                        uint32_t selection_start,
968                        uint32_t selection_end);
969  /**
970   * IsIMEInputEvent() determines if a resource is an IME event.
971   *
972   * @param[in] resource A <code>PP_Resource</code> corresponding to an event.
973   *
974   * @return <code>PP_TRUE</code> if the given resource is a valid input event.
975   */
976  PP_Bool (*IsIMEInputEvent)(PP_Resource resource);
977  /**
978   * GetText() returns the composition text as a UTF-8 string for the given IME
979   * event.
980   *
981   * @param[in] ime_event A <code>PP_Resource</code> corresponding to an IME
982   * event.
983   *
984   * @return A string var representing the composition text. For non-IME input
985   * events the return value will be an undefined var.
986   */
987  struct PP_Var (*GetText)(PP_Resource ime_event);
988  /**
989   * GetSegmentNumber() returns the number of segments in the composition text.
990   *
991   * @param[in] ime_event A <code>PP_Resource</code> corresponding to an IME
992   * event.
993   *
994   * @return The number of segments. For events other than COMPOSITION_UPDATE,
995   * returns 0.
996   */
997  uint32_t (*GetSegmentNumber)(PP_Resource ime_event);
998  /**
999   * GetSegmentOffset() returns the position of the index-th segmentation point
1000   * in the composition text. The position is given by a byte-offset (not a
1001   * character-offset) of the string returned by GetText(). It always satisfies
1002   * 0=GetSegmentOffset(0) < ... < GetSegmentOffset(i) < GetSegmentOffset(i+1)
1003   * < ... < GetSegmentOffset(GetSegmentNumber())=(byte-length of GetText()).
1004   * Note that [GetSegmentOffset(i), GetSegmentOffset(i+1)) represents the range
1005   * of the i-th segment, and hence GetSegmentNumber() can be a valid argument
1006   * to this function instead of an off-by-1 error.
1007   *
1008   * @param[in] ime_event A <code>PP_Resource</code> corresponding to an IME
1009   * event.
1010   *
1011   * @param[in] index An integer indicating a segment.
1012   *
1013   * @return The byte-offset of the segmentation point. If the event is not
1014   * COMPOSITION_UPDATE or index is out of range, returns 0.
1015   */
1016  uint32_t (*GetSegmentOffset)(PP_Resource ime_event, uint32_t index);
1017  /**
1018   * GetTargetSegment() returns the index of the current target segment of
1019   * composition.
1020   *
1021   * @param[in] ime_event A <code>PP_Resource</code> corresponding to an IME
1022   * event.
1023   *
1024   * @return An integer indicating the index of the target segment. When there
1025   * is no active target segment, or the event is not COMPOSITION_UPDATE,
1026   * returns -1.
1027   */
1028  int32_t (*GetTargetSegment)(PP_Resource ime_event);
1029  /**
1030   * GetSelection() returns the range selected by caret in the composition text.
1031   *
1032   * @param[in] ime_event A <code>PP_Resource</code> corresponding to an IME
1033   * event.
1034   *
1035   * @param[out] start The start position of the current selection.
1036   *
1037   * @param[out] end The end position of the current selection.
1038   */
1039  void (*GetSelection)(PP_Resource ime_event, uint32_t* start, uint32_t* end);
1040};
1041
1042typedef struct PPB_IMEInputEvent_1_0 PPB_IMEInputEvent;
1043/**
1044 * @}
1045 */
1046
1047#endif  /* PPAPI_C_PPB_INPUT_EVENT_H_ */
1048
1049