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 <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "remoting/base/util.h" | 16 #include "remoting/base/util.h" |
17 #include "remoting/host/clipboard.h" | 17 #include "remoting/host/clipboard.h" |
| 18 #include "remoting/host/touch_injector_win.h" |
18 #include "remoting/proto/event.pb.h" | 19 #include "remoting/proto/event.pb.h" |
19 #include "ui/events/keycodes/dom4/keycode_converter.h" | 20 #include "ui/events/keycodes/dom4/keycode_converter.h" |
20 | 21 |
21 namespace remoting { | 22 namespace remoting { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 // Helper used to call SendInput() API. | 26 // Helper used to call SendInput() API. |
26 void SendKeyboardInput(uint32_t flags, uint16_t scancode) { | 27 void SendKeyboardInput(uint32_t flags, uint16_t scancode) { |
27 // Populate a Windows INPUT structure for the event. | 28 // Populate a Windows INPUT structure for the event. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 Core(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 81 Core(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
81 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); | 82 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); |
82 | 83 |
83 // Mirrors the ClipboardStub interface. | 84 // Mirrors the ClipboardStub interface. |
84 void InjectClipboardEvent(const ClipboardEvent& event); | 85 void InjectClipboardEvent(const ClipboardEvent& event); |
85 | 86 |
86 // Mirrors the InputStub interface. | 87 // Mirrors the InputStub interface. |
87 void InjectKeyEvent(const KeyEvent& event); | 88 void InjectKeyEvent(const KeyEvent& event); |
88 void InjectTextEvent(const TextEvent& event); | 89 void InjectTextEvent(const TextEvent& event); |
89 void InjectMouseEvent(const MouseEvent& event); | 90 void InjectMouseEvent(const MouseEvent& event); |
| 91 void InjectTouchEvent(const TouchEvent& event); |
90 | 92 |
91 // Mirrors the InputInjector interface. | 93 // Mirrors the InputInjector interface. |
92 void Start(scoped_ptr<protocol::ClipboardStub> client_clipboard); | 94 void Start(scoped_ptr<protocol::ClipboardStub> client_clipboard); |
93 | 95 |
94 void Stop(); | 96 void Stop(); |
95 | 97 |
96 private: | 98 private: |
97 friend class base::RefCountedThreadSafe<Core>; | 99 friend class base::RefCountedThreadSafe<Core>; |
98 virtual ~Core(); | 100 virtual ~Core(); |
99 | 101 |
100 void HandleKey(const KeyEvent& event); | 102 void HandleKey(const KeyEvent& event); |
101 void HandleText(const TextEvent& event); | 103 void HandleText(const TextEvent& event); |
102 void HandleMouse(const MouseEvent& event); | 104 void HandleMouse(const MouseEvent& event); |
| 105 void HandleTouch(const TouchEvent& event); |
103 | 106 |
104 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 107 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
105 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 108 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
106 scoped_ptr<Clipboard> clipboard_; | 109 scoped_ptr<Clipboard> clipboard_; |
| 110 TouchInjectorWin touch_injector_; |
107 | 111 |
108 DISALLOW_COPY_AND_ASSIGN(Core); | 112 DISALLOW_COPY_AND_ASSIGN(Core); |
109 }; | 113 }; |
110 | 114 |
111 scoped_refptr<Core> core_; | 115 scoped_refptr<Core> core_; |
112 | 116 |
113 DISALLOW_COPY_AND_ASSIGN(InputInjectorWin); | 117 DISALLOW_COPY_AND_ASSIGN(InputInjectorWin); |
114 }; | 118 }; |
115 | 119 |
116 InputInjectorWin::InputInjectorWin( | 120 InputInjectorWin::InputInjectorWin( |
(...skipping 16 matching lines...) Expand all Loading... |
133 | 137 |
134 void InputInjectorWin::InjectTextEvent(const TextEvent& event) { | 138 void InputInjectorWin::InjectTextEvent(const TextEvent& event) { |
135 core_->InjectTextEvent(event); | 139 core_->InjectTextEvent(event); |
136 } | 140 } |
137 | 141 |
138 void InputInjectorWin::InjectMouseEvent(const MouseEvent& event) { | 142 void InputInjectorWin::InjectMouseEvent(const MouseEvent& event) { |
139 core_->InjectMouseEvent(event); | 143 core_->InjectMouseEvent(event); |
140 } | 144 } |
141 | 145 |
142 void InputInjectorWin::InjectTouchEvent(const TouchEvent& event) { | 146 void InputInjectorWin::InjectTouchEvent(const TouchEvent& event) { |
143 NOTIMPLEMENTED() << "Raw touch event injection not implemented for Windows."; | 147 core_->InjectTouchEvent(event); |
144 } | 148 } |
145 | 149 |
146 void InputInjectorWin::Start( | 150 void InputInjectorWin::Start( |
147 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 151 scoped_ptr<protocol::ClipboardStub> client_clipboard) { |
148 core_->Start(client_clipboard.Pass()); | 152 core_->Start(client_clipboard.Pass()); |
149 } | 153 } |
150 | 154 |
151 InputInjectorWin::Core::Core( | 155 InputInjectorWin::Core::Core( |
152 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 156 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
153 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) | 157 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 void InputInjectorWin::Core::InjectMouseEvent(const MouseEvent& event) { | 194 void InputInjectorWin::Core::InjectMouseEvent(const MouseEvent& event) { |
191 if (!main_task_runner_->BelongsToCurrentThread()) { | 195 if (!main_task_runner_->BelongsToCurrentThread()) { |
192 main_task_runner_->PostTask( | 196 main_task_runner_->PostTask( |
193 FROM_HERE, base::Bind(&Core::InjectMouseEvent, this, event)); | 197 FROM_HERE, base::Bind(&Core::InjectMouseEvent, this, event)); |
194 return; | 198 return; |
195 } | 199 } |
196 | 200 |
197 HandleMouse(event); | 201 HandleMouse(event); |
198 } | 202 } |
199 | 203 |
| 204 void InputInjectorWin::Core::InjectTouchEvent(const TouchEvent& event) { |
| 205 if (!main_task_runner_->BelongsToCurrentThread()) { |
| 206 main_task_runner_->PostTask( |
| 207 FROM_HERE, base::Bind(&Core::InjectTouchEvent, this, event)); |
| 208 return; |
| 209 } |
| 210 |
| 211 HandleTouch(event); |
| 212 } |
| 213 |
200 void InputInjectorWin::Core::Start( | 214 void InputInjectorWin::Core::Start( |
201 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 215 scoped_ptr<protocol::ClipboardStub> client_clipboard) { |
202 if (!ui_task_runner_->BelongsToCurrentThread()) { | 216 if (!ui_task_runner_->BelongsToCurrentThread()) { |
203 ui_task_runner_->PostTask( | 217 ui_task_runner_->PostTask( |
204 FROM_HERE, | 218 FROM_HERE, |
205 base::Bind(&Core::Start, this, base::Passed(&client_clipboard))); | 219 base::Bind(&Core::Start, this, base::Passed(&client_clipboard))); |
206 return; | 220 return; |
207 } | 221 } |
208 | 222 |
209 clipboard_->Start(client_clipboard.Pass()); | 223 clipboard_->Start(client_clipboard.Pass()); |
| 224 touch_injector_.Init(); |
210 } | 225 } |
211 | 226 |
212 void InputInjectorWin::Core::Stop() { | 227 void InputInjectorWin::Core::Stop() { |
213 if (!ui_task_runner_->BelongsToCurrentThread()) { | 228 if (!ui_task_runner_->BelongsToCurrentThread()) { |
214 ui_task_runner_->PostTask(FROM_HERE, base::Bind(&Core::Stop, this)); | 229 ui_task_runner_->PostTask(FROM_HERE, base::Bind(&Core::Stop, this)); |
215 return; | 230 return; |
216 } | 231 } |
217 | 232 |
218 clipboard_.reset(); | 233 clipboard_.reset(); |
| 234 touch_injector_.Deinitialize(); |
219 } | 235 } |
220 | 236 |
221 InputInjectorWin::Core::~Core() {} | 237 InputInjectorWin::Core::~Core() {} |
222 | 238 |
223 void InputInjectorWin::Core::HandleKey(const KeyEvent& event) { | 239 void InputInjectorWin::Core::HandleKey(const KeyEvent& event) { |
224 // HostEventDispatcher should filter events missing the pressed field. | 240 // HostEventDispatcher should filter events missing the pressed field. |
225 DCHECK(event.has_pressed() && event.has_usb_keycode()); | 241 DCHECK(event.has_pressed() && event.has_usb_keycode()); |
226 | 242 |
227 // Reset the system idle suspend timeout. | 243 // Reset the system idle suspend timeout. |
228 SetThreadExecutionState(ES_SYSTEM_REQUIRED); | 244 SetThreadExecutionState(ES_SYSTEM_REQUIRED); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 input.mi.dwFlags |= down ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP; | 335 input.mi.dwFlags |= down ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP; |
320 } | 336 } |
321 } | 337 } |
322 | 338 |
323 if (input.mi.dwFlags) { | 339 if (input.mi.dwFlags) { |
324 if (SendInput(1, &input, sizeof(INPUT)) == 0) | 340 if (SendInput(1, &input, sizeof(INPUT)) == 0) |
325 PLOG(ERROR) << "Failed to inject a mouse event"; | 341 PLOG(ERROR) << "Failed to inject a mouse event"; |
326 } | 342 } |
327 } | 343 } |
328 | 344 |
| 345 void InputInjectorWin::Core::HandleTouch(const TouchEvent& event) { |
| 346 touch_injector_.InjectTouchEvent(event); |
| 347 } |
| 348 |
329 } // namespace | 349 } // namespace |
330 | 350 |
331 scoped_ptr<InputInjector> InputInjector::Create( | 351 scoped_ptr<InputInjector> InputInjector::Create( |
332 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 352 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
333 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 353 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
334 return make_scoped_ptr( | 354 return make_scoped_ptr( |
335 new InputInjectorWin(main_task_runner, ui_task_runner)); | 355 new InputInjectorWin(main_task_runner, ui_task_runner)); |
336 } | 356 } |
337 | 357 |
338 } // namespace remoting | 358 } // namespace remoting |
OLD | NEW |