summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-21 23:15:10 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-21 23:15:10 +0000
commitcdf4e91a82d97b78c6b217a9423b762192a2fdcc (patch)
tree3eb688bef69938350a158531dac15b493be95ce0
parentdc169b24f5c68386dae030501f618cd9b805097a (diff)
downloadchromium_src-cdf4e91a82d97b78c6b217a9423b762192a2fdcc.zip
chromium_src-cdf4e91a82d97b78c6b217a9423b762192a2fdcc.tar.gz
chromium_src-cdf4e91a82d97b78c6b217a9423b762192a2fdcc.tar.bz2
ppapi: Add support for touch events.
The corresponding webkit side patch is at https://bugs.webkit.org/show_bug.cgi?id=89089 BUG=128236 TEST=manually, using the browser-plugin Review URL: https://chromiumcodereview.appspot.com/10543159 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143486 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ppapi/api/pp_touch_point.idl73
-rw-r--r--ppapi/api/ppb_input_event.idl152
-rw-r--r--ppapi/c/pp_touch_point.h86
-rw-r--r--ppapi/c/ppb_input_event.h162
-rw-r--r--ppapi/cpp/input_event.cc47
-rw-r--r--ppapi/cpp/input_event.h45
-rw-r--r--ppapi/cpp/touch_point.h54
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/browser_ppp_input_event.cc9
-rw-r--r--ppapi/ppapi_sources.gypi2
-rw-r--r--ppapi/proxy/ppapi_messages.h11
-rw-r--r--ppapi/shared_impl/ppb_input_event_shared.cc81
-rw-r--r--ppapi/shared_impl/ppb_input_event_shared.h12
-rw-r--r--ppapi/tests/all_c_includes.h3
-rw-r--r--ppapi/tests/all_cpp_includes.h13
-rw-r--r--ppapi/thunk/ppb_input_event_api.h7
-rw-r--r--ppapi/thunk/ppb_input_event_thunk.cc72
-rw-r--r--webkit/plugins/ppapi/event_conversion.cc154
17 files changed, 968 insertions, 15 deletions
diff --git a/ppapi/api/pp_touch_point.idl b/ppapi/api/pp_touch_point.idl
new file mode 100644
index 0000000..eba6c44
--- /dev/null
+++ b/ppapi/api/pp_touch_point.idl
@@ -0,0 +1,73 @@
+/* Copyright (c) 2012 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.
+ */
+
+
+/**
+ * This file defines the API to create a touch-point.
+ */
+
+/**
+ * The <code>PP_TouchPoint</code> represents all information about a single
+ * touch point, such ase position, id, rotation angle, and pressure.
+ */
+[assert_size(28), returnByValue]
+struct PP_TouchPoint {
+ /**
+ * The identifier for this TouchPoint. This corresponds to the order
+ * in which the points were pressed. For example, the first point to be
+ * pressed has an id of 0, the second has an id of 1, and so on. An id can be
+ * reused when a touch point is released. For example, if two fingers are
+ * down, with id 0 and 1, and finger 0 releases, the next finger to be
+ * pressed can be assigned to id 0.
+ */
+ uint32_t id;
+
+ /**
+ * The x-y pixel position of this TouchPoint, relative to the upper-left of
+ * the instance receiving the event.
+ */
+ PP_FloatPoint position;
+
+ /**
+ * The elliptical radii, in screen pixels, in the x and y direction of this
+ * TouchPoint.
+ */
+ PP_FloatPoint radius;
+
+ /**
+ * The angle of rotation in degrees of the elliptical model of this TouchPoint
+ * clockwise from "up."
+ */
+ float_t rotation_angle;
+
+ /**
+ * The pressure applied to this TouchPoint. This is typically a
+ * value between 0 and 1, with 0 indicating no pressure and 1 indicating
+ * some maximum pressure, but scaling differs depending on the hardware and
+ * the value is not guaranteed to stay within that range.
+ */
+ float_t pressure;
+};
+
+#inline c
+/**
+ * @addtogroup Functions
+ * @{
+ */
+
+/**
+ * PP_MakeTouchPoint() creates a <code>PP_TouchPoint</code>.
+ *
+ * @return A <code>PP_TouchPoint</code> structure.
+ */
+PP_INLINE struct PP_TouchPoint PP_MakeTouchPoint() {
+ struct PP_TouchPoint result = { 0, {0, 0}, {0, 0}, 0, 0 };
+ return result;
+}
+/**
+ * @}
+ */
+
+#endinl
diff --git a/ppapi/api/ppb_input_event.idl b/ppapi/api/ppb_input_event.idl
index 76eb091..4050584 100644
--- a/ppapi/api/ppb_input_event.idl
+++ b/ppapi/api/ppb_input_event.idl
@@ -133,7 +133,35 @@ enum PP_InputEvent_Type {
*
* Register for this event using the PP_INPUTEVENT_CLASS_IME class.
*/
- PP_INPUTEVENT_TYPE_IME_TEXT = 14
+ PP_INPUTEVENT_TYPE_IME_TEXT = 14,
+
+ /**
+ * Notification that a finger was placed on a touch-enabled device.
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_TOUCH class.
+ */
+ PP_INPUTEVENT_TYPE_TOUCHSTART = 15,
+
+ /**
+ * Notification that a finger was moved on a touch-enabled device.
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_TOUCH class.
+ */
+ PP_INPUTEVENT_TYPE_TOUCHMOVE = 16,
+
+ /**
+ * Notification that a finger was released on a touch-enabled device.
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_TOUCH class.
+ */
+ PP_INPUTEVENT_TYPE_TOUCHEND = 17,
+
+ /**
+ * Notification that a touch event was canceled.
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_TOUCH class.
+ */
+ PP_INPUTEVENT_TYPE_TOUCHCANCEL = 18
};
/**
@@ -730,3 +758,125 @@ interface PPB_KeyboardInputEvent {
PP_Var GetCharacterText([in] PP_Resource character_event);
};
+[assert_size(4)]
+enum PP_TouchListType {
+ /**
+ * The list of all TouchPoints which are currently down.
+ */
+ PP_TOUCHLIST_TYPE_TOUCHES = 0,
+
+ /**
+ * The list of all TouchPoints whose state has changed since the last
+ * TouchInputEvent.
+ */
+ PP_TOUCHLIST_TYPE_CHANGEDTOUCHES = 1,
+
+ /**
+ * The list of all TouchPoints which are targeting this plugin. This is a
+ * subset of Touches.
+ */
+ PP_TOUCHLIST_TYPE_TARGETTOUCHES = 2
+};
+
+/**
+ * The <code>PPB_TouchInputEvent</code> interface contains pointers to several
+ * functions related to touch events.
+ */
+[version=1.0, macro="PPB_TOUCH_INPUT_EVENT_INTERFACE"]
+interface PPB_TouchInputEvent {
+ /**
+ * Creates a touch input event with the given parameters. Normally you
+ * will get a touch event passed through the HandleInputEvent and will not
+ * need to create them, but some applications may want to create their own
+ * for internal use. The type must be one of the touch event types.
+ * This newly created touch input event does not have any touch point in any
+ * of the touch-point lists. <code>AddTouchPoint</code> should be called to
+ * add the touch-points.
+ *
+ * @param[in] instance The instance for which this event occurred.
+ *
+ * @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of
+ * input event.
+ *
+ * @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time
+ * when the event occurred.
+ *
+ * @param[in] modifiers A bit field combination of the
+ * <code>PP_InputEvent_Modifier</code> flags.
+ *
+ * @return A <code>PP_Resource</code> containing the new touch input event.
+ */
+ PP_Resource Create([in] PP_Instance instance,
+ [in] PP_InputEvent_Type type,
+ [in] PP_TimeTicks time_stamp,
+ [in] uint32_t modifiers);
+
+ /**
+ * Adds a touch point to the touch event in the specified touch-list.
+ *
+ * @param[in] touch_event A <code>PP_Resource</code> corresponding to a touch
+ * event.
+ *
+ * @param[in] list The list to add the touch point to.
+ *
+ * @param[in] point The point to add to the list.
+ */
+ void AddTouchPoint([in] PP_Resource touch_event,
+ [in] PP_TouchListType list,
+ [in] PP_TouchPoint point);
+
+ /**
+ * IsTouchInputEvent() determines if a resource is a touch event.
+ *
+ * @param[in] resource A <code>PP_Resource</code> corresponding to an event.
+ *
+ * @return <code>PP_TRUE</code> if the given resource is a valid touch input
+ * event, otherwise <code>PP_FALSE</code>.
+ */
+ PP_Bool IsTouchInputEvent([in] PP_Resource resource);
+
+ /**
+ * Returns the number of touch-points in the specified list.
+ *
+ * @param[in] resource A <code>PP_Resource</code> corresponding to a touch
+ * event.
+ *
+ * @param[in] list The list.
+ *
+ * @return The number of touch-points in the specified list.
+ */
+ uint32_t GetTouchCount([in] PP_Resource resource,
+ [in] PP_TouchListType list);
+
+ /**
+ * Returns the touch-point at the specified index from the specified list.
+ *
+ * @param[in] resource A <code>PP_Resource</code> corresponding to a touch
+ * event.
+ *
+ * @param[in] list The list.
+ *
+ * @param[in] index The index.
+ *
+ * @return A <code>PP_TouchPoint</code> representing the touch-point.
+ */
+ PP_TouchPoint GetTouchByIndex([in] PP_Resource resource,
+ [in] PP_TouchListType list,
+ [in] uint32_t index);
+
+ /**
+ * Returns the touch-point with the spcified touch-id in the specified list.
+ *
+ * @param[in] resource A <code>PP_Resource</code> corresponding to a touch
+ * event.
+ *
+ * @param[in] list The list.
+ *
+ * @param[in] touch_id The id of the touch-point.
+ *
+ * @return A <code>PP_TouchPoint</code> representing the touch-point.
+ */
+ PP_TouchPoint GetTouchById([in] PP_Resource resource,
+ [in] PP_TouchListType list,
+ [in] uint32_t touch_id);
+};
diff --git a/ppapi/c/pp_touch_point.h b/ppapi/c/pp_touch_point.h
new file mode 100644
index 0000000..4315ca6
--- /dev/null
+++ b/ppapi/c/pp_touch_point.h
@@ -0,0 +1,86 @@
+/* Copyright (c) 2012 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.
+ */
+
+/* From pp_touch_point.idl modified Thu Jun 21 16:46:17 2012. */
+
+#ifndef PPAPI_C_PP_TOUCH_POINT_H_
+#define PPAPI_C_PP_TOUCH_POINT_H_
+
+#include "ppapi/c/pp_macros.h"
+#include "ppapi/c/pp_point.h"
+#include "ppapi/c/pp_stdint.h"
+
+/**
+ * @file
+ * This file defines the API to create a touch-point.
+ */
+
+
+/**
+ * @addtogroup Structs
+ * @{
+ */
+/**
+ * The <code>PP_TouchPoint</code> represents all information about a single
+ * touch point, such ase position, id, rotation angle, and pressure.
+ */
+struct PP_TouchPoint {
+ /**
+ * The identifier for this TouchPoint. This corresponds to the order
+ * in which the points were pressed. For example, the first point to be
+ * pressed has an id of 0, the second has an id of 1, and so on. An id can be
+ * reused when a touch point is released. For example, if two fingers are
+ * down, with id 0 and 1, and finger 0 releases, the next finger to be
+ * pressed can be assigned to id 0.
+ */
+ uint32_t id;
+ /**
+ * The x-y pixel position of this TouchPoint, relative to the upper-left of
+ * the instance receiving the event.
+ */
+ struct PP_FloatPoint position;
+ /**
+ * The elliptical radii, in screen pixels, in the x and y direction of this
+ * TouchPoint.
+ */
+ struct PP_FloatPoint radius;
+ /**
+ * The angle of rotation in degrees of the elliptical model of this TouchPoint
+ * clockwise from "up."
+ */
+ float rotation_angle;
+ /**
+ * The pressure applied to this TouchPoint. This is typically a
+ * value between 0 and 1, with 0 indicating no pressure and 1 indicating
+ * some maximum pressure, but scaling differs depending on the hardware and
+ * the value is not guaranteed to stay within that range.
+ */
+ float pressure;
+};
+PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_TouchPoint, 28);
+/**
+ * @}
+ */
+
+/**
+ * @addtogroup Functions
+ * @{
+ */
+
+/**
+ * PP_MakeTouchPoint() creates a <code>PP_TouchPoint</code>.
+ *
+ * @return A <code>PP_TouchPoint</code> structure.
+ */
+PP_INLINE struct PP_TouchPoint PP_MakeTouchPoint() {
+ struct PP_TouchPoint result = { 0, {0, 0}, {0, 0}, 0, 0 };
+ return result;
+}
+/**
+ * @}
+ */
+
+#endif /* PPAPI_C_PP_TOUCH_POINT_H_ */
+
diff --git a/ppapi/c/ppb_input_event.h b/ppapi/c/ppb_input_event.h
index 2eb288c..d4637fb 100644
--- a/ppapi/c/ppb_input_event.h
+++ b/ppapi/c/ppb_input_event.h
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-/* From ppb_input_event.idl modified Mon Mar 5 10:11:05 2012. */
+/* From ppb_input_event.idl modified Thu Jun 21 17:17:39 2012. */
#ifndef PPAPI_C_PPB_INPUT_EVENT_H_
#define PPAPI_C_PPB_INPUT_EVENT_H_
@@ -15,6 +15,7 @@
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/pp_stdint.h"
#include "ppapi/c/pp_time.h"
+#include "ppapi/c/pp_touch_point.h"
#include "ppapi/c/pp_var.h"
#define PPB_INPUT_EVENT_INTERFACE_1_0 "PPB_InputEvent;1.0"
@@ -31,6 +32,9 @@
#define PPB_KEYBOARD_INPUT_EVENT_INTERFACE \
PPB_KEYBOARD_INPUT_EVENT_INTERFACE_1_0
+#define PPB_TOUCH_INPUT_EVENT_INTERFACE_1_0 "PPB_TouchInputEvent;1.0"
+#define PPB_TOUCH_INPUT_EVENT_INTERFACE PPB_TOUCH_INPUT_EVENT_INTERFACE_1_0
+
/**
* @file
* This file defines the Input Event interfaces.
@@ -144,7 +148,31 @@ typedef enum {
*
* Register for this event using the PP_INPUTEVENT_CLASS_IME class.
*/
- PP_INPUTEVENT_TYPE_IME_TEXT = 14
+ PP_INPUTEVENT_TYPE_IME_TEXT = 14,
+ /**
+ * Notification that a finger was placed on a touch-enabled device.
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_TOUCH class.
+ */
+ PP_INPUTEVENT_TYPE_TOUCHSTART = 15,
+ /**
+ * Notification that a finger was moved on a touch-enabled device.
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_TOUCH class.
+ */
+ PP_INPUTEVENT_TYPE_TOUCHMOVE = 16,
+ /**
+ * Notification that a finger was released on a touch-enabled device.
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_TOUCH class.
+ */
+ PP_INPUTEVENT_TYPE_TOUCHEND = 17,
+ /**
+ * Notification that a touch event was canceled.
+ *
+ * Register for this event using the PP_INPUTEVENT_CLASS_TOUCH class.
+ */
+ PP_INPUTEVENT_TYPE_TOUCHCANCEL = 18
} PP_InputEvent_Type;
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_Type, 4);
@@ -709,5 +737,135 @@ typedef struct PPB_KeyboardInputEvent_1_0 PPB_KeyboardInputEvent;
* @}
*/
+/**
+ * @addtogroup Enums
+ * @{
+ */
+typedef enum {
+ /**
+ * The list of all TouchPoints which are currently down.
+ */
+ PP_TOUCHLIST_TYPE_TOUCHES = 0,
+ /**
+ * The list of all TouchPoints whose state has changed since the last
+ * TouchInputEvent.
+ */
+ PP_TOUCHLIST_TYPE_CHANGEDTOUCHES = 1,
+ /**
+ * The list of all TouchPoints which are targeting this plugin. This is a
+ * subset of Touches.
+ */
+ PP_TOUCHLIST_TYPE_TARGETTOUCHES = 2
+} PP_TouchListType;
+PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TouchListType, 4);
+/**
+ * @}
+ */
+
+/**
+ * @addtogroup Interfaces
+ * @{
+ */
+/**
+ * The <code>PPB_TouchInputEvent</code> interface contains pointers to several
+ * functions related to touch events.
+ */
+struct PPB_TouchInputEvent_1_0 {
+ /**
+ * Creates a touch input event with the given parameters. Normally you
+ * will get a touch event passed through the HandleInputEvent and will not
+ * need to create them, but some applications may want to create their own
+ * for internal use. The type must be one of the touch event types.
+ * This newly created touch input event does not have any touch point in any
+ * of the touch-point lists. <code>AddTouchPoint</code> should be called to
+ * add the touch-points.
+ *
+ * @param[in] instance The instance for which this event occurred.
+ *
+ * @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of
+ * input event.
+ *
+ * @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time
+ * when the event occurred.
+ *
+ * @param[in] modifiers A bit field combination of the
+ * <code>PP_InputEvent_Modifier</code> flags.
+ *
+ * @return A <code>PP_Resource</code> containing the new touch input event.
+ */
+ PP_Resource (*Create)(PP_Instance instance,
+ PP_InputEvent_Type type,
+ PP_TimeTicks time_stamp,
+ uint32_t modifiers);
+ /**
+ * Adds a touch point to the touch event in the specified touch-list.
+ *
+ * @param[in] touch_event A <code>PP_Resource</code> corresponding to a touch
+ * event.
+ *
+ * @param[in] list The list to add the touch point to.
+ *
+ * @param[in] point The point to add to the list.
+ */
+ void (*AddTouchPoint)(PP_Resource touch_event,
+ PP_TouchListType list,
+ const struct PP_TouchPoint* point);
+ /**
+ * IsTouchInputEvent() determines if a resource is a touch event.
+ *
+ * @param[in] resource A <code>PP_Resource</code> corresponding to an event.
+ *
+ * @return <code>PP_TRUE</code> if the given resource is a valid touch input
+ * event, otherwise <code>PP_FALSE</code>.
+ */
+ PP_Bool (*IsTouchInputEvent)(PP_Resource resource);
+ /**
+ * Returns the number of touch-points in the specified list.
+ *
+ * @param[in] resource A <code>PP_Resource</code> corresponding to a touch
+ * event.
+ *
+ * @param[in] list The list.
+ *
+ * @return The number of touch-points in the specified list.
+ */
+ uint32_t (*GetTouchCount)(PP_Resource resource, PP_TouchListType list);
+ /**
+ * Returns the touch-point at the specified index from the specified list.
+ *
+ * @param[in] resource A <code>PP_Resource</code> corresponding to a touch
+ * event.
+ *
+ * @param[in] list The list.
+ *
+ * @param[in] index The index.
+ *
+ * @return A <code>PP_TouchPoint</code> representing the touch-point.
+ */
+ struct PP_TouchPoint (*GetTouchByIndex)(PP_Resource resource,
+ PP_TouchListType list,
+ uint32_t index);
+ /**
+ * Returns the touch-point with the spcified touch-id in the specified list.
+ *
+ * @param[in] resource A <code>PP_Resource</code> corresponding to a touch
+ * event.
+ *
+ * @param[in] list The list.
+ *
+ * @param[in] touch_id The id of the touch-point.
+ *
+ * @return A <code>PP_TouchPoint</code> representing the touch-point.
+ */
+ struct PP_TouchPoint (*GetTouchById)(PP_Resource resource,
+ PP_TouchListType list,
+ uint32_t touch_id);
+};
+
+typedef struct PPB_TouchInputEvent_1_0 PPB_TouchInputEvent;
+/**
+ * @}
+ */
+
#endif /* PPAPI_C_PPB_INPUT_EVENT_H_ */
diff --git a/ppapi/cpp/input_event.cc b/ppapi/cpp/input_event.cc
index c78095d..409585e 100644
--- a/ppapi/cpp/input_event.cc
+++ b/ppapi/cpp/input_event.cc
@@ -8,6 +8,7 @@
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
#include "ppapi/cpp/point.h"
+#include "ppapi/cpp/touch_point.h"
#include "ppapi/cpp/var.h"
namespace pp {
@@ -218,4 +219,50 @@ Var KeyboardInputEvent::GetCharacterText() const {
pp_resource()));
}
+// TouchInputEvent ------------------------------------------------------------
+TouchInputEvent::TouchInputEvent() : InputEvent() {
+}
+
+TouchInputEvent::TouchInputEvent(const InputEvent& event) : InputEvent() {
+ if (!has_interface<PPB_TouchInputEvent_1_0>())
+ return;
+ // Type check the input event before setting it.
+ if (get_interface<PPB_TouchInputEvent_1_0>()->IsTouchInputEvent(
+ event.pp_resource())) {
+ Module::Get()->core()->AddRefResource(event.pp_resource());
+ PassRefFromConstructor(event.pp_resource());
+ }
+}
+
+void TouchInputEvent::AddTouchPoint(PP_TouchListType list,
+ PP_TouchPoint point) {
+ if (!has_interface<PPB_TouchInputEvent_1_0>())
+ return;
+ get_interface<PPB_TouchInputEvent_1_0>()->AddTouchPoint(pp_resource(), list,
+ &point);
+}
+
+uint32_t TouchInputEvent::GetTouchCount(PP_TouchListType list) const {
+ if (!has_interface<PPB_TouchInputEvent_1_0>())
+ return 0;
+ return get_interface<PPB_TouchInputEvent_1_0>()->GetTouchCount(pp_resource(),
+ list);
+}
+
+TouchPoint TouchInputEvent::GetTouchById(PP_TouchListType list,
+ uint32_t id) const {
+ if (!has_interface<PPB_TouchInputEvent_1_0>())
+ return TouchPoint();
+ return TouchPoint(get_interface<PPB_TouchInputEvent_1_0>()->
+ GetTouchById(pp_resource(), list, id));
+}
+
+TouchPoint TouchInputEvent::GetTouchByIndex(PP_TouchListType list,
+ uint32_t index) const {
+ if (!has_interface<PPB_TouchInputEvent_1_0>())
+ return TouchPoint();
+ return TouchPoint(get_interface<PPB_TouchInputEvent_1_0>()->
+ GetTouchByIndex(pp_resource(), list, index));
+}
+
} // namespace pp
diff --git a/ppapi/cpp/input_event.h b/ppapi/cpp/input_event.h
index 653aae5..379e0e8 100644
--- a/ppapi/cpp/input_event.h
+++ b/ppapi/cpp/input_event.h
@@ -9,6 +9,7 @@
#include "ppapi/c/ppb_input_event.h"
#include "ppapi/cpp/resource.h"
+#include "ppapi/cpp/touch_point.h"
/// @file
/// This file defines the API used to handle mouse and keyboard input events.
@@ -298,6 +299,50 @@ class KeyboardInputEvent : public InputEvent {
Var GetCharacterText() const;
};
+class TouchInputEvent : public InputEvent {
+ public:
+ /// Constructs an is_null() touch input event object.
+ TouchInputEvent();
+
+ /// Constructs a touch input event object from the given generic input event.
+ /// If the given event is itself is_null() or is not a touch input event, the
+ /// touch object will be is_null().
+ explicit TouchInputEvent(const InputEvent& event);
+
+ /// Constructs a touch input even from the given parameters.
+ ///
+ /// @param[in] instance The instance for which this event occured.
+ ///
+ /// @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of
+ /// input event.
+ ///
+ /// @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time
+ /// when the event occured.
+ ///
+ /// @param[in] modifiers A bit field combination of the
+ /// <code>PP_InputEvent_Modifier</code> flags.
+ TouchInputEvent(const InstanceHandle& instance,
+ PP_InputEvent_Type type,
+ PP_TimeTicks time_stamp,
+ uint32_t modifiers);
+
+ /// Adds the touch-point to the specified TouchList.
+ void AddTouchPoint(PP_TouchListType list, PP_TouchPoint point);
+
+ /// @return The number of TouchPoints in this TouchList.
+ uint32_t GetTouchCount(PP_TouchListType list) const;
+
+ /// @return The TouchPoint at the given index of the given list, or an empty
+ /// TouchPoint if the index is out of range.
+ TouchPoint GetTouchByIndex(PP_TouchListType list, uint32_t index) const;
+
+ /// @return The TouchPoint in the given list with the given identifier, or an
+ /// empty TouchPoint if the list does not contain a TouchPoint with that
+ /// identifier.
+ TouchPoint GetTouchById(PP_TouchListType list, uint32_t id) const;
+};
+
+
} // namespace pp
#endif // PPAPI_CPP_INPUT_EVENT_H_
diff --git a/ppapi/cpp/touch_point.h b/ppapi/cpp/touch_point.h
new file mode 100644
index 0000000..0868061
--- /dev/null
+++ b/ppapi/cpp/touch_point.h
@@ -0,0 +1,54 @@
+// Copyright (c) 2012 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_TOUCH_POINT_H_
+#define PPAPI_CPP_TOUCH_POINT_H_
+
+#include "ppapi/c/ppb_input_event.h"
+#include "ppapi/cpp/input_event.h"
+#include "ppapi/cpp/point.h"
+
+namespace pp {
+
+/// Wrapper class for PP_TouchPoint.
+class TouchPoint {
+ public:
+ TouchPoint() : touch_point_(PP_MakeTouchPoint()) {}
+
+ TouchPoint(const PP_TouchPoint& point) : touch_point_(point) {}
+
+ /// @return The identifier for this TouchPoint. This corresponds to the order
+ /// in which the points were pressed. For example, the first point to be
+ /// pressed has an id of 0, the second has an id of 1, and so on. An id can be
+ /// reused when a touch point is released. For example, if two fingers are
+ /// down, with id 0 and 1, and finger 0 releases, the next finger to be
+ /// pressed can be assigned to id 0.
+ uint32_t id() const { return touch_point_.id; }
+
+ /// @return The x-y coordinates of this TouchPoint, in DOM coordinate space.
+ FloatPoint position() const {
+ return pp::FloatPoint(touch_point_.position);
+ }
+
+ /// @return The elliptical radii, in screen pixels, in the x and y direction
+ /// of this TouchPoint.
+ FloatPoint radii() const { return pp::FloatPoint(touch_point_.radius); }
+
+ /// @return The angle of rotation of the elliptical model of this TouchPoint
+ /// from the y-axis.
+ float rotation_angle() const { return touch_point_.rotation_angle; }
+
+ /// @return The pressure applied to this TouchPoint. This is typically a
+ /// value between 0 and 1, with 0 indicating no pressure and 1 indicating
+ /// some maximum pressure, but scaling differs depending on the hardware and
+ /// the value is not guaranteed to stay within that range.
+ float pressure() const { return touch_point_.pressure; }
+
+ private:
+ PP_TouchPoint touch_point_;
+};
+
+} // namespace pp
+
+#endif /* PPAPI_CPP_TOUCH_POINT_H_ */
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppp_input_event.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppp_input_event.cc
index 0217db0..65856a4 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppp_input_event.cc
+++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppp_input_event.cc
@@ -7,9 +7,9 @@
#include "native_client/src/include/nacl_scoped_ptr.h"
#include "native_client/src/include/portability.h"
#include "native_client/src/shared/ppapi_proxy/browser_globals.h"
+#include "native_client/src/shared/ppapi_proxy/browser_ppp.h"
#include "native_client/src/shared/ppapi_proxy/input_event_data.h"
#include "native_client/src/shared/ppapi_proxy/object_serialize.h"
-#include "native_client/src/shared/ppapi_proxy/browser_ppp.h"
#include "native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppp_rpc.h"
#include "native_client/src/shared/ppapi_proxy/utility.h"
#include "ppapi/c/pp_resource.h"
@@ -76,6 +76,13 @@ PP_Bool HandleInputEvent(PP_Instance instance, PP_Resource input_event) {
DebugPrintf(" No implementation for event type %d\n",
data.event_type);
return PP_FALSE;
+ case PP_INPUTEVENT_TYPE_TOUCHSTART:
+ case PP_INPUTEVENT_TYPE_TOUCHMOVE:
+ case PP_INPUTEVENT_TYPE_TOUCHEND:
+ case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
+ DebugPrintf(" No implementation for event type %d\n",
+ data.event_type);
+ return PP_FALSE;
// No default case; if any new types are added we should get a compile
// warning.
}
diff --git a/ppapi/ppapi_sources.gypi b/ppapi/ppapi_sources.gypi
index 155da5a..b54c8e3 100644
--- a/ppapi/ppapi_sources.gypi
+++ b/ppapi/ppapi_sources.gypi
@@ -40,6 +40,7 @@
'c/ppb_mouse_cursor.h',
'c/ppb_mouse_lock.h',
'c/ppb_opengles2.h',
+ 'c/pp_touch_point.h',
'c/ppb_url_loader.h',
'c/ppb_url_request_info.h',
'c/ppb_url_response_info.h',
@@ -177,6 +178,7 @@
'cpp/resource.cc',
'cpp/resource.h',
'cpp/size.h',
+ 'cpp/touch_point.h',
'cpp/url_loader.cc',
'cpp/url_loader.h',
'cpp/url_request_info.cc',
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index 759459f..69005e5 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -146,6 +146,14 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::ViewData)
IPC_STRUCT_TRAITS_MEMBER(clip_rect)
IPC_STRUCT_TRAITS_END()
+IPC_STRUCT_TRAITS_BEGIN(PP_TouchPoint)
+ IPC_STRUCT_TRAITS_MEMBER(id)
+ IPC_STRUCT_TRAITS_MEMBER(position)
+ IPC_STRUCT_TRAITS_MEMBER(radius)
+ IPC_STRUCT_TRAITS_MEMBER(rotation_angle)
+ IPC_STRUCT_TRAITS_MEMBER(pressure)
+IPC_STRUCT_TRAITS_END()
+
IPC_STRUCT_TRAITS_BEGIN(ppapi::Preferences)
IPC_STRUCT_TRAITS_MEMBER(standard_font_family_map)
IPC_STRUCT_TRAITS_MEMBER(fixed_font_family_map)
@@ -177,6 +185,9 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::InputEventData)
IPC_STRUCT_TRAITS_MEMBER(composition_target_segment)
IPC_STRUCT_TRAITS_MEMBER(composition_selection_start)
IPC_STRUCT_TRAITS_MEMBER(composition_selection_end)
+ IPC_STRUCT_TRAITS_MEMBER(touches)
+ IPC_STRUCT_TRAITS_MEMBER(changed_touches)
+ IPC_STRUCT_TRAITS_MEMBER(target_touches)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(ppapi::HostPortPair)
diff --git a/ppapi/shared_impl/ppb_input_event_shared.cc b/ppapi/shared_impl/ppb_input_event_shared.cc
index 7b07de9..cc28027 100644
--- a/ppapi/shared_impl/ppb_input_event_shared.cc
+++ b/ppapi/shared_impl/ppb_input_event_shared.cc
@@ -26,7 +26,10 @@ InputEventData::InputEventData()
character_text(),
composition_target_segment(-1),
composition_selection_start(0),
- composition_selection_end(0) {
+ composition_selection_end(0),
+ touches(),
+ changed_touches(),
+ target_touches() {
}
InputEventData::~InputEventData() {
@@ -127,6 +130,82 @@ void PPB_InputEvent_Shared::GetIMESelection(uint32_t* start, uint32_t* end) {
*end = data_.composition_selection_end;
}
+void PPB_InputEvent_Shared::AddTouchPoint(PP_TouchListType list,
+ const PP_TouchPoint& point) {
+ switch (list) {
+ case PP_TOUCHLIST_TYPE_TOUCHES:
+ data_.touches.push_back(point);
+ break;
+ case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES:
+ data_.changed_touches.push_back(point);
+ break;
+ case PP_TOUCHLIST_TYPE_TARGETTOUCHES:
+ data_.target_touches.push_back(point);
+ break;
+ default:
+ break;
+ }
+}
+
+uint32_t PPB_InputEvent_Shared::GetTouchCount(PP_TouchListType list) {
+ switch (list) {
+ case PP_TOUCHLIST_TYPE_TOUCHES:
+ return data_.touches.size();
+ case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES:
+ return data_.changed_touches.size();
+ case PP_TOUCHLIST_TYPE_TARGETTOUCHES:
+ return data_.target_touches.size();
+ default:
+ return 0;
+ }
+ return data_.touches.size();
+}
+
+PP_TouchPoint PPB_InputEvent_Shared::GetTouchByIndex(PP_TouchListType list,
+ uint32_t index) {
+ std::vector<PP_TouchPoint>* points;
+ switch (list) {
+ case PP_TOUCHLIST_TYPE_TOUCHES:
+ points = &data_.touches;
+ break;
+ case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES:
+ points = &data_.changed_touches;
+ break;
+ case PP_TOUCHLIST_TYPE_TARGETTOUCHES:
+ points = &data_.target_touches;
+ break;
+ default:
+ return PP_MakeTouchPoint();
+ }
+ if (index >= points->size()) {
+ return PP_MakeTouchPoint();
+ }
+ return points->at(index);
+}
+
+PP_TouchPoint PPB_InputEvent_Shared::GetTouchById(PP_TouchListType list,
+ uint32_t id) {
+ const std::vector<PP_TouchPoint>* points;
+ switch (list) {
+ case PP_TOUCHLIST_TYPE_TOUCHES:
+ points = &data_.touches;
+ break;
+ case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES:
+ points = &data_.changed_touches;
+ break;
+ case PP_TOUCHLIST_TYPE_TARGETTOUCHES:
+ points = &data_.target_touches;
+ break;
+ default:
+ return PP_MakeTouchPoint();
+ }
+ for (size_t i = 0; i < points->size(); i++) {
+ if (points->at(i).id == id)
+ return points->at(i);
+ }
+ return PP_MakeTouchPoint();
+}
+
//static
PP_Resource PPB_InputEvent_Shared::CreateIMEInputEvent(
ResourceObjectType type,
diff --git a/ppapi/shared_impl/ppb_input_event_shared.h b/ppapi/shared_impl/ppb_input_event_shared.h
index 74108b3..2518e9e 100644
--- a/ppapi/shared_impl/ppb_input_event_shared.h
+++ b/ppapi/shared_impl/ppb_input_event_shared.h
@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
+#include "ppapi/c/ppb_input_event.h"
#include "ppapi/shared_impl/resource.h"
#include "ppapi/thunk/ppb_input_event_api.h"
@@ -48,6 +49,10 @@ struct PPAPI_SHARED_EXPORT InputEventData {
int32_t composition_target_segment;
uint32_t composition_selection_start;
uint32_t composition_selection_end;
+
+ std::vector<PP_TouchPoint> touches;
+ std::vector<PP_TouchPoint> changed_touches;
+ std::vector<PP_TouchPoint> target_touches;
};
// This simple class implements the PPB_InputEvent_API in terms of the
@@ -83,6 +88,13 @@ class PPAPI_SHARED_EXPORT PPB_InputEvent_Shared
virtual uint32_t GetIMESegmentOffset(uint32_t index) OVERRIDE;
virtual int32_t GetIMETargetSegment() OVERRIDE;
virtual void GetIMESelection(uint32_t* start, uint32_t* end) OVERRIDE;
+ virtual void AddTouchPoint(PP_TouchListType list,
+ const PP_TouchPoint& point) OVERRIDE;
+ virtual uint32_t GetTouchCount(PP_TouchListType list) OVERRIDE;
+ virtual PP_TouchPoint GetTouchByIndex(PP_TouchListType list,
+ uint32_t index) OVERRIDE;
+ virtual PP_TouchPoint GetTouchById(PP_TouchListType list,
+ uint32_t id) OVERRIDE;
// Implementations for event creation.
static PP_Resource CreateIMEInputEvent(ResourceObjectType type,
diff --git a/ppapi/tests/all_c_includes.h b/ppapi/tests/all_c_includes.h
index 9dae089..8dd43df 100644
--- a/ppapi/tests/all_c_includes.h
+++ b/ppapi/tests/all_c_includes.h
@@ -46,7 +46,6 @@
#include "ppapi/c/dev/ppp_video_decoder_dev.h"
#include "ppapi/c/dev/ppp_widget_dev.h"
#include "ppapi/c/dev/ppp_zoom_dev.h"
-#include "ppapi/c/trusted/ppb_file_io_trusted.h"
#include "ppapi/c/pp_bool.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
@@ -62,6 +61,7 @@
#include "ppapi/c/pp_size.h"
#include "ppapi/c/pp_stdint.h"
#include "ppapi/c/pp_time.h"
+#include "ppapi/c/pp_touch_point.h"
#include "ppapi/c/pp_var.h"
#include "ppapi/c/ppb.h"
#include "ppapi/c/ppb_audio.h"
@@ -110,6 +110,7 @@
#include "ppapi/c/private/ppb_x509_certificate_private.h"
#include "ppapi/c/private/ppp_instance_private.h"
#include "ppapi/c/trusted/ppb_audio_trusted.h"
+#include "ppapi/c/trusted/ppb_file_io_trusted.h"
#include "ppapi/c/trusted/ppb_graphics_3d_trusted.h"
#include "ppapi/c/trusted/ppb_image_data_trusted.h"
#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
diff --git a/ppapi/tests/all_cpp_includes.h b/ppapi/tests/all_cpp_includes.h
index 0aca7aa..7a18802 100644
--- a/ppapi/tests/all_cpp_includes.h
+++ b/ppapi/tests/all_cpp_includes.h
@@ -46,23 +46,24 @@
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
#include "ppapi/cpp/mouse_lock.h"
+#include "ppapi/cpp/point.h"
#include "ppapi/cpp/private/flash_fullscreen.h"
#include "ppapi/cpp/private/instance_private.h"
-#include "ppapi/cpp/point.h"
+#include "ppapi/cpp/private/instance_private.h"
+#include "ppapi/cpp/private/net_address_private.h"
+#include "ppapi/cpp/private/tcp_socket_private.h"
+#include "ppapi/cpp/private/udp_socket_private.h"
+#include "ppapi/cpp/private/var_private.h"
#include "ppapi/cpp/rect.h"
#include "ppapi/cpp/resource.h"
#include "ppapi/cpp/size.h"
+#include "ppapi/cpp/touch_point.h"
#include "ppapi/cpp/url_loader.h"
#include "ppapi/cpp/url_request_info.h"
#include "ppapi/cpp/url_response_info.h"
#include "ppapi/cpp/var.h"
#include "ppapi/cpp/var_array_buffer.h"
#include "ppapi/cpp/websocket.h"
-#include "ppapi/cpp/private/instance_private.h"
-#include "ppapi/cpp/private/net_address_private.h"
-#include "ppapi/cpp/private/tcp_socket_private.h"
-#include "ppapi/cpp/private/udp_socket_private.h"
-#include "ppapi/cpp/private/var_private.h"
#include "ppapi/utility/graphics/paint_aggregator.h"
#include "ppapi/utility/graphics/paint_manager.h"
#include "ppapi/utility/non_thread_safe_ref_count.h"
diff --git a/ppapi/thunk/ppb_input_event_api.h b/ppapi/thunk/ppb_input_event_api.h
index eda6b8e..18bda79 100644
--- a/ppapi/thunk/ppb_input_event_api.h
+++ b/ppapi/thunk/ppb_input_event_api.h
@@ -42,6 +42,13 @@ class PPAPI_THUNK_EXPORT PPB_InputEvent_API {
virtual uint32_t GetIMESegmentOffset(uint32_t index) = 0;
virtual int32_t GetIMETargetSegment() = 0;
virtual void GetIMESelection(uint32_t* start, uint32_t* end) = 0;
+ virtual void AddTouchPoint(PP_TouchListType list,
+ const PP_TouchPoint& point) = 0;
+ virtual uint32_t GetTouchCount(PP_TouchListType list) = 0;
+ virtual PP_TouchPoint GetTouchByIndex(PP_TouchListType list,
+ uint32_t index) = 0;
+ virtual PP_TouchPoint GetTouchById(PP_TouchListType list,
+ uint32_t id) = 0;
};
} // namespace thunk
diff --git a/ppapi/thunk/ppb_input_event_thunk.cc b/ppapi/thunk/ppb_input_event_thunk.cc
index 47f9e51..7d527a6 100644
--- a/ppapi/thunk/ppb_input_event_thunk.cc
+++ b/ppapi/thunk/ppb_input_event_thunk.cc
@@ -3,11 +3,11 @@
// 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"
+#include "ppapi/thunk/thunk.h"
namespace ppapi {
namespace thunk {
@@ -379,6 +379,72 @@ const PPB_IMEInputEvent_Dev_0_2 g_ppb_ime_input_event_0_2_thunk = {
&GetIMESelection
};
+// Touch -----------------------------------------------------------------------
+
+PP_Resource CreateTouchInputEvent(PP_Instance instance,
+ PP_InputEvent_Type type,
+ PP_TimeTicks time_stamp,
+ uint32_t modifiers) {
+ EnterResourceCreation enter(instance);
+ if (enter.failed())
+ return 0;
+ // TODO(sad):
+ return 0;
+}
+
+void AddTouchPoint(PP_Resource touch_event,
+ PP_TouchListType list,
+ const PP_TouchPoint* point) {
+ EnterInputEvent enter(touch_event, true);
+ if (enter.failed())
+ return;
+ return enter.object()->AddTouchPoint(list, *point);
+}
+
+PP_Bool IsTouchInputEvent(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_TOUCHSTART ||
+ type == PP_INPUTEVENT_TYPE_TOUCHMOVE ||
+ type == PP_INPUTEVENT_TYPE_TOUCHEND ||
+ type == PP_INPUTEVENT_TYPE_TOUCHCANCEL);
+}
+
+uint32_t GetTouchCount(PP_Resource touch_event, PP_TouchListType list) {
+ EnterInputEvent enter(touch_event, true);
+ if (enter.failed())
+ return 0;
+ return enter.object()->GetTouchCount(list);
+}
+
+struct PP_TouchPoint GetTouchByIndex(PP_Resource touch_event,
+ PP_TouchListType list,
+ uint32_t index) {
+ EnterInputEvent enter(touch_event, true);
+ if (enter.failed())
+ return PP_MakeTouchPoint();
+ return enter.object()->GetTouchByIndex(list, index);
+}
+
+struct PP_TouchPoint GetTouchById(PP_Resource touch_event,
+ PP_TouchListType list,
+ uint32_t id) {
+ EnterInputEvent enter(touch_event, true);
+ if (enter.failed())
+ return PP_MakeTouchPoint();
+ return enter.object()->GetTouchById(list, id);
+}
+
+const PPB_TouchInputEvent_1_0 g_ppb_touch_input_event_thunk = {
+ &CreateTouchInputEvent,
+ &AddTouchPoint,
+ &IsTouchInputEvent,
+ &GetTouchCount,
+ &GetTouchByIndex,
+ &GetTouchById
+};
+
} // namespace
const PPB_InputEvent_1_0* GetPPB_InputEvent_1_0_Thunk() {
@@ -414,5 +480,9 @@ const PPB_IMEInputEvent_Dev_0_2* GetPPB_IMEInputEvent_Dev_0_2_Thunk() {
return &g_ppb_ime_input_event_0_2_thunk;
}
+const PPB_TouchInputEvent_1_0* GetPPB_TouchInputEvent_Thunk() {
+ return &g_ppb_touch_input_event_thunk;
+}
+
} // namespace thunk
} // namespace ppapi
diff --git a/webkit/plugins/ppapi/event_conversion.cc b/webkit/plugins/ppapi/event_conversion.cc
index 22f1b42a8..ab35365 100644
--- a/webkit/plugins/ppapi/event_conversion.cc
+++ b/webkit/plugins/ppapi/event_conversion.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <map>
+
#include "webkit/plugins/ppapi/event_conversion.h"
#include "base/basictypes.h"
@@ -10,14 +12,14 @@
#include "base/memory/scoped_ptr.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
-#include "base/utf_string_conversions.h"
#include "base/utf_string_conversion_utils.h"
+#include "base/utf_string_conversions.h"
#include "ppapi/c/pp_input_event.h"
#include "ppapi/shared_impl/ppb_input_event_shared.h"
#include "ppapi/shared_impl/time_conversion.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
#include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/usb_key_code_conversion.h"
@@ -29,6 +31,8 @@ using WebKit::WebKeyboardEvent;
using WebKit::WebMouseEvent;
using WebKit::WebMouseWheelEvent;
using WebKit::WebString;
+using WebKit::WebTouchEvent;
+using WebKit::WebTouchPoint;
using WebKit::WebUChar;
namespace webkit {
@@ -97,6 +101,14 @@ PP_InputEvent_Type ConvertEventTypes(WebInputEvent::Type wetype) {
return PP_INPUTEVENT_TYPE_KEYUP;
case WebInputEvent::Char:
return PP_INPUTEVENT_TYPE_CHAR;
+ case WebInputEvent::TouchStart:
+ return PP_INPUTEVENT_TYPE_TOUCHSTART;
+ case WebInputEvent::TouchMove:
+ return PP_INPUTEVENT_TYPE_TOUCHMOVE;
+ case WebInputEvent::TouchEnd:
+ return PP_INPUTEVENT_TYPE_TOUCHEND;
+ case WebInputEvent::TouchCancel:
+ return PP_INPUTEVENT_TYPE_TOUCHCANCEL;
case WebInputEvent::Undefined:
default:
return PP_INPUTEVENT_TYPE_UNDEFINED;
@@ -199,6 +211,127 @@ void AppendMouseWheelEvent(const WebInputEvent& event,
result_events->push_back(result);
}
+void SetPPTouchPoints(const WebTouchPoint* touches, uint32_t touches_length,
+ std::vector<PP_TouchPoint>* result) {
+ for (uint32_t i = 0; i < touches_length; i++) {
+ const WebTouchPoint& touch_point = touches[i];
+ PP_TouchPoint pp_pt;
+ pp_pt.id = touch_point.id;
+ pp_pt.position.x = touch_point.position.x;
+ pp_pt.position.y = touch_point.position.y;
+ pp_pt.radius.x = touch_point.radiusX;
+ pp_pt.radius.y = touch_point.radiusY;
+ pp_pt.rotation_angle = touch_point.rotationAngle;
+ pp_pt.pressure = touch_point.force;
+ result->push_back(pp_pt);
+ }
+}
+
+void AppendTouchEvent(const WebInputEvent& event,
+ std::vector<InputEventData>* result_events) {
+ const WebTouchEvent& touch_event =
+ reinterpret_cast<const WebTouchEvent&>(event);
+
+ InputEventData result = GetEventWithCommonFieldsAndType(event);
+ SetPPTouchPoints(touch_event.touches, touch_event.touchesLength,
+ &result.touches);
+ SetPPTouchPoints(touch_event.changedTouches, touch_event.changedTouchesLength,
+ &result.changed_touches);
+ SetPPTouchPoints(touch_event.targetTouches, touch_event.targetTouchesLength,
+ &result.target_touches);
+
+ result_events->push_back(result);
+}
+
+// Structure used to map touch point id's to touch states. Since the pepper
+// touch event structure does not have states for individual touch points and
+// instead relies on the event type in combination with the set of touch lists,
+// we have to set the state for the changed touches to be the same as the event
+// type and all others to be 'stationary.'
+typedef std::map<uint32_t, WebTouchPoint::State> TouchStateMap;
+
+void SetWebTouchPoints(const std::vector<PP_TouchPoint>& pp_touches,
+ const TouchStateMap& states_map,
+ WebTouchPoint* web_touches,
+ uint32_t* web_touches_length) {
+
+ for (uint32_t i = 0; i < pp_touches.size() &&
+ i < WebTouchEvent::touchesLengthCap; i++) {
+ WebTouchPoint pt;
+ const PP_TouchPoint& pp_pt = pp_touches[i];
+ pt.id = pp_pt.id;
+
+ if (states_map.find(pt.id) == states_map.end())
+ pt.state = WebTouchPoint::StateStationary;
+ else
+ pt.state = states_map.find(pt.id)->second;
+
+ pt.position.x = pp_pt.position.x;
+ pt.position.y = pp_pt.position.y;
+ // TODO bug:http://code.google.com/p/chromium/issues/detail?id=93902
+ pt.screenPosition.x = 0;
+ pt.screenPosition.y = 0;
+ pt.force = pp_pt.pressure;
+ pt.radiusX = pp_pt.radius.x;
+ pt.radiusY = pp_pt.radius.y;
+ pt.rotationAngle = pp_pt.rotation_angle;
+ web_touches[i] = pt;
+ (*web_touches_length)++;
+ }
+}
+
+WebTouchEvent* BuildTouchEvent(const InputEventData& event) {
+ WebTouchEvent* web_event = new WebTouchEvent();
+ WebTouchPoint::State state = WebTouchPoint::StateUndefined;
+ switch (event.event_type) {
+ case PP_INPUTEVENT_TYPE_TOUCHSTART:
+ web_event->type = WebInputEvent::TouchStart;
+ state = WebTouchPoint::StatePressed;
+ break;
+ case PP_INPUTEVENT_TYPE_TOUCHMOVE:
+ web_event->type = WebInputEvent::TouchMove;
+ state = WebTouchPoint::StateMoved;
+ break;
+ case PP_INPUTEVENT_TYPE_TOUCHEND:
+ web_event->type = WebInputEvent::TouchEnd;
+ state = WebTouchPoint::StateReleased;
+ break;
+ case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
+ web_event->type = WebInputEvent::TouchCancel;
+ state = WebTouchPoint::StateCancelled;
+ break;
+ default:
+ NOTREACHED();
+ }
+
+ TouchStateMap states_map;
+ for (uint32_t i = 0; i < event.changed_touches.size(); i++)
+ states_map[event.changed_touches[i].id] = state;
+
+ web_event->timeStampSeconds = PPTimeTicksToEventTime(event.event_time_stamp);
+
+ SetWebTouchPoints(event.changed_touches, states_map,
+ web_event->changedTouches,
+ &web_event->changedTouchesLength);
+
+ SetWebTouchPoints(event.touches, states_map, web_event->touches,
+ &web_event->touchesLength);
+
+ SetWebTouchPoints(event.target_touches, states_map, web_event->targetTouches,
+ &web_event->targetTouchesLength);
+
+ if (web_event->type == WebInputEvent::TouchEnd ||
+ web_event->type == WebInputEvent::TouchCancel) {
+ SetWebTouchPoints(event.changed_touches, states_map,
+ web_event->touches, &web_event->touchesLength);
+ SetWebTouchPoints(event.changed_touches, states_map,
+ web_event->targetTouches,
+ &web_event->targetTouchesLength);
+ }
+
+ return web_event;
+}
+
WebKeyboardEvent* BuildKeyEvent(const InputEventData& event) {
WebKeyboardEvent* key_event = new WebKeyboardEvent();
switch (event.event_type) {
@@ -412,6 +545,12 @@ void CreateInputEventData(const WebInputEvent& event,
case WebInputEvent::Char:
AppendCharEvent(event, result);
break;
+ case WebInputEvent::TouchStart:
+ case WebInputEvent::TouchMove:
+ case WebInputEvent::TouchEnd:
+ case WebInputEvent::TouchCancel:
+ AppendTouchEvent(event, result);
+ break;
case WebInputEvent::Undefined:
default:
break;
@@ -450,6 +589,12 @@ WebInputEvent* CreateWebInputEvent(const InputEventData& event) {
// composition events.
NOTREACHED();
break;
+ case PP_INPUTEVENT_TYPE_TOUCHSTART:
+ case PP_INPUTEVENT_TYPE_TOUCHMOVE:
+ case PP_INPUTEVENT_TYPE_TOUCHEND:
+ case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
+ web_input_event.reset(BuildTouchEvent(event));
+ break;
}
return web_input_event.release();
@@ -563,6 +708,11 @@ PP_InputEvent_Class ClassifyInputEvent(WebInputEvent::Type type) {
case WebInputEvent::KeyUp:
case WebInputEvent::Char:
return PP_INPUTEVENT_CLASS_KEYBOARD;
+ case WebInputEvent::TouchCancel:
+ case WebInputEvent::TouchEnd:
+ case WebInputEvent::TouchMove:
+ case WebInputEvent::TouchStart:
+ return PP_INPUTEVENT_CLASS_TOUCH;
case WebInputEvent::Undefined:
default:
NOTREACHED();