OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "ui/views/event_monitor_mac.h" | 5 #include "ui/views/event_monitor_mac.h" |
tapted
2014/12/10 02:58:27
nit: import (since it has an `id`)
Andre
2014/12/10 22:58:05
Done.
| |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/events/event.h" | 8 #include "ui/events/event.h" |
9 #include "ui/events/event_handler.h" | 9 #include "ui/events/event_handler.h" |
10 #include "ui/events/event_utils.h" | 10 #include "ui/events/event_utils.h" |
11 | 11 |
12 namespace views { | 12 namespace views { |
13 | 13 |
14 // static | 14 // static |
15 EventMonitor* EventMonitor::Create(ui::EventHandler* event_handler) { | 15 scoped_ptr<EventMonitor> EventMonitor::CreateApplicationMonitor( |
16 return new EventMonitorMac(event_handler); | 16 ui::EventHandler* event_handler) { |
17 return scoped_ptr<EventMonitor>(new EventMonitorMac(event_handler, nullptr)); | |
17 } | 18 } |
18 | 19 |
19 // static | 20 // static |
21 scoped_ptr<EventMonitor> EventMonitor::CreateWindowMonitor( | |
22 ui::EventHandler* event_handler, | |
23 gfx::NativeWindow target_window) { | |
24 return scoped_ptr<EventMonitor>( | |
25 new EventMonitorMac(event_handler, target_window)); | |
26 } | |
27 | |
28 // static | |
20 gfx::Point EventMonitor::GetLastMouseLocation() { | 29 gfx::Point EventMonitor::GetLastMouseLocation() { |
21 NSPoint mouseLocation = [NSEvent mouseLocation]; | 30 NSPoint mouseLocation = [NSEvent mouseLocation]; |
22 // Flip coordinates to gfx (0,0 in top-left corner) using primary screen. | 31 // Flip coordinates to gfx (0,0 in top-left corner) using primary screen. |
23 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | 32 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
24 mouseLocation.y = NSMaxY([screen frame]) - mouseLocation.y; | 33 mouseLocation.y = NSMaxY([screen frame]) - mouseLocation.y; |
25 return gfx::Point(mouseLocation.x, mouseLocation.y); | 34 return gfx::Point(mouseLocation.x, mouseLocation.y); |
26 } | 35 } |
27 | 36 |
28 EventMonitorMac::EventMonitorMac(ui::EventHandler* event_handler) { | 37 EventMonitorMac::EventMonitorMac(ui::EventHandler* event_handler, |
38 gfx::NativeWindow target_window) { | |
29 DCHECK(event_handler); | 39 DCHECK(event_handler); |
30 monitor_ = [NSEvent addLocalMonitorForEventsMatchingMask:NSAnyEventMask | 40 monitor_ = [NSEvent addLocalMonitorForEventsMatchingMask:NSAnyEventMask |
31 handler:^NSEvent*(NSEvent* event){ | 41 handler:^NSEvent*(NSEvent* event){ |
32 scoped_ptr<ui::Event> ui_event = ui::EventFromNative(event); | 42 if (!target_window || [event window] == target_window) { |
tapted
2014/12/10 02:58:27
So block formatting was taken out of the official
Andre
2014/12/10 22:58:05
Done.
| |
33 event_handler->OnEvent(ui_event.get()); | 43 scoped_ptr<ui::Event> ui_event = ui::EventFromNative(event); |
44 event_handler->OnEvent(ui_event.get()); | |
45 } | |
34 return event; | 46 return event; |
35 }]; | 47 }]; |
36 } | 48 } |
37 | 49 |
38 EventMonitorMac::~EventMonitorMac() { | 50 EventMonitorMac::~EventMonitorMac() { |
39 [NSEvent removeMonitor:monitor_]; | 51 [NSEvent removeMonitor:monitor_]; |
40 } | 52 } |
41 | 53 |
42 } // namespace views | 54 } // namespace views |
OLD | NEW |