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

Unified Diff: ui/base/cocoa/event_hook_application.mm

Issue 11498008: RenderWidget popup should be a NSWindow so it can go outside the main window. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Shouldn't be calling setParentWindow Created 8 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
Index: ui/base/cocoa/event_hook_application.mm
diff --git a/ui/base/cocoa/event_hook_application.mm b/ui/base/cocoa/event_hook_application.mm
new file mode 100644
index 0000000000000000000000000000000000000000..faebb91ace4c7987b0bf4364ed429a041c01c221
--- /dev/null
+++ b/ui/base/cocoa/event_hook_application.mm
@@ -0,0 +1,52 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ui/base/cocoa/event_hook_application.h"
+
+#import "base/mac/scoped_sending_event.h"
+#import "base/logging.h"
+
+@implementation CrEventHookApplication
+
+// Initialize NSApplication using the custom subclass. Check whether NSApp
+// was already initialized using another class, because that would break
+// some things.
++ (NSApplication*)sharedApplication {
+ NSApplication* app = [super sharedApplication];
+
+ // +sharedApplication initializes the global NSApp, so if a specific
+ // NSApplication subclass is requested, require that to be the one
+ // delivered. The practical effect is to require a consistent NSApp
+ // across the executable.
+ CHECK([NSApp isKindOfClass:self])
+ << "NSApp must be of type " << [[self className] UTF8String]
+ << ", not " << [[NSApp className] UTF8String];
+
+ return app;
+}
+
+- (id)init {
+ if ((self = [super init])) {
+ eventHooks_.reset([[NSMutableArray alloc] init]);
+ }
+ return self;
+}
+
+- (void)addEventHook:(id<CrEventHookProtocol>)handler {
+ [eventHooks_ addObject:handler];
+}
+
+- (void)removeEventHook:(id<CrEventHookProtocol>)handler {
+ [eventHooks_ removeObject:handler];
+}
+
+- (void)sendEvent:(NSEvent*)event {
+ base::mac::ScopedSendingEvent sendingEventScoper;
+ for (id<CrEventHookProtocol> handler in eventHooks_.get()) {
+ [handler hookForEvent:event];
+ }
+ [super sendEvent:event];
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698