| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" |
| 16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 18 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 20 #include "remoting/base/util.h" | 21 #include "remoting/base/util.h" |
| 21 #include "remoting/host/clipboard.h" | 22 #include "remoting/host/clipboard.h" |
| 22 #include "remoting/host/touch_injector_win.h" | 23 #include "remoting/host/touch_injector_win.h" |
| 23 #include "remoting/proto/event.pb.h" | 24 #include "remoting/proto/event.pb.h" |
| 24 #include "ui/events/keycodes/dom/keycode_converter.h" | 25 #include "ui/events/keycodes/dom/keycode_converter.h" |
| 25 | 26 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 void InjectClipboardEvent(const ClipboardEvent& event) override; | 70 void InjectClipboardEvent(const ClipboardEvent& event) override; |
| 70 | 71 |
| 71 // InputStub interface. | 72 // InputStub interface. |
| 72 void InjectKeyEvent(const KeyEvent& event) override; | 73 void InjectKeyEvent(const KeyEvent& event) override; |
| 73 void InjectTextEvent(const TextEvent& event) override; | 74 void InjectTextEvent(const TextEvent& event) override; |
| 74 void InjectMouseEvent(const MouseEvent& event) override; | 75 void InjectMouseEvent(const MouseEvent& event) override; |
| 75 void InjectTouchEvent(const TouchEvent& event) override; | 76 void InjectTouchEvent(const TouchEvent& event) override; |
| 76 | 77 |
| 77 // InputInjector interface. | 78 // InputInjector interface. |
| 78 void Start( | 79 void Start( |
| 79 scoped_ptr<protocol::ClipboardStub> client_clipboard) override; | 80 std::unique_ptr<protocol::ClipboardStub> client_clipboard) override; |
| 80 | 81 |
| 81 private: | 82 private: |
| 82 // The actual implementation resides in InputInjectorWin::Core class. | 83 // The actual implementation resides in InputInjectorWin::Core class. |
| 83 class Core : public base::RefCountedThreadSafe<Core> { | 84 class Core : public base::RefCountedThreadSafe<Core> { |
| 84 public: | 85 public: |
| 85 Core(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 86 Core(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 86 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); | 87 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); |
| 87 | 88 |
| 88 // Mirrors the ClipboardStub interface. | 89 // Mirrors the ClipboardStub interface. |
| 89 void InjectClipboardEvent(const ClipboardEvent& event); | 90 void InjectClipboardEvent(const ClipboardEvent& event); |
| 90 | 91 |
| 91 // Mirrors the InputStub interface. | 92 // Mirrors the InputStub interface. |
| 92 void InjectKeyEvent(const KeyEvent& event); | 93 void InjectKeyEvent(const KeyEvent& event); |
| 93 void InjectTextEvent(const TextEvent& event); | 94 void InjectTextEvent(const TextEvent& event); |
| 94 void InjectMouseEvent(const MouseEvent& event); | 95 void InjectMouseEvent(const MouseEvent& event); |
| 95 void InjectTouchEvent(const TouchEvent& event); | 96 void InjectTouchEvent(const TouchEvent& event); |
| 96 | 97 |
| 97 // Mirrors the InputInjector interface. | 98 // Mirrors the InputInjector interface. |
| 98 void Start(scoped_ptr<protocol::ClipboardStub> client_clipboard); | 99 void Start(std::unique_ptr<protocol::ClipboardStub> client_clipboard); |
| 99 | 100 |
| 100 void Stop(); | 101 void Stop(); |
| 101 | 102 |
| 102 private: | 103 private: |
| 103 friend class base::RefCountedThreadSafe<Core>; | 104 friend class base::RefCountedThreadSafe<Core>; |
| 104 virtual ~Core(); | 105 virtual ~Core(); |
| 105 | 106 |
| 106 void HandleKey(const KeyEvent& event); | 107 void HandleKey(const KeyEvent& event); |
| 107 void HandleText(const TextEvent& event); | 108 void HandleText(const TextEvent& event); |
| 108 void HandleMouse(const MouseEvent& event); | 109 void HandleMouse(const MouseEvent& event); |
| 109 void HandleTouch(const TouchEvent& event); | 110 void HandleTouch(const TouchEvent& event); |
| 110 | 111 |
| 111 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 112 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 112 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 113 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 113 scoped_ptr<Clipboard> clipboard_; | 114 std::unique_ptr<Clipboard> clipboard_; |
| 114 TouchInjectorWin touch_injector_; | 115 TouchInjectorWin touch_injector_; |
| 115 | 116 |
| 116 DISALLOW_COPY_AND_ASSIGN(Core); | 117 DISALLOW_COPY_AND_ASSIGN(Core); |
| 117 }; | 118 }; |
| 118 | 119 |
| 119 scoped_refptr<Core> core_; | 120 scoped_refptr<Core> core_; |
| 120 | 121 |
| 121 DISALLOW_COPY_AND_ASSIGN(InputInjectorWin); | 122 DISALLOW_COPY_AND_ASSIGN(InputInjectorWin); |
| 122 }; | 123 }; |
| 123 | 124 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 145 | 146 |
| 146 void InputInjectorWin::InjectMouseEvent(const MouseEvent& event) { | 147 void InputInjectorWin::InjectMouseEvent(const MouseEvent& event) { |
| 147 core_->InjectMouseEvent(event); | 148 core_->InjectMouseEvent(event); |
| 148 } | 149 } |
| 149 | 150 |
| 150 void InputInjectorWin::InjectTouchEvent(const TouchEvent& event) { | 151 void InputInjectorWin::InjectTouchEvent(const TouchEvent& event) { |
| 151 core_->InjectTouchEvent(event); | 152 core_->InjectTouchEvent(event); |
| 152 } | 153 } |
| 153 | 154 |
| 154 void InputInjectorWin::Start( | 155 void InputInjectorWin::Start( |
| 155 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 156 std::unique_ptr<protocol::ClipboardStub> client_clipboard) { |
| 156 core_->Start(std::move(client_clipboard)); | 157 core_->Start(std::move(client_clipboard)); |
| 157 } | 158 } |
| 158 | 159 |
| 159 InputInjectorWin::Core::Core( | 160 InputInjectorWin::Core::Core( |
| 160 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 161 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 161 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) | 162 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) |
| 162 : main_task_runner_(main_task_runner), | 163 : main_task_runner_(main_task_runner), |
| 163 ui_task_runner_(ui_task_runner), | 164 ui_task_runner_(ui_task_runner), |
| 164 clipboard_(Clipboard::Create()) { | 165 clipboard_(Clipboard::Create()) { |
| 165 } | 166 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 if (!main_task_runner_->BelongsToCurrentThread()) { | 210 if (!main_task_runner_->BelongsToCurrentThread()) { |
| 210 main_task_runner_->PostTask( | 211 main_task_runner_->PostTask( |
| 211 FROM_HERE, base::Bind(&Core::InjectTouchEvent, this, event)); | 212 FROM_HERE, base::Bind(&Core::InjectTouchEvent, this, event)); |
| 212 return; | 213 return; |
| 213 } | 214 } |
| 214 | 215 |
| 215 HandleTouch(event); | 216 HandleTouch(event); |
| 216 } | 217 } |
| 217 | 218 |
| 218 void InputInjectorWin::Core::Start( | 219 void InputInjectorWin::Core::Start( |
| 219 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 220 std::unique_ptr<protocol::ClipboardStub> client_clipboard) { |
| 220 if (!ui_task_runner_->BelongsToCurrentThread()) { | 221 if (!ui_task_runner_->BelongsToCurrentThread()) { |
| 221 ui_task_runner_->PostTask( | 222 ui_task_runner_->PostTask( |
| 222 FROM_HERE, | 223 FROM_HERE, |
| 223 base::Bind(&Core::Start, this, base::Passed(&client_clipboard))); | 224 base::Bind(&Core::Start, this, base::Passed(&client_clipboard))); |
| 224 return; | 225 return; |
| 225 } | 226 } |
| 226 | 227 |
| 227 clipboard_->Start(std::move(client_clipboard)); | 228 clipboard_->Start(std::move(client_clipboard)); |
| 228 touch_injector_.Init(); | 229 touch_injector_.Init(); |
| 229 } | 230 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 } | 347 } |
| 347 } | 348 } |
| 348 | 349 |
| 349 void InputInjectorWin::Core::HandleTouch(const TouchEvent& event) { | 350 void InputInjectorWin::Core::HandleTouch(const TouchEvent& event) { |
| 350 touch_injector_.InjectTouchEvent(event); | 351 touch_injector_.InjectTouchEvent(event); |
| 351 } | 352 } |
| 352 | 353 |
| 353 } // namespace | 354 } // namespace |
| 354 | 355 |
| 355 // static | 356 // static |
| 356 scoped_ptr<InputInjector> InputInjector::Create( | 357 std::unique_ptr<InputInjector> InputInjector::Create( |
| 357 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 358 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 358 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 359 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
| 359 return make_scoped_ptr( | 360 return base::WrapUnique( |
| 360 new InputInjectorWin(main_task_runner, ui_task_runner)); | 361 new InputInjectorWin(main_task_runner, ui_task_runner)); |
| 361 } | 362 } |
| 362 | 363 |
| 363 // static | 364 // static |
| 364 bool InputInjector::SupportsTouchEvents() { | 365 bool InputInjector::SupportsTouchEvents() { |
| 365 return TouchInjectorWinDelegate::Create() != nullptr; | 366 return TouchInjectorWinDelegate::Create() != nullptr; |
| 366 } | 367 } |
| 367 | 368 |
| 368 } // namespace remoting | 369 } // namespace remoting |
| OLD | NEW |