Chromium Code Reviews| 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 "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/global_keyboard_shortcuts_mac.h" | |
| 9 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
| 10 #include "chrome/browser/ui/browser_dialogs.h" | 11 #include "chrome/browser/ui/browser_dialogs.h" |
| 11 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 12 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 12 #include "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 13 #include "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
| 13 #include "chrome/grit/chromium_strings.h" | 14 #include "chrome/grit/chromium_strings.h" |
| 14 #include "content/public/browser/native_web_keyboard_event.h" | 15 #include "content/public/browser/native_web_keyboard_event.h" |
| 15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/browser/web_contents_delegate.h" | 17 #include "content/public/browser/web_contents_delegate.h" |
| 18 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
|
groby-ooo-7-16
2014/09/18 20:59:56
nit: transitively included by native_web_keyboard_
noms (inactive)
2014/09/18 21:11:50
Done.
| |
| 17 #include "ui/base/l10n/l10n_util_mac.h" | 19 #include "ui/base/l10n/l10n_util_mac.h" |
| 20 #include "ui/events/keycodes/keyboard_codes.h" | |
| 18 | 21 |
| 19 // Default window size. Taken from the views implementation in | 22 // Default window size. Taken from the views implementation in |
| 20 // chrome/browser/ui/views/user_manager_view.cc. | 23 // chrome/browser/ui/views/user_manager_view.cc. |
| 21 // TODO(noms): Figure out if this size can be computed dynamically or adjusted | 24 // TODO(noms): Figure out if this size can be computed dynamically or adjusted |
| 22 // for smaller screens. | 25 // for smaller screens. |
| 23 const int kWindowWidth = 900; | 26 const int kWindowWidth = 900; |
| 24 const int kWindowHeight = 700; | 27 const int kWindowHeight = 700; |
| 25 | 28 |
| 26 namespace chrome { | 29 namespace chrome { |
| 27 | 30 |
| 28 // Declared in browser_dialogs.h so others don't have to depend on this header. | 31 // Declared in browser_dialogs.h so others don't have to depend on this header. |
| 29 void ShowUserManager(const base::FilePath& profile_path_to_focus) { | 32 void ShowUserManager(const base::FilePath& profile_path_to_focus) { |
| 30 UserManagerMac::Show( | 33 UserManagerMac::Show( |
| 31 profile_path_to_focus, profiles::USER_MANAGER_NO_TUTORIAL); | 34 profile_path_to_focus, profiles::USER_MANAGER_NO_TUTORIAL); |
| 32 } | 35 } |
| 33 | 36 |
| 34 void ShowUserManagerWithTutorial(profiles::UserManagerTutorialMode tutorial) { | 37 void ShowUserManagerWithTutorial(profiles::UserManagerTutorialMode tutorial) { |
| 35 UserManagerMac::Show(base::FilePath(), tutorial); | 38 UserManagerMac::Show(base::FilePath(), tutorial); |
| 36 } | 39 } |
| 37 | 40 |
| 38 void HideUserManager() { | 41 void HideUserManager() { |
| 39 UserManagerMac::Hide(); | 42 UserManagerMac::Hide(); |
| 40 } | 43 } |
| 41 | 44 |
| 42 } // namespace chrome | 45 } // namespace chrome |
| 43 | 46 |
| 44 // Custom WebContentsDelegate that allows handling of hotkeys. | 47 // Custom WebContentsDelegate that allows handling of hotkeys. |
| 45 class UserManagerWebContentsDelegate : public content::WebContentsDelegate { | 48 class UserManagerWebContentsDelegate : public content::WebContentsDelegate { |
| 46 public: | 49 public: |
| 47 UserManagerWebContentsDelegate(ChromeEventProcessingWindow* window) | 50 UserManagerWebContentsDelegate() {} |
| 48 : window_(window) {} | |
| 49 | 51 |
| 50 // WebContentsDelegate implementation. Forwards all unhandled keyboard events | 52 // WebContentsDelegate implementation. Forwards all unhandled keyboard events |
| 51 // to the current window. | 53 // to the current window. |
| 52 virtual void HandleKeyboardEvent( | 54 virtual void HandleKeyboardEvent( |
| 53 content::WebContents* source, | 55 content::WebContents* source, |
| 54 const content::NativeWebKeyboardEvent& event) OVERRIDE { | 56 const content::NativeWebKeyboardEvent& event) OVERRIDE { |
| 55 if (![BrowserWindowUtils shouldHandleKeyboardEvent:event]) | 57 if (![BrowserWindowUtils shouldHandleKeyboardEvent:event]) |
| 56 return; | 58 return; |
| 57 | 59 |
| 58 int commandId = [BrowserWindowUtils getCommandId:event]; | 60 // -getCommandId returns -1 if the event isn't a chrome accelerator. |
| 61 int chromeCommandId = [BrowserWindowUtils getCommandId:event]; | |
| 59 | 62 |
| 60 // Since the User Manager is a "top level" window, only handle close events. | 63 // Also interested in Cmd+A and Cmd+V events that could come from a |
| 61 if (commandId == IDC_CLOSE_WINDOW || commandId == IDC_EXIT) { | 64 // password field. |
| 62 // Not invoking +[BrowserWindowUtils handleKeyboardEvent here], since the | 65 bool isTextEditingCommand = |
| 63 // window in question is a ConstrainedWindowCustomWindow, not a | 66 (event.modifiers & blink::WebInputEvent::MetaKey) && |
| 64 // BrowserWindow. | 67 (event.windowsKeyCode == ui::VKEY_A || |
| 65 [window_ redispatchKeyEvent:event.os_event]; | 68 event.windowsKeyCode == ui::VKEY_V); |
| 69 | |
| 70 // Only handle close window Chrome accelerators and text editing ones. | |
| 71 if (chromeCommandId == IDC_CLOSE_WINDOW || chromeCommandId == IDC_EXIT || | |
| 72 isTextEditingCommand) { | |
| 73 [[NSApp mainMenu] performKeyEquivalent:event.os_event]; | |
| 66 } | 74 } |
| 67 } | 75 } |
| 68 | |
| 69 private: | |
| 70 ChromeEventProcessingWindow* window_; // Used to redispatch key events. | |
| 71 }; | 76 }; |
| 72 | 77 |
| 73 // Window controller for the User Manager view. | 78 // Window controller for the User Manager view. |
| 74 @interface UserManagerWindowController : NSWindowController <NSWindowDelegate> { | 79 @interface UserManagerWindowController : NSWindowController <NSWindowDelegate> { |
| 75 @private | 80 @private |
| 76 scoped_ptr<content::WebContents> webContents_; | 81 scoped_ptr<content::WebContents> webContents_; |
| 77 scoped_ptr<UserManagerWebContentsDelegate> webContentsDelegate_; | 82 scoped_ptr<UserManagerWebContentsDelegate> webContentsDelegate_; |
| 78 UserManagerMac* userManagerObserver_; // Weak. | 83 UserManagerMac* userManagerObserver_; // Weak. |
| 79 } | 84 } |
| 80 - (void)windowWillClose:(NSNotification*)notification; | 85 - (void)windowWillClose:(NSNotification*)notification; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 111 [window setTitle:l10n_util::GetNSString(IDS_PRODUCT_NAME)]; | 116 [window setTitle:l10n_util::GetNSString(IDS_PRODUCT_NAME)]; |
| 112 [window setMinSize:NSMakeSize(kWindowWidth, kWindowHeight)]; | 117 [window setMinSize:NSMakeSize(kWindowWidth, kWindowHeight)]; |
| 113 | 118 |
| 114 if ((self = [super initWithWindow:window])) { | 119 if ((self = [super initWithWindow:window])) { |
| 115 userManagerObserver_ = userManagerObserver; | 120 userManagerObserver_ = userManagerObserver; |
| 116 | 121 |
| 117 // Initialize the web view. | 122 // Initialize the web view. |
| 118 webContents_.reset(content::WebContents::Create( | 123 webContents_.reset(content::WebContents::Create( |
| 119 content::WebContents::CreateParams(profile))); | 124 content::WebContents::CreateParams(profile))); |
| 120 window.contentView = webContents_->GetNativeView(); | 125 window.contentView = webContents_->GetNativeView(); |
| 121 webContentsDelegate_.reset(new UserManagerWebContentsDelegate(window)); | 126 webContentsDelegate_.reset(new UserManagerWebContentsDelegate()); |
| 122 webContents_->SetDelegate(webContentsDelegate_.get()); | 127 webContents_->SetDelegate(webContentsDelegate_.get()); |
| 123 DCHECK(window.contentView); | 128 DCHECK(window.contentView); |
| 124 | 129 |
| 125 [[NSNotificationCenter defaultCenter] | 130 [[NSNotificationCenter defaultCenter] |
| 126 addObserver:self | 131 addObserver:self |
| 127 selector:@selector(windowWillClose:) | 132 selector:@selector(windowWillClose:) |
| 128 name:NSWindowWillCloseNotification | 133 name:NSWindowWillCloseNotification |
| 129 object:self.window]; | 134 object:self.window]; |
| 130 } | 135 } |
| 131 return self; | 136 return self; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 void UserManagerMac::OnGuestProfileCreated(Profile* guest_profile, | 211 void UserManagerMac::OnGuestProfileCreated(Profile* guest_profile, |
| 207 const std::string& url) { | 212 const std::string& url) { |
| 208 instance_ = new UserManagerMac(guest_profile); | 213 instance_ = new UserManagerMac(guest_profile); |
| 209 [instance_->window_controller_ showURL:GURL(url)]; | 214 [instance_->window_controller_ showURL:GURL(url)]; |
| 210 } | 215 } |
| 211 | 216 |
| 212 void UserManagerMac::WindowWasClosed() { | 217 void UserManagerMac::WindowWasClosed() { |
| 213 instance_ = NULL; | 218 instance_ = NULL; |
| 214 delete this; | 219 delete this; |
| 215 } | 220 } |
| OLD | NEW |