Skip to content

Commit

Permalink
[Mac] Cmd+W should close the User Manager
Browse files Browse the repository at this point in the history
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
  • Loading branch information
noms@chromium.org committed Jul 10, 2014
1 parent 8938846 commit 3bb9977
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
1 change: 0 additions & 1 deletion chrome/browser/ui/cocoa/profiles/user_manager_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_window.h"

class UserManagerMac;
@class UserManagerWindowController;

namespace content {
Expand Down
39 changes: 38 additions & 1 deletion chrome/browser/ui/cocoa/profiles/user_manager_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
Expand All @@ -66,7 +101,7 @@ - (id)initWithProfile:(Profile*)profile
NSRect contentRect = NSMakeRect((screenWidth - kWindowWidth) / 2,
(screenHeight - kWindowHeight) / 2,
kWindowWidth, kWindowHeight);
NSWindow* window = [[NSWindow alloc]
ChromeEventProcessingWindow* window = [[ChromeEventProcessingWindow alloc]
initWithContentRect:contentRect
styleMask:NSTitledWindowMask |
NSClosableWindowMask |
Expand All @@ -83,6 +118,8 @@ - (id)initWithProfile:(Profile*)profile
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]
Expand Down

0 comments on commit 3bb9977

Please sign in to comment.