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 c1b84666aebe8bc76e466633013286a66a890d66..6b21c1a36e5b4313898fff8619b0d27047b0f4bf 100644 |
| --- a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm |
| +++ b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm |
| @@ -332,6 +332,88 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| DISALLOW_COPY_AND_ASSIGN(ActiveProfileObserverBridge); |
| }; |
| +// Custom button cell that adds a left padding to a button. |
|
groby-ooo-7-16
2014/06/10 19:53:23
If you want to add padding, -drawInteriorWithFrame
noms (inactive)
2014/06/11 15:09:00
Hmm, I might have done it wrong, but -drawInterior
groby-ooo-7-16
2014/06/11 18:11:21
I'm not sure I follow - how is the button indented
noms (inactive)
2014/06/11 19:29:57
Yeah, my bad. This entire CL is "really annoying a
groby-ooo-7-16
2014/06/12 01:48:12
No, you're not. I misunderstood what you want padd
noms (inactive)
2014/06/16 19:17:10
Ok. The -drawInterior was almost perfect, but beca
|
| +@interface LeftMarginButtonCell : NSButtonCell { |
| + @protected |
| + // Padding added to the left margin of the button. |
| + int leftMarginSpacing_; |
| +} |
| + |
| +- (id)initWithLeftMarginSpacing:(int)leftMarginSpacing; |
| +@end |
| + |
| +@implementation LeftMarginButtonCell |
| +- (id)initWithLeftMarginSpacing:(int)leftMarginSpacing { |
| + if ((self = [super init])) { |
| + leftMarginSpacing_ = leftMarginSpacing; |
| + } |
| + return self; |
| +} |
| + |
| +- (NSRect)drawTitle:(NSAttributedString*)title |
| + withFrame:(NSRect)frame |
| + inView:(NSView*)controlView { |
| + // The title frame origin isn't aware of the left margin spacing added |
| + // in -drawImage, so it must be added when drawing the title as well. |
| + frame.origin.x += leftMarginSpacing_; |
| + frame.size.width -= leftMarginSpacing_; |
| + return [super drawTitle:title withFrame:frame inView:controlView]; |
| +} |
| + |
| +- (NSSize)cellSize { |
| + NSSize buttonSize = [super cellSize]; |
| + buttonSize.width += leftMarginSpacing_; |
| + return buttonSize; |
| +} |
| + |
| +@end |
| + |
| +// Custom button cell that adds a left padding before the button image, and |
| +// a custom spacing between the button image and title. |
| +@interface CustomPaddingImageButtonCell : LeftMarginButtonCell { |
|
groby-ooo-7-16
2014/06/10 19:53:23
You might want to _just_ keep CustomPaddingImageBu
noms (inactive)
2014/06/11 15:09:00
Hmm, it's a little worse than that (I'm noticing t
groby-ooo-7-16
2014/06/11 18:11:22
You might want to. Also, with the image forced to
noms (inactive)
2014/06/11 19:29:57
Does the sketch above explain the padding? I was t
groby-ooo-7-16
2014/06/12 01:48:11
If you use the drawInteriorWithFrame approach, you
|
| + @private |
| + // Spacing between the cell image and title. |
| + int imageTitleSpacing_; |
| +} |
| + |
| +- (id)initWithLeftMarginSpacing:(int)leftMarginSpacing |
| + imageTitleSpacing:(int)imageTitleSpacing; |
| +@end |
| + |
| +@implementation CustomPaddingImageButtonCell |
| +- (id)initWithLeftMarginSpacing:(int)leftMarginSpacing |
| + imageTitleSpacing:(int)imageTitleSpacing { |
| + if ((self = [super initWithLeftMarginSpacing:leftMarginSpacing])) { |
| + imageTitleSpacing_ = imageTitleSpacing; |
| + } |
| + return self; |
| +} |
| + |
| +- (NSRect)drawTitle:(NSAttributedString*)title |
| + withFrame:(NSRect)frame |
| + inView:(NSView*)controlView { |
| + // The title frame origin isn't aware of the left margin spacing added |
| + // in -drawImage, so it must be added when drawing the title as well. |
| + frame.origin.x += imageTitleSpacing_; |
| + frame.size.width -= imageTitleSpacing_; |
| + return [super drawTitle:title withFrame:frame inView:controlView]; |
| +} |
| + |
| +- (void)drawImage:(NSImage*)image |
| + withFrame:(NSRect)frame |
| + inView:(NSView*)controlView { |
| + frame.origin.x = leftMarginSpacing_; |
| + [super drawImage:image withFrame:frame inView:controlView]; |
| +} |
| + |
| +- (NSSize)cellSize { |
| + NSSize buttonSize = [super cellSize]; |
| + buttonSize.width += imageTitleSpacing_; |
| + return buttonSize; |
| +} |
| + |
| +@end |
| + |
| // A custom button that has a transparent backround. |
| @interface TransparentBackgroundButton : NSButton |
| @end |
| @@ -347,7 +429,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| } |
| - (void)drawRect:(NSRect)dirtyRect { |
| - NSColor* backgroundColor = [NSColor colorWithCalibratedWhite:1 alpha:0.4f]; |
| + NSColor* backgroundColor = [NSColor colorWithCalibratedWhite:1 alpha:0.6f]; |
| [backgroundColor setFill]; |
| NSRectFillUsingOperation(dirtyRect, NSCompositeSourceAtop); |
| [super drawRect:dirtyRect]; |
| @@ -487,12 +569,6 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| profile_ = profile; |
| controller_ = controller; |
| - [self setBordered:NO]; |
| - [self setFont:[NSFont labelFontOfSize:kTitleFontSize]]; |
| - [self setAlignment:NSCenterTextAlignment]; |
| - [[self cell] setLineBreakMode:NSLineBreakByTruncatingTail]; |
| - [self setTitle:profileName]; |
| - |
| if (editingAllowed) { |
| // Show an "edit" pencil icon when hovering over. In the default state, |
| // we need to create an empty placeholder of the correct size, so that |
| @@ -500,6 +576,14 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| NSImage* hoverImage = rb->GetNativeImageNamed( |
| IDR_ICON_PROFILES_EDIT_HOVER).AsNSImage(); |
| + |
| + // In order to center the button title, we need to add a left padding of |
| + // the same width as the pencil icon. |
| + base::scoped_nsobject<LeftMarginButtonCell> cell( |
| + [[LeftMarginButtonCell alloc] |
| + initWithLeftMarginSpacing:[hoverImage size].width]); |
| + [self setCell:cell.get()]; |
| + |
| NSImage* placeholder = [[NSImage alloc] initWithSize:[hoverImage size]]; |
| [self setDefaultImage:placeholder]; |
| [self setHoverImage:hoverImage]; |
| @@ -530,6 +614,12 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| // Hide the textfield until the user clicks on the button. |
| [profileNameTextField_ setHidden:YES]; |
| } |
| + |
| + [self setBordered:NO]; |
| + [self setFont:[NSFont labelFontOfSize:kTitleFontSize]]; |
| + [self setAlignment:NSCenterTextAlignment]; |
| + [[self cell] setLineBreakMode:NSLineBreakByTruncatingTail]; |
| + [self setTitle:profileName]; |
| } |
| return self; |
| } |
| @@ -545,62 +635,16 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME]; |
| [self setTitle:text]; |
| } |
| + |
| + [[self window] makeFirstResponder:nil]; |
|
groby-ooo-7-16
2014/06/10 19:53:23
Are you sure you want the window to be first respo
noms (inactive)
2014/06/11 15:09:00
Giant incoming comment:
If I do what you suggeste
noms (inactive)
2014/06/11 15:09:00
Setting the next UI element to be the first respon
groby-ooo-7-16
2014/06/11 18:11:21
You know that you can actually specify the key vie
groby-ooo-7-16
2014/06/11 18:11:21
That's odd. Pressing the button should make the te
noms (inactive)
2014/06/11 19:29:57
I completely agree it should (which is why the cod
groby-ooo-7-16
2014/06/12 01:48:11
So there's something different if you don't change
noms (inactive)
2014/06/16 19:17:10
DONE! \o/
|
| [profileNameTextField_ setHidden:YES]; |
| - [profileNameTextField_ resignFirstResponder]; |
| + [profileNameTextField_ setEnabled:NO]; |
|
groby-ooo-7-16
2014/06/10 19:53:23
You shouldn't need to disable if it's hidden.
|
| } |
| - (void)showEditableView:(id)sender { |
| [profileNameTextField_ setHidden:NO]; |
| - [profileNameTextField_ becomeFirstResponder]; |
| -} |
| - |
| -@end |
| - |
| -// Custom button cell that adds a left padding before the button image, and |
| -// a custom spacing between the button image and title. |
| -@interface CustomPaddingImageButtonCell : NSButtonCell { |
| - @private |
| - // Padding between the left margin of the button and the cell image. |
| - int leftMarginSpacing_; |
| - // Spacing between the cell image and title. |
| - int imageTitleSpacing_; |
| -} |
| - |
| -- (id)initWithLeftMarginSpacing:(int)leftMarginSpacing |
| - imageTitleSpacing:(int)imageTitleSpacing; |
| -@end |
| - |
| -@implementation CustomPaddingImageButtonCell |
| -- (id)initWithLeftMarginSpacing:(int)leftMarginSpacing |
| - imageTitleSpacing:(int)imageTitleSpacing { |
| - if ((self = [super init])) { |
| - leftMarginSpacing_ = leftMarginSpacing; |
| - imageTitleSpacing_ = imageTitleSpacing; |
| - } |
| - return self; |
| -} |
| - |
| -- (NSRect)drawTitle:(NSAttributedString*)title |
| - withFrame:(NSRect)frame |
| - inView:(NSView*)controlView { |
| - // The title frame origin isn't aware of the left margin spacing added |
| - // in -drawImage, so it must be added when drawing the title as well. |
| - frame.origin.x += leftMarginSpacing_ + imageTitleSpacing_; |
| - frame.size.width -= (imageTitleSpacing_ + leftMarginSpacing_); |
| - return [super drawTitle:title withFrame:frame inView:controlView]; |
| -} |
| - |
| -- (void)drawImage:(NSImage*)image |
| - withFrame:(NSRect)frame |
| - inView:(NSView*)controlView { |
| - frame.origin.x = leftMarginSpacing_; |
| - [super drawImage:image withFrame:frame inView:controlView]; |
| -} |
| - |
| -- (NSSize)cellSize { |
| - NSSize buttonSize = [super cellSize]; |
| - buttonSize.width += leftMarginSpacing_ + imageTitleSpacing_; |
| - return buttonSize; |
| + [profileNameTextField_ setEnabled:YES]; |
| + [[self window] makeFirstResponder:profileNameTextField_]; |
| } |
| @end |
| @@ -985,8 +1029,9 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| currentProfileView = [self createGuestProfileView]; |
| // |yOffset| is the next position at which to draw in |container| |
| - // coordinates. |
| - CGFloat yOffset = 0; |
| + // coordinates. Add a pixel offset so that the bottom option buttons don't |
| + // overlap the bubble's rounded corners. |
| + CGFloat yOffset = 1; |
| // Option buttons. Only available with the new profile management flag. |
| if (switches::IsNewProfileManagement()) { |
| @@ -996,7 +1041,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| [container addSubview:optionsView]; |
| rect.origin.y = NSMaxY([optionsView frame]); |
| - NSBox* separator = [self separatorWithFrame:rect]; |
| + NSBox* separator = [self horizontalSeparatorWithFrame:rect]; |
| [container addSubview:separator]; |
| yOffset = NSMaxY([separator frame]); |
| } |
| @@ -1010,8 +1055,8 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| [container addSubview:otherProfileView]; |
| yOffset = NSMaxY([otherProfileView frame]); |
| - NSBox* separator = |
| - [self separatorWithFrame:NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; |
| + NSBox* separator = [self horizontalSeparatorWithFrame:NSMakeRect( |
| + 0, yOffset, kFixedMenuWidth, 0)]; |
| [container addSubview:separator]; |
| yOffset = NSMaxY([separator frame]); |
| } |
| @@ -1021,7 +1066,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| [container addSubview:currentProfileAccountsView]; |
| yOffset = NSMaxY([currentProfileAccountsView frame]); |
| - NSBox* accountsSeparator = [self separatorWithFrame: |
| + NSBox* accountsSeparator = [self horizontalSeparatorWithFrame: |
| NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; |
| [container addSubview:accountsSeparator]; |
| yOffset = NSMaxY([accountsSeparator frame]); |
| @@ -1036,8 +1081,8 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| yOffset = NSMaxY([disclaimerContainer frame]); |
| yOffset += kSmallVerticalSpacing; |
| - NSBox* separator = |
| - [self separatorWithFrame:NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; |
| + NSBox* separator = [self horizontalSeparatorWithFrame:NSMakeRect( |
| + 0, yOffset, kFixedMenuWidth, 0)]; |
| [container addSubview:separator]; |
| yOffset = NSMaxY([separator frame]); |
| } |
| @@ -1422,7 +1467,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| - (NSView*)createOptionsViewWithRect:(NSRect)rect |
| enableLock:(BOOL)enableLock { |
| - int widthOfLockButton = enableLock? 2 * kHorizontalSpacing + 12 : 0; |
| + int widthOfLockButton = enableLock ? 2 * kHorizontalSpacing + 14 : 0; |
| NSRect viewRect = NSMakeRect(0, 0, |
| rect.size.width - widthOfLockButton, |
| kBlueButtonHeight + kVerticalSpacing); |
| @@ -1444,6 +1489,10 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| if (enableLock) { |
| viewRect.origin.x = NSMaxX([notYouButton frame]); |
| + NSBox* separator = [self verticalSeparatorWithFrame:viewRect]; |
| + [container addSubview:separator]; |
| + |
| + viewRect.origin.x = NSMaxX([separator frame]); |
| viewRect.size.width = widthOfLockButton; |
| NSButton* lockButton = |
| [self hoverButtonWithRect:viewRect |
| @@ -1551,7 +1600,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| yOffset = NSMaxY([webview frame]); |
| // Adds the title card. |
| - NSBox* separator = [self separatorWithFrame: |
| + NSBox* separator = [self horizontalSeparatorWithFrame: |
| NSMakeRect(0, yOffset, kFixedGaiaViewWidth, 0)]; |
| [container addSubview:separator]; |
| yOffset = NSMaxY([separator frame]) + kSmallVerticalSpacing; |
| @@ -1623,7 +1672,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| yOffset = NSMaxY([contentView frame]) + kVerticalSpacing; |
| // Adds the title card. |
| - NSBox* separator = [self separatorWithFrame: |
| + NSBox* separator = [self horizontalSeparatorWithFrame: |
| NSMakeRect(0, yOffset, kFixedAccountRemovalViewWidth, 0)]; |
| [container addSubview:separator]; |
| yOffset = NSMaxY([separator frame]) + kSmallVerticalSpacing; |
| @@ -1674,7 +1723,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| yOffset = NSMaxY([contentLabel frame]) + kVerticalSpacing; |
| // Adds the title card. |
| - NSBox* separator = [self separatorWithFrame: |
| + NSBox* separator = [self horizontalSeparatorWithFrame: |
| NSMakeRect(0, yOffset, kFixedEndPreviewViewWidth, 0)]; |
| [container addSubview:separator]; |
| yOffset = NSMaxY([separator frame]) + kSmallVerticalSpacing; |