1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style license that can be 5 // found in the LICENSE file. 6 7 #ifndef BASE_CHROME_APPLICATION_MAC_H_ 8 #define BASE_CHROME_APPLICATION_MAC_H_ 9 10 #import <AppKit/AppKit.h> 11 12 #include "base/basictypes.h" 13 #include "base/scoped_nsobject.h" 14 15 // Event hooks must implement this protocol. 16 @protocol CrApplicationEventHookProtocol 17 - (void)hookForEvent:(NSEvent*)theEvent; 18 @end 19 20 21 @interface CrApplication : NSApplication { 22 @private 23 BOOL handlingSendEvent_; 24 // Array of objects implementing the CrApplicationEventHookProtocol 25 scoped_nsobject<NSMutableArray> eventHooks_; 26 } 27 @property(readonly, 28 getter=isHandlingSendEvent, 29 nonatomic) BOOL handlingSendEvent; 30 31 // Add or remove an event hook to be called for every sendEvent: 32 // that the application receives. These handlers are called before 33 // the normal [NSApplication sendEvent:] call is made. 34 35 // This is not a good alternative to a nested event loop. It should 36 // be used only when normal event logic and notification breaks down 37 // (e.g. when clicking outside a canBecomeKey:NO window to "switch 38 // context" out of it). 39 - (void)addEventHook:(id<CrApplicationEventHookProtocol>)hook; 40 - (void)removeEventHook:(id<CrApplicationEventHookProtocol>)hook; 41 42 + (NSApplication*)sharedApplication; 43 @end 44 45 namespace chrome_application_mac { 46 47 // Controls the state of |handlingSendEvent_| in the event loop so that it is 48 // reset properly. 49 class ScopedSendingEvent { 50 public: 51 ScopedSendingEvent(); 52 ~ScopedSendingEvent(); 53 54 private: 55 CrApplication* app_; 56 BOOL handling_; 57 DISALLOW_COPY_AND_ASSIGN(ScopedSendingEvent); 58 }; 59 60 } // chrome_application_mac 61 62 #endif // BASE_CHROME_APPLICATION_MAC_H_ 63