Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/host/single_window_input_injector.h" | |
| 6 | |
| 7 #include <ApplicationServices/ApplicationServices.h> | |
| 8 #include <Carbon/Carbon.h> | |
| 9 | |
| 10 #include "base/mac/scoped_cftyperef.h" | |
| 11 #include "remoting/proto/internal.pb.h" | |
|
Wez
2014/08/06 04:10:16
I think you want to include the event.pb.h header,
ronakvora do not use
2014/08/06 20:56:19
Done.
| |
| 12 #include "third_party/webrtc/modules/desktop_capture/mac/desktop_configuration.h " | |
| 13 | |
| 14 namespace remoting { | |
| 15 | |
| 16 using protocol::ClipboardEvent; | |
| 17 using protocol::KeyEvent; | |
| 18 using protocol::TextEvent; | |
| 19 using protocol::MouseEvent; | |
| 20 | |
| 21 // A class to generate events to a window on Mac. | |
|
Wez
2014/08/06 04:10:16
nit: Suggest:
"Implements InputInjector to direct
ronakvora do not use
2014/08/06 20:56:19
Done.
| |
| 22 class SingleWindowInputInjectorMac : public SingleWindowInputInjector { | |
| 23 public: | |
| 24 SingleWindowInputInjectorMac( | |
| 25 webrtc::WindowId window_id, | |
| 26 scoped_ptr<InputInjector> input_injector); | |
| 27 virtual ~SingleWindowInputInjectorMac(); | |
| 28 | |
| 29 // InputInjector interface. | |
| 30 virtual void Start( | |
| 31 scoped_ptr<protocol::ClipboardStub> client_clipboard) OVERRIDE; | |
| 32 virtual void InjectKeyEvent(const KeyEvent& event) OVERRIDE; | |
| 33 virtual void InjectTextEvent(const TextEvent& event) OVERRIDE; | |
| 34 virtual void InjectMouseEvent(const MouseEvent& event) OVERRIDE; | |
| 35 virtual void InjectClipboardEvent(const ClipboardEvent& event) OVERRIDE; | |
| 36 | |
| 37 private: | |
| 38 CGRect FindCGRectOfWindow(); | |
| 39 | |
| 40 CGWindowID window_id_; | |
| 41 scoped_ptr<InputInjector> input_injector_; | |
| 42 | |
| 43 DISALLOW_COPY_AND_ASSIGN(SingleWindowInputInjectorMac); | |
| 44 }; | |
| 45 | |
| 46 SingleWindowInputInjectorMac::SingleWindowInputInjectorMac( | |
| 47 webrtc::WindowId window_id, | |
| 48 scoped_ptr<InputInjector> input_injector): | |
| 49 window_id_((CGWindowID)window_id), | |
| 50 input_injector_(input_injector.Pass()) { | |
| 51 } | |
| 52 | |
| 53 SingleWindowInputInjectorMac::~SingleWindowInputInjectorMac() { | |
| 54 } | |
| 55 | |
| 56 void SingleWindowInputInjectorMac::Start( | |
| 57 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | |
| 58 input_injector_->Start(client_clipboard.Pass()); | |
| 59 } | |
| 60 | |
| 61 void SingleWindowInputInjectorMac::InjectKeyEvent(const KeyEvent& event) { | |
| 62 input_injector_->InjectKeyEvent(event); | |
| 63 } | |
| 64 | |
| 65 void SingleWindowInputInjectorMac::InjectTextEvent(const TextEvent& event) { | |
| 66 input_injector_->InjectTextEvent(event); | |
| 67 } | |
| 68 | |
| 69 void SingleWindowInputInjectorMac::InjectMouseEvent(const MouseEvent& event) { | |
| 70 if (event.has_x() && event.has_y()) { | |
| 71 CGRect windowRect = FindCGRectOfWindow(); | |
| 72 if (CGRectIsNull(windowRect)) { | |
| 73 LOG(ERROR) << "Failing silently and just forwarding event"; | |
|
Wez
2014/08/06 04:10:16
nit: Suggest "Window rect is null, so ignoring Mou
ronakvora do not use
2014/08/06 20:56:20
Done.
| |
| 74 input_injector_->InjectMouseEvent(event); | |
| 75 return; | |
| 76 } | |
|
Wez
2014/08/06 04:10:16
nit: Blank line after this, to separate it from th
ronakvora do not use
2014/08/06 20:56:19
Done.
| |
| 77 webrtc::MacDesktopConfiguration desktop_config = | |
| 78 webrtc::MacDesktopConfiguration::GetCurrent( | |
| 79 webrtc::MacDesktopConfiguration::TopLeftOrigin); | |
| 80 | |
| 81 // Create a vector that has the origin of the window. | |
| 82 webrtc::DesktopVector mouse_pos(CGRectGetMinX(windowRect), | |
|
Wez
2014/08/06 04:10:16
mouse_pos -> window_origin, then?
ronakvora do not use
2014/08/06 20:56:19
Yep, you're right. We were doing it this way in ou
| |
| 83 CGRectGetMinY(windowRect)); | |
| 84 | |
| 85 // Subtract coordinates that are already added in for multiple | |
| 86 // desktops. They get added in already in InputInjector. | |
|
Wez
2014/08/06 04:10:16
Suggest: "The underlying InputInjector expects coo
ronakvora do not use
2014/08/06 20:56:19
Done.
| |
| 87 mouse_pos.subtract( | |
| 88 webrtc::DesktopVector(desktop_config.pixel_bounds.left(), | |
| 89 desktop_config.pixel_bounds.top())); | |
| 90 | |
| 91 // Create a new event with coordinates that are in respect to the window. | |
| 92 // We must make sure we are taking into account the fact that when we | |
| 93 // find the window on the host it returns is coordinates in Density | |
|
Lambros
2014/08/05 22:47:25
s/is/its
s/conver/convert
ronakvora do not use
2014/08/06 20:56:19
Done.
| |
| 94 // Independent coordinates. We have to conver to Density Dependent | |
| 95 // because InputInjector assumes Density Dependent coordinates in the | |
| 96 // MouseEvent. | |
| 97 MouseEvent modified_event(event); | |
| 98 modified_event.set_x( | |
| 99 event.x() + mouse_pos.x() * desktop_config.dip_to_pixel_scale); | |
| 100 modified_event.set_y( | |
| 101 event.y() + mouse_pos.y() * desktop_config.dip_to_pixel_scale); | |
| 102 input_injector_->InjectMouseEvent(modified_event); | |
| 103 } else { | |
| 104 input_injector_->InjectMouseEvent(event); | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 void SingleWindowInputInjectorMac::InjectClipboardEvent( | |
| 109 const ClipboardEvent& event) { | |
| 110 input_injector_->InjectClipboardEvent(event); | |
| 111 } | |
| 112 | |
| 113 // This method is used if we are capturing a window instead of a screen. | |
| 114 // It finds the rectangle of the window we are streaming using | |
| 115 // |window_id_|. The InputInjector can then use this rectangle | |
| 116 // to translate the input event to coordinates of the window rather | |
| 117 // than the screen. | |
| 118 CGRect SingleWindowInputInjectorMac::FindCGRectOfWindow() { | |
| 119 CGRect rect; | |
| 120 CGWindowID ids[1] = {window_id_}; | |
| 121 base::ScopedCFTypeRef<CFArrayRef> window_id_array( | |
| 122 CFArrayCreate(NULL, reinterpret_cast<const void **>(&ids), 1, NULL)); | |
| 123 | |
| 124 base::ScopedCFTypeRef<CFArrayRef> window_array( | |
| 125 CGWindowListCreateDescriptionFromArray(window_id_array)); | |
| 126 | |
| 127 if (window_array == NULL || CFArrayGetCount(window_array) == 0) { | |
| 128 // Could not find the window. It might have been closed. | |
| 129 LOG(ERROR) << "Specified window to stream not found for id: " | |
| 130 << window_id_; | |
| 131 return CGRectNull; | |
| 132 } | |
| 133 | |
| 134 // We don't use ScopedCFTypeRef for |window| because the | |
|
Lambros
2014/08/05 22:47:25
I don't think this comment is needed.
ronakvora do not use
2014/08/06 20:56:19
When I had a discussion with Wez, he asked me to d
| |
| 135 // CFDictionaryRef returned by CFArrayGetValueAtIndex is owned by | |
| 136 // window_array. The same is true of the |bounds|. | |
| 137 CFDictionaryRef window = | |
| 138 reinterpret_cast<CFDictionaryRef>( | |
| 139 CFArrayGetValueAtIndex(window_array, 0)); | |
| 140 | |
| 141 if (CFDictionaryContainsKey(window, kCGWindowBounds)) { | |
| 142 CFDictionaryRef bounds = | |
| 143 reinterpret_cast<CFDictionaryRef>( | |
| 144 CFDictionaryGetValue(window, kCGWindowBounds)); | |
| 145 if (bounds) { | |
| 146 CGRectMakeWithDictionaryRepresentation(bounds, &rect); | |
| 147 } else { | |
| 148 return CGRectNull; | |
| 149 } | |
| 150 } else { | |
| 151 return CGRectNull; | |
| 152 } | |
| 153 | |
| 154 return rect; | |
| 155 } | |
| 156 | |
| 157 scoped_ptr<InputInjector> SingleWindowInputInjector::Create( | |
| 158 webrtc::WindowId window_id, | |
| 159 scoped_ptr<InputInjector> input_injector) { | |
| 160 scoped_ptr<SingleWindowInputInjectorMac>injector( | |
| 161 new SingleWindowInputInjectorMac(window_id, input_injector.Pass())); | |
| 162 return injector.PassAs<InputInjector>(); | |
| 163 } | |
| 164 | |
| 165 | |
| 166 | |
| 167 } // namespace remoting | |
| OLD | NEW |