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" |
| 13 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 14 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
| 14 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 15 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 15 #include "content/public/browser/native_web_keyboard_event.h" | 16 #include "content/public/browser/native_web_keyboard_event.h" |
| 16 | 17 |
| 17 using content::NativeWebKeyboardEvent; | 18 using content::NativeWebKeyboardEvent; |
| 18 | 19 |
| 19 @implementation BrowserWindowUtils | 20 @implementation BrowserWindowUtils |
| 20 + (BOOL)shouldHandleKeyboardEvent:(const NativeWebKeyboardEvent&)event { | 21 + (BOOL)shouldHandleKeyboardEvent:(const NativeWebKeyboardEvent&)event { |
| 21 if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char) | 22 if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char) |
| 22 return NO; | 23 return NO; |
| 23 DCHECK(event.os_event != NULL); | 24 DCHECK(event.os_event != NULL); |
| 24 return YES; | 25 return YES; |
| 25 } | 26 } |
| 26 | 27 |
| 27 + (int)getCommandId:(const NativeWebKeyboardEvent&)event { | 28 + (int)getCommandId:(const NativeWebKeyboardEvent&)event { |
| 28 return CommandForKeyEvent(event.os_event); | 29 return CommandForKeyEvent(event.os_event); |
| 29 } | 30 } |
| 30 | 31 |
| 31 + (BOOL)handleKeyboardEvent:(NSEvent*)event | 32 + (BOOL)handleKeyboardEvent:(NSEvent*)event |
| 32 inWindow:(NSWindow*)window { | 33 inWindow:(NSWindow*)window { |
| 33 ChromeEventProcessingWindow* event_window = | 34 ChromeEventProcessingWindow* event_window = |
| 34 static_cast<ChromeEventProcessingWindow*>(window); | 35 base::mac::ObjCCastStrict<ChromeEventProcessingWindow>(window); |
|
tapted
2015/08/26 03:04:48
(this is a good change, but distracts a tiny bit -
jackhou1
2015/08/26 06:24:42
Done.
| |
| 35 DCHECK([event_window isKindOfClass:[ChromeEventProcessingWindow class]]); | |
| 36 | 36 |
| 37 // Do not fire shortcuts on key up. | 37 // Do not fire shortcuts on key up. |
| 38 if ([event type] == NSKeyDown) { | 38 if ([event type] == NSKeyDown) { |
| 39 // Send the event to the menu before sending it to the browser/window | 39 // 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 | 40 // shortcut handling, so that if a user configures cmd-left to mean |
| 41 // "previous tab", it takes precedence over the built-in "history back" | 41 // "previous tab", it takes precedence over the built-in "history back" |
| 42 // binding. Other than that, the |-redispatchKeyEvent:| call would take care | 42 // binding. Other than that, the |-redispatchKeyEvent:| call would take care |
| 43 // of invoking the original menu item shortcut as well. | 43 // of invoking the original menu item shortcut as well. |
| 44 | 44 |
| 45 if ([[NSApp mainMenu] performKeyEquivalent:event]) | 45 if ([[NSApp mainMenu] performKeyEquivalent:event]) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 + (void)activateWindowForController:(NSWindowController*)controller { | 126 + (void)activateWindowForController:(NSWindowController*)controller { |
| 127 // Per http://crbug.com/73779 and http://crbug.com/75223, we need this to | 127 // 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. | 128 // properly activate windows if Chrome is not the active application. |
| 129 [[controller window] makeKeyAndOrderFront:controller]; | 129 [[controller window] makeKeyAndOrderFront:controller]; |
| 130 ProcessSerialNumber psn; | 130 ProcessSerialNumber psn; |
| 131 GetCurrentProcess(&psn); | 131 GetCurrentProcess(&psn); |
| 132 SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly); | 132 SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly); |
| 133 } | 133 } |
| 134 | 134 |
| 135 @end | 135 @end |
| OLD | NEW |