summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-07 15:38:48 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-07 15:38:48 +0000
commit493d1421853518d3b16a7b103311ea4fa1988341 (patch)
treeabc9bd73da85786a933666c8c6042a62aabd7c4b /ppapi
parentb18d98d7de474db2a2057d0e3aaaac9bd87a2f41 (diff)
downloadchromium_src-493d1421853518d3b16a7b103311ea4fa1988341.zip
chromium_src-493d1421853518d3b16a7b103311ea4fa1988341.tar.gz
chromium_src-493d1421853518d3b16a7b103311ea4fa1988341.tar.bz2
Add interfaces for requesting and receiving input event resources.
This converts the input event from a C struct to a resource to give us more ability to change over time. This patch includes a proxy and a C++ wrapper for this resource. You now have to register for classes of input events. No events are sent by default. This also allows us to specify whether the events support bubbling or not, which allows us to better-optimize IPC. TEST=none BUG=none Review URL: http://codereview.chromium.org/7285010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91711 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/c/pp_errors.h5
-rw-r--r--ppapi/c/pp_input_event.h74
-rw-r--r--ppapi/c/pp_point.h19
-rw-r--r--ppapi/c/ppb_input_event.h485
-rw-r--r--ppapi/c/ppp_input_event.h41
-rw-r--r--ppapi/cpp/input_event.cc172
-rw-r--r--ppapi/cpp/input_event.h180
-rw-r--r--ppapi/cpp/instance.cc31
-rw-r--r--ppapi/cpp/instance.h8
-rw-r--r--ppapi/cpp/module.cc26
-rw-r--r--ppapi/cpp/point.h141
-rw-r--r--ppapi/example/example.cc10
-rw-r--r--ppapi/ppapi_cpp.gypi4
-rw-r--r--ppapi/ppapi_proxy.gypi4
-rw-r--r--ppapi/ppapi_shared.gypi6
-rw-r--r--ppapi/proxy/dispatcher.cc4
-rw-r--r--ppapi/proxy/interface_id.h1
-rw-r--r--ppapi/proxy/ppapi_messages.h40
-rw-r--r--ppapi/proxy/ppb_input_event_proxy.cc102
-rw-r--r--ppapi/proxy/ppb_input_event_proxy.h40
-rw-r--r--ppapi/proxy/ppb_instance_proxy.cc52
-rw-r--r--ppapi/proxy/ppb_instance_proxy.h13
-rw-r--r--ppapi/proxy/ppp_input_event_proxy.cc115
-rw-r--r--ppapi/proxy/ppp_input_event_proxy.h46
-rw-r--r--ppapi/shared_impl/input_event_impl.cc79
-rw-r--r--ppapi/shared_impl/input_event_impl.h75
-rw-r--r--ppapi/shared_impl/instance_impl.cc34
-rw-r--r--ppapi/shared_impl/instance_impl.h23
-rw-r--r--ppapi/shared_impl/resource_object_base.h1
-rw-r--r--ppapi/tests/all_c_includes.h2
-rw-r--r--ppapi/thunk/ppb_input_event_api.h40
-rw-r--r--ppapi/thunk/ppb_input_event_thunk.cc210
-rw-r--r--ppapi/thunk/ppb_instance_api.h8
-rw-r--r--ppapi/thunk/thunk.h8
34 files changed, 2019 insertions, 80 deletions
diff --git a/ppapi/c/pp_errors.h b/ppapi/c/pp_errors.h
index f909587..a029e16 100644
--- a/ppapi/c/pp_errors.h
+++ b/ppapi/c/pp_errors.h
@@ -72,6 +72,11 @@ enum {
*/
PP_ERROR_INPROGRESS = -11,
+ /**
+ * The requested command is not supported by the browser.
+ */
+ PP_ERROR_NOTSUPPORTED = -12,
+
/** This value indicates failure due to a file that does not exist. */
PP_ERROR_FILENOTFOUND = -20,
diff --git a/ppapi/c/pp_input_event.h b/ppapi/c/pp_input_event.h
index 1787a2d..4726e74 100644
--- a/ppapi/c/pp_input_event.h
+++ b/ppapi/c/pp_input_event.h
@@ -14,79 +14,7 @@
#include "ppapi/c/pp_macros.h"
#include "ppapi/c/pp_stdint.h"
#include "ppapi/c/pp_time.h"
-
-/**
- *
- * @addtogroup Enums
- * @{
- */
-
-/**
- * This enumeration contains constants representing each mouse button.
- */
-typedef enum {
- PP_INPUTEVENT_MOUSEBUTTON_NONE = -1,
- PP_INPUTEVENT_MOUSEBUTTON_LEFT = 0,
- PP_INPUTEVENT_MOUSEBUTTON_MIDDLE = 1,
- PP_INPUTEVENT_MOUSEBUTTON_RIGHT = 2
-} PP_InputEvent_MouseButton;
-PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_MouseButton, 4);
-/**
- * @}
- */
-
-/**
- * @addtogroup Enums
- * @{
- */
-
-/**
- * This enumeration contains mouse and keyboard event constants.
- */
-typedef enum {
- PP_INPUTEVENT_TYPE_UNDEFINED = -1,
- PP_INPUTEVENT_TYPE_MOUSEDOWN = 0, // PP_InputEvent_Mouse
- PP_INPUTEVENT_TYPE_MOUSEUP = 1, // PP_InputEvent_Mouse
- PP_INPUTEVENT_TYPE_MOUSEMOVE = 2, // PP_InputEvent_Mouse
- PP_INPUTEVENT_TYPE_MOUSEENTER = 3, // PP_InputEvent_Mouse
- PP_INPUTEVENT_TYPE_MOUSELEAVE = 4, // PP_InputEvent_Mouse
- PP_INPUTEVENT_TYPE_MOUSEWHEEL = 5, // PP_InputEvent_Wheel
- PP_INPUTEVENT_TYPE_RAWKEYDOWN = 6, // PP_InputEvent_Key
- PP_INPUTEVENT_TYPE_KEYDOWN = 7, // PP_InputEvent_Key
- PP_INPUTEVENT_TYPE_KEYUP = 8, // PP_InputEvent_Key
- PP_INPUTEVENT_TYPE_CHAR = 9, // PP_InputEvent_Character
- PP_INPUTEVENT_TYPE_CONTEXTMENU = 10 // PP_InputEvent_Mouse
-} PP_InputEvent_Type;
-PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_Type, 4);
-/**
- * @}
- */
-
-/**
- * @addtogroup Enums
- * @{
- */
-
-/**
- * This enumeration contains event modifier constants.
- */
-typedef enum {
- PP_INPUTEVENT_MODIFIER_SHIFTKEY = 1 << 0,
- PP_INPUTEVENT_MODIFIER_CONTROLKEY = 1 << 1,
- PP_INPUTEVENT_MODIFIER_ALTKEY = 1 << 2,
- PP_INPUTEVENT_MODIFIER_METAKEY = 1 << 3,
- PP_INPUTEVENT_MODIFIER_ISKEYPAD = 1 << 4,
- PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT = 1 << 5,
- PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN = 1 << 6,
- PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN = 1 << 7,
- PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN = 1 << 8,
- PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY = 1 << 9,
- PP_INPUTEVENT_MODIFIER_NUMLOCKKEY = 1 << 10
-} PP_InputEvent_Modifier;
-PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_Modifier, 4);
-/**
- * @}
- */
+#include "ppapi/c/ppb_input_event.h"
/**
* @addtogroup Structs
diff --git a/ppapi/c/pp_point.h b/ppapi/c/pp_point.h
index 15b13f3..ed5f3d3 100644
--- a/ppapi/c/pp_point.h
+++ b/ppapi/c/pp_point.h
@@ -21,7 +21,7 @@
*/
/**
- * The PP_Point structure defines the x and y coordinates of a point.
+ * The PP_Point structure defines the integer x and y coordinates of a point.
*/
struct PP_Point {
/**
@@ -37,6 +37,16 @@ struct PP_Point {
int32_t y;
};
PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_Point, 8);
+
+/**
+ * The PP_FloatPoint structure defines the floating-point x and y coordinates
+ * of a point.
+ */
+struct PP_FloatPoint {
+ float x;
+ float y;
+};
+PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_FloatPoint, 8);
/**
* @}
*/
@@ -61,6 +71,13 @@ PP_INLINE struct PP_Point PP_MakePoint(int32_t x, int32_t y) {
ret.y = y;
return ret;
}
+
+PP_INLINE struct PP_FloatPoint PP_MakeFloatPoint(float x, float y) {
+ struct PP_FloatPoint ret;
+ ret.x = x;
+ ret.y = y;
+ return ret;
+}
/**
* @}
*/
diff --git a/ppapi/c/ppb_input_event.h b/ppapi/c/ppb_input_event.h
new file mode 100644
index 0000000..0d33c74
--- /dev/null
+++ b/ppapi/c/ppb_input_event.h
@@ -0,0 +1,485 @@
+/* Copyright (c) 2011 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef PPAPI_C_PPB_INPUT_EVENT_H_
+#define PPAPI_C_PPB_INPUT_EVENT_H_
+
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/c/pp_macros.h"
+#include "ppapi/c/pp_point.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/c/pp_stdint.h"
+#include "ppapi/c/pp_time.h"
+#include "ppapi/c/pp_var.h"
+
+#define PPB_INPUT_EVENT_INTERFACE_0_1 "PPB_InputEvent;0.1"
+#define PPB_INPUT_EVENT_INTERFACE PPB_INPUT_EVENT_INTERFACE_0_1
+
+#define PPB_MOUSE_INPUT_EVENT_INTERFACE_0_1 "PPB_MouseInputEvent;0.1"
+#define PPB_MOUSE_INPUT_EVENT_INTERFACE PPB_MOUSE_INPUT_EVENT_INTERFACE_0_1
+
+#define PPB_WHEEL_INPUT_EVENT_INTERFACE_0_1 "PPB_WheelInputEvent;0.1"
+#define PPB_WHEEL_INPUT_EVENT_INTERFACE PPB_WHEEL_INPUT_EVENT_INTERFACE_0_1
+
+#define PPB_KEYBOARD_INPUT_EVENT_INTERFACE_0_1 "PPB_KeyboardInputEvent;0.1"
+#define PPB_KEYBOARD_INPUT_EVENT_INTERFACE \
+ PPB_KEYBOARD_INPUT_EVENT_INTERFACE_0_1
+
+/**
+ * @addtogroup Enums
+ * @{
+ */
+
+/**
+ * This enumeration contains the types of input events.
+ */
+typedef enum {
+ PP_INPUTEVENT_TYPE_UNDEFINED = -1,
+
+ /**
+ * Notification that a mouse button was pressed.
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_MOUSE class.
+ */
+ PP_INPUTEVENT_TYPE_MOUSEDOWN = 0,
+
+ /**
+ * Notification that a mouse button was released.
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_MOUSE class.
+ */
+ PP_INPUTEVENT_TYPE_MOUSEUP = 1,
+
+ /**
+ * Notification that a mouse button was moved when it is over the instance
+ * or dragged out of it.
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_MOUSE class.
+ */
+ PP_INPUTEVENT_TYPE_MOUSEMOVE = 2,
+
+ /**
+ * Notification that the mouse entered the instance's bounds.
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_MOUSE class.
+ */
+ PP_INPUTEVENT_TYPE_MOUSEENTER = 3,
+
+ /**
+ * Notification that a mouse left the instance's bounds.
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_MOUSE class.
+ */
+ PP_INPUTEVENT_TYPE_MOUSELEAVE = 4,
+
+ /**
+ * Notification that the scroll wheel was used.
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_WHEEL class.
+ */
+ PP_INPUTEVENT_TYPE_MOUSEWHEEL = 5,
+
+ /**
+ * Notification that a key transitioned from "up" to "down".
+ * TODO(brettw) differentiate from KEYDOWN.
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_KEYBOARD class.
+ */
+ PP_INPUTEVENT_TYPE_RAWKEYDOWN = 6,
+
+ /**
+ * Notification that a key was pressed. This does not necessarily correspond
+ * to a character depending on the key and language. Use the
+ * PP_INPUTEVENT_TYPE_CHAR for character input.
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_KEYBOARD class.
+ */
+ PP_INPUTEVENT_TYPE_KEYDOWN = 7,
+
+ /**
+ * Notification that a key was released.
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_KEYBOARD class.
+ */
+ PP_INPUTEVENT_TYPE_KEYUP = 8,
+
+ /**
+ * Notification that a character was typed. Use this for text input. Key
+ * down events may generate 0, 1, or more than one character event depending
+ * on the key, locale, and operating system.
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_KEYBOARD class.
+ */
+ PP_INPUTEVENT_TYPE_CHAR = 9,
+
+ /**
+ * TODO(brettw) when is this used?
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_MOUSE class.
+ */
+ PP_INPUTEVENT_TYPE_CONTEXTMENU = 10
+} PP_InputEvent_Type;
+PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_Type, 4);
+
+/**
+ * This enumeration contains event modifier constants. Each modifier is one
+ * bit. Retrieve the modifiers from an input event using the GetEventModifiers
+ * function on PPB_InputEvent.
+ */
+typedef enum {
+ PP_INPUTEVENT_MODIFIER_SHIFTKEY = 1 << 0,
+ PP_INPUTEVENT_MODIFIER_CONTROLKEY = 1 << 1,
+ PP_INPUTEVENT_MODIFIER_ALTKEY = 1 << 2,
+ PP_INPUTEVENT_MODIFIER_METAKEY = 1 << 3,
+ PP_INPUTEVENT_MODIFIER_ISKEYPAD = 1 << 4,
+ PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT = 1 << 5,
+ PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN = 1 << 6,
+ PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN = 1 << 7,
+ PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN = 1 << 8,
+ PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY = 1 << 9,
+ PP_INPUTEVENT_MODIFIER_NUMLOCKKEY = 1 << 10
+} PP_InputEvent_Modifier;
+PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_Modifier, 4);
+
+/**
+ * This enumeration contains constants representing each mouse button. To get
+ * the mouse button for a mouse down or up event, use GetMouseButton on
+ * PPB_InputEvent.
+ */
+typedef enum {
+ PP_INPUTEVENT_MOUSEBUTTON_NONE = -1,
+ PP_INPUTEVENT_MOUSEBUTTON_LEFT = 0,
+ PP_INPUTEVENT_MOUSEBUTTON_MIDDLE = 1,
+ PP_INPUTEVENT_MOUSEBUTTON_RIGHT = 2
+} PP_InputEvent_MouseButton;
+PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_MouseButton, 4);
+
+/**
+ * @}
+ */
+
+typedef enum {
+ /**
+ * Request mouse input events.
+ *
+ * Normally you will request mouse events by calling RequestInputEvents().
+ * The only use case for filtered events (via RequestFilteringInputEvents())
+ * is for instances that have irregular outlines and you want to perform hit
+ * testing, which is very uncommon. Requesting non-filtered mouse events will
+ * lead to higher performance.
+ */
+ PP_INPUTEVENT_CLASS_MOUSE = 1 << 0,
+
+ /**
+ * Requests keyboard events. Keyboard events must be requested in filtering
+ * mode via RequestFilteringInputEvents(). This is because many commands
+ * should be forwarded to the page.
+ *
+ * A small number of tab and window management commands like Alt-F4 are never
+ * sent to the page. You can not request these keyboard commands since it
+ * would allow pages to trap users on a page.
+ */
+ PP_INPUTEVENT_CLASS_KEYBOARD = 1 << 1,
+
+ /**
+ * Identifies scroll wheel input event. Wheel events must be requested in
+ * filtering mode via RequestFilteringInputEvents(). This is because many
+ * wheel commands should be forwarded to the page.
+ *
+ * Most instances will not need this event. Consuming wheel events by
+ * returning true from your filtered event handler will prevent the user from
+ * scrolling the page when the mouse is over the instance which can be very
+ * annoying.
+ *
+ * If you handle wheel events (for example, you have a document viewer which
+ * the user can scroll), the recommended behavior is to return false only if
+ * the wheel event actually causes your document to scroll. When the user
+ * reaches the end of the document, return false to indicating that the event
+ * was not handled. This will then forward the event to the containing page
+ * for scrolling, producing the nested scrolling behavior users expect from
+ * frames in a page.
+ */
+ PP_INPUTEVENT_CLASS_WHEEL = 1 << 2,
+
+ /**
+ * Identifies touch input events.
+ *
+ * Request touch events only if you intend to handle them. If the browser
+ * knows you do not need to handle touch events, it can handle them at a
+ * higher level and achieve higher performance.
+ */
+ PP_INPUTEVENT_CLASS_TOUCH = 1 << 3,
+
+ /**
+ * Identifies IME composition input events.
+ *
+ * Request this input event class if you allow on-the-spot IME input.
+ */
+ PP_INPUTEVENT_CLASS_IME = 1 << 4
+} PP_InputEvent_Class;
+PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_Class, 4);
+
+struct PPB_InputEvent {
+ /**
+ * Request that input events corresponding to the given input events are
+ * delivered to the instance.
+ *
+ * You can not use this function to request keyboard events
+ * (PP_INPUTEVENT_CLASS_KEYBOARD). You must use RequestFilteringInputEvents()
+ * for this class of input.
+ *
+ * By default, no input events are delivered. Call this function with the
+ * classes of events you are interested in to have them be delivered to
+ * the instance. Calling this function will override any previous setting for
+ * each specified class of input events (for example, if you previously
+ * called RequestFilteringInputEvents(), this function will set those events
+ * to non-filtering mode).
+ *
+ * Input events may have high overhead, so you should only request input
+ * events that your plugin will actually handle. For example, the browser may
+ * do optimizations for scroll or touch events that can be processed
+ * substantially faster if it knows there are no non-default receivers for
+ * that message. Requesting that such messages be delivered, even if they are
+ * processed very quickly, may have a noticable effect on the performance of
+ * the page.
+ *
+ * When requesting input events through this function, the events will be
+ * delivered and <i>not</i> bubbled to the page. This means that even if you
+ * aren't interested in the message, no other parts of the page will get
+ * a crack at the message.
+ *
+ * Example:
+ * RequestInputEvents(instance, PP_INPUTEVENT_CLASS_MOUSE);
+ * RequestFilteringInputEvents(instance,
+ * PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD);
+ *
+ * @param instance The <code>PP_Instance</code> of the instance requesting
+ * the given events.
+ *
+ * @param event_classes A combination of flags from PP_InputEvent_Class that
+ * identifies the classes of events the instance is requesting. The flags
+ * are combined by logically ORing their values.
+ *
+ * @return PP_OK if the operation succeeded, PP_ERROR_BADARGUMENT if instance
+ * is invalid, or PP_ERROR_NOTSUPPORTED if one of the event class bits were
+ * illegal. In the case of an invalid bit, all valid bits will be applied
+ * and only the illegal bits will be ignored. The most common cause of a
+ * PP_ERROR_NOTSUPPORTED return value is requesting keyboard events, these
+ * must use RequestFilteringInputEvents().
+ */
+ int32_t (*RequestInputEvents)(PP_Instance instance,
+ uint32_t event_classes);
+
+ /**
+ * Request that input events corresponding to the given input events are
+ * delivered to the instance for filtering.
+ *
+ * By default, no input events are delivered. In most cases you would
+ * register to receive events by calling RequestInputEvents(). In some cases,
+ * however, you may wish to filter events such that they can be bubbled up
+ * to the DOM. In this case, register for those classes of events using
+ * this function instead of RequestInputEvents(). Keyboard events must always
+ * be registered in filtering mode.
+ *
+ * Filtering input events requires significantly more overhead than just
+ * delivering them to the instance. As such, you should only request
+ * filtering in those cases where it's absolutely necessary. The reason is
+ * that it requires the browser to stop and block for the instance to handle
+ * the input event, rather than sending the input event asynchronously. This
+ * can have significant overhead.
+ *
+ * Example:
+ * RequestInputEvents(instance, PP_INPUTEVENT_CLASS_MOUSE);
+ * RequestFilteringInputEvents(instance,
+ * PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD);
+ *
+ * @return PP_OK if the operation succeeded, PP_ERROR_BADARGUMENT if instance
+ * is invalid, or PP_ERROR_NOTSUPPORTED if one of the event class bits were
+ * illegal. In the case of an invalid bit, all valid bits will be applied
+ * and only the illegal bits will be ignored.
+ */
+ int32_t (*RequestFilteringInputEvents)(PP_Instance instance,
+ uint32_t event_classes);
+
+ /**
+ * Request that input events corresponding to the given input classes no
+ * longer be delivered to the instance.
+ *
+ * By default, no input events are delivered. If you have previously
+ * requested input events via RequestInputEvents() or
+ * RequestFilteringInputEvents(), this function will unregister handling
+ * for the given instance. This will allow greater browser performance for
+ * those events.
+ *
+ * Note that you may still get some input events after clearing the flag if
+ * they were dispatched before the request was cleared. For example, if
+ * there are 3 mouse move events waiting to be delivered, and you clear the
+ * mouse event class during the processing of the first one, you'll still
+ * receive the next two. You just won't get more events generated.
+ *
+ * @param instance The <code>PP_Instance</code> of the instance requesting
+ * to no longer receive the given events.
+ *
+ * @param event_classes A combination of flags from PP_InputEvent_Class that
+ * identifies the classes of events the instance is no longer interested in.
+ */
+ void (*ClearInputEventRequest)(PP_Instance instance,
+ uint32_t event_classes);
+
+ /**
+ * Returns true if the given resource is a valid input event resource.
+ */
+ PP_Bool (*IsInputEvent)(PP_Resource resource);
+
+ /**
+ * Returns the type of input event for the given input event resource.
+ * This is valid for all input events. Returns PP_INPUTEVENT_TYPE_UNDEFINED
+ * if the resource is invalid.
+ */
+ PP_InputEvent_Type (*GetType)(PP_Resource event);
+
+ /**
+ * Returns the time that the event was generated. This will be before the
+ * current time since processing and dispatching the event has some overhead.
+ * Use this value to compare the times the user generated two events without
+ * being sensitive to variable processing time.
+ *
+ * The return value is in time ticks, which is a monotonically increasing
+ * clock not related to the wall clock time. It will not change if the user
+ * changes their clock or daylight savings time starts, so can be reliably
+ * used to compare events. This means, however, that you can't correlate
+ * event times to a particular time of day on the system clock.
+ */
+ PP_TimeTicks (*GetTimeStamp)(PP_Resource event);
+
+ /**
+ * Returns a bitfield indicating which modifiers were down at the time of
+ * the event. This is a combination of the flags in the
+ * PP_InputEvent_Modifier enum.
+ *
+ * @return The modifiers associated with the event, or 0 if the given
+ * resource is not a valid event resource.
+ */
+ uint32_t (*GetModifiers)(PP_Resource event);
+};
+
+struct PPB_MouseInputEvent {
+ /**
+ * Determines if a resource is a mouse event.
+ *
+ * @return PP_TRUE if the given resource is a valid mouse input event.
+ */
+ PP_Bool (*IsMouseInputEvent)(PP_Resource resource);
+
+ /**
+ * Returns which mouse button generated a mouse down or up event.
+ *
+ * @return The mouse button associated with mouse down and up events. This
+ * value will be PP_EVENT_MOUSEBUTTON_NONE for mouse move, enter, and leave
+ * events, and for all non-mouse events.
+ */
+ PP_InputEvent_MouseButton (*GetMouseButton)(PP_Resource mouse_event);
+
+ /**
+ * Returns the pixel location of a mouse input event.
+ *
+ * @return The point associated with the mouse event, relative to the upper-
+ * left of the instance receiving the event. These values can be negative for
+ * mouse drags. The return value will be (0, 0) for non-mouse events.
+ */
+ struct PP_Point (*GetMousePosition)(PP_Resource mouse_event);
+
+ /**
+ * TODO(brettw) figure out exactly what this means.
+ */
+ int32_t (*GetMouseClickCount)(PP_Resource mouse_event);
+};
+
+struct PPB_WheelInputEvent {
+ /**
+ * Determines if a resource is a wheel event.
+ *
+ * @return PP_TRUE if the given resource is a valid wheel input event.
+ */
+ PP_Bool (*IsWheelInputEvent)(PP_Resource resource);
+
+ /**
+ * Indicates the amount vertically and horizontally the user has requested
+ * to scroll by with their mouse wheel. A scroll down or to the right (where
+ * the content moves up or left) is represented as positive values, and
+ * a scroll up or to the left (where the content moves down or right) is
+ * represented as negative values.
+ *
+ * The units are either in pixels (when scroll_by_page is false) or pages
+ * (when scroll_by_page is true). For example, y = -3 means scroll up 3
+ * pixels when scroll_by_page is false, and scroll up 3 pages when
+ * scroll_by_page is true.
+ *
+ * This amount is system dependent and will take into account the user's
+ * preferred scroll sensitivity and potentially also nonlinear acceleration
+ * based on the speed of the scrolling.
+ *
+ * Devices will be of varying resolution. Some mice with large detents will
+ * only generate integer scroll amounts. But fractional values are also
+ * possible, for example, on some trackpads and newer mice that don't have
+ * "clicks".
+ */
+ struct PP_FloatPoint (*GetWheelDelta)(PP_Resource wheel_event);
+
+ /**
+ * The number of "clicks" of the scroll wheel that have produced the
+ * event. The value may have system-specific acceleration applied to it,
+ * depending on the device. The positive and negative meanings are the same
+ * as for GetWheelDelta().
+ *
+ * If you are scrolling, you probably want to use the delta values. These
+ * tick events can be useful if you aren't doing actual scrolling and don't
+ * want or pixel values. An example may be cycling between different items in
+ * a game.
+ *
+ * You may receive fractional values for the wheel ticks if the mouse wheel
+ * is high resolution or doesn't have "clicks". If your program wants
+ * discrete events (as in the "picking items" example) you should accumulate
+ * fractional click values from multiple messages until the total value
+ * reaches positive or negative one. This should represent a similar amount
+ * of scrolling as for a mouse that has a discrete mouse wheel.
+ */
+ struct PP_FloatPoint (*GetWheelTicks)(PP_Resource wheel_event);
+
+ /**
+ * Indicates if the scroll delta x/y indicates pages or lines to
+ * scroll by.
+ *
+ * @return PP_TRUE if the event is a wheel event and the user is scrolling
+ * by pages. PP_FALSE if not or if the resource is not a wheel event.
+ */
+ PP_Bool (*GetScrollByPage)(PP_Resource wheel_event);
+};
+
+struct PPB_KeyboardInputEvent {
+ /**
+ * Determines if a resource is a keyboard event.
+ *
+ * @return PP_TRUE if the given resource is a valid mouse input event.
+ */
+ PP_Bool (*IsKeyboardInputEvent)(PP_Resource resource);
+
+ /**
+ * Returns the DOM |keyCode| field for the keyboard event.
+ * Chrome populates this with the Windows-style Virtual Key code of the key.
+ */
+ uint32_t (*GetKeyCode)(PP_Resource key_event);
+
+ /**
+ * Returns the typed character for the given character event.
+ *
+ * @return A string var representing a single typed character for character
+ * input events. For non-character input events the return value will be an
+ * undefined var.
+ */
+ struct PP_Var (*GetCharacterText)(PP_Resource character_event);
+};
+
+#endif // PPAPI_C_PPB_INPUT_EVENT_H_
diff --git a/ppapi/c/ppp_input_event.h b/ppapi/c/ppp_input_event.h
new file mode 100644
index 0000000..4bc5340
--- /dev/null
+++ b/ppapi/c/ppp_input_event.h
@@ -0,0 +1,41 @@
+/* Copyright (c) 2011 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef PPAPI_C_PPP_INPUT_EVENT_H_
+#define PPAPI_C_PPP_INPUT_EVENT_H_
+
+#include "ppapi/c/pp_bool.h"
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/c/pp_resource.h"
+
+#define PPP_INPUT_EVENT_INTERFACE_0_1 "PPP_InputEvent;0.1"
+#define PPP_INPUT_EVENT_INTERFACE PPP_INPUT_EVENT_INTERFACE_0_1
+
+struct PPP_InputEvent {
+ /**
+ * Function for receiving input events from the browser.
+ *
+ * In order to receive input events, you must register for them by calling
+ * PPB_InputEvent.RequestInputEvents() or RequestFilteringInputEvents(). By
+ * default, no events are delivered.
+ *
+ * In general, you should try to keep input event handling short. Especially
+ * for filtered input events, the browser or page may be blocked waiting for
+ * you to respond.
+ *
+ * The caller of this function will maintain a reference to the input event
+ * resource during this call. Unless you take a reference to the resource
+ * to hold it for later, you don't need to release it.
+ *
+ * @return PP_TRUE if the event was handled, PP_FALSE if not. If you have
+ * registered to filter this class of events by calling
+ * RequestFilteringInputEvents, and you return PP_FALSE, the event will
+ * be forwarded to the page (and eventually the browser) for the default
+ * handling. For non-filtered events, the return value will be ignored.
+ */
+ PP_Bool (*HandleInputEvent)(PP_Instance instance, PP_Resource input_event);
+};
+
+#endif // PPAPI_C_PPP_INPUT_EVENT_H_
diff --git a/ppapi/cpp/input_event.cc b/ppapi/cpp/input_event.cc
new file mode 100644
index 0000000..fe237cc
--- /dev/null
+++ b/ppapi/cpp/input_event.cc
@@ -0,0 +1,172 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/cpp/input_event.h"
+
+#include "ppapi/cpp/common.h"
+#include "ppapi/cpp/instance.h"
+#include "ppapi/cpp/module.h"
+#include "ppapi/cpp/module_impl.h"
+#include "ppapi/cpp/point.h"
+#include "ppapi/cpp/var.h"
+
+namespace pp {
+
+namespace {
+
+template <> const char* interface_name<PPB_InputEvent>() {
+ return PPB_INPUT_EVENT_INTERFACE;
+}
+
+template <> const char* interface_name<PPB_KeyboardInputEvent>() {
+ return PPB_KEYBOARD_INPUT_EVENT_INTERFACE;
+}
+
+template <> const char* interface_name<PPB_MouseInputEvent>() {
+ return PPB_MOUSE_INPUT_EVENT_INTERFACE;
+}
+
+template <> const char* interface_name<PPB_WheelInputEvent>() {
+ return PPB_WHEEL_INPUT_EVENT_INTERFACE;
+}
+
+} // namespace
+
+// InputEvent ------------------------------------------------------------------
+
+InputEvent::InputEvent() : Resource() {
+}
+
+InputEvent::InputEvent(PP_Resource input_event_resource) : Resource() {
+ // Type check the input event before setting it.
+ if (!has_interface<PPB_InputEvent>())
+ return;
+ if (get_interface<PPB_InputEvent>()->IsInputEvent(input_event_resource)) {
+ Module::Get()->core()->AddRefResource(input_event_resource);
+ PassRefFromConstructor(input_event_resource);
+ }
+}
+
+InputEvent::~InputEvent() {
+}
+
+PP_InputEvent_Type InputEvent::GetType() const {
+ if (!has_interface<PPB_InputEvent>())
+ return PP_INPUTEVENT_TYPE_UNDEFINED;
+ return get_interface<PPB_InputEvent>()->GetType(pp_resource());
+}
+
+PP_TimeTicks InputEvent::GetTimeStamp() const {
+ if (!has_interface<PPB_InputEvent>())
+ return 0.0f;
+ return get_interface<PPB_InputEvent>()->GetTimeStamp(pp_resource());
+}
+
+uint32_t InputEvent::GetModifiers() const {
+ if (!has_interface<PPB_InputEvent>())
+ return 0;
+ return get_interface<PPB_InputEvent>()->GetModifiers(pp_resource());
+}
+
+// MouseInputEvent -------------------------------------------------------------
+
+MouseInputEvent::MouseInputEvent() : InputEvent() {
+}
+
+MouseInputEvent::MouseInputEvent(const InputEvent& event) : InputEvent() {
+ // Type check the input event before setting it.
+ if (!has_interface<PPB_MouseInputEvent>())
+ return;
+ if (get_interface<PPB_MouseInputEvent>()->IsMouseInputEvent(
+ event.pp_resource())) {
+ Module::Get()->core()->AddRefResource(event.pp_resource());
+ PassRefFromConstructor(event.pp_resource());
+ }
+}
+
+PP_InputEvent_MouseButton MouseInputEvent::GetMouseButton() const {
+ if (!has_interface<PPB_MouseInputEvent>())
+ return PP_INPUTEVENT_MOUSEBUTTON_NONE;
+ return get_interface<PPB_MouseInputEvent>()->GetMouseButton(pp_resource());
+}
+
+Point MouseInputEvent::GetMousePosition() const {
+ if (!has_interface<PPB_MouseInputEvent>())
+ return Point();
+ return get_interface<PPB_MouseInputEvent>()->GetMousePosition(pp_resource());
+}
+
+int32_t MouseInputEvent::GetMouseClickCount() const {
+ if (!has_interface<PPB_MouseInputEvent>())
+ return 0;
+ return get_interface<PPB_MouseInputEvent>()->GetMouseClickCount(
+ pp_resource());
+}
+
+// WheelInputEvent -------------------------------------------------------------
+
+WheelInputEvent::WheelInputEvent() : InputEvent() {
+}
+
+WheelInputEvent::WheelInputEvent(const InputEvent& event) : InputEvent() {
+ // Type check the input event before setting it.
+ if (!has_interface<PPB_WheelInputEvent>())
+ return;
+ if (get_interface<PPB_WheelInputEvent>()->IsWheelInputEvent(
+ event.pp_resource())) {
+ Module::Get()->core()->AddRefResource(event.pp_resource());
+ PassRefFromConstructor(event.pp_resource());
+ }
+}
+
+FloatPoint WheelInputEvent::GetWheelDelta() const {
+ if (!has_interface<PPB_WheelInputEvent>())
+ return FloatPoint();
+ return get_interface<PPB_WheelInputEvent>()->GetWheelDelta(pp_resource());
+}
+
+FloatPoint WheelInputEvent::GetWheelTicks() const {
+ if (!has_interface<PPB_WheelInputEvent>())
+ return FloatPoint();
+ return get_interface<PPB_WheelInputEvent>()->GetWheelTicks(pp_resource());
+}
+
+bool WheelInputEvent::GetScrollByPage() const {
+ if (!has_interface<PPB_WheelInputEvent>())
+ return false;
+ return PP_ToBool(
+ get_interface<PPB_WheelInputEvent>()->GetScrollByPage(pp_resource()));
+}
+
+// KeyboardInputEvent ----------------------------------------------------------
+
+KeyboardInputEvent::KeyboardInputEvent() : InputEvent() {
+}
+
+KeyboardInputEvent::KeyboardInputEvent(const InputEvent& event) : InputEvent() {
+ // Type check the input event before setting it.
+ if (!has_interface<PPB_KeyboardInputEvent>())
+ return;
+ if (get_interface<PPB_KeyboardInputEvent>()->IsKeyboardInputEvent(
+ event.pp_resource())) {
+ Module::Get()->core()->AddRefResource(event.pp_resource());
+ PassRefFromConstructor(event.pp_resource());
+ }
+}
+
+uint32_t KeyboardInputEvent::GetKeyCode() const {
+ if (!has_interface<PPB_KeyboardInputEvent>())
+ return 0;
+ return get_interface<PPB_KeyboardInputEvent>()->GetKeyCode(pp_resource());
+}
+
+Var KeyboardInputEvent::GetCharacterText() const {
+ if (!has_interface<PPB_KeyboardInputEvent>())
+ return PP_INPUTEVENT_TYPE_UNDEFINED;
+ return Var(Var::PassRef(),
+ get_interface<PPB_KeyboardInputEvent>()->GetCharacterText(
+ pp_resource()));
+}
+
+} // namespace pp
diff --git a/ppapi/cpp/input_event.h b/ppapi/cpp/input_event.h
new file mode 100644
index 0000000..0d8eecc
--- /dev/null
+++ b/ppapi/cpp/input_event.h
@@ -0,0 +1,180 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_CPP_INPUT_EVENT_H_
+#define PPAPI_CPP_INPUT_EVENT_H_
+
+#include "ppapi/c/ppb_input_event.h"
+#include "ppapi/cpp/resource.h"
+
+namespace pp {
+
+class FloatPoint;
+class Point;
+class Var;
+
+/// Represents an input event resource. Normally you will get passed this
+/// object through the HandleInputEvent on the Instance object.
+///
+/// Typically you would check the type of the event and then create the
+/// appropriate event-specific object to query the properties.
+///
+/// bool MyInstance::HandleInputEvent(const pp::InputEvent& event) {
+/// switch (event.GetType()) {
+/// case PP_INPUTEVENT_TYPE_MOUSE_DOWN {
+/// pp::MouseInputEvent mouse_event(event);
+/// return HandleMouseDown(mouse_event.GetMousePosition());
+/// }
+/// default:
+/// return false;
+/// }
+class InputEvent : public Resource {
+ public:
+ /// Default constructor that creates an is_null() InputEvent object.
+ InputEvent();
+
+ /// Constructs an input event from the given input event resource ID. The
+ /// InputEvent object will be is_null() if the given resource is not a valid
+ /// input event.
+ explicit InputEvent(PP_Resource input_event_resource);
+
+ ~InputEvent();
+
+ /// Returns the type of input event for the given input event resource.
+ /// This is valid for all input events. Returns PP_INPUTEVENT_TYPE_UNDEFINED
+ /// if the resource is invalid.
+ PP_InputEvent_Type GetType() const;
+
+ /// Returns the time that the event was generated. This will be before the
+ /// current time since processing and dispatching the event has some overhead.
+ /// Use this value to compare the times the user generated two events without
+ /// being sensitive to variable processing time.
+ ///
+ /// The return value is in time ticks, which is a monotonically increasing
+ /// clock not related to the wall clock time. It will not change if the user
+ /// changes their clock or daylight savings time starts, so can be reliably
+ /// used to compare events. This means, however, that you can't correlate
+ /// event times to a particular time of day on the system clock.
+ PP_TimeTicks GetTimeStamp() const;
+
+ /// Returns a bitfield indicating which modifiers were down at the time of
+ /// the event. This is a combination of the flags in the
+ /// PP_InputEvent_Modifier enum.
+ ///
+ /// @return The modifiers associated with the event, or 0 if the given
+ /// resource is not a valid event resource.
+ uint32_t GetModifiers() const;
+};
+
+class MouseInputEvent : public InputEvent {
+ public:
+ /// Constructs an is_null() mouse input event object.
+ MouseInputEvent();
+
+ /// Constructs a mouse input event object from the given generic input
+ /// event. If the given event is itself is_null() or is not a mouse input
+ /// event, the mouse object will be is_null().
+ explicit MouseInputEvent(const InputEvent& event);
+
+ /// Returns the mouse position for a mouse input event.
+ ///
+ /// @return The mouse button associated with mouse down and up events. This
+ /// value will be PP_EVENT_MOUSEBUTTON_NONE for mouse move, enter, and leave
+ /// events, and for all non-mouse events.
+ PP_InputEvent_MouseButton GetMouseButton() const;
+
+ /// Returns the pixel location of a mouse input event. This value is in
+ /// floating-point units to support high-resolution input events.
+ ///
+ /// @return The point associated with the mouse event, relative to the upper-
+ /// left of the instance receiving the event. These values can be negative for
+ /// mouse drags. The return value will be (0, 0) for non-mouse events.
+ Point GetMousePosition() const;
+
+ // TODO(brettw) figure out exactly what this means.
+ int32_t GetMouseClickCount() const;
+};
+
+class WheelInputEvent : public InputEvent {
+ public:
+ /// Constructs an is_null() wheel input event object.
+ WheelInputEvent();
+
+ /// Constructs a wheel input event object from the given generic input
+ /// event. If the given event is itself is_null() or is not a wheel input
+ /// event, the wheel object will be is_null().
+ explicit WheelInputEvent(const InputEvent& event);
+
+ /// Indicates the amount vertically and horizontally the user has requested
+ /// to scroll by with their mouse wheel. A scroll down or to the right (where
+ /// the content moves up or left) is represented as positive values, and
+ /// a scroll up or to the left (where the content moves down or right) is
+ /// represented as negative values.
+ ///
+ /// The units are either in pixels (when scroll_by_page is false) or pages
+ /// (when scroll_by_page is true). For example, y = -3 means scroll up 3
+ /// pixels when scroll_by_page is false, and scroll up 3 pages when
+ /// scroll_by_page is true.
+ ///
+ /// This amount is system dependent and will take into account the user's
+ /// preferred scroll sensitivity and potentially also nonlinear acceleration
+ /// based on the speed of the scrolling.
+ ///
+ /// Devices will be of varying resolution. Some mice with large detents will
+ /// only generate integer scroll amounts. But fractional values are also
+ /// possible, for example, on some trackpads and newer mice that don't have
+ /// "clicks".
+ FloatPoint GetWheelDelta() const;
+
+ /// The number of "clicks" of the scroll wheel that have produced the
+ /// event. The value may have system-specific acceleration applied to it,
+ /// depending on the device. The positive and negative meanings are the same
+ /// as for GetWheelDelta().
+ ///
+ /// If you are scrolling, you probably want to use the delta values. These
+ /// tick events can be useful if you aren't doing actual scrolling and don't
+ /// want or pixel values. An example may be cycling between different items in
+ /// a game.
+ ///
+ /// You may receive fractional values for the wheel ticks if the mouse wheel
+ /// is high resolution or doesn't have "clicks". If your program wants
+ /// discrete events (as in the "picking items" example) you should accumulate
+ /// fractional click values from multiple messages until the total value
+ /// reaches positive or negative one. This should represent a similar amount
+ /// of scrolling as for a mouse that has a discrete mouse wheel.
+ FloatPoint GetWheelTicks() const;
+
+ // Indicates if the scroll delta x/y indicates pages or lines to
+ // scroll by.
+ //
+ // @return PP_TRUE if the event is a wheel event and the user is scrolling
+ // by pages. PP_FALSE if not or if the resource is not a wheel event.
+ bool GetScrollByPage() const;
+};
+
+class KeyboardInputEvent : public InputEvent {
+ public:
+ /// Constructs an is_null() keyboard input event object.
+ KeyboardInputEvent();
+
+ /// Constructs a keyboard input event object from the given generic input
+ /// event. If the given event is itself is_null() or is not a keyboard input
+ /// event, the keybaord object will be is_null().
+ explicit KeyboardInputEvent(const InputEvent& event);
+
+ /// Returns the DOM |keyCode| field for the keyboard event.
+ /// Chrome populates this with the Windows-style Virtual Key code of the key.
+ uint32_t GetKeyCode() const;
+
+ /// Returns the typed character for the given character event.
+ ///
+ /// @return A string var representing a single typed character for character
+ /// input events. For non-character input events the return value will be an
+ /// undefined var.
+ Var GetCharacterText() const;
+};
+
+} // namespace pp
+
+#endif // PPAPI_CPP_INPUT_EVENT_H_
diff --git a/ppapi/cpp/instance.cc b/ppapi/cpp/instance.cc
index eaac9fc8..f4c8043 100644
--- a/ppapi/cpp/instance.cc
+++ b/ppapi/cpp/instance.cc
@@ -4,6 +4,8 @@
#include "ppapi/cpp/instance.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/c/ppb_input_event.h"
#include "ppapi/c/ppb_instance.h"
#include "ppapi/c/ppb_messaging.h"
#include "ppapi/cpp/common.h"
@@ -21,6 +23,10 @@ namespace pp {
namespace {
+template <> const char* interface_name<PPB_InputEvent>() {
+ return PPB_INPUT_EVENT_INTERFACE;
+}
+
template <> const char* interface_name<PPB_Instance>() {
return PPB_INSTANCE_INTERFACE;
}
@@ -65,6 +71,10 @@ bool Instance::HandleInputEvent(const PP_InputEvent& /*event*/) {
return false;
}
+bool Instance::HandleInputEvent(const InputEvent& /*event*/) {
+ return false;
+}
+
void Instance::HandleMessage(const Var& /*message*/) {
return;
}
@@ -121,6 +131,27 @@ bool Instance::IsFullFrame() {
pp_instance()));
}
+int32_t Instance::RequestInputEvents(uint32_t event_classes) {
+ if (!has_interface<PPB_InputEvent>())
+ return PP_ERROR_NOINTERFACE;
+ return get_interface<PPB_InputEvent>()->RequestInputEvents(pp_instance(),
+ event_classes);
+}
+
+int32_t Instance::RequestFilteringInputEvents(uint32_t event_classes) {
+ if (!has_interface<PPB_InputEvent>())
+ return PP_ERROR_NOINTERFACE;
+ return get_interface<PPB_InputEvent>()->RequestFilteringInputEvents(
+ pp_instance(), event_classes);
+}
+
+void Instance::ClearInputEventRequest(uint32_t event_classes) {
+ if (!has_interface<PPB_InputEvent>())
+ return;
+ get_interface<PPB_InputEvent>()->ClearInputEventRequest(pp_instance(),
+ event_classes);
+}
+
void Instance::PostMessage(const Var& message) {
if (!has_interface<PPB_Messaging>())
return;
diff --git a/ppapi/cpp/instance.h b/ppapi/cpp/instance.h
index 72de24e..03c3259 100644
--- a/ppapi/cpp/instance.h
+++ b/ppapi/cpp/instance.h
@@ -24,6 +24,7 @@ struct PP_InputEvent;
namespace pp {
class Graphics2D;
+class InputEvent;
class ImageData;
class Point;
class Rect;
@@ -154,6 +155,9 @@ class Instance {
/// @return true if @a event was handled, false otherwise.
virtual bool HandleInputEvent(const PP_InputEvent& event);
+ /// @see InputEvent for an example
+ virtual bool HandleInputEvent(const InputEvent& event);
+
/// Notification of a data stream available after an instance was created
/// based on the MIME type of a DOMWindow navigation. This only applies to
/// modules that are pre-registered to handle certain MIME types. If you
@@ -204,6 +208,10 @@ class Instance {
/// See PPB_Instance.IsFullFrame.
bool IsFullFrame();
+ int32_t RequestInputEvents(uint32_t event_classes);
+ int32_t RequestFilteringInputEvents(uint32_t event_classes);
+ void ClearInputEventRequest(uint32_t event_classes);
+
// These functions use the PPP_Messaging and PPB_Messaging interfaces, so that
// messaging can be done conveniently for a pp::Instance without using a
// separate C++ class.
diff --git a/ppapi/cpp/module.cc b/ppapi/cpp/module.cc
index 6791d0a..1610cea 100644
--- a/ppapi/cpp/module.cc
+++ b/ppapi/cpp/module.cc
@@ -27,17 +27,36 @@
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_var.h"
+#include "ppapi/c/ppp_input_event.h"
#include "ppapi/c/ppp_instance.h"
#include "ppapi/c/ppp_messaging.h"
#include "ppapi/cpp/common.h"
-#include "ppapi/cpp/url_loader.h"
+#include "ppapi/cpp/input_event.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/rect.h"
#include "ppapi/cpp/resource.h"
+#include "ppapi/cpp/url_loader.h"
#include "ppapi/cpp/var.h"
namespace pp {
+// PPP_InputEvent implementation -----------------------------------------------
+
+PP_Bool InputEvent_HandleEvent(PP_Instance pp_instance, PP_Resource resource) {
+ Module* module_singleton = Module::Get();
+ if (!module_singleton)
+ return PP_FALSE;
+ Instance* instance = module_singleton->InstanceForPPInstance(pp_instance);
+ if (!instance)
+ return PP_FALSE;
+
+ return BoolToPPBool(instance->HandleInputEvent(InputEvent(resource)));
+}
+
+const PPP_InputEvent input_event_interface = {
+ &InputEvent_HandleEvent
+};
+
// PPP_Instance implementation -------------------------------------------------
PP_Bool Instance_DidCreate(PP_Instance pp_instance,
@@ -139,6 +158,8 @@ static PPP_Instance instance_interface = {
#endif
};
+// PPP_Messaging implementation ------------------------------------------------
+
void Messaging_HandleMessage(PP_Instance pp_instance, PP_Var var) {
Module* module_singleton = Module::Get();
if (!module_singleton)
@@ -168,9 +189,10 @@ bool Module::Init() {
}
const void* Module::GetPluginInterface(const char* interface_name) {
+ if (strcmp(interface_name, PPP_INPUT_EVENT_INTERFACE) == 0)
+ return &input_event_interface;
if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0)
return &instance_interface;
-
if (strcmp(interface_name, PPP_MESSAGING_INTERFACE) == 0)
return &instance_messaging_interface;
diff --git a/ppapi/cpp/point.h b/ppapi/cpp/point.h
index fb92c06..94ad519 100644
--- a/ppapi/cpp/point.h
+++ b/ppapi/cpp/point.h
@@ -39,6 +39,7 @@ class Point {
point_.x = point.x;
point_.y = point.y;
}
+
/// Destructor.
~Point() {
}
@@ -132,6 +133,129 @@ class Point {
PP_Point point_;
};
+/// A 2 dimensional floating-point point with 0,0 being the upper-left starting
+/// coordinate.
+class FloatPoint {
+ public:
+ /// A constructor for a point at 0,0.
+ FloatPoint() {
+ float_point_.x = 0.0f;
+ float_point_.y = 0.0f;
+ }
+
+ /// A constructor accepting two values for x and y and converting them to a
+ /// FloatPoint.
+ ///
+ /// @param[in] in_x An value representing a horizontal coordinate of a
+ /// point, starting with 0 as the left-most coordinate.
+ ///
+ /// @param[in] in_y An value representing a vertical coordinate of a point,
+ /// starting with 0 as the top-most coordinate.
+ FloatPoint(float in_x, float in_y) {
+ float_point_.x = in_x;
+ float_point_.y = in_y;
+ }
+
+ /// A constructor accepting a pointer to a PP_FloatPoint and converting the
+ /// PP_Point to a Point. This is an implicit conversion constructor.
+ /// @param[in] point A PP_FloatPoint.
+ FloatPoint(const PP_FloatPoint& point) { // Implicit.
+ float_point_.x = point.x;
+ float_point_.y = point.y;
+ }
+ /// Destructor.
+ ~FloatPoint() {
+ }
+
+ /// A function allowing implicit conversion of a FloatPoint to a
+ /// PP_FloatPoint.
+ operator PP_FloatPoint() const {
+ return float_point_;
+ }
+
+ /// Getter function for returning the internal PP_FloatPoint struct.
+ /// @return A const reference to the internal PP_FloatPoint struct.
+ const PP_FloatPoint& pp_float_point() const {
+ return float_point_;
+ }
+
+ /// Getter function for returning the internal PP_Point struct.
+ /// @return A mutable reference to the PP_Point struct.
+ PP_FloatPoint& pp_float_point() {
+ return float_point_;
+ }
+
+ /// Getter function for returning the value of x.
+ /// @return The value of x for this Point.
+ float x() const { return float_point_.x; }
+
+ /// Setter function for setting the value of x.
+ /// @param[in] in_x A new x value.
+ void set_x(float in_x) {
+ float_point_.x = in_x;
+ }
+
+ /// Getter function for returning the value of y.
+ /// @return The value of y for this Point.
+ float y() const { return float_point_.y; }
+
+ /// Setter function for setting the value of y.
+ /// @param[in] in_y A new y value.
+ void set_y(float in_y) {
+ float_point_.y = in_y;
+ }
+
+ /// Adds two Points (this and other) together by adding their x values and
+ /// y values.
+ /// @param[in] other A Point.
+ /// @return A new Point containing the result.
+ FloatPoint operator+(const FloatPoint& other) const {
+ return FloatPoint(x() + other.x(), y() + other.y());
+ }
+
+ /// Subtracts one Point from another Point by subtracting their x values
+ /// and y values. Returnes a new point with the result.
+ /// @param[in] other A FloatPoint.
+ /// @return A new Point containing the result.
+ FloatPoint operator-(const FloatPoint& other) const {
+ return FloatPoint(x() - other.x(), y() - other.y());
+ }
+
+ /// Adds two Points (this and other) together by adding their x and y
+ /// values. Returns this point as the result.
+ /// @param[in] other A Point.
+ /// @return This Point containing the result.
+ FloatPoint& operator+=(const FloatPoint& other) {
+ float_point_.x += other.x();
+ float_point_.y += other.y();
+ return *this;
+ }
+
+ /// Subtracts one Point from another Point by subtracting their x values
+ /// and y values. Returns this point as the result.
+ /// @param[in] other A Point.
+ /// @return This Point containing the result.
+ FloatPoint& operator-=(const FloatPoint& other) {
+ float_point_.x -= other.x();
+ float_point_.y -= other.y();
+ return *this;
+ }
+
+ /// Swaps the coordinates of two Points.
+ /// @param[in] other A Point.
+ void swap(FloatPoint& other) {
+ float x = float_point_.x;
+ float y = float_point_.y;
+ float_point_.x = other.float_point_.x;
+ float_point_.y = other.float_point_.y;
+ other.float_point_.x = x;
+ other.float_point_.y = y;
+ }
+
+ private:
+ PP_FloatPoint float_point_;
+};
+
} // namespace pp
/// Determines whether the x and y values of two Points are equal.
@@ -151,4 +275,21 @@ inline bool operator!=(const pp::Point& lhs, const pp::Point& rhs) {
return !(lhs == rhs);
}
+/// Determines whether the x and y values of two FloatPoints are equal.
+/// @param[in] lhs The Point on the left-hand side of the equation.
+/// @param[in] rhs The Point on the right-hand side of the equation.
+/// @return true if they are equal, false if unequal.
+inline bool operator==(const pp::FloatPoint& lhs, const pp::FloatPoint& rhs) {
+ return lhs.x() == rhs.x() && lhs.y() == rhs.y();
+}
+
+/// Determines whether two Points have different coordinates.
+/// @param[in] lhs The Point on the left-hand side of the equation.
+/// @param[in] rhs The Point on the right-hand side of the equation.
+/// @return true if the coordinates of lhs are equal to the coordinates
+/// of rhs, otherwise false.
+inline bool operator!=(const pp::FloatPoint& lhs, const pp::FloatPoint& rhs) {
+ return !(lhs == rhs);
+}
+
#endif // PPAPI_CPP_POINT_H_
diff --git a/ppapi/example/example.cc b/ppapi/example/example.cc
index 93696f0..6ef0640 100644
--- a/ppapi/example/example.cc
+++ b/ppapi/example/example.cc
@@ -17,12 +17,12 @@
#include "ppapi/c/dev/ppb_cursor_control_dev.h"
#include "ppapi/c/dev/ppp_printing_dev.h"
#include "ppapi/c/pp_errors.h"
-#include "ppapi/c/pp_input_event.h"
#include "ppapi/c/pp_rect.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/dev/scriptable_object_deprecated.h"
#include "ppapi/cpp/graphics_2d.h"
#include "ppapi/cpp/image_data.h"
+#include "ppapi/cpp/input_event.h"
#include "ppapi/cpp/private/instance_private.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/private/var_private.h"
@@ -169,7 +169,9 @@ class MyInstance : public pp::InstancePrivate, public MyFetcherClient {
height_(0),
animation_counter_(0),
print_settings_valid_(false),
- showing_custom_cursor_(false) {}
+ showing_custom_cursor_(false) {
+ RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
+ }
virtual ~MyInstance() {
if (fetcher_) {
@@ -196,8 +198,8 @@ class MyInstance : public pp::InstancePrivate, public MyFetcherClient {
return true;
}
- virtual bool HandleInputEvent(const PP_InputEvent& event) {
- switch (event.type) {
+ virtual bool HandleInputEvent(const pp::InputEvent& event) {
+ switch (event.GetType()) {
case PP_INPUTEVENT_TYPE_MOUSEDOWN:
SayHello();
ToggleCursor();
diff --git a/ppapi/ppapi_cpp.gypi b/ppapi/ppapi_cpp.gypi
index b9a87da..1fbd940 100644
--- a/ppapi/ppapi_cpp.gypi
+++ b/ppapi/ppapi_cpp.gypi
@@ -37,6 +37,7 @@
'c/ppb_file_system.h',
'c/ppb_graphics_2d.h',
'c/ppb_image_data.h',
+ 'c/ppb_input_event.h',
'c/ppb_instance.h',
'c/ppb_messaging.h',
'c/ppb_url_loader.h',
@@ -44,6 +45,7 @@
'c/ppb_url_response_info.h',
'c/ppb_var.h',
'c/ppp.h',
+ 'c/ppp_input_event.h',
'c/ppp_instance.h',
'c/ppp_messaging.h',
@@ -149,6 +151,8 @@
'cpp/graphics_2d.h',
'cpp/image_data.cc',
'cpp/image_data.h',
+ 'cpp/input_event.cc',
+ 'cpp/input_event.h',
'cpp/instance.cc',
'cpp/instance.h',
'cpp/logging.h',
diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi
index 43ffd3d..db9dc29 100644
--- a/ppapi/ppapi_proxy.gypi
+++ b/ppapi/ppapi_proxy.gypi
@@ -98,6 +98,8 @@
'proxy/ppb_graphics_2d_proxy.h',
'proxy/ppb_image_data_proxy.cc',
'proxy/ppb_image_data_proxy.h',
+ 'proxy/ppb_input_event_proxy.cc',
+ 'proxy/ppb_input_event_proxy.h',
'proxy/ppb_instance_proxy.cc',
'proxy/ppb_instance_proxy.h',
'proxy/ppb_memory_proxy.cc',
@@ -126,6 +128,8 @@
'proxy/ppp_class_proxy.h',
'proxy/ppp_graphics_3d_proxy.cc',
'proxy/ppp_graphics_3d_proxy.h',
+ 'proxy/ppp_input_event_proxy.cc',
+ 'proxy/ppp_input_event_proxy.h',
'proxy/ppp_instance_private_proxy.cc',
'proxy/ppp_instance_private_proxy.h',
'proxy/ppp_instance_proxy.cc',
diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi
index 476dc1f..d3cea67 100644
--- a/ppapi/ppapi_shared.gypi
+++ b/ppapi/ppapi_shared.gypi
@@ -37,6 +37,10 @@
'shared_impl/function_group_base.h',
'shared_impl/image_data_impl.cc',
'shared_impl/image_data_impl.h',
+ 'shared_impl/input_event_impl.cc',
+ 'shared_impl/input_event_impl.h',
+ 'shared_impl/instance_impl.cc',
+ 'shared_impl/instance_impl.h',
'shared_impl/ppapi_preferences.cc',
'shared_impl/ppapi_preferences.h',
'shared_impl/ppp_instance_combined.cc',
@@ -74,6 +78,8 @@
'thunk/ppb_cursor_control_thunk.cc',
'thunk/ppb_directory_reader_api.h',
'thunk/ppb_directory_reader_thunk.cc',
+ 'thunk/ppb_input_event_api.h',
+ 'thunk/ppb_input_event_thunk.cc',
'thunk/ppb_file_chooser_api.h',
'thunk/ppb_file_chooser_thunk.cc',
'thunk/ppb_file_io_api.h',
diff --git a/ppapi/proxy/dispatcher.cc b/ppapi/proxy/dispatcher.cc
index 7941992..8cb8028 100644
--- a/ppapi/proxy/dispatcher.cc
+++ b/ppapi/proxy/dispatcher.cc
@@ -66,6 +66,7 @@
#include "ppapi/proxy/ppb_font_proxy.h"
#include "ppapi/proxy/ppb_graphics_2d_proxy.h"
#include "ppapi/proxy/ppb_image_data_proxy.h"
+#include "ppapi/proxy/ppb_input_event_proxy.h"
#include "ppapi/proxy/ppb_instance_proxy.h"
#include "ppapi/proxy/ppb_memory_proxy.h"
#include "ppapi/proxy/ppb_opengles2_proxy.h"
@@ -80,6 +81,7 @@
#include "ppapi/proxy/ppb_var_proxy.h"
#include "ppapi/proxy/ppp_class_proxy.h"
#include "ppapi/proxy/ppp_graphics_3d_proxy.h"
+#include "ppapi/proxy/ppp_input_event_proxy.h"
#include "ppapi/proxy/ppp_instance_private_proxy.h"
#include "ppapi/proxy/ppp_instance_proxy.h"
#include "ppapi/proxy/var_serialization_rules.h"
@@ -136,6 +138,7 @@ InterfaceList::InterfaceList() {
AddPPB(PPB_Font_Proxy::GetInfo());
AddPPB(PPB_Graphics2D_Proxy::GetInfo());
AddPPB(PPB_ImageData_Proxy::GetInfo());
+ AddPPB(PPB_InputEvent_Proxy::GetInfo());
AddPPB(PPB_Instance_Proxy::GetInfoPrivate());
AddPPB(PPB_Instance_Proxy::GetInfo0_4());
AddPPB(PPB_Instance_Proxy::GetInfo0_5());
@@ -159,6 +162,7 @@ InterfaceList::InterfaceList() {
// PPP (plugin) interfaces.
AddPPP(PPP_Graphics3D_Proxy::GetInfo());
+ AddPPP(PPP_InputEvent_Proxy::GetInfo());
AddPPP(PPP_Instance_Private_Proxy::GetInfo());
AddPPP(PPP_Instance_Proxy::GetInfo0_4());
AddPPP(PPP_Instance_Proxy::GetInfo0_5());
diff --git a/ppapi/proxy/interface_id.h b/ppapi/proxy/interface_id.h
index 47d0083..26ef71f6a 100644
--- a/ppapi/proxy/interface_id.h
+++ b/ppapi/proxy/interface_id.h
@@ -54,6 +54,7 @@ enum InterfaceID {
INTERFACE_ID_PPP_CLASS,
INTERFACE_ID_PPP_GRAPHICS_3D_DEV,
+ INTERFACE_ID_PPP_INPUT_EVENT,
INTERFACE_ID_PPP_INSTANCE,
INTERFACE_ID_PPP_INSTANCE_PRIVATE,
INTERFACE_ID_PPP_VIDEO_DECODER_DEV,
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index faba350..7b31079 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -30,15 +30,24 @@
#include "ppapi/proxy/ppapi_param_traits.h"
#include "ppapi/proxy/serialized_flash_menu.h"
#include "ppapi/proxy/serialized_structs.h"
+#include "ppapi/shared_impl/input_event_impl.h"
#include "ppapi/shared_impl/ppapi_preferences.h"
#define IPC_MESSAGE_START PpapiMsgStart
+IPC_ENUM_TRAITS(PP_InputEvent_Type)
+IPC_ENUM_TRAITS(PP_InputEvent_MouseButton)
+
IPC_STRUCT_TRAITS_BEGIN(PP_Point)
IPC_STRUCT_TRAITS_MEMBER(x)
IPC_STRUCT_TRAITS_MEMBER(y)
IPC_STRUCT_TRAITS_END()
+IPC_STRUCT_TRAITS_BEGIN(PP_FloatPoint)
+ IPC_STRUCT_TRAITS_MEMBER(x)
+ IPC_STRUCT_TRAITS_MEMBER(y)
+IPC_STRUCT_TRAITS_END()
+
IPC_STRUCT_TRAITS_BEGIN(PP_Size)
IPC_STRUCT_TRAITS_MEMBER(height)
IPC_STRUCT_TRAITS_MEMBER(width)
@@ -58,6 +67,21 @@ IPC_STRUCT_TRAITS_BEGIN(::ppapi::Preferences)
IPC_STRUCT_TRAITS_MEMBER(default_fixed_font_size)
IPC_STRUCT_TRAITS_END()
+IPC_STRUCT_TRAITS_BEGIN(::ppapi::InputEventData)
+ IPC_STRUCT_TRAITS_MEMBER(is_filtered)
+ IPC_STRUCT_TRAITS_MEMBER(event_type)
+ IPC_STRUCT_TRAITS_MEMBER(event_time_stamp)
+ IPC_STRUCT_TRAITS_MEMBER(event_modifiers)
+ IPC_STRUCT_TRAITS_MEMBER(mouse_button)
+ IPC_STRUCT_TRAITS_MEMBER(mouse_position)
+ IPC_STRUCT_TRAITS_MEMBER(mouse_click_count)
+ IPC_STRUCT_TRAITS_MEMBER(wheel_delta)
+ IPC_STRUCT_TRAITS_MEMBER(wheel_ticks)
+ IPC_STRUCT_TRAITS_MEMBER(wheel_scroll_by_page)
+ IPC_STRUCT_TRAITS_MEMBER(key_code)
+ IPC_STRUCT_TRAITS_MEMBER(character_text)
+IPC_STRUCT_TRAITS_END()
+
// These are from the browser to the plugin.
// Loads the given plugin.
IPC_MESSAGE_CONTROL1(PpapiMsg_LoadPlugin, FilePath /* path */)
@@ -234,6 +258,15 @@ IPC_MESSAGE_ROUTED2(PpapiMsg_PPPClass_Deallocate,
IPC_MESSAGE_ROUTED1(PpapiMsg_PPPGraphics3D_ContextLost,
PP_Instance /* instance */)
+// PPP_InputEvent.
+IPC_MESSAGE_ROUTED2(PpapiMsg_PPPInputEvent_HandleInputEvent,
+ PP_Instance /* instance */,
+ ppapi::InputEventData /* data */)
+IPC_SYNC_MESSAGE_ROUTED2_1(PpapiMsg_PPPInputEvent_HandleFilteredInputEvent,
+ PP_Instance /* instance */,
+ ppapi::InputEventData /* data */,
+ PP_Bool /* result */)
+
// PPP_Instance.
IPC_SYNC_MESSAGE_ROUTED3_1(PpapiMsg_PPPInstance_DidCreate,
PP_Instance /* instance */,
@@ -625,6 +658,13 @@ IPC_SYNC_MESSAGE_ROUTED1_2(PpapiHostMsg_PPBInstance_GetScreenSize,
PP_Instance /* instance */,
PP_Bool /* result */,
PP_Size /* size */)
+IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBInstance_RequestInputEvents,
+ PP_Instance /* instance */,
+ bool /* is_filtering */,
+ uint32_t /* event_classes */)
+IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBInstance_ClearInputEvents,
+ PP_Instance /* instance */,
+ uint32_t /* event_classes */)
IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBInstance_PostMessage,
PP_Instance /* instance */,
pp::proxy::SerializedVar /* message */)
diff --git a/ppapi/proxy/ppb_input_event_proxy.cc b/ppapi/proxy/ppb_input_event_proxy.cc
new file mode 100644
index 0000000..d5c6f4b
--- /dev/null
+++ b/ppapi/proxy/ppb_input_event_proxy.cc
@@ -0,0 +1,102 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/proxy/ppb_input_event_proxy.h"
+
+#include "ppapi/c/ppb_audio_config.h"
+#include "ppapi/proxy/plugin_dispatcher.h"
+#include "ppapi/proxy/plugin_resource.h"
+#include "ppapi/proxy/plugin_var_tracker.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/shared_impl/input_event_impl.h"
+#include "ppapi/thunk/thunk.h"
+
+using ppapi::InputEventData;
+using ppapi::InputEventImpl;
+using ppapi::thunk::PPB_InputEvent_API;
+
+namespace pp {
+namespace proxy {
+
+// The implementation is actually in InputEventImpl.
+class InputEvent : public PluginResource, public InputEventImpl {
+ public:
+ InputEvent(const HostResource& resource, const InputEventData& data);
+ virtual ~InputEvent();
+
+ // ResourceObjectBase overrides.
+ virtual PPB_InputEvent_API* AsPPB_InputEvent_API() OVERRIDE;
+
+ // InputEventImpl overrides.
+ virtual PP_Var StringToPPVar(const std::string& str) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(InputEvent);
+};
+
+InputEvent::InputEvent(const HostResource& resource, const InputEventData& data)
+ : PluginResource(resource),
+ InputEventImpl(data) {
+}
+
+InputEvent::~InputEvent() {
+}
+
+PPB_InputEvent_API* InputEvent::AsPPB_InputEvent_API() {
+ return this;
+}
+
+PP_Var InputEvent::StringToPPVar(const std::string& str) {
+ PP_Var ret;
+ ret.type = PP_VARTYPE_STRING;
+ ret.value.as_id = PluginVarTracker::GetInstance()->MakeString(str);
+ return ret;
+}
+
+namespace {
+
+InterfaceProxy* CreateInputEventProxy(Dispatcher* dispatcher,
+ const void* target_interface) {
+ return new PPB_InputEvent_Proxy(dispatcher, target_interface);
+}
+
+} // namespace
+
+PPB_InputEvent_Proxy::PPB_InputEvent_Proxy(Dispatcher* dispatcher,
+ const void* target_interface)
+ : InterfaceProxy(dispatcher, target_interface) {
+}
+
+PPB_InputEvent_Proxy::~PPB_InputEvent_Proxy() {
+}
+
+// static
+const InterfaceProxy::Info* PPB_InputEvent_Proxy::GetInfo() {
+ static const Info info = {
+ ::ppapi::thunk::GetPPB_InputEvent_Thunk(),
+ PPB_INPUT_EVENT_INTERFACE,
+ INTERFACE_ID_NONE,
+ false,
+ &CreateInputEventProxy,
+ };
+ return &info;
+}
+
+// static
+PP_Resource PPB_InputEvent_Proxy::CreateProxyResource(
+ PP_Instance instance,
+ const InputEventData& data) {
+ linked_ptr<InputEvent> object(new InputEvent(
+ HostResource::MakeInstanceOnly(instance), data));
+ return PluginResourceTracker::GetInstance()->AddResource(object);
+}
+
+bool PPB_InputEvent_Proxy::OnMessageReceived(const IPC::Message& msg) {
+ // There are no IPC messages for this interface.
+ NOTREACHED();
+ return false;
+}
+
+} // namespace proxy
+} // namespace pp
diff --git a/ppapi/proxy/ppb_input_event_proxy.h b/ppapi/proxy/ppb_input_event_proxy.h
new file mode 100644
index 0000000..bd80535
--- /dev/null
+++ b/ppapi/proxy/ppb_input_event_proxy.h
@@ -0,0 +1,40 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_PROXY_PPB_INPUT_EVENT_PROXY_H_
+#define PPAPI_PROXY_PPB_INPUT_EVENT_PROXY_H_
+
+#include "base/basictypes.h"
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/proxy/interface_proxy.h"
+#include "ppapi/shared_impl/input_event_impl.h"
+
+namespace ppapi {
+struct InputEventData;
+}
+
+namespace pp {
+namespace proxy {
+
+class PPB_InputEvent_Proxy : public InterfaceProxy {
+ public:
+ PPB_InputEvent_Proxy(Dispatcher* dispatcher, const void* target_interface);
+ virtual ~PPB_InputEvent_Proxy();
+
+ static const Info* GetInfo();
+
+ static PP_Resource CreateProxyResource(PP_Instance instance,
+ const ppapi::InputEventData& data);
+
+ // InterfaceProxy implementation.
+ virtual bool OnMessageReceived(const IPC::Message& msg);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PPB_InputEvent_Proxy);
+};
+
+} // namespace proxy
+} // namespace pp
+
+#endif // PPAPI_PROXY_PPB_INPUT_EVENT_PROXY_H_
diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc
index 98ae45d..6850971 100644
--- a/ppapi/proxy/ppb_instance_proxy.cc
+++ b/ppapi/proxy/ppb_instance_proxy.cc
@@ -116,6 +116,10 @@ bool PPB_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) {
OnMsgSetFullscreen)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetScreenSize,
OnMsgGetScreenSize)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_RequestInputEvents,
+ OnMsgRequestInputEvents)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ClearInputEvents,
+ OnMsgClearInputEvents)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -198,6 +202,35 @@ PP_Bool PPB_Instance_Proxy::GetScreenSize(PP_Instance instance,
return result;
}
+int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance,
+ uint32_t event_classes) {
+ dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
+ INTERFACE_ID_PPB_INSTANCE, instance, false, event_classes));
+
+ // We always register for the classes we can handle, this function validates
+ // the flags so we can notify it if anything was invalid, without requiring
+ // a sync reply.
+ return ValidateRequestInputEvents(false, event_classes);
+}
+
+int32_t PPB_Instance_Proxy::RequestFilteringInputEvents(
+ PP_Instance instance,
+ uint32_t event_classes) {
+ dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
+ INTERFACE_ID_PPB_INSTANCE, instance, true, event_classes));
+
+ // We always register for the classes we can handle, this function validates
+ // the flags so we can notify it if anything was invalid, without requiring
+ // a sync reply.
+ return ValidateRequestInputEvents(true, event_classes);
+}
+
+void PPB_Instance_Proxy::ClearInputEventRequest(PP_Instance instance,
+ uint32_t event_classes) {
+ dispatcher()->Send(new PpapiHostMsg_PPBInstance_ClearInputEvents(
+ INTERFACE_ID_PPB_INSTANCE, instance, event_classes));
+}
+
void PPB_Instance_Proxy::ZoomChanged(PP_Instance instance,
double factor) {
// Not proxied yet.
@@ -289,6 +322,25 @@ void PPB_Instance_Proxy::OnMsgGetScreenSize(PP_Instance instance,
*result = enter.functions()->GetScreenSize(instance, size);
}
+void PPB_Instance_Proxy::OnMsgRequestInputEvents(PP_Instance instance,
+ bool is_filtering,
+ uint32_t event_classes) {
+ EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false);
+ if (enter.succeeded()) {
+ if (is_filtering)
+ enter.functions()->RequestFilteringInputEvents(instance, event_classes);
+ else
+ enter.functions()->RequestInputEvents(instance, event_classes);
+ }
+}
+
+void PPB_Instance_Proxy::OnMsgClearInputEvents(PP_Instance instance,
+ uint32_t event_classes) {
+ EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false);
+ if (enter.succeeded())
+ enter.functions()->ClearInputEventRequest(instance, event_classes);
+}
+
void PPB_Instance_Proxy::OnMsgPostMessage(PP_Instance instance,
SerializedVarReceiveInput message) {
EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false);
diff --git a/ppapi/proxy/ppb_instance_proxy.h b/ppapi/proxy/ppb_instance_proxy.h
index 1a719ea6..3ae978e 100644
--- a/ppapi/proxy/ppb_instance_proxy.h
+++ b/ppapi/proxy/ppb_instance_proxy.h
@@ -11,6 +11,7 @@
#include "ppapi/proxy/host_resource.h"
#include "ppapi/proxy/interface_proxy.h"
#include "ppapi/shared_impl/function_group_base.h"
+#include "ppapi/shared_impl/instance_impl.h"
#include "ppapi/thunk/ppb_instance_api.h"
namespace pp {
@@ -21,6 +22,7 @@ class SerializedVarOutParam;
class SerializedVarReturnValue;
class PPB_Instance_Proxy : public InterfaceProxy,
+ public ppapi::InstanceImpl,
public ppapi::FunctionGroupBase,
public ppapi::thunk::PPB_Instance_FunctionAPI {
public:
@@ -51,6 +53,12 @@ class PPB_Instance_Proxy : public InterfaceProxy,
virtual PP_Bool SetFullscreen(PP_Instance instance,
PP_Bool fullscreen) OVERRIDE;
virtual PP_Bool GetScreenSize(PP_Instance instance, PP_Size* size) OVERRIDE;
+ virtual int32_t RequestInputEvents(PP_Instance instance,
+ uint32_t event_classes) OVERRIDE;
+ virtual int32_t RequestFilteringInputEvents(PP_Instance instance,
+ uint32_t event_classes) OVERRIDE;
+ virtual void ClearInputEventRequest(PP_Instance instance,
+ uint32_t event_classes) OVERRIDE;
virtual void ZoomChanged(PP_Instance instance, double factor) OVERRIDE;
virtual void ZoomLimitsChanged(PP_Instance instance,
double minimum_factor,
@@ -77,6 +85,11 @@ class PPB_Instance_Proxy : public InterfaceProxy,
void OnMsgGetScreenSize(PP_Instance instance,
PP_Bool* result,
PP_Size* size);
+ void OnMsgRequestInputEvents(PP_Instance instance,
+ bool is_filtering,
+ uint32_t event_classes);
+ void OnMsgClearInputEvents(PP_Instance instance,
+ uint32_t event_classes);
void OnMsgPostMessage(PP_Instance instance,
SerializedVarReceiveInput message);
};
diff --git a/ppapi/proxy/ppp_input_event_proxy.cc b/ppapi/proxy/ppp_input_event_proxy.cc
new file mode 100644
index 0000000..1a1945d
--- /dev/null
+++ b/ppapi/proxy/ppp_input_event_proxy.cc
@@ -0,0 +1,115 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/proxy/ppp_input_event_proxy.h"
+
+#include <algorithm>
+
+#include "ppapi/c/ppp_input_event.h"
+#include "ppapi/proxy/host_dispatcher.h"
+#include "ppapi/proxy/plugin_dispatcher.h"
+#include "ppapi/proxy/plugin_resource_tracker.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/proxy/ppb_input_event_proxy.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_input_event_api.h"
+
+using ppapi::InputEventData;
+using ppapi::thunk::EnterResourceNoLock;
+using ppapi::thunk::PPB_InputEvent_API;
+
+namespace pp {
+namespace proxy {
+
+namespace {
+
+PP_Bool HandleInputEvent(PP_Instance instance, PP_Resource input_event) {
+ EnterResourceNoLock<PPB_InputEvent_API> enter(input_event, false);
+ if (enter.failed()) {
+ NOTREACHED();
+ return PP_FALSE;
+ }
+ const InputEventData& data = enter.object()->GetInputEventData();
+ HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
+ if (!dispatcher) {
+ NOTREACHED();
+ return PP_FALSE;
+ }
+
+ // Need to send different messages depending on whether filtering is needed.
+ PP_Bool result = PP_FALSE;
+ if (data.is_filtered) {
+ dispatcher->Send(new PpapiMsg_PPPInputEvent_HandleFilteredInputEvent(
+ INTERFACE_ID_PPP_INPUT_EVENT, instance, data, &result));
+ } else {
+ dispatcher->Send(new PpapiMsg_PPPInputEvent_HandleInputEvent(
+ INTERFACE_ID_PPP_INPUT_EVENT, instance, data));
+ }
+ return result;
+}
+
+static const PPP_InputEvent input_event_interface = {
+ &HandleInputEvent
+};
+
+InterfaceProxy* CreateInputEventProxy(Dispatcher* dispatcher,
+ const void* target_interface) {
+ return new PPP_InputEvent_Proxy(dispatcher, target_interface);
+}
+
+} // namespace
+
+PPP_InputEvent_Proxy::PPP_InputEvent_Proxy(Dispatcher* dispatcher,
+ const void* target_interface)
+ : InterfaceProxy(dispatcher, target_interface) {
+}
+
+PPP_InputEvent_Proxy::~PPP_InputEvent_Proxy() {
+}
+
+// static
+const InterfaceProxy::Info* PPP_InputEvent_Proxy::GetInfo() {
+ static const Info info = {
+ &input_event_interface,
+ PPP_INPUT_EVENT_INTERFACE,
+ INTERFACE_ID_PPP_INPUT_EVENT,
+ false,
+ &CreateInputEventProxy,
+ };
+ return &info;
+}
+
+bool PPP_InputEvent_Proxy::OnMessageReceived(const IPC::Message& msg) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(PPP_InputEvent_Proxy, msg)
+ IPC_MESSAGE_HANDLER(PpapiMsg_PPPInputEvent_HandleInputEvent,
+ OnMsgHandleInputEvent)
+ IPC_MESSAGE_HANDLER(PpapiMsg_PPPInputEvent_HandleFilteredInputEvent,
+ OnMsgHandleFilteredInputEvent)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void PPP_InputEvent_Proxy::OnMsgHandleInputEvent(PP_Instance instance,
+ const InputEventData& data) {
+ PP_Resource event_resource = PPB_InputEvent_Proxy::CreateProxyResource(
+ instance, data);
+ ppp_input_event_target()->HandleInputEvent(instance, event_resource);
+ PluginResourceTracker::GetInstance()->ReleaseResource(event_resource);
+}
+
+void PPP_InputEvent_Proxy::OnMsgHandleFilteredInputEvent(
+ PP_Instance instance,
+ const InputEventData& data,
+ PP_Bool* result) {
+ PP_Resource event_resource = PPB_InputEvent_Proxy::CreateProxyResource(
+ instance, data);
+ *result = ppp_input_event_target()->HandleInputEvent(instance,
+ event_resource);
+ PluginResourceTracker::GetInstance()->ReleaseResource(event_resource);
+}
+
+} // namespace proxy
+} // namespace pp
diff --git a/ppapi/proxy/ppp_input_event_proxy.h b/ppapi/proxy/ppp_input_event_proxy.h
new file mode 100644
index 0000000..b294aa5
--- /dev/null
+++ b/ppapi/proxy/ppp_input_event_proxy.h
@@ -0,0 +1,46 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_PROXY_PPP_INPUT_EVENT_PROXY_H_
+#define PPAPI_PROXY_PPP_INPUT_EVENT_PROXY_H_
+
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/proxy/interface_proxy.h"
+
+struct PPP_InputEvent;
+
+namespace ppapi {
+struct InputEventData;
+}
+
+namespace pp {
+namespace proxy {
+
+class PPP_InputEvent_Proxy : public InterfaceProxy {
+ public:
+ PPP_InputEvent_Proxy(Dispatcher* dispatcher, const void* target_interface);
+ virtual ~PPP_InputEvent_Proxy();
+
+ static const Info* GetInfo();
+
+ const PPP_InputEvent* ppp_input_event_target() const {
+ return static_cast<const PPP_InputEvent*>(target_interface());
+ }
+
+ // InterfaceProxy implementation.
+ virtual bool OnMessageReceived(const IPC::Message& msg);
+
+ private:
+ // Message handlers.
+ void OnMsgHandleInputEvent(PP_Instance instance,
+ const ppapi::InputEventData& data);
+ void OnMsgHandleFilteredInputEvent(PP_Instance instance,
+ const ppapi::InputEventData& data,
+ PP_Bool* result);
+};
+
+} // namespace proxy
+} // namespace pp
+
+#endif // PPAPI_PROXY_PPP_INPUT_EVENT_PROXY_H_
diff --git a/ppapi/shared_impl/input_event_impl.cc b/ppapi/shared_impl/input_event_impl.cc
new file mode 100644
index 0000000..599cfa1
--- /dev/null
+++ b/ppapi/shared_impl/input_event_impl.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/shared_impl/input_event_impl.h"
+
+namespace ppapi {
+
+InputEventData::InputEventData()
+ : is_filtered(false),
+ event_type(PP_INPUTEVENT_TYPE_UNDEFINED),
+ event_time_stamp(0.0),
+ event_modifiers(0),
+ mouse_button(PP_INPUTEVENT_MOUSEBUTTON_NONE),
+ mouse_position(PP_MakePoint(0, 0)),
+ mouse_click_count(0),
+ wheel_delta(PP_MakeFloatPoint(0.0f, 0.0f)),
+ wheel_ticks(PP_MakeFloatPoint(0.0f, 0.0f)),
+ wheel_scroll_by_page(false),
+ key_code(0),
+ character_text() {
+}
+
+InputEventData::~InputEventData() {
+}
+
+InputEventImpl::InputEventImpl(const InputEventData& data) : data_(data) {
+}
+
+const InputEventData& InputEventImpl::GetInputEventData() const {
+ return data_;
+}
+
+PP_InputEvent_Type InputEventImpl::GetType() {
+ return data_.event_type;
+}
+
+PP_TimeTicks InputEventImpl::GetTimeStamp() {
+ return data_.event_time_stamp;
+}
+
+uint32_t InputEventImpl::GetModifiers() {
+ return data_.event_modifiers;
+}
+
+PP_InputEvent_MouseButton InputEventImpl::GetMouseButton() {
+ return data_.mouse_button;
+}
+
+PP_Point InputEventImpl::GetMousePosition() {
+ return data_.mouse_position;
+}
+
+int32_t InputEventImpl::GetMouseClickCount() {
+ return data_.mouse_click_count;
+}
+
+PP_FloatPoint InputEventImpl::GetWheelDelta() {
+ return data_.wheel_delta;
+}
+
+PP_FloatPoint InputEventImpl::GetWheelTicks() {
+ return data_.wheel_ticks;
+}
+
+PP_Bool InputEventImpl::GetWheelScrollByPage() {
+ return PP_FromBool(data_.wheel_scroll_by_page);
+}
+
+uint32_t InputEventImpl::GetKeyCode() {
+ return data_.key_code;
+}
+
+PP_Var InputEventImpl::GetCharacterText() {
+ return StringToPPVar(data_.character_text);
+}
+
+} // namespace ppapi
+
diff --git a/ppapi/shared_impl/input_event_impl.h b/ppapi/shared_impl/input_event_impl.h
new file mode 100644
index 0000000..b5411dd
--- /dev/null
+++ b/ppapi/shared_impl/input_event_impl.h
@@ -0,0 +1,75 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_SHARED_IMPL_INPUT_EVENT_IMPL_H_
+#define PPAPI_SHARED_IMPL_INPUT_EVENT_IMPL_H_
+
+#include <string>
+
+#include "base/compiler_specific.h"
+#include "ppapi/thunk/ppb_input_event_api.h"
+
+namespace ppapi {
+
+// IF YOU ADD STUFF TO THIS CLASS
+// ==============================
+// Be sure to add it to the STRUCT_TRAITS at the top of ppapi_messages.h
+struct InputEventData {
+ InputEventData();
+ ~InputEventData();
+
+ // Internal-only value. Set to true when this input event is filtered, that
+ // is, should be delivered synchronously. This is used by the proxy.
+ bool is_filtered;
+
+ PP_InputEvent_Type event_type;
+ PP_TimeTicks event_time_stamp;
+ uint32_t event_modifiers;
+
+ PP_InputEvent_MouseButton mouse_button;
+ PP_Point mouse_position;
+ int32_t mouse_click_count;
+
+ PP_FloatPoint wheel_delta;
+ PP_FloatPoint wheel_ticks;
+ bool wheel_scroll_by_page;
+
+ uint32_t key_code;
+
+ std::string character_text;
+};
+
+// This simple class implements the PPB_InputEvent_API in terms of the
+// shared InputEventData structure
+class InputEventImpl : public thunk::PPB_InputEvent_API {
+ public:
+ explicit InputEventImpl(const InputEventData& data);
+
+ // PPB_InputEvent_API implementation.
+ virtual const InputEventData& GetInputEventData() const OVERRIDE;
+ virtual PP_InputEvent_Type GetType() OVERRIDE;
+ virtual PP_TimeTicks GetTimeStamp() OVERRIDE;
+ virtual uint32_t GetModifiers() OVERRIDE;
+ virtual PP_InputEvent_MouseButton GetMouseButton() OVERRIDE;
+ virtual PP_Point GetMousePosition() OVERRIDE;
+ virtual int32_t GetMouseClickCount() OVERRIDE;
+ virtual PP_FloatPoint GetWheelDelta() OVERRIDE;
+ virtual PP_FloatPoint GetWheelTicks() OVERRIDE;
+ virtual PP_Bool GetWheelScrollByPage() OVERRIDE;
+ virtual uint32_t GetKeyCode() OVERRIDE;
+ virtual PP_Var GetCharacterText() OVERRIDE;
+
+ protected:
+ // Derived classes override this to convert a string to a PP_Var in either
+ // the proxy or the impl.
+ virtual PP_Var StringToPPVar(const std::string& str) = 0;
+
+ private:
+ InputEventData data_;
+};
+
+} // namespace ppapi
+
+#endif // PPAPI_SHARED_IMPL_INPUT_EVENT_IMPL_H_
+
diff --git a/ppapi/shared_impl/instance_impl.cc b/ppapi/shared_impl/instance_impl.cc
new file mode 100644
index 0000000..1268dd7
--- /dev/null
+++ b/ppapi/shared_impl/instance_impl.cc
@@ -0,0 +1,34 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/shared_impl/instance_impl.h"
+
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/c/ppb_input_event.h"
+
+namespace ppapi {
+
+InstanceImpl::~InstanceImpl() {
+}
+
+int32_t InstanceImpl::ValidateRequestInputEvents(bool is_filtering,
+ uint32_t event_classes) {
+ // See if any bits are set we don't know about.
+ if (event_classes &
+ ~static_cast<uint32_t>(PP_INPUTEVENT_CLASS_MOUSE |
+ PP_INPUTEVENT_CLASS_KEYBOARD |
+ PP_INPUTEVENT_CLASS_WHEEL |
+ PP_INPUTEVENT_CLASS_TOUCH |
+ PP_INPUTEVENT_CLASS_IME))
+ return PP_ERROR_NOTSUPPORTED;
+
+ // See if the keyboard is requested in non-filtering mode.
+ if (!is_filtering && (event_classes & PP_INPUTEVENT_CLASS_KEYBOARD))
+ return PP_ERROR_NOTSUPPORTED;
+
+ // Everything else is valid.
+ return PP_OK;
+}
+
+} // namespace ppapi
diff --git a/ppapi/shared_impl/instance_impl.h b/ppapi/shared_impl/instance_impl.h
new file mode 100644
index 0000000..9cbfb89
--- /dev/null
+++ b/ppapi/shared_impl/instance_impl.h
@@ -0,0 +1,23 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_SHARED_IMPL_INSTANCE_IMPL_H_
+#define PPAPI_SHARED_IMPL_INSTANCE_IMPL_H_
+
+#include "ppapi/c/pp_stdint.h"
+
+namespace ppapi {
+
+class InstanceImpl {
+ public:
+ virtual ~InstanceImpl();
+
+ // Error checks the given resquest to Request[Filtering]InputEvents. Returns
+ // PP_OK if the given classes are all valid, PP_ERROR_NOTSUPPORTED if not.
+ int32_t ValidateRequestInputEvents(bool is_filtering, uint32_t event_classes);
+};
+
+} // namespace ppapi
+
+#endif // PPAPI_SHARED_IMPL_INSTANCE_IMPL_H_
diff --git a/ppapi/shared_impl/resource_object_base.h b/ppapi/shared_impl/resource_object_base.h
index 77f6dd16..1394718 100644
--- a/ppapi/shared_impl/resource_object_base.h
+++ b/ppapi/shared_impl/resource_object_base.h
@@ -28,6 +28,7 @@
F(PPB_Graphics2D_API) \
F(PPB_Graphics3D_API) \
F(PPB_ImageData_API) \
+ F(PPB_InputEvent_API) \
F(PPB_LayerCompositor_API) \
F(PPB_PDFFont_API) \
F(PPB_Scrollbar_API) \
diff --git a/ppapi/tests/all_c_includes.h b/ppapi/tests/all_c_includes.h
index 3100deb..b5e702d 100644
--- a/ppapi/tests/all_c_includes.h
+++ b/ppapi/tests/all_c_includes.h
@@ -73,12 +73,14 @@
#include "ppapi/c/ppb_core.h"
#include "ppapi/c/ppb_graphics_2d.h"
#include "ppapi/c/ppb_image_data.h"
+#include "ppapi/c/ppb_input_event.h"
#include "ppapi/c/ppb_instance.h"
#include "ppapi/c/ppb_messaging.h"
#include "ppapi/c/ppb_url_loader.h"
#include "ppapi/c/ppb_url_request_info.h"
#include "ppapi/c/ppb_url_response_info.h"
#include "ppapi/c/ppp.h"
+#include "ppapi/c/ppp_input_event.h"
#include "ppapi/c/ppp_instance.h"
#include "ppapi/c/ppp_messaging.h"
#include "ppapi/c/private/ppb_flash.h"
diff --git a/ppapi/thunk/ppb_input_event_api.h b/ppapi/thunk/ppb_input_event_api.h
new file mode 100644
index 0000000..51ac5db
--- /dev/null
+++ b/ppapi/thunk/ppb_input_event_api.h
@@ -0,0 +1,40 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_THUNK_PPB_INPUT_EVENT_API_H_
+#define PPAPI_THUNK_PPB_INPUT_EVENT_API_H_
+
+#include "ppapi/c/ppb_input_event.h"
+
+namespace ppapi {
+
+struct InputEventData;
+
+namespace thunk {
+
+class PPB_InputEvent_API {
+ public:
+ virtual ~PPB_InputEvent_API() {}
+
+ // This function is not exposed through the C API, but returns the internal
+ // event data for easy proxying.
+ virtual const InputEventData& GetInputEventData() const = 0;
+
+ virtual PP_InputEvent_Type GetType() = 0;
+ virtual PP_TimeTicks GetTimeStamp() = 0;
+ virtual uint32_t GetModifiers() = 0;
+ virtual PP_InputEvent_MouseButton GetMouseButton() = 0;
+ virtual PP_Point GetMousePosition() = 0;
+ virtual int32_t GetMouseClickCount() = 0;
+ virtual PP_FloatPoint GetWheelDelta() = 0;
+ virtual PP_FloatPoint GetWheelTicks() = 0;
+ virtual PP_Bool GetWheelScrollByPage() = 0;
+ virtual uint32_t GetKeyCode() = 0;
+ virtual PP_Var GetCharacterText() = 0;
+};
+
+} // namespace thunk
+} // namespace ppapi
+
+#endif // PPAPI_THUNK_PPB_INPUT_EVENT_API_H_
diff --git a/ppapi/thunk/ppb_input_event_thunk.cc b/ppapi/thunk/ppb_input_event_thunk.cc
new file mode 100644
index 0000000..501502c
--- /dev/null
+++ b/ppapi/thunk/ppb_input_event_thunk.cc
@@ -0,0 +1,210 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/thunk/thunk.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_input_event_api.h"
+#include "ppapi/thunk/ppb_instance_api.h"
+#include "ppapi/thunk/resource_creation_api.h"
+
+namespace ppapi {
+namespace thunk {
+
+namespace {
+
+typedef EnterFunction<PPB_Instance_FunctionAPI> EnterInstance;
+typedef EnterResource<PPB_InputEvent_API> EnterInputEvent;
+
+// InputEvent ------------------------------------------------------------------
+
+int32_t RequestInputEvents(PP_Instance instance, uint32_t event_classes) {
+ EnterInstance enter(instance, true);
+ if (enter.failed())
+ return PP_ERROR_BADARGUMENT;
+ return enter.functions()->RequestInputEvents(instance, event_classes);
+}
+
+int32_t RequestFilteringInputEvents(PP_Instance instance,
+ uint32_t event_classes) {
+ EnterInstance enter(instance, true);
+ if (enter.failed())
+ return PP_ERROR_BADARGUMENT;
+ return enter.functions()->RequestFilteringInputEvents(instance,
+ event_classes);
+}
+
+void ClearInputEventRequest(PP_Instance instance,
+ uint32_t event_classes) {
+ EnterInstance enter(instance, true);
+ if (enter.succeeded())
+ enter.functions()->ClearInputEventRequest(instance, event_classes);
+}
+
+PP_Bool IsInputEvent(PP_Resource resource) {
+ EnterInputEvent enter(resource, false);
+ return enter.succeeded() ? PP_TRUE : PP_FALSE;
+}
+
+PP_InputEvent_Type GetType(PP_Resource event) {
+ EnterInputEvent enter(event, true);
+ if (enter.failed())
+ return PP_INPUTEVENT_TYPE_UNDEFINED;
+ return enter.object()->GetType();
+}
+
+PP_TimeTicks GetTimeStamp(PP_Resource event) {
+ EnterInputEvent enter(event, true);
+ if (enter.failed())
+ return 0.0;
+ return enter.object()->GetTimeStamp();
+}
+
+uint32_t GetModifiers(PP_Resource event) {
+ EnterInputEvent enter(event, true);
+ if (enter.failed())
+ return 0;
+ return enter.object()->GetModifiers();
+}
+
+const PPB_InputEvent g_ppb_input_event_thunk = {
+ &RequestInputEvents,
+ &RequestFilteringInputEvents,
+ &ClearInputEventRequest,
+ &IsInputEvent,
+ &GetType,
+ &GetTimeStamp,
+ &GetModifiers
+};
+
+// Mouse -----------------------------------------------------------------------
+
+PP_Bool IsMouseInputEvent(PP_Resource resource) {
+ if (!IsInputEvent(resource))
+ return PP_FALSE; // Prevent warning log in GetType.
+ PP_InputEvent_Type type = GetType(resource);
+ return PP_FromBool(type == PP_INPUTEVENT_TYPE_MOUSEDOWN ||
+ type == PP_INPUTEVENT_TYPE_MOUSEUP ||
+ type == PP_INPUTEVENT_TYPE_MOUSEMOVE ||
+ type == PP_INPUTEVENT_TYPE_MOUSEENTER ||
+ type == PP_INPUTEVENT_TYPE_MOUSELEAVE ||
+ type == PP_INPUTEVENT_TYPE_CONTEXTMENU);
+}
+
+PP_InputEvent_MouseButton GetMouseButton(PP_Resource mouse_event) {
+ EnterInputEvent enter(mouse_event, true);
+ if (enter.failed())
+ return PP_INPUTEVENT_MOUSEBUTTON_NONE;
+ return enter.object()->GetMouseButton();
+}
+
+PP_Point GetMousePosition(PP_Resource mouse_event) {
+ EnterInputEvent enter(mouse_event, true);
+ if (enter.failed())
+ return PP_MakePoint(0, 0);
+ return enter.object()->GetMousePosition();
+}
+
+int32_t GetMouseClickCount(PP_Resource mouse_event) {
+ EnterInputEvent enter(mouse_event, true);
+ if (enter.failed())
+ return 0;
+ return enter.object()->GetMouseClickCount();
+}
+
+const PPB_MouseInputEvent g_ppb_mouse_input_event_thunk = {
+ &IsMouseInputEvent,
+ &GetMouseButton,
+ &GetMousePosition,
+ &GetMouseClickCount
+};
+
+// Wheel -----------------------------------------------------------------------
+
+PP_Bool IsWheelInputEvent(PP_Resource resource) {
+ if (!IsInputEvent(resource))
+ return PP_FALSE; // Prevent warning log in GetType.
+ PP_InputEvent_Type type = GetType(resource);
+ return PP_FromBool(type == PP_INPUTEVENT_TYPE_MOUSEWHEEL);
+}
+
+PP_FloatPoint GetWheelDelta(PP_Resource wheel_event) {
+ EnterInputEvent enter(wheel_event, true);
+ if (enter.failed())
+ return PP_MakeFloatPoint(0.0f, 0.0f);
+ return enter.object()->GetWheelDelta();
+}
+
+PP_FloatPoint GetWheelTicks(PP_Resource wheel_event) {
+ EnterInputEvent enter(wheel_event, true);
+ if (enter.failed())
+ return PP_MakeFloatPoint(0.0f, 0.0f);
+ return enter.object()->GetWheelTicks();
+}
+
+PP_Bool GetWheelScrollByPage(PP_Resource wheel_event) {
+ EnterInputEvent enter(wheel_event, true);
+ if (enter.failed())
+ return PP_FALSE;
+ return enter.object()->GetWheelScrollByPage();
+}
+
+const PPB_WheelInputEvent g_ppb_wheel_input_event_thunk = {
+ &IsWheelInputEvent,
+ &GetWheelDelta,
+ &GetWheelTicks,
+ &GetWheelScrollByPage
+};
+
+// Keyboard --------------------------------------------------------------------
+
+PP_Bool IsKeyboardInputEvent(PP_Resource resource) {
+ if (!IsInputEvent(resource))
+ return PP_FALSE; // Prevent warning log in GetType.
+ PP_InputEvent_Type type = GetType(resource);
+ return PP_FromBool(type == PP_INPUTEVENT_TYPE_KEYDOWN ||
+ type == PP_INPUTEVENT_TYPE_KEYUP ||
+ type == PP_INPUTEVENT_TYPE_CHAR);
+}
+
+uint32_t GetKeyCode(PP_Resource key_event) {
+ EnterInputEvent enter(key_event, true);
+ if (enter.failed())
+ return 0;
+ return enter.object()->GetKeyCode();
+}
+
+PP_Var GetCharacterText(PP_Resource character_event) {
+ EnterInputEvent enter(character_event, true);
+ if (enter.failed())
+ return PP_MakeUndefined();
+ return enter.object()->GetCharacterText();
+}
+
+const PPB_KeyboardInputEvent g_ppb_keyboard_input_event_thunk = {
+ &IsKeyboardInputEvent,
+ &GetKeyCode,
+ &GetCharacterText
+};
+
+} // namespace
+
+const PPB_InputEvent* GetPPB_InputEvent_Thunk() {
+ return &g_ppb_input_event_thunk;
+}
+
+const PPB_MouseInputEvent* GetPPB_MouseInputEvent_Thunk() {
+ return &g_ppb_mouse_input_event_thunk;
+}
+
+const PPB_KeyboardInputEvent* GetPPB_KeyboardInputEvent_Thunk() {
+ return &g_ppb_keyboard_input_event_thunk;
+}
+
+const PPB_WheelInputEvent* GetPPB_WheelInputEvent_Thunk() {
+ return &g_ppb_wheel_input_event_thunk;
+}
+
+} // namespace thunk
+} // namespace ppapi
diff --git a/ppapi/thunk/ppb_instance_api.h b/ppapi/thunk/ppb_instance_api.h
index f77da8a..f06a759 100644
--- a/ppapi/thunk/ppb_instance_api.h
+++ b/ppapi/thunk/ppb_instance_api.h
@@ -33,6 +33,14 @@ class PPB_Instance_FunctionAPI {
virtual PP_Bool SetFullscreen(PP_Instance instance, PP_Bool fullscreen) = 0;
virtual PP_Bool GetScreenSize(PP_Instance instance, PP_Size* size) = 0;
+ // InputEvent.
+ virtual int32_t RequestInputEvents(PP_Instance instance,
+ uint32_t event_classes) = 0;
+ virtual int32_t RequestFilteringInputEvents(PP_Instance instance,
+ uint32_t event_classes) = 0;
+ virtual void ClearInputEventRequest(PP_Instance instance,
+ uint32_t event_classes) = 0;
+
// Messaging.
virtual void PostMessage(PP_Instance instance, PP_Var message) = 0;
diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h
index 00c4ecf..bcd5caa 100644
--- a/ppapi/thunk/thunk.h
+++ b/ppapi/thunk/thunk.h
@@ -32,10 +32,13 @@ struct PPB_Graphics2D;
struct PPB_Graphics3D_Dev;
struct PPB_ImageData;
struct PPB_ImageDataTrusted;
+struct PPB_InputEvent;
struct PPB_Instance;
struct PPB_Instance_Private;
+struct PPB_KeyboardInputEvent;
struct PPB_LayerCompositor_Dev;
struct PPB_Messaging;
+struct PPB_MouseInputEvent;
struct PPB_Scrollbar_0_4_Dev;
struct PPB_Surface3D_Dev;
struct PPB_Transport_Dev;
@@ -45,6 +48,7 @@ struct PPB_URLRequestInfo;
struct PPB_URLResponseInfo;
struct PPB_VideoDecoder_Dev;
struct PPB_VideoLayer_Dev;
+struct PPB_WheelInputEvent;
struct PPB_Widget_Dev;
struct PPB_Zoom_Dev;
@@ -85,13 +89,16 @@ const PPB_GLESChromiumTextureMapping_Dev*
GetPPB_GLESChromiumTextureMapping_Thunk();
const PPB_Graphics2D* GetPPB_Graphics2D_Thunk();
const PPB_Graphics3D_Dev* GetPPB_Graphics3D_Thunk();
+const PPB_InputEvent* GetPPB_InputEvent_Thunk();
const PPB_ImageData* GetPPB_ImageData_Thunk();
const PPB_ImageDataTrusted* GetPPB_ImageDataTrusted_Thunk();
const PPB_Instance_0_4* GetPPB_Instance_0_4_Thunk();
const PPB_Instance_0_5* GetPPB_Instance_0_5_Thunk();
const PPB_Instance_Private* GetPPB_Instance_Private_Thunk();
+const PPB_KeyboardInputEvent* GetPPB_KeyboardInputEvent_Thunk();
const PPB_LayerCompositor_Dev* GetPPB_LayerCompositor_Thunk();
const PPB_Messaging* GetPPB_Messaging_Thunk();
+const PPB_MouseInputEvent* GetPPB_MouseInputEvent_Thunk();
const PPB_Scrollbar_0_4_Dev* GetPPB_Scrollbar_Thunk();
const PPB_Surface3D_Dev* GetPPB_Surface3D_Thunk();
const PPB_Transport_Dev* GetPPB_Transport_Thunk();
@@ -101,6 +108,7 @@ const PPB_URLRequestInfo* GetPPB_URLRequestInfo_Thunk();
const PPB_URLResponseInfo* GetPPB_URLResponseInfo_Thunk();
const PPB_VideoDecoder_Dev* GetPPB_VideoDecoder_Thunk();
const PPB_VideoLayer_Dev* GetPPB_VideoLayer_Thunk();
+const PPB_WheelInputEvent* GetPPB_WheelInputEvent_Thunk();
const PPB_Widget_Dev* GetPPB_Widget_Thunk();
const PPB_Zoom_Dev* GetPPB_Zoom_Thunk();