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/event_executor.h" | 5 #include "remoting/host/event_executor.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/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "remoting/host/video_frame_capturer.h" | |
14 #include "remoting/host/clipboard.h" | 13 #include "remoting/host/clipboard.h" |
15 #include "remoting/proto/event.pb.h" | 14 #include "remoting/proto/event.pb.h" |
| 15 // SkSize.h assumes that stdint.h-style types are already defined. |
| 16 #include "third_party/skia/include/core/SkTypes.h" |
| 17 #include "third_party/skia/include/core/SkSize.h" |
16 | 18 |
17 namespace remoting { | 19 namespace remoting { |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 using protocol::ClipboardEvent; | 23 using protocol::ClipboardEvent; |
22 using protocol::KeyEvent; | 24 using protocol::KeyEvent; |
23 using protocol::MouseEvent; | 25 using protocol::MouseEvent; |
24 | 26 |
25 // USB to XKB keycode map table. | 27 // USB to XKB keycode map table. |
26 #define USB_KEYMAP(usb, xkb, win, mac) {usb, win} | 28 #define USB_KEYMAP(usb, xkb, win, mac) {usb, win} |
27 #include "ui/base/keycodes/usb_keycode_map.h" | 29 #include "ui/base/keycodes/usb_keycode_map.h" |
28 #undef USB_KEYMAP | 30 #undef USB_KEYMAP |
29 | 31 |
30 // A class to generate events on Windows. | 32 // A class to generate events on Windows. |
31 class EventExecutorWin : public EventExecutor { | 33 class EventExecutorWin : public EventExecutor { |
32 public: | 34 public: |
33 EventExecutorWin(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 35 EventExecutorWin(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
34 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 36 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); |
35 VideoFrameCapturer* capturer); | |
36 virtual ~EventExecutorWin() {} | 37 virtual ~EventExecutorWin() {} |
37 | 38 |
38 // ClipboardStub interface. | 39 // ClipboardStub interface. |
39 virtual void InjectClipboardEvent(const ClipboardEvent& event) OVERRIDE; | 40 virtual void InjectClipboardEvent(const ClipboardEvent& event) OVERRIDE; |
40 | 41 |
41 // InputStub interface. | 42 // InputStub interface. |
42 virtual void InjectKeyEvent(const KeyEvent& event) OVERRIDE; | 43 virtual void InjectKeyEvent(const KeyEvent& event) OVERRIDE; |
43 virtual void InjectMouseEvent(const MouseEvent& event) OVERRIDE; | 44 virtual void InjectMouseEvent(const MouseEvent& event) OVERRIDE; |
44 | 45 |
45 // EventExecutor interface. | 46 // EventExecutor interface. |
46 virtual void OnSessionStarted( | 47 virtual void OnSessionStarted( |
47 scoped_ptr<protocol::ClipboardStub> client_clipboard) OVERRIDE; | 48 scoped_ptr<protocol::ClipboardStub> client_clipboard) OVERRIDE; |
48 virtual void OnSessionFinished() OVERRIDE; | 49 virtual void OnSessionFinished() OVERRIDE; |
49 | 50 |
50 private: | 51 private: |
51 HKL GetForegroundKeyboardLayout(); | 52 HKL GetForegroundKeyboardLayout(); |
52 void HandleKey(const KeyEvent& event); | 53 void HandleKey(const KeyEvent& event); |
53 void HandleMouse(const MouseEvent& event); | 54 void HandleMouse(const MouseEvent& event); |
54 | 55 |
55 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 56 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
56 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 57 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
57 VideoFrameCapturer* capturer_; | |
58 scoped_ptr<Clipboard> clipboard_; | 58 scoped_ptr<Clipboard> clipboard_; |
59 | 59 |
60 DISALLOW_COPY_AND_ASSIGN(EventExecutorWin); | 60 DISALLOW_COPY_AND_ASSIGN(EventExecutorWin); |
61 }; | 61 }; |
62 | 62 |
63 EventExecutorWin::EventExecutorWin( | 63 EventExecutorWin::EventExecutorWin( |
64 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 64 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
65 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 65 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) |
66 VideoFrameCapturer* capturer) | |
67 : main_task_runner_(main_task_runner), | 66 : main_task_runner_(main_task_runner), |
68 ui_task_runner_(ui_task_runner), | 67 ui_task_runner_(ui_task_runner), |
69 capturer_(capturer), | |
70 clipboard_(Clipboard::Create()) { | 68 clipboard_(Clipboard::Create()) { |
71 } | 69 } |
72 | 70 |
73 void EventExecutorWin::InjectClipboardEvent(const ClipboardEvent& event) { | 71 void EventExecutorWin::InjectClipboardEvent(const ClipboardEvent& event) { |
74 if (!ui_task_runner_->BelongsToCurrentThread()) { | 72 if (!ui_task_runner_->BelongsToCurrentThread()) { |
75 ui_task_runner_->PostTask( | 73 ui_task_runner_->PostTask( |
76 FROM_HERE, | 74 FROM_HERE, |
77 base::Bind(&EventExecutorWin::InjectClipboardEvent, | 75 base::Bind(&EventExecutorWin::InjectClipboardEvent, |
78 base::Unretained(this), | 76 base::Unretained(this), |
79 event)); | 77 event)); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 212 |
215 // TODO(garykac) Collapse mouse (x,y) and button events into a single | 213 // TODO(garykac) Collapse mouse (x,y) and button events into a single |
216 // input event when possible. | 214 // input event when possible. |
217 if (event.has_x() && event.has_y()) { | 215 if (event.has_x() && event.has_y()) { |
218 int x = event.x(); | 216 int x = event.x(); |
219 int y = event.y(); | 217 int y = event.y(); |
220 | 218 |
221 INPUT input; | 219 INPUT input; |
222 input.type = INPUT_MOUSE; | 220 input.type = INPUT_MOUSE; |
223 input.mi.time = 0; | 221 input.mi.time = 0; |
224 SkISize screen_size = capturer_->size_most_recent(); | 222 SkISize screen_size(SkISize::Make(GetSystemMetrics(SM_CXVIRTUALSCREEN), |
| 223 GetSystemMetrics(SM_CYVIRTUALSCREEN))); |
225 if ((screen_size.width() > 1) && (screen_size.height() > 1)) { | 224 if ((screen_size.width() > 1) && (screen_size.height() > 1)) { |
| 225 x = std::max(0, std::min(screen_size.width(), x)); |
| 226 y = std::max(0, std::min(screen_size.height(), y)); |
226 input.mi.dx = static_cast<int>((x * 65535) / (screen_size.width() - 1)); | 227 input.mi.dx = static_cast<int>((x * 65535) / (screen_size.width() - 1)); |
227 input.mi.dy = static_cast<int>((y * 65535) / (screen_size.height() - 1)); | 228 input.mi.dy = static_cast<int>((y * 65535) / (screen_size.height() - 1)); |
228 input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE; | 229 input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE; |
229 if (SendInput(1, &input, sizeof(INPUT)) == 0) { | 230 if (SendInput(1, &input, sizeof(INPUT)) == 0) { |
230 LOG_GETLASTERROR(ERROR) << "Failed to inject a mouse move event"; | 231 LOG_GETLASTERROR(ERROR) << "Failed to inject a mouse move event"; |
231 } | 232 } |
232 } | 233 } |
233 } | 234 } |
234 | 235 |
235 if (event.has_wheel_offset_x() && event.has_wheel_offset_y()) { | 236 if (event.has_wheel_offset_x() && event.has_wheel_offset_y()) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 if (SendInput(1, &button_event, sizeof(INPUT)) == 0) { | 283 if (SendInput(1, &button_event, sizeof(INPUT)) == 0) { |
283 LOG_GETLASTERROR(ERROR) << "Failed to inject a mouse button event"; | 284 LOG_GETLASTERROR(ERROR) << "Failed to inject a mouse button event"; |
284 } | 285 } |
285 } | 286 } |
286 } | 287 } |
287 | 288 |
288 } // namespace | 289 } // namespace |
289 | 290 |
290 scoped_ptr<EventExecutor> EventExecutor::Create( | 291 scoped_ptr<EventExecutor> EventExecutor::Create( |
291 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 292 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
292 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 293 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
293 VideoFrameCapturer* capturer) { | |
294 return scoped_ptr<EventExecutor>( | 294 return scoped_ptr<EventExecutor>( |
295 new EventExecutorWin(main_task_runner, ui_task_runner, capturer)); | 295 new EventExecutorWin(main_task_runner, ui_task_runner)); |
296 } | 296 } |
297 | 297 |
298 } // namespace remoting | 298 } // namespace remoting |
OLD | NEW |