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

Unified Diff: chrome/browser/app_controller_mac.mm

Issue 1025793002: Mac: Possible fix for Cmd-W closing window instead of a tab (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@grd
Patch Set: 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/app_controller_mac.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/app_controller_mac.mm
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index 866f7c009875b50a5bcb09b28ded63f4c8085fff..b6c2f6fc2fe82e22192fceed3d75257fa6d77cb0 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -111,13 +111,6 @@ using content::DownloadManager;
namespace {
-// Declare notification names from the 10.7 SDK.
-#if !defined(MAC_OS_X_VERSION_10_7) || \
- MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
-NSString* NSPopoverDidShowNotification = @"NSPopoverDidShowNotification";
-NSString* NSPopoverDidCloseNotification = @"NSPopoverDidCloseNotification";
-#endif
-
// How long we allow a workspace change notification to wait to be
// associated with a dock activation. The animation lasts 250ms. See
// applicationShouldHandleReopen:hasVisibleWindows:.
@@ -353,19 +346,6 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver {
name:NSWindowDidResignMainNotification
object:nil];
- if (base::mac::IsOSLionOrLater()) {
- [notificationCenter
- addObserver:self
- selector:@selector(popoverDidShow:)
- name:NSPopoverDidShowNotification
- object:nil];
- [notificationCenter
- addObserver:self
- selector:@selector(popoverDidClose:)
- name:NSPopoverDidCloseNotification
- object:nil];
- }
-
// Register for space change notifications.
[[[NSWorkspace sharedWorkspace] notificationCenter]
addObserver:self
@@ -562,21 +542,26 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver {
// Close Tab/Close Window accordingly.
- (void)menuNeedsUpdate:(NSMenu*)menu {
DCHECK(menu == [closeTabMenuItem_ menu]);
- NSWindow* window = [NSApp keyWindow];
- NSWindow* mainWindow = [NSApp mainWindow];
- if (!window || ([window parentWindow] == mainWindow)) {
- // If the key window is a child of the main window (e.g. a bubble), the main
- // window should be the one that handles the close menu item action.
- // Also, there might be a small amount of time where there is no key window;
- // in that case as well, just use our main browser window if there is one.
- // You might think that we should just always use the main window, but the
- // "About Chrome" window serves as a counterexample.
- window = mainWindow;
+
+ BOOL enableCloseTabShortcut = NO;
+ id target = [NSApp targetForAction:@selector(performClose:)];
+
+ // |target| is an instance of NSPopover or NSWindow.
+ // If a popover (likely the dictionary lookup popover), we want Cmd-W to
+ // close the popover so map it to "Close Window".
+ // Otherwise, map Cmd-W to "Close Tab" if it's a browser window.
+ if ([target isKindOfClass:[NSWindow class]]) {
+ NSWindow* window = target;
+ NSWindow* mainWindow = [NSApp mainWindow];
+ if (!window || ([window parentWindow] == mainWindow)) {
+ // If the target window is a child of the main window (e.g. a bubble), the
+ // main window should be the one that handles the close menu item action.
+ window = mainWindow;
+ }
+ enableCloseTabShortcut =
+ [[window windowController] isKindOfClass:[TabWindowController class]];
}
- BOOL hasTabs =
- [[window windowController] isKindOfClass:[TabWindowController class]];
- BOOL enableCloseTabShortcut = hasTabs && !hasPopover_;
[self adjustCloseWindowMenuItemKeyEquivalent:enableCloseTabShortcut];
[self adjustCloseTabMenuItemKeyEquivalent:enableCloseTabShortcut];
}
@@ -639,16 +624,6 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver {
isPoweringOff_ = YES;
}
-// Called on Lion and later when a popover (e.g. dictionary) is shown.
-- (void)popoverDidShow:(NSNotification*)notify {
- hasPopover_ = YES;
-}
-
-// Called on Lion and later when a popover (e.g. dictionary) is closed.
-- (void)popoverDidClose:(NSNotification*)notify {
- hasPopover_ = NO;
-}
-
- (void)checkForAnyKeyWindows {
if ([NSApp keyWindow])
return;
« no previous file with comments | « chrome/browser/app_controller_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698