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 |
| 22 void SetTouchEventType(PP_InputEvent_Type pp_type, |
| 23 protocol::TouchEvent* touch_event) { |
| 24 DCHECK(touch_event); |
| 25 switch (pp_type) { |
| 26 case PP_INPUTEVENT_TYPE_TOUCHSTART: |
| 27 touch_event->set_event_type(protocol::TouchEvent::TOUCH_POINT_START); |
| 28 return; |
| 29 case PP_INPUTEVENT_TYPE_TOUCHMOVE: |
| 30 touch_event->set_event_type(protocol::TouchEvent::TOUCH_POINT_MOVE); |
| 31 return; |
| 32 case PP_INPUTEVENT_TYPE_TOUCHEND: |
| 33 touch_event->set_event_type(protocol::TouchEvent::TOUCH_POINT_END); |
| 34 return; |
| 35 case PP_INPUTEVENT_TYPE_TOUCHCANCEL: |
| 36 touch_event->set_event_type(protocol::TouchEvent::TOUCH_POINT_CANCEL); |
| 37 return; |
| 38 default: |
| 39 NOTREACHED() << "Unknown event type: " << pp_type; |
| 40 return; |
| 41 } |
| 42 } |
| 43 |
| 44 // Creates a protocol::TouchEvent instance from |pp_touch_event|. |
| 45 // Note that only the changed touches are added to the TouchEvent. |
| 46 protocol::TouchEvent MakeTouchEvent(const pp::TouchInputEvent& pp_touch_event) { |
| 47 protocol::TouchEvent touch_event; |
| 48 SetTouchEventType(pp_touch_event.GetType(), &touch_event); |
| 49 DCHECK(touch_event.has_event_type()); |
| 50 |
| 51 for (uint32_t i = 0; |
| 52 i < pp_touch_event.GetTouchCount(PP_TOUCHLIST_TYPE_CHANGEDTOUCHES); |
| 53 ++i) { |
| 54 pp::TouchPoint pp_point = |
| 55 pp_touch_event.GetTouchByIndex(PP_TOUCHLIST_TYPE_CHANGEDTOUCHES, i); |
| 56 protocol::TouchEventPoint* point = touch_event.add_touch_points(); |
| 57 point->set_id(pp_point.id()); |
| 58 point->set_x(pp_point.position().x()); |
| 59 point->set_y(pp_point.position().y()); |
| 60 point->set_radius_x(pp_point.radii().x()); |
| 61 point->set_radius_y(pp_point.radii().y()); |
| 62 point->set_angle(pp_point.rotation_angle()); |
| 63 } |
| 64 |
| 65 return touch_event; |
| 66 } |
| 67 |
21 // Builds the Chromotocol lock states flags for the PPAPI |event|. | 68 // Builds the Chromotocol lock states flags for the PPAPI |event|. |
22 uint32_t MakeLockStates(const pp::InputEvent& event) { | 69 uint32_t MakeLockStates(const pp::InputEvent& event) { |
23 uint32_t modifiers = event.GetModifiers(); | 70 uint32_t modifiers = event.GetModifiers(); |
24 uint32_t lock_states = 0; | 71 uint32_t lock_states = 0; |
25 | 72 |
26 if (modifiers & PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY) | 73 if (modifiers & PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY) |
27 lock_states |= protocol::KeyEvent::LOCK_STATES_CAPSLOCK; | 74 lock_states |= protocol::KeyEvent::LOCK_STATES_CAPSLOCK; |
28 | 75 |
29 if (modifiers & PP_INPUTEVENT_MODIFIER_NUMLOCKKEY) | 76 if (modifiers & PP_INPUTEVENT_MODIFIER_NUMLOCKKEY) |
30 lock_states |= protocol::KeyEvent::LOCK_STATES_NUMLOCK; | 77 lock_states |= protocol::KeyEvent::LOCK_STATES_NUMLOCK; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 send_mouse_input_when_unfocused_(false), | 112 send_mouse_input_when_unfocused_(false), |
66 send_mouse_move_deltas_(false), | 113 send_mouse_move_deltas_(false), |
67 wheel_delta_x_(0), | 114 wheel_delta_x_(0), |
68 wheel_delta_y_(0), | 115 wheel_delta_y_(0), |
69 wheel_ticks_x_(0), | 116 wheel_ticks_x_(0), |
70 wheel_ticks_y_(0) { | 117 wheel_ticks_y_(0) { |
71 } | 118 } |
72 | 119 |
73 bool PepperInputHandler::HandleInputEvent(const pp::InputEvent& event) { | 120 bool PepperInputHandler::HandleInputEvent(const pp::InputEvent& event) { |
74 switch (event.GetType()) { | 121 switch (event.GetType()) { |
| 122 // Touch input cases. |
| 123 case PP_INPUTEVENT_TYPE_TOUCHSTART: |
| 124 case PP_INPUTEVENT_TYPE_TOUCHMOVE: |
| 125 case PP_INPUTEVENT_TYPE_TOUCHEND: |
| 126 case PP_INPUTEVENT_TYPE_TOUCHCANCEL: { |
| 127 if (!input_stub_) |
| 128 return true; |
| 129 pp::TouchInputEvent pp_touch_event(event); |
| 130 input_stub_->InjectTouchEvent(MakeTouchEvent(pp_touch_event)); |
| 131 return true; |
| 132 } |
| 133 |
75 case PP_INPUTEVENT_TYPE_CONTEXTMENU: { | 134 case PP_INPUTEVENT_TYPE_CONTEXTMENU: { |
76 // We need to return true here or else we'll get a local (plugin) context | 135 // 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. | 136 // menu instead of the mouseup event for the right click. |
78 return true; | 137 return true; |
79 } | 138 } |
80 | 139 |
81 case PP_INPUTEVENT_TYPE_KEYDOWN: | 140 case PP_INPUTEVENT_TYPE_KEYDOWN: |
82 case PP_INPUTEVENT_TYPE_KEYUP: { | 141 case PP_INPUTEVENT_TYPE_KEYUP: { |
83 if (!input_stub_) | 142 if (!input_stub_) |
84 return true; | 143 return true; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 } | 253 } |
195 | 254 |
196 return false; | 255 return false; |
197 } | 256 } |
198 | 257 |
199 void PepperInputHandler::DidChangeFocus(bool has_focus) { | 258 void PepperInputHandler::DidChangeFocus(bool has_focus) { |
200 has_focus_ = has_focus; | 259 has_focus_ = has_focus; |
201 } | 260 } |
202 | 261 |
203 } // namespace remoting | 262 } // namespace remoting |
OLD | NEW |