Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Side by Side Diff: chrome/browser/ui/cocoa/profiles/user_manager_mac.mm

Issue 378693003: [Mac] Cmd+W should close the User Manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "chrome/browser/ui/cocoa/profiles/user_manager_mac.h" 5 #include "chrome/browser/ui/cocoa/profiles/user_manager_mac.h"
6 6
7 #include "base/mac/foundation_util.h"
8 #include "chrome/app/chrome_command_ids.h"
7 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/profiles/profile_manager.h" 10 #include "chrome/browser/profiles/profile_manager.h"
9 #include "chrome/browser/ui/browser_dialogs.h" 11 #include "chrome/browser/ui/browser_dialogs.h"
12 #import "chrome/browser/ui/cocoa/browser_window_utils.h"
13 #include "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
14 #include "content/public/browser/native_web_keyboard_event.h"
10 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_contents_delegate.h"
11 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
12 #include "ui/base/l10n/l10n_util_mac.h" 18 #include "ui/base/l10n/l10n_util_mac.h"
13 19
14 // Default window size. Taken from the views implementation in 20 // Default window size. Taken from the views implementation in
15 // chrome/browser/ui/views/user_manager_view.cc. 21 // chrome/browser/ui/views/user_manager_view.cc.
16 // TODO(noms): Figure out if this size can be computed dynamically or adjusted 22 // TODO(noms): Figure out if this size can be computed dynamically or adjusted
17 // for smaller screens. 23 // for smaller screens.
18 const int kWindowWidth = 900; 24 const int kWindowWidth = 900;
19 const int kWindowHeight = 700; 25 const int kWindowHeight = 700;
20 26
21 namespace chrome { 27 namespace chrome {
22 28
23 // Declared in browser_dialogs.h so others don't have to depend on this header. 29 // Declared in browser_dialogs.h so others don't have to depend on this header.
24 void ShowUserManager(const base::FilePath& profile_path_to_focus) { 30 void ShowUserManager(const base::FilePath& profile_path_to_focus) {
25 UserManagerMac::Show( 31 UserManagerMac::Show(
26 profile_path_to_focus, profiles::USER_MANAGER_NO_TUTORIAL); 32 profile_path_to_focus, profiles::USER_MANAGER_NO_TUTORIAL);
27 } 33 }
28 34
29 void ShowUserManagerWithTutorial(profiles::UserManagerTutorialMode tutorial) { 35 void ShowUserManagerWithTutorial(profiles::UserManagerTutorialMode tutorial) {
30 UserManagerMac::Show(base::FilePath(), tutorial); 36 UserManagerMac::Show(base::FilePath(), tutorial);
31 } 37 }
32 38
33 void HideUserManager() { 39 void HideUserManager() {
34 UserManagerMac::Hide(); 40 UserManagerMac::Hide();
35 } 41 }
36 42
37 } // namespace chrome 43 } // namespace chrome
38 44
45 // Custom WebContentsDelegate that allows handling of hotkeys.
46 class UserManagerWebContentsDelegate : public content::WebContentsDelegate {
47 public:
48 UserManagerWebContentsDelegate(NSWindow* window) : window_(window) {}
groby-ooo-7-16 2014/07/08 23:31:28 Make the ctor take a ChromeEventProcessingWindow..
noms (inactive) 2014/07/09 18:06:55 Done.
49
50 // WebContentsDelegate implementation. Forwards all unhandled keyboard events
51 // to the current window.
52 virtual void HandleKeyboardEvent(
53 content::WebContents* source,
54 const content::NativeWebKeyboardEvent& event) OVERRIDE {
55 // Since the User Manager is a "top level" window, only handle close events.
groby-ooo-7-16 2014/07/08 23:31:28 Really? No other shortcuts? Quit?
noms (inactive) 2014/07/09 18:06:55 I guess that would make sense. No other shortcuts
56 if (![BrowserWindowUtils shouldHandleKeyboardEvent:event] ||
57 [BrowserWindowUtils getCommandId:event] != IDC_CLOSE_WINDOW)
groby-ooo-7-16 2014/07/08 23:31:28 getCommandId != -1, maybe? Or skip this entirely,
noms (inactive) 2014/07/09 18:06:55 Hmm, I may be misreading this, but wouldn't redisp
groby-ooo-7-16 2014/07/09 19:48:13 That's really odd UI behavior. You're essentially
noms (inactive) 2014/07/09 21:08:14 Trying to soothe some worries: It's not app modal.
58 return;
59
60 // Not invoking +[BrowserWindowUtils handleKeyboardEvent here], since the
61 // window in question is a ConstrainedWindowCustomWindow, not a
62 // BrowserWindow.
63 ChromeEventProcessingWindow* event_window =
groby-ooo-7-16 2014/07/08 23:31:28 Which kills the DCHECK here.
noms (inactive) 2014/07/09 18:06:55 Done.
64 base::mac::ObjCCastStrict<ChromeEventProcessingWindow>(window_);
65 [event_window redispatchKeyEvent:event.os_event];
66 }
67
68 private:
69 NSWindow* window_; // Used to redispatch key events.
70 };
71
39 // Window controller for the User Manager view. 72 // Window controller for the User Manager view.
40 @interface UserManagerWindowController : NSWindowController <NSWindowDelegate> { 73 @interface UserManagerWindowController : NSWindowController <NSWindowDelegate> {
41 @private 74 @private
42 scoped_ptr<content::WebContents> webContents_; 75 scoped_ptr<content::WebContents> webContents_;
76 scoped_ptr<UserManagerWebContentsDelegate> webContentsDelegate_;
43 UserManagerMac* userManagerObserver_; // Weak. 77 UserManagerMac* userManagerObserver_; // Weak.
44 } 78 }
45 - (void)windowWillClose:(NSNotification*)notification; 79 - (void)windowWillClose:(NSNotification*)notification;
46 - (void)dealloc; 80 - (void)dealloc;
47 - (id)initWithProfile:(Profile*)profile 81 - (id)initWithProfile:(Profile*)profile
48 withObserver:(UserManagerMac*)userManagerObserver; 82 withObserver:(UserManagerMac*)userManagerObserver;
49 - (void)showURL:(const GURL&)url; 83 - (void)showURL:(const GURL&)url;
50 - (void)show; 84 - (void)show;
51 - (void)close; 85 - (void)close;
52 - (BOOL)isVisible; 86 - (BOOL)isVisible;
53 @end 87 @end
54 88
55 @implementation UserManagerWindowController 89 @implementation UserManagerWindowController
56 90
57 - (id)initWithProfile:(Profile*)profile 91 - (id)initWithProfile:(Profile*)profile
58 withObserver:(UserManagerMac*)userManagerObserver { 92 withObserver:(UserManagerMac*)userManagerObserver {
59 93
60 // Center the window on the primary screen. 94 // Center the window on the primary screen.
61 CGFloat screenHeight = 95 CGFloat screenHeight =
62 [[[NSScreen screens] objectAtIndex:0] frame].size.height; 96 [[[NSScreen screens] objectAtIndex:0] frame].size.height;
63 CGFloat screenWidth = 97 CGFloat screenWidth =
64 [[[NSScreen screens] objectAtIndex:0] frame].size.width; 98 [[[NSScreen screens] objectAtIndex:0] frame].size.width;
65 99
66 NSRect contentRect = NSMakeRect((screenWidth - kWindowWidth) / 2, 100 NSRect contentRect = NSMakeRect((screenWidth - kWindowWidth) / 2,
67 (screenHeight - kWindowHeight) / 2, 101 (screenHeight - kWindowHeight) / 2,
68 kWindowWidth, kWindowHeight); 102 kWindowWidth, kWindowHeight);
69 NSWindow* window = [[NSWindow alloc] 103 ChromeEventProcessingWindow* window = [[ChromeEventProcessingWindow alloc]
70 initWithContentRect:contentRect 104 initWithContentRect:contentRect
71 styleMask:NSTitledWindowMask | 105 styleMask:NSTitledWindowMask |
72 NSClosableWindowMask | 106 NSClosableWindowMask |
73 NSResizableWindowMask 107 NSResizableWindowMask
74 backing:NSBackingStoreBuffered 108 backing:NSBackingStoreBuffered
75 defer:NO]; 109 defer:NO];
76 [window setTitle:l10n_util::GetNSString(IDS_USER_MANAGER_SCREEN_TITLE)]; 110 [window setTitle:l10n_util::GetNSString(IDS_USER_MANAGER_SCREEN_TITLE)];
77 [window setMinSize:NSMakeSize(kWindowWidth, kWindowHeight)]; 111 [window setMinSize:NSMakeSize(kWindowWidth, kWindowHeight)];
78 112
79 if ((self = [super initWithWindow:window])) { 113 if ((self = [super initWithWindow:window])) {
80 userManagerObserver_ = userManagerObserver; 114 userManagerObserver_ = userManagerObserver;
81 115
82 // Initialize the web view. 116 // Initialize the web view.
83 webContents_.reset(content::WebContents::Create( 117 webContents_.reset(content::WebContents::Create(
84 content::WebContents::CreateParams(profile))); 118 content::WebContents::CreateParams(profile)));
85 window.contentView = webContents_->GetNativeView(); 119 window.contentView = webContents_->GetNativeView();
120 webContentsDelegate_.reset(
121 new UserManagerWebContentsDelegate([self window]));
122 webContents_->SetDelegate(webContentsDelegate_.get());
86 DCHECK(window.contentView); 123 DCHECK(window.contentView);
87 124
88 [[NSNotificationCenter defaultCenter] 125 [[NSNotificationCenter defaultCenter]
89 addObserver:self 126 addObserver:self
90 selector:@selector(windowWillClose:) 127 selector:@selector(windowWillClose:)
91 name:NSWindowWillCloseNotification 128 name:NSWindowWillCloseNotification
92 object:self.window]; 129 object:self.window];
93 } 130 }
94 return self; 131 return self;
95 } 132 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 void UserManagerMac::OnGuestProfileCreated(Profile* guest_profile, 206 void UserManagerMac::OnGuestProfileCreated(Profile* guest_profile,
170 const std::string& url) { 207 const std::string& url) {
171 instance_ = new UserManagerMac(guest_profile); 208 instance_ = new UserManagerMac(guest_profile);
172 [instance_->window_controller_ showURL:GURL(url)]; 209 [instance_->window_controller_ showURL:GURL(url)];
173 } 210 }
174 211
175 void UserManagerMac::WindowWasClosed() { 212 void UserManagerMac::WindowWasClosed() {
176 instance_ = NULL; 213 instance_ = NULL;
177 delete this; 214 delete this;
178 } 215 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698