| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 static const NSUInteger kEscKeyCode = 53; | 21 static const NSUInteger kEscKeyCode = 53; |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 typedef std::set<remoting::ChromotingHost*> Hosts; | 24 typedef std::set<remoting::ChromotingHost*> Hosts; |
| 25 } | 25 } |
| 26 | 26 |
| 27 @interface LocalInputMonitorImpl : NSObject { | 27 @interface LocalInputMonitorImpl : NSObject { |
| 28 @private | 28 @private |
| 29 GTMCarbonHotKey* hotKey_; | 29 GTMCarbonHotKey* hotKey_; |
| 30 CFRunLoopSourceRef mouseRunLoopSource_; | 30 CFRunLoopSourceRef mouseRunLoopSource_; |
| 31 base::mac::ScopedCFTypeRef<CFMachPortRef> mouseMachPort_; |
| 31 base::Lock hostsLock_; | 32 base::Lock hostsLock_; |
| 32 Hosts hosts_; | 33 Hosts hosts_; |
| 33 } | 34 } |
| 34 | 35 |
| 35 // Called when the hotKey is hit. | 36 // Called when the hotKey is hit. |
| 36 - (void)hotKeyHit:(GTMCarbonHotKey*)hotKey; | 37 - (void)hotKeyHit:(GTMCarbonHotKey*)hotKey; |
| 37 | 38 |
| 38 // Called when the local mouse moves | 39 // Called when the local mouse moves |
| 39 - (void)localMouseMoved:(const SkIPoint&)mousePos; | 40 - (void)localMouseMoved:(const SkIPoint&)mousePos; |
| 40 | 41 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 71 [GTMCarbonEventDispatcherHandler sharedEventDispatcherHandler]; | 72 [GTMCarbonEventDispatcherHandler sharedEventDispatcherHandler]; |
| 72 hotKey_ = [handler registerHotKey:kEscKeyCode | 73 hotKey_ = [handler registerHotKey:kEscKeyCode |
| 73 modifiers:(NSAlternateKeyMask | NSControlKeyMask) | 74 modifiers:(NSAlternateKeyMask | NSControlKeyMask) |
| 74 target:self | 75 target:self |
| 75 action:@selector(hotKeyHit:) | 76 action:@selector(hotKeyHit:) |
| 76 userInfo:nil | 77 userInfo:nil |
| 77 whenPressed:YES]; | 78 whenPressed:YES]; |
| 78 if (!hotKey_) { | 79 if (!hotKey_) { |
| 79 LOG(ERROR) << "registerHotKey failed."; | 80 LOG(ERROR) << "registerHotKey failed."; |
| 80 } | 81 } |
| 81 base::mac::ScopedCFTypeRef<CFMachPortRef> mouseMachPort(CGEventTapCreate( | 82 mouseMachPort_.reset(CGEventTapCreate( |
| 82 kCGSessionEventTap, kCGHeadInsertEventTap, kCGEventTapOptionListenOnly, | 83 kCGSessionEventTap, kCGHeadInsertEventTap, kCGEventTapOptionListenOnly, |
| 83 1 << kCGEventMouseMoved, LocalMouseMoved, self)); | 84 1 << kCGEventMouseMoved, LocalMouseMoved, self)); |
| 84 if (mouseMachPort) { | 85 if (mouseMachPort_) { |
| 85 mouseRunLoopSource_ = CFMachPortCreateRunLoopSource( | 86 mouseRunLoopSource_ = CFMachPortCreateRunLoopSource( |
| 86 NULL, mouseMachPort, 0); | 87 NULL, mouseMachPort_, 0); |
| 87 CFRunLoopAddSource( | 88 CFRunLoopAddSource( |
| 88 CFRunLoopGetMain(), mouseRunLoopSource_, kCFRunLoopCommonModes); | 89 CFRunLoopGetMain(), mouseRunLoopSource_, kCFRunLoopCommonModes); |
| 89 } else { | 90 } else { |
| 90 LOG(ERROR) << "CGEventTapCreate failed."; | 91 LOG(ERROR) << "CGEventTapCreate failed."; |
| 91 } | 92 } |
| 92 if (!hotKey_ && !mouseMachPort) { | 93 if (!hotKey_ && !mouseMachPort_) { |
| 93 [self release]; | 94 [self release]; |
| 94 return nil; | 95 return nil; |
| 95 } | 96 } |
| 96 } | 97 } |
| 97 return self; | 98 return self; |
| 98 } | 99 } |
| 99 | 100 |
| 100 - (void)hotKeyHit:(GTMCarbonHotKey*)hotKey { | 101 - (void)hotKeyHit:(GTMCarbonHotKey*)hotKey { |
| 101 base::AutoLock lock(hostsLock_); | 102 base::AutoLock lock(hostsLock_); |
| 102 for (Hosts::const_iterator i = hosts_.begin(); i != hosts_.end(); ++i) { | 103 for (Hosts::const_iterator i = hosts_.begin(); i != hosts_.end(); ++i) { |
| 103 (*i)->Shutdown(base::Closure()); | 104 (*i)->Shutdown(base::Closure()); |
| 104 } | 105 } |
| 105 } | 106 } |
| 106 | 107 |
| 107 - (void)localMouseMoved:(const SkIPoint&)mousePos { | 108 - (void)localMouseMoved:(const SkIPoint&)mousePos { |
| 108 base::AutoLock lock(hostsLock_); | 109 base::AutoLock lock(hostsLock_); |
| 109 for (Hosts::const_iterator i = hosts_.begin(); i != hosts_.end(); ++i) { | 110 for (Hosts::const_iterator i = hosts_.begin(); i != hosts_.end(); ++i) { |
| 110 (*i)->LocalMouseMoved(mousePos); | 111 (*i)->LocalMouseMoved(mousePos); |
| 111 } | 112 } |
| 112 } | 113 } |
| 113 | 114 |
| 114 - (void)invalidate { | 115 - (void)invalidate { |
| 115 if (hotKey_) { | 116 if (hotKey_) { |
| 116 GTMCarbonEventDispatcherHandler* handler = | 117 GTMCarbonEventDispatcherHandler* handler = |
| 117 [GTMCarbonEventDispatcherHandler sharedEventDispatcherHandler]; | 118 [GTMCarbonEventDispatcherHandler sharedEventDispatcherHandler]; |
| 118 [handler unregisterHotKey:hotKey_]; | 119 [handler unregisterHotKey:hotKey_]; |
| 119 hotKey_ = NULL; | 120 hotKey_ = NULL; |
| 120 } | 121 } |
| 121 if (mouseRunLoopSource_) { | 122 if (mouseRunLoopSource_) { |
| 123 CFMachPortInvalidate(mouseMachPort_); |
| 122 CFRunLoopRemoveSource( | 124 CFRunLoopRemoveSource( |
| 123 CFRunLoopGetMain(), mouseRunLoopSource_, kCFRunLoopCommonModes); | 125 CFRunLoopGetMain(), mouseRunLoopSource_, kCFRunLoopCommonModes); |
| 124 CFRelease(mouseRunLoopSource_); | 126 CFRelease(mouseRunLoopSource_); |
| 127 mouseMachPort_.reset(0); |
| 125 mouseRunLoopSource_ = NULL; | 128 mouseRunLoopSource_ = NULL; |
| 126 } | 129 } |
| 127 } | 130 } |
| 128 | 131 |
| 129 - (void)addHost:(remoting::ChromotingHost*)host { | 132 - (void)addHost:(remoting::ChromotingHost*)host { |
| 130 base::AutoLock lock(hostsLock_); | 133 base::AutoLock lock(hostsLock_); |
| 131 hosts_.insert(host); | 134 hosts_.insert(host); |
| 132 } | 135 } |
| 133 | 136 |
| 134 - (bool)removeHost:(remoting::ChromotingHost*)host { | 137 - (bool)removeHost:(remoting::ChromotingHost*)host { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 if ([local_input_monitor removeHost:host_]) { | 181 if ([local_input_monitor removeHost:host_]) { |
| 179 [local_input_monitor invalidate]; | 182 [local_input_monitor invalidate]; |
| 180 [local_input_monitor release]; | 183 [local_input_monitor release]; |
| 181 local_input_monitor = nil; | 184 local_input_monitor = nil; |
| 182 } | 185 } |
| 183 } | 186 } |
| 184 | 187 |
| 185 remoting::LocalInputMonitor* remoting::LocalInputMonitor::Create() { | 188 remoting::LocalInputMonitor* remoting::LocalInputMonitor::Create() { |
| 186 return new LocalInputMonitorMac; | 189 return new LocalInputMonitorMac; |
| 187 } | 190 } |
| OLD | NEW |