|
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 |
|
3 // found in the LICENSE file. |
|
4 |
|
5 #ifndef BASE_CHROME_APPLICATION_MAC_H_ |
|
6 #define BASE_CHROME_APPLICATION_MAC_H_ |
|
7 |
|
8 #import <AppKit/AppKit.h> |
|
9 |
|
10 #include "base/basictypes.h" |
|
11 #include "base/scoped_nsobject.h" |
|
12 |
|
13 // Event hooks must implement this protocol. |
|
14 @protocol CrApplicationEventHookProtocol |
|
15 - (void)hookForEvent:(NSEvent*)theEvent; |
|
16 @end |
|
17 |
|
18 |
|
19 @interface CrApplication : NSApplication { |
|
20 @private |
|
21 BOOL handlingSendEvent_; |
|
22 // Array of objects implementing the CrApplicationEventHookProtocol |
|
23 scoped_nsobject<NSMutableArray> eventHooks_; |
|
24 } |
|
25 @property(readonly, |
|
26 getter=isHandlingSendEvent, |
|
27 nonatomic) 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 } // chrome_application_mac |
|
59 |
|
60 #endif // BASE_CHROME_APPLICATION_MAC_H_ |