OLD | NEW |
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 "remoting/client/plugin/pepper_input_handler.h" | 5 #include "remoting/client/plugin/pepper_input_handler.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ppapi/cpp/image_data.h" | 8 #include "ppapi/cpp/image_data.h" |
9 #include "ppapi/cpp/input_event.h" | 9 #include "ppapi/cpp/input_event.h" |
10 #include "ppapi/cpp/module_impl.h" | 10 #include "ppapi/cpp/module_impl.h" |
11 #include "ppapi/cpp/mouse_cursor.h" | 11 #include "ppapi/cpp/mouse_cursor.h" |
12 #include "ppapi/cpp/point.h" | 12 #include "ppapi/cpp/point.h" |
| 13 #include "ppapi/cpp/touch_point.h" |
13 #include "ppapi/cpp/var.h" | 14 #include "ppapi/cpp/var.h" |
14 #include "remoting/proto/event.pb.h" | 15 #include "remoting/proto/event.pb.h" |
15 #include "ui/events/keycodes/dom4/keycode_converter.h" | 16 #include "ui/events/keycodes/dom4/keycode_converter.h" |
16 | 17 |
17 namespace remoting { | 18 namespace remoting { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 // Builds the Chromotocol lock states flags for the PPAPI |event|. | 22 // Builds the Chromotocol lock states flags for the PPAPI |event|. |
22 uint32_t MakeLockStates(const pp::InputEvent& event) { | 23 uint32_t MakeLockStates(const pp::InputEvent& event) { |
23 uint32_t modifiers = event.GetModifiers(); | 24 uint32_t modifiers = event.GetModifiers(); |
24 uint32_t lock_states = 0; | 25 uint32_t lock_states = 0; |
25 | 26 |
26 if (modifiers & PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY) | 27 if (modifiers & PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY) |
27 lock_states |= protocol::KeyEvent::LOCK_STATES_CAPSLOCK; | 28 lock_states |= protocol::KeyEvent::LOCK_STATES_CAPSLOCK; |
28 | 29 |
29 if (modifiers & PP_INPUTEVENT_MODIFIER_NUMLOCKKEY) | 30 if (modifiers & PP_INPUTEVENT_MODIFIER_NUMLOCKKEY) |
30 lock_states |= protocol::KeyEvent::LOCK_STATES_NUMLOCK; | 31 lock_states |= protocol::KeyEvent::LOCK_STATES_NUMLOCK; |
31 | 32 |
32 return lock_states; | 33 return lock_states; |
33 } | 34 } |
34 | 35 |
| 36 // Creates protocol::TouchEvent instance from |pp_touch_event|. |
| 37 // Note that only the changed touches are added to the TouchEvent. |
| 38 protocol::TouchEvent MakeTouchEvent(const pp::TouchInputEvent& pp_touch_event) { |
| 39 protocol::TouchEvent touch_event; |
| 40 protocol::TouchEvent::TouchEventType type; |
| 41 switch (pp_touch_event.GetType()) { |
| 42 case PP_INPUTEVENT_TYPE_TOUCHSTART: |
| 43 type = protocol::TouchEvent::TOUCH_POINT_START; |
| 44 break; |
| 45 case PP_INPUTEVENT_TYPE_TOUCHMOVE: |
| 46 type = protocol::TouchEvent::TOUCH_POINT_MOVE; |
| 47 break; |
| 48 case PP_INPUTEVENT_TYPE_TOUCHEND: |
| 49 type = protocol::TouchEvent::TOUCH_POINT_END; |
| 50 break; |
| 51 case PP_INPUTEVENT_TYPE_TOUCHCANCEL: |
| 52 type = protocol::TouchEvent::TOUCH_POINT_CANCEL; |
| 53 break; |
| 54 default: |
| 55 NOTREACHED() << "Unknown event type: " << pp_touch_event.GetType(); |
| 56 return touch_event; |
| 57 } |
| 58 touch_event.set_event_type(type); |
| 59 |
| 60 for (uint32_t i = 0; |
| 61 i < pp_touch_event.GetTouchCount(PP_TOUCHLIST_TYPE_CHANGEDTOUCHES); |
| 62 ++i) { |
| 63 pp::TouchPoint pp_point = |
| 64 pp_touch_event.GetTouchByIndex(PP_TOUCHLIST_TYPE_CHANGEDTOUCHES, i); |
| 65 protocol::TouchEventPoint* point = touch_event.add_touch_points(); |
| 66 point->set_id(pp_point.id()); |
| 67 point->set_x(pp_point.position().x()); |
| 68 point->set_y(pp_point.position().y()); |
| 69 point->set_radius_x(pp_point.radii().x()); |
| 70 point->set_radius_y(pp_point.radii().y()); |
| 71 } |
| 72 |
| 73 return touch_event; |
| 74 } |
| 75 |
35 // Builds a protocol::KeyEvent from the supplied PPAPI event. | 76 // Builds a protocol::KeyEvent from the supplied PPAPI event. |
36 protocol::KeyEvent MakeKeyEvent(const pp::KeyboardInputEvent& pp_key_event) { | 77 protocol::KeyEvent MakeKeyEvent(const pp::KeyboardInputEvent& pp_key_event) { |
37 protocol::KeyEvent key_event; | 78 protocol::KeyEvent key_event; |
38 std::string dom_code = pp_key_event.GetCode().AsString(); | 79 std::string dom_code = pp_key_event.GetCode().AsString(); |
39 key_event.set_usb_keycode( | 80 key_event.set_usb_keycode( |
40 ui::KeycodeConverter::CodeToUsbKeycode(dom_code.c_str())); | 81 ui::KeycodeConverter::CodeToUsbKeycode(dom_code.c_str())); |
41 key_event.set_pressed(pp_key_event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN); | 82 key_event.set_pressed(pp_key_event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN); |
42 key_event.set_lock_states(MakeLockStates(pp_key_event)); | 83 key_event.set_lock_states(MakeLockStates(pp_key_event)); |
43 return key_event; | 84 return key_event; |
44 } | 85 } |
(...skipping 20 matching lines...) Expand all Loading... |
65 send_mouse_input_when_unfocused_(false), | 106 send_mouse_input_when_unfocused_(false), |
66 send_mouse_move_deltas_(false), | 107 send_mouse_move_deltas_(false), |
67 wheel_delta_x_(0), | 108 wheel_delta_x_(0), |
68 wheel_delta_y_(0), | 109 wheel_delta_y_(0), |
69 wheel_ticks_x_(0), | 110 wheel_ticks_x_(0), |
70 wheel_ticks_y_(0) { | 111 wheel_ticks_y_(0) { |
71 } | 112 } |
72 | 113 |
73 bool PepperInputHandler::HandleInputEvent(const pp::InputEvent& event) { | 114 bool PepperInputHandler::HandleInputEvent(const pp::InputEvent& event) { |
74 switch (event.GetType()) { | 115 switch (event.GetType()) { |
| 116 // Touch input cases. |
| 117 case PP_INPUTEVENT_TYPE_TOUCHSTART: |
| 118 case PP_INPUTEVENT_TYPE_TOUCHMOVE: |
| 119 case PP_INPUTEVENT_TYPE_TOUCHEND: |
| 120 case PP_INPUTEVENT_TYPE_TOUCHCANCEL: { |
| 121 if (!input_stub_) |
| 122 return true; |
| 123 pp::TouchInputEvent pp_touch_event(event); |
| 124 input_stub_->InjectTouchEvent(MakeTouchEvent(pp_touch_event)); |
| 125 return true; |
| 126 } |
| 127 |
75 case PP_INPUTEVENT_TYPE_CONTEXTMENU: { | 128 case PP_INPUTEVENT_TYPE_CONTEXTMENU: { |
76 // We need to return true here or else we'll get a local (plugin) context | 129 // We need to return true here or else we'll get a local (plugin) context |
77 // menu instead of the mouseup event for the right click. | 130 // menu instead of the mouseup event for the right click. |
78 return true; | 131 return true; |
79 } | 132 } |
80 | 133 |
81 case PP_INPUTEVENT_TYPE_KEYDOWN: | 134 case PP_INPUTEVENT_TYPE_KEYDOWN: |
82 case PP_INPUTEVENT_TYPE_KEYUP: { | 135 case PP_INPUTEVENT_TYPE_KEYUP: { |
83 if (!input_stub_) | 136 if (!input_stub_) |
84 return true; | 137 return true; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 } | 247 } |
195 | 248 |
196 return false; | 249 return false; |
197 } | 250 } |
198 | 251 |
199 void PepperInputHandler::DidChangeFocus(bool has_focus) { | 252 void PepperInputHandler::DidChangeFocus(bool has_focus) { |
200 has_focus_ = has_focus; | 253 has_focus_ = has_focus; |
201 } | 254 } |
202 | 255 |
203 } // namespace remoting | 256 } // namespace remoting |
OLD | NEW |