Skip to content

Commit

Permalink
Add tooltips to profile name when truncated
Browse files Browse the repository at this point in the history
This adds tooltips to profile names in both the old and new profile
switcher when they are truncated on OSX.
This lines up with behaviour on Windows.

Also added myself to the AUTHORS file seeing this is my first contribution.

BUG=459572

Review URL: https://codereview.chromium.org/943453003

Cr-Commit-Position: refs/heads/master@{#318769}
  • Loading branch information
wesleylancel authored and Commit bot committed Mar 2, 2015
1 parent a656e72 commit 30f4cc5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ Vinay Anantharaman <vinaya@adobe.com>
Vipul Bhasin <vipul.bhasin@gmail.com>
Visa Putkinen <v.putkinen@partner.samsung.com>
Vivek Galatage <vivek.vg@samsung.com>
Wesley Lancel <wesleylancel@gmail.com>
Will Hirsch <chromium@willhirsch.co.uk>
William Xie <william.xie@intel.com>
Xiang Long <xiang.long@intel.com>
Expand Down
4 changes: 4 additions & 0 deletions base/mac/sdk_forward_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ enum {
- (NSString*)UUIDString;
@end

@interface NSControl (MountainLionSDK)
@property BOOL allowsExpansionToolTips;
@end

#endif // MAC_OS_X_VERSION_10_8


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h"

#include "base/mac/bundle_locations.h"
#include "base/mac/sdk_forward_declarations.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/avatar_menu.h"
Expand Down Expand Up @@ -159,6 +160,8 @@ - (AvatarMenuItemController*)initAvatarItem:(int)itemIndex
NSRect frame = [nameField frame];
frame.size.width = kMaxItemTextWidth;
[nameField setFrame:frame];
if ([nameField respondsToSelector:@selector(setAllowsExpansionToolTips:)])
[nameField setAllowsExpansionToolTips:YES];
}
*widthAdjust = std::max(*widthAdjust, delta.width);

Expand Down
17 changes: 17 additions & 0 deletions chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,13 @@ - (id)initWithFrame:(NSRect)frameRect
IDS_PROFILES_NEW_AVATAR_MENU_EDIT_NAME_ACCESSIBLE_NAME,
base::SysNSStringToUTF16(profileName))
forAttribute:NSAccessibilityTitleAttribute];

NSSize textSize = [profileName sizeWithAttributes:@{
NSFontAttributeName : [profileNameTextField_ font]
}];

if (textSize.width > frameRect.size.width - [hoverImage size].width * 2)
[self setToolTip:profileName];
}

[[self cell] accessibilitySetOverrideValue:NSAccessibilityButtonRole
Expand Down Expand Up @@ -1805,6 +1812,16 @@ - (NSButton*)createOtherProfileView:(int)itemIndex {
[profileButton setTarget:self];
[profileButton setAction:@selector(switchToProfile:)];

NSSize textSize = [[profileButton title] sizeWithAttributes:@{
NSFontAttributeName : [profileButton font]
}];

CGFloat availableWidth = rect.size.width - kSmallImageSide -
kImageTitleSpacing - kHorizontalSpacing;

if (std::ceil(textSize.width) > availableWidth)
[profileButton setToolTip:[profileButton title]];

return profileButton.autorelease();
}

Expand Down

0 comments on commit 30f4cc5

Please sign in to comment.