Chromium Code Reviews| Index: remoting/host/input_injector_mac.cc |
| diff --git a/remoting/host/input_injector_mac.cc b/remoting/host/input_injector_mac.cc |
| index c5e870026e3deff4e3e9205e2a6902b76f579821..240a6cf4bca000db92c6b2d1d2f0be649f06a113 100644 |
| --- a/remoting/host/input_injector_mac.cc |
| +++ b/remoting/host/input_injector_mac.cc |
| @@ -60,6 +60,7 @@ class InputInjectorMac : public InputInjector { |
| public: |
| explicit InputInjectorMac( |
| scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| + |
| virtual ~InputInjectorMac(); |
| // ClipboardStub interface. |
| @@ -73,8 +74,15 @@ class InputInjectorMac : public InputInjector { |
| // InputInjector interface. |
| virtual void Start( |
| scoped_ptr<protocol::ClipboardStub> client_clipboard) OVERRIDE; |
| + // TODO(sidj, sskhandp) Remove these methods and use |
| + // WindowInputInjectorMac instead. |
| + virtual void SetWindowId(webrtc::WindowId windowId); |
|
Lambros
2014/07/30 00:14:48
Do these need to be virtual?
ronakvora do not use
2014/07/30 20:55:36
Nope, changed.
|
| + virtual void SetEnableWindowCapture(bool enable_window_capture); |
|
Lambros
2014/07/30 00:14:48
Don't say "Capture" here. Maybe replace these meth
ronakvora do not use
2014/07/30 20:55:36
Done.
|
| private: |
| + // TODO(sidj, sskhandp) put these inside of WindowInputInjectorMac. |
|
Lambros
2014/07/30 00:14:49
Remove TODO - I don't think it's worth defining a
ronakvora do not use
2014/07/30 20:55:36
Done.
|
| + CGWindowID windowId_input_injector_mac_; |
|
Lambros
2014/07/30 00:14:49
nit: window_id_
ronakvora do not use
2014/07/30 20:55:36
Done.
|
| + bool enable_window_capture_injector_mac_; |
|
Lambros
2014/07/30 00:14:48
nit: window_injection_enabled_ - don't use "captur
ronakvora do not use
2014/07/30 20:55:36
Done.
|
| // The actual implementation resides in InputInjectorMac::Core class. |
| class Core : public base::RefCountedThreadSafe<Core> { |
| public: |
| @@ -91,11 +99,17 @@ class InputInjectorMac : public InputInjector { |
| // Mirrors the InputInjector interface. |
| void Start(scoped_ptr<protocol::ClipboardStub> client_clipboard); |
| + // TODO(sidj, sskhandp) Remove these methods and use |
|
Lambros
2014/07/30 00:14:48
Remove TODO.
ronakvora do not use
2014/07/30 20:55:36
Done.
|
| + // WindowInputInjectorMac instead. |
| + void SetWindowId(CGWindowID windowId); |
| + void SetEnableWindowCapture(bool enable_window_capture); |
| + |
| void Stop(); |
| private: |
| friend class base::RefCountedThreadSafe<Core>; |
| virtual ~Core(); |
| + CGRect FindCGRectOfWindow(webrtc::MacDesktopConfiguration desktop_config); |
| scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| webrtc::DesktopVector mouse_pos_; |
| @@ -103,6 +117,9 @@ class InputInjectorMac : public InputInjector { |
| scoped_ptr<Clipboard> clipboard_; |
| CGEventFlags left_modifiers_; |
| CGEventFlags right_modifiers_; |
| + // TODO(sidj, sskhandp) put these inside of WindowInputInjectorMac. |
|
Lambros
2014/07/30 00:14:48
Remove TODO.
ronakvora do not use
2014/07/30 20:55:36
Done.
|
| + CGWindowID windowId_core_; |
| + bool enable_window_capture_core_; |
| DISALLOW_COPY_AND_ASSIGN(Core); |
| }; |
| @@ -142,6 +159,16 @@ void InputInjectorMac::Start( |
| core_->Start(client_clipboard.Pass()); |
| } |
| +void InputInjectorMac::SetWindowId(webrtc::WindowId windowId) { |
| + windowId_input_injector_mac_ = (CGWindowID) windowId; |
| + core_->SetWindowId(windowId_input_injector_mac_); |
| +} |
| + |
| +void InputInjectorMac::SetEnableWindowCapture(bool enable_window_capture) { |
| + enable_window_capture_injector_mac_ = enable_window_capture; |
| + core_->SetEnableWindowCapture(enable_window_capture_injector_mac_); |
| +} |
| + |
| InputInjectorMac::Core::Core( |
| scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| : task_runner_(task_runner), |
| @@ -163,6 +190,13 @@ InputInjectorMac::Core::Core( |
| #pragma clang diagnostic pop |
| } |
| +void InputInjectorMac::Core::SetWindowId(CGWindowID windowId) { |
| + windowId_core_ = windowId; |
| +} |
| +void InputInjectorMac::Core::SetEnableWindowCapture |
| + (bool enable_window_capture) { |
| + enable_window_capture_core_ = enable_window_capture; |
| +} |
| void InputInjectorMac::Core::InjectClipboardEvent(const ClipboardEvent& event) { |
| if (!task_runner_->BelongsToCurrentThread()) { |
| task_runner_->PostTask( |
| @@ -228,6 +262,39 @@ void InputInjectorMac::Core::InjectTextEvent(const TextEvent& event) { |
| CreateAndPostKeyEvent(kVK_Space, false, 0, text); |
| } |
| +CGRect InputInjectorMac::Core::FindCGRectOfWindow( |
| + webrtc::MacDesktopConfiguration desktop_config) { |
| + CGRect rect; |
| + CGWindowID ids[1] = {windowId_core_}; |
| + CFArrayRef window_id_array = |
| + CFArrayCreate(NULL, reinterpret_cast<const void **>(&ids), 1, NULL); |
| + CFArrayRef window_array = |
| + CGWindowListCreateDescriptionFromArray(window_id_array); |
| + if (window_array == NULL || 0 == CFArrayGetCount(window_array)) { |
| + // Could not find the window. It might have been closed. |
| + LOG(ERROR) << "Specified window to stream not found for id: " |
| + << windowId_core_; |
| + CFRelease(window_id_array); |
|
Lambros
2014/07/30 00:14:49
Use ScopedCFTypeRef from base/mac/scoped_cftyperef
ronakvora do not use
2014/07/30 20:55:36
I've been a bit confused on the scoped_X types. Do
|
| + CFRelease(window_array); |
| + return CGRectNull; |
| + } |
| + CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>( |
| + CFArrayGetValueAtIndex(window_array, 0)); |
| + |
| + if (CFDictionaryContainsKey(window, kCGWindowBounds)) { |
| + CFDictionaryRef bounds = |
| + reinterpret_cast<CFDictionaryRef> |
| + (CFDictionaryGetValue(window, kCGWindowBounds)); |
| + if (bounds) { |
| + CGRectMakeWithDictionaryRepresentation(bounds, &rect); |
| + } |
| + } |
| + |
| + CFRelease(window_id_array); |
| + CFRelease(window_array); |
| + return rect; |
| +} |
| + |
| void InputInjectorMac::Core::InjectMouseEvent(const MouseEvent& event) { |
| if (event.has_x() && event.has_y()) { |
| // On multi-monitor systems (0,0) refers to the top-left of the "main" |
| @@ -263,6 +330,20 @@ void InputInjectorMac::Core::InjectMouseEvent(const MouseEvent& event) { |
| mouse_pos_.set(mouse_pos_.x() / desktop_config.dip_to_pixel_scale, |
| mouse_pos_.y() / desktop_config.dip_to_pixel_scale); |
| + // Translate the mouse position into window coordinates. |
| + // TODO(sskhandp, sidj) Remove this if clause and implement |
| + // functionality in WindowInputInjectorMac. |
| + if (enable_window_capture_core_) { |
| + CGRect windowRect = FindCGRectOfWindow(desktop_config); |
| + if (CGRectEqualToRect(windowRect, CGRectNull)) { |
| + LOG(ERROR) << "Can't find rectangle of window."; |
| + return; |
| + } |
| + mouse_pos_ = mouse_pos_.add( |
| + webrtc::DesktopVector(CGRectGetMinX(windowRect), |
| + CGRectGetMinY(windowRect))); |
| + } |
| + |
| VLOG(3) << "Moving mouse to " << mouse_pos_.x() << "," << mouse_pos_.y(); |
| } |
| if (event.has_button() && event.has_button_down()) { |
| @@ -341,4 +422,16 @@ scoped_ptr<InputInjector> InputInjector::Create( |
| return scoped_ptr<InputInjector>(new InputInjectorMac(main_task_runner)); |
| } |
| +// TODO(sskhandp, sidj) remove this method and make WindowInputInjector |
|
Lambros
2014/07/30 00:14:48
Remove TODO.
ronakvora do not use
2014/07/30 20:55:36
Done.
|
| +scoped_ptr<InputInjector> InputInjector::Create( |
| + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| + webrtc::WindowId windowId, |
| + bool enable_window_capture) { |
| + InputInjectorMac* injector = new InputInjectorMac(main_task_runner); |
|
Lambros
2014/07/30 00:14:49
nit: Declare |injector| as scoped_ptr instead of r
ronakvora do not use
2014/07/30 20:55:36
Done.
|
| + injector->SetWindowId(windowId); |
| + injector->SetEnableWindowCapture(enable_window_capture); |
| + return scoped_ptr<InputInjector>(injector); |
| +} |
| + |
| } // namespace remoting |