summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r--chrome/browser/ui/browser.cc2
-rw-r--r--chrome/browser/ui/browser_init.cc6
-rw-r--r--chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm2
-rw-r--r--chrome/browser/ui/cocoa/infobars/infobar_test_helper.h4
-rw-r--r--chrome/browser/ui/cocoa/keystone_infobar.mm2
-rw-r--r--chrome/browser/ui/cocoa/tabpose_window.mm4
-rw-r--r--chrome/browser/ui/cocoa/translate/translate_infobar_base.mm20
-rw-r--r--chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc8
-rw-r--r--chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.cc8
-rw-r--r--chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.h4
-rw-r--r--chrome/browser/ui/gtk/translate/before_translate_infobar_gtk.cc2
-rw-r--r--chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.cc14
-rw-r--r--chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.h17
-rw-r--r--chrome/browser/ui/views/extensions/extension_view.cc3
-rw-r--r--chrome/browser/ui/views/infobars/after_translate_infobar.cc117
-rw-r--r--chrome/browser/ui/views/infobars/after_translate_infobar.h26
-rw-r--r--chrome/browser/ui/views/infobars/before_translate_infobar.cc135
-rw-r--r--chrome/browser/ui/views/infobars/before_translate_infobar.h22
-rw-r--r--chrome/browser/ui/views/infobars/confirm_infobar.cc99
-rw-r--r--chrome/browser/ui/views/infobars/confirm_infobar.h23
-rw-r--r--chrome/browser/ui/views/infobars/extension_infobar.cc153
-rw-r--r--chrome/browser/ui/views/infobars/extension_infobar.h42
-rw-r--r--chrome/browser/ui/views/infobars/infobar_background.cc32
-rw-r--r--chrome/browser/ui/views/infobars/infobar_background.h9
-rw-r--r--chrome/browser/ui/views/infobars/infobar_button_border.cc64
-rw-r--r--chrome/browser/ui/views/infobars/infobar_button_border.h12
-rw-r--r--chrome/browser/ui/views/infobars/infobar_container.cc12
-rw-r--r--chrome/browser/ui/views/infobars/infobar_container.h8
-rw-r--r--chrome/browser/ui/views/infobars/infobar_view.cc254
-rw-r--r--chrome/browser/ui/views/infobars/infobar_view.h94
-rw-r--r--chrome/browser/ui/views/infobars/link_infobar.cc58
-rw-r--r--chrome/browser/ui/views/infobars/link_infobar.h13
-rw-r--r--chrome/browser/ui/views/infobars/translate_infobar_base.cc157
-rw-r--r--chrome/browser/ui/views/infobars/translate_infobar_base.h43
-rw-r--r--chrome/browser/ui/views/infobars/translate_message_infobar.cc39
-rw-r--r--chrome/browser/ui/views/infobars/translate_message_infobar.h7
36 files changed, 663 insertions, 852 deletions
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index d5bffbc..fa9a5cbb 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -3344,7 +3344,7 @@ void Browser::Observe(NotificationType type,
TabStripModel* model = tab_handler_->GetTabStripModel();
for (int m = 0; m < model->count(); ++m) {
TabContents* tab_contents = model->GetTabContentsAt(m)->tab_contents();
- for (int i = 0; i < tab_contents->infobar_delegate_count(); ) {
+ for (size_t i = 0; i < tab_contents->infobar_count(); ) {
CrashedExtensionInfoBarDelegate* delegate = tab_contents->
GetInfoBarDelegateAt(i)->AsCrashedExtensionInfoBarDelegate();
if (delegate && delegate->extension_id() == extension->id())
diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc
index ed30dff..f062f37 100644
--- a/chrome/browser/ui/browser_init.cc
+++ b/chrome/browser/ui/browser_init.cc
@@ -148,7 +148,6 @@ class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual bool Accept();
virtual bool Cancel();
- private:
// The Profile that we restore sessions from.
Profile* profile_;
@@ -256,7 +255,7 @@ void NotifyNotDefaultBrowserTask::Run() {
// In ChromeBot tests, there might be a race. This line appears to get
// called during shutdown and |tab| can be NULL.
TabContents* tab = browser->GetSelectedTabContents();
- if (!tab || tab->infobar_delegate_count() > 0)
+ if (!tab || tab->infobar_count() > 0)
return;
tab->AddInfoBar(new DefaultBrowserInfoBarDelegate(tab));
}
@@ -295,8 +294,7 @@ void CheckDefaultBrowserTask::Run() {
// SessionCrashedInfoBarDelegate ----------------------------------------------
-// A delegate for the InfoBar shown when the previous session has crashed. The
-// bar deletes itself automatically after it is closed.
+// A delegate for the InfoBar shown when the previous session has crashed.
class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
explicit SessionCrashedInfoBarDelegate(TabContents* contents);
diff --git a/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm b/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm
index 68562a9..3d65217 100644
--- a/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm
+++ b/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm
@@ -126,7 +126,7 @@ class InfoBarNotificationObserver : public NotificationObserver {
currentTabContents_ = contents;
if (currentTabContents_) {
- for (int i = 0; i < currentTabContents_->infobar_delegate_count(); ++i) {
+ for (size_t i = 0; i < currentTabContents_->infobar_count(); ++i) {
[self addInfoBar:currentTabContents_->GetInfoBarDelegateAt(i)
animate:NO];
}
diff --git a/chrome/browser/ui/cocoa/infobars/infobar_test_helper.h b/chrome/browser/ui/cocoa/infobars/infobar_test_helper.h
index e14e0dd..aca76f9 100644
--- a/chrome/browser/ui/cocoa/infobars/infobar_test_helper.h
+++ b/chrome/browser/ui/cocoa/infobars/infobar_test_helper.h
@@ -28,7 +28,7 @@ class MockLinkInfoBarDelegate : public LinkInfoBarDelegate {
static const char kLink[];
private:
- // LinkInfoBarDelegate
+ // LinkInfoBarDelegate:
virtual void InfoBarClosed();
virtual SkBitmap* GetIcon() const;
virtual string16 GetMessageTextWithOffset(size_t* link_offset) const;
@@ -68,7 +68,7 @@ class MockConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
static const char kMessage[];
private:
- // ConfirmInfoBarDelegate
+ // ConfirmInfoBarDelegate:
virtual void InfoBarClosed();
virtual SkBitmap* GetIcon() const;
virtual string16 GetMessageText() const;
diff --git a/chrome/browser/ui/cocoa/keystone_infobar.mm b/chrome/browser/ui/cocoa/keystone_infobar.mm
index ff910bd..7b2c235 100644
--- a/chrome/browser/ui/cocoa/keystone_infobar.mm
+++ b/chrome/browser/ui/cocoa/keystone_infobar.mm
@@ -195,7 +195,7 @@ bool KeystonePromotionInfoBarDelegate::Cancel() {
// Only show if no other info bars are showing, because that's how the
// default browser info bar works.
- if (tabContents && tabContents->infobar_delegate_count() == 0) {
+ if (tabContents && tabContents->infobar_count() == 0) {
tabContents->AddInfoBar(
new KeystonePromotionInfoBarDelegate(tabContents));
}
diff --git a/chrome/browser/ui/cocoa/tabpose_window.mm b/chrome/browser/ui/cocoa/tabpose_window.mm
index 41283b8..22aa6ad 100644
--- a/chrome/browser/ui/cocoa/tabpose_window.mm
+++ b/chrome/browser/ui/cocoa/tabpose_window.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -189,7 +189,7 @@ void ThumbnailLoader::LoadThumbnail() {
// means I need to create InfoBarControllers here. At that point, we can get
// the height from that controller. Until then, hardcode. :-/
const int kInfoBarHeight = 31;
- topOffset += contents_->infobar_delegate_count() * kInfoBarHeight;
+ topOffset += contents_->infobar_count() * kInfoBarHeight;
bool always_show_bookmark_bar =
contents_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
diff --git a/chrome/browser/ui/cocoa/translate/translate_infobar_base.mm b/chrome/browser/ui/cocoa/translate/translate_infobar_base.mm
index 4b94e89..5cac0a9 100644
--- a/chrome/browser/ui/cocoa/translate/translate_infobar_base.mm
+++ b/chrome/browser/ui/cocoa/translate/translate_infobar_base.mm
@@ -216,20 +216,22 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
}
- (void)sourceLanguageModified:(NSInteger)newLanguageIdx {
- DCHECK_GT(newLanguageIdx, -1);
- if (newLanguageIdx == [self delegate]->original_language_index())
+ size_t newLanguageIdxSizeT = static_cast<size_t>(newLanguageIdx);
+ DCHECK_NE(TranslateInfoBarDelegate::kNoIndex, newLanguageIdxSizeT);
+ if (newLanguageIdxSizeT == [self delegate]->original_language_index())
return;
- [self delegate]->SetOriginalLanguage(newLanguageIdx);
+ [self delegate]->SetOriginalLanguage(newLanguageIdxSizeT);
int commandId = IDC_TRANSLATE_ORIGINAL_LANGUAGE_BASE + newLanguageIdx;
int newMenuIdx = [fromLanguagePopUp_ indexOfItemWithTag:commandId];
[fromLanguagePopUp_ selectItemAtIndex:newMenuIdx];
}
- (void)targetLanguageModified:(NSInteger)newLanguageIdx {
- DCHECK_GT(newLanguageIdx, -1);
- if (newLanguageIdx == [self delegate]->target_language_index())
+ size_t newLanguageIdxSizeT = static_cast<size_t>(newLanguageIdx);
+ DCHECK_NE(TranslateInfoBarDelegate::kNoIndex, newLanguageIdxSizeT);
+ if (newLanguageIdxSizeT == [self delegate]->target_language_index())
return;
- [self delegate]->SetTargetLanguage(newLanguageIdx);
+ [self delegate]->SetTargetLanguage(newLanguageIdxSizeT);
int commandId = IDC_TRANSLATE_TARGET_LANGUAGE_BASE + newLanguageIdx;
int newMenuIdx = [toLanguagePopUp_ indexOfItemWithTag:commandId];
[toLanguagePopUp_ selectItemAtIndex:newMenuIdx];
@@ -355,7 +357,8 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
NSMenu* originalLanguageMenu = [fromLanguagePopUp_ menu];
[originalLanguageMenu setAutoenablesItems:NO];
int selectedMenuIndex = 0;
- int selectedLangIndex = [self delegate]->original_language_index();
+ int selectedLangIndex =
+ static_cast<int>([self delegate]->original_language_index());
for (int i = 0; i < originalLanguageMenuModel_->GetItemCount(); ++i) {
NSString* title = base::SysUTF16ToNSString(
originalLanguageMenuModel_->GetLabelAt(i));
@@ -377,7 +380,8 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
NSMenu* targetLanguageMenu = [toLanguagePopUp_ menu];
[targetLanguageMenu setAutoenablesItems:NO];
- selectedLangIndex = [self delegate]->target_language_index();
+ selectedLangIndex =
+ static_cast<int>([self delegate]->target_language_index());
for (int i = 0; i < targetLanguageMenuModel_->GetItemCount(); ++i) {
NSString* title = base::SysUTF16ToNSString(
targetLanguageMenuModel_->GetLabelAt(i));
diff --git a/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc b/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc
index a0b7376..e1a3608 100644
--- a/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc
+++ b/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc
@@ -139,7 +139,7 @@ void InfoBarContainerGtk::Observe(NotificationType type,
// InfoBarContainerGtk, private: -----------------------------------------------
void InfoBarContainerGtk::UpdateInfoBars() {
- for (int i = 0; i < tab_contents_->infobar_delegate_count(); ++i) {
+ for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) {
InfoBarDelegate* delegate = tab_contents_->GetInfoBarDelegateAt(i);
AddInfoBar(delegate, false);
}
@@ -201,7 +201,7 @@ void InfoBarContainerGtk::RemoveInfoBar(InfoBarDelegate* delegate,
}
InfoBarDelegate* next_delegate = NULL;
- for (int i = 1; i < tab_contents_->infobar_delegate_count(); ++i) {
+ for (size_t i = 1; i < tab_contents_->infobar_count(); ++i) {
if (tab_contents_->GetInfoBarDelegateAt(i - 1) == delegate) {
next_delegate = tab_contents_->GetInfoBarDelegateAt(i);
break;
@@ -211,8 +211,8 @@ void InfoBarContainerGtk::RemoveInfoBar(InfoBarDelegate* delegate,
ShowArrowForDelegate(next_delegate, animate);
}
-void InfoBarContainerGtk::UpdateToolbarInfoBarState(
- InfoBar* infobar, bool animate) {
+void InfoBarContainerGtk::UpdateToolbarInfoBarState(InfoBar* infobar,
+ bool animate) {
GtkWindow* parent = platform_util::GetTopLevel(widget());
BrowserWindowGtk* browser_window =
BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent);
diff --git a/chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.cc b/chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.cc
index 4b6f489..3eeec4e 100644
--- a/chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.cc
+++ b/chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.cc
@@ -69,7 +69,7 @@ bool AfterTranslateInfoBar::ShowOptionsMenuButton() const {
}
void AfterTranslateInfoBar::OnOriginalLanguageModified(GtkWidget* sender) {
- int index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender));
+ size_t index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender));
if (index == GetDelegate()->original_language_index())
return;
@@ -81,7 +81,7 @@ void AfterTranslateInfoBar::OnOriginalLanguageModified(GtkWidget* sender) {
}
void AfterTranslateInfoBar::OnTargetLanguageModified(GtkWidget* sender) {
- int index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender));
+ size_t index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender));
if (index == GetDelegate()->target_language_index())
return;
@@ -94,10 +94,10 @@ void AfterTranslateInfoBar::OnRevertPressed(GtkWidget* sender) {
GetDelegate()->RevertTranslation();
}
-void AfterTranslateInfoBar::SetOriginalLanguage(int language_index) {
+void AfterTranslateInfoBar::SetOriginalLanguage(size_t language_index) {
GetDelegate()->SetOriginalLanguage(language_index);
}
-void AfterTranslateInfoBar::SetTargetLanguage(int language_index) {
+void AfterTranslateInfoBar::SetTargetLanguage(size_t language_index) {
GetDelegate()->SetTargetLanguage(language_index);
}
diff --git a/chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.h b/chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.h
index 201a4c0..0f5d5fe 100644
--- a/chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.h
+++ b/chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.h
@@ -29,8 +29,8 @@ class AfterTranslateInfoBar : public TranslateInfoBarBase {
// These methods set the original/target language on the
// TranslateInfobarDelegate.
- void SetOriginalLanguage(int language_index);
- void SetTargetLanguage(int language_index);
+ void SetOriginalLanguage(size_t language_index);
+ void SetTargetLanguage(size_t language_index);
ScopedRunnableMethodFactory<AfterTranslateInfoBar> method_factory_;
diff --git a/chrome/browser/ui/gtk/translate/before_translate_infobar_gtk.cc b/chrome/browser/ui/gtk/translate/before_translate_infobar_gtk.cc
index 20a14c7..c3cdc12 100644
--- a/chrome/browser/ui/gtk/translate/before_translate_infobar_gtk.cc
+++ b/chrome/browser/ui/gtk/translate/before_translate_infobar_gtk.cc
@@ -80,7 +80,7 @@ bool BeforeTranslateInfoBar::ShowOptionsMenuButton() const {
}
void BeforeTranslateInfoBar::OnLanguageModified(GtkWidget* sender) {
- int index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender));
+ size_t index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender));
if (index == GetDelegate()->original_language_index())
return;
diff --git a/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.cc b/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.cc
index 9457ae6..5b0182c 100644
--- a/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.cc
+++ b/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.cc
@@ -134,14 +134,15 @@ GtkWidget* TranslateInfoBarBase::CreateLabel(const std::string& text) {
return label;
}
-GtkWidget* TranslateInfoBarBase::CreateLanguageCombobox(int selected_language,
- int exclude_language) {
+GtkWidget* TranslateInfoBarBase::CreateLanguageCombobox(
+ size_t selected_language,
+ size_t exclude_language) {
GtkListStore* model = gtk_list_store_new(LANGUAGE_COMBO_COLUMN_COUNT,
G_TYPE_INT, G_TYPE_STRING);
bool set_selection = false;
GtkTreeIter selected_iter;
TranslateInfoBarDelegate* delegate = GetDelegate();
- for (int i = 0; i < delegate->GetLanguageCount(); ++i) {
+ for (size_t i = 0; i < delegate->GetLanguageCount(); ++i) {
if (i == exclude_language)
continue;
GtkTreeIter tree_iter;
@@ -171,7 +172,7 @@ GtkWidget* TranslateInfoBarBase::CreateLanguageCombobox(int selected_language,
}
// static
-int TranslateInfoBarBase::GetLanguageComboboxActiveId(GtkComboBox* combo) {
+size_t TranslateInfoBarBase::GetLanguageComboboxActiveId(GtkComboBox* combo) {
GtkTreeIter iter;
if (!gtk_combo_box_get_active_iter(combo, &iter))
return 0;
@@ -180,7 +181,7 @@ int TranslateInfoBarBase::GetLanguageComboboxActiveId(GtkComboBox* combo) {
gtk_tree_model_get(gtk_combo_box_get_model(combo), &iter,
LANGUAGE_COMBO_COLUMN_ID, &id,
-1);
- return id;
+ return static_cast<size_t>(id);
}
TranslateInfoBarDelegate* TranslateInfoBarBase::GetDelegate() const {
@@ -234,8 +235,5 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
NOTREACHED();
}
infobar->Init();
- // Set |infobar_view_| so that the model can notify the infobar when it
- // changes.
- infobar_view_ = infobar;
return infobar;
}
diff --git a/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.h b/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.h
index 65b6488..f35ffd5 100644
--- a/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.h
+++ b/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.h
@@ -6,7 +6,6 @@
#define CHROME_BROWSER_UI_GTK_TRANSLATE_TRANSLATE_INFOBAR_BASE_GTK_H_
#pragma once
-#include "chrome/browser/translate/translate_infobar_view.h"
#include "chrome/browser/ui/gtk/infobars/infobar_gtk.h"
#include "ui/base/animation/animation_delegate.h"
@@ -16,8 +15,7 @@ class TranslateInfoBarDelegate;
// This class contains some of the base functionality that translate infobars
// use.
-class TranslateInfoBarBase : public TranslateInfoBarView,
- public InfoBar,
+class TranslateInfoBarBase : public InfoBar,
public ui::AnimationDelegate {
public:
explicit TranslateInfoBarBase(TranslateInfoBarDelegate* delegate);
@@ -33,10 +31,6 @@ class TranslateInfoBarBase : public TranslateInfoBarView,
virtual void GetBottomColor(InfoBarDelegate::Type type,
double* r, double* g, double *b);
- // Overridden from TranslateInfoBarView:
- virtual void OriginalLanguageChanged() {}
- virtual void TargetLanguageChanged() {}
-
// Overridden from ui::AnimationDelegate:
virtual void AnimationProgressed(const ui::Animation* animation);
@@ -53,13 +47,14 @@ class TranslateInfoBarBase : public TranslateInfoBarView,
// |selected_language| is the language index (as used in the
// TranslateInfoBarDelegate) that should be selected initially.
// |exclude_language| is the language index of the language that should not be
- // included in the list (-1 means no language excluded).
- GtkWidget* CreateLanguageCombobox(int selected_language,
- int exclude_language);
+ // included in the list (TranslateInfoBarDelegate::kNoIndex means no language
+ // excluded).
+ GtkWidget* CreateLanguageCombobox(size_t selected_language,
+ size_t exclude_language);
// Given an above-constructed combobox, returns the currently selected
// language id.
- static int GetLanguageComboboxActiveId(GtkComboBox* combo);
+ static size_t GetLanguageComboboxActiveId(GtkComboBox* combo);
// Convenience to retrieve the TranslateInfoBarDelegate for this infobar.
TranslateInfoBarDelegate* GetDelegate() const;
diff --git a/chrome/browser/ui/views/extensions/extension_view.cc b/chrome/browser/ui/views/extensions/extension_view.cc
index 9fa7603..d6ff1c4 100644
--- a/chrome/browser/ui/views/extensions/extension_view.cc
+++ b/chrome/browser/ui/views/extensions/extension_view.cc
@@ -171,9 +171,8 @@ void ExtensionView::ViewHierarchyChanged(bool is_add,
void ExtensionView::PreferredSizeChanged() {
View::PreferredSizeChanged();
- if (container_) {
+ if (container_)
container_->OnExtensionPreferredSizeChanged(this);
- }
}
bool ExtensionView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) {
diff --git a/chrome/browser/ui/views/infobars/after_translate_infobar.cc b/chrome/browser/ui/views/infobars/after_translate_infobar.cc
index b7eea3d..5a91252 100644
--- a/chrome/browser/ui/views/infobars/after_translate_infobar.cc
+++ b/chrome/browser/ui/views/infobars/after_translate_infobar.cc
@@ -26,34 +26,34 @@ AfterTranslateInfoBar::AfterTranslateInfoBar(
options_menu_model_(delegate),
swapped_language_buttons_(false) {
std::vector<string16> strings;
- TranslateInfoBarDelegate::GetAfterTranslateStrings(
- &strings, &swapped_language_buttons_);
- DCHECK(strings.size() == 3U);
+ GetDelegate()->GetAfterTranslateStrings(&strings, &swapped_language_buttons_);
+ DCHECK_EQ(3U, strings.size());
label_1_ = CreateLabel(strings[0]);
AddChildView(label_1_);
+ original_language_menu_button_ = CreateMenuButton(string16(), true, this);
+ target_language_menu_button_ = CreateMenuButton(string16(), true, this);
+ AddChildView(swapped_language_buttons_ ?
+ target_language_menu_button_ : original_language_menu_button_);
+
label_2_ = CreateLabel(strings[1]);
AddChildView(label_2_);
+ AddChildView(swapped_language_buttons_ ?
+ original_language_menu_button_ : target_language_menu_button_);
+
label_3_ = CreateLabel(strings[2]);
AddChildView(label_3_);
- original_language_menu_button_ = CreateMenuButton(string16(), true, this);
- AddChildView(original_language_menu_button_);
-
- target_language_menu_button_ = CreateMenuButton(string16(), true, this);
- AddChildView(target_language_menu_button_);
-
- options_menu_button_ =
- CreateMenuButton(l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS),
- false, this);
- AddChildView(options_menu_button_);
-
revert_button_ = InfoBarTextButton::Create(this,
l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_REVERT));
AddChildView(revert_button_);
+ options_menu_button_ = CreateMenuButton(
+ l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS), false, this);
+ AddChildView(options_menu_button_);
+
UpdateLanguageButtonText(LanguagesMenuModel::ORIGINAL);
UpdateLanguageButtonText(LanguagesMenuModel::TARGET);
}
@@ -61,51 +61,44 @@ AfterTranslateInfoBar::AfterTranslateInfoBar(
AfterTranslateInfoBar::~AfterTranslateInfoBar() {
}
-// Overridden from views::View:
void AfterTranslateInfoBar::Layout() {
- // Layout the icon and close button.
TranslateInfoBarBase::Layout();
- // Layout the options menu button on right of bar.
- int available_width = InfoBarView::GetAvailableWidth();
- gfx::Size pref_size = options_menu_button_->GetPreferredSize();
- options_menu_button_->SetBounds(available_width - pref_size.width(),
- OffsetY(this, pref_size), pref_size.width(), pref_size.height());
-
- views::MenuButton* left_button = swapped_language_buttons_ ?
- target_language_menu_button_ : original_language_menu_button_;
- views::MenuButton* right_button = swapped_language_buttons_ ?
- original_language_menu_button_ : target_language_menu_button_;
-
- pref_size = label_1_->GetPreferredSize();
- label_1_->SetBounds(icon_->bounds().right() + InfoBarView::kIconLabelSpacing,
- InfoBarView::OffsetY(this, pref_size), pref_size.width(),
- pref_size.height());
-
- pref_size = left_button->GetPreferredSize();
- left_button->SetBounds(label_1_->bounds().right() +
- InfoBarView::kButtonInLabelSpacing, OffsetY(this, pref_size),
- pref_size.width(), pref_size.height());
-
- pref_size = label_2_->GetPreferredSize();
- label_2_->SetBounds(left_button->bounds().right() +
- InfoBarView::kButtonInLabelSpacing, InfoBarView::OffsetY(this, pref_size),
- pref_size.width(), pref_size.height());
-
- pref_size = right_button->GetPreferredSize();
- right_button->SetBounds(label_2_->bounds().right() +
- InfoBarView::kButtonInLabelSpacing, OffsetY(this, pref_size),
- pref_size.width(), pref_size.height());
-
- pref_size = label_3_->GetPreferredSize();
- label_3_->SetBounds(right_button->bounds().right() +
- InfoBarView::kButtonInLabelSpacing, InfoBarView::OffsetY(this, pref_size),
- pref_size.width(), pref_size.height());
-
- pref_size = revert_button_->GetPreferredSize();
- revert_button_->SetBounds(label_3_->bounds().right() +
- InfoBarView::kButtonInLabelSpacing, InfoBarView::OffsetY(this, pref_size),
- pref_size.width(), pref_size.height());
+ int available_width = GetAvailableWidth();
+ gfx::Size label_1_size = label_1_->GetPreferredSize();
+ label_1_->SetBounds(icon_->bounds().right() + kIconLabelSpacing,
+ OffsetY(this, label_1_size), label_1_size.width(), label_1_size.height());
+
+ views::MenuButton* first_button = original_language_menu_button_;
+ views::MenuButton* second_button = target_language_menu_button_;
+ if (swapped_language_buttons_)
+ std::swap(first_button, second_button);
+ gfx::Size first_button_size = first_button->GetPreferredSize();
+ first_button->SetBounds(label_1_->bounds().right() + kButtonInLabelSpacing,
+ OffsetY(this, first_button_size), first_button_size.width(),
+ first_button_size.height());
+
+ gfx::Size label_2_size = label_2_->GetPreferredSize();
+ label_2_->SetBounds(first_button->bounds().right() + kButtonInLabelSpacing,
+ OffsetY(this, label_2_size), label_2_size.width(), label_2_size.height());
+
+ gfx::Size second_button_size = second_button->GetPreferredSize();
+ second_button->SetBounds(label_2_->bounds().right() + kButtonInLabelSpacing,
+ OffsetY(this, second_button_size), second_button_size.width(),
+ second_button_size.height());
+
+ gfx::Size label_3_size = label_3_->GetPreferredSize();
+ label_3_->SetBounds(second_button->bounds().right() + kButtonInLabelSpacing,
+ OffsetY(this, label_3_size), label_3_size.width(), label_3_size.height());
+
+ gfx::Size revert_button_size = revert_button_->GetPreferredSize();
+ revert_button_->SetBounds(label_3_->bounds().right() + kButtonInLabelSpacing,
+ OffsetY(this, revert_button_size),
+ revert_button_size.width(), revert_button_size.height());
+
+ gfx::Size options_size = options_menu_button_->GetPreferredSize();
+ options_menu_button_->SetBounds(available_width - options_size.width(),
+ OffsetY(this, options_size), options_size.width(), options_size.height());
}
void AfterTranslateInfoBar::OriginalLanguageChanged() {
@@ -118,11 +111,10 @@ void AfterTranslateInfoBar::TargetLanguageChanged() {
void AfterTranslateInfoBar::ButtonPressed(views::Button* sender,
const views::Event& event) {
- if (sender == revert_button_) {
+ if (sender == revert_button_)
GetDelegate()->RevertTranslation();
- return;
- }
- TranslateInfoBarBase::ButtonPressed(sender, event);
+ else
+ TranslateInfoBarBase::ButtonPressed(sender, event);
}
void AfterTranslateInfoBar::RunMenu(views::View* source,
@@ -139,12 +131,11 @@ void AfterTranslateInfoBar::RunMenu(views::View* source,
new views::Menu2(&target_language_menu_model_));
}
target_language_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
- } else if (source == options_menu_button_) {
+ } else {
+ DCHECK_EQ(options_menu_button_, source);
if (!options_menu_.get())
options_menu_.reset(new views::Menu2(&options_menu_model_));
options_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
- } else {
- NOTREACHED();
}
}
diff --git a/chrome/browser/ui/views/infobars/after_translate_infobar.h b/chrome/browser/ui/views/infobars/after_translate_infobar.h
index 0ee237a..977e629 100644
--- a/chrome/browser/ui/views/infobars/after_translate_infobar.h
+++ b/chrome/browser/ui/views/infobars/after_translate_infobar.h
@@ -8,15 +8,11 @@
#include "chrome/browser/translate/languages_menu_model.h"
#include "chrome/browser/translate/options_menu_model.h"
-#include "chrome/browser/translate/translate_infobar_view.h"
#include "chrome/browser/ui/views/infobars/translate_infobar_base.h"
-#include "views/controls/button/button.h"
-#include "views/controls/link.h"
#include "views/controls/menu/view_menu_delegate.h"
class InfoBarTextButton;
class TranslateInfoBarDelegate;
-
namespace views {
class Menu2;
class MenuButton;
@@ -26,31 +22,27 @@ class AfterTranslateInfoBar : public TranslateInfoBarBase,
public views::ViewMenuDelegate {
public:
explicit AfterTranslateInfoBar(TranslateInfoBarDelegate* delegate);
+
+ private:
virtual ~AfterTranslateInfoBar();
- // Overridden from views::View:
+ // TranslateInfoBarBase:
virtual void Layout();
-
- // Overridden from TranslateInfoBarView:
+ virtual void ButtonPressed(views::Button* sender, const views::Event& event);
virtual void OriginalLanguageChanged();
virtual void TargetLanguageChanged();
- // Overridden from views::ButtonListener:
- virtual void ButtonPressed(views::Button* sender, const views::Event& event);
-
- protected:
- // Overridden from views::ViewMenuDelegate:
+ // views::ViewMenuDelegate:
virtual void RunMenu(View* source, const gfx::Point& pt);
- private:
// Sets the text of the original or target language menu buttons to reflect
// the current value from the delegate.
void UpdateLanguageButtonText(LanguagesMenuModel::LanguageType language);
// The text displayed in the infobar is something like:
- // "Translated from <lang1> to <lang2>"
- // Where <lang1> and <lang2> are displayed in a combobox.
- // So the text is split in 3 chunks, each one displayed in one of the label
+ // "Translated from <lang1> to <lang2> [more text in some languages]"
+ // ...where <lang1> and <lang2> are comboboxes.
+ // So the text is split in 3 chunks, each one displayed in one of the labels
// below.
views::Label* label_1_;
views::Label* label_2_;
@@ -58,8 +50,8 @@ class AfterTranslateInfoBar : public TranslateInfoBarBase,
views::MenuButton* original_language_menu_button_;
views::MenuButton* target_language_menu_button_;
- views::MenuButton* options_menu_button_;
InfoBarTextButton* revert_button_;
+ views::MenuButton* options_menu_button_;
scoped_ptr<views::Menu2> original_language_menu_;
LanguagesMenuModel original_language_menu_model_;
diff --git a/chrome/browser/ui/views/infobars/before_translate_infobar.cc b/chrome/browser/ui/views/infobars/before_translate_infobar.cc
index cb35426..0159cb4 100644
--- a/chrome/browser/ui/views/infobars/before_translate_infobar.cc
+++ b/chrome/browser/ui/views/infobars/before_translate_infobar.cc
@@ -12,6 +12,7 @@
#include "ui/base/l10n/l10n_util.h"
#include "views/controls/button/menu_button.h"
#include "views/controls/image_view.h"
+#include "views/controls/label.h"
#include "views/controls/menu/menu_2.h"
BeforeTranslateInfoBar::BeforeTranslateInfoBar(
@@ -22,118 +23,111 @@ BeforeTranslateInfoBar::BeforeTranslateInfoBar(
languages_menu_model_(delegate, LanguagesMenuModel::ORIGINAL),
options_menu_model_(delegate) {
size_t offset = 0;
- string16 text =
- l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE,
- string16(), &offset);
+ string16 text(l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE,
+ string16(), &offset));
label_1_ = CreateLabel(text.substr(0, offset));
AddChildView(label_1_);
+ language_menu_button_ = CreateMenuButton(string16(), true, this);
+ AddChildView(language_menu_button_);
+
label_2_ = CreateLabel(text.substr(offset));
AddChildView(label_2_);
- accept_button_ =
- InfoBarTextButton::CreateWithMessageID(this,
- IDS_TRANSLATE_INFOBAR_ACCEPT);
+ accept_button_ = InfoBarTextButton::CreateWithMessageID(this,
+ IDS_TRANSLATE_INFOBAR_ACCEPT);
AddChildView(accept_button_);
- deny_button_ =
- InfoBarTextButton::CreateWithMessageID(this,
- IDS_TRANSLATE_INFOBAR_DENY);
+ deny_button_ = InfoBarTextButton::CreateWithMessageID(this,
+ IDS_TRANSLATE_INFOBAR_DENY);
AddChildView(deny_button_);
- language_menu_button_ = CreateMenuButton(string16(), true, this);
- AddChildView(language_menu_button_);
-
- options_menu_button_ =
- CreateMenuButton(l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS),
- false, this);
- AddChildView(options_menu_button_);
-
+ const string16& language(delegate->GetLanguageDisplayableNameAt(
+ delegate->original_language_index()));
if (delegate->ShouldShowNeverTranslateButton()) {
- const string16& language = delegate->GetLanguageDisplayableNameAt(
- delegate->original_language_index());
never_translate_button_ = InfoBarTextButton::CreateWithMessageIDAndParam(
this, IDS_TRANSLATE_INFOBAR_NEVER_TRANSLATE, language);
AddChildView(never_translate_button_);
- }
-
- if (delegate->ShouldShowAlwaysTranslateButton()) {
- const string16& language = delegate->GetLanguageDisplayableNameAt(
- delegate->original_language_index());
+ } else if (delegate->ShouldShowAlwaysTranslateButton()) {
always_translate_button_ = InfoBarTextButton::CreateWithMessageIDAndParam(
this, IDS_TRANSLATE_INFOBAR_ALWAYS_TRANSLATE, language);
AddChildView(always_translate_button_);
}
+ options_menu_button_ = CreateMenuButton(
+ l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS), false, this);
+ AddChildView(options_menu_button_);
+
UpdateOriginalButtonText();
}
BeforeTranslateInfoBar::~BeforeTranslateInfoBar() {
}
-// Overridden from views::View:
void BeforeTranslateInfoBar::Layout() {
- // Layout the icon and close button.
TranslateInfoBarBase::Layout();
- // Layout the options menu button on right of bar.
- int available_width = InfoBarView::GetAvailableWidth();
- gfx::Size pref_size = options_menu_button_->GetPreferredSize();
- options_menu_button_->SetBounds(available_width - pref_size.width(),
- OffsetY(this, pref_size), pref_size.width(), pref_size.height());
-
- pref_size = label_1_->GetPreferredSize();
- label_1_->SetBounds(icon_->bounds().right() + InfoBarView::kIconLabelSpacing,
- InfoBarView::OffsetY(this, pref_size), pref_size.width(),
- pref_size.height());
-
- pref_size = language_menu_button_->GetPreferredSize();
- language_menu_button_->SetBounds(label_1_->bounds().right() +
- InfoBarView::kButtonInLabelSpacing, OffsetY(this, pref_size),
- pref_size.width(), pref_size.height());
-
- pref_size = label_2_->GetPreferredSize();
- label_2_->SetBounds(language_menu_button_->bounds().right() +
- InfoBarView::kButtonInLabelSpacing, InfoBarView::OffsetY(this, pref_size),
- pref_size.width(), pref_size.height());
-
- pref_size = accept_button_->GetPreferredSize();
- accept_button_->SetBounds(
- label_2_->bounds().right() + InfoBarView::kEndOfLabelSpacing,
- OffsetY(this, pref_size), pref_size.width(), pref_size.height());
-
- pref_size = deny_button_->GetPreferredSize();
+ int available_width = GetAvailableWidth();
+ gfx::Size label_1_size = label_1_->GetPreferredSize();
+ label_1_->SetBounds(icon_->bounds().right() + kIconLabelSpacing,
+ OffsetY(this, label_1_size), label_1_size.width(), label_1_size.height());
+
+ gfx::Size language_button_size = language_menu_button_->GetPreferredSize();
+ language_menu_button_->SetBounds(
+ label_1_->bounds().right() + kButtonInLabelSpacing,
+ OffsetY(this, language_button_size), language_button_size.width(),
+ language_button_size.height());
+
+ gfx::Size label_2_size = label_2_->GetPreferredSize();
+ label_2_->SetBounds(
+ language_menu_button_->bounds().right() + kButtonInLabelSpacing,
+ OffsetY(this, label_2_size), label_2_size.width(), label_2_size.height());
+
+ gfx::Size accept_button_size = accept_button_->GetPreferredSize();
+ accept_button_->SetBounds(label_2_->bounds().right() + kEndOfLabelSpacing,
+ OffsetY(this, accept_button_size), accept_button_size.width(),
+ accept_button_size.height());
+
+ gfx::Size deny_button_size = deny_button_->GetPreferredSize();
deny_button_->SetBounds(
- accept_button_->bounds().right() + InfoBarView::kButtonButtonSpacing,
- OffsetY(this, pref_size), pref_size.width(), pref_size.height());
+ accept_button_->bounds().right() + kButtonButtonSpacing,
+ OffsetY(this, deny_button_size), deny_button_size.width(),
+ deny_button_size.height());
if (never_translate_button_) {
- pref_size = never_translate_button_->GetPreferredSize();
+ gfx::Size never_button_size = never_translate_button_->GetPreferredSize();
never_translate_button_->SetBounds(
- deny_button_->bounds().right() + InfoBarView::kButtonButtonSpacing,
- OffsetY(this, pref_size), pref_size.width(), pref_size.height());
+ deny_button_->bounds().right() + kButtonButtonSpacing,
+ OffsetY(this, never_button_size), never_button_size.width(),
+ never_button_size.height());
}
+
if (always_translate_button_) {
- DCHECK(!never_translate_button_);
- pref_size = always_translate_button_->GetPreferredSize();
+ gfx::Size always_button_size = always_translate_button_->GetPreferredSize();
always_translate_button_->SetBounds(
- deny_button_->bounds().right() + InfoBarView::kButtonButtonSpacing,
- OffsetY(this, pref_size), pref_size.width(), pref_size.height());
+ deny_button_->bounds().right() + kButtonButtonSpacing,
+ OffsetY(this, always_button_size), always_button_size.width(),
+ always_button_size.height());
}
+
+ gfx::Size options_size = options_menu_button_->GetPreferredSize();
+ options_menu_button_->SetBounds(available_width - options_size.width(),
+ OffsetY(this, options_size), options_size.width(), options_size.height());
}
void BeforeTranslateInfoBar::ButtonPressed(views::Button* sender,
const views::Event& event) {
+ TranslateInfoBarDelegate* delegate = GetDelegate();
if (sender == accept_button_) {
- GetDelegate()->Translate();
+ delegate->Translate();
} else if (sender == deny_button_) {
+ delegate->TranslationDeclined();
RemoveInfoBar();
- GetDelegate()->TranslationDeclined();
} else if (sender == never_translate_button_) {
- GetDelegate()->NeverTranslatePageLanguage();
+ delegate->NeverTranslatePageLanguage();
} else if (sender == always_translate_button_) {
- GetDelegate()->AlwaysTranslatePageLanguage();
+ delegate->AlwaysTranslatePageLanguage();
} else {
TranslateInfoBarBase::ButtonPressed(sender, event);
}
@@ -143,22 +137,17 @@ void BeforeTranslateInfoBar::OriginalLanguageChanged() {
UpdateOriginalButtonText();
}
-void BeforeTranslateInfoBar::TargetLanguageChanged() {
- NOTREACHED();
-}
-
void BeforeTranslateInfoBar::RunMenu(views::View* source,
const gfx::Point& pt) {
if (source == language_menu_button_) {
if (!languages_menu_.get())
languages_menu_.reset(new views::Menu2(&languages_menu_model_));
languages_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
- } else if (source == options_menu_button_) {
+ } else {
+ DCHECK_EQ(options_menu_button_, source);
if (!options_menu_.get())
options_menu_.reset(new views::Menu2(&options_menu_model_));
options_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
- } else {
- NOTREACHED();
}
}
diff --git a/chrome/browser/ui/views/infobars/before_translate_infobar.h b/chrome/browser/ui/views/infobars/before_translate_infobar.h
index 2f2c538..c0beea7 100644
--- a/chrome/browser/ui/views/infobars/before_translate_infobar.h
+++ b/chrome/browser/ui/views/infobars/before_translate_infobar.h
@@ -8,15 +8,11 @@
#include "chrome/browser/translate/languages_menu_model.h"
#include "chrome/browser/translate/options_menu_model.h"
-#include "chrome/browser/translate/translate_infobar_view.h"
#include "chrome/browser/ui/views/infobars/translate_infobar_base.h"
-#include "views/controls/button/button.h"
-#include "views/controls/link.h"
#include "views/controls/menu/view_menu_delegate.h"
class InfoBarTextButton;
class TranslateInfoBarDelegate;
-
namespace views {
class Menu2;
class MenuButton;
@@ -26,41 +22,35 @@ class BeforeTranslateInfoBar : public TranslateInfoBarBase,
public views::ViewMenuDelegate {
public:
explicit BeforeTranslateInfoBar(TranslateInfoBarDelegate* delegate);
+
+ private:
virtual ~BeforeTranslateInfoBar();
- // Overridden from views::View:
+ // TranslateInfoBarBase:
virtual void Layout();
-
- // Overridden from views::ButtonListener:
virtual void ButtonPressed(views::Button* sender, const views::Event& event);
-
- // Overridden from TranslateInfoBarView:
virtual void OriginalLanguageChanged();
- virtual void TargetLanguageChanged();
- protected:
// Overridden from views::ViewMenuDelegate:
virtual void RunMenu(View* source, const gfx::Point& pt);
- private:
// Sets the text of the original language menu button to reflect the current
// value from the delegate.
void UpdateOriginalButtonText();
// The text displayed in the infobar is something like:
// "The page is in <lang>. Would you like to translate it?"
- // Where <lang> is displayed in a combobox.
- // So the text is split in 2 chunks, each one displayed in one of the label
- // below.
+ // ...where <lang> is a combobox. So the text is split in 2 chunks, each
+ // displayed in one of the labels below.
views::Label* label_1_;
views::Label* label_2_;
views::MenuButton* language_menu_button_;
- views::MenuButton* options_menu_button_;
InfoBarTextButton* accept_button_;
InfoBarTextButton* deny_button_;
InfoBarTextButton* never_translate_button_;
InfoBarTextButton* always_translate_button_;
+ views::MenuButton* options_menu_button_;
scoped_ptr<views::Menu2> languages_menu_;
LanguagesMenuModel languages_menu_model_;
diff --git a/chrome/browser/ui/views/infobars/confirm_infobar.cc b/chrome/browser/ui/views/infobars/confirm_infobar.cc
index 427beda..bfc306b 100644
--- a/chrome/browser/ui/views/infobars/confirm_infobar.cc
+++ b/chrome/browser/ui/views/infobars/confirm_infobar.cc
@@ -39,25 +39,24 @@ void AlertInfoBar::Layout() {
InfoBarView::Layout();
// Layout the icon and text.
- gfx::Size icon_ps = icon_->GetPreferredSize();
- icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_ps), icon_ps.width(),
- icon_ps.height());
+ gfx::Size icon_size = icon_->GetPreferredSize();
+ icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_size),
+ icon_size.width(), icon_size.height());
- gfx::Size text_ps = label_->GetPreferredSize();
- int text_width = std::min(
- text_ps.width(),
+ gfx::Size text_size = label_->GetPreferredSize();
+ int text_width = std::min(text_size.width(),
GetAvailableWidth() - icon_->bounds().right() - kIconLabelSpacing);
label_->SetBounds(icon_->bounds().right() + kIconLabelSpacing,
- OffsetY(this, text_ps), text_width, text_ps.height());
+ OffsetY(this, text_size), text_width, text_size.height());
}
-// ConfirmInfoBarDelegate, InfoBarDelegate overrides: --------------------------
+// ConfirmInfoBarDelegate -----------------------------------------------------
InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() {
return new ConfirmInfoBar(this);
}
-// ConfirmInfoBar, public: -----------------------------------------------------
+// ConfirmInfoBar -------------------------------------------------------------
ConfirmInfoBar::ConfirmInfoBar(ConfirmInfoBarDelegate* delegate)
: AlertInfoBar(delegate),
@@ -94,101 +93,87 @@ ConfirmInfoBar::~ConfirmInfoBar() {
}
}
-// ConfirmInfoBar, views::LinkController implementation: -----------------------
-
-void ConfirmInfoBar::LinkActivated(views::Link* source, int event_flags) {
- DCHECK(source == link_);
- DCHECK(link_->IsVisible());
- DCHECK(!link_->GetText().empty());
- if (GetDelegate()->LinkClicked(
- event_utils::DispositionFromEventFlags(event_flags))) {
- RemoveInfoBar();
- }
-}
-
-// ConfirmInfoBar, views::View overrides: --------------------------------------
-
void ConfirmInfoBar::Layout() {
- // First layout right aligned items (from right to left) in order to determine
- // the space avalable, then layout the left aligned items.
-
- // Layout the close button.
InfoBarView::Layout();
- // Layout the cancel and OK buttons.
int available_width = AlertInfoBar::GetAvailableWidth();
int ok_button_width = 0;
int cancel_button_width = 0;
- gfx::Size ok_ps = ok_button_->GetPreferredSize();
- gfx::Size cancel_ps = cancel_button_->GetPreferredSize();
+ gfx::Size ok_size = ok_button_->GetPreferredSize();
+ gfx::Size cancel_size = cancel_button_->GetPreferredSize();
if (GetDelegate()->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) {
- ok_button_width = ok_ps.width();
+ ok_button_width = ok_size.width();
} else {
ok_button_->SetVisible(false);
}
if (GetDelegate()->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) {
- cancel_button_width = cancel_ps.width();
+ cancel_button_width = cancel_size.width();
} else {
cancel_button_->SetVisible(false);
}
cancel_button_->SetBounds(available_width - cancel_button_width,
- OffsetY(this, cancel_ps), cancel_ps.width(),
- cancel_ps.height());
+ OffsetY(this, cancel_size), cancel_size.width(), cancel_size.height());
int spacing = cancel_button_width > 0 ? kButtonButtonSpacing : 0;
ok_button_->SetBounds(cancel_button_->x() - spacing - ok_button_width,
- OffsetY(this, ok_ps), ok_ps.width(), ok_ps.height());
+ OffsetY(this, ok_size), ok_size.width(), ok_size.height());
// Layout the icon and label.
AlertInfoBar::Layout();
// Now append the link to the label's right edge.
link_->SetVisible(!link_->GetText().empty());
- gfx::Size link_ps = link_->GetPreferredSize();
+ gfx::Size link_size = link_->GetPreferredSize();
int link_x = label()->bounds().right() + kEndOfLabelSpacing;
- int link_w = std::min(GetAvailableWidth() - link_x, link_ps.width());
- link_->SetBounds(link_x, OffsetY(this, link_ps), link_w, link_ps.height());
+ int link_w = std::min(GetAvailableWidth() - link_x, link_size.width());
+ link_->SetBounds(link_x, OffsetY(this, link_size), link_w,
+ link_size.height());
}
void ConfirmInfoBar::ViewHierarchyChanged(bool is_add,
views::View* parent,
views::View* child) {
if (is_add && child == this && !initialized_) {
- Init();
+ AddChildView(ok_button_);
+ AddChildView(cancel_button_);
+ AddChildView(link_);
initialized_ = true;
}
+
+ // This must happen after adding all other children so InfoBarView can ensure
+ // the close button is the last child.
InfoBarView::ViewHierarchyChanged(is_add, parent, child);
}
-// ConfirmInfoBar, views::ButtonListener implementation: ---------------
+int ConfirmInfoBar::GetAvailableWidth() const {
+ return ok_button_->x() - kEndOfLabelSpacing;
+}
-void ConfirmInfoBar::ButtonPressed(
- views::Button* sender, const views::Event& event) {
- InfoBarView::ButtonPressed(sender, event);
+void ConfirmInfoBar::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ ConfirmInfoBarDelegate* delegate = GetDelegate();
if (sender == ok_button_) {
- if (GetDelegate()->Accept())
+ if (delegate->Accept())
RemoveInfoBar();
} else if (sender == cancel_button_) {
- if (GetDelegate()->Cancel())
+ if (delegate->Cancel())
RemoveInfoBar();
+ } else {
+ InfoBarView::ButtonPressed(sender, event);
}
}
-// ConfirmInfoBar, InfoBar overrides: ------------------------------------------
-
-int ConfirmInfoBar::GetAvailableWidth() const {
- return ok_button_->x() - kEndOfLabelSpacing;
+void ConfirmInfoBar::LinkActivated(views::Link* source, int event_flags) {
+ DCHECK_EQ(link_, source);
+ DCHECK(link_->IsVisible());
+ DCHECK(!link_->GetText().empty());
+ if (GetDelegate()->LinkClicked(
+ event_utils::DispositionFromEventFlags(event_flags))) {
+ RemoveInfoBar();
+ }
}
-// ConfirmInfoBar, private: ----------------------------------------------------
-
ConfirmInfoBarDelegate* ConfirmInfoBar::GetDelegate() {
return delegate()->AsConfirmInfoBarDelegate();
}
-
-void ConfirmInfoBar::Init() {
- AddChildView(ok_button_);
- AddChildView(cancel_button_);
- AddChildView(link_);
-}
diff --git a/chrome/browser/ui/views/infobars/confirm_infobar.h b/chrome/browser/ui/views/infobars/confirm_infobar.h
index de9afb2..0905bcc 100644
--- a/chrome/browser/ui/views/infobars/confirm_infobar.h
+++ b/chrome/browser/ui/views/infobars/confirm_infobar.h
@@ -11,7 +11,6 @@
class ConfirmInfoBarDelegate;
class InfoBarTextButton;
-
namespace views {
class Label;
}
@@ -42,31 +41,23 @@ class AlertInfoBar : public InfoBarView {
// TODO(pkasting): The above layout is the desired, but not current, layout; fix
// coming in a future patch.
class ConfirmInfoBar : public AlertInfoBar,
- public views::LinkController {
+ public views::LinkController {
public:
explicit ConfirmInfoBar(ConfirmInfoBarDelegate* delegate);
- virtual ~ConfirmInfoBar();
- // Overridden from views::LinkController:
- virtual void LinkActivated(views::Link* source, int event_flags);
+ private:
+ virtual ~ConfirmInfoBar();
- // Overridden from views::View:
+ // InfoBarView:
virtual void Layout();
-
- protected:
- // Overridden from views::View:
virtual void ViewHierarchyChanged(bool is_add,
views::View* parent,
views::View* child);
-
- // Overridden from views::ButtonListener:
- virtual void ButtonPressed(views::Button* sender, const views::Event& event);
-
- // Overridden from InfoBar:
virtual int GetAvailableWidth() const;
+ virtual void ButtonPressed(views::Button* sender, const views::Event& event);
- private:
- void Init();
+ // views::LinkController:
+ virtual void LinkActivated(views::Link* source, int event_flags);
ConfirmInfoBarDelegate* GetDelegate();
diff --git a/chrome/browser/ui/views/infobars/extension_infobar.cc b/chrome/browser/ui/views/infobars/extension_infobar.cc
index 53663f8..7d5a404 100644
--- a/chrome/browser/ui/views/infobars/extension_infobar.cc
+++ b/chrome/browser/ui/views/infobars/extension_infobar.cc
@@ -5,9 +5,10 @@
#include "chrome/browser/ui/views/infobars/extension_infobar.h"
#include "chrome/browser/extensions/extension_context_menu_model.h"
-#include "chrome/browser/extensions/extension_infobar_delegate.h"
#include "chrome/browser/extensions/extension_host.h"
+#include "chrome/browser/extensions/extension_infobar_delegate.h"
#include "chrome/browser/platform_util.h"
+#include "chrome/browser/ui/views/infobars/infobar_background.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_icon_set.h"
@@ -20,120 +21,116 @@
#include "views/controls/menu/menu_2.h"
#include "views/widget/widget.h"
+// ExtensionInfoBarDelegate ---------------------------------------------------
+
+InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() {
+ return new ExtensionInfoBar(this);
+}
+
+// ExtensionInfoBar -----------------------------------------------------------
+
+namespace {
// The horizontal margin between the menu and the Extension (HTML) view.
static const int kMenuHorizontalMargin = 1;
// The amount of space to the right of the Extension (HTML) view (to avoid
// overlapping the close button for the InfoBar).
static const int kFarRightMargin = 30;
-
-// The margin between the extension icon and the drop-down arrow bitmap.
-static const int kDropArrowLeftMargin = 3;
+};
ExtensionInfoBar::ExtensionInfoBar(ExtensionInfoBarDelegate* delegate)
: InfoBarView(delegate),
delegate_(delegate),
ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) {
- delegate_->set_observer(this);
-
- ExtensionHost* extension_host = delegate_->extension_host();
+ delegate->set_observer(this);
- // We set the target height for the InfoBar to be the height of the
- // ExtensionView it contains (plus 1 because the view should not overlap the
- // separator line at the bottom). When the InfoBar is first created, however,
- // this value is 0 but becomes positive after the InfoBar has been shown. See
- // function: OnExtensionPreferredSizeChanged.
- gfx::Size sz = extension_host->view()->GetPreferredSize();
- if (sz.height() > 0)
- sz.set_height(sz.height() + 1);
- set_target_height(sz.height());
+ ExtensionView* extension_view = delegate->extension_host()->view();
+ int height = extension_view->GetPreferredSize().height();
+ set_target_height((height > 0) ?
+ (height + InfoBarBackground::kSeparatorLineHeight) : height);
// Setup the extension icon and its associated drop down menu.
SetupIconAndMenu();
// Get notified of resize events for the ExtensionView.
- extension_host->view()->SetContainer(this);
+ extension_view->SetContainer(this);
// We show the ExtensionView, but we don't want it deleted when we get
// destroyed, which happens on tab switching (for example).
- extension_host->view()->set_parent_owned(false);
- AddChildView(extension_host->view());
+ extension_view->set_parent_owned(false);
+ AddChildView(extension_view);
}
ExtensionInfoBar::~ExtensionInfoBar() {
- if (delegate_) {
- delegate_->extension_host()->view()->SetContainer(NULL);
- delegate_->set_observer(NULL);
+ if (GetDelegate()) {
+ GetDelegate()->extension_host()->view()->SetContainer(NULL);
+ GetDelegate()->set_observer(NULL);
}
}
+void ExtensionInfoBar::Layout() {
+ InfoBarView::Layout();
+
+ gfx::Size menu_size = menu_->GetPreferredSize();
+ menu_->SetBounds(0, (height() - menu_size.height()) / 2, menu_size.width(),
+ menu_size.height());
+
+ int x = menu_->bounds().right() + kMenuHorizontalMargin;
+ GetDelegate()->extension_host()->view()->SetBounds(x, 0,
+ width() - x - kFarRightMargin - 1, height() - 1);
+}
+
+void ExtensionInfoBar::OnExtensionMouseMove(ExtensionView* view) {
+}
+
+void ExtensionInfoBar::OnExtensionMouseLeave(ExtensionView* view) {
+}
+
void ExtensionInfoBar::OnExtensionPreferredSizeChanged(ExtensionView* view) {
- DCHECK(view == delegate_->extension_host()->view());
+ ExtensionInfoBarDelegate* delegate = GetDelegate();
+ DCHECK_EQ(delegate->extension_host()->view(), view);
// When the infobar is closed, it animates to 0 vertical height. We'll
// continue to get size changed notifications from the ExtensionView, but we
// need to ignore them otherwise we'll try to re-animate open (and leak the
// infobar view).
- if (delegate_->closing())
+ if (delegate->closing())
return;
- delegate_->extension_host()->view()->SetVisible(true);
-
- gfx::Size sz = view->GetPreferredSize();
- // Clamp height to a min and a max size of between 1 and 2 InfoBars.
- int default_height = static_cast<int>(InfoBarView::kDefaultTargetHeight);
- sz.set_height(std::max(default_height, sz.height()));
- sz.set_height(std::min(2 * default_height, sz.height()));
+ view->SetVisible(true);
if (height() == 0)
animation()->Reset(0.0);
- set_target_height(sz.height());
- animation()->Show();
-}
-void ExtensionInfoBar::Layout() {
- // Layout the close button and the background.
- InfoBarView::Layout();
+ // Clamp height to a min and a max size of between 1 and 2 InfoBars.
+ set_target_height(std::min(2 * kDefaultTargetHeight,
+ std::max(kDefaultTargetHeight, view->GetPreferredSize().height())));
- // Layout the extension icon + drop down menu.
- int x = 0;
- gfx::Size sz = menu_->GetPreferredSize();
- menu_->SetBounds(x,
- (height() - sz.height()) / 2,
- sz.width(), sz.height());
- x += sz.width() + kMenuHorizontalMargin;
-
- // Layout the ExtensionView, showing the HTML InfoBar.
- ExtensionView* view = delegate_->extension_host()->view();
- view->SetBounds(x, 0, width() - x - kFarRightMargin - 1, height() - 1);
+ animation()->Show();
}
-void ExtensionInfoBar::OnImageLoaded(
- SkBitmap* image, ExtensionResource resource, int index) {
- if (!delegate_)
+void ExtensionInfoBar::OnImageLoaded(SkBitmap* image,
+ ExtensionResource resource,
+ int index) {
+ if (!GetDelegate())
return; // The delegate can go away while we asynchronously load images.
+ SkBitmap* icon = image;
+ // Fall back on the default extension icon on failure.
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
-
- // We fall back on the default extension icon on failure.
- SkBitmap* icon;
if (!image || image->empty())
icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION);
- else
- icon = image;
SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW);
int image_size = Extension::EXTENSION_ICON_BITTY;
- scoped_ptr<gfx::CanvasSkia> canvas(
- new gfx::CanvasSkia(
- image_size + kDropArrowLeftMargin + drop_image->width(),
- image_size, false));
- canvas->DrawBitmapInt(*icon,
- 0, 0, icon->width(), icon->height(),
- 0, 0, image_size, image_size,
- false);
- canvas->DrawBitmapInt(*drop_image,
- image_size + kDropArrowLeftMargin,
+ // The margin between the extension icon and the drop-down arrow bitmap.
+ static const int kDropArrowLeftMargin = 3;
+ scoped_ptr<gfx::CanvasSkia> canvas(new gfx::CanvasSkia(
+ image_size + kDropArrowLeftMargin + drop_image->width(), image_size,
+ false));
+ canvas->DrawBitmapInt(*icon, 0, 0, icon->width(), icon->height(), 0, 0,
+ image_size, image_size, false);
+ canvas->DrawBitmapInt(*drop_image, image_size + kDropArrowLeftMargin,
image_size / 2);
menu_->SetIcon(canvas->ExtractBitmap());
menu_->SetVisible(true);
@@ -142,12 +139,12 @@ void ExtensionInfoBar::OnImageLoaded(
}
void ExtensionInfoBar::OnDelegateDeleted() {
- delegate_->extension_host()->view()->SetContainer(NULL);
+ GetDelegate()->extension_host()->view()->SetContainer(NULL);
delegate_ = NULL;
}
void ExtensionInfoBar::RunMenu(View* source, const gfx::Point& pt) {
- const Extension* extension = delegate_->extension_host()->extension();
+ const Extension* extension = GetDelegate()->extension_host()->extension();
if (!extension->ShowConfigureContextMenus())
return;
@@ -155,8 +152,8 @@ void ExtensionInfoBar::RunMenu(View* source, const gfx::Point& pt) {
Browser* browser = BrowserView::GetBrowserViewForNativeWindow(
platform_util::GetTopLevel(source->GetWidget()->GetNativeView()))->
browser();
- options_menu_contents_ = new ExtensionContextMenuModel(
- extension, browser, NULL);
+ options_menu_contents_ = new ExtensionContextMenuModel(extension, browser,
+ NULL);
}
options_menu_menu_.reset(new views::Menu2(options_menu_contents_.get()));
@@ -168,20 +165,18 @@ void ExtensionInfoBar::SetupIconAndMenu() {
menu_->SetVisible(false);
AddChildView(menu_);
- const Extension* extension = delegate_->extension_host()->extension();
+ const Extension* extension = GetDelegate()->extension_host()->extension();
+ int image_size = Extension::EXTENSION_ICON_BITTY;
ExtensionResource icon_resource = extension->GetIconResource(
- Extension::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_EXACTLY);
+ image_size, ExtensionIconSet::MATCH_EXACTLY);
if (!icon_resource.relative_path().empty()) {
- // Create a tracker to load the image. It will report back on OnImageLoaded.
tracker_.LoadImage(extension, icon_resource,
- gfx::Size(Extension::EXTENSION_ICON_BITTY,
- Extension::EXTENSION_ICON_BITTY),
- ImageLoadingTracker::DONT_CACHE);
+ gfx::Size(image_size, image_size), ImageLoadingTracker::DONT_CACHE);
} else {
- OnImageLoaded(NULL, icon_resource, 0); // |image|, |index|.
+ OnImageLoaded(NULL, icon_resource, 0);
}
}
-InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() {
- return new ExtensionInfoBar(this);
+ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() {
+ return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL;
}
diff --git a/chrome/browser/ui/views/infobars/extension_infobar.h b/chrome/browser/ui/views/infobars/extension_infobar.h
index aaa2729..9a7068a 100644
--- a/chrome/browser/ui/views/infobars/extension_infobar.h
+++ b/chrome/browser/ui/views/infobars/extension_infobar.h
@@ -6,19 +6,16 @@
#define CHROME_BROWSER_UI_VIEWS_INFOBARS_EXTENSION_INFOBAR_H_
#pragma once
-#include "chrome/browser/ui/views/infobars/infobar_view.h"
-
#include "chrome/browser/extensions/extension_infobar_delegate.h"
#include "chrome/browser/extensions/image_loading_tracker.h"
#include "chrome/browser/ui/views/extensions/extension_view.h"
+#include "chrome/browser/ui/views/infobars/infobar_view.h"
#include "views/controls/menu/view_menu_delegate.h"
class ExtensionContextMenuModel;
-class ExtensionInfoBarDelegate;
-
namespace views {
- class MenuButton;
- class Menu2;
+class MenuButton;
+class Menu2;
}
// This class implements InfoBars for Extensions.
@@ -29,34 +26,41 @@ class ExtensionInfoBar : public InfoBarView,
public views::ViewMenuDelegate {
public:
explicit ExtensionInfoBar(ExtensionInfoBarDelegate* delegate);
- virtual ~ExtensionInfoBar();
- // Overridden from ExtensionView::Container:
- virtual void OnExtensionMouseMove(ExtensionView* view) {}
- virtual void OnExtensionMouseLeave(ExtensionView* view) {}
- virtual void OnExtensionPreferredSizeChanged(ExtensionView* view);
+ private:
+ virtual ~ExtensionInfoBar();
- // Overridden from views::View:
+ // InfoBarView:
virtual void Layout();
- // Overridden from ImageLoadingTracker::Observer:
- virtual void OnImageLoaded(
- SkBitmap* image, ExtensionResource resource, int index);
+ // ExtensionView::Container:
+ virtual void OnExtensionMouseMove(ExtensionView* view);
+ virtual void OnExtensionMouseLeave(ExtensionView* view);
+ virtual void OnExtensionPreferredSizeChanged(ExtensionView* view);
+
+ // ImageLoadingTracker::Observer:
+ virtual void OnImageLoaded(SkBitmap* image,
+ ExtensionResource resource,
+ int index);
- // Overridden from ExtensionInfoBarDelegate::DelegateObserver:
+ // ExtensionInfoBarDelegate::DelegateObserver:
virtual void OnDelegateDeleted();
- // Overridden from views::ViewMenuDelegate:
+ // views::ViewMenuDelegate:
virtual void RunMenu(View* source, const gfx::Point& pt);
- private:
// Setup the menu button showing the small extension icon and its dropdown
// menu.
void SetupIconAndMenu();
+ ExtensionInfoBarDelegate* GetDelegate();
+
NotificationRegistrar notification_registrar_;
- ExtensionInfoBarDelegate* delegate_;
+ // TODO(pkasting): This shadows InfoBarView::delegate_. Get rid of this once
+ // InfoBars own their delegates (and thus we don't need the DelegateObserver
+ // functionality). For now, almost everyone should use GetDelegate() instead.
+ InfoBarDelegate* delegate_;
// The dropdown menu for accessing the contextual extension actions.
scoped_refptr<ExtensionContextMenuModel> options_menu_contents_;
diff --git a/chrome/browser/ui/views/infobars/infobar_background.cc b/chrome/browser/ui/views/infobars/infobar_background.cc
index 0af9149..71fa45c 100644
--- a/chrome/browser/ui/views/infobars/infobar_background.cc
+++ b/chrome/browser/ui/views/infobars/infobar_background.cc
@@ -8,18 +8,8 @@
#include "ui/gfx/canvas.h"
#include "views/view.h"
-static const SkColor kWarningBackgroundColorTop = SkColorSetRGB(255, 242, 183);
-static const SkColor kWarningBackgroundColorBottom =
- SkColorSetRGB(250, 230, 145);
-
-static const SkColor kPageActionBackgroundColorTop =
- SkColorSetRGB(218, 231, 249);
-static const SkColor kPageActionBackgroundColorBottom =
- SkColorSetRGB(179, 202, 231);
-
-static const int kSeparatorLineHeight = 1;
-
-// InfoBarBackground, public: --------------------------------------------------
+// static
+const int InfoBarBackground::kSeparatorLineHeight = 1;
InfoBarBackground::InfoBarBackground(InfoBarDelegate::Type infobar_type) {
gradient_background_.reset(
@@ -28,23 +18,31 @@ InfoBarBackground::InfoBarBackground(InfoBarDelegate::Type infobar_type) {
GetBottomColor(infobar_type)));
}
+InfoBarBackground::~InfoBarBackground() {
+}
+
SkColor InfoBarBackground::GetTopColor(InfoBarDelegate::Type infobar_type) {
+ static const SkColor kWarningBackgroundColorTop =
+ SkColorSetRGB(255, 242, 183);
+ static const SkColor kPageActionBackgroundColorTop =
+ SkColorSetRGB(218, 231, 249);
+
return (infobar_type == InfoBarDelegate::WARNING_TYPE) ?
kWarningBackgroundColorTop : kPageActionBackgroundColorTop;
}
SkColor InfoBarBackground::GetBottomColor(InfoBarDelegate::Type infobar_type) {
+ static const SkColor kWarningBackgroundColorBottom =
+ SkColorSetRGB(250, 230, 145);
+ static const SkColor kPageActionBackgroundColorBottom =
+ SkColorSetRGB(179, 202, 231);
+
return (infobar_type == InfoBarDelegate::WARNING_TYPE) ?
kWarningBackgroundColorBottom : kPageActionBackgroundColorBottom;
}
-// InfoBarBackground, views::Background overrides: -----------------------------
-
void InfoBarBackground::Paint(gfx::Canvas* canvas, views::View* view) const {
- // First paint the gradient background.
gradient_background_->Paint(canvas, view);
-
- // Now paint the separator line.
canvas->FillRectInt(ResourceBundle::toolbar_separator_color, 0,
view->height() - kSeparatorLineHeight, view->width(),
kSeparatorLineHeight);
diff --git a/chrome/browser/ui/views/infobars/infobar_background.h b/chrome/browser/ui/views/infobars/infobar_background.h
index 9b967c0..1849588 100644
--- a/chrome/browser/ui/views/infobars/infobar_background.h
+++ b/chrome/browser/ui/views/infobars/infobar_background.h
@@ -12,15 +12,18 @@
class InfoBarBackground : public views::Background {
public:
- explicit InfoBarBackground(InfoBarDelegate::Type infobar_type);
+ static const int kSeparatorLineHeight;
- // Overridden from views::Background:
- virtual void Paint(gfx::Canvas* canvas, views::View* view) const;
+ explicit InfoBarBackground(InfoBarDelegate::Type infobar_type);
+ virtual ~InfoBarBackground();
static SkColor GetTopColor(InfoBarDelegate::Type infobar_type);
static SkColor GetBottomColor(InfoBarDelegate::Type infobar_type);
private:
+ // views::Background:
+ virtual void Paint(gfx::Canvas* canvas, views::View* view) const;
+
scoped_ptr<views::Background> gradient_background_;
DISALLOW_COPY_AND_ASSIGN(InfoBarBackground);
diff --git a/chrome/browser/ui/views/infobars/infobar_button_border.cc b/chrome/browser/ui/views/infobars/infobar_button_border.cc
index 84a3bd9..981f3d5 100644
--- a/chrome/browser/ui/views/infobars/infobar_button_border.cc
+++ b/chrome/browser/ui/views/infobars/infobar_button_border.cc
@@ -5,19 +5,13 @@
#include "chrome/browser/ui/views/infobars/infobar_button_border.h"
#include "grit/theme_resources.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "views/controls/button/text_button.h"
-// Preferred padding between text and edge
-static const int kPreferredPaddingHorizontal = 6;
-static const int kPreferredPaddingVertical = 5;
-
-// InfoBarButtonBorder, public: ----------------------------------------------
-
InfoBarButtonBorder::InfoBarButtonBorder() {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
-
normal_set_.top_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_LEFT_N);
normal_set_.top = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_N);
normal_set_.top_right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_RIGHT_N);
@@ -54,9 +48,9 @@ InfoBarButtonBorder::InfoBarButtonBorder() {
InfoBarButtonBorder::~InfoBarButtonBorder() {
}
-// InfoBarButtonBorder, Border overrides: ------------------------------------
-
void InfoBarButtonBorder::GetInsets(gfx::Insets* insets) const {
+ static const int kPreferredPaddingHorizontal = 6;
+ static const int kPreferredPaddingVertical = 5;
insets->Set(kPreferredPaddingVertical, kPreferredPaddingHorizontal,
kPreferredPaddingVertical, kPreferredPaddingHorizontal);
}
@@ -65,25 +59,19 @@ void InfoBarButtonBorder::Paint(const views::View& view,
gfx::Canvas* canvas) const {
const views::TextButton* mb = static_cast<const views::TextButton*>(&view);
int state = mb->state();
-
- // TextButton takes care of deciding when to call Paint.
const MBBImageSet* set = &normal_set_;
if (state == views::TextButton::BS_HOT)
set = &hot_set_;
else if (state == views::TextButton::BS_PUSHED)
set = &pushed_set_;
- gfx::Rect bounds = view.bounds();
-
// Draw top left image.
canvas->DrawBitmapInt(*set->top_left, 0, 0);
// Stretch top image.
- canvas->DrawBitmapInt(
- *set->top,
- 0, 0, set->top->width(), set->top->height(),
- set->top_left->width(),
- 0,
+ const gfx::Rect& bounds = view.bounds();
+ canvas->DrawBitmapInt(*set->top, 0, 0, set->top->width(), set->top->height(),
+ set->top_left->width(), 0,
bounds.width() - set->top_right->width() - set->top_left->width(),
set->top->height(), false);
@@ -92,46 +80,32 @@ void InfoBarButtonBorder::Paint(const views::View& view,
bounds.width() - set->top_right->width(), 0);
// Stretch left image.
- canvas->DrawBitmapInt(
- *set->left,
- 0, 0, set->left->width(), set->left->height(),
- 0,
- set->top_left->height(),
- set->top_left->width(),
+ canvas->DrawBitmapInt(*set->left, 0, 0, set->left->width(),
+ set->left->height(), 0, set->top_left->height(), set->top_left->width(),
bounds.height() - set->top->height() - set->bottom_left->height(), false);
// Stretch center image.
- canvas->DrawBitmapInt(
- *set->center,
- 0, 0, set->center->width(), set->center->height(),
- set->left->width(),
- set->top->height(),
+ canvas->DrawBitmapInt(*set->center, 0, 0, set->center->width(),
+ set->center->height(), set->left->width(), set->top->height(),
bounds.width() - set->right->width() - set->left->width(),
bounds.height() - set->bottom->height() - set->top->height(), false);
// Stretch right image.
- canvas->DrawBitmapInt(
- *set->right,
- 0, 0, set->right->width(), set->right->height(),
- bounds.width() - set->right->width(),
- set->top_right->height(),
- set->right->width(),
- bounds.height() - set->bottom_right->height() -
- set->top_right->height(), false);
+ canvas->DrawBitmapInt(*set->right, 0, 0, set->right->width(),
+ set->right->height(), bounds.width() - set->right->width(),
+ set->top_right->height(), set->right->width(),
+ bounds.height() - set->bottom_right->height() - set->top_right->height(),
+ false);
// Draw bottom left image.
- canvas->DrawBitmapInt(*set->bottom_left,
- 0,
+ canvas->DrawBitmapInt(*set->bottom_left, 0,
bounds.height() - set->bottom_left->height());
// Stretch bottom image.
- canvas->DrawBitmapInt(
- *set->bottom,
- 0, 0, set->bottom->width(), set->bottom->height(),
- set->bottom_left->width(),
+ canvas->DrawBitmapInt(*set->bottom, 0, 0, set->bottom->width(),
+ set->bottom->height(), set->bottom_left->width(),
bounds.height() - set->bottom->height(),
- bounds.width() - set->bottom_right->width() -
- set->bottom_left->width(),
+ bounds.width() - set->bottom_right->width() - set->bottom_left->width(),
set->bottom->height(), false);
// Draw bottom right image.
diff --git a/chrome/browser/ui/views/infobars/infobar_button_border.h b/chrome/browser/ui/views/infobars/infobar_button_border.h
index c8cfa83..fccdd87 100644
--- a/chrome/browser/ui/views/infobars/infobar_button_border.h
+++ b/chrome/browser/ui/views/infobars/infobar_button_border.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -8,8 +8,7 @@
#include "views/border.h"
-#include "third_party/skia/include/core/SkBitmap.h"
-
+class SkBitmap;
namespace gfx {
class Canvas;
}
@@ -19,18 +18,17 @@ class View;
// A TextButtonBorder that is dark and also paints the button frame in the
// normal state.
-
class InfoBarButtonBorder : public views::Border {
public:
InfoBarButtonBorder();
+
+ private:
virtual ~InfoBarButtonBorder();
- // Overriden from Border:
+ // views::Border:
virtual void GetInsets(gfx::Insets* insets) const;
virtual void Paint(const views::View& view, gfx::Canvas* canvas) const;
- private:
- // Images
struct MBBImageSet {
SkBitmap* top_left;
SkBitmap* top;
diff --git a/chrome/browser/ui/views/infobars/infobar_container.cc b/chrome/browser/ui/views/infobars/infobar_container.cc
index c829c14..b0c7f37 100644
--- a/chrome/browser/ui/views/infobars/infobar_container.cc
+++ b/chrome/browser/ui/views/infobars/infobar_container.cc
@@ -14,8 +14,6 @@
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
-// InfoBarContainer, public: ---------------------------------------------------
-
InfoBarContainer::InfoBarContainer(Delegate* delegate)
: delegate_(delegate),
tab_contents_(NULL) {
@@ -62,14 +60,12 @@ void InfoBarContainer::RemoveDelegate(InfoBarDelegate* delegate) {
void InfoBarContainer::PaintInfoBarArrows(gfx::Canvas* canvas,
views::View* outer_view,
int arrow_center_x) {
- for(int i = 0; i < GetChildViewCount(); ++i) {
+ for (int i = 0; i < GetChildViewCount(); ++i) {
InfoBarView* infobar = static_cast<InfoBarView*>(GetChildViewAt(i));
infobar->PaintArrow(canvas, outer_view, arrow_center_x);
}
}
-// InfoBarContainer, views::View overrides: ------------------------------------
-
gfx::Size InfoBarContainer::GetPreferredSize() {
// We do not have a preferred width (we will expand to fit the available width
// of the delegate). Our preferred height is the sum of the preferred
@@ -106,8 +102,6 @@ void InfoBarContainer::ViewHierarchyChanged(bool is_add,
}
}
-// InfoBarContainer, NotificationObserver implementation: ----------------------
-
void InfoBarContainer::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
@@ -124,10 +118,8 @@ void InfoBarContainer::Observe(NotificationType type,
}
}
-// InfoBarContainer, private: --------------------------------------------------
-
void InfoBarContainer::UpdateInfoBars() {
- for (int i = 0; i < tab_contents_->infobar_delegate_count(); ++i) {
+ for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) {
InfoBarDelegate* delegate = tab_contents_->GetInfoBarDelegateAt(i);
InfoBarView* infobar = static_cast<InfoBarView*>(delegate->CreateInfoBar());
infobar->set_container(this);
diff --git a/chrome/browser/ui/views/infobars/infobar_container.h b/chrome/browser/ui/views/infobars/infobar_container.h
index 9a02bc8..6b82b5f 100644
--- a/chrome/browser/ui/views/infobars/infobar_container.h
+++ b/chrome/browser/ui/views/infobars/infobar_container.h
@@ -51,18 +51,16 @@ class InfoBarContainer : public AccessiblePaneView,
views::View* outer_view,
int arrow_center_x);
- // Overridden from views::View:
+ private:
+ // AccessiblePaneView:
virtual gfx::Size GetPreferredSize();
virtual void Layout();
virtual AccessibilityTypes::Role GetAccessibleRole();
-
- protected:
virtual void ViewHierarchyChanged(bool is_add,
views::View* parent,
views::View* child);
- private:
- // Overridden from NotificationObserver:
+ // NotificationObserver:
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details);
diff --git a/chrome/browser/ui/views/infobars/infobar_view.cc b/chrome/browser/ui/views/infobars/infobar_view.cc
index 5e90a16..5871c96 100644
--- a/chrome/browser/ui/views/infobars/infobar_view.cc
+++ b/chrome/browser/ui/views/infobars/infobar_view.cc
@@ -27,7 +27,7 @@
#endif
// static
-const double InfoBarView::kDefaultTargetHeight = 36.0;
+const int InfoBarView::kDefaultTargetHeight = 36;
const int InfoBarView::kHorizontalPadding = 6;
const int InfoBarView::kIconLabelSpacing = 6;
const int InfoBarView::kButtonButtonSpacing = 10;
@@ -35,8 +35,6 @@ const int InfoBarView::kEndOfLabelSpacing = 16;
const int InfoBarView::kCloseButtonSpacing = 12;
const int InfoBarView::kButtonInLabelSpacing = 5;
-// InfoBarView, public: -------------------------------------------------------
-
InfoBarView::InfoBarView(InfoBarDelegate* delegate)
: InfoBar(delegate),
delegate_(delegate),
@@ -44,24 +42,14 @@ InfoBarView::InfoBarView(InfoBarDelegate* delegate)
close_button_(new views::ImageButton(this))),
ALLOW_THIS_IN_INITIALIZER_LIST(delete_factory_(this)),
target_height_(kDefaultTargetHeight) {
- // We delete ourselves when we're removed from the view hierarchy.
+ // InfoBar deletes itself at the appropriate time.
set_parent_owned(false);
- set_background(new InfoBarBackground(delegate->GetInfoBarType()));
-
- switch (delegate->GetInfoBarType()) {
- case InfoBarDelegate::WARNING_TYPE:
- SetAccessibleName(
- l10n_util::GetStringUTF16(IDS_ACCNAME_INFOBAR_WARNING));
- break;
- case InfoBarDelegate::PAGE_ACTION_TYPE:
- SetAccessibleName(
- l10n_util::GetStringUTF16(IDS_ACCNAME_INFOBAR_PAGE_ACTION));
- break;
- default:
- NOTREACHED();
- break;
- }
+ InfoBarDelegate::Type infobar_type = delegate->GetInfoBarType();
+ set_background(new InfoBarBackground(infobar_type));
+ SetAccessibleName(l10n_util::GetStringUTF16(
+ (infobar_type == InfoBarDelegate::WARNING_TYPE) ?
+ IDS_ACCNAME_INFOBAR_WARNING : IDS_ACCNAME_INFOBAR_PAGE_ACTION));
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
close_button_->SetImage(views::CustomButton::BS_NORMAL,
@@ -72,13 +60,48 @@ InfoBarView::InfoBarView(InfoBarDelegate* delegate)
rb.GetBitmapNamed(IDR_CLOSE_BAR_P));
close_button_->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE));
+ close_button_->SetFocusable(true);
AddChildView(close_button_);
animation_.reset(new ui::SlideAnimation(this));
animation_->SetTweenType(ui::Tween::LINEAR);
}
-InfoBarView::~InfoBarView() {
+void InfoBarView::AnimateOpen() {
+ animation_->Show();
+}
+
+void InfoBarView::Open() {
+ // Set the animation value to 1.0 so that GetPreferredSize() returns the right
+ // size.
+ animation_->Reset(1.0);
+ if (container_)
+ container_->InfoBarAnimated(false);
+}
+
+void InfoBarView::AnimateClose() {
+ bool restore_focus = true;
+#if defined(OS_WIN)
+ // Do not restore focus (and active state with it) on Windows if some other
+ // top-level window became active.
+ if (GetWidget() &&
+ !ui::DoesWindowBelongToActiveWindow(GetWidget()->GetNativeView())) {
+ restore_focus = false;
+ }
+#endif // defined(OS_WIN)
+ DestroyFocusTracker(restore_focus);
+ animation_->Hide();
+}
+
+void InfoBarView::Close() {
+ GetParent()->RemoveChildView(this);
+ // Note that we only tell the delegate we're closed here, and not when we're
+ // simply destroyed (by virtue of a tab switch or being moved from window to
+ // window), since this action can cause the delegate to destroy itself.
+ if (delegate_) {
+ delegate_->InfoBarClosed();
+ delegate_ = NULL;
+ }
}
void InfoBarView::PaintArrow(gfx::Canvas* canvas,
@@ -133,22 +156,14 @@ void InfoBarView::PaintArrow(gfx::Canvas* canvas,
canvas_skia->drawPath(border_path, paint);
}
-// InfoBarView, views::View overrides: ----------------------------------------
-
-AccessibilityTypes::Role InfoBarView::GetAccessibleRole() {
- return AccessibilityTypes::ROLE_ALERT;
-}
-
-gfx::Size InfoBarView::GetPreferredSize() {
- int height = static_cast<int>(target_height_ * animation_->GetCurrentValue());
- return gfx::Size(0, height);
+InfoBarView::~InfoBarView() {
}
void InfoBarView::Layout() {
- gfx::Size button_ps = close_button_->GetPreferredSize();
- close_button_->SetBounds(width() - kHorizontalPadding - button_ps.width(),
- OffsetY(this, button_ps), button_ps.width(),
- button_ps.height());
+ gfx::Size button_size = close_button_->GetPreferredSize();
+ close_button_->SetBounds(width() - kHorizontalPadding - button_size.width(),
+ OffsetY(this, button_size), button_size.width(),
+ button_size.height());
}
void InfoBarView::ViewHierarchyChanged(bool is_add,
@@ -156,27 +171,58 @@ void InfoBarView::ViewHierarchyChanged(bool is_add,
views::View* child) {
if (child == this) {
if (is_add) {
- InfoBarAdded();
+ // The container_ pointer must be set before adding to the view hierarchy.
+ DCHECK(container_);
+#if defined(OS_WIN)
+ // When we're added to a view hierarchy within a widget, we create an
+ // external focus tracker to track what was focused in case we obtain
+ // focus so that we can restore focus when we're removed.
+ views::Widget* widget = GetWidget();
+ if (widget) {
+ focus_tracker_.reset(
+ new views::ExternalFocusTracker(this, GetFocusManager()));
+ }
+#endif
+ if (GetFocusManager())
+ GetFocusManager()->AddFocusChangeListener(this);
+ NotifyAccessibilityEvent(AccessibilityTypes::EVENT_ALERT);
} else {
- InfoBarRemoved();
+ DestroyFocusTracker(false);
+ // NULL our container_ pointer so that if Animation::Stop results in
+ // AnimationEnded being called, we do not try and delete ourselves twice.
+ container_ = NULL;
+ animation_->Stop();
+ // Finally, clean ourselves up when we're removed from the view hierarchy
+ // since no-one refers to us now.
+ MessageLoop::current()->PostTask(FROM_HERE,
+ delete_factory_.NewRunnableMethod(&InfoBarView::DeleteSelf));
+ if (GetFocusManager())
+ GetFocusManager()->RemoveFocusChangeListener(this);
}
}
- if (GetWidget() && GetWidget()->IsAccessibleWidget()) {
- // For accessibility, make the close button the last child view.
- if (parent == this && child != close_button_ &&
- HasChildView(close_button_) &&
- GetChildViewAt(GetChildViewCount() - 1) != close_button_) {
- RemoveChildView(close_button_);
- AddChildView(close_button_);
- }
+ // For accessibility, ensure the close button is the last child view.
+ if ((parent == this) && (child != close_button_) &&
+ HasChildView(close_button_) &&
+ (GetChildViewAt(GetChildViewCount() - 1) != close_button_)) {
+ RemoveChildView(close_button_);
+ AddChildView(close_button_);
+ }
+}
- // Allow screen reader users to focus the close button.
- close_button_->SetFocusable(true);
+void InfoBarView::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ if (sender == close_button_) {
+ if (delegate_)
+ delegate_->InfoBarDismissed();
+ RemoveInfoBar();
}
}
-// InfoBarView, protected: ----------------------------------------------------
+void InfoBarView::AnimationProgressed(const ui::Animation* animation) {
+ if (container_)
+ container_->InfoBarAnimated(true);
+}
int InfoBarView::GetAvailableWidth() const {
return close_button_->x() - kCloseButtonSpacing;
@@ -187,43 +233,29 @@ void InfoBarView::RemoveInfoBar() const {
container_->RemoveDelegate(delegate());
}
-int InfoBarView::CenterY(const gfx::Size prefsize) {
- return std::max((static_cast<int>(target_height_) -
- prefsize.height()) / 2, 0);
+int InfoBarView::CenterY(const gfx::Size prefsize) const {
+ return std::max((target_height_ - prefsize.height()) / 2, 0);
}
-int InfoBarView::OffsetY(views::View* parent, const gfx::Size prefsize) {
- return CenterY(prefsize) -
- (static_cast<int>(target_height_) - parent->height());
+int InfoBarView::OffsetY(views::View* parent, const gfx::Size prefsize) const {
+ return CenterY(prefsize) - (target_height_ - parent->height());
}
-// InfoBarView, views::ButtonListener implementation: -------------------------
-
-void InfoBarView::ButtonPressed(views::Button* sender,
- const views::Event& event) {
- if (sender == close_button_) {
- if (delegate_)
- delegate_->InfoBarDismissed();
- RemoveInfoBar();
- }
+AccessibilityTypes::Role InfoBarView::GetAccessibleRole() {
+ return AccessibilityTypes::ROLE_ALERT;
}
-// InfoBarView, views::FocusChangeListener implementation: --------------------
+gfx::Size InfoBarView::GetPreferredSize() {
+ int height = static_cast<int>(target_height_ * animation_->GetCurrentValue());
+ return gfx::Size(0, height);
+}
void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) {
// This will trigger some screen readers to read the entire contents of this
// infobar.
- if (focused_before && focused_now &&
- !this->IsParentOf(focused_before) && this->IsParentOf(focused_now)) {
+ if (focused_before && focused_now && !this->IsParentOf(focused_before) &&
+ this->IsParentOf(focused_now))
NotifyAccessibilityEvent(AccessibilityTypes::EVENT_ALERT);
- }
-}
-
-// InfoBarView, ui::AnimationDelegate implementation: -------------------------
-
-void InfoBarView::AnimationProgressed(const ui::Animation* animation) {
- if (container_)
- container_->InfoBarAnimated(true);
}
void InfoBarView::AnimationEnded(const ui::Animation* animation) {
@@ -235,86 +267,12 @@ void InfoBarView::AnimationEnded(const ui::Animation* animation) {
}
}
-// InfoBarView, private: ------------------------------------------------------
-
-void InfoBarView::AnimateOpen() {
- animation_->Show();
-}
-
-void InfoBarView::Open() {
- // Set the animation value to 1.0 so that GetPreferredSize() returns the right
- // size.
- animation_->Reset(1.0);
- if (container_)
- container_->InfoBarAnimated(false);
-}
-
-void InfoBarView::AnimateClose() {
- bool restore_focus = true;
-#if defined(OS_WIN)
- // Do not restore focus (and active state with it) on Windows if some other
- // top-level window became active.
- if (GetWidget() &&
- !ui::DoesWindowBelongToActiveWindow(GetWidget()->GetNativeView())) {
- restore_focus = false;
- }
-#endif // defined(OS_WIN)
- DestroyFocusTracker(restore_focus);
- animation_->Hide();
-}
-
-void InfoBarView::Close() {
- GetParent()->RemoveChildView(this);
- // Note that we only tell the delegate we're closed here, and not when we're
- // simply destroyed (by virtue of a tab switch or being moved from window to
- // window), since this action can cause the delegate to destroy itself.
- if (delegate_) {
- delegate_->InfoBarClosed();
- delegate_ = NULL;
- }
-}
-
-void InfoBarView::InfoBarAdded() {
- // The container_ pointer must be set before adding to the view hierarchy.
- DCHECK(container_);
-#if defined(OS_WIN)
- // When we're added to a view hierarchy within a widget, we create an
- // external focus tracker to track what was focused in case we obtain
- // focus so that we can restore focus when we're removed.
- views::Widget* widget = GetWidget();
- if (widget) {
- focus_tracker_.reset(new views::ExternalFocusTracker(this,
- GetFocusManager()));
- }
-#endif
-
- if (GetFocusManager())
- GetFocusManager()->AddFocusChangeListener(this);
-
- NotifyAccessibilityEvent(AccessibilityTypes::EVENT_ALERT);
-}
-
-void InfoBarView::InfoBarRemoved() {
- DestroyFocusTracker(false);
- // NULL our container_ pointer so that if Animation::Stop results in
- // AnimationEnded being called, we do not try and delete ourselves twice.
- container_ = NULL;
- animation_->Stop();
- // Finally, clean ourselves up when we're removed from the view hierarchy
- // since no-one refers to us now.
- MessageLoop::current()->PostTask(FROM_HERE,
- delete_factory_.NewRunnableMethod(&InfoBarView::DeleteSelf));
-
- if (GetFocusManager())
- GetFocusManager()->RemoveFocusChangeListener(this);
-}
-
void InfoBarView::DestroyFocusTracker(bool restore_focus) {
- if (focus_tracker_.get()) {
+ if (focus_tracker_ != NULL) {
if (restore_focus)
focus_tracker_->FocusLastFocusedExternalView();
focus_tracker_->SetFocusManager(NULL);
- focus_tracker_.reset(NULL);
+ focus_tracker_.reset();
}
}
diff --git a/chrome/browser/ui/views/infobars/infobar_view.h b/chrome/browser/ui/views/infobars/infobar_view.h
index b52e64f..b3d5606 100644
--- a/chrome/browser/ui/views/infobars/infobar_view.h
+++ b/chrome/browser/ui/views/infobars/infobar_view.h
@@ -46,7 +46,6 @@ class InfoBarView : public InfoBar,
public ui::AnimationDelegate {
public:
explicit InfoBarView(InfoBarDelegate* delegate);
- virtual ~InfoBarView();
InfoBarDelegate* delegate() const { return delegate_; }
@@ -54,21 +53,20 @@ class InfoBarView : public InfoBar,
// InfoBar is added to the view hierarchy.
void set_container(InfoBarContainer* container) { container_ = container; }
- // The target height of the InfoBar, regardless of what its current height
- // is (due to animation).
- static const double kDefaultTargetHeight;
+ // Starts animating the InfoBar open.
+ void AnimateOpen();
- static const int kHorizontalPadding;
- static const int kIconLabelSpacing;
- static const int kButtonButtonSpacing;
- static const int kEndOfLabelSpacing;
- static const int kCloseButtonSpacing;
- static const int kButtonInLabelSpacing;
+ // Opens the InfoBar immediately.
+ void Open();
- // Overridden from views::View:
- virtual AccessibilityTypes::Role GetAccessibleRole();
- virtual gfx::Size GetPreferredSize();
- virtual void Layout();
+ // Starts animating the InfoBar closed. It will not be closed until the
+ // animation has completed, when |Close| will be called.
+ void AnimateClose();
+
+ // Closes the InfoBar immediately and removes it from its container. Notifies
+ // the delegate that it has closed. The InfoBar is deleted after this function
+ // is called.
+ void Close();
// Paint the arrow on |canvas|. |arrow_center_x| indicates the
// desired location of the center of the arrow in the |outer_view|
@@ -78,11 +76,31 @@ class InfoBarView : public InfoBar,
int arrow_center_x);
protected:
- // Overridden from views::View:
+ // The target height of the InfoBar, regardless of what its current height
+ // is (due to animation).
+ static const int kDefaultTargetHeight;
+
+ static const int kHorizontalPadding;
+ static const int kIconLabelSpacing;
+ static const int kButtonButtonSpacing;
+ static const int kEndOfLabelSpacing;
+ static const int kCloseButtonSpacing;
+ static const int kButtonInLabelSpacing;
+
+ virtual ~InfoBarView();
+
+ // views::View:
+ virtual void Layout();
virtual void ViewHierarchyChanged(bool is_add,
views::View* parent,
views::View* child);
+ // views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender, const views::Event& event);
+
+ // ui::AnimationDelegate:
+ virtual void AnimationProgressed(const ui::Animation* animation);
+
// Returns the available width of the View for use by child view layout,
// excluding the close button.
virtual int GetAvailableWidth() const;
@@ -91,53 +109,31 @@ class InfoBarView : public InfoBar,
// (Will lead to this InfoBar being closed).
void RemoveInfoBar() const;
- void set_target_height(double height) { target_height_ = height; }
+ void set_target_height(int height) { target_height_ = height; }
ui::SlideAnimation* animation() { return animation_.get(); }
// Returns a centered y-position of a control of height specified in
// |prefsize| within the standard InfoBar height. Stable during an animation.
- int CenterY(const gfx::Size prefsize);
+ int CenterY(const gfx::Size prefsize) const;
// Returns a centered y-position of a control of height specified in
// |prefsize| within the standard InfoBar height, adjusted according to the
// current amount of animation offset the |parent| InfoBar currently has.
// Changes during an animation.
- int OffsetY(views::View* parent, const gfx::Size prefsize);
+ int OffsetY(views::View* parent, const gfx::Size prefsize) const;
- // Overridden from views::ButtonListener:
- virtual void ButtonPressed(views::Button* sender, const views::Event& event);
+ private:
+ // views::View:
+ virtual AccessibilityTypes::Role GetAccessibleRole();
+ virtual gfx::Size GetPreferredSize();
- // Overridden from views::FocusChangeListener:
+ // views::FocusChangeListener:
virtual void FocusWillChange(View* focused_before, View* focused_now);
- // Overridden from ui::AnimationDelegate:
- virtual void AnimationProgressed(const ui::Animation* animation);
+ // ui::AnimationDelegate:
virtual void AnimationEnded(const ui::Animation* animation);
- private:
- friend class InfoBarContainer;
-
- // Starts animating the InfoBar open.
- void AnimateOpen();
-
- // Opens the InfoBar immediately.
- void Open();
-
- // Starts animating the InfoBar closed. It will not be closed until the
- // animation has completed, when |Close| will be called.
- void AnimateClose();
-
- // Closes the InfoBar immediately and removes it from its container. Notifies
- // the delegate that it has closed. The InfoBar is deleted after this function
- // is called.
- void Close();
-
- // Called when an InfoBar is added or removed from a view hierarchy to do
- // setup and shutdown.
- void InfoBarAdded();
- void InfoBarRemoved();
-
// Destroys the external focus tracker, if present. If |restore_focus| is
// true, restores focus to the view tracked by the focus tracker before doing
// so.
@@ -153,7 +149,7 @@ class InfoBarView : public InfoBar,
// The InfoBar's delegate.
InfoBarDelegate* delegate_;
- // The Close Button at the right edge of the InfoBar.
+ // The close button at the right edge of the InfoBar.
views::ImageButton* close_button_;
// The animation that runs when the InfoBar is opened or closed.
@@ -166,8 +162,8 @@ class InfoBarView : public InfoBar,
// Used to delete this object after a return to the message loop.
ScopedRunnableMethodFactory<InfoBarView> delete_factory_;
- // The target height for the InfoBar.
- double target_height_;
+ // The target height for the InfoBarView.
+ int target_height_;
DISALLOW_COPY_AND_ASSIGN(InfoBarView);
};
diff --git a/chrome/browser/ui/views/infobars/link_infobar.cc b/chrome/browser/ui/views/infobars/link_infobar.cc
index 973b977..7049e3d 100644
--- a/chrome/browser/ui/views/infobars/link_infobar.cc
+++ b/chrome/browser/ui/views/infobars/link_infobar.cc
@@ -10,20 +10,20 @@
#include "ui/base/resource/resource_bundle.h"
#include "views/controls/image_view.h"
-// LinkInfoBarDelegate, InfoBarDelegate overrides: -----------------------------
+// LinkInfoBarDelegate --------------------------------------------------------
InfoBar* LinkInfoBarDelegate::CreateInfoBar() {
return new LinkInfoBar(this);
}
-// LinkInfoBar, public: --------------------------------------------------------
+// LinkInfoBar ----------------------------------------------------------------
LinkInfoBar::LinkInfoBar(LinkInfoBarDelegate* delegate)
: InfoBarView(delegate),
icon_(new views::ImageView),
label_1_(new views::Label),
- label_2_(new views::Label),
- link_(new views::Link) {
+ link_(new views::Link),
+ label_2_(new views::Label) {
// Set up the icon.
if (delegate->GetIcon())
icon_->SetImage(delegate->GetIcon());
@@ -60,26 +60,13 @@ LinkInfoBar::LinkInfoBar(LinkInfoBarDelegate* delegate)
LinkInfoBar::~LinkInfoBar() {
}
-// LinkInfoBar, views::LinkController implementation: --------------------------
-
-void LinkInfoBar::LinkActivated(views::Link* source, int event_flags) {
- DCHECK(source == link_);
- if (GetDelegate()->LinkClicked(
- event_utils::DispositionFromEventFlags(event_flags))) {
- RemoveInfoBar();
- }
-}
-
-// LinkInfoBar, views::View overrides: -----------------------------------------
-
void LinkInfoBar::Layout() {
- // Layout the close button.
InfoBarView::Layout();
// Layout the icon.
- gfx::Size icon_ps = icon_->GetPreferredSize();
- icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_ps), icon_ps.width(),
- icon_ps.height());
+ gfx::Size icon_size = icon_->GetPreferredSize();
+ icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_size),
+ icon_size.width(), icon_size.height());
int label_1_x = icon_->bounds().right() + kIconLabelSpacing;
@@ -88,32 +75,37 @@ void LinkInfoBar::Layout() {
int available_width = GetAvailableWidth() - label_1_x;
// Layout the left label.
- gfx::Size label_1_ps = label_1_->GetPreferredSize();
- label_1_->SetBounds(label_1_x, OffsetY(this, label_1_ps), label_1_ps.width(),
- label_1_ps.height());
+ 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_ps = link_->GetPreferredSize();
+ 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_ps), link_ps.width(), link_ps.height());
+ 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_ps.width(),
- OffsetY(this, link_ps), link_ps.width(), link_ps.height());
+ 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).
- gfx::Size label_2_ps = label_2_->GetPreferredSize();
- label_2_->SetBounds(link_->bounds().right(),
- OffsetY(this, label_2_ps), label_2_ps.width(),
- label_2_ps.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());
}
-// LinkInfoBar, private: -------------------------------------------------------
+void LinkInfoBar::LinkActivated(views::Link* source, int event_flags) {
+ DCHECK(source == link_);
+ if (GetDelegate()->LinkClicked(
+ event_utils::DispositionFromEventFlags(event_flags))) {
+ RemoveInfoBar();
+ }
+}
LinkInfoBarDelegate* LinkInfoBar::GetDelegate() {
return delegate()->AsLinkInfoBarDelegate();
diff --git a/chrome/browser/ui/views/infobars/link_infobar.h b/chrome/browser/ui/views/infobars/link_infobar.h
index 1ca6bb7..6e8be356 100644
--- a/chrome/browser/ui/views/infobars/link_infobar.h
+++ b/chrome/browser/ui/views/infobars/link_infobar.h
@@ -16,21 +16,22 @@ class LinkInfoBar : public InfoBarView,
public views::LinkController {
public:
explicit LinkInfoBar(LinkInfoBarDelegate* delegate);
- virtual ~LinkInfoBar();
- // Overridden from views::LinkController:
- virtual void LinkActivated(views::Link* source, int event_flags);
+ private:
+ virtual ~LinkInfoBar();
- // Overridden from views::View:
+ // InfoBarView:
virtual void Layout();
- private:
+ // views::LinkController:
+ virtual void LinkActivated(views::Link* source, int event_flags);
+
LinkInfoBarDelegate* GetDelegate();
views::ImageView* icon_;
views::Label* label_1_;
- views::Label* label_2_;
views::Link* link_;
+ views::Label* label_2_;
DISALLOW_COPY_AND_ASSIGN(LinkInfoBar);
};
diff --git a/chrome/browser/ui/views/infobars/translate_infobar_base.cc b/chrome/browser/ui/views/infobars/translate_infobar_base.cc
index 4162401..2dbdacb 100644
--- a/chrome/browser/ui/views/infobars/translate_infobar_base.cc
+++ b/chrome/browser/ui/views/infobars/translate_infobar_base.cc
@@ -16,9 +16,33 @@
#include "ui/gfx/canvas_skia.h"
#include "views/controls/button/menu_button.h"
#include "views/controls/image_view.h"
+#include "views/controls/label.h"
-TranslateInfoBarBase::TranslateInfoBarBase(
- TranslateInfoBarDelegate* delegate)
+// TranslateInfoBarDelegate ---------------------------------------------------
+
+InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
+ TranslateInfoBarBase* infobar = NULL;
+ switch (type_) {
+ case BEFORE_TRANSLATE:
+ infobar = new BeforeTranslateInfoBar(this);
+ break;
+ case AFTER_TRANSLATE:
+ infobar = new AfterTranslateInfoBar(this);
+ break;
+ case TRANSLATING:
+ case TRANSLATION_ERROR:
+ infobar = new TranslateMessageInfoBar(this);
+ break;
+ default:
+ NOTREACHED();
+ }
+ infobar_view_ = infobar;
+ return infobar;
+}
+
+// TranslateInfoBarBase -------------------------------------------------------
+
+TranslateInfoBarBase::TranslateInfoBarBase(TranslateInfoBarDelegate* delegate)
: InfoBarView(delegate),
normal_background_(InfoBarDelegate::PAGE_ACTION_TYPE),
error_background_(InfoBarDelegate::WARNING_TYPE) {
@@ -28,37 +52,24 @@ TranslateInfoBarBase::TranslateInfoBarBase(
icon_->SetImage(image);
AddChildView(icon_);
+ background_color_animation_.reset(new ui::SlideAnimation(this));
+ background_color_animation_->SetTweenType(ui::Tween::LINEAR);
+ background_color_animation_->SetSlideDuration(500);
TranslateInfoBarDelegate::BackgroundAnimationType animation =
- delegate->background_animation_type();
- if (animation != TranslateInfoBarDelegate::NONE) {
- background_color_animation_.reset(new ui::SlideAnimation(this));
- background_color_animation_->SetTweenType(ui::Tween::LINEAR);
- background_color_animation_->SetSlideDuration(500);
- if (animation == TranslateInfoBarDelegate::NORMAL_TO_ERROR) {
- background_color_animation_->Show();
- } else {
- DCHECK_EQ(TranslateInfoBarDelegate::ERROR_TO_NORMAL, animation);
- // Hide() runs the animation in reverse.
- background_color_animation_->Reset(1.0);
- background_color_animation_->Hide();
- }
+ GetDelegate()->background_animation_type();
+ if (animation == TranslateInfoBarDelegate::NORMAL_TO_ERROR) {
+ background_color_animation_->Show();
+ } else if (animation == TranslateInfoBarDelegate::ERROR_TO_NORMAL) {
+ // Hide() runs the animation in reverse.
+ background_color_animation_->Reset(1.0);
+ background_color_animation_->Hide();
}
}
TranslateInfoBarBase::~TranslateInfoBarBase() {
}
-// Overridden from views::View:
-void TranslateInfoBarBase::Layout() {
- // Layout the close button.
- InfoBarView::Layout();
-
- // Layout the icon on left of bar.
- gfx::Size icon_ps = icon_->GetPreferredSize();
- icon_->SetBounds(InfoBarView::kHorizontalPadding,
- InfoBarView::OffsetY(this, icon_ps), icon_ps.width(), icon_ps.height());
-}
-
+// static
views::Label* TranslateInfoBarBase::CreateLabel(const string16& text) {
views::Label* label = new views::Label(UTF16ToWideHack(text),
ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont));
@@ -67,27 +78,7 @@ views::Label* TranslateInfoBarBase::CreateLabel(const string16& text) {
return label;
}
-void TranslateInfoBarBase::PaintBackground(gfx::Canvas* canvas) {
- // If we're not animating, simply paint the background for the current state.
- if (background_color_animation_ == NULL ||
- !background_color_animation_->is_animating()) {
- GetBackground().Paint(canvas, this);
- return;
- }
-
- FadeBackground(canvas, 1.0 - background_color_animation_->GetCurrentValue(),
- normal_background_);
- FadeBackground(canvas, background_color_animation_->GetCurrentValue(),
- error_background_);
-}
-
-void TranslateInfoBarBase::AnimationProgressed(const ui::Animation* animation) {
- if (background_color_animation_.get() == animation)
- SchedulePaint(); // That'll trigger a PaintBackgroud.
- else
- InfoBarView::AnimationProgressed(animation);
-}
-
+// static
views::MenuButton* TranslateInfoBarBase::CreateMenuButton(
const string16& text,
bool normal_has_border,
@@ -118,34 +109,45 @@ views::MenuButton* TranslateInfoBarBase::CreateMenuButton(
return menu_button;
}
-gfx::Point TranslateInfoBarBase::DetermineMenuPosition(
- views::MenuButton* menu_button) {
- gfx::Rect lb = menu_button->GetContentsBounds();
- gfx::Point menu_position(lb.origin());
- menu_position.Offset(2, lb.height() - 3);
- if (base::i18n::IsRTL())
- menu_position.Offset(lb.width() - 4, 0);
-
- View::ConvertPointToScreen(menu_button, &menu_position);
-#if defined(OS_WIN)
- int left_bound = GetSystemMetrics(SM_XVIRTUALSCREEN);
- if (menu_position.x() < left_bound)
- menu_position.set_x(left_bound);
-#endif
- return menu_position;
+void TranslateInfoBarBase::Layout() {
+ InfoBarView::Layout();
+
+ gfx::Size icon_size = icon_->GetPreferredSize();
+ icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_size),
+ icon_size.width(), icon_size.height());
}
-TranslateInfoBarDelegate* TranslateInfoBarBase::GetDelegate() const {
- return static_cast<TranslateInfoBarDelegate*>(delegate());
+TranslateInfoBarDelegate* TranslateInfoBarBase::GetDelegate() {
+ return delegate()->AsTranslateInfoBarDelegate();
+}
+
+void TranslateInfoBarBase::PaintBackground(gfx::Canvas* canvas) {
+ // If we're not animating, simply paint the background for the current state.
+ if (!background_color_animation_->is_animating()) {
+ GetBackground().Paint(canvas, this);
+ return;
+ }
+
+ FadeBackground(canvas, 1.0 - background_color_animation_->GetCurrentValue(),
+ normal_background_);
+ FadeBackground(canvas, background_color_animation_->GetCurrentValue(),
+ error_background_);
}
-const InfoBarBackground& TranslateInfoBarBase::GetBackground() const {
+void TranslateInfoBarBase::AnimationProgressed(const ui::Animation* animation) {
+ if (animation == background_color_animation_.get())
+ SchedulePaint(); // That'll trigger a PaintBackgroud.
+ else
+ InfoBarView::AnimationProgressed(animation);
+}
+
+const views::Background& TranslateInfoBarBase::GetBackground() {
return GetDelegate()->IsError() ? error_background_ : normal_background_;
}
void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas,
double animation_value,
- const InfoBarBackground& background) {
+ const views::Background& background) {
// Draw the background into an offscreen buffer with alpha value per animation
// value, then blend it back into the current canvas.
canvas->SaveLayerAlpha(static_cast<int>(animation_value * 255));
@@ -153,26 +155,3 @@ void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas,
background.Paint(canvas, this);
canvas->Restore();
}
-
-// TranslateInfoBarDelegate views specific method:
-InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
- TranslateInfoBarBase* infobar = NULL;
- switch (type_) {
- case BEFORE_TRANSLATE:
- infobar = new BeforeTranslateInfoBar(this);
- break;
- case AFTER_TRANSLATE:
- infobar = new AfterTranslateInfoBar(this);
- break;
- case TRANSLATING:
- case TRANSLATION_ERROR:
- infobar = new TranslateMessageInfoBar(this);
- break;
- default:
- NOTREACHED();
- }
- // Set |infobar_view_| so that the model can notify the infobar when it
- // changes.
- infobar_view_ = infobar;
- return infobar;
-}
diff --git a/chrome/browser/ui/views/infobars/translate_infobar_base.h b/chrome/browser/ui/views/infobars/translate_infobar_base.h
index 16daf32..d6d8255 100644
--- a/chrome/browser/ui/views/infobars/translate_infobar_base.h
+++ b/chrome/browser/ui/views/infobars/translate_infobar_base.h
@@ -25,50 +25,43 @@ class TranslateInfoBarBase : public TranslateInfoBarView,
explicit TranslateInfoBarBase(TranslateInfoBarDelegate* delegate);
virtual ~TranslateInfoBarBase();
- // TranslateInfoBarView implementation:
- virtual void OriginalLanguageChanged() {}
- virtual void TargetLanguageChanged() {}
-
- // Overridden from views::View:
- virtual void Layout();
- virtual void PaintBackground(gfx::Canvas* canvas);
-
protected:
- // Overridden from ui::AnimationDelegate:
- virtual void AnimationProgressed(const ui::Animation* animation);
-
// Creates a label with the appropriate font and color for the translate
// infobars.
- views::Label* CreateLabel(const string16& text);
+ static views::Label* CreateLabel(const string16& text);
// Creates a menu-button with a custom appearance for the translate infobars.
- views::MenuButton* CreateMenuButton(const string16& text,
- bool normal_has_border,
- views::ViewMenuDelegate* menu_delegate);
+ static views::MenuButton* CreateMenuButton(
+ const string16& text,
+ bool normal_has_border,
+ views::ViewMenuDelegate* menu_delegate);
- // Returns the location at which the menu triggered by |menu_button| should be
- // positioned.
- gfx::Point DetermineMenuPosition(views::MenuButton* menu_button);
+ // InfoBarView:
+ virtual void Layout();
// Convenience to retrieve the TranslateInfoBarDelegate for this infobar.
- TranslateInfoBarDelegate* GetDelegate() const;
+ TranslateInfoBarDelegate* GetDelegate();
// The translate icon.
views::ImageView* icon_;
- InfoBarBackground normal_background_;
- InfoBarBackground error_background_;
- scoped_ptr<ui::SlideAnimation> background_color_animation_;
-
private:
+ // InfoBarView:
+ virtual void PaintBackground(gfx::Canvas* canvas);
+ virtual void AnimationProgressed(const ui::Animation* animation);
+
// Returns the background that should be displayed when not animating.
- const InfoBarBackground& GetBackground() const;
+ const views::Background& GetBackground();
// Paints |background| to |canvas| with the opacity level based on
// |animation_value|.
void FadeBackground(gfx::Canvas* canvas,
double animation_value,
- const InfoBarBackground& background);
+ const views::Background& background);
+
+ InfoBarBackground normal_background_;
+ InfoBarBackground error_background_;
+ scoped_ptr<ui::SlideAnimation> background_color_animation_;
DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarBase);
};
diff --git a/chrome/browser/ui/views/infobars/translate_message_infobar.cc b/chrome/browser/ui/views/infobars/translate_message_infobar.cc
index 7abff8f..47ead3c 100644
--- a/chrome/browser/ui/views/infobars/translate_message_infobar.cc
+++ b/chrome/browser/ui/views/infobars/translate_message_infobar.cc
@@ -11,48 +11,45 @@
TranslateMessageInfoBar::TranslateMessageInfoBar(
TranslateInfoBarDelegate* delegate)
- : TranslateInfoBarBase(delegate) {
+ : TranslateInfoBarBase(delegate),
+ button_(NULL) {
label_ = CreateLabel(delegate->GetMessageInfoBarText());
AddChildView(label_);
string16 button_text = delegate->GetMessageInfoBarButtonText();
- if (button_text.empty()) {
- button_ = NULL;
- } else {
+ if (!button_text.empty()) {
button_ = InfoBarTextButton::Create(this, button_text);
AddChildView(button_);
}
}
+TranslateMessageInfoBar::~TranslateMessageInfoBar() {
+}
+
void TranslateMessageInfoBar::Layout() {
TranslateInfoBarBase::Layout();
- int x = icon_->bounds().right() + InfoBarView::kIconLabelSpacing;
- gfx::Size label_pref_size = label_->GetPreferredSize();
+ int x = icon_->bounds().right() + kIconLabelSpacing;
+ gfx::Size label_size = label_->GetPreferredSize();
int available_width = GetAvailableWidth() - x;
- gfx::Size button_pref_size;
+ gfx::Size button_size;
if (button_) {
- button_pref_size = button_->GetPreferredSize();
- available_width -=
- (button_pref_size.width() + InfoBarView::kButtonInLabelSpacing);
+ button_size = button_->GetPreferredSize();
+ available_width -= (button_size.width() + kButtonInLabelSpacing);
}
- label_->SetBounds(x, InfoBarView::OffsetY(this, label_pref_size),
- std::min(label_pref_size.width(), available_width),
- label_pref_size.height());
+ label_->SetBounds(x, OffsetY(this, label_size),
+ std::min(label_size.width(), available_width), label_size.height());
if (button_) {
- button_->SetBounds(label_->bounds().right() +
- InfoBarView::kButtonInLabelSpacing,
- InfoBarView::OffsetY(this, button_pref_size),
- button_pref_size.width(), button_pref_size.height());
+ button_->SetBounds(label_->bounds().right() + kButtonInLabelSpacing,
+ OffsetY(this, button_size), button_size.width(), button_size.height());
}
}
void TranslateMessageInfoBar::ButtonPressed(views::Button* sender,
const views::Event& event) {
- if (sender == button_) {
+ if (sender == button_)
GetDelegate()->MessageInfoBarButtonPressed();
- return;
- }
- TranslateInfoBarBase::ButtonPressed(sender, event);
+ else
+ TranslateInfoBarBase::ButtonPressed(sender, event);
}
diff --git a/chrome/browser/ui/views/infobars/translate_message_infobar.h b/chrome/browser/ui/views/infobars/translate_message_infobar.h
index 6f5fa72..a29122d 100644
--- a/chrome/browser/ui/views/infobars/translate_message_infobar.h
+++ b/chrome/browser/ui/views/infobars/translate_message_infobar.h
@@ -14,12 +14,13 @@ class TranslateMessageInfoBar : public TranslateInfoBarBase {
public:
explicit TranslateMessageInfoBar(TranslateInfoBarDelegate* delegate);
- virtual void Layout();
+ private:
+ virtual ~TranslateMessageInfoBar();
- // views::ButtonListener implementation:
+ // TranslateInfoBarBase:
+ virtual void Layout();
virtual void ButtonPressed(views::Button* sender, const views::Event& event);
- private:
views::Label* label_;
InfoBarTextButton* button_;