Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Unified Diff: ui/views/event_monitor_mac.mm

Issue 678823002: MacViews: Create abstraction for event monitoring (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@views-tabs
Patch Set: Rebase Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/event_monitor_mac.h ('k') | ui/views/event_monitor_mac_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/event_monitor_mac.mm
diff --git a/ui/views/event_monitor_mac.mm b/ui/views/event_monitor_mac.mm
new file mode 100644
index 0000000000000000000000000000000000000000..a04f292550447e5d92b6a88c3205afb1f78d11ef
--- /dev/null
+++ b/ui/views/event_monitor_mac.mm
@@ -0,0 +1,42 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/views/event_monitor_mac.h"
+
+#include "base/logging.h"
+#include "ui/events/event.h"
+#include "ui/events/event_handler.h"
+#include "ui/events/event_utils.h"
+
+namespace views {
+
+// static
+EventMonitor* EventMonitor::Create(ui::EventHandler* event_handler) {
+ return new EventMonitorMac(event_handler);
+}
+
+// static
+gfx::Point EventMonitor::GetLastMouseLocation() {
+ NSPoint mouseLocation = [NSEvent mouseLocation];
+ // Flip coordinates to gfx (0,0 in top-left corner) using primary screen.
+ NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
+ mouseLocation.y = NSMaxY([screen frame]) - mouseLocation.y;
+ return gfx::Point(mouseLocation.x, mouseLocation.y);
+}
+
+EventMonitorMac::EventMonitorMac(ui::EventHandler* event_handler) {
+ DCHECK(event_handler);
+ monitor_ = [NSEvent addLocalMonitorForEventsMatchingMask:NSAnyEventMask
+ handler:^NSEvent*(NSEvent* event){
+ scoped_ptr<ui::Event> ui_event = ui::EventFromNative(event);
+ event_handler->OnEvent(ui_event.get());
+ return event;
+ }];
+}
+
+EventMonitorMac::~EventMonitorMac() {
+ [NSEvent removeMonitor:monitor_];
+}
+
+} // namespace views
« no previous file with comments | « ui/views/event_monitor_mac.h ('k') | ui/views/event_monitor_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698