| 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
|
|
|