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

Side by Side Diff: ui/views/event_monitor_mac.mm

Issue 1380083005: Mac: Use [NSArray firstObject] for [NSScreen screens] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 unified diff | Download patch
« no previous file with comments | « ui/snapshot/snapshot_mac.mm ('k') | ui/views/widget/native_widget_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
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 #import "ui/views/event_monitor_mac.h" 5 #import "ui/views/event_monitor_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "ui/events/event.h" 10 #include "ui/events/event.h"
(...skipping 12 matching lines...) Expand all
23 scoped_ptr<EventMonitor> EventMonitor::CreateWindowMonitor( 23 scoped_ptr<EventMonitor> EventMonitor::CreateWindowMonitor(
24 ui::EventHandler* event_handler, 24 ui::EventHandler* event_handler,
25 gfx::NativeWindow target_window) { 25 gfx::NativeWindow target_window) {
26 return make_scoped_ptr(new EventMonitorMac(event_handler, target_window)); 26 return make_scoped_ptr(new EventMonitorMac(event_handler, target_window));
27 } 27 }
28 28
29 // static 29 // static
30 gfx::Point EventMonitor::GetLastMouseLocation() { 30 gfx::Point EventMonitor::GetLastMouseLocation() {
31 NSPoint mouseLocation = [NSEvent mouseLocation]; 31 NSPoint mouseLocation = [NSEvent mouseLocation];
32 // Flip coordinates to gfx (0,0 in top-left corner) using primary screen. 32 // Flip coordinates to gfx (0,0 in top-left corner) using primary screen.
33 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; 33 NSScreen* screen = [[NSScreen screens] firstObject];
34 mouseLocation.y = NSMaxY([screen frame]) - mouseLocation.y; 34 mouseLocation.y = NSMaxY([screen frame]) - mouseLocation.y;
35 return gfx::Point(mouseLocation.x, mouseLocation.y); 35 return gfx::Point(mouseLocation.x, mouseLocation.y);
36 } 36 }
37 37
38 EventMonitorMac::EventMonitorMac(ui::EventHandler* event_handler, 38 EventMonitorMac::EventMonitorMac(ui::EventHandler* event_handler,
39 gfx::NativeWindow target_window) { 39 gfx::NativeWindow target_window) {
40 DCHECK(event_handler); 40 DCHECK(event_handler);
41 monitor_ = [NSEvent addLocalMonitorForEventsMatchingMask:NSAnyEventMask 41 monitor_ = [NSEvent addLocalMonitorForEventsMatchingMask:NSAnyEventMask
42 handler:^NSEvent*(NSEvent* event) { 42 handler:^NSEvent*(NSEvent* event) {
43 if (!target_window || [event window] == target_window) { 43 if (!target_window || [event window] == target_window) {
44 scoped_ptr<ui::Event> ui_event = ui::EventFromNative(event); 44 scoped_ptr<ui::Event> ui_event = ui::EventFromNative(event);
45 if (ui_event) 45 if (ui_event)
46 event_handler->OnEvent(ui_event.get()); 46 event_handler->OnEvent(ui_event.get());
47 } 47 }
48 return event; 48 return event;
49 }]; 49 }];
50 } 50 }
51 51
52 EventMonitorMac::~EventMonitorMac() { 52 EventMonitorMac::~EventMonitorMac() {
53 [NSEvent removeMonitor:monitor_]; 53 [NSEvent removeMonitor:monitor_];
54 } 54 }
55 55
56 } // namespace views 56 } // namespace views
OLDNEW
« no previous file with comments | « ui/snapshot/snapshot_mac.mm ('k') | ui/views/widget/native_widget_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698