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/bind.h" | 11 #include "base/bind.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/mac/scoped_cftyperef.h" | 14 #include "base/mac/scoped_cftyperef.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "remoting/host/clipboard.h" | 16 #include "remoting/host/clipboard.h" |
17 #include "remoting/proto/internal.pb.h" | 17 #include "remoting/proto/internal.pb.h" |
18 #include "remoting/protocol/message_decoder.h" | 18 #include "remoting/protocol/message_decoder.h" |
19 #include "third_party/skia/include/core/SkPoint.h" | 19 #include "third_party/skia/include/core/SkPoint.h" |
20 #include "third_party/skia/include/core/SkRect.h" | |
20 | 21 |
21 namespace remoting { | 22 namespace remoting { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 using protocol::ClipboardEvent; | 26 using protocol::ClipboardEvent; |
26 using protocol::KeyEvent; | 27 using protocol::KeyEvent; |
27 using protocol::MouseEvent; | 28 using protocol::MouseEvent; |
28 | 29 |
29 // USB to Mac keycode mapping table. | 30 // USB to Mac keycode mapping table. |
30 #define USB_KEYMAP(usb, xkb, win, mac) {usb, mac} | 31 #define USB_KEYMAP(usb, xkb, win, mac) {usb, mac} |
31 #include "ui/base/keycodes/usb_keycode_map.h" | 32 #include "ui/base/keycodes/usb_keycode_map.h" |
32 #undef USB_KEYMAP | 33 #undef USB_KEYMAP |
33 | 34 |
35 SkIRect CGRectToSkIRect(const CGRect& rect) { | |
Jamie
2012/08/30 20:53:53
skia/ext/skia_utils_mac.h defines this function. I
Wez
2012/08/31 00:47:42
Sadly, it defines only CGRectToSkRect(), not CGRec
Jamie
2012/08/31 01:20:02
I was about to suggest adding it, but then I saw h
| |
36 SkIRect sk_rect = { | |
37 SkScalarRound(rect.origin.x), | |
38 SkScalarRound(rect.origin.y), | |
39 SkScalarRound(rect.origin.x + rect.size.width), | |
40 SkScalarRound(rect.origin.y + rect.size.height) | |
41 }; | |
42 return sk_rect; | |
43 } | |
44 | |
34 // A class to generate events on Mac. | 45 // A class to generate events on Mac. |
35 class EventExecutorMac : public EventExecutor { | 46 class EventExecutorMac : public EventExecutor { |
36 public: | 47 public: |
37 EventExecutorMac(scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 48 EventExecutorMac(scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
38 virtual ~EventExecutorMac() {} | 49 virtual ~EventExecutorMac() {} |
39 | 50 |
40 // ClipboardStub interface. | 51 // ClipboardStub interface. |
41 virtual void InjectClipboardEvent(const ClipboardEvent& event) OVERRIDE; | 52 virtual void InjectClipboardEvent(const ClipboardEvent& event) OVERRIDE; |
42 | 53 |
43 // InputStub interface. | 54 // InputStub interface. |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 #pragma clang diagnostic ignored "-Wdeprecated-declarations" | 311 #pragma clang diagnostic ignored "-Wdeprecated-declarations" |
301 CGError error = CGPostKeyboardEvent(0, keycode, event.pressed()); | 312 CGError error = CGPostKeyboardEvent(0, keycode, event.pressed()); |
302 #pragma clang diagnostic pop | 313 #pragma clang diagnostic pop |
303 if (error != kCGErrorSuccess) { | 314 if (error != kCGErrorSuccess) { |
304 LOG(WARNING) << "CGPostKeyboardEvent error " << error; | 315 LOG(WARNING) << "CGPostKeyboardEvent error " << error; |
305 } | 316 } |
306 } | 317 } |
307 | 318 |
308 void EventExecutorMac::InjectMouseEvent(const MouseEvent& event) { | 319 void EventExecutorMac::InjectMouseEvent(const MouseEvent& event) { |
309 if (event.has_x() && event.has_y()) { | 320 if (event.has_x() && event.has_y()) { |
310 // TODO(wez): This code assumes that MouseEvent(0,0) (top-left of client vie w) | 321 // On multi-monitor systems (0,0) refers to the top-left of the "main" |
311 // corresponds to local (0,0) (top-left of primary monitor). That won't in | 322 // display, whereas our coordinate scheme places (0,0) at the top-left of |
312 // general be true on multi-monitor systems, though. | 323 // the bounding rectangle around all the displays, so we need to translate |
324 // accordingly. | |
325 // TODO(wez): Move display config tracking into a separate class used both | |
326 // here and in the Capturer. | |
Jamie
2012/08/30 20:53:53
I assume this would allow us to avoid doing this c
Wez
2012/08/31 00:47:42
If it registered for display-change notifications
| |
327 | |
328 // Set the mouse position assuming single-monitor. | |
329 mouse_pos_ = SkIPoint::Make(event.x(), event.y()); | |
330 | |
331 // Determine how many active displays there are. | |
332 CGDisplayCount display_count; | |
333 CGError error = CGGetActiveDisplayList(0, NULL, &display_count); | |
334 CHECK_EQ(error, CGDisplayNoErr); | |
335 | |
336 if (display_count > 1) { | |
337 // Determine the bounding box of the displays, to get the top-left origin. | |
338 std::vector<CGDirectDisplayID> display_ids(display_count); | |
339 error = CGGetActiveDisplayList(display_count, &display_ids[0], | |
340 &display_count); | |
341 CHECK_EQ(error, CGDisplayNoErr); | |
342 CHECK_EQ(display_count, display_ids.size()); | |
343 | |
344 SkIRect desktop_bounds = SkIRect::MakeEmpty(); | |
345 for (unsigned int d = 0; d < display_count; ++d) { | |
346 CGRect display_bounds = CGDisplayBounds(display_ids[d]); | |
347 desktop_bounds.join(CGRectToSkIRect(display_bounds)); | |
348 } | |
349 | |
350 // Adjust the injected mouse event position. | |
351 mouse_pos_ += SkIPoint::Make(desktop_bounds.left(), desktop_bounds.top()); | |
352 } | |
353 | |
313 VLOG(3) << "Moving mouse to " << event.x() << "," << event.y(); | 354 VLOG(3) << "Moving mouse to " << event.x() << "," << event.y(); |
314 mouse_pos_ = SkIPoint::Make(event.x(), event.y()); | |
315 } | 355 } |
316 if (event.has_button() && event.has_button_down()) { | 356 if (event.has_button() && event.has_button_down()) { |
317 if (event.button() >= 1 && event.button() <= 3) { | 357 if (event.button() >= 1 && event.button() <= 3) { |
318 VLOG(2) << "Button " << event.button() | 358 VLOG(2) << "Button " << event.button() |
319 << (event.button_down() ? " down" : " up"); | 359 << (event.button_down() ? " down" : " up"); |
320 int button_change = 1 << (event.button() - 1); | 360 int button_change = 1 << (event.button() - 1); |
321 if (event.button_down()) | 361 if (event.button_down()) |
322 mouse_button_state_ |= button_change; | 362 mouse_button_state_ |= button_change; |
323 else | 363 else |
324 mouse_button_state_ &= ~button_change; | 364 mouse_button_state_ &= ~button_change; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 | 431 |
392 } // namespace | 432 } // namespace |
393 | 433 |
394 scoped_ptr<EventExecutor> EventExecutor::Create( | 434 scoped_ptr<EventExecutor> EventExecutor::Create( |
395 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 435 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
396 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 436 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
397 return scoped_ptr<EventExecutor>(new EventExecutorMac(main_task_runner)); | 437 return scoped_ptr<EventExecutor>(new EventExecutorMac(main_task_runner)); |
398 } | 438 } |
399 | 439 |
400 } // namespace remoting | 440 } // namespace remoting |
OLD | NEW |