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

Side by Side 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, 1 month 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« 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