From 898afa22677fc999cd9aeafdde60be43030bacdf Mon Sep 17 00:00:00 2001 From: "pkasting@chromium.org" Date: Mon, 30 Dec 2013 16:59:31 +0000 Subject: [PATCH] Size infobar elements to their preferred size at creation time. This allows for some code simplifications where we can call SetPosition() instead of SetBounds(), and omit some GetPreferredSize() calls. Labels and Links still need to use these since their widths actually change; some simplification for that is coming in a future patch. This also uses OffsetY() to position the extension infobar contents like all other infobar objects (instead of dynamically changing the height). This also makes two other minor changes in passing: * Don't bother always calling SetFocusable() on Links, that will happen automatically. * Correctly account for icon width when calculating the close button bounds BUG=none TEST=Shrinking an infobar to its minimum width should result in less close button overlap with infobar content R=msw@chromium.org Review URL: https://codereview.chromium.org/119713002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242725 0039d316-1c4b-4281-b951-d872f2087c98 --- .../ui/views/infobars/after_translate_infobar.cc | 57 +++++++++--------- .../views/infobars/alternate_nav_infobar_view.cc | 6 +- .../ui/views/infobars/before_translate_infobar.cc | 68 +++++++++------------- .../browser/ui/views/infobars/confirm_infobar.cc | 26 ++++----- .../browser/ui/views/infobars/extension_infobar.cc | 28 +++++---- chrome/browser/ui/views/infobars/infobar_view.cc | 38 ++++++------ chrome/browser/ui/views/infobars/infobar_view.h | 8 +-- .../ui/views/infobars/translate_message_infobar.cc | 10 ++-- 8 files changed, 113 insertions(+), 128 deletions(-) diff --git a/chrome/browser/ui/views/infobars/after_translate_infobar.cc b/chrome/browser/ui/views/infobars/after_translate_infobar.cc index 07be1bcc6ae1..98430b36a7be 100644 --- a/chrome/browser/ui/views/infobars/after_translate_infobar.cc +++ b/chrome/browser/ui/views/infobars/after_translate_infobar.cc @@ -39,46 +39,43 @@ void AfterTranslateInfoBar::Layout() { int available_width = std::max(0, EndX() - StartX() - ContentMinimumWidth()); gfx::Size label_1_size = label_1_->GetPreferredSize(); - label_1_->SetBounds(StartX(), OffsetY(label_1_size), - std::min(label_1_size.width(), available_width), label_1_size.height()); + label_1_->SetBounds(StartX(), OffsetY(label_1_), + std::min(label_1_size.width(), available_width), + label_1_size.height()); available_width = std::max(0, available_width - label_1_size.width()); views::MenuButton* first_button, * second_button; GetButtons(&first_button, &second_button); - gfx::Size first_button_size = first_button->GetPreferredSize(); - first_button->SetBounds(label_1_->bounds().right() + kButtonInLabelSpacing, - OffsetY(first_button_size), first_button_size.width(), - first_button_size.height()); + first_button->SetPosition( + gfx::Point(label_1_->bounds().right() + kButtonInLabelSpacing, + OffsetY(first_button))); gfx::Size label_2_size = label_2_->GetPreferredSize(); - label_2_->SetBounds(first_button->bounds().right() + kButtonInLabelSpacing, - OffsetY(label_2_size), std::min(label_2_size.width(), available_width), - label_2_size.height()); + label_2_->SetBounds( + first_button->bounds().right() + kButtonInLabelSpacing, OffsetY(label_2_), + std::min(label_2_size.width(), available_width), label_2_size.height()); available_width = std::max(0, available_width - label_2_size.width()); if (!autodetermined_source_language_) { - gfx::Size second_button_size = second_button->GetPreferredSize(); - second_button->SetBounds(label_2_->bounds().right() + kButtonInLabelSpacing, - OffsetY(second_button_size), second_button_size.width(), - second_button_size.height()); + second_button->SetPosition( + gfx::Point(label_2_->bounds().right() + kButtonInLabelSpacing, + OffsetY(second_button))); gfx::Size label_3_size = label_3_->GetPreferredSize(); - label_3_->SetBounds(second_button->bounds().right() + kButtonInLabelSpacing, - OffsetY(label_3_size), std::min(label_3_size.width(), available_width), + label_3_->SetBounds( + second_button->bounds().right() + kButtonInLabelSpacing, + OffsetY(label_3_), std::min(label_3_size.width(), available_width), label_3_size.height()); } - gfx::Size revert_button_size = revert_button_->GetPreferredSize(); - revert_button_->SetBounds( + revert_button_->SetPosition(gfx::Point( (autodetermined_source_language_ ? label_2_ : label_3_)->bounds().right() + kButtonInLabelSpacing, - OffsetY(revert_button_size), - revert_button_size.width(), - revert_button_size.height()); + OffsetY(revert_button_))); - gfx::Size options_size = options_menu_button_->GetPreferredSize(); - options_menu_button_->SetBounds(EndX() - options_size.width(), - OffsetY(options_size), options_size.width(), options_size.height()); + options_menu_button_->SetPosition( + gfx::Point(EndX() - options_menu_button_->width(), + OffsetY(options_menu_button_))); } void AfterTranslateInfoBar::ViewHierarchyChanged( @@ -118,8 +115,8 @@ void AfterTranslateInfoBar::ViewHierarchyChanged( AddChildView(second_button); if (autodetermined_source_language_) second_button->SetVisible(false); - label_3_ = CreateLabel(autodetermined_source_language_ ? base::string16() : - strings[2]); + label_3_ = CreateLabel(autodetermined_source_language_ ? + base::string16() : strings[2]); AddChildView(label_3_); revert_button_ = CreateLabelButton(this, @@ -156,14 +153,12 @@ void AfterTranslateInfoBar::ButtonPressed(views::Button* sender, int AfterTranslateInfoBar::ContentMinimumWidth() const { return - (kButtonInLabelSpacing + - original_language_menu_button_->GetPreferredSize().width() + + (kButtonInLabelSpacing + original_language_menu_button_->width() + kButtonInLabelSpacing) + - (kButtonInLabelSpacing + - target_language_menu_button_->GetPreferredSize().width() + + (kButtonInLabelSpacing + target_language_menu_button_->width() + kButtonInLabelSpacing) + - (kButtonInLabelSpacing + revert_button_->GetPreferredSize().width()) + - (kEndOfLabelSpacing + options_menu_button_->GetPreferredSize().width()); + (kButtonInLabelSpacing + revert_button_->width()) + + (kEndOfLabelSpacing + options_menu_button_->width()); } void AfterTranslateInfoBar::OnMenuButtonClicked(views::View* source, diff --git a/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.cc b/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.cc index bff44c1dd752..d3c26b9f2679 100644 --- a/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.cc +++ b/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.cc @@ -40,17 +40,17 @@ void AlternateNavInfoBarView::Layout() { // view because its subsequent view will be too small to show an ellipsis. gfx::Size label_1_size = label_1_->GetPreferredSize(); int available_width = EndX() - StartX(); - label_1_->SetBounds(StartX(), OffsetY(label_1_size), + label_1_->SetBounds(StartX(), OffsetY(label_1_), std::min(label_1_size.width(), available_width), label_1_size.height()); available_width = std::max(0, available_width - label_1_size.width()); gfx::Size link_size = link_->GetPreferredSize(); - link_->SetBounds(label_1_->bounds().right(), OffsetY(link_size), + link_->SetBounds(label_1_->bounds().right(), OffsetY(link_), std::min(link_size.width(), available_width), link_size.height()); available_width = std::max(0, available_width - link_size.width()); gfx::Size label_2_size = label_2_->GetPreferredSize(); - label_2_->SetBounds(link_->bounds().right(), OffsetY(label_2_size), + label_2_->SetBounds(link_->bounds().right(), OffsetY(label_2_), std::min(label_2_size.width(), available_width), label_2_size.height()); } diff --git a/chrome/browser/ui/views/infobars/before_translate_infobar.cc b/chrome/browser/ui/views/infobars/before_translate_infobar.cc index 483e3d98f403..909c7f9e01b8 100644 --- a/chrome/browser/ui/views/infobars/before_translate_infobar.cc +++ b/chrome/browser/ui/views/infobars/before_translate_infobar.cc @@ -36,52 +36,43 @@ void BeforeTranslateInfoBar::Layout() { int available_width = std::max(0, EndX() - StartX() - ContentMinimumWidth()); gfx::Size label_1_size = label_1_->GetPreferredSize(); - label_1_->SetBounds(StartX(), OffsetY(label_1_size), + label_1_->SetBounds(StartX(), OffsetY(label_1_), std::min(label_1_size.width(), available_width), label_1_size.height()); available_width = std::max(0, available_width - label_1_size.width()); - gfx::Size language_button_size = language_menu_button_->GetPreferredSize(); - language_menu_button_->SetBounds( - label_1_->bounds().right() + kButtonInLabelSpacing, - OffsetY(language_button_size), language_button_size.width(), - language_button_size.height()); + language_menu_button_->SetPosition( + gfx::Point(label_1_->bounds().right() + kButtonInLabelSpacing, + OffsetY(language_menu_button_))); gfx::Size label_2_size = label_2_->GetPreferredSize(); label_2_->SetBounds( language_menu_button_->bounds().right() + kButtonInLabelSpacing, - OffsetY(label_2_size), std::min(label_2_size.width(), available_width), + OffsetY(label_2_), std::min(label_2_size.width(), available_width), label_2_size.height()); - gfx::Size accept_button_size = accept_button_->GetPreferredSize(); - accept_button_->SetBounds(label_2_->bounds().right() + kEndOfLabelSpacing, - OffsetY(accept_button_size), accept_button_size.width(), - accept_button_size.height()); + accept_button_->SetPosition( + gfx::Point(label_2_->bounds().right() + kEndOfLabelSpacing, + OffsetY(accept_button_))); - gfx::Size deny_button_size = deny_button_->GetPreferredSize(); - deny_button_->SetBounds( - accept_button_->bounds().right() + kButtonButtonSpacing, - OffsetY(deny_button_size), deny_button_size.width(), - deny_button_size.height()); + deny_button_->SetPosition( + gfx::Point(accept_button_->bounds().right() + kButtonButtonSpacing, + OffsetY(deny_button_))); if (never_translate_button_) { - gfx::Size never_button_size = never_translate_button_->GetPreferredSize(); - never_translate_button_->SetBounds( - deny_button_->bounds().right() + kButtonButtonSpacing, - OffsetY(never_button_size), never_button_size.width(), - never_button_size.height()); + never_translate_button_->SetPosition( + gfx::Point(deny_button_->bounds().right() + kButtonButtonSpacing, + OffsetY(never_translate_button_))); } if (always_translate_button_) { - gfx::Size always_button_size = always_translate_button_->GetPreferredSize(); - always_translate_button_->SetBounds( - deny_button_->bounds().right() + kButtonButtonSpacing, - OffsetY(always_button_size), always_button_size.width(), - always_button_size.height()); + always_translate_button_->SetPosition( + gfx::Point(deny_button_->bounds().right() + kButtonButtonSpacing, + OffsetY(always_translate_button_))); } - gfx::Size options_size = options_menu_button_->GetPreferredSize(); - options_menu_button_->SetBounds(EndX() - options_size.width(), - OffsetY(options_size), options_size.width(), options_size.height()); + options_menu_button_->SetPosition( + gfx::Point(EndX() - options_menu_button_->width(), + OffsetY(options_menu_button_))); } void BeforeTranslateInfoBar::ViewHierarchyChanged( @@ -150,18 +141,15 @@ void BeforeTranslateInfoBar::ViewHierarchyChanged( int BeforeTranslateInfoBar::ContentMinimumWidth() const { return - (kButtonInLabelSpacing + - language_menu_button_->GetPreferredSize().width() + + (kButtonInLabelSpacing + language_menu_button_->width() + kButtonInLabelSpacing) + - (kEndOfLabelSpacing + accept_button_->GetPreferredSize().width()) + - (kButtonButtonSpacing + deny_button_->GetPreferredSize().width()) + - ((never_translate_button_ == NULL) ? 0 : - (kButtonButtonSpacing + - never_translate_button_->GetPreferredSize().width())) + - ((always_translate_button_ == NULL) ? 0 : - (kButtonButtonSpacing + - always_translate_button_->GetPreferredSize().width())) + - (kEndOfLabelSpacing + options_menu_button_->GetPreferredSize().width()); + (kEndOfLabelSpacing + accept_button_->width()) + + (kButtonButtonSpacing + deny_button_->width()) + + (never_translate_button_ ? + (kButtonButtonSpacing + never_translate_button_->width()) : 0) + + (always_translate_button_ ? + (kButtonButtonSpacing + always_translate_button_->width()) : 0) + + (kEndOfLabelSpacing + options_menu_button_->width()); } void BeforeTranslateInfoBar::ButtonPressed(views::Button* sender, diff --git a/chrome/browser/ui/views/infobars/confirm_infobar.cc b/chrome/browser/ui/views/infobars/confirm_infobar.cc index 8bb41f6e7721..10e77a3924b3 100644 --- a/chrome/browser/ui/views/infobars/confirm_infobar.cc +++ b/chrome/browser/ui/views/infobars/confirm_infobar.cc @@ -39,28 +39,24 @@ void ConfirmInfoBar::Layout() { int available_width = std::max(0, EndX() - StartX() - ContentMinimumWidth()); gfx::Size label_size = label_->GetPreferredSize(); - label_->SetBounds(StartX(), OffsetY(label_size), - std::min(label_size.width(), available_width), label_size.height()); + label_->SetBounds(StartX(), OffsetY(label_), + std::min(label_size.width(), available_width), + label_size.height()); available_width = std::max(0, available_width - label_size.width()); int button_x = label_->bounds().right() + kEndOfLabelSpacing; if (ok_button_ != NULL) { - gfx::Size ok_size = ok_button_->GetPreferredSize(); - ok_button_->SetBounds(button_x, OffsetY(ok_size), ok_size.width(), - ok_size.height()); - button_x += ok_size.width() + kButtonButtonSpacing; + ok_button_->SetPosition(gfx::Point(button_x, OffsetY(ok_button_))); + button_x += ok_button_->width() + kButtonButtonSpacing; } - if (cancel_button_ != NULL) { - gfx::Size cancel_size = cancel_button_->GetPreferredSize(); - cancel_button_->SetBounds(button_x, OffsetY(cancel_size), - cancel_size.width(), cancel_size.height()); - } + if (cancel_button_ != NULL) + cancel_button_->SetPosition(gfx::Point(button_x, OffsetY(cancel_button_))); if (link_ != NULL) { gfx::Size link_size = link_->GetPreferredSize(); int link_width = std::min(link_size.width(), available_width); - link_->SetBounds(EndX() - link_width, OffsetY(link_size), link_width, + link_->SetBounds(EndX() - link_width, OffsetY(link_), link_width, link_size.height()); } } @@ -118,11 +114,11 @@ int ConfirmInfoBar::ContentMinimumWidth() const { int width = (link_ == NULL) ? 0 : kEndOfLabelSpacing; // Space before link int before_cancel_spacing = kEndOfLabelSpacing; if (ok_button_ != NULL) { - width += kEndOfLabelSpacing + ok_button_->GetPreferredSize().width(); + width += kEndOfLabelSpacing + ok_button_->width(); before_cancel_spacing = kButtonButtonSpacing; } - return width + ((cancel_button_ == NULL) ? 0 : - (before_cancel_spacing + cancel_button_->GetPreferredSize().width())); + return width + + (cancel_button_ ? (before_cancel_spacing + cancel_button_->width()) : 0); } void ConfirmInfoBar::LinkClicked(views::Link* source, int event_flags) { diff --git a/chrome/browser/ui/views/infobars/extension_infobar.cc b/chrome/browser/ui/views/infobars/extension_infobar.cc index 236c97d51b1d..a345422fa6e6 100644 --- a/chrome/browser/ui/views/infobars/extension_infobar.cc +++ b/chrome/browser/ui/views/infobars/extension_infobar.cc @@ -90,8 +90,6 @@ ExtensionInfoBar::ExtensionInfoBar( icon_as_menu_(NULL), icon_as_image_(NULL), weak_ptr_factory_(this) { - int height = GetDelegate()->height(); - SetBarTargetHeight((height > 0) ? (height + kSeparatorLineHeight) : 0); } ExtensionInfoBar::~ExtensionInfoBar() { @@ -100,15 +98,22 @@ ExtensionInfoBar::~ExtensionInfoBar() { void ExtensionInfoBar::Layout() { InfoBarView::Layout(); - gfx::Size size = infobar_icon_->GetPreferredSize(); - infobar_icon_->SetBounds(StartX(), OffsetY(size), size.width(), - size.height()); - - GetDelegate()->extension_view_host()->view()->SetBounds( - infobar_icon_->bounds().right() + kIconHorizontalMargin, - arrow_height(), - std::max(0, EndX() - StartX() - ContentMinimumWidth()), - height() - arrow_height() - 1); + infobar_icon_->SetPosition(gfx::Point(StartX(), OffsetY(infobar_icon_))); + ExtensionViewViews* extension_view = + GetDelegate()->extension_view_host()->view(); + // TODO(pkasting): We'd like to simply set the extension view's desired height + // at creation time and position using OffsetY() like for other infobar items, + // but the NativeViewHost inside does not seem to be clipped by the ClipRect() + // call in InfoBarView::PaintChildren(), so we have to manually clamp the size + // here. + extension_view->SetSize( + gfx::Size(std::max(0, EndX() - StartX() - ContentMinimumWidth()), + std::min(height() - kSeparatorLineHeight - arrow_height(), + GetDelegate()->height()))); + // We do SetPosition() separately after SetSize() so OffsetY() will work. + extension_view->SetPosition( + gfx::Point(infobar_icon_->bounds().right() + kIconHorizontalMargin, + std::max(arrow_height(), OffsetY(extension_view)))); } void ExtensionInfoBar::ViewHierarchyChanged( @@ -203,6 +208,7 @@ void ExtensionInfoBar::OnImageLoaded(const gfx::Image& image) { icon_as_image_->SetImage(*icon); } + infobar_icon_->SizeToPreferredSize(); infobar_icon_->SetVisible(true); Layout(); diff --git a/chrome/browser/ui/views/infobars/infobar_view.cc b/chrome/browser/ui/views/infobars/infobar_view.cc index 5b81098f39bc..dab49e78c13f 100644 --- a/chrome/browser/ui/views/infobars/infobar_view.cc +++ b/chrome/browser/ui/views/infobars/infobar_view.cc @@ -82,6 +82,7 @@ views::Label* InfoBarView::CreateLabel(const base::string16& text) const { ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); views::Label* label = new views::Label(text, rb.GetFont(ui::ResourceBundle::MediumFont)); + label->SizeToPreferredSize(); label->SetBackgroundColor(background()->get_color()); label->SetEnabledColor(SK_ColorBLACK); label->SetHorizontalAlignment(gfx::ALIGN_LEFT); @@ -94,10 +95,10 @@ views::Link* InfoBarView::CreateLink(const base::string16& text, views::Link* link = new views::Link; link->SetText(text); link->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); + link->SizeToPreferredSize(); link->SetHorizontalAlignment(gfx::ALIGN_LEFT); link->set_listener(listener); link->SetBackgroundColor(background()->get_color()); - link->SetFocusable(true); return link; } @@ -127,6 +128,7 @@ views::MenuButton* InfoBarView::CreateMenuButton( menu_button->SetEnabledColor(SK_ColorBLACK); menu_button->SetHoverColor(SK_ColorBLACK); menu_button->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); + menu_button->SizeToPreferredSize(); menu_button->SetFocusable(true); return menu_button; } @@ -183,6 +185,7 @@ views::LabelButton* InfoBarView::CreateLabelButton( } } #endif + label_button->SizeToPreferredSize(); label_button->SetFocusable(true); return label_button; } @@ -234,19 +237,16 @@ void InfoBarView::Layout() { int start_x = kHorizontalPadding; if (icon_ != NULL) { - gfx::Size icon_size = icon_->GetPreferredSize(); - icon_->SetBounds(start_x, OffsetY(icon_size), icon_size.width(), - icon_size.height()); + icon_->SetPosition(gfx::Point(start_x, OffsetY(icon_))); + start_x = icon_->bounds().right() + kHorizontalPadding; } int content_minimum_width = ContentMinimumWidth(); - gfx::Size button_size = close_button_->GetPreferredSize(); - close_button_->SetBounds( - std::max( - start_x + content_minimum_width + - ((content_minimum_width > 0) ? kCloseButtonSpacing : 0), - width() - kHorizontalPadding - button_size.width()), - OffsetY(button_size), button_size.width(), button_size.height()); + close_button_->SetPosition(gfx::Point( + std::max(start_x + content_minimum_width + + ((content_minimum_width > 0) ? kCloseButtonSpacing : 0), + width() - kHorizontalPadding - close_button_->width()), + OffsetY(close_button_))); } void InfoBarView::ViewHierarchyChanged( @@ -258,6 +258,7 @@ void InfoBarView::ViewHierarchyChanged( if (!image.IsEmpty()) { icon_ = new views::ImageView; icon_->SetImage(image.ToImageSkia()); + icon_->SizeToPreferredSize(); AddChildView(icon_); } @@ -269,6 +270,7 @@ void InfoBarView::ViewHierarchyChanged( rb.GetImageNamed(IDR_CLOSE_1_H).ToImageSkia()); close_button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageNamed(IDR_CLOSE_1_P).ToImageSkia()); + close_button_->SizeToPreferredSize(); close_button_->SetAccessibleName( l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); close_button_->SetFocusable(true); @@ -285,7 +287,7 @@ void InfoBarView::ViewHierarchyChanged( const int kMinimumVerticalPadding = 6; int height = kDefaultBarTargetHeight; for (int i = 0; i < child_count(); ++i) { - const int child_height = child_at(i)->GetPreferredSize().height(); + const int child_height = child_at(i)->height(); height = std::max(height, child_height + kMinimumVerticalPadding); } SetBarTargetHeight(height); @@ -332,9 +334,9 @@ int InfoBarView::EndX() const { return close_button_->x() - kCloseButtonSpacing; } -int InfoBarView::OffsetY(const gfx::Size& prefsize) const { +int InfoBarView::OffsetY(views::View* view) const { return arrow_height() + - std::max((bar_target_height() - prefsize.height()) / 2, 0) - + std::max((bar_target_height() - view->height()) / 2, 0) - (bar_target_height() - bar_height()); } @@ -401,11 +403,9 @@ void InfoBarView::GetAccessibleState(ui::AccessibleViewState* state) { gfx::Size InfoBarView::GetPreferredSize() { return gfx::Size( - kHorizontalPadding + - ((icon_ == NULL) ? - 0 : (icon_->GetPreferredSize().width() + kHorizontalPadding)) + - ContentMinimumWidth() + kCloseButtonSpacing + - close_button_->GetPreferredSize().width() + kHorizontalPadding, + kHorizontalPadding + (icon_ ? (icon_->width() + kHorizontalPadding) : 0) + + ContentMinimumWidth() + kCloseButtonSpacing + close_button_->width() + + kHorizontalPadding, total_height()); } diff --git a/chrome/browser/ui/views/infobars/infobar_view.h b/chrome/browser/ui/views/infobars/infobar_view.h index 2d5341c799d8..51113c276b35 100644 --- a/chrome/browser/ui/views/infobars/infobar_view.h +++ b/chrome/browser/ui/views/infobars/infobar_view.h @@ -87,10 +87,10 @@ class InfoBarView : public InfoBar, int StartX() const; int EndX() const; - // Given a control with size |prefsize|, returns the centered y position - // within us, taking into account animation so the control "slides in" (or - // out) as we animate open and closed. - int OffsetY(const gfx::Size& prefsize) const; + // Given a |view|, returns the centered y position within us, taking into + // account animation so the control "slides in" (or out) as we animate open + // and closed. + int OffsetY(views::View* view) const; // Convenience getter. const InfoBarContainer::Delegate* container_delegate() const; diff --git a/chrome/browser/ui/views/infobars/translate_message_infobar.cc b/chrome/browser/ui/views/infobars/translate_message_infobar.cc index 9f3dea4737ed..973f5eefac12 100644 --- a/chrome/browser/ui/views/infobars/translate_message_infobar.cc +++ b/chrome/browser/ui/views/infobars/translate_message_infobar.cc @@ -22,15 +22,16 @@ void TranslateMessageInfoBar::Layout() { TranslateInfoBarBase::Layout(); gfx::Size label_size = label_->GetPreferredSize(); - label_->SetBounds(StartX(), OffsetY(label_size), + label_->SetBounds(StartX(), OffsetY(label_), std::min(label_size.width(), std::max(0, EndX() - StartX() - ContentMinimumWidth())), label_size.height()); if (button_) { gfx::Size button_size = button_->GetPreferredSize(); - button_->SetBounds(label_->bounds().right() + kButtonInLabelSpacing, - OffsetY(button_size), button_size.width(), button_size.height()); + button_->SetPosition( + gfx::Point(label_->bounds().right() + kButtonInLabelSpacing, + OffsetY(button_))); } } @@ -64,6 +65,5 @@ void TranslateMessageInfoBar::ButtonPressed(views::Button* sender, } int TranslateMessageInfoBar::ContentMinimumWidth() const { - return (button_ != NULL) ? - (button_->GetPreferredSize().width() + kButtonInLabelSpacing) : 0; + return button_ ? (button_->width() + kButtonInLabelSpacing) : 0; } -- 2.11.4.GIT