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

Unified Diff: chrome/browser/ui/cocoa/passwords/autosignin_prompt_view_controller.mm

Issue 1961023002: Close the account chooser and auto sign-in opt in with ESC on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/passwords/autosignin_prompt_view_controller.mm
diff --git a/chrome/browser/ui/cocoa/passwords/autosignin_prompt_view_controller.mm b/chrome/browser/ui/cocoa/passwords/autosignin_prompt_view_controller.mm
index 3e41ef5e10909fa12a5e43dec264fc8c0545b131..6fdf43cf7b2b5eb0615378670aaad6c4aed44737 100644
--- a/chrome/browser/ui/cocoa/passwords/autosignin_prompt_view_controller.mm
+++ b/chrome/browser/ui/cocoa/passwords/autosignin_prompt_view_controller.mm
@@ -4,9 +4,12 @@
#import "chrome/browser/ui/cocoa/passwords/autosignin_prompt_view_controller.h"
+#include <Carbon/Carbon.h>
+
#include "base/logging.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/string16.h"
+#import "chrome/browser/ui/cocoa/key_equivalent_constants.h"
#import "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h"
#include "chrome/browser/ui/passwords/password_dialog_controller.h"
#include "chrome/browser/ui/passwords/password_dialog_prompts.h"
@@ -32,6 +35,26 @@ NSButton* BiggerDialogButton(NSString* title) {
} // namespace
+@interface AutoSigninPromptView : NSView
+@property (nonatomic, copy) BOOL (^escHandler)(NSEvent* theEvent);
+@end
+
+@implementation AutoSigninPromptView
+@synthesize escHandler = _escHandler;
+
+-(void)dealloc {
+ [_escHandler release];
+ [super dealloc];
+}
+
+- (BOOL)performKeyEquivalent:(NSEvent*)theEvent {
+ if (_escHandler(theEvent))
+ return YES;
+ return [super performKeyEquivalent:theEvent];
+}
+
+@end
+
@interface AutoSigninPromptViewController () {
NSButton* _okButton;
NSButton* _turnOffButton;
@@ -39,6 +62,7 @@ NSButton* BiggerDialogButton(NSString* title) {
}
- (void)onOkClicked:(id)sender;
- (void)onTurnOffClicked:(id)sender;
+- (BOOL)handleEscPress:(NSEvent*)theEvent;
@end
@implementation AutoSigninPromptViewController
@@ -60,7 +84,13 @@ NSButton* BiggerDialogButton(NSString* title) {
// | [ Turn Off ] [ OK ] |
// ------------------------------------
- (void)loadView {
- base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]);
+ base::scoped_nsobject<AutoSigninPromptView> view(
+ [[AutoSigninPromptView alloc] initWithFrame:NSZeroRect]);
+ __block AutoSigninPromptViewController* weakSelf = self;
+ [view setEscHandler:^(NSEvent* theEvent) {
+ return [weakSelf handleEscPress:theEvent];
+ }];
+
// Title.
base::string16 titleText =
@@ -87,7 +117,7 @@ NSButton* BiggerDialogButton(NSString* title) {
BiggerDialogButton(l10n_util::GetNSString(IDS_AUTO_SIGNIN_FIRST_RUN_OK));
[_okButton setTarget:self];
[_okButton setAction:@selector(onOkClicked:)];
- [_okButton setKeyEquivalent:@"\r"];
+ [_okButton setKeyEquivalent:kKeyEquivalentReturn];
[view addSubview:_okButton];
_turnOffButton = BiggerDialogButton(
@@ -96,6 +126,14 @@ NSButton* BiggerDialogButton(NSString* title) {
[_turnOffButton setAction:@selector(onTurnOffClicked:)];
[view addSubview:_turnOffButton];
+ // Invisible button to handle ESC.
+ base::scoped_nsobject<NSButton> cancel_button(
+ [[NSButton alloc] initWithFrame:NSZeroRect]);
+ [cancel_button setTarget:self];
+ [cancel_button setAction:@selector(onEscClicked:)];
+ [cancel_button setKeyEquivalent:kKeyEquivalentEscape];
+ [view addSubview:cancel_button];
+
// Layout.
// Compute the bubble width using the title and the buttons.
const CGFloat contentWidth = kDesiredBubbleWidth;
@@ -142,6 +180,15 @@ NSButton* BiggerDialogButton(NSString* title) {
_bridge->GetDialogController()->OnAutoSigninTurnOff();
}
+- (BOOL)handleEscPress:(NSEvent*)theEvent {
+ if ([theEvent keyCode] == kVK_Escape) {
+ if (_bridge)
+ _bridge->PerformClose();
+ return YES;
+ }
+ return NO;
+}
+
@end
@implementation AutoSigninPromptViewController(Testing)

Powered by Google App Engine
This is Rietveld 408576698