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/local_input_monitor.h" | 5 #include "remoting/host/local_input_monitor.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/mac/scoped_cftyperef.h" | 14 #include "base/mac/scoped_cftyperef.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
18 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
19 #include "remoting/host/client_session_control.h" | 19 #include "remoting/host/client_session_control.h" |
20 #include "third_party/skia/include/core/SkPoint.h" | |
21 #import "third_party/GTM/AppKit/GTMCarbonEvent.h" | 20 #import "third_party/GTM/AppKit/GTMCarbonEvent.h" |
| 21 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
22 | 22 |
23 // Esc Key Code is 53. | 23 // Esc Key Code is 53. |
24 // http://boredzo.org/blog/wp-content/uploads/2007/05/IMTx-virtual-keycodes.pdf | 24 // http://boredzo.org/blog/wp-content/uploads/2007/05/IMTx-virtual-keycodes.pdf |
25 static const NSUInteger kEscKeyCode = 53; | 25 static const NSUInteger kEscKeyCode = 53; |
26 | 26 |
27 namespace remoting { | 27 namespace remoting { |
28 namespace { | 28 namespace { |
29 | 29 |
30 class LocalInputMonitorMac : public base::NonThreadSafe, | 30 class LocalInputMonitorMac : public base::NonThreadSafe, |
31 public LocalInputMonitor { | 31 public LocalInputMonitor { |
32 public: | 32 public: |
33 // Invoked by LocalInputMonitorManager. | 33 // Invoked by LocalInputMonitorManager. |
34 class EventHandler { | 34 class EventHandler { |
35 public: | 35 public: |
36 virtual ~EventHandler() {} | 36 virtual ~EventHandler() {} |
37 | 37 |
38 virtual void OnLocalMouseMoved(const SkIPoint& position) = 0; | 38 virtual void OnLocalMouseMoved(const webrtc::DesktopVector& position) = 0; |
39 virtual void OnDisconnectShortcut() = 0; | 39 virtual void OnDisconnectShortcut() = 0; |
40 }; | 40 }; |
41 | 41 |
42 LocalInputMonitorMac( | 42 LocalInputMonitorMac( |
43 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 43 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
44 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 44 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
45 base::WeakPtr<ClientSessionControl> client_session_control); | 45 base::WeakPtr<ClientSessionControl> client_session_control); |
46 virtual ~LocalInputMonitorMac(); | 46 virtual ~LocalInputMonitorMac(); |
47 | 47 |
48 private: | 48 private: |
(...skipping 14 matching lines...) Expand all Loading... |
63 base::ScopedCFTypeRef<CFMachPortRef> mouseMachPort_; | 63 base::ScopedCFTypeRef<CFMachPortRef> mouseMachPort_; |
64 remoting::LocalInputMonitorMac::EventHandler* monitor_; | 64 remoting::LocalInputMonitorMac::EventHandler* monitor_; |
65 } | 65 } |
66 | 66 |
67 - (id)initWithMonitor:(remoting::LocalInputMonitorMac::EventHandler*)monitor; | 67 - (id)initWithMonitor:(remoting::LocalInputMonitorMac::EventHandler*)monitor; |
68 | 68 |
69 // Called when the hotKey is hit. | 69 // Called when the hotKey is hit. |
70 - (void)hotKeyHit:(GTMCarbonHotKey*)hotKey; | 70 - (void)hotKeyHit:(GTMCarbonHotKey*)hotKey; |
71 | 71 |
72 // Called when the local mouse moves | 72 // Called when the local mouse moves |
73 - (void)localMouseMoved:(const SkIPoint&)mousePos; | 73 - (void)localMouseMoved:(const webrtc::DesktopVector&)mousePos; |
74 | 74 |
75 // Must be called when the LocalInputMonitorManager is no longer to be used. | 75 // Must be called when the LocalInputMonitorManager is no longer to be used. |
76 // Similar to NSTimer in that more than a simple release is required. | 76 // Similar to NSTimer in that more than a simple release is required. |
77 - (void)invalidate; | 77 - (void)invalidate; |
78 | 78 |
79 @end | 79 @end |
80 | 80 |
81 static CGEventRef LocalMouseMoved(CGEventTapProxy proxy, CGEventType type, | 81 static CGEventRef LocalMouseMoved(CGEventTapProxy proxy, CGEventType type, |
82 CGEventRef event, void* context) { | 82 CGEventRef event, void* context) { |
83 int64_t pid = CGEventGetIntegerValueField(event, kCGEventSourceUnixProcessID); | 83 int64_t pid = CGEventGetIntegerValueField(event, kCGEventSourceUnixProcessID); |
84 if (pid == 0) { | 84 if (pid == 0) { |
85 CGPoint cgMousePos = CGEventGetLocation(event); | 85 CGPoint cgMousePos = CGEventGetLocation(event); |
86 SkIPoint mousePos = SkIPoint::Make(cgMousePos.x, cgMousePos.y); | 86 webrtc::DesktopVector mousePos(cgMousePos.x, cgMousePos.y); |
87 [static_cast<LocalInputMonitorManager*>(context) localMouseMoved:mousePos]; | 87 [static_cast<LocalInputMonitorManager*>(context) localMouseMoved:mousePos]; |
88 } | 88 } |
89 return NULL; | 89 return NULL; |
90 } | 90 } |
91 | 91 |
92 @implementation LocalInputMonitorManager | 92 @implementation LocalInputMonitorManager |
93 | 93 |
94 - (id)initWithMonitor:(remoting::LocalInputMonitorMac::EventHandler*)monitor { | 94 - (id)initWithMonitor:(remoting::LocalInputMonitorMac::EventHandler*)monitor { |
95 if ((self = [super init])) { | 95 if ((self = [super init])) { |
96 monitor_ = monitor; | 96 monitor_ = monitor; |
(...skipping 25 matching lines...) Expand all Loading... |
122 return nil; | 122 return nil; |
123 } | 123 } |
124 } | 124 } |
125 return self; | 125 return self; |
126 } | 126 } |
127 | 127 |
128 - (void)hotKeyHit:(GTMCarbonHotKey*)hotKey { | 128 - (void)hotKeyHit:(GTMCarbonHotKey*)hotKey { |
129 monitor_->OnDisconnectShortcut(); | 129 monitor_->OnDisconnectShortcut(); |
130 } | 130 } |
131 | 131 |
132 - (void)localMouseMoved:(const SkIPoint&)mousePos { | 132 - (void)localMouseMoved:(const webrtc::DesktopVector&)mousePos { |
133 monitor_->OnLocalMouseMoved(mousePos); | 133 monitor_->OnLocalMouseMoved(mousePos); |
134 } | 134 } |
135 | 135 |
136 - (void)invalidate { | 136 - (void)invalidate { |
137 if (hotKey_) { | 137 if (hotKey_) { |
138 GTMCarbonEventDispatcherHandler* handler = | 138 GTMCarbonEventDispatcherHandler* handler = |
139 [GTMCarbonEventDispatcherHandler sharedEventDispatcherHandler]; | 139 [GTMCarbonEventDispatcherHandler sharedEventDispatcherHandler]; |
140 [handler unregisterHotKey:hotKey_]; | 140 [handler unregisterHotKey:hotKey_]; |
141 hotKey_ = NULL; | 141 hotKey_ = NULL; |
142 } | 142 } |
(...skipping 24 matching lines...) Expand all Loading... |
167 void Stop(); | 167 void Stop(); |
168 | 168 |
169 private: | 169 private: |
170 friend class base::RefCountedThreadSafe<Core>; | 170 friend class base::RefCountedThreadSafe<Core>; |
171 virtual ~Core(); | 171 virtual ~Core(); |
172 | 172 |
173 void StartOnUiThread(); | 173 void StartOnUiThread(); |
174 void StopOnUiThread(); | 174 void StopOnUiThread(); |
175 | 175 |
176 // EventHandler interface. | 176 // EventHandler interface. |
177 virtual void OnLocalMouseMoved(const SkIPoint& position) OVERRIDE; | 177 virtual void OnLocalMouseMoved( |
| 178 const webrtc::DesktopVector& position) OVERRIDE; |
178 virtual void OnDisconnectShortcut() OVERRIDE; | 179 virtual void OnDisconnectShortcut() OVERRIDE; |
179 | 180 |
180 // Task runner on which public methods of this class must be called. | 181 // Task runner on which public methods of this class must be called. |
181 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; | 182 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; |
182 | 183 |
183 // Task runner on which |window_| is created. | 184 // Task runner on which |window_| is created. |
184 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 185 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
185 | 186 |
186 LocalInputMonitorManager* manager_; | 187 LocalInputMonitorManager* manager_; |
187 | 188 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 } | 242 } |
242 | 243 |
243 void LocalInputMonitorMac::Core::StopOnUiThread() { | 244 void LocalInputMonitorMac::Core::StopOnUiThread() { |
244 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 245 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
245 | 246 |
246 [manager_ invalidate]; | 247 [manager_ invalidate]; |
247 [manager_ release]; | 248 [manager_ release]; |
248 manager_ = nil; | 249 manager_ = nil; |
249 } | 250 } |
250 | 251 |
251 void LocalInputMonitorMac::Core::OnLocalMouseMoved(const SkIPoint& position) { | 252 void LocalInputMonitorMac::Core::OnLocalMouseMoved( |
| 253 const webrtc::DesktopVector& position) { |
252 caller_task_runner_->PostTask( | 254 caller_task_runner_->PostTask( |
253 FROM_HERE, base::Bind(&ClientSessionControl::OnLocalMouseMoved, | 255 FROM_HERE, base::Bind(&ClientSessionControl::OnLocalMouseMoved, |
254 client_session_control_, | 256 client_session_control_, |
255 position)); | 257 position)); |
256 } | 258 } |
257 | 259 |
258 void LocalInputMonitorMac::Core::OnDisconnectShortcut() { | 260 void LocalInputMonitorMac::Core::OnDisconnectShortcut() { |
259 caller_task_runner_->PostTask( | 261 caller_task_runner_->PostTask( |
260 FROM_HERE, base::Bind(&ClientSessionControl::DisconnectSession, | 262 FROM_HERE, base::Bind(&ClientSessionControl::DisconnectSession, |
261 client_session_control_)); | 263 client_session_control_)); |
262 } | 264 } |
263 | 265 |
264 } // namespace | 266 } // namespace |
265 | 267 |
266 scoped_ptr<LocalInputMonitor> LocalInputMonitor::Create( | 268 scoped_ptr<LocalInputMonitor> LocalInputMonitor::Create( |
267 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 269 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
268 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, | 270 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
269 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 271 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
270 base::WeakPtr<ClientSessionControl> client_session_control) { | 272 base::WeakPtr<ClientSessionControl> client_session_control) { |
271 return scoped_ptr<LocalInputMonitor>( | 273 return scoped_ptr<LocalInputMonitor>( |
272 new LocalInputMonitorMac(caller_task_runner, | 274 new LocalInputMonitorMac(caller_task_runner, |
273 ui_task_runner, | 275 ui_task_runner, |
274 client_session_control)); | 276 client_session_control)); |
275 } | 277 } |
276 | 278 |
277 } // namespace remoting | 279 } // namespace remoting |
OLD | NEW |