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
3 // found in the LICENSE file.
5 #ifndef CONTENT_COMMON_CHROME_APPLICATION_MAC_H_
6 #define CONTENT_COMMON_CHROME_APPLICATION_MAC_H_
11 #import <AppKit/AppKit.h>
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_nsobject.h"
15 #include "base/message_pump_mac.h"
17 // Event hooks must implement this protocol.
18 @protocol CrApplicationEventHookProtocol
19 - (void)hookForEvent
:(NSEvent
*)theEvent
;
23 @interface CrApplication
: NSApplication
<CrAppProtocol
> {
25 BOOL handlingSendEvent_
;
26 // Array of objects implementing the CrApplicationEventHookProtocol
27 scoped_nsobject
<NSMutableArray
> eventHooks_
;
29 - (BOOL
)isHandlingSendEvent
;
31 // Unconditionally clears |handlingSendEvent_|. This should not be
32 // used except in recovering from some sort of exceptional condition.
33 - (void)clearIsHandlingSendEvent
;
35 // Add or remove an event hook to be called for every sendEvent:
36 // that the application receives. These handlers are called before
37 // the normal [NSApplication sendEvent:] call is made.
39 // This is not a good alternative to a nested event loop. It should
40 // be used only when normal event logic and notification breaks down
41 // (e.g. when clicking outside a canBecomeKey:NO window to "switch
42 // context" out of it).
43 - (void)addEventHook
:(id
<CrApplicationEventHookProtocol
>)hook
;
44 - (void)removeEventHook
:(id
<CrApplicationEventHookProtocol
>)hook
;
46 + (NSApplication
*)sharedApplication
;
49 namespace chrome_application_mac
{
51 // Controls the state of |handlingSendEvent_| in the event loop so that it is
53 class ScopedSendingEvent
{
56 ~ScopedSendingEvent();
61 DISALLOW_COPY_AND_ASSIGN(ScopedSendingEvent
);
64 } // namespace chrome_application_mac
66 #endif // defined(__OBJC__)
68 namespace chrome_application_mac
{
70 // To be used to instantiate CrApplication from C++ code.
73 } // namespace chrome_application_mac
75 #endif // CONTENT_COMMON_CHROME_APPLICATION_MAC_H_