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

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

Issue 809903005: ui/views: Cleanup usage of scoped_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no need of Pass() Created 5 years, 11 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/views/event_monitor_aura.cc ('k') | ui/views/painter.cc » ('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"
11 #include "ui/events/event_handler.h" 11 #include "ui/events/event_handler.h"
12 #include "ui/events/event_utils.h" 12 #include "ui/events/event_utils.h"
13 13
14 namespace views { 14 namespace views {
15 15
16 // static 16 // static
17 scoped_ptr<EventMonitor> EventMonitor::CreateApplicationMonitor( 17 scoped_ptr<EventMonitor> EventMonitor::CreateApplicationMonitor(
18 ui::EventHandler* event_handler) { 18 ui::EventHandler* event_handler) {
19 return scoped_ptr<EventMonitor>(new EventMonitorMac(event_handler, nullptr)); 19 return make_scoped_ptr(new EventMonitorMac(event_handler, nullptr));
20 } 20 }
21 21
22 // static 22 // static
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 scoped_ptr<EventMonitor>( 26 return make_scoped_ptr(new EventMonitorMac(event_handler, target_window));
27 new EventMonitorMac(event_handler, target_window));
28 } 27 }
29 28
30 // static 29 // static
31 gfx::Point EventMonitor::GetLastMouseLocation() { 30 gfx::Point EventMonitor::GetLastMouseLocation() {
32 NSPoint mouseLocation = [NSEvent mouseLocation]; 31 NSPoint mouseLocation = [NSEvent mouseLocation];
33 // 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.
34 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; 33 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
35 mouseLocation.y = NSMaxY([screen frame]) - mouseLocation.y; 34 mouseLocation.y = NSMaxY([screen frame]) - mouseLocation.y;
36 return gfx::Point(mouseLocation.x, mouseLocation.y); 35 return gfx::Point(mouseLocation.x, mouseLocation.y);
37 } 36 }
38 37
39 EventMonitorMac::EventMonitorMac(ui::EventHandler* event_handler, 38 EventMonitorMac::EventMonitorMac(ui::EventHandler* event_handler,
40 gfx::NativeWindow target_window) { 39 gfx::NativeWindow target_window) {
41 DCHECK(event_handler); 40 DCHECK(event_handler);
42 monitor_ = [NSEvent addLocalMonitorForEventsMatchingMask:NSAnyEventMask 41 monitor_ = [NSEvent addLocalMonitorForEventsMatchingMask:NSAnyEventMask
43 handler:^NSEvent*(NSEvent* event) { 42 handler:^NSEvent*(NSEvent* event) {
44 if (!target_window || [event window] == target_window) { 43 if (!target_window || [event window] == target_window) {
45 scoped_ptr<ui::Event> ui_event = ui::EventFromNative(event); 44 scoped_ptr<ui::Event> ui_event = ui::EventFromNative(event);
46 event_handler->OnEvent(ui_event.get()); 45 event_handler->OnEvent(ui_event.get());
47 } 46 }
48 return event; 47 return event;
49 }]; 48 }];
50 } 49 }
51 50
52 EventMonitorMac::~EventMonitorMac() { 51 EventMonitorMac::~EventMonitorMac() {
53 [NSEvent removeMonitor:monitor_]; 52 [NSEvent removeMonitor:monitor_];
54 } 53 }
55 54
56 } // namespace views 55 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/event_monitor_aura.cc ('k') | ui/views/painter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698