Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Side by Side Diff: webkit/plugins/ppapi/event_conversion.cc

Issue 10543159: ppapi: Add support for touch events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <map>
6
5 #include "webkit/plugins/ppapi/event_conversion.h" 7 #include "webkit/plugins/ppapi/event_conversion.h"
6 8
7 #include "base/basictypes.h" 9 #include "base/basictypes.h"
8 #include "base/i18n/char_iterator.h" 10 #include "base/i18n/char_iterator.h"
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
11 #include "base/string_util.h" 13 #include "base/string_util.h"
12 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
13 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
14 #include "base/utf_string_conversion_utils.h" 16 #include "base/utf_string_conversion_utils.h"
15 #include "ppapi/c/pp_input_event.h" 17 #include "ppapi/c/pp_input_event.h"
16 #include "ppapi/shared_impl/ppb_input_event_shared.h" 18 #include "ppapi/shared_impl/ppb_input_event_shared.h"
17 #include "ppapi/shared_impl/time_conversion.h" 19 #include "ppapi/shared_impl/time_conversion.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads. h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads. h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
21 #include "webkit/plugins/ppapi/common.h" 23 #include "webkit/plugins/ppapi/common.h"
22 #include "webkit/plugins/ppapi/usb_key_code_conversion.h" 24 #include "webkit/plugins/ppapi/usb_key_code_conversion.h"
23 25
24 using ppapi::EventTimeToPPTimeTicks; 26 using ppapi::EventTimeToPPTimeTicks;
25 using ppapi::InputEventData; 27 using ppapi::InputEventData;
26 using ppapi::PPTimeTicksToEventTime; 28 using ppapi::PPTimeTicksToEventTime;
27 using WebKit::WebInputEvent; 29 using WebKit::WebInputEvent;
28 using WebKit::WebKeyboardEvent; 30 using WebKit::WebKeyboardEvent;
29 using WebKit::WebMouseEvent; 31 using WebKit::WebMouseEvent;
30 using WebKit::WebMouseWheelEvent; 32 using WebKit::WebMouseWheelEvent;
31 using WebKit::WebString; 33 using WebKit::WebString;
34 using WebKit::WebTouchEvent;
35 using WebKit::WebTouchPoint;
32 using WebKit::WebUChar; 36 using WebKit::WebUChar;
33 37
34 namespace webkit { 38 namespace webkit {
35 namespace ppapi { 39 namespace ppapi {
36 40
37 namespace { 41 namespace {
38 42
39 // Verify the modifier flags WebKit uses match the Pepper ones. If these start 43 // Verify the modifier flags WebKit uses match the Pepper ones. If these start
40 // not matching, we'll need to write conversion code to preserve the Pepper 44 // not matching, we'll need to write conversion code to preserve the Pepper
41 // values (since plugins will be depending on them). 45 // values (since plugins will be depending on them).
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 case WebInputEvent::MouseWheel: 94 case WebInputEvent::MouseWheel:
91 return PP_INPUTEVENT_TYPE_WHEEL; 95 return PP_INPUTEVENT_TYPE_WHEEL;
92 case WebInputEvent::RawKeyDown: 96 case WebInputEvent::RawKeyDown:
93 return PP_INPUTEVENT_TYPE_RAWKEYDOWN; 97 return PP_INPUTEVENT_TYPE_RAWKEYDOWN;
94 case WebInputEvent::KeyDown: 98 case WebInputEvent::KeyDown:
95 return PP_INPUTEVENT_TYPE_KEYDOWN; 99 return PP_INPUTEVENT_TYPE_KEYDOWN;
96 case WebInputEvent::KeyUp: 100 case WebInputEvent::KeyUp:
97 return PP_INPUTEVENT_TYPE_KEYUP; 101 return PP_INPUTEVENT_TYPE_KEYUP;
98 case WebInputEvent::Char: 102 case WebInputEvent::Char:
99 return PP_INPUTEVENT_TYPE_CHAR; 103 return PP_INPUTEVENT_TYPE_CHAR;
104 case WebInputEvent::TouchStart:
105 return PP_INPUTEVENT_TYPE_TOUCHSTART;
106 case WebInputEvent::TouchMove:
107 return PP_INPUTEVENT_TYPE_TOUCHMOVE;
108 case WebInputEvent::TouchEnd:
109 return PP_INPUTEVENT_TYPE_TOUCHEND;
110 case WebInputEvent::TouchCancel:
111 return PP_INPUTEVENT_TYPE_TOUCHCANCEL;
100 case WebInputEvent::Undefined: 112 case WebInputEvent::Undefined:
101 default: 113 default:
102 return PP_INPUTEVENT_TYPE_UNDEFINED; 114 return PP_INPUTEVENT_TYPE_UNDEFINED;
103 } 115 }
104 } 116 }
105 117
106 // Generates a PP_InputEvent with the fields common to all events, as well as 118 // Generates a PP_InputEvent with the fields common to all events, as well as
107 // the event type from the given web event. Event-specific fields will be zero 119 // the event type from the given web event. Event-specific fields will be zero
108 // initialized. 120 // initialized.
109 InputEventData GetEventWithCommonFieldsAndType(const WebInputEvent& web_event) { 121 InputEventData GetEventWithCommonFieldsAndType(const WebInputEvent& web_event) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 InputEventData result = GetEventWithCommonFieldsAndType(event); 204 InputEventData result = GetEventWithCommonFieldsAndType(event);
193 result.event_modifiers = mouse_wheel_event.modifiers; 205 result.event_modifiers = mouse_wheel_event.modifiers;
194 result.wheel_delta.x = mouse_wheel_event.deltaX; 206 result.wheel_delta.x = mouse_wheel_event.deltaX;
195 result.wheel_delta.y = mouse_wheel_event.deltaY; 207 result.wheel_delta.y = mouse_wheel_event.deltaY;
196 result.wheel_ticks.x = mouse_wheel_event.wheelTicksX; 208 result.wheel_ticks.x = mouse_wheel_event.wheelTicksX;
197 result.wheel_ticks.y = mouse_wheel_event.wheelTicksY; 209 result.wheel_ticks.y = mouse_wheel_event.wheelTicksY;
198 result.wheel_scroll_by_page = !!mouse_wheel_event.scrollByPage; 210 result.wheel_scroll_by_page = !!mouse_wheel_event.scrollByPage;
199 result_events->push_back(result); 211 result_events->push_back(result);
200 } 212 }
201 213
214 void SetPPTouchPoints(const WebTouchPoint* touches, uint32_t touches_length,
215 std::vector<PP_TouchPoint_Dev>* result) {
216 for (uint32_t i = 0; i < touches_length; i++) {
217 const WebTouchPoint& touch_point = touches[i];
218 PP_TouchPoint_Dev pp_pt;
219 pp_pt.id = touch_point.id;
220 pp_pt.position.x = touch_point.position.x;
221 pp_pt.position.y = touch_point.position.y;
222 pp_pt.radius.x = touch_point.radiusX;
223 pp_pt.radius.y = touch_point.radiusY;
224 pp_pt.rotation_angle = touch_point.rotationAngle;
225 pp_pt.pressure = touch_point.force;
226 result->push_back(pp_pt);
227 }
228 }
229
230 void AppendTouchEvent(const WebInputEvent& event,
231 std::vector<InputEventData>* result_events) {
232 const WebTouchEvent& touch_event =
233 reinterpret_cast<const WebTouchEvent&>(event);
234
235 InputEventData result = GetEventWithCommonFieldsAndType(event);
236 SetPPTouchPoints(touch_event.touches, touch_event.touchesLength,
237 &result.touches);
238 SetPPTouchPoints(touch_event.changedTouches, touch_event.changedTouchesLength,
239 &result.changed_touches);
240 SetPPTouchPoints(touch_event.targetTouches, touch_event.targetTouchesLength,
241 &result.target_touches);
242
243 result_events->push_back(result);
244 }
245
246 // Structure used to map touch point id's to touch states. Since the pepper
247 // touch event structure does not have states for individual touch points and
248 // instead relies on the event type in combination with the set of touch lists,
249 // we have to set the state for the changed touches to be the same as the event
250 // type and all others to be 'stationary.'
251 typedef std::map<uint32_t, WebTouchPoint::State> TouchStateMap;
252
253 void SetWebTouchPoints(const std::vector<PP_TouchPoint_Dev>& pp_touches,
254 const TouchStateMap& states_map,
255 WebTouchPoint* web_touches,
256 uint32_t* web_touches_length) {
257
258 for (uint32_t i = 0; i < pp_touches.size() &&
259 i < WebTouchEvent::touchesLengthCap; i++) {
260 WebTouchPoint pt;
261 const PP_TouchPoint_Dev& pp_pt = pp_touches[i];
262 pt.id = pp_pt.id;
263
264 if (states_map.find(pt.id) == states_map.end())
265 pt.state = WebTouchPoint::StateStationary;
266 else
267 pt.state = states_map.find(pt.id)->second;
268
269 pt.position.x = pp_pt.position.x;
270 pt.position.y = pp_pt.position.y;
271 // TODO bug:http://code.google.com/p/chromium/issues/detail?id=93902
272 pt.screenPosition.x = 0;
273 pt.screenPosition.y = 0;
274 pt.force = pp_pt.pressure;
275 pt.radiusX = pp_pt.radius.x;
276 pt.radiusY = pp_pt.radius.y;
277 pt.rotationAngle = pp_pt.rotation_angle;
278 web_touches[i] = pt;
279 (*web_touches_length)++;
280 }
281 }
282
283 WebTouchEvent* BuildTouchEvent(const InputEventData& event) {
284 WebTouchEvent* web_event = new WebTouchEvent();
285 WebTouchPoint::State state = WebTouchPoint::StateUndefined;
286 switch (event.event_type) {
287 case PP_INPUTEVENT_TYPE_TOUCHSTART:
288 web_event->type = WebInputEvent::TouchStart;
289 state = WebTouchPoint::StatePressed;
290 break;
291 case PP_INPUTEVENT_TYPE_TOUCHMOVE:
292 web_event->type = WebInputEvent::TouchMove;
293 state = WebTouchPoint::StateReleased;
294 break;
295 case PP_INPUTEVENT_TYPE_TOUCHEND:
296 web_event->type = WebInputEvent::TouchEnd;
297 state = WebTouchPoint::StateMoved;
298 break;
299 case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
300 web_event->type = WebInputEvent::TouchCancel;
301 state = WebTouchPoint::StateCancelled;
302 break;
303 default:
304 NOTREACHED();
305 }
306
307 TouchStateMap states_map;
308 for (uint32_t i = 0; i < event.changed_touches.size(); i++)
309 states_map[event.changed_touches[i].id] = state;
310
311 web_event->timeStampSeconds = PPTimeTicksToEventTime(event.event_time_stamp);
312
313 SetWebTouchPoints(event.changed_touches, states_map,
314 web_event->changedTouches,
315 &web_event->changedTouchesLength);
316
317 SetWebTouchPoints(event.touches, states_map, web_event->touches,
318 &web_event->touchesLength);
319
320 SetWebTouchPoints(event.target_touches, states_map, web_event->targetTouches,
321 &web_event->targetTouchesLength);
322
323 return web_event;
324 }
325
202 WebKeyboardEvent* BuildKeyEvent(const InputEventData& event) { 326 WebKeyboardEvent* BuildKeyEvent(const InputEventData& event) {
203 WebKeyboardEvent* key_event = new WebKeyboardEvent(); 327 WebKeyboardEvent* key_event = new WebKeyboardEvent();
204 switch (event.event_type) { 328 switch (event.event_type) {
205 case PP_INPUTEVENT_TYPE_RAWKEYDOWN: 329 case PP_INPUTEVENT_TYPE_RAWKEYDOWN:
206 key_event->type = WebInputEvent::RawKeyDown; 330 key_event->type = WebInputEvent::RawKeyDown;
207 break; 331 break;
208 case PP_INPUTEVENT_TYPE_KEYDOWN: 332 case PP_INPUTEVENT_TYPE_KEYDOWN:
209 key_event->type = WebInputEvent::KeyDown; 333 key_event->type = WebInputEvent::KeyDown;
210 break; 334 break;
211 case PP_INPUTEVENT_TYPE_KEYUP: 335 case PP_INPUTEVENT_TYPE_KEYUP:
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 AppendMouseWheelEvent(event, result); 529 AppendMouseWheelEvent(event, result);
406 break; 530 break;
407 case WebInputEvent::RawKeyDown: 531 case WebInputEvent::RawKeyDown:
408 case WebInputEvent::KeyDown: 532 case WebInputEvent::KeyDown:
409 case WebInputEvent::KeyUp: 533 case WebInputEvent::KeyUp:
410 AppendKeyEvent(event, result); 534 AppendKeyEvent(event, result);
411 break; 535 break;
412 case WebInputEvent::Char: 536 case WebInputEvent::Char:
413 AppendCharEvent(event, result); 537 AppendCharEvent(event, result);
414 break; 538 break;
539 case WebInputEvent::TouchStart:
540 case WebInputEvent::TouchMove:
541 case WebInputEvent::TouchEnd:
542 case WebInputEvent::TouchCancel:
543 AppendTouchEvent(event, result);
544 break;
415 case WebInputEvent::Undefined: 545 case WebInputEvent::Undefined:
416 default: 546 default:
417 break; 547 break;
418 } 548 }
419 } 549 }
420 550
421 WebInputEvent* CreateWebInputEvent(const InputEventData& event) { 551 WebInputEvent* CreateWebInputEvent(const InputEventData& event) {
422 scoped_ptr<WebInputEvent> web_input_event; 552 scoped_ptr<WebInputEvent> web_input_event;
423 switch (event.event_type) { 553 switch (event.event_type) {
424 case PP_INPUTEVENT_TYPE_UNDEFINED: 554 case PP_INPUTEVENT_TYPE_UNDEFINED:
(...skipping 18 matching lines...) Expand all
443 web_input_event.reset(BuildCharEvent(event)); 573 web_input_event.reset(BuildCharEvent(event));
444 break; 574 break;
445 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_START: 575 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_START:
446 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE: 576 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE:
447 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_END: 577 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_END:
448 case PP_INPUTEVENT_TYPE_IME_TEXT: 578 case PP_INPUTEVENT_TYPE_IME_TEXT:
449 // TODO(kinaba) implement in WebKit an event structure to handle 579 // TODO(kinaba) implement in WebKit an event structure to handle
450 // composition events. 580 // composition events.
451 NOTREACHED(); 581 NOTREACHED();
452 break; 582 break;
583 case PP_INPUTEVENT_TYPE_TOUCHSTART:
584 case PP_INPUTEVENT_TYPE_TOUCHMOVE:
585 case PP_INPUTEVENT_TYPE_TOUCHEND:
586 case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
587 web_input_event.reset(BuildTouchEvent(event));
588 break;
453 } 589 }
454 590
455 return web_input_event.release(); 591 return web_input_event.release();
456 } 592 }
457 593
458 // Generate a coherent sequence of input events to simulate a user event. 594 // Generate a coherent sequence of input events to simulate a user event.
459 // From src/third_party/WebKit/Tools/DumpRenderTree/chromium/EventSender.cpp. 595 // From src/third_party/WebKit/Tools/DumpRenderTree/chromium/EventSender.cpp.
460 std::vector<linked_ptr<WebInputEvent> > CreateSimulatedWebInputEvents( 596 std::vector<linked_ptr<WebInputEvent> > CreateSimulatedWebInputEvents(
461 const ::ppapi::InputEventData& event, 597 const ::ppapi::InputEventData& event,
462 int plugin_x, 598 int plugin_x,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 case WebInputEvent::MouseLeave: 692 case WebInputEvent::MouseLeave:
557 case WebInputEvent::ContextMenu: 693 case WebInputEvent::ContextMenu:
558 return PP_INPUTEVENT_CLASS_MOUSE; 694 return PP_INPUTEVENT_CLASS_MOUSE;
559 case WebInputEvent::MouseWheel: 695 case WebInputEvent::MouseWheel:
560 return PP_INPUTEVENT_CLASS_WHEEL; 696 return PP_INPUTEVENT_CLASS_WHEEL;
561 case WebInputEvent::RawKeyDown: 697 case WebInputEvent::RawKeyDown:
562 case WebInputEvent::KeyDown: 698 case WebInputEvent::KeyDown:
563 case WebInputEvent::KeyUp: 699 case WebInputEvent::KeyUp:
564 case WebInputEvent::Char: 700 case WebInputEvent::Char:
565 return PP_INPUTEVENT_CLASS_KEYBOARD; 701 return PP_INPUTEVENT_CLASS_KEYBOARD;
702 case WebInputEvent::TouchCancel:
703 case WebInputEvent::TouchEnd:
704 case WebInputEvent::TouchMove:
705 case WebInputEvent::TouchStart:
706 return PP_INPUTEVENT_CLASS_TOUCH;
566 case WebInputEvent::Undefined: 707 case WebInputEvent::Undefined:
567 default: 708 default:
568 NOTREACHED(); 709 NOTREACHED();
569 return PP_InputEvent_Class(0); 710 return PP_InputEvent_Class(0);
570 } 711 }
571 } 712 }
572 713
573 void ConvertWebKitGamepadData(WebKit::WebGamepads& webkit_data, 714 void ConvertWebKitGamepadData(WebKit::WebGamepads& webkit_data,
574 PP_GamepadsSampleData* output_data) { 715 PP_GamepadsSampleData* output_data) {
575 output_data->length = webkit_data.length; 716 output_data->length = webkit_data.length;
(...skipping 15 matching lines...) Expand all
591 output_pad.buttons_length = webkit_pad.buttonsLength; 732 output_pad.buttons_length = webkit_pad.buttonsLength;
592 memcpy(output_pad.buttons, 733 memcpy(output_pad.buttons,
593 webkit_pad.buttons, 734 webkit_pad.buttons,
594 sizeof(output_pad.buttons)); 735 sizeof(output_pad.buttons));
595 } 736 }
596 } 737 }
597 } 738 }
598 739
599 } // namespace ppapi 740 } // namespace ppapi
600 } // namespace webkit 741 } // namespace webkit
OLDNEW
« ppapi/thunk/ppb_input_event_thunk.cc ('K') | « ppapi/thunk/ppb_input_event_thunk.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698