OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_win.h" | 5 #include "remoting/host/event_executor.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
| 9 #include "base/compiler_specific.h" |
9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
10 #include "base/stl_util-inl.h" | |
11 #include "remoting/host/capturer.h" | 11 #include "remoting/host/capturer.h" |
12 #include "remoting/proto/event.pb.h" | 12 #include "remoting/proto/event.pb.h" |
13 #include "ui/base/keycodes/keyboard_codes.h" | 13 #include "ui/base/keycodes/keyboard_codes.h" |
14 | 14 |
15 namespace remoting { | 15 namespace remoting { |
16 | 16 |
17 using protocol::MouseEvent; | 17 using protocol::MouseEvent; |
18 using protocol::KeyEvent; | 18 using protocol::KeyEvent; |
19 | 19 |
20 EventExecutorWin::EventExecutorWin( | 20 namespace { |
21 MessageLoopForUI* message_loop, Capturer* capturer) | 21 |
| 22 // A class to generate events on Windows. |
| 23 class EventExecutorWin : public EventExecutor { |
| 24 public: |
| 25 EventExecutorWin(MessageLoopForUI* message_loop, Capturer* capturer); |
| 26 virtual ~EventExecutorWin() {} |
| 27 |
| 28 virtual void InjectKeyEvent(const KeyEvent* event, Task* done) OVERRIDE; |
| 29 virtual void InjectMouseEvent(const MouseEvent* event, Task* done) OVERRIDE; |
| 30 |
| 31 private: |
| 32 void HandleKey(const KeyEvent* event); |
| 33 void HandleMouse(const MouseEvent* event); |
| 34 |
| 35 MessageLoopForUI* message_loop_; |
| 36 Capturer* capturer_; |
| 37 |
| 38 DISALLOW_COPY_AND_ASSIGN(EventExecutorWin); |
| 39 }; |
| 40 |
| 41 EventExecutorWin::EventExecutorWin(MessageLoopForUI* message_loop, |
| 42 Capturer* capturer) |
22 : message_loop_(message_loop), | 43 : message_loop_(message_loop), |
23 capturer_(capturer) { | 44 capturer_(capturer) { |
24 } | 45 } |
25 | 46 |
26 EventExecutorWin::~EventExecutorWin() { | |
27 } | |
28 | |
29 void EventExecutorWin::InjectKeyEvent(const KeyEvent* event, Task* done) { | 47 void EventExecutorWin::InjectKeyEvent(const KeyEvent* event, Task* done) { |
30 if (MessageLoop::current() != message_loop_) { | 48 if (MessageLoop::current() != message_loop_) { |
31 message_loop_->PostTask( | 49 message_loop_->PostTask( |
32 FROM_HERE, | 50 FROM_HERE, |
33 NewRunnableMethod(this, &EventExecutorWin::InjectKeyEvent, | 51 NewRunnableMethod(this, &EventExecutorWin::InjectKeyEvent, |
34 event, done)); | 52 event, done)); |
35 return; | 53 return; |
36 } | 54 } |
37 HandleKey(event); | 55 HandleKey(event); |
38 done->Run(); | 56 done->Run(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 93 } |
76 | 94 |
77 // Flag to mark keyup events. Default is keydown. | 95 // Flag to mark keyup events. Default is keydown. |
78 if (!down) { | 96 if (!down) { |
79 input.ki.dwFlags |= KEYEVENTF_KEYUP; | 97 input.ki.dwFlags |= KEYEVENTF_KEYUP; |
80 } | 98 } |
81 | 99 |
82 SendInput(1, &input, sizeof(INPUT)); | 100 SendInput(1, &input, sizeof(INPUT)); |
83 } | 101 } |
84 | 102 |
85 protocol::InputStub* CreateEventExecutor(MessageLoopForUI* message_loop, | |
86 Capturer* capturer) { | |
87 return new EventExecutorWin(message_loop, capturer); | |
88 } | |
89 | |
90 void EventExecutorWin::HandleMouse(const MouseEvent* event) { | 103 void EventExecutorWin::HandleMouse(const MouseEvent* event) { |
91 // TODO(garykac) Collapse mouse (x,y) and button events into a single | 104 // TODO(garykac) Collapse mouse (x,y) and button events into a single |
92 // input event when possible. | 105 // input event when possible. |
93 if (event->has_x() && event->has_y()) { | 106 if (event->has_x() && event->has_y()) { |
94 int x = event->x(); | 107 int x = event->x(); |
95 int y = event->y(); | 108 int y = event->y(); |
96 | 109 |
97 INPUT input; | 110 INPUT input; |
98 input.type = INPUT_MOUSE; | 111 input.type = INPUT_MOUSE; |
99 input.mi.time = 0; | 112 input.mi.time = 0; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 down ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP; | 159 down ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP; |
147 } else { | 160 } else { |
148 button_event.mi.dwFlags = | 161 button_event.mi.dwFlags = |
149 down ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP; | 162 down ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP; |
150 } | 163 } |
151 | 164 |
152 SendInput(1, &button_event, sizeof(INPUT)); | 165 SendInput(1, &button_event, sizeof(INPUT)); |
153 } | 166 } |
154 } | 167 } |
155 | 168 |
| 169 } // namespace |
| 170 |
| 171 EventExecutor* EventExecutor::Create(MessageLoopForUI* message_loop, |
| 172 Capturer* capturer) { |
| 173 return new EventExecutorWin(message_loop, capturer); |
| 174 } |
| 175 |
156 } // namespace remoting | 176 } // namespace remoting |
| 177 |
| 178 DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::EventExecutorWin); |
| 179 |
OLD | NEW |