summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-22 21:25:50 +0000
committerpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-22 21:25:50 +0000
commit74c0c64228af300d578993cc7274a4968c91b39a (patch)
tree8b6c07d3b85971b28b510df48a3040c5729aaa2b
parent64d50ed649d61c5b84b09369b091018f70547bf8 (diff)
downloadchromium_src-74c0c64228af300d578993cc7274a4968c91b39a.zip
chromium_src-74c0c64228af300d578993cc7274a4968c91b39a.tar.gz
chromium_src-74c0c64228af300d578993cc7274a4968c91b39a.tar.bz2
Remove potential for command-key equivalents to beat the file menu fix-up timer by clearing the command keys for close tab/window before we fire the timer.
BUG=16689 TEST=cmd-w closes tabs/windows correctly based on number of tabs in the window and if the window is a browser window. Also comment 16 in the bug. Review URL: http://codereview.chromium.org/215056 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26862 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/app_controller_mac.mm33
1 files changed, 33 insertions, 0 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index 4db0cc0..46e1696 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -208,11 +208,24 @@
return nil;
}
+// Helper routine to get the window controller if the main window is a tabbed
+// window, or nil if not. Examples of non-tabbed windows are "about" or
+// "preferences".
+- (TabWindowController*)mainWindowTabController {
+ NSWindowController* mainWindowController =
+ [[NSApp mainWindow] windowController];
+ if ([mainWindowController isKindOfClass:[TabWindowController class]])
+ return (TabWindowController*)mainWindowController;
+
+ return nil;
+}
+
// If the window has tabs, 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)inHaveTabs {
[closeWindowMenuItem_ setKeyEquivalent:(inHaveTabs ? @"W" : @"w")];
+ [closeWindowMenuItem_ setKeyEquivalentModifierMask:NSCommandKeyMask];
}
// If the window has tabs, make "close tab" take over cmd-w, otherwise it
@@ -227,10 +240,25 @@
}
}
+// Explicitly remove any command-key equivalents from the close tab/window
+// menus so that nothing can go haywire if we get a user action during pending
+// updates.
+- (void)clearCloseMenuItemKeyEquivalents {
+ [closeTabMenuItem_ setKeyEquivalent:@""];
+ [closeTabMenuItem_ setKeyEquivalentModifierMask:0];
+ [closeWindowMenuItem_ setKeyEquivalent:@""];
+ [closeWindowMenuItem_ setKeyEquivalentModifierMask:0];
+}
+
// See if we have a window with tabs open, and adjust the key equivalents for
// Close Tab/Close Window accordingly
- (void)fixCloseMenuItemKeyEquivalents {
TabWindowController* tabController = [self keyWindowTabController];
+ if (!tabController && ![NSApp keyWindow]) {
+ // There might be a small amount of time where there is no key window,
+ // so just use our main browser window if there is one.
+ tabController = [self mainWindowTabController];
+ }
BOOL windowWithMultipleTabs =
(tabController && [tabController numberOfTabs] > 1);
[self adjustCloseWindowMenuItemKeyEquivalent:windowWithMultipleTabs];
@@ -243,6 +271,11 @@
// we do the enabling.
- (void)delayedFixCloseMenuItemKeyEquivalents {
if (!fileMenuUpdatePending_) {
+ // The OS prefers keypresses to timers, so it's possible that a cmd-w
+ // can sneak in before this timer fires. In order to prevent that from
+ // having any bad consequences, just clear the keys combos altogether. They
+ // will be reset when the timer eventually fires.
+ [self clearCloseMenuItemKeyEquivalents];
[self performSelector:@selector(fixCloseMenuItemKeyEquivalents)
withObject:nil
afterDelay:0];