OLD | NEW |
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 24 matching lines...) Expand all Loading... |
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 event_handler->OnEvent(ui_event.get()); | 45 if (ui_event) |
| 46 event_handler->OnEvent(ui_event.get()); |
46 } | 47 } |
47 return event; | 48 return event; |
48 }]; | 49 }]; |
49 } | 50 } |
50 | 51 |
51 EventMonitorMac::~EventMonitorMac() { | 52 EventMonitorMac::~EventMonitorMac() { |
52 [NSEvent removeMonitor:monitor_]; | 53 [NSEvent removeMonitor:monitor_]; |
53 } | 54 } |
54 | 55 |
55 } // namespace views | 56 } // namespace views |
OLD | NEW |