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/host/input_injector.h" | 5 #include "remoting/host/input_injector.h" |
6 | 6 |
7 #include <X11/extensions/XInput.h> | 7 #include <X11/extensions/XInput.h> |
8 #include <X11/extensions/XTest.h> | 8 #include <X11/extensions/XTest.h> |
9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
10 #include <X11/XKBlib.h> | 10 #include <X11/XKBlib.h> |
11 #undef Status // Xlib.h #defines this, which breaks protobuf headers. | 11 #undef Status // Xlib.h #defines this, which breaks protobuf headers. |
12 | 12 |
13 #include <set> | 13 #include <set> |
14 | 14 |
15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
18 #include "base/location.h" | 18 #include "base/location.h" |
19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
20 #include "base/strings/utf_string_conversion_utils.h" | 20 #include "base/strings/utf_string_conversion_utils.h" |
21 #include "remoting/base/logging.h" | 21 #include "remoting/base/logging.h" |
22 #if defined(OS_CHROMEOS) | 22 #if defined(OS_CHROMEOS) |
23 #include "remoting/host/chromeos/point_transformer.h" | 23 #include "remoting/host/chromeos/point_transformer.h" |
24 #endif | 24 #endif |
25 #include "remoting/host/clipboard.h" | 25 #include "remoting/host/clipboard.h" |
26 #include "remoting/host/linux/unicode_to_keysym.h" | 26 #include "remoting/host/linux/unicode_to_keysym.h" |
27 #include "remoting/proto/internal.pb.h" | 27 #include "remoting/proto/internal.pb.h" |
28 #include "remoting/protocol/usb_key_codes.h" | |
29 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 28 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
| 29 #include "ui/events/keycodes/dom/dom_code.h" |
30 #include "ui/events/keycodes/dom/keycode_converter.h" | 30 #include "ui/events/keycodes/dom/keycode_converter.h" |
31 | 31 |
32 namespace remoting { | 32 namespace remoting { |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 using protocol::ClipboardEvent; | 36 using protocol::ClipboardEvent; |
37 using protocol::KeyEvent; | 37 using protocol::KeyEvent; |
38 using protocol::TextEvent; | 38 using protocol::TextEvent; |
39 using protocol::MouseEvent; | 39 using protocol::MouseEvent; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 for (std::vector<uint32_t>::iterator it = keysyms.begin(); | 82 for (std::vector<uint32_t>::iterator it = keysyms.begin(); |
83 it != keysyms.end(); ++it) { | 83 it != keysyms.end(); ++it) { |
84 if (FindKeycodeForKeySym(display, *it, keycode, modifiers)) { | 84 if (FindKeycodeForKeySym(display, *it, keycode, modifiers)) { |
85 return true; | 85 return true; |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 return false; | 89 return false; |
90 } | 90 } |
91 | 91 |
92 bool IsModifierKey(int usb_keycode) { | 92 bool IsModifierKey(ui::DomCode dom_code) { |
93 return usb_keycode == kUsbLeftControl || | 93 return dom_code == ui::DomCode::CONTROL_LEFT || |
94 usb_keycode == kUsbLeftShift || | 94 dom_code == ui::DomCode::SHIFT_LEFT || |
95 usb_keycode == kUsbLeftAlt || | 95 dom_code == ui::DomCode::ALT_LEFT || |
96 usb_keycode == kUsbLeftOs || | 96 dom_code == ui::DomCode::OS_LEFT || |
97 usb_keycode == kUsbRightControl || | 97 dom_code == ui::DomCode::CONTROL_RIGHT || |
98 usb_keycode == kUsbRightShift || | 98 dom_code == ui::DomCode::SHIFT_RIGHT || |
99 usb_keycode == kUsbRightAlt || | 99 dom_code == ui::DomCode::ALT_RIGHT || |
100 usb_keycode == kUsbRightOs; | 100 dom_code == ui::DomCode::OS_RIGHT; |
101 } | 101 } |
102 | 102 |
103 // Pixel-to-wheel-ticks conversion ratio used by GTK. | 103 // Pixel-to-wheel-ticks conversion ratio used by GTK. |
104 // From third_party/WebKit/Source/web/gtk/WebInputEventFactory.cpp . | 104 // From third_party/WebKit/Source/web/gtk/WebInputEventFactory.cpp . |
105 const float kWheelTicksPerPixel = 3.0f / 160.0f; | 105 const float kWheelTicksPerPixel = 3.0f / 160.0f; |
106 | 106 |
107 // A class to generate events on X11. | 107 // A class to generate events on X11. |
108 class InputInjectorX11 : public InputInjector { | 108 class InputInjectorX11 : public InputInjector { |
109 public: | 109 public: |
110 explicit InputInjectorX11( | 110 explicit InputInjectorX11( |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 VLOG(3) << "Converting USB keycode: " << std::hex << event.usb_keycode() | 307 VLOG(3) << "Converting USB keycode: " << std::hex << event.usb_keycode() |
308 << " to keycode: " << keycode << std::dec; | 308 << " to keycode: " << keycode << std::dec; |
309 | 309 |
310 // Ignore events which can't be mapped. | 310 // Ignore events which can't be mapped. |
311 if (keycode == ui::KeycodeConverter::InvalidNativeKeycode()) | 311 if (keycode == ui::KeycodeConverter::InvalidNativeKeycode()) |
312 return; | 312 return; |
313 | 313 |
314 if (event.pressed()) { | 314 if (event.pressed()) { |
315 if (pressed_keys_.find(keycode) != pressed_keys_.end()) { | 315 if (pressed_keys_.find(keycode) != pressed_keys_.end()) { |
316 // Ignore repeats for modifier keys. | 316 // Ignore repeats for modifier keys. |
317 if (IsModifierKey(event.usb_keycode())) | 317 if (IsModifierKey(static_cast<ui::DomCode>(event.usb_keycode()))) |
318 return; | 318 return; |
319 // Key is already held down, so lift the key up to ensure this repeated | 319 // Key is already held down, so lift the key up to ensure this repeated |
320 // press takes effect. | 320 // press takes effect. |
321 XTestFakeKeyEvent(display_, keycode, False, CurrentTime); | 321 XTestFakeKeyEvent(display_, keycode, False, CurrentTime); |
322 } | 322 } |
323 | 323 |
324 if (pressed_keys_.empty()) { | 324 if (pressed_keys_.empty()) { |
325 // Disable auto-repeat, if necessary, to avoid triggering auto-repeat | 325 // Disable auto-repeat, if necessary, to avoid triggering auto-repeat |
326 // if network congestion delays the key-up event from the client. | 326 // if network congestion delays the key-up event from the client. |
327 saved_auto_repeat_enabled_ = IsAutoRepeatEnabled(); | 327 saved_auto_repeat_enabled_ = IsAutoRepeatEnabled(); |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 return nullptr; | 655 return nullptr; |
656 return injector.Pass(); | 656 return injector.Pass(); |
657 } | 657 } |
658 | 658 |
659 // static | 659 // static |
660 bool InputInjector::SupportsTouchEvents() { | 660 bool InputInjector::SupportsTouchEvents() { |
661 return false; | 661 return false; |
662 } | 662 } |
663 | 663 |
664 } // namespace remoting | 664 } // namespace remoting |
OLD | NEW |