| 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/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "remoting/host/capturer.h" | 12 #include "remoting/host/capturer.h" |
| 13 #include "remoting/proto/event.pb.h" | 13 #include "remoting/proto/event.pb.h" |
| 14 #include "ui/base/keycodes/keyboard_codes.h" | 14 #include "ui/base/keycodes/keyboard_codes.h" |
| 15 | 15 |
| 16 namespace remoting { | 16 namespace remoting { |
| 17 | 17 |
| 18 using protocol::ClipboardEvent; |
| 19 using protocol::KeyEvent; |
| 18 using protocol::MouseEvent; | 20 using protocol::MouseEvent; |
| 19 using protocol::KeyEvent; | |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // USB to XKB keycode map table. | 24 // USB to XKB keycode map table. |
| 24 #define USB_KEYMAP(usb, xkb, win, mac) {usb, win} | 25 #define USB_KEYMAP(usb, xkb, win, mac) {usb, win} |
| 25 #define INVALID_KEYCODE 0x0000 | 26 #define INVALID_KEYCODE 0x0000 |
| 26 #include "remoting/host/usb_keycode_map.h" | 27 #include "remoting/host/usb_keycode_map.h" |
| 27 #undef USB_KEYMAP | 28 #undef USB_KEYMAP |
| 28 | 29 |
| 29 // A class to generate events on Windows. | 30 // A class to generate events on Windows. |
| 30 class EventExecutorWin : public EventExecutor { | 31 class EventExecutorWin : public EventExecutor { |
| 31 public: | 32 public: |
| 32 EventExecutorWin(MessageLoop* message_loop, Capturer* capturer); | 33 EventExecutorWin(MessageLoop* message_loop, Capturer* capturer); |
| 33 virtual ~EventExecutorWin() {} | 34 virtual ~EventExecutorWin() {} |
| 34 | 35 |
| 36 // ClipboardStub interface. |
| 37 virtual void InjectClipboardEvent(const ClipboardEvent& event) OVERRIDE; |
| 38 |
| 39 // InputStub interface. |
| 35 virtual void InjectKeyEvent(const KeyEvent& event) OVERRIDE; | 40 virtual void InjectKeyEvent(const KeyEvent& event) OVERRIDE; |
| 36 virtual void InjectMouseEvent(const MouseEvent& event) OVERRIDE; | 41 virtual void InjectMouseEvent(const MouseEvent& event) OVERRIDE; |
| 37 | 42 |
| 38 private: | 43 private: |
| 39 void HandleKey(const KeyEvent& event); | 44 void HandleKey(const KeyEvent& event); |
| 40 void HandleMouse(const MouseEvent& event); | 45 void HandleMouse(const MouseEvent& event); |
| 41 | 46 |
| 42 MessageLoop* message_loop_; | 47 MessageLoop* message_loop_; |
| 43 Capturer* capturer_; | 48 Capturer* capturer_; |
| 44 | 49 |
| 45 DISALLOW_COPY_AND_ASSIGN(EventExecutorWin); | 50 DISALLOW_COPY_AND_ASSIGN(EventExecutorWin); |
| 46 }; | 51 }; |
| 47 | 52 |
| 48 EventExecutorWin::EventExecutorWin(MessageLoop* message_loop, | 53 EventExecutorWin::EventExecutorWin(MessageLoop* message_loop, |
| 49 Capturer* capturer) | 54 Capturer* capturer) |
| 50 : message_loop_(message_loop), | 55 : message_loop_(message_loop), |
| 51 capturer_(capturer) { | 56 capturer_(capturer) { |
| 52 } | 57 } |
| 53 | 58 |
| 59 void EventExecutorWin::InjectClipboardEvent(const ClipboardEvent& event) { |
| 60 // TODO(simonmorris): Implement clipboard injection. |
| 61 } |
| 62 |
| 54 void EventExecutorWin::InjectKeyEvent(const KeyEvent& event) { | 63 void EventExecutorWin::InjectKeyEvent(const KeyEvent& event) { |
| 55 if (MessageLoop::current() != message_loop_) { | 64 if (MessageLoop::current() != message_loop_) { |
| 56 message_loop_->PostTask( | 65 message_loop_->PostTask( |
| 57 FROM_HERE, | 66 FROM_HERE, |
| 58 base::Bind(&EventExecutorWin::InjectKeyEvent, base::Unretained(this), | 67 base::Bind(&EventExecutorWin::InjectKeyEvent, base::Unretained(this), |
| 59 event)); | 68 event)); |
| 60 return; | 69 return; |
| 61 } | 70 } |
| 62 | 71 |
| 63 HandleKey(event); | 72 HandleKey(event); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 button_event.mi.dwFlags = | 196 button_event.mi.dwFlags = |
| 188 down ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP; | 197 down ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP; |
| 189 } | 198 } |
| 190 | 199 |
| 191 SendInput(1, &button_event, sizeof(INPUT)); | 200 SendInput(1, &button_event, sizeof(INPUT)); |
| 192 } | 201 } |
| 193 } | 202 } |
| 194 | 203 |
| 195 } // namespace | 204 } // namespace |
| 196 | 205 |
| 197 scoped_ptr<protocol::InputStub> EventExecutor::Create(MessageLoop* message_loop, | 206 scoped_ptr<protocol::HostEventStub> EventExecutor::Create( |
| 198 Capturer* capturer) { | 207 MessageLoop* message_loop, Capturer* capturer) { |
| 199 return scoped_ptr<protocol::InputStub>( | 208 return scoped_ptr<protocol::HostEventStub>( |
| 200 new EventExecutorWin(message_loop, capturer)); | 209 new EventExecutorWin(message_loop, capturer)); |
| 201 } | 210 } |
| 202 | 211 |
| 203 } // namespace remoting | 212 } // namespace remoting |
| OLD | NEW |