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 <ApplicationServices/ApplicationServices.h> | 7 #include <ApplicationServices/ApplicationServices.h> |
8 #include <Carbon/Carbon.h> | 8 #include <Carbon/Carbon.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/mac/scoped_cftyperef.h" | 12 #include "base/mac/scoped_cftyperef.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "remoting/host/capturer.h" | 14 #include "remoting/host/capturer.h" |
15 #include "remoting/proto/internal.pb.h" | 15 #include "remoting/proto/internal.pb.h" |
16 #include "remoting/protocol/message_decoder.h" | 16 #include "remoting/protocol/message_decoder.h" |
17 | 17 |
18 namespace remoting { | 18 namespace remoting { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // USB to Mac keycode mapping table. | 22 // USB to Mac keycode mapping table. |
23 #define USB_KEYMAP(usb, xkb, win, mac) {usb, mac} | 23 #define USB_KEYMAP(usb, xkb, win, mac) {usb, mac} |
24 #include "remoting/host/usb_keycode_map.h" | 24 #include "remoting/host/usb_keycode_map.h" |
25 #define INVALID_KEYCODE 0xffff | 25 #define INVALID_KEYCODE 0xffff |
26 | 26 |
| 27 using protocol::ClipboardEvent; |
| 28 using protocol::KeyEvent; |
27 using protocol::MouseEvent; | 29 using protocol::MouseEvent; |
28 using protocol::KeyEvent; | |
29 | 30 |
30 // A class to generate events on Mac. | 31 // A class to generate events on Mac. |
31 class EventExecutorMac : public EventExecutor { | 32 class EventExecutorMac : public EventExecutor { |
32 public: | 33 public: |
33 EventExecutorMac(MessageLoop* message_loop, Capturer* capturer); | 34 EventExecutorMac(MessageLoop* message_loop, Capturer* capturer); |
34 virtual ~EventExecutorMac() {} | 35 virtual ~EventExecutorMac() {} |
35 | 36 |
| 37 // ClipboardStub interface. |
| 38 virtual void InjectClipboardEvent(const ClipboardEvent& event) OVERRIDE; |
| 39 |
| 40 // InputStub interface. |
36 virtual void InjectKeyEvent(const KeyEvent& event) OVERRIDE; | 41 virtual void InjectKeyEvent(const KeyEvent& event) OVERRIDE; |
37 virtual void InjectMouseEvent(const MouseEvent& event) OVERRIDE; | 42 virtual void InjectMouseEvent(const MouseEvent& event) OVERRIDE; |
38 | 43 |
39 private: | 44 private: |
40 MessageLoop* message_loop_; | 45 MessageLoop* message_loop_; |
41 Capturer* capturer_; | 46 Capturer* capturer_; |
42 int last_x_, last_y_; | 47 int last_x_, last_y_; |
43 int mouse_buttons_; | 48 int mouse_buttons_; |
44 | 49 |
45 DISALLOW_COPY_AND_ASSIGN(EventExecutorMac); | 50 DISALLOW_COPY_AND_ASSIGN(EventExecutorMac); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 return INVALID_KEYCODE; | 243 return INVALID_KEYCODE; |
239 | 244 |
240 for (uint i = 0; i < arraysize(usb_keycode_map); i++) { | 245 for (uint i = 0; i < arraysize(usb_keycode_map); i++) { |
241 if (usb_keycode_map[i].usb_keycode == usb_keycode) | 246 if (usb_keycode_map[i].usb_keycode == usb_keycode) |
242 return usb_keycode_map[i].native_keycode; | 247 return usb_keycode_map[i].native_keycode; |
243 } | 248 } |
244 | 249 |
245 return INVALID_KEYCODE; | 250 return INVALID_KEYCODE; |
246 } | 251 } |
247 | 252 |
| 253 void EventExecutorMac::InjectClipboardEvent(const ClipboardEvent& event) { |
| 254 // TODO(simonmorris): Implement clipboard injection. |
| 255 } |
| 256 |
248 void EventExecutorMac::InjectKeyEvent(const KeyEvent& event) { | 257 void EventExecutorMac::InjectKeyEvent(const KeyEvent& event) { |
249 int keycode = 0; | 258 int keycode = 0; |
250 if (event.has_usb_keycode() && event.usb_keycode() != INVALID_KEYCODE) { | 259 if (event.has_usb_keycode() && event.usb_keycode() != INVALID_KEYCODE) { |
251 keycode = UsbKeycodeToMacKeycode(event.usb_keycode()); | 260 keycode = UsbKeycodeToMacKeycode(event.usb_keycode()); |
252 VLOG(1) << "USB keycode: " << std::hex << event.usb_keycode() | 261 VLOG(1) << "USB keycode: " << std::hex << event.usb_keycode() |
253 << " to Mac keycode: " << keycode << std::dec; | 262 << " to Mac keycode: " << keycode << std::dec; |
254 } else { | 263 } else { |
255 int win_keycode = event.keycode(); | 264 int win_keycode = event.keycode(); |
256 if (win_keycode >= 0 && win_keycode < 256) { | 265 if (win_keycode >= 0 && win_keycode < 256) { |
257 keycode = kUsVkeyToKeysym[win_keycode]; | 266 keycode = kUsVkeyToKeysym[win_keycode]; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 // Note that |dy| (the vertical wheel) is the primary wheel. | 333 // Note that |dy| (the vertical wheel) is the primary wheel. |
325 error = CGPostScrollWheelEvent(2, dy, dx); | 334 error = CGPostScrollWheelEvent(2, dy, dx); |
326 if (error != kCGErrorSuccess) { | 335 if (error != kCGErrorSuccess) { |
327 LOG(WARNING) << "CGPostScrollWheelEvent error " << error; | 336 LOG(WARNING) << "CGPostScrollWheelEvent error " << error; |
328 } | 337 } |
329 } | 338 } |
330 } | 339 } |
331 | 340 |
332 } // namespace | 341 } // namespace |
333 | 342 |
334 scoped_ptr<protocol::InputStub> EventExecutor::Create(MessageLoop* message_loop, | 343 scoped_ptr<protocol::HostEventStub> EventExecutor::Create( |
335 Capturer* capturer) { | 344 MessageLoop* message_loop, Capturer* capturer) { |
336 return scoped_ptr<protocol::InputStub>( | 345 return scoped_ptr<protocol::HostEventStub>( |
337 new EventExecutorMac(message_loop, capturer)); | 346 new EventExecutorMac(message_loop, capturer)); |
338 } | 347 } |
339 | 348 |
340 } // namespace remoting | 349 } // namespace remoting |
OLD | NEW |