Chromium Code Reviews| Index: chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm |
| diff --git a/chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm b/chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm |
| index 9d96a8365eae93fe243529b61ed3dc0ceb41db8a..435e44bfba034cb9bb71d37daa4ac8661d130b0e 100644 |
| --- a/chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm |
| +++ b/chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm |
| @@ -46,6 +46,18 @@ const double kBoundsAnimationMaxDurationSeconds = 0.18; |
| // Edge thickness to trigger user resizing via system, in screen pixels. |
| const double kWidthOfMouseResizeArea = 15.0; |
| +// Notification observer to prevent panels becoming key when windows are closed. |
| +@interface WindowCloseWatcher : NSObject |
| +- (void)windowWillClose:(NSNotification*)notification; |
| +@end |
| + |
| +namespace { |
| + |
| +// Leaky singleton. Initialized when the first panel is created. |
| +WindowCloseWatcher* g_window_close_watcher = nil; |
| + |
| +} |
| + |
| @interface PanelWindowControllerCocoa (PanelsCanBecomeKey) |
| // Internal helper method for extracting the total number of panel windows |
| // from the panel manager. Used to decide if panel can become the key window. |
| @@ -88,6 +100,7 @@ const double kWidthOfMouseResizeArea = 15.0; |
| return ([app isHandlingSendEvent] && [[app currentEvent] window] == self) || |
| [controller activationRequestedByPanel] || |
| [app isCyclingWindows] || |
| + [self isKeyWindow] || |
|
tapted
2015/03/31 11:34:10
This case is encountered when there are multiple p
|
| [app previousKeyWindow] == self || |
| [[app windows] count] == static_cast<NSUInteger>([controller numPanels]); |
| } |
| @@ -168,6 +181,9 @@ const double kWidthOfMouseResizeArea = 15.0; |
| animateOnBoundsChange_ = YES; |
| canBecomeKeyWindow_ = YES; |
| activationRequestedByPanel_ = NO; |
| + |
| + if (!g_window_close_watcher) |
|
Mark Mentovai
2015/03/31 13:13:31
Doesn’t need to be global. You can just write
s
tapted
2015/03/31 23:55:29
Ooh - I didn't think of that. It results in
`erro
|
| + g_window_close_watcher = [[WindowCloseWatcher alloc] init]; |
| } |
| return self; |
| } |
| @@ -927,3 +943,45 @@ const double kWidthOfMouseResizeArea = 15.0; |
| } |
| @end |
| + |
| +@implementation WindowCloseWatcher |
| + |
| +- (id)init { |
| + if ((self = [super init])) { |
| + [[NSNotificationCenter defaultCenter] |
| + addObserver:self |
| + selector:@selector(windowWillClose:) |
| + name:NSWindowWillCloseNotification |
| + object:nil]; |
| + } |
| + return self; |
| +} |
| + |
| +- (void)windowWillClose:(NSNotification*)notification { |
| + // If it looks like a panel may (refuse to) become key after this window is |
| + // closed, then explicitly set the topmost browser window on the active space |
| + // to be key (if there is one). Otherwise AppKit will stop looking for windows |
| + // to make key once it encounters the panel. |
| + id closingWindow = [notification object]; |
| + BOOL orderNext = NO; |
| + for (NSWindow* window : [NSApp orderedWindows]) { |
| + if ([window isEqual:closingWindow] || ![window isOnActiveSpace]) |
| + continue; |
| + |
| + if ([window isKindOfClass:[PanelWindowCocoaImpl class]] && |
| + ![window canBecomeKeyWindow]) { |
| + orderNext = YES; |
| + continue; |
| + } |
| + |
| + if (orderNext) { |
| + if (![window canBecomeKeyWindow]) |
| + continue; |
| + |
| + [window makeKeyWindow]; |
| + } |
| + return; |
| + } |
| +} |
| + |
| +@end |