Chromium Code Reviews| Index: chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm |
| diff --git a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm |
| index cbdbc703cd1c1592f58d667de3fac489f5371169..258cd881102c3015f3bbf961f154b30fecd549af 100644 |
| --- a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm |
| +++ b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm |
| @@ -3,6 +3,7 @@ |
| // found in the LICENSE file. |
| #import <Cocoa/Cocoa.h> |
| +#import <Carbon/Carbon.h> // kVK_Return |
| #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" |
| @@ -795,6 +796,37 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| @end |
| +// Wrapper for a BackgroundColorHoverButton so that the button can be activated |
| +// on enter, to match the behaviour on Windows. |
| +@interface BackgroundColorHoverButtonContainer : NSView { |
|
groby-ooo-7-16
2015/02/02 21:57:33
Why not just subclass BackgroundColorHoverButton,
noms (inactive)
2015/02/02 23:01:05
Ah, duh. I misunderstood my old CL when I tried to
|
| +@private |
| + NSButton* button_; |
| +} |
| + |
| +- (id)initWithFrame:(NSRect)frame |
| + button:(NSButton*)button; |
| +@end |
| + |
| +@implementation BackgroundColorHoverButtonContainer |
| +- (id)initWithFrame:(NSRect)frame |
| + button:(NSButton*)button { |
| + if ((self = [super initWithFrame:frame])) { |
| + button_ = button; |
| + [self addSubview:button_]; |
| + } |
| + return self; |
| +} |
| + |
| +-(void)keyDown:(NSEvent*)event { |
| + // On enter, activate the wrapped button. |
|
groby-ooo-7-16
2015/02/02 21:57:33
Do we care about the state of modifier keys? Menus
noms (inactive)
2015/02/02 23:01:05
I don't think we do, nope.
|
| + if ([event keyCode] == kVK_Return) |
| + [button_ performClick:self]; |
| + else |
| + [super keyDown:event]; |
| +} |
| + |
| +@end |
| + |
| // A custom view with the given background color. |
| @interface BackgroundColorView : NSView { |
| @private |
| @@ -887,7 +919,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| // Creates an item for the profile |itemIndex| that is used in the fast profile |
| // switcher in the middle of the bubble. |
| -- (NSButton*)createOtherProfileView:(int)itemIndex; |
| +- (NSView*)createOtherProfileView:(int)itemIndex; |
| // Creates the "Not you" and Lock option buttons. |
| - (NSView*)createOptionsViewWithRect:(NSRect)rect |
| @@ -911,10 +943,10 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| // Creates a button with |text|, an icon given by |imageResourceId| and with |
| // |action|. |
| -- (NSButton*)hoverButtonWithRect:(NSRect)rect |
| - text:(NSString*)text |
| - imageResourceId:(int)imageResourceId |
| - action:(SEL)action; |
| +- (NSView*)hoverButtonWithRect:(NSRect)rect |
| + text:(NSString*)text |
| + imageResourceId:(int)imageResourceId |
| + action:(SEL)action; |
| // Creates a generic link button with |title| and an |action| positioned at |
| // |frameOrigin|. |
| @@ -1760,14 +1792,14 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| return [self createCurrentProfileView:guestItem]; |
| } |
| -- (NSButton*)createOtherProfileView:(int)itemIndex { |
| +- (NSView*)createOtherProfileView:(int)itemIndex { |
| const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex); |
| NSRect rect = NSMakeRect( |
| 0, 0, kFixedMenuWidth, kBlueButtonHeight + kSmallVerticalSpacing); |
| base::scoped_nsobject<BackgroundColorHoverButton> profileButton( |
| [[BackgroundColorHoverButton alloc] |
| - initWithFrame:rect |
| + initWithFrame:NSMakeRect(0, 0, rect.size.width, rect.size.height) |
| imageTitleSpacing:kImageTitleSpacing |
| backgroundColor:GetDialogBackgroundColor()]); |
| [profileButton setTitle:base::SysUTF16ToNSString(item.name)]; |
| @@ -1780,7 +1812,11 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| [profileButton setTarget:self]; |
| [profileButton setAction:@selector(switchToProfile:)]; |
| - return profileButton.autorelease(); |
| + base::scoped_nsobject<BackgroundColorHoverButtonContainer> container( |
| + [[BackgroundColorHoverButtonContainer alloc] |
| + initWithFrame:rect |
| + button:profileButton]); |
| + return container.autorelease(); |
| } |
| - (NSView*)createOptionsViewWithRect:(NSRect)rect |
| @@ -1791,7 +1827,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); |
| if (displayLock) { |
| - NSButton* lockButton = |
| + NSView* lockButton = |
| [self hoverButtonWithRect:viewRect |
| text:l10n_util::GetNSString( |
| IDS_PROFILES_PROFILE_SIGNOUT_BUTTON) |
| @@ -1806,7 +1842,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| } |
| if ([self shouldShowGoIncognito]) { |
| - NSButton* goIncognitoButton = |
| + NSView* goIncognitoButton = |
| [self hoverButtonWithRect:viewRect |
| text:l10n_util::GetNSString( |
| IDS_PROFILES_GO_INCOGNITO_BUTTON) |
| @@ -1823,7 +1859,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| NSString* text = isGuestSession_ ? |
| l10n_util::GetNSString(IDS_PROFILES_EXIT_GUEST) : |
| l10n_util::GetNSString(IDS_PROFILES_SWITCH_USERS_BUTTON); |
| - NSButton* switchUsersButton = |
| + NSView* switchUsersButton = |
| [self hoverButtonWithRect:viewRect |
| text:text |
| imageResourceId:IDR_ICON_PROFILES_MENU_AVATAR |
| @@ -2078,7 +2114,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); |
| // Adds "Disconnect your Google Account" button at the bottom. |
| - NSButton* disconnectButton = |
| + NSView* disconnectButton = |
| [self hoverButtonWithRect:viewRect |
| text:l10n_util::GetNSString( |
| IDS_PROFILES_DISCONNECT_BUTTON) |
| @@ -2094,7 +2130,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| // Adds "Add person" button. |
| viewRect.origin.y = yOffset; |
| - NSButton* addPersonButton = |
| + NSView* addPersonButton = |
| [self hoverButtonWithRect:viewRect |
| text:l10n_util::GetNSString( |
| IDS_PROFILES_ADD_PERSON_BUTTON) |
| @@ -2146,13 +2182,13 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| return YES; |
| } |
| -- (NSButton*)hoverButtonWithRect:(NSRect)rect |
| - text:(NSString*)text |
| - imageResourceId:(int)imageResourceId |
| - action:(SEL)action { |
| +- (NSView*)hoverButtonWithRect:(NSRect)rect |
| + text:(NSString*)text |
| + imageResourceId:(int)imageResourceId |
| + action:(SEL)action { |
| base::scoped_nsobject<BackgroundColorHoverButton> button( |
| [[BackgroundColorHoverButton alloc] |
| - initWithFrame:rect |
| + initWithFrame:NSMakeRect(0, 0, rect.size.width, rect.size.height) |
| imageTitleSpacing:kImageTitleSpacing |
| backgroundColor:GetDialogBackgroundColor()]); |
| @@ -2168,7 +2204,12 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| [button setTarget:self]; |
| [button setAction:action]; |
| - return button.autorelease(); |
| + base::scoped_nsobject<BackgroundColorHoverButtonContainer> container( |
| + [[BackgroundColorHoverButtonContainer alloc] |
| + initWithFrame:rect |
| + button:button]); |
| + |
| + return container.autorelease(); |
| } |
| - (NSButton*)linkButtonWithTitle:(NSString*)title |