| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome_application_mac.h" | 5 #import "chrome/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 @property(readwrite, | 10 - (void)setHandlingSendEvent:(BOOL)handlingSendEvent; |
| 11 getter=isHandlingSendEvent, | |
| 12 nonatomic) BOOL handlingSendEvent; | |
| 13 @end | 11 @end |
| 14 | 12 |
| 15 @implementation CrApplication | 13 @implementation CrApplication |
| 16 @synthesize handlingSendEvent = handlingSendEvent_; | |
| 17 | |
| 18 // Initialize NSApplication using the custom subclass. Check whether NSApp | 14 // Initialize NSApplication using the custom subclass. Check whether NSApp |
| 19 // was already initialized using another class, because that would break | 15 // was already initialized using another class, because that would break |
| 20 // some things. | 16 // some things. |
| 21 + (NSApplication*)sharedApplication { | 17 + (NSApplication*)sharedApplication { |
| 22 NSApplication* app = [super sharedApplication]; | 18 NSApplication* app = [super sharedApplication]; |
| 23 if (![NSApp isKindOfClass:self]) { | 19 if (![NSApp isKindOfClass:self]) { |
| 24 LOG(ERROR) << "NSApp should be of type " << [[self className] UTF8String] | 20 LOG(ERROR) << "NSApp should be of type " << [[self className] UTF8String] |
| 25 << ", not " << [[NSApp className] UTF8String]; | 21 << ", not " << [[NSApp className] UTF8String]; |
| 26 DCHECK(false) << "NSApp is of wrong type"; | 22 DCHECK(false) << "NSApp is of wrong type"; |
| 27 } | 23 } |
| 28 return app; | 24 return app; |
| 29 } | 25 } |
| 30 | 26 |
| 31 - (id)init { | 27 - (id)init { |
| 32 if ((self = [super init])) { | 28 if ((self = [super init])) { |
| 33 eventHooks_.reset([[NSMutableArray alloc] init]); | 29 eventHooks_.reset([[NSMutableArray alloc] init]); |
| 34 } | 30 } |
| 35 return self; | 31 return self; |
| 36 } | 32 } |
| 37 | 33 |
| 34 - (BOOL)isHandlingSendEvent { |
| 35 return handlingSendEvent_; |
| 36 } |
| 37 |
| 38 - (void)setHandlingSendEvent:(BOOL)handlingSendEvent { |
| 39 handlingSendEvent_ = handlingSendEvent; |
| 40 } |
| 41 |
| 38 - (void)sendEvent:(NSEvent*)event { | 42 - (void)sendEvent:(NSEvent*)event { |
| 39 chrome_application_mac::ScopedSendingEvent sendingEventScoper; | 43 chrome_application_mac::ScopedSendingEvent sendingEventScoper; |
| 40 for (id<CrApplicationEventHookProtocol> handler in eventHooks_.get()) { | 44 for (id<CrApplicationEventHookProtocol> handler in eventHooks_.get()) { |
| 41 [handler hookForEvent:event]; | 45 [handler hookForEvent:event]; |
| 42 } | 46 } |
| 43 [super sendEvent:event]; | 47 [super sendEvent:event]; |
| 44 } | 48 } |
| 45 | 49 |
| 46 - (void)addEventHook:(id<CrApplicationEventHookProtocol>)handler { | 50 - (void)addEventHook:(id<CrApplicationEventHookProtocol>)handler { |
| 47 [eventHooks_ addObject:handler]; | 51 [eventHooks_ addObject:handler]; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 59 : app_(static_cast<CrApplication*>([CrApplication sharedApplication])), | 63 : app_(static_cast<CrApplication*>([CrApplication sharedApplication])), |
| 60 handling_([app_ isHandlingSendEvent]) { | 64 handling_([app_ isHandlingSendEvent]) { |
| 61 [app_ setHandlingSendEvent:YES]; | 65 [app_ setHandlingSendEvent:YES]; |
| 62 } | 66 } |
| 63 | 67 |
| 64 ScopedSendingEvent::~ScopedSendingEvent() { | 68 ScopedSendingEvent::~ScopedSendingEvent() { |
| 65 [app_ setHandlingSendEvent:handling_]; | 69 [app_ setHandlingSendEvent:handling_]; |
| 66 } | 70 } |
| 67 | 71 |
| 68 } // namespace chrome_application_mac | 72 } // namespace chrome_application_mac |
| OLD | NEW |