Chromium Code Reviews| 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|. | |
|
Wez
2015/02/05 02:09:06
"Creates a protocol::TouchEvent..."
Rintaro Kuroiwa
2015/02/06 23:35:00
Done.
| |
| 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 point->set_angle(pp_point.rotation_angle()); | |
| 72 } | |
| 73 | |
| 74 return touch_event; | |
| 75 } | |
| 76 | |
| 35 // Builds a protocol::KeyEvent from the supplied PPAPI event. | 77 // Builds a protocol::KeyEvent from the supplied PPAPI event. |
| 36 protocol::KeyEvent MakeKeyEvent(const pp::KeyboardInputEvent& pp_key_event) { | 78 protocol::KeyEvent MakeKeyEvent(const pp::KeyboardInputEvent& pp_key_event) { |
| 37 protocol::KeyEvent key_event; | 79 protocol::KeyEvent key_event; |
| 38 std::string dom_code = pp_key_event.GetCode().AsString(); | 80 std::string dom_code = pp_key_event.GetCode().AsString(); |
| 39 key_event.set_usb_keycode( | 81 key_event.set_usb_keycode( |
| 40 ui::KeycodeConverter::CodeToUsbKeycode(dom_code.c_str())); | 82 ui::KeycodeConverter::CodeToUsbKeycode(dom_code.c_str())); |
| 41 key_event.set_pressed(pp_key_event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN); | 83 key_event.set_pressed(pp_key_event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN); |
| 42 key_event.set_lock_states(MakeLockStates(pp_key_event)); | 84 key_event.set_lock_states(MakeLockStates(pp_key_event)); |
| 43 return key_event; | 85 return key_event; |
| 44 } | 86 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 65 send_mouse_input_when_unfocused_(false), | 107 send_mouse_input_when_unfocused_(false), |
| 66 send_mouse_move_deltas_(false), | 108 send_mouse_move_deltas_(false), |
| 67 wheel_delta_x_(0), | 109 wheel_delta_x_(0), |
| 68 wheel_delta_y_(0), | 110 wheel_delta_y_(0), |
| 69 wheel_ticks_x_(0), | 111 wheel_ticks_x_(0), |
| 70 wheel_ticks_y_(0) { | 112 wheel_ticks_y_(0) { |
| 71 } | 113 } |
| 72 | 114 |
| 73 bool PepperInputHandler::HandleInputEvent(const pp::InputEvent& event) { | 115 bool PepperInputHandler::HandleInputEvent(const pp::InputEvent& event) { |
| 74 switch (event.GetType()) { | 116 switch (event.GetType()) { |
| 117 // Touch input cases. | |
| 118 case PP_INPUTEVENT_TYPE_TOUCHSTART: | |
| 119 case PP_INPUTEVENT_TYPE_TOUCHMOVE: | |
| 120 case PP_INPUTEVENT_TYPE_TOUCHEND: | |
| 121 case PP_INPUTEVENT_TYPE_TOUCHCANCEL: { | |
| 122 if (!input_stub_) | |
| 123 return true; | |
| 124 pp::TouchInputEvent pp_touch_event(event); | |
| 125 input_stub_->InjectTouchEvent(MakeTouchEvent(pp_touch_event)); | |
| 126 return true; | |
| 127 } | |
| 128 | |
| 75 case PP_INPUTEVENT_TYPE_CONTEXTMENU: { | 129 case PP_INPUTEVENT_TYPE_CONTEXTMENU: { |
| 76 // We need to return true here or else we'll get a local (plugin) context | 130 // 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. | 131 // menu instead of the mouseup event for the right click. |
| 78 return true; | 132 return true; |
| 79 } | 133 } |
| 80 | 134 |
| 81 case PP_INPUTEVENT_TYPE_KEYDOWN: | 135 case PP_INPUTEVENT_TYPE_KEYDOWN: |
| 82 case PP_INPUTEVENT_TYPE_KEYUP: { | 136 case PP_INPUTEVENT_TYPE_KEYUP: { |
| 83 if (!input_stub_) | 137 if (!input_stub_) |
| 84 return true; | 138 return true; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 } | 248 } |
| 195 | 249 |
| 196 return false; | 250 return false; |
| 197 } | 251 } |
| 198 | 252 |
| 199 void PepperInputHandler::DidChangeFocus(bool has_focus) { | 253 void PepperInputHandler::DidChangeFocus(bool has_focus) { |
| 200 has_focus_ = has_focus; | 254 has_focus_ = has_focus; |
| 201 } | 255 } |
| 202 | 256 |
| 203 } // namespace remoting | 257 } // namespace remoting |
| OLD | NEW |