| 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/var.h" | 13 #include "ppapi/cpp/var.h" |
| 14 #include "remoting/proto/event.pb.h" | 14 #include "remoting/proto/event.pb.h" |
| 15 #include "ui/events/keycodes/dom4/keycode_converter.h" | 15 #include "ui/events/keycodes/dom4/keycode_converter.h" |
| 16 | 16 |
| 17 namespace remoting { | 17 namespace remoting { |
| 18 | 18 |
| 19 PepperInputHandler::PepperInputHandler( | 19 PepperInputHandler::PepperInputHandler( |
| 20 pp::Instance* instance) | 20 pp::Instance* instance) |
| 21 : pp::MouseLock(instance), | 21 : pp::MouseLock(instance), |
| 22 instance_(instance), | 22 instance_(instance), |
| 23 input_stub_(NULL), | 23 input_stub_(NULL), |
| 24 callback_factory_(this), | 24 callback_factory_(this), |
| 25 has_focus_(false), | 25 has_focus_(false), |
| 26 send_mouse_input_when_unfocused_(false), |
| 26 mouse_lock_state_(MouseLockDisallowed), | 27 mouse_lock_state_(MouseLockDisallowed), |
| 27 wheel_delta_x_(0), | 28 wheel_delta_x_(0), |
| 28 wheel_delta_y_(0), | 29 wheel_delta_y_(0), |
| 29 wheel_ticks_x_(0), | 30 wheel_ticks_x_(0), |
| 30 wheel_ticks_y_(0) { | 31 wheel_ticks_y_(0) { |
| 31 } | 32 } |
| 32 | 33 |
| 33 PepperInputHandler::~PepperInputHandler() {} | 34 PepperInputHandler::~PepperInputHandler() {} |
| 34 | 35 |
| 35 // Helper function to get the USB key code using the Dev InputEvent interface. | 36 // Helper function to get the USB key code using the Dev InputEvent interface. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 key_event.set_pressed(event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN); | 68 key_event.set_pressed(event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN); |
| 68 key_event.set_lock_states(lock_states); | 69 key_event.set_lock_states(lock_states); |
| 69 | 70 |
| 70 if (input_stub_) | 71 if (input_stub_) |
| 71 input_stub_->InjectKeyEvent(key_event); | 72 input_stub_->InjectKeyEvent(key_event); |
| 72 return true; | 73 return true; |
| 73 } | 74 } |
| 74 | 75 |
| 75 case PP_INPUTEVENT_TYPE_MOUSEDOWN: | 76 case PP_INPUTEVENT_TYPE_MOUSEDOWN: |
| 76 case PP_INPUTEVENT_TYPE_MOUSEUP: { | 77 case PP_INPUTEVENT_TYPE_MOUSEUP: { |
| 77 if (!has_focus_) | 78 if (!has_focus_ && !send_mouse_input_when_unfocused_) |
| 78 return false; | 79 return false; |
| 79 | 80 |
| 80 pp::MouseInputEvent pp_mouse_event(event); | 81 pp::MouseInputEvent pp_mouse_event(event); |
| 81 protocol::MouseEvent mouse_event; | 82 protocol::MouseEvent mouse_event; |
| 82 switch (pp_mouse_event.GetButton()) { | 83 switch (pp_mouse_event.GetButton()) { |
| 83 case PP_INPUTEVENT_MOUSEBUTTON_LEFT: | 84 case PP_INPUTEVENT_MOUSEBUTTON_LEFT: |
| 84 mouse_event.set_button(protocol::MouseEvent::BUTTON_LEFT); | 85 mouse_event.set_button(protocol::MouseEvent::BUTTON_LEFT); |
| 85 break; | 86 break; |
| 86 case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE: | 87 case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE: |
| 87 mouse_event.set_button(protocol::MouseEvent::BUTTON_MIDDLE); | 88 mouse_event.set_button(protocol::MouseEvent::BUTTON_MIDDLE); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 107 | 108 |
| 108 if (input_stub_) | 109 if (input_stub_) |
| 109 input_stub_->InjectMouseEvent(mouse_event); | 110 input_stub_->InjectMouseEvent(mouse_event); |
| 110 } | 111 } |
| 111 return true; | 112 return true; |
| 112 } | 113 } |
| 113 | 114 |
| 114 case PP_INPUTEVENT_TYPE_MOUSEMOVE: | 115 case PP_INPUTEVENT_TYPE_MOUSEMOVE: |
| 115 case PP_INPUTEVENT_TYPE_MOUSEENTER: | 116 case PP_INPUTEVENT_TYPE_MOUSEENTER: |
| 116 case PP_INPUTEVENT_TYPE_MOUSELEAVE: { | 117 case PP_INPUTEVENT_TYPE_MOUSELEAVE: { |
| 117 if (!has_focus_) | 118 if (!has_focus_ && !send_mouse_input_when_unfocused_) |
| 118 return false; | 119 return false; |
| 119 | 120 |
| 120 pp::MouseInputEvent pp_mouse_event(event); | 121 pp::MouseInputEvent pp_mouse_event(event); |
| 121 protocol::MouseEvent mouse_event; | 122 protocol::MouseEvent mouse_event; |
| 122 mouse_event.set_x(pp_mouse_event.GetPosition().x()); | 123 mouse_event.set_x(pp_mouse_event.GetPosition().x()); |
| 123 mouse_event.set_y(pp_mouse_event.GetPosition().y()); | 124 mouse_event.set_y(pp_mouse_event.GetPosition().y()); |
| 124 | 125 |
| 125 // Add relative movement if the mouse is locked. | 126 // Add relative movement if the mouse is locked. |
| 126 if (mouse_lock_state_ == MouseLockOn) { | 127 if (mouse_lock_state_ == MouseLockOn) { |
| 127 pp::Point delta = pp_mouse_event.GetMovement(); | 128 pp::Point delta = pp_mouse_event.GetMovement(); |
| 128 mouse_event.set_delta_x(delta.x()); | 129 mouse_event.set_delta_x(delta.x()); |
| 129 mouse_event.set_delta_y(delta.y()); | 130 mouse_event.set_delta_y(delta.y()); |
| 130 } | 131 } |
| 131 | 132 |
| 132 if (input_stub_) | 133 if (input_stub_) |
| 133 input_stub_->InjectMouseEvent(mouse_event); | 134 input_stub_->InjectMouseEvent(mouse_event); |
| 134 return true; | 135 return true; |
| 135 } | 136 } |
| 136 | 137 |
| 137 case PP_INPUTEVENT_TYPE_WHEEL: { | 138 case PP_INPUTEVENT_TYPE_WHEEL: { |
| 138 if (!has_focus_) | 139 if (!has_focus_ && !send_mouse_input_when_unfocused_) |
| 139 return false; | 140 return false; |
| 140 | 141 |
| 141 pp::WheelInputEvent pp_wheel_event(event); | 142 pp::WheelInputEvent pp_wheel_event(event); |
| 142 | 143 |
| 143 // Don't handle scroll-by-page events, for now. | 144 // Don't handle scroll-by-page events, for now. |
| 144 if (pp_wheel_event.GetScrollByPage()) | 145 if (pp_wheel_event.GetScrollByPage()) |
| 145 return false; | 146 return false; |
| 146 | 147 |
| 147 // Add this event to our accumulated sub-pixel deltas and clicks. | 148 // Add this event to our accumulated sub-pixel deltas and clicks. |
| 148 pp::FloatPoint delta = pp_wheel_event.GetDelta(); | 149 pp::FloatPoint delta = pp_wheel_event.GetDelta(); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 mouse_lock_state_ = MouseLockOff; | 301 mouse_lock_state_ = MouseLockOff; |
| 301 UpdateMouseCursor(); | 302 UpdateMouseCursor(); |
| 302 } | 303 } |
| 303 | 304 |
| 304 // Cancel as needed. | 305 // Cancel as needed. |
| 305 if (should_cancel) | 306 if (should_cancel) |
| 306 CancelMouseLock(); | 307 CancelMouseLock(); |
| 307 } | 308 } |
| 308 | 309 |
| 309 } // namespace remoting | 310 } // namespace remoting |
| OLD | NEW |