Chromium Code Reviews| 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..588100d04be802d49a1adccf6273ad0cea4a99e9 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); |
|
vabr (Chromium)
2016/05/09 11:16:17
Is this settable so that it can be a no-op before
vasilii
2016/05/09 11:45:54
It's done to avoid back pointers to the bridge or
|
| +@end |
| + |
| +@implementation AutoSigninPromptView |
| +@synthesize escHandler = _escHandler; |
| + |
| +-(void)dealloc { |
| + [_escHandler release]; |
| + [super dealloc]; |
| +} |
| + |
| +- (BOOL)performKeyEquivalent:(NSEvent*)theEvent { |
| + if (_escHandler(theEvent)) |
| + return TRUE; |
|
vabr (Chromium)
2016/05/09 11:16:17
TRUE or YES?
vasilii
2016/05/09 11:45:54
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 TRUE; |
|
vabr (Chromium)
2016/05/09 11:16:17
ditto here and on line 189: YES/NO instead of TRUE
vasilii
2016/05/09 11:45:54
Done.
|
| + } |
| + return FALSE; |
| +} |
| + |
| @end |
| @implementation AutoSigninPromptViewController(Testing) |