OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/views/event_monitor_mac.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "ui/events/event.h" |
| 9 #include "ui/events/event_handler.h" |
| 10 #include "ui/events/event_utils.h" |
| 11 |
| 12 namespace views { |
| 13 |
| 14 // static |
| 15 EventMonitor* EventMonitor::Create(ui::EventHandler* event_handler) { |
| 16 return new EventMonitorMac(event_handler); |
| 17 } |
| 18 |
| 19 // static |
| 20 gfx::Point EventMonitor::GetLastMouseLocation() { |
| 21 NSPoint mouseLocation = [NSEvent mouseLocation]; |
| 22 // Flip coordinates to gfx (0,0 in top-left corner) using primary screen. |
| 23 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| 24 mouseLocation.y = NSMaxY([screen frame]) - mouseLocation.y; |
| 25 return gfx::Point(mouseLocation.x, mouseLocation.y); |
| 26 } |
| 27 |
| 28 EventMonitorMac::EventMonitorMac(ui::EventHandler* event_handler) { |
| 29 DCHECK(event_handler); |
| 30 monitor_ = [NSEvent addLocalMonitorForEventsMatchingMask:NSAnyEventMask |
| 31 handler:^NSEvent*(NSEvent* event){ |
| 32 scoped_ptr<ui::Event> ui_event = ui::EventFromNative(event); |
| 33 event_handler->OnEvent(ui_event.get()); |
| 34 return event; |
| 35 }]; |
| 36 } |
| 37 |
| 38 EventMonitorMac::~EventMonitorMac() { |
| 39 [NSEvent removeMonitor:monitor_]; |
| 40 } |
| 41 |
| 42 } // namespace views |
OLD | NEW |