From 296383bd8221c9d006d6bbc35badf1a434be51fa Mon Sep 17 00:00:00 2001 From: "thakis@chromium.org" Date: Fri, 16 Oct 2009 00:53:06 +0000 Subject: Let cmd-` switch windows again. BUG=24817 TEST=Open three windows. Focus web contents. Cmd-` should cycle windows Cmd-shift-` should cycle in the other direction. Review URL: http://codereview.chromium.org/280005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29229 0039d316-1c4b-4281-b951-d872f2087c98 --- .../browser/tab_contents/tab_contents_view_mac.mm | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'chrome/browser') diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.mm b/chrome/browser/tab_contents/tab_contents_view_mac.mm index 61195b1..21b4970 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.mm +++ b/chrome/browser/tab_contents/tab_contents_view_mac.mm @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#import + #include "chrome/browser/tab_contents/tab_contents_view_mac.h" #include @@ -259,6 +261,10 @@ void TabContentsViewMac::Observe(NotificationType type, } } +@interface NSApplication(SPI) +- (void)_cycleWindowsReversed:(BOOL)reversed; +@end + @implementation TabContentsViewCocoa - (id)initWithTabContentsViewMac:(TabContentsViewMac*)w { @@ -303,6 +309,25 @@ void TabContentsViewMac::Observe(NotificationType type, return; } + // Cmd-` is not in the menu and it's apparently handled by |NSApp sendEvent| + // if the application doesn't swallow it. We do, so we need to handle this + // key ourself. On foreign keyboards, the "switch windows" key is not the + // ` key, so do this by keycode instead of |event characters|. + if ([event type] == NSKeyDown && + [event keyCode] == kVK_ANSI_Grave && + [NSApp respondsToSelector:@selector(_cycleWindowsReversed:)]) { + const NSUInteger kModifierMask = NSShiftKeyMask | + NSControlKeyMask | + NSAlternateKeyMask | + NSCommandKeyMask; + if (([event modifierFlags] & kModifierMask) == NSCommandKeyMask) + [NSApp _cycleWindowsReversed:NO]; + else if (([event modifierFlags] & kModifierMask) == + (NSCommandKeyMask | NSShiftKeyMask) && + [NSApp respondsToSelector:@selector(_cycleWindowsReversed:)]) + [NSApp _cycleWindowsReversed:YES]; + } + // If this tab is no longer active, it's window will be |nil|. In that case, // best ignore the event. if (![self window]) -- cgit v1.1