| 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::KeyEvent; |
| 27 using protocol::MouseEvent; | 28 using protocol::MouseEvent; |
| 28 using protocol::KeyEvent; | |
| 29 | 29 |
| 30 // A class to generate events on Mac. | 30 // A class to generate events on Mac. |
| 31 class EventExecutorMac : public EventExecutor { | 31 class EventExecutorMac : public EventExecutor { |
| 32 public: | 32 public: |
| 33 EventExecutorMac(MessageLoop* message_loop, Capturer* capturer); | 33 EventExecutorMac(MessageLoop* message_loop, Capturer* capturer); |
| 34 virtual ~EventExecutorMac() {} | 34 virtual ~EventExecutorMac() {} |
| 35 | 35 |
| 36 // ClipboardStub interface. |
| 37 virtual void InjectClipboardEvent(const protocol::ClipboardEvent& event) |
| 38 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( |
| 254 const protocol::ClipboardEvent& event) { |
| 255 // TODO(simonmorris): Implement clipboard injection. |
| 256 } |
| 257 |
| 248 void EventExecutorMac::InjectKeyEvent(const KeyEvent& event) { | 258 void EventExecutorMac::InjectKeyEvent(const KeyEvent& event) { |
| 249 int keycode = 0; | 259 int keycode = 0; |
| 250 if (event.has_usb_keycode() && event.usb_keycode() != INVALID_KEYCODE) { | 260 if (event.has_usb_keycode() && event.usb_keycode() != INVALID_KEYCODE) { |
| 251 keycode = UsbKeycodeToMacKeycode(event.usb_keycode()); | 261 keycode = UsbKeycodeToMacKeycode(event.usb_keycode()); |
| 252 VLOG(1) << "USB keycode: " << std::hex << event.usb_keycode() | 262 VLOG(1) << "USB keycode: " << std::hex << event.usb_keycode() |
| 253 << " to Mac keycode: " << keycode << std::dec; | 263 << " to Mac keycode: " << keycode << std::dec; |
| 254 } else { | 264 } else { |
| 255 int win_keycode = event.keycode(); | 265 int win_keycode = event.keycode(); |
| 256 if (win_keycode >= 0 && win_keycode < 256) { | 266 if (win_keycode >= 0 && win_keycode < 256) { |
| 257 keycode = kUsVkeyToKeysym[win_keycode]; | 267 keycode = kUsVkeyToKeysym[win_keycode]; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 341 |
| 332 } // namespace | 342 } // namespace |
| 333 | 343 |
| 334 scoped_ptr<protocol::InputStub> EventExecutor::Create(MessageLoop* message_loop, | 344 scoped_ptr<protocol::InputStub> EventExecutor::Create(MessageLoop* message_loop, |
| 335 Capturer* capturer) { | 345 Capturer* capturer) { |
| 336 return scoped_ptr<protocol::InputStub>( | 346 return scoped_ptr<protocol::InputStub>( |
| 337 new EventExecutorMac(message_loop, capturer)); | 347 new EventExecutorMac(message_loop, capturer)); |
| 338 } | 348 } |
| 339 | 349 |
| 340 } // namespace remoting | 350 } // namespace remoting |
| OLD | NEW |