| 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 <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/mac/scoped_cftyperef.h" | 15 #include "base/mac/scoped_cftyperef.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "remoting/host/clipboard.h" | 18 #include "remoting/host/clipboard.h" |
| 19 #include "remoting/proto/internal.pb.h" | 19 #include "remoting/proto/internal.pb.h" |
| 20 #include "remoting/protocol/message_decoder.h" | 20 #include "remoting/protocol/message_decoder.h" |
| 21 #include "skia/ext/skia_utils_mac.h" | 21 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
| 22 #include "third_party/skia/include/core/SkPoint.h" | |
| 23 #include "third_party/skia/include/core/SkRect.h" | |
| 24 #include "third_party/webrtc/modules/desktop_capture/mac/desktop_configuration.h
" | 22 #include "third_party/webrtc/modules/desktop_capture/mac/desktop_configuration.h
" |
| 25 #include "ui/events/keycodes/dom4/keycode_converter.h" | 23 #include "ui/events/keycodes/dom4/keycode_converter.h" |
| 26 | 24 |
| 27 namespace remoting { | 25 namespace remoting { |
| 28 | 26 |
| 29 namespace { | 27 namespace { |
| 30 | 28 |
| 31 using protocol::ClipboardEvent; | 29 using protocol::ClipboardEvent; |
| 32 using protocol::KeyEvent; | 30 using protocol::KeyEvent; |
| 33 using protocol::MouseEvent; | 31 using protocol::MouseEvent; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // Mirrors the InputInjector interface. | 64 // Mirrors the InputInjector interface. |
| 67 void Start(scoped_ptr<protocol::ClipboardStub> client_clipboard); | 65 void Start(scoped_ptr<protocol::ClipboardStub> client_clipboard); |
| 68 | 66 |
| 69 void Stop(); | 67 void Stop(); |
| 70 | 68 |
| 71 private: | 69 private: |
| 72 friend class base::RefCountedThreadSafe<Core>; | 70 friend class base::RefCountedThreadSafe<Core>; |
| 73 virtual ~Core(); | 71 virtual ~Core(); |
| 74 | 72 |
| 75 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 73 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 76 SkIPoint mouse_pos_; | 74 webrtc::DesktopVector mouse_pos_; |
| 77 uint32 mouse_button_state_; | 75 uint32 mouse_button_state_; |
| 78 scoped_ptr<Clipboard> clipboard_; | 76 scoped_ptr<Clipboard> clipboard_; |
| 79 | 77 |
| 80 DISALLOW_COPY_AND_ASSIGN(Core); | 78 DISALLOW_COPY_AND_ASSIGN(Core); |
| 81 }; | 79 }; |
| 82 | 80 |
| 83 scoped_refptr<Core> core_; | 81 scoped_refptr<Core> core_; |
| 84 | 82 |
| 85 DISALLOW_COPY_AND_ASSIGN(InputInjectorMac); | 83 DISALLOW_COPY_AND_ASSIGN(InputInjectorMac); |
| 86 }; | 84 }; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 } | 169 } |
| 172 | 170 |
| 173 void InputInjectorMac::Core::InjectMouseEvent(const MouseEvent& event) { | 171 void InputInjectorMac::Core::InjectMouseEvent(const MouseEvent& event) { |
| 174 if (event.has_x() && event.has_y()) { | 172 if (event.has_x() && event.has_y()) { |
| 175 // On multi-monitor systems (0,0) refers to the top-left of the "main" | 173 // On multi-monitor systems (0,0) refers to the top-left of the "main" |
| 176 // display, whereas our coordinate scheme places (0,0) at the top-left of | 174 // display, whereas our coordinate scheme places (0,0) at the top-left of |
| 177 // the bounding rectangle around all the displays, so we need to translate | 175 // the bounding rectangle around all the displays, so we need to translate |
| 178 // accordingly. | 176 // accordingly. |
| 179 | 177 |
| 180 // Set the mouse position assuming single-monitor. | 178 // Set the mouse position assuming single-monitor. |
| 181 mouse_pos_ = SkIPoint::Make(event.x(), event.y()); | 179 mouse_pos_.set(event.x(), event.y()); |
| 182 | 180 |
| 183 // Fetch the desktop configuration. | 181 // Fetch the desktop configuration. |
| 184 // TODO(wez): Optimize this out, or at least only enumerate displays in | 182 // TODO(wez): Optimize this out, or at least only enumerate displays in |
| 185 // response to display-changed events. VideoFrameCapturer's VideoFrames | 183 // response to display-changed events. VideoFrameCapturer's VideoFrames |
| 186 // could be augmented to include native cursor coordinates for use by | 184 // could be augmented to include native cursor coordinates for use by |
| 187 // MouseClampingFilter, removing the need for translation here. | 185 // MouseClampingFilter, removing the need for translation here. |
| 188 webrtc::MacDesktopConfiguration desktop_config = | 186 webrtc::MacDesktopConfiguration desktop_config = |
| 189 webrtc::MacDesktopConfiguration::GetCurrent( | 187 webrtc::MacDesktopConfiguration::GetCurrent( |
| 190 webrtc::MacDesktopConfiguration::TopLeftOrigin); | 188 webrtc::MacDesktopConfiguration::TopLeftOrigin); |
| 191 | 189 |
| 192 // Translate the mouse position into desktop coordinates. | 190 // Translate the mouse position into desktop coordinates. |
| 193 mouse_pos_ += SkIPoint::Make(desktop_config.pixel_bounds.left(), | 191 mouse_pos_.add(webrtc::DesktopVector(desktop_config.pixel_bounds.left(), |
| 194 desktop_config.pixel_bounds.top()); | 192 desktop_config.pixel_bounds.top())); |
| 195 | 193 |
| 196 // Constrain the mouse position to the desktop coordinates. | 194 // Constrain the mouse position to the desktop coordinates. |
| 197 mouse_pos_ = SkIPoint::Make( | 195 mouse_pos_.set( |
| 198 std::max(desktop_config.pixel_bounds.left(), | 196 std::max(desktop_config.pixel_bounds.left(), |
| 199 std::min(desktop_config.pixel_bounds.right(), mouse_pos_.x())), | 197 std::min(desktop_config.pixel_bounds.right(), mouse_pos_.x())), |
| 200 std::max(desktop_config.pixel_bounds.top(), | 198 std::max(desktop_config.pixel_bounds.top(), |
| 201 std::min(desktop_config.pixel_bounds.bottom(), mouse_pos_.y()))); | 199 std::min(desktop_config.pixel_bounds.bottom(), mouse_pos_.y()))); |
| 202 | 200 |
| 203 // Convert from pixel to Density Independent Pixel coordinates. | 201 // Convert from pixel to Density Independent Pixel coordinates. |
| 204 mouse_pos_ = SkIPoint::Make( | 202 mouse_pos_.set(mouse_pos_.x() / desktop_config.dip_to_pixel_scale, |
| 205 SkScalarRound(mouse_pos_.x() / desktop_config.dip_to_pixel_scale), | 203 mouse_pos_.y() / desktop_config.dip_to_pixel_scale); |
| 206 SkScalarRound(mouse_pos_.y() / desktop_config.dip_to_pixel_scale)); | |
| 207 | 204 |
| 208 VLOG(3) << "Moving mouse to " << mouse_pos_.x() << "," << mouse_pos_.y(); | 205 VLOG(3) << "Moving mouse to " << mouse_pos_.x() << "," << mouse_pos_.y(); |
| 209 } | 206 } |
| 210 if (event.has_button() && event.has_button_down()) { | 207 if (event.has_button() && event.has_button_down()) { |
| 211 if (event.button() >= 1 && event.button() <= 3) { | 208 if (event.button() >= 1 && event.button() <= 3) { |
| 212 VLOG(2) << "Button " << event.button() | 209 VLOG(2) << "Button " << event.button() |
| 213 << (event.button_down() ? " down" : " up"); | 210 << (event.button_down() ? " down" : " up"); |
| 214 int button_change = 1 << (event.button() - 1); | 211 int button_change = 1 << (event.button() - 1); |
| 215 if (event.button_down()) | 212 if (event.button_down()) |
| 216 mouse_button_state_ |= button_change; | 213 mouse_button_state_ |= button_change; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 275 |
| 279 } // namespace | 276 } // namespace |
| 280 | 277 |
| 281 scoped_ptr<InputInjector> InputInjector::Create( | 278 scoped_ptr<InputInjector> InputInjector::Create( |
| 282 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 279 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 283 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 280 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
| 284 return scoped_ptr<InputInjector>(new InputInjectorMac(main_task_runner)); | 281 return scoped_ptr<InputInjector>(new InputInjectorMac(main_task_runner)); |
| 285 } | 282 } |
| 286 | 283 |
| 287 } // namespace remoting | 284 } // namespace remoting |
| OLD | NEW |