Chromium Code Reviews| Index: remoting/host/input_injector_x11.cc |
| diff --git a/remoting/host/input_injector_x11.cc b/remoting/host/input_injector_x11.cc |
| index 3c9d0a88fe17565532968acb8a2f348e25f0d80d..6459b02143257870579498295214897ecd13b106 100644 |
| --- a/remoting/host/input_injector_x11.cc |
| +++ b/remoting/host/input_injector_x11.cc |
| @@ -26,6 +26,8 @@ |
| #include "remoting/host/clipboard.h" |
| #include "remoting/host/linux/unicode_to_keysym.h" |
| #include "remoting/host/linux/x11_util.h" |
| +#include "remoting/host/linux/x_server_character_injector.h" |
| +#include "remoting/host/linux/x_server_keyboard_interface.h" |
| #include "remoting/proto/internal.pb.h" |
| #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
| #include "ui/events/keycodes/dom/dom_code.h" |
| @@ -45,56 +47,6 @@ using protocol::TextEvent; |
| using protocol::MouseEvent; |
| using protocol::TouchEvent; |
| -bool FindKeycodeForKeySym(Display* display, |
| - KeySym key_sym, |
| - uint32_t* keycode, |
| - uint32_t* modifiers) { |
| - *keycode = XKeysymToKeycode(display, key_sym); |
| - |
| - const uint32_t kModifiersToTry[] = { |
| - 0, |
| - ShiftMask, |
| - Mod2Mask, |
| - Mod3Mask, |
| - Mod4Mask, |
| - ShiftMask | Mod2Mask, |
| - ShiftMask | Mod3Mask, |
| - ShiftMask | Mod4Mask, |
| - }; |
| - |
| - // TODO(sergeyu): Is there a better way to find modifiers state? |
| - for (size_t i = 0; i < arraysize(kModifiersToTry); ++i) { |
| - unsigned long key_sym_with_mods; |
| - if (XkbLookupKeySym(display, *keycode, kModifiersToTry[i], nullptr, |
| - &key_sym_with_mods) && |
| - key_sym_with_mods == key_sym) { |
| - *modifiers = kModifiersToTry[i]; |
| - return true; |
| - } |
| - } |
| - |
| - return false; |
| -} |
| - |
| -// Finds a keycode and set of modifiers that generate character with the |
| -// specified |code_point|. |
| -bool FindKeycodeForUnicode(Display* display, |
| - uint32_t code_point, |
| - uint32_t* keycode, |
| - uint32_t* modifiers) { |
| - std::vector<uint32_t> keysyms; |
| - GetKeySymsForUnicode(code_point, &keysyms); |
| - |
| - for (std::vector<uint32_t>::iterator it = keysyms.begin(); |
| - it != keysyms.end(); ++it) { |
| - if (FindKeycodeForKeySym(display, *it, keycode, modifiers)) { |
| - return true; |
| - } |
| - } |
| - |
| - return false; |
| -} |
| - |
| bool IsModifierKey(ui::DomCode dom_code) { |
| return dom_code == ui::DomCode::CONTROL_LEFT || |
| dom_code == ui::DomCode::SHIFT_LEFT || |
| @@ -199,6 +151,10 @@ class InputInjectorX11 : public InputInjector { |
| std::unique_ptr<Clipboard> clipboard_; |
| + std::unique_ptr<XServerKeyboardInterface> keyboard_; |
|
Sergey Ulanov
2016/09/21 19:59:23
Do you need this here? Can XServerCharacterInjecto
Yuwei
2016/09/23 01:40:37
Done.
|
| + |
| + std::unique_ptr<XServerCharacterInjector> character_injector_; |
| + |
| bool saved_auto_repeat_enabled_; |
| DISALLOW_COPY_AND_ASSIGN(Core); |
| @@ -364,21 +320,8 @@ void InputInjectorX11::Core::InjectTextEvent(const TextEvent& event) { |
| text.c_str(), text.size(), &index, &code_point)) { |
| continue; |
| } |
| - |
| - uint32_t keycode; |
| - uint32_t modifiers; |
| - if (!FindKeycodeForUnicode(display_, code_point, &keycode, &modifiers)) |
| - continue; |
| - |
| - XkbLockModifiers(display_, XkbUseCoreKbd, modifiers, modifiers); |
| - |
| - XTestFakeKeyEvent(display_, keycode, True, CurrentTime); |
| - XTestFakeKeyEvent(display_, keycode, False, CurrentTime); |
| - |
| - XkbLockModifiers(display_, XkbUseCoreKbd, modifiers, 0); |
| + character_injector_->Inject(code_point); |
| } |
| - |
| - XFlush(display_); |
| } |
| InputInjectorX11::Core::~Core() { |
| @@ -634,6 +577,9 @@ void InputInjectorX11::Core::Start( |
| InitMouseButtonMap(); |
| clipboard_->Start(std::move(client_clipboard)); |
| + |
| + keyboard_.reset(new XServerKeyboardInterface(display_)); |
| + character_injector_.reset(new XServerCharacterInjector(keyboard_.get())); |
| } |
| void InputInjectorX11::Core::Stop() { |
| @@ -643,6 +589,8 @@ void InputInjectorX11::Core::Stop() { |
| } |
| clipboard_.reset(); |
| + character_injector_.reset(); |
| + keyboard_.reset(); |
| } |
| } // namespace |