chrome_application_mac.h (1876B)
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 @interface CrApplication : NSApplication { 21 @private 22 BOOL handlingSendEvent_; 23 // Array of objects implementing the CrApplicationEventHookProtocol 24 scoped_nsobject<NSMutableArray> eventHooks_; 25 } 26 @property(readonly, getter=isHandlingSendEvent, nonatomic) 27 BOOL handlingSendEvent; 28 29 // Add or remove an event hook to be called for every sendEvent: 30 // that the application receives. These handlers are called before 31 // the normal [NSApplication sendEvent:] call is made. 32 33 // This is not a good alternative to a nested event loop. It should 34 // be used only when normal event logic and notification breaks down 35 // (e.g. when clicking outside a canBecomeKey:NO window to "switch 36 // context" out of it). 37 - (void)addEventHook:(id<CrApplicationEventHookProtocol>)hook; 38 - (void)removeEventHook:(id<CrApplicationEventHookProtocol>)hook; 39 40 + (NSApplication*)sharedApplication; 41 @end 42 43 namespace chrome_application_mac { 44 45 // Controls the state of |handlingSendEvent_| in the event loop so that it is 46 // reset properly. 47 class ScopedSendingEvent { 48 public: 49 ScopedSendingEvent(); 50 ~ScopedSendingEvent(); 51 52 private: 53 CrApplication* app_; 54 BOOL handling_; 55 DISALLOW_COPY_AND_ASSIGN(ScopedSendingEvent); 56 }; 57 58 } // namespace chrome_application_mac 59 60 #endif // BASE_CHROME_APPLICATION_MAC_H_