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

Unified Diff: content/public/browser/event_hook_application_mac.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: Created EventHookApplication in content 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: content/public/browser/event_hook_application_mac.mm
diff --git a/content/public/browser/event_hook_application_mac.mm b/content/public/browser/event_hook_application_mac.mm
new file mode 100644
index 0000000000000000000000000000000000000000..e21c801c17fd78ba6c4fde8e071cf51d306b25e8
--- /dev/null
+++ b/content/public/browser/event_hook_application_mac.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 "content/public/browser/event_hook_application_mac.h"
+
+#import "base/mac/scoped_sending_event.h"
+#import "base/logging.h"
+
+@implementation EventHookApplication
+
+// 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<EventHookProtocol>)handler {
+ [eventHooks_ addObject:handler];
+}
+
+- (void)removeEventHook:(id<EventHookProtocol>)handler {
+ [eventHooks_ removeObject:handler];
+}
+
+- (void)sendEvent:(NSEvent*)event {
+ base::mac::ScopedSendingEvent sendingEventScoper;
+ for (id<EventHookProtocol> handler in eventHooks_.get()) {
+ [handler hookForEvent:event];
+ }
+ [super sendEvent:event];
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698