Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/cocoa/chrome_browser_window.h" | 5 #import "chrome/browser/cocoa/chrome_browser_window.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "chrome/browser/cocoa/browser_window_controller.h" | 8 #import "chrome/browser/cocoa/browser_window_controller.h" |
| 9 #import "chrome/browser/renderer_host/render_widget_host_view_mac.h" | |
| 9 #include "chrome/browser/global_keyboard_shortcuts_mac.h" | 10 #include "chrome/browser/global_keyboard_shortcuts_mac.h" |
| 10 | 11 |
| 12 typedef int (*KeyToCommandMapper)(bool, bool, bool, int); | |
| 13 | |
| 11 @implementation ChromeBrowserWindow | 14 @implementation ChromeBrowserWindow |
| 12 | 15 |
| 13 - (BOOL)performKeyEquivalent:(NSEvent*)event { | 16 - (BOOL)handleExtraKeyboardShortcut:(NSEvent*)event fromTable: |
| 17 (KeyToCommandMapper)commandForKeyboardShortcut { | |
| 14 // Extract info from |event|. | 18 // Extract info from |event|. |
| 15 NSUInteger modifers = [event modifierFlags]; | 19 NSUInteger modifers = [event modifierFlags]; |
| 16 const bool cmdKey = modifers & NSCommandKeyMask; | 20 const bool cmdKey = modifers & NSCommandKeyMask; |
| 17 const bool shiftKey = modifers & NSShiftKeyMask; | 21 const bool shiftKey = modifers & NSShiftKeyMask; |
| 18 const bool cntrlKey = modifers & NSControlKeyMask; | 22 const bool cntrlKey = modifers & NSControlKeyMask; |
| 19 const int keyCode = [event keyCode]; | 23 const int keyCode = [event keyCode]; |
| 20 | 24 |
| 21 int cmdNum = CommandForKeyboardShortcut(cmdKey, shiftKey, cntrlKey, | 25 int cmdNum = commandForKeyboardShortcut(cmdKey, shiftKey, cntrlKey, |
| 22 keyCode); | 26 keyCode); |
| 23 | 27 |
| 24 BrowserWindowController* controller = | 28 BrowserWindowController* controller = |
| 25 (BrowserWindowController*)[self delegate]; | 29 (BrowserWindowController*)[self delegate]; |
| 26 // A bit of sanity. | 30 // A bit of sanity. |
| 27 DCHECK([controller isKindOfClass:[BrowserWindowController class]]); | 31 DCHECK([controller isKindOfClass:[BrowserWindowController class]]); |
| 28 DCHECK([controller respondsToSelector:@selector(executeCommand:)]); | 32 DCHECK([controller respondsToSelector:@selector(executeCommand:)]); |
| 29 | 33 |
| 30 if (cmdNum != -1) { | 34 if (cmdNum != -1) { |
| 31 [controller executeCommand:cmdNum]; | 35 [controller executeCommand:cmdNum]; |
| 32 return YES; | 36 return YES; |
| 33 } | 37 } |
| 38 return NO; | |
| 39 } | |
| 34 | 40 |
| 41 - (BOOL)handleExtraWindowKeyboardShortcut:(NSEvent*)event { | |
| 42 return [self handleExtraKeyboardShortcut:event | |
| 43 fromTable:CommandForWindowKeyboardShortcut]; | |
| 44 } | |
| 45 | |
| 46 - (BOOL)handleExtraBrowserKeyboardShortcut:(NSEvent*)event { | |
| 47 return [self handleExtraKeyboardShortcut:event | |
| 48 fromTable:CommandForBrowserKeyboardShortcut]; | |
| 49 } | |
| 50 | |
| 51 - (BOOL)performKeyEquivalent:(NSEvent*)event { | |
| 52 // Give the web site a chance to handle the event. If it doesn't want to | |
| 53 // handle it, it will call us back with one of the |handle*| methods above. | |
| 54 NSResponder* r = [self firstResponder]; | |
|
pink (ping after 24hrs)
2009/10/09 14:36:51
what happens when the renderer is hung? Does that
Nico
2009/10/09 16:50:06
Yes, that will work once BrowserWindowCocoa::GetCo
| |
| 55 if ([r isKindOfClass:[RenderWidgetHostViewCocoa class]]) | |
| 56 return [r performKeyEquivalent:event]; | |
| 57 | |
| 58 // Handle per-window shortcuts like cmd-1, but do not handle browser-level | |
| 59 // shortcuts like cmd-left (else, cmd-left would do history navigation even | |
| 60 // if e.g. the Omnibox has focus). | |
| 61 if ([self handleExtraWindowKeyboardShortcut:event]) | |
| 62 return YES; | |
| 35 return [super performKeyEquivalent:event]; | 63 return [super performKeyEquivalent:event]; |
| 36 } | 64 } |
| 37 | 65 |
| 38 - (void)setShouldHideTitle:(BOOL)flag { | 66 - (void)setShouldHideTitle:(BOOL)flag { |
| 39 shouldHideTitle_ = flag; | 67 shouldHideTitle_ = flag; |
| 40 } | 68 } |
| 41 | 69 |
| 42 -(BOOL)_isTitleHidden { | 70 -(BOOL)_isTitleHidden { |
| 43 return shouldHideTitle_; | 71 return shouldHideTitle_; |
| 44 } | 72 } |
| 45 | 73 |
| 46 @end | 74 @end |
| OLD | NEW |