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

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

Issue 287103004: New avatar menu: For supervised users, show "(Supervised)" in the avatar button (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add Mac implementation Created 6 years, 7 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
Index: chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm
diff --git a/chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm b/chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm
index 93810f3afe2b1c0b23f10836a811a60c807f3217..efec9e26d994f4de61c49ccfdcf0a7787c549291 100644
--- a/chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm
+++ b/chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm
@@ -27,7 +27,7 @@ const CGFloat kButtonPadding = 12;
const CGFloat kButtonDefaultPadding = 5;
const CGFloat kButtonHeight = 27;
const CGFloat kButtonTitleImageSpacing = 10;
-const CGFloat kMaxButtonWidth = 120;
+const CGFloat kMaxButtonContentWidth = 100;
const ui::NinePartImageIds kNormalBorderImageIds =
IMAGE_GRID(IDR_AVATAR_MAC_BUTTON_NORMAL);
@@ -109,6 +109,7 @@ NSImage* GetImageFromResourceID(int resourceId) {
@end
@interface AvatarButtonController (Private)
+- (base::string16)getElidedAvatarName;
- (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent;
- (void)dealloc;
- (void)themeDidChangeNotification:(NSNotification*)aNotification;
@@ -177,6 +178,16 @@ NSImage* GetImageFromResourceID(int resourceId) {
}
}
+- (base::string16)getElidedAvatarName {
+ base::string16 avatarName =
+ profiles::GetAvatarNameForProfile(browser_->profile());
+ int maxTextWidth = kMaxButtonContentWidth - [[button_ image] size].width;
msw 2014/05/27 17:16:41 nit: it seems like you're decreasing the width twi
Marc Treib 2014/05/28 11:04:05 Yes: The old 120 pixels were the total width of th
+ return gfx::ElideText(avatarName,
msw 2014/05/27 17:16:41 nit: will this fade/truncate and [not] add ellipsi
Marc Treib 2014/05/28 11:04:05 This adds an ellipsis. The button looks identical
+ gfx::FontList(gfx::Font([button_ font])),
+ maxTextWidth,
+ gfx::ELIDE_AT_END);
+}
+
- (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent {
// The button text has a black foreground and a white drop shadow for regular
// windows, and a light text with a dark drop shadow for guest windows
@@ -198,14 +209,21 @@ NSImage* GetImageFromResourceID(int resourceId) {
[shadow setShadowColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.4]];
}
+ base::string16 profileName = [self getElidedAvatarName];
+ NSString* buttonTitle = nil;
+ if (browser_->profile()->IsManaged()) {
+ // Add the "supervised" label after eliding the profile name, so the label
+ // will not get elided, but will instead enlarge the button.
+ buttonTitle = l10n_util::GetNSStringF(IDS_MANAGED_USER_NEW_AVATAR_LABEL,
+ profileName);
+ } else {
+ buttonTitle = base::SysUTF16ToNSString(profileName);
+ }
+
base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle(
[[NSMutableParagraphStyle alloc] init]);
- [paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
[paragraphStyle setAlignment:NSLeftTextAlignment];
- NSString* buttonTitle = base::SysUTF16ToNSString(
- profiles::GetAvatarNameForProfile(browser_->profile()));
-
base::scoped_nsobject<NSAttributedString> attributedTitle(
[[NSAttributedString alloc]
initWithString:buttonTitle
@@ -215,10 +233,6 @@ NSImage* GetImageFromResourceID(int resourceId) {
[button_ setAttributedTitle:attributedTitle];
[button_ sizeToFit];
- // Truncate the title if needed.
- if (NSWidth([button_ bounds]) > kMaxButtonWidth)
- [button_ setFrameSize:NSMakeSize(kMaxButtonWidth, kButtonHeight)];
-
if (layoutParent) {
// Because the width of the button might have changed, the parent browser
// frame needs to recalculate the button bounds and redraw it.

Powered by Google App Engine
This is Rietveld 408576698