Add include.
[chromium-blink-merge.git] / ui / views / event_monitor_mac.mm
bloba04f292550447e5d92b6a88c3205afb1f78d11ef
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.
5 #include "ui/views/event_monitor_mac.h"
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"
12 namespace views {
14 // static
15 EventMonitor* EventMonitor::Create(ui::EventHandler* event_handler) {
16   return new EventMonitorMac(event_handler);
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);
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               }];
38 EventMonitorMac::~EventMonitorMac() {
39   [NSEvent removeMonitor:monitor_];
42 }  // namespace views