summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/views/infobars
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-24 00:16:58 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-24 00:16:58 +0000
commit26616172ccaeae9842d7e52b556bc49e16751455 (patch)
treef7f3833290a36d704ef486eecd119114594706e1 /chrome/browser/ui/views/infobars
parent4c189b074264429bbac3c55260f1b1204d292f72 (diff)
downloadchromium_src-26616172ccaeae9842d7e52b556bc49e16751455.zip
chromium_src-26616172ccaeae9842d7e52b556bc49e16751455.tar.gz
chromium_src-26616172ccaeae9842d7e52b556bc49e16751455.tar.bz2
Cleanup:
* Remove InfoBarTextButton and just use a normal views::TextButton. The custom things InfoBarTextButton wanted to do (like fixing some button sizing issues) are now part of the base TextButton. * Restore the "needs elevation" badge for the "set default browser" infobar, which was lost in http://src.chromium.org/viewvc/chrome?view=rev&revision=70913 . * Factor out common code for creating buttons, labels, and links into static methods on InfoBarView. * Remove the ability of LinkInfoBar to draw links right-aligned, which was unused. BUG=none TEST=none Review URL: http://codereview.chromium.org/6574011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75821 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/views/infobars')
-rw-r--r--chrome/browser/ui/views/infobars/after_translate_infobar.cc9
-rw-r--r--chrome/browser/ui/views/infobars/after_translate_infobar.h3
-rw-r--r--chrome/browser/ui/views/infobars/before_translate_infobar.cc21
-rw-r--r--chrome/browser/ui/views/infobars/before_translate_infobar.h9
-rw-r--r--chrome/browser/ui/views/infobars/confirm_infobar.cc43
-rw-r--r--chrome/browser/ui/views/infobars/confirm_infobar.h6
-rw-r--r--chrome/browser/ui/views/infobars/infobar_text_button.cc57
-rw-r--r--chrome/browser/ui/views/infobars/infobar_text_button.h38
-rw-r--r--chrome/browser/ui/views/infobars/infobar_view.cc83
-rw-r--r--chrome/browser/ui/views/infobars/infobar_view.h24
-rw-r--r--chrome/browser/ui/views/infobars/link_infobar.cc59
-rw-r--r--chrome/browser/ui/views/infobars/translate_infobar_base.cc40
-rw-r--r--chrome/browser/ui/views/infobars/translate_infobar_base.h12
-rw-r--r--chrome/browser/ui/views/infobars/translate_message_infobar.cc4
-rw-r--r--chrome/browser/ui/views/infobars/translate_message_infobar.h4
15 files changed, 157 insertions, 255 deletions
diff --git a/chrome/browser/ui/views/infobars/after_translate_infobar.cc b/chrome/browser/ui/views/infobars/after_translate_infobar.cc
index 6c38fae..990b8f2 100644
--- a/chrome/browser/ui/views/infobars/after_translate_infobar.cc
+++ b/chrome/browser/ui/views/infobars/after_translate_infobar.cc
@@ -5,15 +5,10 @@
#include "chrome/browser/ui/views/infobars/after_translate_infobar.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/translate/options_menu_model.h"
#include "chrome/browser/translate/translate_infobar_delegate.h"
-#include "chrome/browser/ui/views/infobars/infobar_button_border.h"
-#include "chrome/browser/ui/views/infobars/infobar_text_button.h"
-#include "grit/app_resources.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "views/controls/button/menu_button.h"
-#include "views/controls/button/text_button.h"
#include "views/controls/image_view.h"
#include "views/controls/label.h"
#include "views/controls/menu/menu_2.h"
@@ -46,8 +41,8 @@ AfterTranslateInfoBar::AfterTranslateInfoBar(
label_3_ = CreateLabel(strings[2]);
AddChildView(label_3_);
- revert_button_ = InfoBarTextButton::Create(this,
- l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_REVERT));
+ revert_button_ = CreateTextButton(this,
+ l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_REVERT), false);
AddChildView(revert_button_);
options_menu_button_ = CreateMenuButton(
diff --git a/chrome/browser/ui/views/infobars/after_translate_infobar.h b/chrome/browser/ui/views/infobars/after_translate_infobar.h
index bf873be..8dc53bf 100644
--- a/chrome/browser/ui/views/infobars/after_translate_infobar.h
+++ b/chrome/browser/ui/views/infobars/after_translate_infobar.h
@@ -11,7 +11,6 @@
#include "chrome/browser/ui/views/infobars/translate_infobar_base.h"
#include "views/controls/menu/view_menu_delegate.h"
-class InfoBarTextButton;
class TranslateInfoBarDelegate;
namespace views {
class Menu2;
@@ -45,7 +44,7 @@ class AfterTranslateInfoBar : public TranslateInfoBarBase,
views::MenuButton* original_language_menu_button_;
views::MenuButton* target_language_menu_button_;
- InfoBarTextButton* revert_button_;
+ views::TextButton* revert_button_;
views::MenuButton* options_menu_button_;
scoped_ptr<views::Menu2> original_language_menu_;
diff --git a/chrome/browser/ui/views/infobars/before_translate_infobar.cc b/chrome/browser/ui/views/infobars/before_translate_infobar.cc
index 19a83f5..577bad4 100644
--- a/chrome/browser/ui/views/infobars/before_translate_infobar.cc
+++ b/chrome/browser/ui/views/infobars/before_translate_infobar.cc
@@ -5,9 +5,7 @@
#include "chrome/browser/ui/views/infobars/before_translate_infobar.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/translate/options_menu_model.h"
#include "chrome/browser/translate/translate_infobar_delegate.h"
-#include "chrome/browser/ui/views/infobars/infobar_text_button.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "views/controls/button/menu_button.h"
@@ -35,23 +33,26 @@ BeforeTranslateInfoBar::BeforeTranslateInfoBar(
label_2_ = CreateLabel(text.substr(offset));
AddChildView(label_2_);
- accept_button_ = InfoBarTextButton::CreateWithMessageID(this,
- IDS_TRANSLATE_INFOBAR_ACCEPT);
+ accept_button_ = CreateTextButton(this,
+ l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_ACCEPT), false);
AddChildView(accept_button_);
- deny_button_ = InfoBarTextButton::CreateWithMessageID(this,
- IDS_TRANSLATE_INFOBAR_DENY);
+ deny_button_ = CreateTextButton(this,
+ l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_DENY), false);
AddChildView(deny_button_);
const string16& language(delegate->GetLanguageDisplayableNameAt(
delegate->original_language_index()));
if (delegate->ShouldShowNeverTranslateButton()) {
- never_translate_button_ = InfoBarTextButton::CreateWithMessageIDAndParam(
- this, IDS_TRANSLATE_INFOBAR_NEVER_TRANSLATE, language);
+ DCHECK(!delegate->ShouldShowAlwaysTranslateButton());
+ never_translate_button_ = CreateTextButton(this,
+ l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_NEVER_TRANSLATE,
+ language), false);
AddChildView(never_translate_button_);
} else if (delegate->ShouldShowAlwaysTranslateButton()) {
- always_translate_button_ = InfoBarTextButton::CreateWithMessageIDAndParam(
- this, IDS_TRANSLATE_INFOBAR_ALWAYS_TRANSLATE, language);
+ always_translate_button_ = CreateTextButton(this,
+ l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_ALWAYS_TRANSLATE,
+ language), false);
AddChildView(always_translate_button_);
}
diff --git a/chrome/browser/ui/views/infobars/before_translate_infobar.h b/chrome/browser/ui/views/infobars/before_translate_infobar.h
index b327fcd..efe8dc7 100644
--- a/chrome/browser/ui/views/infobars/before_translate_infobar.h
+++ b/chrome/browser/ui/views/infobars/before_translate_infobar.h
@@ -11,7 +11,6 @@
#include "chrome/browser/ui/views/infobars/translate_infobar_base.h"
#include "views/controls/menu/view_menu_delegate.h"
-class InfoBarTextButton;
class TranslateInfoBarDelegate;
namespace views {
class Menu2;
@@ -42,10 +41,10 @@ class BeforeTranslateInfoBar : public TranslateInfoBarBase,
views::Label* label_2_;
views::MenuButton* language_menu_button_;
- InfoBarTextButton* accept_button_;
- InfoBarTextButton* deny_button_;
- InfoBarTextButton* never_translate_button_;
- InfoBarTextButton* always_translate_button_;
+ views::TextButton* accept_button_;
+ views::TextButton* deny_button_;
+ views::TextButton* never_translate_button_;
+ views::TextButton* always_translate_button_;
views::MenuButton* options_menu_button_;
scoped_ptr<views::Menu2> languages_menu_;
diff --git a/chrome/browser/ui/views/infobars/confirm_infobar.cc b/chrome/browser/ui/views/infobars/confirm_infobar.cc
index d9737d5..5ae1f94 100644
--- a/chrome/browser/ui/views/infobars/confirm_infobar.cc
+++ b/chrome/browser/ui/views/infobars/confirm_infobar.cc
@@ -4,11 +4,9 @@
#include "chrome/browser/ui/views/infobars/confirm_infobar.h"
-#include "base/utf_string_conversions.h"
#include "chrome/browser/tab_contents/infobar_delegate.h"
#include "chrome/browser/ui/views/event_utils.h"
-#include "chrome/browser/ui/views/infobars/infobar_text_button.h"
-#include "ui/base/resource/resource_bundle.h"
+#include "views/controls/button/text_button.h"
#include "views/controls/image_view.h"
#include "views/controls/label.h"
@@ -16,11 +14,7 @@
AlertInfoBar::AlertInfoBar(ConfirmInfoBarDelegate* delegate)
: InfoBarView(delegate) {
- label_ = new views::Label(
- UTF16ToWideHack(delegate->GetMessageText()),
- ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont));
- label_->SetColor(SK_ColorBLACK);
- label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ label_ = CreateLabel(delegate->GetMessageText());
AddChildView(label_);
icon_ = new views::ImageView;
@@ -43,11 +37,12 @@ void AlertInfoBar::Layout() {
icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_size),
icon_size.width(), icon_size.height());
- gfx::Size text_size = label_->GetPreferredSize();
- int text_width = std::min(text_size.width(),
+ int available_width = std::max(0,
GetAvailableWidth() - icon_->bounds().right() - kIconLabelSpacing);
+ gfx::Size label_size = label_->GetPreferredSize();
label_->SetBounds(icon_->bounds().right() + kIconLabelSpacing,
- OffsetY(this, text_size), text_width, text_size.height());
+ OffsetY(this, label_size), std::min(label_size.width(), available_width),
+ label_size.height());
}
// ConfirmInfoBarDelegate -----------------------------------------------------
@@ -60,29 +55,19 @@ InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() {
ConfirmInfoBar::ConfirmInfoBar(ConfirmInfoBarDelegate* delegate)
: AlertInfoBar(delegate),
- ok_button_(NULL),
- cancel_button_(NULL),
- link_(NULL),
initialized_(false) {
- ok_button_ = InfoBarTextButton::Create(this,
+ ok_button_ = CreateTextButton(this,
(delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) ?
delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK) :
- string16());
- ok_button_->SetAccessibleName(WideToUTF16Hack(ok_button_->text()));
- cancel_button_ = InfoBarTextButton::Create(this,
+ string16(),
+ delegate->NeedElevation(ConfirmInfoBarDelegate::BUTTON_OK));
+ cancel_button_ = CreateTextButton(this,
(delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) ?
delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL) :
- string16());
- cancel_button_->SetAccessibleName(WideToUTF16Hack(cancel_button_->text()));
-
- // Set up the link.
- link_ = new views::Link;
- link_->SetText(UTF16ToWideHack(delegate->GetLinkText()));
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- link_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
- link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- link_->SetController(this);
- link_->MakeReadableOverBackgroundColor(background()->get_color());
+ string16(),
+ delegate->NeedElevation(ConfirmInfoBarDelegate::BUTTON_CANCEL));
+
+ link_ = CreateLink(delegate->GetLinkText(), this, background()->get_color());
}
ConfirmInfoBar::~ConfirmInfoBar() {
diff --git a/chrome/browser/ui/views/infobars/confirm_infobar.h b/chrome/browser/ui/views/infobars/confirm_infobar.h
index 15aac4b..7b19020 100644
--- a/chrome/browser/ui/views/infobars/confirm_infobar.h
+++ b/chrome/browser/ui/views/infobars/confirm_infobar.h
@@ -10,9 +10,9 @@
#include "views/controls/link.h"
class ConfirmInfoBarDelegate;
-class InfoBarTextButton;
namespace views {
class Label;
+class TextButton;
}
// TODO(pkasting): This class will die soon.
@@ -59,8 +59,8 @@ class ConfirmInfoBar : public AlertInfoBar,
ConfirmInfoBarDelegate* GetDelegate();
- InfoBarTextButton* ok_button_;
- InfoBarTextButton* cancel_button_;
+ views::TextButton* ok_button_;
+ views::TextButton* cancel_button_;
views::Link* link_;
bool initialized_;
diff --git a/chrome/browser/ui/views/infobars/infobar_text_button.cc b/chrome/browser/ui/views/infobars/infobar_text_button.cc
deleted file mode 100644
index 5adabc7..0000000
--- a/chrome/browser/ui/views/infobars/infobar_text_button.cc
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ui/views/infobars/infobar_text_button.h"
-
-#include "base/utf_string_conversions.h"
-#include "chrome/browser/ui/views/infobars/infobar_button_border.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/resource/resource_bundle.h"
-
-// static
-InfoBarTextButton* InfoBarTextButton::Create(views::ButtonListener* listener,
- const string16& text) {
- return new InfoBarTextButton(listener, text);
-}
-
-// static
-InfoBarTextButton* InfoBarTextButton::CreateWithMessageID(
- views::ButtonListener* listener, int message_id) {
- return new InfoBarTextButton(listener,
- l10n_util::GetStringUTF16(message_id));
-}
-
-// static
-InfoBarTextButton* InfoBarTextButton::CreateWithMessageIDAndParam(
- views::ButtonListener* listener, int message_id, const string16& param) {
- return new InfoBarTextButton(listener,
- l10n_util::GetStringFUTF16(message_id, param));
-}
-
-InfoBarTextButton::~InfoBarTextButton() {
-}
-
-bool InfoBarTextButton::OnMousePressed(const views::MouseEvent& e) {
- return views::CustomButton::OnMousePressed(e);
-}
-
-InfoBarTextButton::InfoBarTextButton(views::ButtonListener* listener,
- const string16& text)
- // Don't use text to construct TextButton because we need to set font
- // before setting text so that the button will resize to fit entire text.
- : TextButton(listener, std::wstring()) {
- set_border(new InfoBarButtonBorder);
- SetNormalHasBorder(true); // Normal button state has border.
- SetAnimationDuration(0); // Disable animation during state change.
- // Set font colors for different states.
- SetEnabledColor(SK_ColorBLACK);
- SetHighlightColor(SK_ColorBLACK);
- SetHoverColor(SK_ColorBLACK);
- // Set font then text, then size button to fit text.
- SetFont(
- ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont));
- SetText(UTF16ToWideHack(text));
- ClearMaxTextSize();
- SizeToPreferredSize();
-}
diff --git a/chrome/browser/ui/views/infobars/infobar_text_button.h b/chrome/browser/ui/views/infobars/infobar_text_button.h
deleted file mode 100644
index 14ee42f..0000000
--- a/chrome/browser/ui/views/infobars/infobar_text_button.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_TEXT_BUTTON_H_
-#define CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_TEXT_BUTTON_H_
-#pragma once
-
-#include "views/controls/button/text_button.h"
-
-// A TextButton subclass that overrides OnMousePressed to default to
-// CustomButton so as to create pressed state effect.
-
-class InfoBarTextButton : public views::TextButton {
- public:
- // Creates a button with the specified |text|.
- static InfoBarTextButton* Create(views::ButtonListener* listener,
- const string16& text);
- // Creates a button which text is the resource string identified by
- // |message_id|.
- static InfoBarTextButton* CreateWithMessageID(views::ButtonListener* listener,
- int message_id);
- static InfoBarTextButton* CreateWithMessageIDAndParam(
- views::ButtonListener* listener, int message_id, const string16& param);
-
- virtual ~InfoBarTextButton();
-
- protected:
- InfoBarTextButton(views::ButtonListener* listener, const string16& text);
-
- // Overriden from TextButton:
- virtual bool OnMousePressed(const views::MouseEvent& e);
-
- private:
- DISALLOW_COPY_AND_ASSIGN(InfoBarTextButton);
-};
-
-#endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_TEXT_BUTTON_H_
diff --git a/chrome/browser/ui/views/infobars/infobar_view.cc b/chrome/browser/ui/views/infobars/infobar_view.cc
index 06d2c9f..044a7d5 100644
--- a/chrome/browser/ui/views/infobars/infobar_view.cc
+++ b/chrome/browser/ui/views/infobars/infobar_view.cc
@@ -7,6 +7,7 @@
#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/ui/views/infobars/infobar_background.h"
+#include "chrome/browser/ui/views/infobars/infobar_button_border.h"
#include "chrome/browser/ui/views/infobars/infobar_container.h"
#include "chrome/browser/tab_contents/infobar_delegate.h"
#include "grit/generated_resources.h"
@@ -17,12 +18,20 @@
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas_skia_paint.h"
#include "views/controls/button/image_button.h"
+#include "views/controls/button/menu_button.h"
+#include "views/controls/button/text_button.h"
#include "views/controls/image_view.h"
#include "views/controls/label.h"
+#include "views/controls/link.h"
#include "views/focus/external_focus_tracker.h"
#include "views/widget/widget.h"
#if defined(OS_WIN)
+#include <shellapi.h>
+
+#include "base/win/win_util.h"
+#include "base/win/windows_version.h"
+#include "ui/gfx/icon_util.h"
#include "ui/base/win/hwnd_util.h"
#endif
@@ -158,6 +167,80 @@ void InfoBarView::PaintArrow(gfx::Canvas* canvas,
InfoBarView::~InfoBarView() {
}
+// static
+views::Label* InfoBarView::CreateLabel(const string16& text) {
+ views::Label* label = new views::Label(UTF16ToWideHack(text),
+ ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont));
+ label->SetColor(SK_ColorBLACK);
+ label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ return label;
+}
+
+// static
+views::Link* InfoBarView::CreateLink(const string16& text,
+ views::LinkController* controller,
+ const SkColor& background_color) {
+ views::Link* link = new views::Link;
+ link->SetText(UTF16ToWideHack(text));
+ link->SetFont(
+ ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont));
+ link->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ link->SetController(controller);
+ link->MakeReadableOverBackgroundColor(background_color);
+ return link;
+}
+
+// static
+views::MenuButton* InfoBarView::CreateMenuButton(
+ const string16& text,
+ bool normal_has_border,
+ views::ViewMenuDelegate* menu_delegate) {
+ views::MenuButton* menu_button =
+ new views::MenuButton(NULL, UTF16ToWideHack(text), menu_delegate, true);
+ menu_button->set_border(new InfoBarButtonBorder);
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ menu_button->set_menu_marker(
+ rb.GetBitmapNamed(IDR_INFOBARBUTTON_MENU_DROPARROW));
+ if (normal_has_border) {
+ menu_button->SetNormalHasBorder(true);
+ menu_button->SetAnimationDuration(0);
+ }
+ menu_button->SetEnabledColor(SK_ColorBLACK);
+ menu_button->SetHighlightColor(SK_ColorBLACK);
+ menu_button->SetHoverColor(SK_ColorBLACK);
+ menu_button->SetFont(rb.GetFont(ResourceBundle::MediumFont));
+ return menu_button;
+}
+
+// static
+views::TextButton* InfoBarView::CreateTextButton(
+ views::ButtonListener* listener,
+ const string16& text,
+ bool needs_elevation) {
+ views::TextButton* text_button =
+ new views::TextButton(listener, UTF16ToWideHack(text));
+ text_button->set_border(new InfoBarButtonBorder);
+ text_button->SetNormalHasBorder(true);
+ text_button->SetAnimationDuration(0);
+ text_button->SetEnabledColor(SK_ColorBLACK);
+ text_button->SetHighlightColor(SK_ColorBLACK);
+ text_button->SetHoverColor(SK_ColorBLACK);
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ text_button->SetFont(rb.GetFont(ResourceBundle::MediumFont));
+#if defined(OS_WIN)
+ if (needs_elevation &&
+ (base::win::GetVersion() >= base::win::VERSION_VISTA) &&
+ base::win::UserAccountControlIsEnabled()) {
+ SHSTOCKICONINFO icon_info = { sizeof SHSTOCKICONINFO };
+ SHGetStockIconInfo(SIID_SHIELD, SHGSI_ICON | SHGSI_SMALLICON, &icon_info);
+ text_button->SetIcon(*IconUtil::CreateSkBitmapFromHICON(icon_info.hIcon,
+ gfx::Size(GetSystemMetrics(SM_CXSMICON),
+ GetSystemMetrics(SM_CYSMICON))));
+ }
+#endif
+ return text_button;
+}
+
void InfoBarView::Layout() {
gfx::Size button_size = close_button_->GetPreferredSize();
close_button_->SetBounds(width() - kHorizontalPadding - button_size.width(),
diff --git a/chrome/browser/ui/views/infobars/infobar_view.h b/chrome/browser/ui/views/infobars/infobar_view.h
index dc62f25..3695d11 100644
--- a/chrome/browser/ui/views/infobars/infobar_view.h
+++ b/chrome/browser/ui/views/infobars/infobar_view.h
@@ -23,6 +23,11 @@ class ExternalFocusTracker;
class ImageButton;
class ImageView;
class Label;
+class Link;
+class LinkController;
+class MenuButton;
+class TextButton;
+class ViewMenuDelegate;
}
// TODO(pkasting): infobar_delegate.h forward declares "class InfoBar" but the
@@ -84,6 +89,25 @@ class InfoBarView : public InfoBar,
virtual ~InfoBarView();
+ // Creates a label with the appropriate font and color for an infobar.
+ static views::Label* CreateLabel(const string16& text);
+
+ // Creates a link with the appropriate font and color for an infobar.
+ static views::Link* CreateLink(const string16& text,
+ views::LinkController* controller,
+ const SkColor& background_color);
+
+ // Creates a menu button with an infobar-specific appearance.
+ static views::MenuButton* CreateMenuButton(
+ const string16& text,
+ bool normal_has_border,
+ views::ViewMenuDelegate* menu_delegate);
+
+ // Creates a text button with an infobar-specific appearance.
+ static views::TextButton* CreateTextButton(views::ButtonListener* listener,
+ const string16& text,
+ bool needs_elevation);
+
// views::View:
virtual void Layout();
virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
diff --git a/chrome/browser/ui/views/infobars/link_infobar.cc b/chrome/browser/ui/views/infobars/link_infobar.cc
index 64105ee..9fc4e67 100644
--- a/chrome/browser/ui/views/infobars/link_infobar.cc
+++ b/chrome/browser/ui/views/infobars/link_infobar.cc
@@ -4,10 +4,8 @@
#include "chrome/browser/ui/views/infobars/link_infobar.h"
-#include "base/utf_string_conversions.h"
#include "chrome/browser/tab_contents/infobar_delegate.h"
#include "chrome/browser/ui/views/event_utils.h"
-#include "ui/base/resource/resource_bundle.h"
#include "views/controls/image_view.h"
// LinkInfoBarDelegate --------------------------------------------------------
@@ -20,41 +18,23 @@ InfoBar* LinkInfoBarDelegate::CreateInfoBar() {
LinkInfoBar::LinkInfoBar(LinkInfoBarDelegate* delegate)
: InfoBarView(delegate),
- icon_(new views::ImageView),
- label_1_(new views::Label),
- link_(new views::Link),
- label_2_(new views::Label) {
- // Set up the icon.
+ icon_(new views::ImageView) {
if (delegate->GetIcon())
icon_->SetImage(delegate->GetIcon());
AddChildView(icon_);
- // Set up the labels.
size_t offset;
string16 message_text = delegate->GetMessageTextWithOffset(&offset);
- if (offset != string16::npos) {
- label_1_->SetText(UTF16ToWideHack(message_text.substr(0, offset)));
- label_2_->SetText(UTF16ToWideHack(message_text.substr(offset)));
- } else {
- label_1_->SetText(UTF16ToWideHack(message_text));
- }
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- label_1_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
- label_2_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
- label_1_->SetColor(SK_ColorBLACK);
- label_2_->SetColor(SK_ColorBLACK);
- label_1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- label_2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ DCHECK_NE(string16::npos, offset);
+ label_1_ = CreateLabel(message_text.substr(0, offset));
AddChildView(label_1_);
- AddChildView(label_2_);
- // Set up the link.
- link_->SetText(UTF16ToWideHack(delegate->GetLinkText()));
- link_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
- link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- link_->SetController(this);
- link_->MakeReadableOverBackgroundColor(background()->get_color());
+ link_ = CreateLink(delegate->GetLinkText(), this,
+ background()->get_color());
AddChildView(link_);
+
+ label_2_ = CreateLabel(message_text.substr(offset));
+ AddChildView(label_2_);
}
LinkInfoBar::~LinkInfoBar() {
@@ -69,31 +49,14 @@ void LinkInfoBar::Layout() {
icon_size.width(), icon_size.height());
int label_1_x = icon_->bounds().right() + kIconLabelSpacing;
-
- // Figure out the amount of space available to the rest of the content now
- // that the close button and the icon have been positioned.
- int available_width = GetAvailableWidth() - label_1_x;
-
- // Layout the left label.
gfx::Size label_1_size = label_1_->GetPreferredSize();
label_1_->SetBounds(label_1_x, OffsetY(this, label_1_size),
label_1_size.width(), label_1_size.height());
- // Layout the link.
gfx::Size link_size = link_->GetPreferredSize();
- bool has_second_label = !label_2_->GetText().empty();
- if (has_second_label) {
- // Embed the link in the text string between the two labels.
- link_->SetBounds(label_1_->bounds().right(), OffsetY(this, link_size),
- link_size.width(), link_size.height());
- } else {
- // Right-align the link toward the edge of the InfoBar.
- link_->SetBounds(label_1_x + available_width - link_size.width(),
- OffsetY(this, link_size), link_size.width(), link_size.height());
- }
-
- // Layout the right label (we do this regardless of whether or not it has
- // text).
+ link_->SetBounds(label_1_->bounds().right(), OffsetY(this, link_size),
+ link_size.width(), link_size.height());
+
gfx::Size label_2_size = label_2_->GetPreferredSize();
label_2_->SetBounds(link_->bounds().right(), OffsetY(this, label_2_size),
label_2_size.width(), label_2_size.height());
diff --git a/chrome/browser/ui/views/infobars/translate_infobar_base.cc b/chrome/browser/ui/views/infobars/translate_infobar_base.cc
index 83e0d81..9fa5165 100644
--- a/chrome/browser/ui/views/infobars/translate_infobar_base.cc
+++ b/chrome/browser/ui/views/infobars/translate_infobar_base.cc
@@ -72,46 +72,6 @@ TranslateInfoBarBase::TranslateInfoBarBase(TranslateInfoBarDelegate* delegate)
TranslateInfoBarBase::~TranslateInfoBarBase() {
}
-// static
-views::Label* TranslateInfoBarBase::CreateLabel(const string16& text) {
- views::Label* label = new views::Label(UTF16ToWideHack(text),
- ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont));
- label->SetColor(SK_ColorBLACK);
- label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- return label;
-}
-
-// static
-views::MenuButton* TranslateInfoBarBase::CreateMenuButton(
- const string16& text,
- bool normal_has_border,
- views::ViewMenuDelegate* menu_delegate) {
- // Don't use text to instantiate MenuButton because we need to set font before
- // setting text so that the button will resize to fit the entire text.
- views::MenuButton* menu_button =
- new views::MenuButton(NULL, std::wstring(), menu_delegate, true);
- menu_button->set_border(new InfoBarButtonBorder);
- menu_button->set_menu_marker(ResourceBundle::GetSharedInstance().
- GetBitmapNamed(IDR_INFOBARBUTTON_MENU_DROPARROW));
- if (normal_has_border) {
- menu_button->SetNormalHasBorder(true); // Normal button state has border.
- // Disable animation during state change.
- menu_button->SetAnimationDuration(0);
- }
- // Set font colors for different states.
- menu_button->SetEnabledColor(SK_ColorBLACK);
- menu_button->SetHighlightColor(SK_ColorBLACK);
- menu_button->SetHoverColor(SK_ColorBLACK);
-
- // Set font then text, then size button to fit text.
- menu_button->SetFont(ResourceBundle::GetSharedInstance().GetFont(
- ResourceBundle::MediumFont));
- menu_button->SetText(UTF16ToWideHack(text));
- menu_button->ClearMaxTextSize();
- menu_button->SizeToPreferredSize();
- return menu_button;
-}
-
void TranslateInfoBarBase::Layout() {
InfoBarView::Layout();
diff --git a/chrome/browser/ui/views/infobars/translate_infobar_base.h b/chrome/browser/ui/views/infobars/translate_infobar_base.h
index 35ed3aa..89ee12c 100644
--- a/chrome/browser/ui/views/infobars/translate_infobar_base.h
+++ b/chrome/browser/ui/views/infobars/translate_infobar_base.h
@@ -14,8 +14,8 @@
class TranslateInfoBarDelegate;
namespace views {
+class ImageView;
class MenuButton;
-class ViewMenuDelegate;
}
// This class contains some of the base functionality that translate infobars
@@ -29,16 +29,6 @@ class TranslateInfoBarBase : public TranslateInfoBarView,
protected:
static const int kButtonInLabelSpacing;
- // Creates a label with the appropriate font and color for the translate
- // infobars.
- static views::Label* CreateLabel(const string16& text);
-
- // Creates a menu-button with a custom appearance for the translate infobars.
- static views::MenuButton* CreateMenuButton(
- const string16& text,
- bool normal_has_border,
- views::ViewMenuDelegate* menu_delegate);
-
// InfoBarView:
virtual void Layout();
diff --git a/chrome/browser/ui/views/infobars/translate_message_infobar.cc b/chrome/browser/ui/views/infobars/translate_message_infobar.cc
index 47ead3c..6cabbfd 100644
--- a/chrome/browser/ui/views/infobars/translate_message_infobar.cc
+++ b/chrome/browser/ui/views/infobars/translate_message_infobar.cc
@@ -5,7 +5,7 @@
#include "chrome/browser/ui/views/infobars/translate_message_infobar.h"
#include "chrome/browser/translate/translate_infobar_delegate.h"
-#include "chrome/browser/ui/views/infobars/infobar_text_button.h"
+#include "views/controls/button/text_button.h"
#include "views/controls/image_view.h"
#include "views/controls/label.h"
@@ -18,7 +18,7 @@ TranslateMessageInfoBar::TranslateMessageInfoBar(
string16 button_text = delegate->GetMessageInfoBarButtonText();
if (!button_text.empty()) {
- button_ = InfoBarTextButton::Create(this, button_text);
+ button_ = CreateTextButton(this, button_text, false);
AddChildView(button_);
}
}
diff --git a/chrome/browser/ui/views/infobars/translate_message_infobar.h b/chrome/browser/ui/views/infobars/translate_message_infobar.h
index a29122d..a503df5 100644
--- a/chrome/browser/ui/views/infobars/translate_message_infobar.h
+++ b/chrome/browser/ui/views/infobars/translate_message_infobar.h
@@ -8,8 +8,6 @@
#include "chrome/browser/ui/views/infobars/translate_infobar_base.h"
-class InfoBarTextButton;
-
class TranslateMessageInfoBar : public TranslateInfoBarBase {
public:
explicit TranslateMessageInfoBar(TranslateInfoBarDelegate* delegate);
@@ -22,7 +20,7 @@ class TranslateMessageInfoBar : public TranslateInfoBarBase {
virtual void ButtonPressed(views::Button* sender, const views::Event& event);
views::Label* label_;
- InfoBarTextButton* button_;
+ views::TextButton* button_;
DISALLOW_COPY_AND_ASSIGN(TranslateMessageInfoBar);
};