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

Unified Diff: chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm

Issue 2632293002: macOS: Adding tooltip in the profile chooser (Closed)
Patch Set: Mihai's comments Created 3 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 caac7e85b636c9820ddf40ac024d3837bbee4bf5..00878e59a3c4ffa7b88e59eb0b48afff7fcae03d 100644
--- a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm
+++ b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm
@@ -2138,14 +2138,20 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
// Profile name, left-aligned to the right of profile icon.
xOffset += kMdImageSide + kHorizontalSpacing;
CGFloat fontSize = kTextFontSize + 1.0;
- NSTextField* profileName =
- BuildLabel(base::SysUTF16ToNSString(profileNameString), NSZeroPoint, nil);
+ NSString* profileNameNSString = base::SysUTF16ToNSString(profileNameString);
+ NSTextField* profileName = BuildLabel(profileNameNSString, NSZeroPoint, nil);
[[profileName cell] setLineBreakMode:NSLineBreakByTruncatingTail];
[profileName setFont:[NSFont labelFontOfSize:fontSize]];
[profileName sizeToFit];
const int profileNameYOffset =
cardYOffset +
std::floor((kMdImageSide - NSHeight([profileName frame])) / 2);
+ if (profileName.frame.size.width > availableTextWidth) {
+ // Add the tooltip only if the profile name is truncated. This method to
+ // test if text field is truncated is not ideal (spaces between characters
+ // may be reduced to avoid truncation).
+ profileName.toolTip = profileNameNSString;
+ }
[profileName
setFrame:NSMakeRect(xOffset, profileNameYOffset, availableTextWidth,
NSHeight([profileName frame]))];
@@ -2158,10 +2164,16 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
cardYOffset += kMdImageSide / 2 - [profileName frame].size.height;
[profileName setFrameOrigin:NSMakePoint(xOffset, cardYOffset)];
+ NSString* elidedEmail =
+ ElideEmail(base::UTF16ToUTF8(item.username), availableTextWidth);
NSTextField* username = BuildLabel(
- ElideEmail(base::UTF16ToUTF8(item.username), availableTextWidth),
- NSZeroPoint, skia::SkColorToSRGBNSColor(SK_ColorGRAY));
+ elidedEmail, NSZeroPoint, skia::SkColorToSRGBNSColor(SK_ColorGRAY));
[username setFrameOrigin:NSMakePoint(xOffset, NSMaxY([profileName frame]))];
+ NSString* usernameNSString = base::SysUTF16ToNSString(item.username);
+ if (![elidedEmail isEqualToString:usernameNSString]) {
+ // Add the tooltip only if the user name is truncated.
+ username.toolTip = usernameNSString;
+ }
[profileCard addSubview:username];
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698