diff options
author | noms@chromium.org <noms@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-10 19:16:22 +0000 |
---|---|---|
committer | noms@chromium.org <noms@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-10 19:16:22 +0000 |
commit | 3bb99779444dab729ec6693a9005c4bd6178aaae (patch) | |
tree | 332fd9bb1c5a733f90b220b0c26abebb2aba0678 | |
parent | 89388467d74db2a1d712f367a23cffa4ed91ba9f (diff) | |
download | chromium_src-3bb99779444dab729ec6693a9005c4bd6178aaae.zip chromium_src-3bb99779444dab729ec6693a9005c4bd6178aaae.tar.gz chromium_src-3bb99779444dab729ec6693a9005c4bd6178aaae.tar.bz2 |
[Mac] Cmd+W should close the User Manager
This implementation is similar to that in ui/cocoa/autofill/autofill_sign_in_container.mm.
BUG=364644
TEST=Start Chrome with --new-profile-management turned on. From the avatar
menu, select "Not <name>". The User Manager should show up. Cmd+W should
close it, but other accelerators (eg. Cmd+t) should not work.
Review URL: https://codereview.chromium.org/378693003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282390 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/cocoa/profiles/user_manager_mac.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/profiles/user_manager_mac.mm | 39 |
2 files changed, 38 insertions, 2 deletions
diff --git a/chrome/browser/ui/cocoa/profiles/user_manager_mac.h b/chrome/browser/ui/cocoa/profiles/user_manager_mac.h index 5778628..e710062 100644 --- a/chrome/browser/ui/cocoa/profiles/user_manager_mac.h +++ b/chrome/browser/ui/cocoa/profiles/user_manager_mac.h @@ -12,7 +12,6 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_window.h" -class UserManagerMac; @class UserManagerWindowController; namespace content { diff --git a/chrome/browser/ui/cocoa/profiles/user_manager_mac.mm b/chrome/browser/ui/cocoa/profiles/user_manager_mac.mm index 3087ac4..446ff2a 100644 --- a/chrome/browser/ui/cocoa/profiles/user_manager_mac.mm +++ b/chrome/browser/ui/cocoa/profiles/user_manager_mac.mm @@ -4,10 +4,15 @@ #include "chrome/browser/ui/cocoa/profiles/user_manager_mac.h" +#include "chrome/app/chrome_command_ids.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/ui/browser_dialogs.h" +#import "chrome/browser/ui/cocoa/browser_window_utils.h" +#include "chrome/browser/ui/cocoa/chrome_event_processing_window.h" +#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/web_contents.h" +#include "content/public/browser/web_contents_delegate.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util_mac.h" @@ -36,10 +41,40 @@ void HideUserManager() { } // namespace chrome +// Custom WebContentsDelegate that allows handling of hotkeys. +class UserManagerWebContentsDelegate : public content::WebContentsDelegate { + public: + UserManagerWebContentsDelegate(ChromeEventProcessingWindow* window) + : window_(window) {} + + // WebContentsDelegate implementation. Forwards all unhandled keyboard events + // to the current window. + virtual void HandleKeyboardEvent( + content::WebContents* source, + const content::NativeWebKeyboardEvent& event) OVERRIDE { + if (![BrowserWindowUtils shouldHandleKeyboardEvent:event]) + return; + + int commandId = [BrowserWindowUtils getCommandId:event]; + + // 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]; + } + } + + private: + ChromeEventProcessingWindow* window_; // Used to redispatch key events. +}; + // Window controller for the User Manager view. @interface UserManagerWindowController : NSWindowController <NSWindowDelegate> { @private scoped_ptr<content::WebContents> webContents_; + scoped_ptr<UserManagerWebContentsDelegate> webContentsDelegate_; UserManagerMac* userManagerObserver_; // Weak. } - (void)windowWillClose:(NSNotification*)notification; @@ -66,7 +101,7 @@ void HideUserManager() { NSRect contentRect = NSMakeRect((screenWidth - kWindowWidth) / 2, (screenHeight - kWindowHeight) / 2, kWindowWidth, kWindowHeight); - NSWindow* window = [[NSWindow alloc] + ChromeEventProcessingWindow* window = [[ChromeEventProcessingWindow alloc] initWithContentRect:contentRect styleMask:NSTitledWindowMask | NSClosableWindowMask | @@ -83,6 +118,8 @@ void HideUserManager() { webContents_.reset(content::WebContents::Create( content::WebContents::CreateParams(profile))); window.contentView = webContents_->GetNativeView(); + webContentsDelegate_.reset(new UserManagerWebContentsDelegate(window)); + webContents_->SetDelegate(webContentsDelegate_.get()); DCHECK(window.contentView); [[NSNotificationCenter defaultCenter] |