Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_chromeos.h" | 5 #include "remoting/host/input_injector_chromeos.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "remoting/host/chromeos/point_transformer.h" | 15 #include "remoting/host/chromeos/point_transformer.h" |
| 16 #include "remoting/host/clipboard.h" | 16 #include "remoting/host/clipboard.h" |
| 17 #include "remoting/proto/internal.pb.h" | 17 #include "remoting/proto/internal.pb.h" |
| 18 #include "ui/base/ime/chromeos/ime_keyboard.h" | |
| 19 #include "ui/base/ime/chromeos/input_method_manager.h" | |
| 18 #include "ui/events/keycodes/dom/dom_code.h" | 20 #include "ui/events/keycodes/dom/dom_code.h" |
| 19 #include "ui/events/keycodes/dom/keycode_converter.h" | 21 #include "ui/events/keycodes/dom/keycode_converter.h" |
| 20 #include "ui/ozone/public/input_controller.h" | |
| 21 #include "ui/ozone/public/ozone_platform.h" | 22 #include "ui/ozone/public/ozone_platform.h" |
| 22 #include "ui/ozone/public/system_input_injector.h" | 23 #include "ui/ozone/public/system_input_injector.h" |
| 23 | 24 |
| 24 namespace remoting { | 25 namespace remoting { |
| 25 | 26 |
| 26 using protocol::ClipboardEvent; | 27 using protocol::ClipboardEvent; |
| 27 using protocol::KeyEvent; | 28 using protocol::KeyEvent; |
| 28 using protocol::MouseEvent; | 29 using protocol::MouseEvent; |
| 29 using protocol::TextEvent; | 30 using protocol::TextEvent; |
| 30 using protocol::TouchEvent; | 31 using protocol::TouchEvent; |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 ui::EventFlags MouseButtonToUIFlags(MouseEvent::MouseButton button) { | 35 ui::EventFlags MouseButtonToUIFlags(MouseEvent::MouseButton button) { |
| 35 switch (button) { | 36 switch (button) { |
| 36 case MouseEvent::BUTTON_LEFT: | 37 case MouseEvent::BUTTON_LEFT: |
| 37 return ui::EF_LEFT_MOUSE_BUTTON; | 38 return ui::EF_LEFT_MOUSE_BUTTON; |
| 38 case MouseEvent::BUTTON_RIGHT: | 39 case MouseEvent::BUTTON_RIGHT: |
| 39 return ui::EF_RIGHT_MOUSE_BUTTON; | 40 return ui::EF_RIGHT_MOUSE_BUTTON; |
| 40 case MouseEvent::BUTTON_MIDDLE: | 41 case MouseEvent::BUTTON_MIDDLE: |
| 41 return ui::EF_MIDDLE_MOUSE_BUTTON; | 42 return ui::EF_MIDDLE_MOUSE_BUTTON; |
| 42 default: | 43 default: |
| 43 NOTREACHED(); | 44 NOTREACHED(); |
| 44 return ui::EF_NONE; | 45 return ui::EF_NONE; |
| 45 } | 46 } |
| 46 } | 47 } |
| 47 | 48 |
| 49 bool shouldSetLockStates(ui::DomCode dom_code, bool key_pressed) { | |
| 50 if (!key_pressed) | |
| 51 return false; | |
| 52 switch (dom_code) { | |
| 53 // Ignores all the keys that could possibly be mapped to Caps Lock in event | |
| 54 // rewriter. | |
|
rkjnsn
2017/06/05 17:49:23
Can you include a reference to where this list com
weidongg
2017/06/05 20:06:57
https://cs.chromium.org/chromium/src/ui/chromeos/e
| |
| 55 case ui::DomCode::F16: | |
| 56 case ui::DomCode::CAPS_LOCK: | |
| 57 case ui::DomCode::META_LEFT: | |
| 58 case ui::DomCode::META_RIGHT: | |
| 59 case ui::DomCode::CONTROL_LEFT: | |
| 60 case ui::DomCode::CONTROL_RIGHT: | |
| 61 case ui::DomCode::ALT_LEFT: | |
| 62 case ui::DomCode::ALT_RIGHT: | |
| 63 case ui::DomCode::ESCAPE: | |
| 64 case ui::DomCode::BACKSPACE: | |
| 65 return false; | |
| 66 default: | |
| 67 return true; | |
| 68 } | |
| 69 } | |
| 70 | |
| 48 } // namespace | 71 } // namespace |
| 49 | 72 |
| 50 // This class is run exclusively on the UI thread of the browser process. | 73 // This class is run exclusively on the UI thread of the browser process. |
| 51 class InputInjectorChromeos::Core { | 74 class InputInjectorChromeos::Core { |
| 52 public: | 75 public: |
| 53 Core(); | 76 Core(); |
| 54 | 77 |
| 55 // Mirrors the public InputInjectorChromeos interface. | 78 // Mirrors the public InputInjectorChromeos interface. |
| 56 void InjectClipboardEvent(const ClipboardEvent& event); | 79 void InjectClipboardEvent(const ClipboardEvent& event); |
| 57 void InjectKeyEvent(const KeyEvent& event); | 80 void InjectKeyEvent(const KeyEvent& event); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 78 | 101 |
| 79 void InputInjectorChromeos::Core::InjectClipboardEvent( | 102 void InputInjectorChromeos::Core::InjectClipboardEvent( |
| 80 const ClipboardEvent& event) { | 103 const ClipboardEvent& event) { |
| 81 clipboard_->InjectClipboardEvent(event); | 104 clipboard_->InjectClipboardEvent(event); |
| 82 } | 105 } |
| 83 | 106 |
| 84 void InputInjectorChromeos::Core::InjectKeyEvent(const KeyEvent& event) { | 107 void InputInjectorChromeos::Core::InjectKeyEvent(const KeyEvent& event) { |
| 85 DCHECK(event.has_pressed()); | 108 DCHECK(event.has_pressed()); |
| 86 DCHECK(event.has_usb_keycode()); | 109 DCHECK(event.has_usb_keycode()); |
| 87 | 110 |
| 88 if (event.has_lock_states()) { | |
| 89 SetLockStates(event.lock_states()); | |
| 90 } | |
| 91 | |
| 92 ui::DomCode dom_code = | 111 ui::DomCode dom_code = |
| 93 ui::KeycodeConverter::UsbKeycodeToDomCode(event.usb_keycode()); | 112 ui::KeycodeConverter::UsbKeycodeToDomCode(event.usb_keycode()); |
| 94 | 113 |
| 114 if (event.has_lock_states() && | |
| 115 shouldSetLockStates(dom_code, event.pressed())) { | |
| 116 SetLockStates(event.lock_states()); | |
| 117 } | |
| 118 | |
| 95 // Ignore events which can't be mapped. | 119 // Ignore events which can't be mapped. |
| 96 if (dom_code != ui::DomCode::NONE) { | 120 if (dom_code != ui::DomCode::NONE) { |
| 97 delegate_->InjectKeyEvent(dom_code, event.pressed(), | 121 delegate_->InjectKeyEvent(dom_code, event.pressed(), |
| 98 true /* suppress_auto_repeat */); | 122 true /* suppress_auto_repeat */); |
| 99 } | 123 } |
| 100 } | 124 } |
| 101 | 125 |
| 102 void InputInjectorChromeos::Core::InjectTextEvent(const TextEvent& event) { | 126 void InputInjectorChromeos::Core::InjectTextEvent(const TextEvent& event) { |
| 103 // Chrome OS only supports It2Me, which is not supported on mobile clients, so | 127 // Chrome OS only supports It2Me, which is not supported on mobile clients, so |
| 104 // we don't need to implement text events. | 128 // we don't need to implement text events. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 124 delegate_ = ozone_platform->CreateSystemInputInjector(); | 148 delegate_ = ozone_platform->CreateSystemInputInjector(); |
| 125 DCHECK(delegate_); | 149 DCHECK(delegate_); |
| 126 | 150 |
| 127 // Implemented by remoting::ClipboardAura. | 151 // Implemented by remoting::ClipboardAura. |
| 128 clipboard_ = Clipboard::Create(); | 152 clipboard_ = Clipboard::Create(); |
| 129 clipboard_->Start(std::move(client_clipboard)); | 153 clipboard_->Start(std::move(client_clipboard)); |
| 130 point_transformer_.reset(new PointTransformer()); | 154 point_transformer_.reset(new PointTransformer()); |
| 131 } | 155 } |
| 132 | 156 |
| 133 void InputInjectorChromeos::Core::SetLockStates(uint32_t states) { | 157 void InputInjectorChromeos::Core::SetLockStates(uint32_t states) { |
| 134 ui::InputController* input_controller = | 158 chromeos::input_method::InputMethodManager* ime = |
| 135 ui::OzonePlatform::GetInstance()->GetInputController(); | 159 chromeos::input_method::InputMethodManager::Get(); |
| 136 input_controller->SetCapsLockEnabled( | 160 ime->GetImeKeyboard()->SetCapsLockEnabled( |
| 137 states & protocol::KeyEvent::LOCK_STATES_CAPSLOCK); | 161 states & protocol::KeyEvent::LOCK_STATES_CAPSLOCK); |
| 138 } | 162 } |
| 139 | 163 |
| 140 InputInjectorChromeos::InputInjectorChromeos( | 164 InputInjectorChromeos::InputInjectorChromeos( |
| 141 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 165 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 142 : input_task_runner_(task_runner) { | 166 : input_task_runner_(task_runner) { |
| 143 core_.reset(new Core()); | 167 core_.reset(new Core()); |
| 144 } | 168 } |
| 145 | 169 |
| 146 InputInjectorChromeos::~InputInjectorChromeos() { | 170 InputInjectorChromeos::~InputInjectorChromeos() { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 // browser process. | 214 // browser process. |
| 191 return base::WrapUnique(new InputInjectorChromeos(ui_task_runner)); | 215 return base::WrapUnique(new InputInjectorChromeos(ui_task_runner)); |
| 192 } | 216 } |
| 193 | 217 |
| 194 // static | 218 // static |
| 195 bool InputInjector::SupportsTouchEvents() { | 219 bool InputInjector::SupportsTouchEvents() { |
| 196 return false; | 220 return false; |
| 197 } | 221 } |
| 198 | 222 |
| 199 } // namespace remoting | 223 } // namespace remoting |
| OLD | NEW |