michael@0: // Copyright (c) 2009 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef BASE_CHROME_APPLICATION_MAC_H_ michael@0: #define BASE_CHROME_APPLICATION_MAC_H_ michael@0: michael@0: #import michael@0: michael@0: #include "base/basictypes.h" michael@0: #include "base/scoped_nsobject.h" michael@0: michael@0: // Event hooks must implement this protocol. michael@0: @protocol CrApplicationEventHookProtocol michael@0: - (void)hookForEvent:(NSEvent*)theEvent; michael@0: @end michael@0: michael@0: michael@0: @interface CrApplication : NSApplication { michael@0: @private michael@0: BOOL handlingSendEvent_; michael@0: // Array of objects implementing the CrApplicationEventHookProtocol michael@0: scoped_nsobject eventHooks_; michael@0: } michael@0: @property(readonly, michael@0: getter=isHandlingSendEvent, michael@0: nonatomic) BOOL handlingSendEvent; michael@0: michael@0: // Add or remove an event hook to be called for every sendEvent: michael@0: // that the application receives. These handlers are called before michael@0: // the normal [NSApplication sendEvent:] call is made. michael@0: michael@0: // This is not a good alternative to a nested event loop. It should michael@0: // be used only when normal event logic and notification breaks down michael@0: // (e.g. when clicking outside a canBecomeKey:NO window to "switch michael@0: // context" out of it). michael@0: - (void)addEventHook:(id)hook; michael@0: - (void)removeEventHook:(id)hook; michael@0: michael@0: + (NSApplication*)sharedApplication; michael@0: @end michael@0: michael@0: namespace chrome_application_mac { michael@0: michael@0: // Controls the state of |handlingSendEvent_| in the event loop so that it is michael@0: // reset properly. michael@0: class ScopedSendingEvent { michael@0: public: michael@0: ScopedSendingEvent(); michael@0: ~ScopedSendingEvent(); michael@0: michael@0: private: michael@0: CrApplication* app_; michael@0: BOOL handling_; michael@0: DISALLOW_COPY_AND_ASSIGN(ScopedSendingEvent); michael@0: }; michael@0: michael@0: } // chrome_application_mac michael@0: michael@0: #endif // BASE_CHROME_APPLICATION_MAC_H_