summaryrefslogtreecommitdiffstats
path: root/ppapi/thunk
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/thunk
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/thunk')
-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
4 files changed, 266 insertions, 0 deletions
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();