summaryrefslogtreecommitdiffstats
path: root/chrome/browser/app_controller_mac.mm
diff options
context:
space:
mode:
authorasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-18 20:11:56 +0000
committerasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-18 20:11:56 +0000
commitebbe94b785d1e18ef34f7cc5db026bbb7cba9adb (patch)
tree2ea94ce4b815c0f965e6dbe7b59523b18ddf41fb /chrome/browser/app_controller_mac.mm
parentf2a9e3f812d05f0ac61cbae4b5e911f29913c9b2 (diff)
downloadchromium_src-ebbe94b785d1e18ef34f7cc5db026bbb7cba9adb.zip
chromium_src-ebbe94b785d1e18ef34f7cc5db026bbb7cba9adb.tar.gz
chromium_src-ebbe94b785d1e18ef34f7cc5db026bbb7cba9adb.tar.bz2
Better fix for Lion dictionary popover cmd-W bug.
This reverts http://crrev.com/117681 and http://crrev.com/104931 and instead uses new 10.7 notifications to change the shortcuts on Close Tab and Close Window items, so that cmd-W does a "Close Window" when the dictionary is open. The above is also how Safari appears to solve this issue, as can be seen by going to the File menu when the dictionary popover is up. BUG=104931, 110306, 109061 TEST=1. Open a tab and double 3-finger tap on a word to bring up the dictionary popup. Hit cmd-W. The popup should close but the tab should stay open. Hit cmd-W again. The tab should close. 2. Try cmd-shift-W with > 1 tab open. The window should close. 3. Open a window that doesn't have tabs (e.g. Chrome -> About Chrome). File -> Close Tab should be disabled. Review URL: http://codereview.chromium.org/9230011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118131 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/app_controller_mac.mm')
-rw-r--r--chrome/browser/app_controller_mac.mm63
1 files changed, 42 insertions, 21 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index cf82cba..000bc5c 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -89,6 +89,13 @@ using content::UserMetricsAction;
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
+
// True while AppController is calling Browser::OpenEmptyWindow(). We need a
// global flag here, analogue to BrowserInit::InProcessStartup() because
// otherwise the SessionService will try to restore sessions when we make a new
@@ -192,13 +199,6 @@ const AEEventClass kAECloudPrintUninstallClass = 'GCPu';
// the profile is loaded or any preferences have been registered). Defer any
// user-data initialization until -applicationDidFinishLaunching:.
- (void)awakeFromNib {
-}
-
-// This method is called very early in application startup (ie, before
-// the profile is loaded or any preferences have been registered), just
-// after -awakeFromNib. This is separate from -awakeFromNib: so that
-// test code can load nibs without these side effects.
-- (void)registerEventHandlersAndInitialize {
// We need to register the handlers early to catch events fired on launch.
NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
[em setEventHandler:self
@@ -249,6 +249,19 @@ const AEEventClass kAECloudPrintUninstallClass = 'GCPu';
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];
+ }
+
// Set up the command updater for when there are no windows open
[self initMenuState];
@@ -271,12 +284,6 @@ const AEEventClass kAECloudPrintUninstallClass = 'GCPu';
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
-- (void)dealloc {
- if ([NSApp delegate] == self)
- [NSApp setDelegate:nil];
- [super dealloc];
-}
-
// (NSApplicationDelegate protocol) This is the Apple-approved place to override
// the default handlers.
- (void)applicationWillFinishLaunching:(NSNotification*)notification {
@@ -377,15 +384,16 @@ const AEEventClass kAECloudPrintUninstallClass = 'GCPu';
// If the window has a tab controller, make "close window" be cmd-shift-w,
// otherwise leave it as the normal cmd-w. Capitalization of the key equivalent
// affects whether the shift modifer is used.
-- (void)adjustCloseWindowMenuItemKeyEquivalent:(BOOL)hasTabs {
- [closeWindowMenuItem_ setKeyEquivalent:(hasTabs ? @"W" : @"w")];
+- (void)adjustCloseWindowMenuItemKeyEquivalent:(BOOL)enableCloseTabShortcut {
+ [closeWindowMenuItem_ setKeyEquivalent:(enableCloseTabShortcut ? @"W" :
+ @"w")];
[closeWindowMenuItem_ setKeyEquivalentModifierMask:NSCommandKeyMask];
}
// If the window has a tab controller, make "close tab" take over cmd-w,
// otherwise it shouldn't have any key-equivalent because it should be disabled.
-- (void)adjustCloseTabMenuItemKeyEquivalent:(BOOL)hasTabs {
- if (hasTabs) {
+- (void)adjustCloseTabMenuItemKeyEquivalent:(BOOL)enableCloseTabShortcut {
+ if (enableCloseTabShortcut) {
[closeTabMenuItem_ setKeyEquivalent:@"w"];
[closeTabMenuItem_ setKeyEquivalentModifierMask:NSCommandKeyMask];
} else {
@@ -423,8 +431,9 @@ const AEEventClass kAECloudPrintUninstallClass = 'GCPu';
BOOL hasTabs =
[[window windowController] isKindOfClass:[TabWindowController class]];
- [self adjustCloseWindowMenuItemKeyEquivalent:hasTabs];
- [self adjustCloseTabMenuItemKeyEquivalent:hasTabs];
+ BOOL enableCloseTabShortcut = hasTabs && !hasPopover_;
+ [self adjustCloseWindowMenuItemKeyEquivalent:enableCloseTabShortcut];
+ [self adjustCloseTabMenuItemKeyEquivalent:enableCloseTabShortcut];
}
// Fix up the "close tab/close window" command-key equivalents. We do this
@@ -487,6 +496,18 @@ const AEEventClass kAECloudPrintUninstallClass = 'GCPu';
}
}
+// Called on Lion and later when a popover (e.g. dictionary) is shown.
+- (void)popoverDidShow:(NSNotification*)notify {
+ hasPopover_ = YES;
+ [self fixCloseMenuItemKeyEquivalents];
+}
+
+// Called on Lion and later when a popover (e.g. dictionary) is closed.
+- (void)popoverDidClose:(NSNotification*)notify {
+ hasPopover_ = NO;
+ [self fixCloseMenuItemKeyEquivalents];
+}
+
// Called when the user has changed browser windows, meaning the backing profile
// may have changed. This can cause a rebuild of the user-data menus. This is a
// no-op if the new profile is the same as the current one. This will always be
@@ -1109,7 +1130,7 @@ const AEEventClass kAECloudPrintUninstallClass = 'GCPu';
// process, gets the required data and launches Print dialog.
- (void)submitCloudPrintJob:(NSAppleEventDescriptor*)event {
// Pull parameter list out of Apple Event.
- NSAppleEventDescriptor *paramList =
+ NSAppleEventDescriptor* paramList =
[event paramDescriptorForKeyword:cloud_print::kAECloudPrintClass];
if (paramList != nil) {
@@ -1282,7 +1303,7 @@ const AEEventClass kAECloudPrintUninstallClass = 'GCPu';
return bookmarkMenuBridge_.get();
}
-- (void)applicationDidChangeScreenParameters:(NSNotification *)notification {
+- (void)applicationDidChangeScreenParameters:(NSNotification*)notification {
// During this callback the working area is not always already updated. Defer.
[self performSelector:@selector(delayedPanelManagerScreenParametersUpdate)
withObject:nil