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/input_injector.h" | 5 #include "remoting/host/input_injector.h" |
6 | 6 |
7 #include <ApplicationServices/ApplicationServices.h> | 7 #include <ApplicationServices/ApplicationServices.h> |
8 #include <Carbon/Carbon.h> | 8 #include <Carbon/Carbon.h> |
9 #include <IOKit/pwr_mgt/IOPMLib.h> | 9 #include <IOKit/pwr_mgt/IOPMLib.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 #include <utility> | 13 #include <utility> |
14 | 14 |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
17 #include "base/location.h" | 17 #include "base/location.h" |
18 #include "base/mac/scoped_cftyperef.h" | 18 #include "base/mac/scoped_cftyperef.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/memory/ptr_util.h" |
20 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
21 #include "base/single_thread_task_runner.h" | 22 #include "base/single_thread_task_runner.h" |
22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
23 #include "base/time/time.h" | 24 #include "base/time/time.h" |
24 #include "remoting/host/clipboard.h" | 25 #include "remoting/host/clipboard.h" |
25 #include "remoting/proto/internal.pb.h" | 26 #include "remoting/proto/internal.pb.h" |
26 #include "remoting/protocol/message_decoder.h" | 27 #include "remoting/protocol/message_decoder.h" |
27 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 28 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
28 #include "third_party/webrtc/modules/desktop_capture/mac/desktop_configuration.h
" | 29 #include "third_party/webrtc/modules/desktop_capture/mac/desktop_configuration.h
" |
29 #include "ui/events/keycodes/dom/keycode_converter.h" | 30 #include "ui/events/keycodes/dom/keycode_converter.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // ClipboardStub interface. | 76 // ClipboardStub interface. |
76 void InjectClipboardEvent(const ClipboardEvent& event) override; | 77 void InjectClipboardEvent(const ClipboardEvent& event) override; |
77 | 78 |
78 // InputStub interface. | 79 // InputStub interface. |
79 void InjectKeyEvent(const KeyEvent& event) override; | 80 void InjectKeyEvent(const KeyEvent& event) override; |
80 void InjectTextEvent(const TextEvent& event) override; | 81 void InjectTextEvent(const TextEvent& event) override; |
81 void InjectMouseEvent(const MouseEvent& event) override; | 82 void InjectMouseEvent(const MouseEvent& event) override; |
82 void InjectTouchEvent(const TouchEvent& event) override; | 83 void InjectTouchEvent(const TouchEvent& event) override; |
83 | 84 |
84 // InputInjector interface. | 85 // InputInjector interface. |
85 void Start(scoped_ptr<protocol::ClipboardStub> client_clipboard) override; | 86 void Start( |
| 87 std::unique_ptr<protocol::ClipboardStub> client_clipboard) override; |
86 | 88 |
87 private: | 89 private: |
88 // The actual implementation resides in InputInjectorMac::Core class. | 90 // The actual implementation resides in InputInjectorMac::Core class. |
89 class Core : public base::RefCountedThreadSafe<Core> { | 91 class Core : public base::RefCountedThreadSafe<Core> { |
90 public: | 92 public: |
91 explicit Core(scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 93 explicit Core(scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
92 | 94 |
93 // Mirrors the ClipboardStub interface. | 95 // Mirrors the ClipboardStub interface. |
94 void InjectClipboardEvent(const ClipboardEvent& event); | 96 void InjectClipboardEvent(const ClipboardEvent& event); |
95 | 97 |
96 // Mirrors the InputStub interface. | 98 // Mirrors the InputStub interface. |
97 void InjectKeyEvent(const KeyEvent& event); | 99 void InjectKeyEvent(const KeyEvent& event); |
98 void InjectTextEvent(const TextEvent& event); | 100 void InjectTextEvent(const TextEvent& event); |
99 void InjectMouseEvent(const MouseEvent& event); | 101 void InjectMouseEvent(const MouseEvent& event); |
100 | 102 |
101 // Mirrors the InputInjector interface. | 103 // Mirrors the InputInjector interface. |
102 void Start(scoped_ptr<protocol::ClipboardStub> client_clipboard); | 104 void Start(std::unique_ptr<protocol::ClipboardStub> client_clipboard); |
103 | 105 |
104 void Stop(); | 106 void Stop(); |
105 | 107 |
106 private: | 108 private: |
107 friend class base::RefCountedThreadSafe<Core>; | 109 friend class base::RefCountedThreadSafe<Core>; |
108 virtual ~Core(); | 110 virtual ~Core(); |
109 | 111 |
110 void WakeUpDisplay(); | 112 void WakeUpDisplay(); |
111 | 113 |
112 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 114 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
113 webrtc::DesktopVector mouse_pos_; | 115 webrtc::DesktopVector mouse_pos_; |
114 uint32_t mouse_button_state_; | 116 uint32_t mouse_button_state_; |
115 scoped_ptr<Clipboard> clipboard_; | 117 std::unique_ptr<Clipboard> clipboard_; |
116 uint64_t left_modifiers_; | 118 uint64_t left_modifiers_; |
117 uint64_t right_modifiers_; | 119 uint64_t right_modifiers_; |
118 base::TimeTicks last_time_display_woken_; | 120 base::TimeTicks last_time_display_woken_; |
119 | 121 |
120 DISALLOW_COPY_AND_ASSIGN(Core); | 122 DISALLOW_COPY_AND_ASSIGN(Core); |
121 }; | 123 }; |
122 | 124 |
123 scoped_refptr<Core> core_; | 125 scoped_refptr<Core> core_; |
124 | 126 |
125 DISALLOW_COPY_AND_ASSIGN(InputInjectorMac); | 127 DISALLOW_COPY_AND_ASSIGN(InputInjectorMac); |
(...skipping 22 matching lines...) Expand all Loading... |
148 | 150 |
149 void InputInjectorMac::InjectMouseEvent(const MouseEvent& event) { | 151 void InputInjectorMac::InjectMouseEvent(const MouseEvent& event) { |
150 core_->InjectMouseEvent(event); | 152 core_->InjectMouseEvent(event); |
151 } | 153 } |
152 | 154 |
153 void InputInjectorMac::InjectTouchEvent(const TouchEvent& event) { | 155 void InputInjectorMac::InjectTouchEvent(const TouchEvent& event) { |
154 NOTIMPLEMENTED() << "Raw touch event injection not implemented for Mac."; | 156 NOTIMPLEMENTED() << "Raw touch event injection not implemented for Mac."; |
155 } | 157 } |
156 | 158 |
157 void InputInjectorMac::Start( | 159 void InputInjectorMac::Start( |
158 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 160 std::unique_ptr<protocol::ClipboardStub> client_clipboard) { |
159 core_->Start(std::move(client_clipboard)); | 161 core_->Start(std::move(client_clipboard)); |
160 } | 162 } |
161 | 163 |
162 InputInjectorMac::Core::Core( | 164 InputInjectorMac::Core::Core( |
163 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 165 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
164 : task_runner_(task_runner), | 166 : task_runner_(task_runner), |
165 mouse_button_state_(0), | 167 mouse_button_state_(0), |
166 clipboard_(Clipboard::Create()), | 168 clipboard_(Clipboard::Create()), |
167 left_modifiers_(0), | 169 left_modifiers_(0), |
168 right_modifiers_(0) { | 170 right_modifiers_(0) { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 int delta_x = static_cast<int>(event.wheel_delta_x()); | 330 int delta_x = static_cast<int>(event.wheel_delta_x()); |
329 int delta_y = static_cast<int>(event.wheel_delta_y()); | 331 int delta_y = static_cast<int>(event.wheel_delta_y()); |
330 base::ScopedCFTypeRef<CGEventRef> event(CGEventCreateScrollWheelEvent( | 332 base::ScopedCFTypeRef<CGEventRef> event(CGEventCreateScrollWheelEvent( |
331 nullptr, kCGScrollEventUnitPixel, 2, delta_y, delta_x)); | 333 nullptr, kCGScrollEventUnitPixel, 2, delta_y, delta_x)); |
332 if (event) | 334 if (event) |
333 CGEventPost(kCGSessionEventTap, event); | 335 CGEventPost(kCGSessionEventTap, event); |
334 } | 336 } |
335 } | 337 } |
336 | 338 |
337 void InputInjectorMac::Core::Start( | 339 void InputInjectorMac::Core::Start( |
338 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 340 std::unique_ptr<protocol::ClipboardStub> client_clipboard) { |
339 if (!task_runner_->BelongsToCurrentThread()) { | 341 if (!task_runner_->BelongsToCurrentThread()) { |
340 task_runner_->PostTask( | 342 task_runner_->PostTask( |
341 FROM_HERE, | 343 FROM_HERE, |
342 base::Bind(&Core::Start, this, base::Passed(&client_clipboard))); | 344 base::Bind(&Core::Start, this, base::Passed(&client_clipboard))); |
343 return; | 345 return; |
344 } | 346 } |
345 | 347 |
346 clipboard_->Start(std::move(client_clipboard)); | 348 clipboard_->Start(std::move(client_clipboard)); |
347 } | 349 } |
348 | 350 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 if (result == kIOReturnSuccess) { | 383 if (result == kIOReturnSuccess) { |
382 IOPMAssertionRelease(power_assertion_id); | 384 IOPMAssertionRelease(power_assertion_id); |
383 } | 385 } |
384 } | 386 } |
385 | 387 |
386 InputInjectorMac::Core::~Core() {} | 388 InputInjectorMac::Core::~Core() {} |
387 | 389 |
388 } // namespace | 390 } // namespace |
389 | 391 |
390 // static | 392 // static |
391 scoped_ptr<InputInjector> InputInjector::Create( | 393 std::unique_ptr<InputInjector> InputInjector::Create( |
392 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 394 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
393 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 395 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
394 return make_scoped_ptr(new InputInjectorMac(main_task_runner)); | 396 return base::WrapUnique(new InputInjectorMac(main_task_runner)); |
395 } | 397 } |
396 | 398 |
397 // static | 399 // static |
398 bool InputInjector::SupportsTouchEvents() { | 400 bool InputInjector::SupportsTouchEvents() { |
399 return false; | 401 return false; |
400 } | 402 } |
401 | 403 |
402 } // namespace remoting | 404 } // namespace remoting |
OLD | NEW |