Chromium Code Reviews| 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" |
| 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 EventMonitor* EventMonitor::Create(ui::EventHandler* event_handler) { |
| 16 return new EventMonitorMac(event_handler); | 16 return new EventMonitorMac(event_handler, nullptr); |
| 17 } | 17 } |
| 18 | 18 |
| 19 // static | 19 // static |
| 20 EventMonitor* EventMonitor::Create(ui::EventHandler* event_handler, | |
| 21 gfx::NativeWindow target_window) { | |
| 22 return new EventMonitorMac(event_handler, target_window); | |
| 23 } | |
| 24 | |
| 25 // static | |
| 20 gfx::Point EventMonitor::GetLastMouseLocation() { | 26 gfx::Point EventMonitor::GetLastMouseLocation() { |
| 21 NSPoint mouseLocation = [NSEvent mouseLocation]; | 27 NSPoint mouseLocation = [NSEvent mouseLocation]; |
| 22 // Flip coordinates to gfx (0,0 in top-left corner) using primary screen. | 28 // Flip coordinates to gfx (0,0 in top-left corner) using primary screen. |
| 23 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | 29 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| 24 mouseLocation.y = NSMaxY([screen frame]) - mouseLocation.y; | 30 mouseLocation.y = NSMaxY([screen frame]) - mouseLocation.y; |
| 25 return gfx::Point(mouseLocation.x, mouseLocation.y); | 31 return gfx::Point(mouseLocation.x, mouseLocation.y); |
|
tapted
2014/11/20 22:39:02
also orthogonal, but we probably should move this
Andre
2014/11/21 00:28:28
Yeah, we should add ScreenPointFromNSPoint there.
| |
| 26 } | 32 } |
| 27 | 33 |
| 28 EventMonitorMac::EventMonitorMac(ui::EventHandler* event_handler) { | 34 EventMonitorMac::EventMonitorMac(ui::EventHandler* event_handler, |
| 35 gfx::NativeWindow target_window) { | |
| 29 DCHECK(event_handler); | 36 DCHECK(event_handler); |
| 30 monitor_ = [NSEvent addLocalMonitorForEventsMatchingMask:NSAnyEventMask | 37 monitor_ = [NSEvent addLocalMonitorForEventsMatchingMask:NSAnyEventMask |
| 31 handler:^NSEvent*(NSEvent* event){ | 38 handler:^NSEvent*(NSEvent* event){ |
| 32 scoped_ptr<ui::Event> ui_event = ui::EventFromNative(event); | 39 if (!target_window || [event window] == target_window) { |
|
tapted
2014/11/20 22:39:02
Can the EventMonitorMac outlive this NSWindow?
(M
Andre
2014/11/21 00:28:28
There is that risk, same with EventMonitorAura as
tapted
2014/11/21 00:57:34
WidgetObserver might be nicer, in which case these
Andre
2014/12/10 00:18:13
Done.
Added the comment.
| |
| 33 event_handler->OnEvent(ui_event.get()); | 40 scoped_ptr<ui::Event> ui_event = ui::EventFromNative(event); |
| 41 event_handler->OnEvent(ui_event.get()); | |
| 42 } | |
| 34 return event; | 43 return event; |
| 35 }]; | 44 }]; |
| 36 } | 45 } |
| 37 | 46 |
| 38 EventMonitorMac::~EventMonitorMac() { | 47 EventMonitorMac::~EventMonitorMac() { |
| 39 [NSEvent removeMonitor:monitor_]; | 48 [NSEvent removeMonitor:monitor_]; |
| 40 } | 49 } |
| 41 | 50 |
| 42 } // namespace views | 51 } // namespace views |
| OLD | NEW |