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 protocol::InputStub* input_stub) | 21 protocol::InputStub* input_stub) |
22 : pp::MouseLock(instance), | 22 : pp::MouseLock(instance), |
23 instance_(instance), | 23 instance_(instance), |
24 input_stub_(input_stub), | 24 input_stub_(input_stub), |
25 callback_factory_(this), | 25 callback_factory_(this), |
26 has_focus_(false), | 26 has_focus_(false), |
27 send_mouse_input_when_unfocused_(false), | |
Wez
2014/05/22 01:14:23
nit: You could call this (and the related method,
Jamie
2014/05/22 01:32:09
Since it controls more than just mouse movements,
| |
27 mouse_lock_state_(MouseLockDisallowed), | 28 mouse_lock_state_(MouseLockDisallowed), |
28 wheel_delta_x_(0), | 29 wheel_delta_x_(0), |
29 wheel_delta_y_(0), | 30 wheel_delta_y_(0), |
30 wheel_ticks_x_(0), | 31 wheel_ticks_x_(0), |
31 wheel_ticks_y_(0) { | 32 wheel_ticks_y_(0) { |
32 } | 33 } |
33 | 34 |
34 PepperInputHandler::~PepperInputHandler() { | 35 PepperInputHandler::~PepperInputHandler() { |
35 } | 36 } |
36 | 37 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 key_event.set_usb_keycode(GetUsbKeyCode(pp_key_event)); | 69 key_event.set_usb_keycode(GetUsbKeyCode(pp_key_event)); |
69 key_event.set_pressed(event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN); | 70 key_event.set_pressed(event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN); |
70 key_event.set_lock_states(lock_states); | 71 key_event.set_lock_states(lock_states); |
71 | 72 |
72 input_stub_->InjectKeyEvent(key_event); | 73 input_stub_->InjectKeyEvent(key_event); |
73 return true; | 74 return true; |
74 } | 75 } |
75 | 76 |
76 case PP_INPUTEVENT_TYPE_MOUSEDOWN: | 77 case PP_INPUTEVENT_TYPE_MOUSEDOWN: |
77 case PP_INPUTEVENT_TYPE_MOUSEUP: { | 78 case PP_INPUTEVENT_TYPE_MOUSEUP: { |
78 if (!has_focus_) | 79 if (!has_focus_ && !send_mouse_input_when_unfocused_) |
Wez
2014/05/22 01:14:23
Should we be filtering these at all? Is there any
Jamie
2014/05/22 01:32:09
I wrote up a summary when I added this code:
http
| |
79 return false; | 80 return false; |
80 | 81 |
81 pp::MouseInputEvent pp_mouse_event(event); | 82 pp::MouseInputEvent pp_mouse_event(event); |
82 protocol::MouseEvent mouse_event; | 83 protocol::MouseEvent mouse_event; |
83 switch (pp_mouse_event.GetButton()) { | 84 switch (pp_mouse_event.GetButton()) { |
84 case PP_INPUTEVENT_MOUSEBUTTON_LEFT: | 85 case PP_INPUTEVENT_MOUSEBUTTON_LEFT: |
85 mouse_event.set_button(protocol::MouseEvent::BUTTON_LEFT); | 86 mouse_event.set_button(protocol::MouseEvent::BUTTON_LEFT); |
86 break; | 87 break; |
87 case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE: | 88 case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE: |
88 mouse_event.set_button(protocol::MouseEvent::BUTTON_MIDDLE); | 89 mouse_event.set_button(protocol::MouseEvent::BUTTON_MIDDLE); |
(...skipping 18 matching lines...) Expand all Loading... | |
107 } | 108 } |
108 | 109 |
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 input_stub_->InjectMouseEvent(mouse_event); | 133 input_stub_->InjectMouseEvent(mouse_event); |
133 return true; | 134 return true; |
134 } | 135 } |
135 | 136 |
136 case PP_INPUTEVENT_TYPE_WHEEL: { | 137 case PP_INPUTEVENT_TYPE_WHEEL: { |
137 if (!has_focus_) | 138 if (!has_focus_ && !send_mouse_input_when_unfocused_) |
138 return false; | 139 return false; |
139 | 140 |
140 pp::WheelInputEvent pp_wheel_event(event); | 141 pp::WheelInputEvent pp_wheel_event(event); |
141 | 142 |
142 // Don't handle scroll-by-page events, for now. | 143 // Don't handle scroll-by-page events, for now. |
143 if (pp_wheel_event.GetScrollByPage()) | 144 if (pp_wheel_event.GetScrollByPage()) |
144 return false; | 145 return false; |
145 | 146 |
146 // Add this event to our accumulated sub-pixel deltas and clicks. | 147 // Add this event to our accumulated sub-pixel deltas and clicks. |
147 pp::FloatPoint delta = pp_wheel_event.GetDelta(); | 148 pp::FloatPoint delta = pp_wheel_event.GetDelta(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 cursor_image_ = image.Pass(); | 210 cursor_image_ = image.Pass(); |
210 cursor_hotspot_ = hotspot; | 211 cursor_hotspot_ = hotspot; |
211 | 212 |
212 if (mouse_lock_state_ != MouseLockDisallowed && !cursor_image_) { | 213 if (mouse_lock_state_ != MouseLockDisallowed && !cursor_image_) { |
213 RequestMouseLock(); | 214 RequestMouseLock(); |
214 } else { | 215 } else { |
215 CancelMouseLock(); | 216 CancelMouseLock(); |
216 } | 217 } |
217 } | 218 } |
218 | 219 |
220 void PepperInputHandler::SendMouseInputWhenUnfocused() { | |
221 send_mouse_input_when_unfocused_ = true; | |
222 } | |
223 | |
219 void PepperInputHandler::MouseLockLost() { | 224 void PepperInputHandler::MouseLockLost() { |
220 DCHECK(mouse_lock_state_ == MouseLockOn || | 225 DCHECK(mouse_lock_state_ == MouseLockOn || |
221 mouse_lock_state_ == MouseLockCancelling); | 226 mouse_lock_state_ == MouseLockCancelling); |
222 | 227 |
223 mouse_lock_state_ = MouseLockOff; | 228 mouse_lock_state_ = MouseLockOff; |
224 UpdateMouseCursor(); | 229 UpdateMouseCursor(); |
225 } | 230 } |
226 | 231 |
227 void PepperInputHandler::RequestMouseLock() { | 232 void PepperInputHandler::RequestMouseLock() { |
228 // Request mouse lock only if the plugin is focused, the host-supplied cursor | 233 // Request mouse lock only if the plugin is focused, the host-supplied cursor |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 mouse_lock_state_ = MouseLockOff; | 303 mouse_lock_state_ = MouseLockOff; |
299 UpdateMouseCursor(); | 304 UpdateMouseCursor(); |
300 } | 305 } |
301 | 306 |
302 // Cancel as needed. | 307 // Cancel as needed. |
303 if (should_cancel) | 308 if (should_cancel) |
304 CancelMouseLock(); | 309 CancelMouseLock(); |
305 } | 310 } |
306 | 311 |
307 } // namespace remoting | 312 } // namespace remoting |
OLD | NEW |