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

Unified Diff: ui/views/event_monitor_mac.mm

Issue 793003004: MacViews: Implement event monitoring for a specific window (Reland) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Created 6 years 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
index a04f292550447e5d92b6a88c3205afb1f78d11ef..43ca5713d90fee73b7bcf36277facebbaea10595 100644
--- a/ui/views/event_monitor_mac.mm
+++ b/ui/views/event_monitor_mac.mm
@@ -2,7 +2,9 @@
// 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"
+#import "ui/views/event_monitor_mac.h"
+
+#import <Cocoa/Cocoa.h>
#include "base/logging.h"
#include "ui/events/event.h"
@@ -12,8 +14,17 @@
namespace views {
// static
-EventMonitor* EventMonitor::Create(ui::EventHandler* event_handler) {
- return new EventMonitorMac(event_handler);
+scoped_ptr<EventMonitor> EventMonitor::CreateApplicationMonitor(
+ ui::EventHandler* event_handler) {
+ return scoped_ptr<EventMonitor>(new EventMonitorMac(event_handler, nullptr));
+}
+
+// static
+scoped_ptr<EventMonitor> EventMonitor::CreateWindowMonitor(
+ ui::EventHandler* event_handler,
+ gfx::NativeWindow target_window) {
+ return scoped_ptr<EventMonitor>(
+ new EventMonitorMac(event_handler, target_window));
}
// static
@@ -25,14 +36,17 @@ gfx::Point EventMonitor::GetLastMouseLocation() {
return gfx::Point(mouseLocation.x, mouseLocation.y);
}
-EventMonitorMac::EventMonitorMac(ui::EventHandler* event_handler) {
+EventMonitorMac::EventMonitorMac(ui::EventHandler* event_handler,
+ gfx::NativeWindow target_window) {
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;
- }];
+ handler:^NSEvent*(NSEvent* event) {
+ if (!target_window || [event window] == target_window) {
+ scoped_ptr<ui::Event> ui_event = ui::EventFromNative(event);
+ event_handler->OnEvent(ui_event.get());
+ }
+ return event;
+ }];
}
EventMonitorMac::~EventMonitorMac() {
« 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