Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3094)

Unified Diff: chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm

Issue 1040993005: [Mac] A more robust way to ensure panels avoid key status on window close (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: static Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/panels/panel_cocoa_browsertest.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..06ce789dc186277dc55d387db02d803e0aa504a0 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,11 @@ 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
+
@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 +93,7 @@ const double kWidthOfMouseResizeArea = 15.0;
return ([app isHandlingSendEvent] && [[app currentEvent] window] == self) ||
[controller activationRequestedByPanel] ||
[app isCyclingWindows] ||
+ [self isKeyWindow] ||
[app previousKeyWindow] == self ||
[[app windows] count] == static_cast<NSUInteger>([controller numPanels]);
}
@@ -168,6 +174,10 @@ const double kWidthOfMouseResizeArea = 15.0;
animateOnBoundsChange_ = YES;
canBecomeKeyWindow_ = YES;
activationRequestedByPanel_ = NO;
+
+ // Leaky singleton. Initialized when the first panel is created.
+ static WindowCloseWatcher* watcher = [[WindowCloseWatcher alloc] init];
+ (void)watcher; // Suppress the unused variable warning.
}
return self;
}
@@ -927,3 +937,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
« no previous file with comments | « chrome/browser/ui/cocoa/panels/panel_cocoa_browsertest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698