OLD | NEW |
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" | 7 #include "base/mac/foundation_util.h" |
8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
9 #import "chrome/browser/app_controller_mac.h" | 9 #import "chrome/browser/app_controller_mac.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
12 #include "chrome/browser/profiles/profiles_state.h" | 12 #include "chrome/browser/profiles/profiles_state.h" |
13 #include "chrome/browser/ui/browser_dialogs.h" | 13 #include "chrome/browser/ui/browser_dialogs.h" |
14 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 14 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
15 #include "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 15 #include "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
16 #include "chrome/browser/ui/user_manager.h" | 16 #include "chrome/browser/ui/user_manager.h" |
17 #include "chrome/grit/chromium_strings.h" | 17 #include "chrome/grit/chromium_strings.h" |
18 #include "content/public/browser/native_web_keyboard_event.h" | 18 #include "content/public/browser/native_web_keyboard_event.h" |
19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
20 #include "content/public/browser/web_contents_delegate.h" | 20 #include "content/public/browser/web_contents_delegate.h" |
21 #include "ui/base/l10n/l10n_util_mac.h" | 21 #include "ui/base/l10n/l10n_util_mac.h" |
22 #include "ui/events/keycodes/keyboard_codes.h" | 22 #include "ui/events/keycodes/keyboard_codes.h" |
23 | 23 |
24 // Default window size. Taken from the views implementation in | |
25 // chrome/browser/ui/views/user_manager_view.cc. | |
26 // TODO(noms): Figure out if this size can be computed dynamically or adjusted | |
27 // for smaller screens. | |
28 const int kWindowWidth = 900; | |
29 const int kWindowHeight = 700; | |
30 | 24 |
31 // An open User Manager window. There can only be one open at a time. This | 25 // An open User Manager window. There can only be one open at a time. This |
32 // is reset to NULL when the window is closed. | 26 // is reset to NULL when the window is closed. |
33 UserManagerMac* instance_ = NULL; // Weak. | 27 UserManagerMac* instance_ = NULL; // Weak. |
34 | 28 |
35 // Custom WebContentsDelegate that allows handling of hotkeys. | 29 // Custom WebContentsDelegate that allows handling of hotkeys. |
36 class UserManagerWebContentsDelegate : public content::WebContentsDelegate { | 30 class UserManagerWebContentsDelegate : public content::WebContentsDelegate { |
37 public: | 31 public: |
38 UserManagerWebContentsDelegate() {} | 32 UserManagerWebContentsDelegate() {} |
39 | 33 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 @implementation UserManagerWindowController | 76 @implementation UserManagerWindowController |
83 | 77 |
84 - (id)initWithProfile:(Profile*)profile | 78 - (id)initWithProfile:(Profile*)profile |
85 withObserver:(UserManagerMac*)userManagerObserver { | 79 withObserver:(UserManagerMac*)userManagerObserver { |
86 | 80 |
87 // Center the window on the screen that currently has focus. | 81 // Center the window on the screen that currently has focus. |
88 NSScreen* mainScreen = [NSScreen mainScreen]; | 82 NSScreen* mainScreen = [NSScreen mainScreen]; |
89 CGFloat screenHeight = [mainScreen frame].size.height; | 83 CGFloat screenHeight = [mainScreen frame].size.height; |
90 CGFloat screenWidth = [mainScreen frame].size.width; | 84 CGFloat screenWidth = [mainScreen frame].size.width; |
91 | 85 |
92 NSRect contentRect = NSMakeRect((screenWidth - kWindowWidth) / 2, | 86 NSRect contentRect = |
93 (screenHeight - kWindowHeight) / 2, | 87 NSMakeRect((screenWidth - UserManager::kWindowWidth) / 2, |
94 kWindowWidth, kWindowHeight); | 88 (screenHeight - UserManager::kWindowHeight) / 2, |
| 89 UserManager::kWindowWidth, UserManager::kWindowHeight); |
95 ChromeEventProcessingWindow* window = [[ChromeEventProcessingWindow alloc] | 90 ChromeEventProcessingWindow* window = [[ChromeEventProcessingWindow alloc] |
96 initWithContentRect:contentRect | 91 initWithContentRect:contentRect |
97 styleMask:NSTitledWindowMask | | 92 styleMask:NSTitledWindowMask | |
98 NSClosableWindowMask | | 93 NSClosableWindowMask | |
99 NSResizableWindowMask | 94 NSResizableWindowMask |
100 backing:NSBackingStoreBuffered | 95 backing:NSBackingStoreBuffered |
101 defer:NO | 96 defer:NO |
102 screen:mainScreen]; | 97 screen:mainScreen]; |
103 [window setTitle:l10n_util::GetNSString(IDS_PRODUCT_NAME)]; | 98 [window setTitle:l10n_util::GetNSString(IDS_PRODUCT_NAME)]; |
104 [window setMinSize:NSMakeSize(kWindowWidth, kWindowHeight)]; | 99 [window setMinSize:NSMakeSize(UserManager::kWindowWidth, |
| 100 UserManager::kWindowHeight)]; |
105 | 101 |
106 if ((self = [super initWithWindow:window])) { | 102 if ((self = [super initWithWindow:window])) { |
107 userManagerObserver_ = userManagerObserver; | 103 userManagerObserver_ = userManagerObserver; |
108 | 104 |
109 // Initialize the web view. | 105 // Initialize the web view. |
110 webContents_.reset(content::WebContents::Create( | 106 webContents_.reset(content::WebContents::Create( |
111 content::WebContents::CreateParams(profile))); | 107 content::WebContents::CreateParams(profile))); |
112 window.contentView = webContents_->GetNativeView(); | 108 window.contentView = webContents_->GetNativeView(); |
113 webContentsDelegate_.reset(new UserManagerWebContentsDelegate()); | 109 webContentsDelegate_.reset(new UserManagerWebContentsDelegate()); |
114 webContents_->SetDelegate(webContentsDelegate_.get()); | 110 webContents_->SetDelegate(webContentsDelegate_.get()); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 const std::string& url) { | 204 const std::string& url) { |
209 DCHECK(!instance_); | 205 DCHECK(!instance_); |
210 instance_ = new UserManagerMac(guest_profile); | 206 instance_ = new UserManagerMac(guest_profile); |
211 [instance_->window_controller() showURL:GURL(url)]; | 207 [instance_->window_controller() showURL:GURL(url)]; |
212 } | 208 } |
213 | 209 |
214 void UserManagerMac::WindowWasClosed() { | 210 void UserManagerMac::WindowWasClosed() { |
215 instance_ = NULL; | 211 instance_ = NULL; |
216 delete this; | 212 delete this; |
217 } | 213 } |
OLD | NEW |