| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROME_BROWSER_APPLICATION_MAC_H_ | 5 #ifndef CHROME_BROWSER_CHROME_BROWSER_APPLICATION_MAC_H_ |
| 6 #define CHROME_BROWSER_CHROME_BROWSER_APPLICATION_MAC_H_ | 6 #define CHROME_BROWSER_CHROME_BROWSER_APPLICATION_MAC_H_ |
| 7 | 7 |
| 8 #ifdef __OBJC__ | 8 #ifdef __OBJC__ |
| 9 | 9 |
| 10 #import <AppKit/AppKit.h> | 10 #import <AppKit/AppKit.h> |
| 11 | 11 |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #import "base/mac/scoped_sending_event.h" | 14 #import "base/mac/scoped_sending_event.h" |
| 15 #import "base/memory/scoped_nsobject.h" | 15 #import "base/memory/scoped_nsobject.h" |
| 16 #import "base/message_pump_mac.h" | 16 #import "base/message_pump_mac.h" |
| 17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 18 #import "ui/base/cocoa/event_hook_application.h" |
| 18 | 19 |
| 19 // Event hooks must implement this protocol. | 20 @interface BrowserCrApplication : CrEventHookApplication<CrAppProtocol, |
| 20 @protocol CrApplicationEventHookProtocol | 21 CrAppControlProtocol> { |
| 21 - (void)hookForEvent:(NSEvent*)theEvent; | |
| 22 @end | |
| 23 | |
| 24 @interface BrowserCrApplication : NSApplication<CrAppProtocol, | |
| 25 CrAppControlProtocol> { | |
| 26 @private | 22 @private |
| 27 BOOL handlingSendEvent_; | 23 BOOL handlingSendEvent_; |
| 28 BOOL cyclingWindows_; | 24 BOOL cyclingWindows_; |
| 29 | 25 |
| 30 // Array of objects implementing CrApplicationEventHookProtocol. | |
| 31 scoped_nsobject<NSMutableArray> eventHooks_; | |
| 32 | |
| 33 // App's previous key windows. Most recent key window is last. | 26 // App's previous key windows. Most recent key window is last. |
| 34 // Does not include current key window. Elements of this vector are weak | 27 // Does not include current key window. Elements of this vector are weak |
| 35 // references. | 28 // references. |
| 36 std::vector<NSWindow*> previousKeyWindows_; | 29 std::vector<NSWindow*> previousKeyWindows_; |
| 37 | 30 |
| 38 // Guards previousKeyWindows_. | 31 // Guards previousKeyWindows_. |
| 39 base::Lock previousKeyWindowsLock_; | 32 base::Lock previousKeyWindowsLock_; |
| 40 } | 33 } |
| 41 | 34 |
| 42 // Our implementation of |-terminate:| only attempts to terminate the | 35 // Our implementation of |-terminate:| only attempts to terminate the |
| 43 // application, i.e., begins a process which may lead to termination. This | 36 // application, i.e., begins a process which may lead to termination. This |
| 44 // method cancels that process. | 37 // method cancels that process. |
| 45 - (void)cancelTerminate:(id)sender; | 38 - (void)cancelTerminate:(id)sender; |
| 46 | 39 |
| 47 // Add or remove an event hook to be called for every sendEvent: | |
| 48 // that the application receives. These handlers are called before | |
| 49 // the normal [NSApplication sendEvent:] call is made. | |
| 50 | |
| 51 // This is not a good alternative to a nested event loop. It should | |
| 52 // be used only when normal event logic and notification breaks down | |
| 53 // (e.g. when clicking outside a canBecomeKey:NO window to "switch | |
| 54 // context" out of it). | |
| 55 - (void)addEventHook:(id<CrApplicationEventHookProtocol>)hook; | |
| 56 - (void)removeEventHook:(id<CrApplicationEventHookProtocol>)hook; | |
| 57 | |
| 58 // Keep track of the previous key windows and whether windows are being | 40 // Keep track of the previous key windows and whether windows are being |
| 59 // cycled for use in determining whether a Panel window can become the | 41 // cycled for use in determining whether a Panel window can become the |
| 60 // key window. | 42 // key window. |
| 61 - (NSWindow*)previousKeyWindow; | 43 - (NSWindow*)previousKeyWindow; |
| 62 - (BOOL)isCyclingWindows; | 44 - (BOOL)isCyclingWindows; |
| 63 @end | 45 @end |
| 64 | 46 |
| 65 namespace chrome_browser_application_mac { | 47 namespace chrome_browser_application_mac { |
| 66 | 48 |
| 67 // Bin for unknown exceptions. Exposed for testing purposes. | 49 // Bin for unknown exceptions. Exposed for testing purposes. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 86 | 68 |
| 87 // Calls -[NSApp terminate:]. | 69 // Calls -[NSApp terminate:]. |
| 88 void Terminate(); | 70 void Terminate(); |
| 89 | 71 |
| 90 // Cancels a termination started by |Terminate()|. | 72 // Cancels a termination started by |Terminate()|. |
| 91 void CancelTerminate(); | 73 void CancelTerminate(); |
| 92 | 74 |
| 93 } // namespace chrome_browser_application_mac | 75 } // namespace chrome_browser_application_mac |
| 94 | 76 |
| 95 #endif // CHROME_BROWSER_CHROME_BROWSER_APPLICATION_MAC_H_ | 77 #endif // CHROME_BROWSER_CHROME_BROWSER_APPLICATION_MAC_H_ |
| OLD | NEW |