Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/cocoa/browser_window_utils.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 6 | 6 |
| 7 #include <Carbon/Carbon.h> | 7 #include <Carbon/Carbon.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #import "base/mac/foundation_util.h" | |
| 10 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
| 11 #include "chrome/browser/global_keyboard_shortcuts_mac.h" | 12 #include "chrome/browser/global_keyboard_shortcuts_mac.h" |
| 12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #import "chrome/browser/ui/cocoa/chrome_command_dispatch_delegate.h" | |
| 13 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 15 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
| 14 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 16 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 15 #include "content/public/browser/native_web_keyboard_event.h" | 17 #include "content/public/browser/native_web_keyboard_event.h" |
| 16 | 18 |
| 17 using content::NativeWebKeyboardEvent; | 19 using content::NativeWebKeyboardEvent; |
| 18 | 20 |
| 19 @implementation BrowserWindowUtils | 21 @implementation BrowserWindowUtils |
| 20 + (BOOL)shouldHandleKeyboardEvent:(const NativeWebKeyboardEvent&)event { | 22 + (BOOL)shouldHandleKeyboardEvent:(const NativeWebKeyboardEvent&)event { |
| 21 if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char) | 23 if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char) |
| 22 return NO; | 24 return NO; |
| 23 DCHECK(event.os_event != NULL); | 25 DCHECK(event.os_event != NULL); |
| 24 return YES; | 26 return YES; |
| 25 } | 27 } |
| 26 | 28 |
| 27 + (int)getCommandId:(const NativeWebKeyboardEvent&)event { | 29 + (int)getCommandId:(const NativeWebKeyboardEvent&)event { |
| 28 return CommandForKeyEvent(event.os_event); | 30 return CommandForKeyEvent(event.os_event); |
| 29 } | 31 } |
| 30 | 32 |
| 31 + (BOOL)handleKeyboardEvent:(NSEvent*)event | 33 + (BOOL)handleKeyboardEvent:(NSEvent*)event |
| 32 inWindow:(NSWindow*)window { | 34 inWindow:(NSWindow*)window { |
| 33 ChromeEventProcessingWindow* event_window = | 35 ChromeEventProcessingWindow* event_window = |
| 34 static_cast<ChromeEventProcessingWindow*>(window); | 36 base::mac::ObjCCastStrict<ChromeEventProcessingWindow>(window); |
| 35 DCHECK([event_window isKindOfClass:[ChromeEventProcessingWindow class]]); | 37 ChromeCommandDispatchDelegate* command_delegate = |
| 38 base::mac::ObjCCastStrict<ChromeCommandDispatchDelegate>( | |
| 39 [event_window commandDelegate]); | |
| 36 | 40 |
| 37 // Do not fire shortcuts on key up. | 41 // Do not fire shortcuts on key up. |
| 38 if ([event type] == NSKeyDown) { | 42 if ([event type] == NSKeyDown) { |
| 39 // Send the event to the menu before sending it to the browser/window | 43 // Send the event to the menu before sending it to the browser/window |
| 40 // shortcut handling, so that if a user configures cmd-left to mean | 44 // shortcut handling, so that if a user configures cmd-left to mean |
| 41 // "previous tab", it takes precedence over the built-in "history back" | 45 // "previous tab", it takes precedence over the built-in "history back" |
| 42 // binding. Other than that, the |-redispatchKeyEvent:| call would take care | 46 // binding. Other than that, the |-redispatchKeyEvent:| call would take care |
| 43 // of invoking the original menu item shortcut as well. | 47 // of invoking the original menu item shortcut as well. |
| 44 | 48 |
| 45 if ([[NSApp mainMenu] performKeyEquivalent:event]) | 49 if ([[NSApp mainMenu] performKeyEquivalent:event]) |
| 46 return true; | 50 return true; |
| 47 | 51 |
| 48 if ([event_window handleExtraKeyboardShortcut:event]) | 52 if ([command_delegate handleExtraKeyboardShortcut:event window:window]) |
|
tapted
2015/07/31 03:06:49
If it's cleaner, I think it's OK to leave handleEx
jackhou1
2015/08/04 01:03:58
Done.
| |
| 49 return true; | 53 return true; |
| 50 } | 54 } |
| 51 | 55 |
| 52 return [event_window redispatchKeyEvent:event]; | 56 return [event_window redispatchKeyEvent:event]; |
| 53 } | 57 } |
| 54 | 58 |
| 55 + (NSString*)scheduleReplaceOldTitle:(NSString*)oldTitle | 59 + (NSString*)scheduleReplaceOldTitle:(NSString*)oldTitle |
| 56 withNewTitle:(NSString*)newTitle | 60 withNewTitle:(NSString*)newTitle |
| 57 forWindow:(NSWindow*)window { | 61 forWindow:(NSWindow*)window { |
| 58 if (oldTitle) | 62 if (oldTitle) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 + (void)activateWindowForController:(NSWindowController*)controller { | 130 + (void)activateWindowForController:(NSWindowController*)controller { |
| 127 // Per http://crbug.com/73779 and http://crbug.com/75223, we need this to | 131 // Per http://crbug.com/73779 and http://crbug.com/75223, we need this to |
| 128 // properly activate windows if Chrome is not the active application. | 132 // properly activate windows if Chrome is not the active application. |
| 129 [[controller window] makeKeyAndOrderFront:controller]; | 133 [[controller window] makeKeyAndOrderFront:controller]; |
| 130 ProcessSerialNumber psn; | 134 ProcessSerialNumber psn; |
| 131 GetCurrentProcess(&psn); | 135 GetCurrentProcess(&psn); |
| 132 SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly); | 136 SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly); |
| 133 } | 137 } |
| 134 | 138 |
| 135 @end | 139 @end |
| OLD | NEW |