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