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

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

Issue 143743005: [Mac, Win] New avatar bubble should be a fixed width. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
Index: chrome/browser/ui/cocoa/browser/profile_chooser_controller.mm
diff --git a/chrome/browser/ui/cocoa/browser/profile_chooser_controller.mm b/chrome/browser/ui/cocoa/browser/profile_chooser_controller.mm
index 8ae9adc564f0498d491653f4028a53491661cc13..a5f4e183011205eddea1e9e38843eb2644b54090 100644
--- a/chrome/browser/ui/cocoa/browser/profile_chooser_controller.mm
+++ b/chrome/browser/ui/cocoa/browser/profile_chooser_controller.mm
@@ -50,18 +50,19 @@
namespace {
-// Constants taken from the Windows/Views implementation at:
-// chrome/browser/ui/views/profile_chooser_view.cc
-const int kLargeImageSide = 64;
-const int kSmallImageSide = 32;
-
-const CGFloat kMinMenuWidth = 250;
+// Constants taken from ui/views/layout/layout_constants.h
const CGFloat kVerticalSpacing = 20.0;
const CGFloat kSmallVerticalSpacing = 10.0;
const CGFloat kHorizontalSpacing = 20.0;
const CGFloat kTitleFontSize = 15.0;
const CGFloat kTextFontSize = 12.0;
+// Constants taken from the Windows/Views implementation at:
+// chrome/browser/ui/views/profile_chooser_view.cc
+const int kLargeImageSide = 64;
+const int kSmallImageSide = 32;
+const CGFloat kFixedMenuWidth = 250;
Alexei Svitkine (slow) 2014/01/23 15:42:05 Can these be defined in some shared location?
+
// Minimum size for embedded sign in pages as defined in Gaia.
const CGFloat kMinGaiaViewWidth = 320;
const CGFloat kMinGaiaViewHeight = 440;
@@ -91,6 +92,17 @@ NSString* ElideEmail(const std::string& email, CGFloat width) {
return base::SysUTF16ToNSString(elidedEmail);
}
+NSString* ElideText(const base::string16& text,
+ CGFloat width,
+ ui::ResourceBundle::FontStyle fontStyle) {
Alexei Svitkine (slow) 2014/01/23 15:41:40 font_style, since this is a C++ function.
+ base::string16 elidedText = gfx::ElideText(
Alexei Svitkine (slow) 2014/01/23 15:41:40 elided_text
+ text,
+ ui::ResourceBundle::GetSharedInstance().GetFontList(fontStyle),
+ width,
+ gfx::ELIDE_AT_END);
+ return base::SysUTF16ToNSString(elidedText);
+}
+
} // namespace
// Class that listens to changes to the OAuth2Tokens for the active profile, or
@@ -328,14 +340,11 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
if (!currentProfileView) // Guest windows don't have an active profile.
currentProfileView = [self createGuestProfileView];
- CGFloat contentsWidth =
- std::max(kMinMenuWidth, NSWidth([currentProfileView frame]));
- CGFloat contentsWidthWithSpacing = contentsWidth + 2 * kHorizontalSpacing;
-
// |yOffset| is the next position at which to draw in |contentView|
// coordinates.
CGFloat yOffset = kVerticalSpacing;
- NSRect viewRect = NSMakeRect(kHorizontalSpacing, yOffset, contentsWidth, 0);
+ NSRect viewRect = NSMakeRect(kHorizontalSpacing, yOffset,
+ kFixedMenuWidth - 2 * kHorizontalSpacing, 0);
// Guest / Add Person / View All Persons buttons.
NSView* optionsView = [self createOptionsViewWithRect:viewRect];
@@ -343,7 +352,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
yOffset = NSMaxY([optionsView frame]) + kVerticalSpacing;
NSBox* separator = [self separatorWithFrame:NSMakeRect(
- 0, yOffset, contentsWidthWithSpacing, 0)];
+ 0, yOffset, kFixedMenuWidth, 0)];
[contentView addSubview:separator];
yOffset = NSMaxY([separator frame]) + kVerticalSpacing;
@@ -370,7 +379,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
yOffset = NSMaxY([currentProfileAccountsView frame]) + kVerticalSpacing;
NSBox* accountsSeparator = [self separatorWithFrame:NSMakeRect(
- 0, yOffset, contentsWidthWithSpacing, 0)];
+ 0, yOffset, kFixedMenuWidth, 0)];
[contentView addSubview:accountsSeparator];
yOffset = NSMaxY([accountsSeparator frame]) + kVerticalSpacing;
}
@@ -383,7 +392,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
yOffset = NSMaxY([currentProfileView frame]) + kVerticalSpacing;
}
- SetWindowSize([self window], NSMakeSize(contentsWidthWithSpacing, yOffset));
+ SetWindowSize([self window], NSMakeSize(kFixedMenuWidth, yOffset));
}
- (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item {
@@ -409,10 +418,19 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
maxXLinksContainer = NSMaxX([linksContainer frame]);
}
- // Profile name.
+ // Since the bubble is fixed width, we need to calculate the width available
+ // for the profile name, as longer names will have to be elided.
+ CGFloat availableTextWidth =
+ kFixedMenuWidth - // Entire width of the bubble.
Alexei Svitkine (slow) 2014/01/23 15:41:40 Indent 2 more.
+ 2 * kHorizontalSpacing - // Bubble insets.
+ kLargeImageSide - // Width of the first column.
+ kHorizontalSpacing; // Spacing between the two columns.
+
base::scoped_nsobject<NSTextField> profileName([[NSTextField alloc]
initWithFrame:NSZeroRect]);
- [profileName setStringValue:base::SysUTF16ToNSString(item.name)];
+ [profileName setStringValue:ElideText(item.name,
+ availableTextWidth,
+ ui::ResourceBundle::MediumFont)];
[profileName setFont:[NSFont labelFontOfSize:kTitleFontSize]];
[profileName setEditable:NO];
[profileName setDrawsBackground:NO];
@@ -496,8 +514,17 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
base::scoped_nsobject<NSButton> profileButton([[NSButton alloc]
initWithFrame:NSZeroRect]);
+ // Since the bubble is fixed width, we need to calculate the width available
+ // for the profile name, as longer names will have to be elided.
+ CGFloat availableTextWidth =
+ kFixedMenuWidth - // Entire width of the bubble.
Alexei Svitkine (slow) 2014/01/23 15:41:40 Indent 2 more.
+ 2 * kHorizontalSpacing - // Bubble insets.
+ kSmallImageSide; // Width of the button image.
+
// TODO(noms): Increase the spacing between the icon and the text to 10px;
- [profileButton setTitle:base::SysUTF16ToNSString(item.name)];
+ [profileButton setTitle:ElideText(item.name,
+ availableTextWidth,
+ ui::ResourceBundle::MediumFont)];
[profileButton setImage:CreateProfileImage(
item.icon, kSmallImageSide).ToNSImage()];
[profileButton setImagePosition:NSImageLeft];
@@ -554,12 +581,18 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
DCHECK(item.signed_in);
base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]);
-
NSRect viewRect = NSMakeRect(0, 0, rect.size.width, kBlueButtonHeight);
+
+ // Elide the button text so that the contents fit inside the bubble.
+ NSString* elidedButtonText = ElideText(
+ l10n_util::GetStringFUTF16(IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON,
+ item.name),
+ rect.size.width,
+ ui::ResourceBundle::BaseFont);
+
base::scoped_nsobject<NSButton> addAccountsButton([[BlueLabelButton alloc]
initWithFrame:viewRect]);
- [addAccountsButton setTitle:l10n_util::GetNSStringFWithFixup(
- IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, item.name)];
+ [addAccountsButton setTitle:elidedButtonText];
[addAccountsButton setTarget:self];
[addAccountsButton setAction:@selector(addAccount:)];
[container addSubview:addAccountsButton];
« no previous file with comments | « no previous file | chrome/browser/ui/views/profile_chooser_view.cc » ('j') | chrome/browser/ui/views/profile_chooser_view.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698