Index: webkit/plugins/ppapi/event_conversion.cc |
diff --git a/webkit/plugins/ppapi/event_conversion.cc b/webkit/plugins/ppapi/event_conversion.cc |
index 22f1b42a8d27fc5b0d81f4aeb1c696b6bf5fd60a..39fed11f8527484b0bddbfaf33d6471d611613ef 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" |
@@ -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,118 @@ void AppendMouseWheelEvent(const WebInputEvent& event, |
result_events->push_back(result); |
} |
+void SetPPTouchPoints(const WebTouchPoint* touches, uint32_t touches_length, |
+ std::vector<PP_TouchPoint_Dev>* result) { |
+ for (uint32_t i = 0; i < touches_length; i++) { |
+ const WebTouchPoint& touch_point = touches[i]; |
+ PP_TouchPoint_Dev 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_Dev>& 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_Dev& 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::StateReleased; |
+ break; |
+ case PP_INPUTEVENT_TYPE_TOUCHEND: |
+ web_event->type = WebInputEvent::TouchEnd; |
+ state = WebTouchPoint::StateMoved; |
+ 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); |
+ |
+ return web_event; |
+} |
+ |
WebKeyboardEvent* BuildKeyEvent(const InputEventData& event) { |
WebKeyboardEvent* key_event = new WebKeyboardEvent(); |
switch (event.event_type) { |
@@ -412,6 +536,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 +580,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 +699,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(); |