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

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

Issue 465313003: Update the new avatar menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments fixed Created 6 years, 4 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/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 b94e3f46d6005b34f086516cd492b84fc4068ae1..6abe49f19776e85e69b5ef093279f64bae3eb383 100644
--- a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm
+++ b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm
@@ -87,7 +87,7 @@ const int kBlueButtonHeight = 30;
// Fixed size for embedded sign in pages as defined in Gaia.
const CGFloat kFixedGaiaViewWidth = 360;
-const CGFloat kFixedGaiaViewHeight = 400;
+const CGFloat kFixedGaiaViewHeight = 440;
// Fixed size for the account removal view.
const CGFloat kFixedAccountRemovalViewWidth = 280;
@@ -118,6 +118,11 @@ NSString* ElideEmail(const std::string& email, CGFloat width) {
return base::SysUTF16ToNSString(elidedEmail);
}
+NSString* ElideMessage(const base::string16& message, CGFloat width) {
+ return base::SysUTF16ToNSString(
+ gfx::ElideText(message, gfx::FontList(), width, gfx::ELIDE_TAIL));
+}
+
// Builds a label with the given |title| anchored at |frame_origin|. Sets the
// text color to |text_color| if not null.
NSTextField* BuildLabel(NSString* title,
@@ -190,7 +195,7 @@ NSColor* GetDialogBackgroundColor() {
// Builds a title card with one back button right aligned and one label center
// aligned.
NSView* BuildTitleCard(NSRect frame_rect,
- NSString* message,
+ const base::string16& message,
id back_button_target,
SEL back_button_action) {
base::scoped_nsobject<NSView> container(
@@ -208,7 +213,11 @@ NSView* BuildTitleCard(NSRect frame_rect,
[button setFrameSize:NSMakeSize(kProfileButtonHeight, kProfileButtonHeight)];
[button setFrameOrigin:NSMakePoint(kHorizontalSpacing, 0)];
- NSTextField* title_label = BuildLabel(message, NSZeroPoint, nil);
+ CGFloat max_label_width = frame_rect.size.width -
+ (kHorizontalSpacing * 2 + kProfileButtonHeight) * 2;
+ NSTextField* title_label = BuildLabel(
+ ElideMessage(message, max_label_width),
+ NSZeroPoint, nil);
[title_label setAlignment:NSCenterTextAlignment];
[title_label setFont:[NSFont labelFontOfSize:kTitleFontSize]];
[title_label sizeToFit];
@@ -711,15 +720,17 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
- (NSView*)buildProfileChooserView;
// Builds a tutorial card with a title label using |titleMessage|, a content
-// label using |contentMessage|, and a bottom row with a right-aligned link
-// using |linkMessage|, and a left aligned button using |buttonMessage|.
-// On click, the link would execute |linkAction|, and the button would execute
-// |buttonAction|. It sets |tutorialMode_| to the given |mode|.
+// label using |contentMessage|, a link using |linkMessage|, and a button using
+// |buttonMessage|. If |stackButton| is YES, places the button above the link.
+// Otherwise places both on the same row with the link left aligned and button
+// right aligned. On click, the link would execute |linkAction|, and the button
+// would execute |buttonAction|. It sets |tutorialMode_| to the given |mode|.
- (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode
titleMessage:(NSString*)titleMessage
contentMessage:(NSString*)contentMessage
linkMessage:(NSString*)linkMessage
buttonMessage:(NSString*)buttonMessage
+ stackButton:(BOOL)stackButton
linkAction:(SEL)linkAction
buttonAction:(SEL)buttonAction;
@@ -1158,6 +1169,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
contentMessage:contentMessage
linkMessage:linkMessage
buttonMessage:buttonMessage
+ stackButton:NO
linkAction:@selector(configureSyncSettings:)
buttonAction:@selector(syncSettingsConfirmed:)];
}
@@ -1190,8 +1202,9 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE);
NSString* contentMessage = l10n_util::GetNSString(
IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT);
- NSString* linkMessage = l10n_util::GetNSStringF(
- IDS_PROFILES_NOT_YOU, avatarItem.name);
+ NSString* linkMessage = ElideMessage(
+ l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU, avatarItem.name),
+ kFixedMenuWidth - 2 * kHorizontalSpacing);
NSString* buttonMessage = l10n_util::GetNSString(
IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON);
return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_WELCOME_UPGRADE
@@ -1199,6 +1212,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
contentMessage:contentMessage
linkMessage:linkMessage
buttonMessage:buttonMessage
+ stackButton:YES
linkAction:@selector(showSwitchUserView:)
buttonAction:@selector(seeWhatsNew:)];
}
@@ -1208,6 +1222,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
contentMessage:(NSString*)contentMessage
linkMessage:(NSString*)linkMessage
buttonMessage:(NSString*)buttonMessage
+ stackButton:(BOOL)stackButton
linkAction:(SEL)linkAction
buttonAction:(SEL)buttonAction {
tutorialMode_ = mode;
@@ -1218,7 +1233,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
initWithFrame:NSMakeRect(0, 0, kFixedMenuWidth, 0)
withColor:tutorialBackgroundColor]);
CGFloat availableWidth = kFixedMenuWidth - 2 * kHorizontalSpacing;
- CGFloat yOffset = kSmallVerticalSpacing;
+ CGFloat yOffset = kVerticalSpacing;
// Adds links and buttons at the bottom.
base::scoped_nsobject<NSButton> tutorialOkButton([[HoverButton alloc]
@@ -1227,27 +1242,38 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
[tutorialOkButton setBezelStyle:NSRoundedBezelStyle];
[tutorialOkButton setTarget:self];
[tutorialOkButton setAction:buttonAction];
- [tutorialOkButton sizeToFit];
- NSSize buttonSize = [tutorialOkButton frame].size;
- const CGFloat kTopBottomTextPadding = 6;
- const CGFloat kLeftRightTextPadding = 15;
- buttonSize.width += 2 * kLeftRightTextPadding;
- buttonSize.height += 2 * kTopBottomTextPadding;
- [tutorialOkButton setFrameSize:buttonSize];
[tutorialOkButton setAlignment:NSCenterTextAlignment];
- [tutorialOkButton setFrameOrigin:NSMakePoint(
- kFixedMenuWidth - NSWidth([tutorialOkButton frame]) - kHorizontalSpacing,
- yOffset)];
- [container addSubview:tutorialOkButton];
+ [tutorialOkButton sizeToFit];
NSButton* learnMoreLink =
[self linkButtonWithTitle:linkMessage
frameOrigin:NSZeroPoint
action:linkAction];
[[learnMoreLink cell] setTextColor:[NSColor whiteColor]];
- CGFloat linkYOffset = yOffset + (NSHeight([tutorialOkButton frame]) -
- NSHeight([learnMoreLink frame])) / 2;
- [learnMoreLink setFrameOrigin:NSMakePoint(kHorizontalSpacing, linkYOffset)];
+
+ if (stackButton) {
+ [learnMoreLink setFrameOrigin:NSMakePoint(
+ (kFixedMenuWidth - NSWidth([learnMoreLink frame])) / 2, yOffset)];
+ [tutorialOkButton setFrameSize:NSMakeSize(
+ availableWidth, NSHeight([tutorialOkButton frame]))];
+ [tutorialOkButton setFrameOrigin:NSMakePoint(
+ kHorizontalSpacing, yOffset + NSHeight([learnMoreLink frame]))];
+ } else {
+ NSSize buttonSize = [tutorialOkButton frame].size;
+ const CGFloat kTopBottomTextPadding = 6;
+ const CGFloat kLeftRightTextPadding = 15;
+ buttonSize.width += 2 * kLeftRightTextPadding;
+ buttonSize.height += 2 * kTopBottomTextPadding;
+ [tutorialOkButton setFrameSize:buttonSize];
+ CGFloat buttonXOffset = kFixedMenuWidth -
+ NSWidth([tutorialOkButton frame]) - kHorizontalSpacing;
+ [tutorialOkButton setFrameOrigin:NSMakePoint(buttonXOffset, yOffset)];
+
+ CGFloat linkYOffset = yOffset + (NSHeight([tutorialOkButton frame]) -
+ NSHeight([learnMoreLink frame])) / 2;
+ [learnMoreLink setFrameOrigin:NSMakePoint(kHorizontalSpacing, linkYOffset)];
+ }
+ [container addSubview:tutorialOkButton];
[container addSubview:learnMoreLink];
yOffset = std::max(NSMaxY([learnMoreLink frame]),
@@ -1679,7 +1705,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
NSView* titleView = BuildTitleCard(
NSMakeRect(0, yOffset, kFixedGaiaViewWidth, 0),
- l10n_util::GetNSString(messageId),
+ l10n_util::GetStringUTF16(messageId),
self /* backButtonTarget*/,
@selector(navigateBackFromSigninPage:) /* backButtonAction */);
[container addSubview:titleView];
@@ -1749,7 +1775,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
NSView* titleView = BuildTitleCard(
NSMakeRect(0, yOffset, kFixedAccountRemovalViewWidth,0),
- l10n_util::GetNSString(IDS_PROFILES_ACCOUNT_REMOVAL_TITLE),
+ l10n_util::GetStringUTF16(IDS_PROFILES_ACCOUNT_REMOVAL_TITLE),
self /* backButtonTarget*/,
@selector(showAccountManagement:) /* backButtonAction */);
[container addSubview:titleView];
@@ -1805,9 +1831,10 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
yOffset = NSMaxY([separator frame]);
// Adds the content text.
+ base::string16 elidedName(gfx::ElideText(
+ avatarItem.name, gfx::FontList(), availableWidth, gfx::ELIDE_TAIL));
NSTextField* contentLabel = BuildLabel(
- l10n_util::GetNSStringF(
- IDS_PROFILES_NOT_YOU_CONTENT_TEXT, avatarItem.name),
+ l10n_util::GetNSStringF(IDS_PROFILES_NOT_YOU_CONTENT_TEXT, elidedName),
NSMakePoint(kHorizontalSpacing, yOffset + kVerticalSpacing),
nil);
[contentLabel setFrameSize:NSMakeSize(availableWidth, 0)];
@@ -1823,7 +1850,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
NSView* titleView = BuildTitleCard(
NSMakeRect(0, yOffset, kFixedSwitchUserViewWidth,0),
- l10n_util::GetNSStringF(IDS_PROFILES_NOT_YOU, avatarItem.name),
+ l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU, avatarItem.name),
self /* backButtonTarget*/,
@selector(navigateBackFromSwitchUserView:) /* backButtonAction */);
[container addSubview:titleView];

Powered by Google App Engine
This is Rietveld 408576698