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" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 } | 45 } |
46 | 46 |
47 bool PepperInputHandler::HandleInputEvent(const pp::InputEvent& event) { | 47 bool PepperInputHandler::HandleInputEvent(const pp::InputEvent& event) { |
48 switch (event.GetType()) { | 48 switch (event.GetType()) { |
49 case PP_INPUTEVENT_TYPE_CONTEXTMENU: { | 49 case PP_INPUTEVENT_TYPE_CONTEXTMENU: { |
50 // We need to return true here or else we'll get a local (plugin) context | 50 // We need to return true here or else we'll get a local (plugin) context |
51 // menu instead of the mouseup event for the right click. | 51 // menu instead of the mouseup event for the right click. |
52 return true; | 52 return true; |
53 } | 53 } |
54 | 54 |
55 case PP_INPUTEVENT_TYPE_KEYDOWN: | 55 case PP_INPUTEVENT_TYPE_KEYDOWN: |
weitao
2014/02/07 23:54:23
While at it, could you please also ignore key even
Jamie
2014/02/08 00:12:54
We don't get key events when we don't have focus.
| |
56 case PP_INPUTEVENT_TYPE_KEYUP: { | 56 case PP_INPUTEVENT_TYPE_KEYUP: { |
57 pp::KeyboardInputEvent pp_key_event(event); | 57 pp::KeyboardInputEvent pp_key_event(event); |
58 uint32_t modifiers = event.GetModifiers(); | 58 uint32_t modifiers = event.GetModifiers(); |
59 uint32_t lock_states = 0; | 59 uint32_t lock_states = 0; |
60 | 60 |
61 if (modifiers & PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY) | 61 if (modifiers & PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY) |
62 lock_states |= protocol::KeyEvent::LOCK_STATES_CAPSLOCK; | 62 lock_states |= protocol::KeyEvent::LOCK_STATES_CAPSLOCK; |
63 | 63 |
64 if (modifiers & PP_INPUTEVENT_MODIFIER_NUMLOCKKEY) | 64 if (modifiers & PP_INPUTEVENT_MODIFIER_NUMLOCKKEY) |
65 lock_states |= protocol::KeyEvent::LOCK_STATES_NUMLOCK; | 65 lock_states |= protocol::KeyEvent::LOCK_STATES_NUMLOCK; |
66 | 66 |
67 protocol::KeyEvent key_event; | 67 protocol::KeyEvent key_event; |
68 key_event.set_usb_keycode(GetUsbKeyCode(pp_key_event)); | 68 key_event.set_usb_keycode(GetUsbKeyCode(pp_key_event)); |
69 key_event.set_pressed(event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN); | 69 key_event.set_pressed(event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN); |
70 key_event.set_lock_states(lock_states); | 70 key_event.set_lock_states(lock_states); |
71 | 71 |
72 input_stub_->InjectKeyEvent(key_event); | 72 input_stub_->InjectKeyEvent(key_event); |
73 return true; | 73 return true; |
74 } | 74 } |
75 | 75 |
76 case PP_INPUTEVENT_TYPE_MOUSEDOWN: | 76 case PP_INPUTEVENT_TYPE_MOUSEDOWN: |
77 case PP_INPUTEVENT_TYPE_MOUSEUP: { | 77 case PP_INPUTEVENT_TYPE_MOUSEUP: { |
78 if (!has_focus_) | |
79 return false; | |
Jamie
2014/02/07 22:34:39
I'm in two minds about this one. Some platforms (s
weitao
2014/02/07 23:54:23
I agree the first behavior is better.
On 2014/02/
| |
80 | |
78 pp::MouseInputEvent pp_mouse_event(event); | 81 pp::MouseInputEvent pp_mouse_event(event); |
79 protocol::MouseEvent mouse_event; | 82 protocol::MouseEvent mouse_event; |
80 switch (pp_mouse_event.GetButton()) { | 83 switch (pp_mouse_event.GetButton()) { |
81 case PP_INPUTEVENT_MOUSEBUTTON_LEFT: | 84 case PP_INPUTEVENT_MOUSEBUTTON_LEFT: |
82 mouse_event.set_button(protocol::MouseEvent::BUTTON_LEFT); | 85 mouse_event.set_button(protocol::MouseEvent::BUTTON_LEFT); |
83 break; | 86 break; |
84 case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE: | 87 case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE: |
85 mouse_event.set_button(protocol::MouseEvent::BUTTON_MIDDLE); | 88 mouse_event.set_button(protocol::MouseEvent::BUTTON_MIDDLE); |
86 break; | 89 break; |
87 case PP_INPUTEVENT_MOUSEBUTTON_RIGHT: | 90 case PP_INPUTEVENT_MOUSEBUTTON_RIGHT: |
(...skipping 16 matching lines...) Expand all Loading... | |
104 } | 107 } |
105 | 108 |
106 input_stub_->InjectMouseEvent(mouse_event); | 109 input_stub_->InjectMouseEvent(mouse_event); |
107 } | 110 } |
108 return true; | 111 return true; |
109 } | 112 } |
110 | 113 |
111 case PP_INPUTEVENT_TYPE_MOUSEMOVE: | 114 case PP_INPUTEVENT_TYPE_MOUSEMOVE: |
112 case PP_INPUTEVENT_TYPE_MOUSEENTER: | 115 case PP_INPUTEVENT_TYPE_MOUSEENTER: |
113 case PP_INPUTEVENT_TYPE_MOUSELEAVE: { | 116 case PP_INPUTEVENT_TYPE_MOUSELEAVE: { |
117 if (!has_focus_) | |
118 return false; | |
119 | |
114 pp::MouseInputEvent pp_mouse_event(event); | 120 pp::MouseInputEvent pp_mouse_event(event); |
115 protocol::MouseEvent mouse_event; | 121 protocol::MouseEvent mouse_event; |
116 mouse_event.set_x(pp_mouse_event.GetPosition().x()); | 122 mouse_event.set_x(pp_mouse_event.GetPosition().x()); |
117 mouse_event.set_y(pp_mouse_event.GetPosition().y()); | 123 mouse_event.set_y(pp_mouse_event.GetPosition().y()); |
118 | 124 |
119 // Add relative movement if the mouse is locked. | 125 // Add relative movement if the mouse is locked. |
120 if (mouse_lock_state_ == MouseLockOn) { | 126 if (mouse_lock_state_ == MouseLockOn) { |
121 pp::Point delta = pp_mouse_event.GetMovement(); | 127 pp::Point delta = pp_mouse_event.GetMovement(); |
122 mouse_event.set_delta_x(delta.x()); | 128 mouse_event.set_delta_x(delta.x()); |
123 mouse_event.set_delta_y(delta.y()); | 129 mouse_event.set_delta_y(delta.y()); |
124 } | 130 } |
125 | 131 |
126 input_stub_->InjectMouseEvent(mouse_event); | 132 input_stub_->InjectMouseEvent(mouse_event); |
127 return true; | 133 return true; |
128 } | 134 } |
129 | 135 |
130 case PP_INPUTEVENT_TYPE_WHEEL: { | 136 case PP_INPUTEVENT_TYPE_WHEEL: { |
137 if (!has_focus_) | |
138 return false; | |
139 | |
131 pp::WheelInputEvent pp_wheel_event(event); | 140 pp::WheelInputEvent pp_wheel_event(event); |
132 | 141 |
133 // Don't handle scroll-by-page events, for now. | 142 // Don't handle scroll-by-page events, for now. |
134 if (pp_wheel_event.GetScrollByPage()) | 143 if (pp_wheel_event.GetScrollByPage()) |
135 return false; | 144 return false; |
136 | 145 |
137 // Add this event to our accumulated sub-pixel deltas and clicks. | 146 // Add this event to our accumulated sub-pixel deltas and clicks. |
138 pp::FloatPoint delta = pp_wheel_event.GetDelta(); | 147 pp::FloatPoint delta = pp_wheel_event.GetDelta(); |
139 wheel_delta_x_ += delta.x(); | 148 wheel_delta_x_ += delta.x(); |
140 wheel_delta_y_ += delta.y(); | 149 wheel_delta_y_ += delta.y(); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 mouse_lock_state_ = MouseLockOff; | 298 mouse_lock_state_ = MouseLockOff; |
290 UpdateMouseCursor(); | 299 UpdateMouseCursor(); |
291 } | 300 } |
292 | 301 |
293 // Cancel as needed. | 302 // Cancel as needed. |
294 if (should_cancel) | 303 if (should_cancel) |
295 CancelMouseLock(); | 304 CancelMouseLock(); |
296 } | 305 } |
297 | 306 |
298 } // namespace remoting | 307 } // namespace remoting |
OLD | NEW |