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

Side by Side Diff: content/common/chrome_application_mac.mm

Issue 8498034: [Mac] Move event hooks from CrApplication to BrowserCrApplication. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: And copyright, sigh. Created 9 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/common/chrome_application_mac.h" 5 #import "content/common/chrome_application_mac.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 @interface CrApplication () 9 @interface CrApplication ()
10 - (void)setHandlingSendEvent:(BOOL)handlingSendEvent; 10 - (void)setHandlingSendEvent:(BOOL)handlingSendEvent;
11 @end 11 @end
12 12
13 @implementation CrApplication 13 @implementation CrApplication
14 // Initialize NSApplication using the custom subclass. Check whether NSApp 14 // Initialize NSApplication using the custom subclass. Check whether NSApp
15 // was already initialized using another class, because that would break 15 // was already initialized using another class, because that would break
16 // some things. 16 // some things.
17 + (NSApplication*)sharedApplication { 17 + (NSApplication*)sharedApplication {
18 NSApplication* app = [super sharedApplication]; 18 NSApplication* app = [super sharedApplication];
19 if (![NSApp isKindOfClass:self]) { 19 if (![NSApp isKindOfClass:self]) {
20 DLOG(ERROR) << "NSApp should be of type " << [[self className] UTF8String] 20 DLOG(ERROR) << "NSApp should be of type " << [[self className] UTF8String]
21 << ", not " << [[NSApp className] UTF8String]; 21 << ", not " << [[NSApp className] UTF8String];
22 DCHECK(false) << "NSApp is of wrong type"; 22 DCHECK(false) << "NSApp is of wrong type";
23 } 23 }
24 return app; 24 return app;
25 } 25 }
26 26
27 - (id)init {
28 if ((self = [super init])) {
29 eventHooks_.reset([[NSMutableArray alloc] init]);
30 }
31 return self;
32 }
33
34 - (BOOL)isHandlingSendEvent { 27 - (BOOL)isHandlingSendEvent {
35 return handlingSendEvent_; 28 return handlingSendEvent_;
36 } 29 }
37 30
38 - (void)setHandlingSendEvent:(BOOL)handlingSendEvent { 31 - (void)setHandlingSendEvent:(BOOL)handlingSendEvent {
39 handlingSendEvent_ = handlingSendEvent; 32 handlingSendEvent_ = handlingSendEvent;
40 } 33 }
41 34
42 - (void)clearIsHandlingSendEvent { 35 - (void)clearIsHandlingSendEvent {
43 [self setHandlingSendEvent:NO]; 36 [self setHandlingSendEvent:NO];
44 } 37 }
45 38
46 - (void)sendEvent:(NSEvent*)event { 39 - (void)sendEvent:(NSEvent*)event {
47 content::mac::ScopedSendingEvent sendingEventScoper; 40 content::mac::ScopedSendingEvent sendingEventScoper;
48 for (id<CrApplicationEventHookProtocol> handler in eventHooks_.get()) {
49 [handler hookForEvent:event];
50 }
51 [super sendEvent:event]; 41 [super sendEvent:event];
52 } 42 }
53 43
54 - (void)addEventHook:(id<CrApplicationEventHookProtocol>)handler {
55 [eventHooks_ addObject:handler];
56 }
57
58 - (void)removeEventHook:(id<CrApplicationEventHookProtocol>)handler {
59 [eventHooks_ removeObject:handler];
60 }
61
62 @end 44 @end
63 45
64 namespace chrome_application_mac { 46 namespace chrome_application_mac {
65 47
66 void RegisterCrApp() { 48 void RegisterCrApp() {
67 [CrApplication sharedApplication]; 49 [CrApplication sharedApplication];
68 } 50 }
69 51
70 } // namespace chrome_application_mac 52 } // namespace chrome_application_mac
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698