Chromium Code Reviews| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 | 192 |
| 193 private: | 193 private: |
| 194 friend class base::RefCountedThreadSafe<Core>; | 194 friend class base::RefCountedThreadSafe<Core>; |
| 195 virtual ~Core(); | 195 virtual ~Core(); |
| 196 | 196 |
| 197 void HandleKey(const KeyEvent& event); | 197 void HandleKey(const KeyEvent& event); |
| 198 void HandleText(const TextEvent& event); | 198 void HandleText(const TextEvent& event); |
| 199 void HandleMouse(const MouseEvent& event); | 199 void HandleMouse(const MouseEvent& event); |
| 200 void HandleTouch(const TouchEvent& event); | 200 void HandleTouch(const TouchEvent& event); |
| 201 | 201 |
| 202 // Sets the keyboard lock states to those provided. | |
| 203 void SetLockStates(uint32_t states); | |
| 204 | |
| 202 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 205 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 203 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 206 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 204 std::unique_ptr<Clipboard> clipboard_; | 207 std::unique_ptr<Clipboard> clipboard_; |
| 205 std::unique_ptr<TouchInjectorWin> touch_injector_; | 208 std::unique_ptr<TouchInjectorWin> touch_injector_; |
| 206 | 209 |
| 207 DISALLOW_COPY_AND_ASSIGN(Core); | 210 DISALLOW_COPY_AND_ASSIGN(Core); |
| 208 }; | 211 }; |
| 209 | 212 |
| 210 scoped_refptr<Core> core_; | 213 scoped_refptr<Core> core_; |
| 211 | 214 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 | 344 |
| 342 int scancode = | 345 int scancode = |
| 343 ui::KeycodeConverter::UsbKeycodeToNativeKeycode(event.usb_keycode()); | 346 ui::KeycodeConverter::UsbKeycodeToNativeKeycode(event.usb_keycode()); |
| 344 VLOG(3) << "Converting USB keycode: " << std::hex << event.usb_keycode() | 347 VLOG(3) << "Converting USB keycode: " << std::hex << event.usb_keycode() |
| 345 << " to scancode: " << scancode << std::dec; | 348 << " to scancode: " << scancode << std::dec; |
| 346 | 349 |
| 347 // Ignore events which can't be mapped. | 350 // Ignore events which can't be mapped. |
| 348 if (scancode == ui::KeycodeConverter::InvalidNativeKeycode()) | 351 if (scancode == ui::KeycodeConverter::InvalidNativeKeycode()) |
| 349 return; | 352 return; |
| 350 | 353 |
| 354 if (event.has_lock_states()) { | |
| 355 SetLockStates(event.lock_states()); | |
| 356 } | |
| 357 | |
| 351 uint32_t flags = KEYEVENTF_SCANCODE | (event.pressed() ? 0 : KEYEVENTF_KEYUP); | 358 uint32_t flags = KEYEVENTF_SCANCODE | (event.pressed() ? 0 : KEYEVENTF_KEYUP); |
| 352 SendKeyboardInput(flags, scancode); | 359 SendKeyboardInput(flags, scancode); |
| 353 } | 360 } |
| 354 | 361 |
| 355 void InputInjectorWin::Core::HandleText(const TextEvent& event) { | 362 void InputInjectorWin::Core::HandleText(const TextEvent& event) { |
| 356 // HostEventDispatcher should filter events missing the pressed field. | 363 // HostEventDispatcher should filter events missing the pressed field. |
| 357 DCHECK(event.has_text()); | 364 DCHECK(event.has_text()); |
| 358 | 365 |
| 359 base::string16 text = base::UTF8ToUTF16(event.text()); | 366 base::string16 text = base::UTF8ToUTF16(event.text()); |
| 360 for (base::string16::const_iterator it = text.begin(); | 367 for (base::string16::const_iterator it = text.begin(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 377 if (SendInput(inputs.size(), inputs.data(), sizeof(INPUT)) != inputs.size()) | 384 if (SendInput(inputs.size(), inputs.data(), sizeof(INPUT)) != inputs.size()) |
| 378 PLOG(ERROR) << "Failed to inject a mouse event"; | 385 PLOG(ERROR) << "Failed to inject a mouse event"; |
| 379 } | 386 } |
| 380 } | 387 } |
| 381 | 388 |
| 382 void InputInjectorWin::Core::HandleTouch(const TouchEvent& event) { | 389 void InputInjectorWin::Core::HandleTouch(const TouchEvent& event) { |
| 383 DCHECK(touch_injector_); | 390 DCHECK(touch_injector_); |
| 384 touch_injector_->InjectTouchEvent(event); | 391 touch_injector_->InjectTouchEvent(event); |
| 385 } | 392 } |
| 386 | 393 |
| 394 void InputInjectorWin::Core::SetLockStates(uint32_t states) { | |
| 395 // Can't use SendKeyboardInput because we need to send virtual key codes, not | |
| 396 // scan codes. | |
| 397 INPUT input[2]; | |
| 398 memset(&input, 0, sizeof(input)); | |
| 399 input[0].type = INPUT_KEYBOARD; | |
| 400 input[1].type = INPUT_KEYBOARD; | |
| 401 input[1].ki.dwFlags = KEYEVENTF_KEYUP; | |
| 402 if (!!(states | protocol::KeyEvent::LOCK_STATES_CAPSLOCK) != | |
| 403 !!(GetKeyState(VK_CAPITAL) & 1)) { | |
| 404 input[0].ki.wVk = VK_CAPITAL; | |
| 405 input[1].ki.wVk = VK_CAPITAL; | |
| 406 SendInput(arraysize(input), input, sizeof(INPUT)); | |
| 407 } | |
| 408 if (!!(states | protocol::KeyEvent::LOCK_STATES_NUMLOCK) != | |
| 409 !!(GetKeyState(VK_NUMLOCK) & 1)) { | |
| 410 input[0].ki.wVk = VK_NUMLOCK; | |
| 411 input[1].ki.wVk = VK_NUMLOCK; | |
| 412 SendInput(arraysize(input), input, sizeof(INPUT)); | |
| 413 } | |
| 414 } | |
|
rkjnsn
2017/04/26 23:12:21
This builds, but I'm not able to test it, as I don
| |
| 415 | |
| 387 } // namespace | 416 } // namespace |
| 388 | 417 |
| 389 // static | 418 // static |
| 390 std::unique_ptr<InputInjector> InputInjector::Create( | 419 std::unique_ptr<InputInjector> InputInjector::Create( |
| 391 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 420 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 392 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 421 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
| 393 return base::WrapUnique( | 422 return base::WrapUnique( |
| 394 new InputInjectorWin(main_task_runner, ui_task_runner)); | 423 new InputInjectorWin(main_task_runner, ui_task_runner)); |
| 395 } | 424 } |
| 396 | 425 |
| 397 // static | 426 // static |
| 398 bool InputInjector::SupportsTouchEvents() { | 427 bool InputInjector::SupportsTouchEvents() { |
| 399 return base::win::GetVersion() >= base::win::VERSION_WIN8; | 428 return base::win::GetVersion() >= base::win::VERSION_WIN8; |
| 400 } | 429 } |
| 401 | 430 |
| 402 } // namespace remoting | 431 } // namespace remoting |
| OLD | NEW |