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 // Crates protocol::TouchEvent instance from |pp_touch_event|. | |
|
Wez
2015/01/21 03:08:37
s/Creates/Creates
Rintaro Kuroiwa
2015/01/28 01:12:29
Done.
| |
| 37 // Note that only the changed touches are added to the instance. | |
|
Wez
2015/01/21 03:08:37
s/instance/TouchEvent
Rintaro Kuroiwa
2015/01/28 01:12:29
Done.
| |
| 38 protocol::TouchEvent MakeTouchEvent(const pp::TouchInputEvent& pp_touch_event) { | |
| 39 using protocol::TouchEvent; | |
|
Wez
2015/01/21 03:08:37
nit: Blank line after this "using", since it's not
Rintaro Kuroiwa
2015/01/28 01:12:29
Not saving any lines, removing :)
| |
| 40 TouchEvent touch_event; | |
| 41 TouchEvent::Point::TouchPointEventType type; | |
| 42 switch (pp_touch_event.GetType()) { | |
| 43 case PP_INPUTEVENT_TYPE_TOUCHSTART: | |
| 44 type = TouchEvent::Point::TOUCH_POINT_START; | |
| 45 break; | |
| 46 case PP_INPUTEVENT_TYPE_TOUCHMOVE: | |
| 47 type = TouchEvent::Point::TOUCH_POINT_MOVE; | |
| 48 break; | |
| 49 case PP_INPUTEVENT_TYPE_TOUCHEND: | |
| 50 type = TouchEvent::Point::TOUCH_POINT_END; | |
| 51 break; | |
| 52 case PP_INPUTEVENT_TYPE_TOUCHCANCEL: | |
| 53 type = TouchEvent::Point::TOUCH_POINT_CANCEL; | |
| 54 break; | |
| 55 default: | |
| 56 NOTIMPLEMENTED() << "Unknown event type: " << pp_touch_event.GetType(); | |
| 57 return touch_event; | |
| 58 } | |
| 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 TouchEvent::Point* point = touch_event.add_touch_points(); | |
| 66 point->set_event_type(type); | |
| 67 point->set_id(pp_point.id()); | |
| 68 point->set_x(pp_point.position().x()); | |
| 69 point->set_y(pp_point.position().y()); | |
| 70 point->set_radius_x(pp_point.radii().x()); | |
| 71 point->set_radius_y(pp_point.radii().y()); | |
| 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 12 matching lines...) Expand all Loading... | |
| 57 return mouse_event; | 99 return mouse_event; |
| 58 } | 100 } |
| 59 | 101 |
| 60 } // namespace | 102 } // namespace |
| 61 | 103 |
| 62 PepperInputHandler::PepperInputHandler() | 104 PepperInputHandler::PepperInputHandler() |
| 63 : input_stub_(nullptr), | 105 : input_stub_(nullptr), |
| 64 has_focus_(false), | 106 has_focus_(false), |
| 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), |
| 109 send_touch_events_(false), | |
| 67 wheel_delta_x_(0), | 110 wheel_delta_x_(0), |
| 68 wheel_delta_y_(0), | 111 wheel_delta_y_(0), |
| 69 wheel_ticks_x_(0), | 112 wheel_ticks_x_(0), |
| 70 wheel_ticks_y_(0) { | 113 wheel_ticks_y_(0) { |
| 71 } | 114 } |
| 72 | 115 |
| 73 bool PepperInputHandler::HandleInputEvent(const pp::InputEvent& event) { | 116 bool PepperInputHandler::HandleInputEvent(const pp::InputEvent& event) { |
| 74 switch (event.GetType()) { | 117 switch (event.GetType()) { |
| 118 // Touch input cases. | |
| 119 case PP_INPUTEVENT_TYPE_TOUCHSTART: | |
| 120 case PP_INPUTEVENT_TYPE_TOUCHMOVE: | |
| 121 case PP_INPUTEVENT_TYPE_TOUCHEND: | |
| 122 case PP_INPUTEVENT_TYPE_TOUCHCANCEL: { | |
| 123 if (!send_touch_events_) | |
| 124 return false; | |
| 125 pp::TouchInputEvent pp_touch_event(event); | |
| 126 input_stub_->InjectTouchEvent(MakeTouchEvent(pp_touch_event)); | |
| 127 return true; | |
| 128 } | |
| 129 | |
| 75 case PP_INPUTEVENT_TYPE_CONTEXTMENU: { | 130 case PP_INPUTEVENT_TYPE_CONTEXTMENU: { |
| 76 // We need to return true here or else we'll get a local (plugin) context | 131 // 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. | 132 // menu instead of the mouseup event for the right click. |
| 78 return true; | 133 return true; |
| 79 } | 134 } |
| 80 | 135 |
| 81 case PP_INPUTEVENT_TYPE_KEYDOWN: | 136 case PP_INPUTEVENT_TYPE_KEYDOWN: |
| 82 case PP_INPUTEVENT_TYPE_KEYUP: { | 137 case PP_INPUTEVENT_TYPE_KEYUP: { |
| 83 if (!input_stub_) | 138 if (!input_stub_) |
| 84 return true; | 139 return true; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 } | 249 } |
| 195 | 250 |
| 196 return false; | 251 return false; |
| 197 } | 252 } |
| 198 | 253 |
| 199 void PepperInputHandler::DidChangeFocus(bool has_focus) { | 254 void PepperInputHandler::DidChangeFocus(bool has_focus) { |
| 200 has_focus_ = has_focus; | 255 has_focus_ = has_focus; |
| 201 } | 256 } |
| 202 | 257 |
| 203 } // namespace remoting | 258 } // namespace remoting |
| OLD | NEW |