Index: chrome/browser/ui/cocoa/profiles/user_manager_mac.mm |
diff --git a/chrome/browser/ui/cocoa/profiles/user_manager_mac.mm b/chrome/browser/ui/cocoa/profiles/user_manager_mac.mm |
index 957d95ba57bb6b8b04cab3e077f8fa47836a668c..429374f400f20ae991e396b00ed6f4dc56e26ecd 100644 |
--- a/chrome/browser/ui/cocoa/profiles/user_manager_mac.mm |
+++ b/chrome/browser/ui/cocoa/profiles/user_manager_mac.mm |
@@ -6,6 +6,7 @@ |
#include "chrome/app/chrome_command_ids.h" |
#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/global_keyboard_shortcuts_mac.h" |
#include "chrome/browser/profiles/profile_manager.h" |
#include "chrome/browser/ui/browser_dialogs.h" |
#import "chrome/browser/ui/cocoa/browser_window_utils.h" |
@@ -44,8 +45,7 @@ void HideUserManager() { |
// Custom WebContentsDelegate that allows handling of hotkeys. |
class UserManagerWebContentsDelegate : public content::WebContentsDelegate { |
public: |
- UserManagerWebContentsDelegate(ChromeEventProcessingWindow* window) |
- : window_(window) {} |
+ UserManagerWebContentsDelegate() {} |
// WebContentsDelegate implementation. Forwards all unhandled keyboard events |
// to the current window. |
@@ -55,19 +55,25 @@ class UserManagerWebContentsDelegate : public content::WebContentsDelegate { |
if (![BrowserWindowUtils shouldHandleKeyboardEvent:event]) |
return; |
- int commandId = [BrowserWindowUtils getCommandId:event]; |
+ // -getCommandId returns -1 if the event isn't a chrome accelerator. |
+ int chromeCommandId = [BrowserWindowUtils getCommandId:event]; |
+ |
+ // Also interested in Cmd+A and Cmd+V events that could come from a |
+ // password field. |
+ bool isTextEditingCommand = false; |
+ if (chromeCommandId == -1 && [event.os_event type] == NSKeyDown) { |
+ NSUInteger modifiers = [event.os_event modifierFlags]; |
+ const bool cmdKey = (modifiers & NSCommandKeyMask) != 0; |
+ const unichar keyChar = KeyCharacterForEvent(event.os_event); |
+ isTextEditingCommand = cmdKey && (keyChar == 'a' || keyChar == 'v'); |
groby-ooo-7-16
2014/09/18 06:35:11
nit: Get rid of modifiers and cmdKey, just the tes
noms (inactive)
2014/09/18 15:59:11
AMAZING! Done.
|
+ } |
- // Since the User Manager is a "top level" window, only handle close events. |
- if (commandId == IDC_CLOSE_WINDOW || commandId == IDC_EXIT) { |
- // Not invoking +[BrowserWindowUtils handleKeyboardEvent here], since the |
- // window in question is a ConstrainedWindowCustomWindow, not a |
- // BrowserWindow. |
- [window_ redispatchKeyEvent:event.os_event]; |
+ // Only handle close window Chrome accelerators and text editing ones. |
+ if (chromeCommandId == IDC_CLOSE_WINDOW || chromeCommandId == IDC_EXIT || |
+ isTextEditingCommand) { |
+ [[NSApp mainMenu] performKeyEquivalent:event.os_event]; |
} |
} |
- |
- private: |
- ChromeEventProcessingWindow* window_; // Used to redispatch key events. |
}; |
// Window controller for the User Manager view. |
@@ -118,7 +124,7 @@ class UserManagerWebContentsDelegate : public content::WebContentsDelegate { |
webContents_.reset(content::WebContents::Create( |
content::WebContents::CreateParams(profile))); |
window.contentView = webContents_->GetNativeView(); |
- webContentsDelegate_.reset(new UserManagerWebContentsDelegate(window)); |
+ webContentsDelegate_.reset(new UserManagerWebContentsDelegate()); |
webContents_->SetDelegate(webContentsDelegate_.get()); |
DCHECK(window.contentView); |