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

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

Issue 553133002: [Mac] Add text-editing accelerators to the User Manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: possibly moar better? Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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"
17 #include "ui/base/l10n/l10n_util_mac.h" 18 #include "ui/base/l10n/l10n_util_mac.h"
18 19
(...skipping 18 matching lines...) Expand all
37 38
38 void HideUserManager() { 39 void HideUserManager() {
39 UserManagerMac::Hide(); 40 UserManagerMac::Hide();
40 } 41 }
41 42
42 } // namespace chrome 43 } // namespace chrome
43 44
44 // Custom WebContentsDelegate that allows handling of hotkeys. 45 // Custom WebContentsDelegate that allows handling of hotkeys.
45 class UserManagerWebContentsDelegate : public content::WebContentsDelegate { 46 class UserManagerWebContentsDelegate : public content::WebContentsDelegate {
46 public: 47 public:
47 UserManagerWebContentsDelegate(ChromeEventProcessingWindow* window) 48 UserManagerWebContentsDelegate() {}
48 : window_(window) {}
49 49
50 // WebContentsDelegate implementation. Forwards all unhandled keyboard events 50 // WebContentsDelegate implementation. Forwards all unhandled keyboard events
51 // to the current window. 51 // to the current window.
52 virtual void HandleKeyboardEvent( 52 virtual void HandleKeyboardEvent(
53 content::WebContents* source, 53 content::WebContents* source,
54 const content::NativeWebKeyboardEvent& event) OVERRIDE { 54 const content::NativeWebKeyboardEvent& event) OVERRIDE {
55 if (![BrowserWindowUtils shouldHandleKeyboardEvent:event]) 55 if (![BrowserWindowUtils shouldHandleKeyboardEvent:event])
56 return; 56 return;
57 57
58 int commandId = [BrowserWindowUtils getCommandId:event]; 58 // -getCommandId returns -1 if the event isn't a chrome accelerator.
59 int chromeCommandId = [BrowserWindowUtils getCommandId:event];
59 60
60 // Since the User Manager is a "top level" window, only handle close events. 61 // Also interested in Cmd+A and Cmd+V events that could come from a
61 if (commandId == IDC_CLOSE_WINDOW || commandId == IDC_EXIT) { 62 // password field.
62 // Not invoking +[BrowserWindowUtils handleKeyboardEvent here], since the 63 bool isTextEditingCommand = false;
63 // window in question is a ConstrainedWindowCustomWindow, not a 64 if (chromeCommandId == -1 && [event.os_event type] == NSKeyDown) {
64 // BrowserWindow. 65 NSUInteger modifiers = [event.os_event modifierFlags];
65 [window_ redispatchKeyEvent:event.os_event]; 66 const bool cmdKey = (modifiers & NSCommandKeyMask) != 0;
67 const unichar keyChar = KeyCharacterForEvent(event.os_event);
68 isTextEditingCommand = cmdKey && (keyChar == 'a' || keyChar == 'v');
noms (inactive) 2014/09/17 19:45:46 So I don't like this very much, but ui::VKEY_A has
groby-ooo-7-16 2014/09/17 21:42:44 Yes, there is - If you only had the NSEvent, Keybo
noms (inactive) 2014/09/18 15:59:11 Gah, I should've looked at NativeWebKeyboardEvent.
69 }
70
71 // Only handle close window Chrome accelerators and text editing ones.
72 if (chromeCommandId == IDC_CLOSE_WINDOW || chromeCommandId == IDC_EXIT ||
73 isTextEditingCommand) {
74 [[NSApp mainMenu] performKeyEquivalent:event.os_event];
66 } 75 }
67 } 76 }
68
69 private:
70 ChromeEventProcessingWindow* window_; // Used to redispatch key events.
71 }; 77 };
72 78
73 // Window controller for the User Manager view. 79 // Window controller for the User Manager view.
74 @interface UserManagerWindowController : NSWindowController <NSWindowDelegate> { 80 @interface UserManagerWindowController : NSWindowController <NSWindowDelegate> {
75 @private 81 @private
76 scoped_ptr<content::WebContents> webContents_; 82 scoped_ptr<content::WebContents> webContents_;
77 scoped_ptr<UserManagerWebContentsDelegate> webContentsDelegate_; 83 scoped_ptr<UserManagerWebContentsDelegate> webContentsDelegate_;
78 UserManagerMac* userManagerObserver_; // Weak. 84 UserManagerMac* userManagerObserver_; // Weak.
79 } 85 }
80 - (void)windowWillClose:(NSNotification*)notification; 86 - (void)windowWillClose:(NSNotification*)notification;
(...skipping 30 matching lines...) Expand all
111 [window setTitle:l10n_util::GetNSString(IDS_PRODUCT_NAME)]; 117 [window setTitle:l10n_util::GetNSString(IDS_PRODUCT_NAME)];
112 [window setMinSize:NSMakeSize(kWindowWidth, kWindowHeight)]; 118 [window setMinSize:NSMakeSize(kWindowWidth, kWindowHeight)];
113 119
114 if ((self = [super initWithWindow:window])) { 120 if ((self = [super initWithWindow:window])) {
115 userManagerObserver_ = userManagerObserver; 121 userManagerObserver_ = userManagerObserver;
116 122
117 // Initialize the web view. 123 // Initialize the web view.
118 webContents_.reset(content::WebContents::Create( 124 webContents_.reset(content::WebContents::Create(
119 content::WebContents::CreateParams(profile))); 125 content::WebContents::CreateParams(profile)));
120 window.contentView = webContents_->GetNativeView(); 126 window.contentView = webContents_->GetNativeView();
121 webContentsDelegate_.reset(new UserManagerWebContentsDelegate(window)); 127 webContentsDelegate_.reset(new UserManagerWebContentsDelegate());
122 webContents_->SetDelegate(webContentsDelegate_.get()); 128 webContents_->SetDelegate(webContentsDelegate_.get());
123 DCHECK(window.contentView); 129 DCHECK(window.contentView);
124 130
125 [[NSNotificationCenter defaultCenter] 131 [[NSNotificationCenter defaultCenter]
126 addObserver:self 132 addObserver:self
127 selector:@selector(windowWillClose:) 133 selector:@selector(windowWillClose:)
128 name:NSWindowWillCloseNotification 134 name:NSWindowWillCloseNotification
129 object:self.window]; 135 object:self.window];
130 } 136 }
131 return self; 137 return self;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 void UserManagerMac::OnGuestProfileCreated(Profile* guest_profile, 212 void UserManagerMac::OnGuestProfileCreated(Profile* guest_profile,
207 const std::string& url) { 213 const std::string& url) {
208 instance_ = new UserManagerMac(guest_profile); 214 instance_ = new UserManagerMac(guest_profile);
209 [instance_->window_controller_ showURL:GURL(url)]; 215 [instance_->window_controller_ showURL:GURL(url)];
210 } 216 }
211 217
212 void UserManagerMac::WindowWasClosed() { 218 void UserManagerMac::WindowWasClosed() {
213 instance_ = NULL; 219 instance_ = NULL;
214 delete this; 220 delete this;
215 } 221 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698