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