diff options
author | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-15 19:26:30 +0000 |
---|---|---|
committer | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-15 19:26:30 +0000 |
commit | c14fdfe52509b7c3a749aeec9b0582628e741b76 (patch) | |
tree | bd89c00b3134fe01ead329ab54ff0762bd238920 /chrome/browser/cocoa/chrome_event_processing_window.mm | |
parent | 9f36b348f2408118d42d219c8a4fa04877ed3b83 (diff) | |
download | chromium_src-c14fdfe52509b7c3a749aeec9b0582628e741b76.zip chromium_src-c14fdfe52509b7c3a749aeec9b0582628e741b76.tar.gz chromium_src-c14fdfe52509b7c3a749aeec9b0582628e741b76.tar.bz2 |
BUG=http://crbug.com/24459
TEST=see bug report. Also play with entering and leaving fullscreen.
Review URL: http://codereview.chromium.org/269070
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29165 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/chrome_event_processing_window.mm')
-rw-r--r-- | chrome/browser/cocoa/chrome_event_processing_window.mm | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/chrome_event_processing_window.mm b/chrome/browser/cocoa/chrome_event_processing_window.mm new file mode 100644 index 0000000..7a82ab4 --- /dev/null +++ b/chrome/browser/cocoa/chrome_event_processing_window.mm @@ -0,0 +1,69 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "chrome/browser/cocoa/chrome_event_processing_window.h" + +#include "base/logging.h" +#import "chrome/browser/cocoa/browser_window_controller.h" +#import "chrome/browser/cocoa/browser_frame_view.h" +#import "chrome/browser/cocoa/tab_strip_controller.h" +#import "chrome/browser/renderer_host/render_widget_host_view_mac.h" +#include "chrome/browser/global_keyboard_shortcuts_mac.h" + +typedef int (*KeyToCommandMapper)(bool, bool, bool, int); + +@implementation ChromeEventProcessingWindow + +- (BOOL)handleExtraKeyboardShortcut:(NSEvent*)event fromTable: + (KeyToCommandMapper)commandForKeyboardShortcut { + // Extract info from |event|. + NSUInteger modifers = [event modifierFlags]; + const bool cmdKey = modifers & NSCommandKeyMask; + const bool shiftKey = modifers & NSShiftKeyMask; + const bool cntrlKey = modifers & NSControlKeyMask; + const int keyCode = [event keyCode]; + + int cmdNum = commandForKeyboardShortcut(cmdKey, shiftKey, cntrlKey, + keyCode); + + BrowserWindowController* controller = + (BrowserWindowController*)[self delegate]; + // A bit of sanity. + DCHECK([controller isKindOfClass:[BrowserWindowController class]]); + DCHECK([controller respondsToSelector:@selector(executeCommand:)]); + + if (cmdNum != -1) { + [controller executeCommand:cmdNum]; + return YES; + } + return NO; +} + +- (BOOL)handleExtraWindowKeyboardShortcut:(NSEvent*)event { + return [self handleExtraKeyboardShortcut:event + fromTable:CommandForWindowKeyboardShortcut]; +} + +- (BOOL)handleExtraBrowserKeyboardShortcut:(NSEvent*)event { + return [self handleExtraKeyboardShortcut:event + fromTable:CommandForBrowserKeyboardShortcut]; +} + +- (BOOL)performKeyEquivalent:(NSEvent*)event { + // Give the web site a chance to handle the event. If it doesn't want to + // handle it, it will call us back with one of the |handle*| methods above. + NSResponder* r = [self firstResponder]; + if ([r isKindOfClass:[RenderWidgetHostViewCocoa class]]) + return [r performKeyEquivalent:event]; + + // Handle per-window shortcuts like cmd-1, but do not handle browser-level + // shortcuts like cmd-left (else, cmd-left would do history navigation even + // if e.g. the Omnibox has focus). + if ([self handleExtraWindowKeyboardShortcut:event]) + return YES; + return [super performKeyEquivalent:event]; +} + +@end // ChromeEventProcessingWindow + |