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

Unified Diff: chrome/browser/ui/views/profile_chooser_view.cc

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/views/profile_chooser_view.cc
diff --git a/chrome/browser/ui/views/profile_chooser_view.cc b/chrome/browser/ui/views/profile_chooser_view.cc
index 02ecb52ad66526421e6d25316c6075cec5cbd632..cd481efe170d9b45c71188d870f378a7f12c3f25 100644
--- a/chrome/browser/ui/views/profile_chooser_view.cc
+++ b/chrome/browser/ui/views/profile_chooser_view.cc
@@ -49,8 +49,9 @@ namespace {
// Helpers --------------------------------------------------------------------
-const int kMinMenuWidth = 250;
+const int kFixedMenuWidth = 250;
const int kButtonHeight = 29;
+const int kLargeImageSide = 64;
// Creates a GridLayout with a single column. This ensures that all the child
// views added get auto-expanded to fill the full width of the bubble.
@@ -60,7 +61,7 @@ views::GridLayout* CreateSingleColumnLayout(views::View* view) {
views::ColumnSet* columns = layout->AddColumnSet(0);
columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
- views::GridLayout::USE_PREF, 0, 0);
+ views::GridLayout::FIXED, kFixedMenuWidth, 0);
return layout;
}
@@ -73,7 +74,7 @@ views::GridLayout* CreateDoubleColumnLayout(views::View* view) {
columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
views::GridLayout::USE_PREF, 0, 0);
columns->AddPaddingColumn(0, views::kUnrelatedControlLargeHorizontalSpacing);
- columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
+ columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
views::GridLayout::USE_PREF, 0, 0);
return layout;
}
@@ -87,6 +88,16 @@ views::Link* CreateLink(const base::string16& link_text,
return link_button;
}
+base::string16 ElideText(const base::string16& text,
+ float width,
+ ui::ResourceBundle::FontStyle font_style) {
+ return gfx::ElideText(
+ text,
+ ui::ResourceBundle::GetSharedInstance().GetFontList(font_style),
+ width,
+ gfx::ELIDE_AT_END);
+}
+
// BackgroundColorHoverButton -------------------------------------------------
@@ -166,7 +177,6 @@ class EditableProfilePhoto : public views::ImageView {
bool is_editing_allowed)
: views::ImageView(),
change_photo_button_(NULL) {
- const int kLargeImageSide = 64;
const SkColor kBackgroundColor = SkColorSetARGB(125, 0, 0, 0);
const int kOverlayHeight = 20;
@@ -234,12 +244,29 @@ class EditableProfileName : public views::TextButton,
EditableProfileName(views::TextfieldController* controller,
const base::string16& text,
bool is_editing_allowed)
- : views::TextButton(this, text),
+ : views::TextButton(this, base::string16()),
+ full_profile_name_(text),
profile_name_textfield_(NULL) {
+
+ // The button has a fixed width, so we need to calculate the exact width
+ // available for the profile name column, so that the text can be
+ // elided correctly if needed.
+ float available_button_width =
+ kFixedMenuWidth - // Entire width of the bubble.
+ 2 * views::kButtonHEdgeMarginNew - // Bubble insets.
+ kLargeImageSide - // Width of the profile photo.
+ views::kUnrelatedControlLargeHorizontalSpacing;
+
ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
+ const gfx::ImageSkia& icon = *rb->GetImageSkiaNamed(IDR_INFOBAR_AUTOFILL);
+ float icon_width = is_editing_allowed? icon.width() : 0;
+ base::string16 elided_name = ElideText(text,
sky 2014/01/23 01:00:52 You shouldn't need to elide the text yourself. You
+ available_button_width - icon_width,
+ ui::ResourceBundle::MediumFont);
const gfx::FontList& medium_font_list =
rb->GetFontList(ui::ResourceBundle::MediumFont);
SetFontList(medium_font_list);
+ SetText(elided_name);
set_border(NULL);
if (!is_editing_allowed)
@@ -273,7 +300,7 @@ class EditableProfileName : public views::TextButton,
const ui::Event& event) OVERRIDE {
if (profile_name_textfield_) {
profile_name_textfield_->SetVisible(true);
- profile_name_textfield_->SetText(text());
+ profile_name_textfield_->SetText(full_profile_name_);
profile_name_textfield_->SelectAll(false);
profile_name_textfield_->RequestFocus();
}
@@ -294,6 +321,11 @@ class EditableProfileName : public views::TextButton,
views::View::Layout();
}
+ // The complete profile name. Because the control has a fixed width, we will
+ // have to elide the profile name when displaying it. However, in edit mode,
+ // we should show the entire name.
+ base::string16 full_profile_name_;
+
// Button that is shown when hovering over the image view. Can be NULL if
// the profile name isn't allowed to be edited (e.g. for guest profiles).
views::Textfield* profile_name_textfield_;
@@ -430,7 +462,7 @@ void ProfileChooserView::ShowView(BubbleViewMode view_to_display,
view_mode_ = view_to_display;
views::GridLayout* layout = CreateSingleColumnLayout(this);
- layout->set_minimum_size(gfx::Size(kMinMenuWidth, 0));
+ layout->set_minimum_size(gfx::Size(kFixedMenuWidth, 0));
if (view_to_display == GAIA_SIGNIN_VIEW ||
view_to_display == GAIA_ADD_ACCOUNT_VIEW) {
@@ -714,7 +746,18 @@ views::View* ProfileChooserView::CreateOtherProfilesView(
kSmallImageSide + profiles::kAvatarIconPadding,
kSmallImageSide + profiles::kAvatarIconPadding);
- views::TextButton* button = new views::TextButton(this, item.name);
+ // Since the bubble has a fixed width, we need to calculate the exact
+ // width available for the profile name, and elide it if needed.
+ float available_text_width =
+ kFixedMenuWidth - // Entire width of the bubble.
+ 2 * views::kButtonHEdgeMarginNew - // Insets.
+ kSmallImageSide - // Width of the button icon.
+ views::kItemLabelSpacing; // Space between text and icon.
+ views::TextButton* button = new views::TextButton(
+ this,
+ ElideText(item.name,
+ available_text_width,
+ ui::ResourceBundle::MediumFont));
open_other_profile_indexes_map_[button] = index;
button->SetIcon(*image.ToImageSkia());
button->set_icon_text_spacing(views::kItemLabelSpacing);
@@ -806,10 +849,14 @@ views::View* ProfileChooserView::CreateCurrentProfileAccountsView(
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
- add_account_button_ = new views::BlueButton(
- this,
- l10n_util::GetStringFUTF16(IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON,
- avatar_item.name));
+ // Elide the button text so that the contents fit inside the bubble.
+ base::string16 elided_button_text =
+ ElideText(l10n_util::GetStringFUTF16(
+ IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, avatar_item.name),
+ kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew, // Width - insets.
+ ui::ResourceBundle::MediumFont);
+
+ add_account_button_ = new views::BlueButton(this, elided_button_text);
layout->StartRow(1, 0);
layout->AddView(add_account_button_);
return view;

Powered by Google App Engine
This is Rietveld 408576698