summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authorjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-29 18:45:02 +0000
committerjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-29 18:45:02 +0000
commit80ea37d8369d4c6dc5a3fc64271762f97092629b (patch)
tree49c874a70cc004393afe1cfe233f441ddd4fa151 /chrome/browser/views
parent2e1e8b56450c4cc0e4b5e5931a13aeea4d1d9922 (diff)
downloadchromium_src-80ea37d8369d4c6dc5a3fc64271762f97092629b.zip
chromium_src-80ea37d8369d4c6dc5a3fc64271762f97092629b.tar.gz
chromium_src-80ea37d8369d4c6dc5a3fc64271762f97092629b.tar.bz2
Translate infobar always/never translate buttons
Adding extra buttons on the translate infobar to let user easily set the "never/always translate this language" property when they declined/accepted translation for a language more than 3 times. Original review: http://codereview.chromium.org/2825015/show BUG=NONE TEST=Visit a page in a foreign language, translate the page. Repeat 4 times. On the fourth time, the "before translate" infobar should show a button that says "always translate". Similarly when declining translations 4 times. Review URL: http://codereview.chromium.org/2835025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51148 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/infobars/before_translate_infobar.cc37
-rw-r--r--chrome/browser/views/infobars/before_translate_infobar.h2
-rw-r--r--chrome/browser/views/infobars/infobar_text_button.cc7
-rw-r--r--chrome/browser/views/infobars/infobar_text_button.h2
4 files changed, 48 insertions, 0 deletions
diff --git a/chrome/browser/views/infobars/before_translate_infobar.cc b/chrome/browser/views/infobars/before_translate_infobar.cc
index 7f65180..a06a586 100644
--- a/chrome/browser/views/infobars/before_translate_infobar.cc
+++ b/chrome/browser/views/infobars/before_translate_infobar.cc
@@ -18,6 +18,8 @@
BeforeTranslateInfoBar::BeforeTranslateInfoBar(
TranslateInfoBarDelegate2* delegate)
: TranslateInfoBarBase(delegate),
+ never_translate_button_(NULL),
+ always_translate_button_(NULL),
languages_menu_model_(delegate, LanguagesMenuModel2::ORIGINAL),
options_menu_model_(delegate) {
size_t offset = 0;
@@ -49,6 +51,22 @@ BeforeTranslateInfoBar::BeforeTranslateInfoBar(
false, this);
AddChildView(options_menu_button_);
+ 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());
+ always_translate_button_ = InfoBarTextButton::CreateWithMessageIDAndParam(
+ this, IDS_TRANSLATE_INFOBAR_ALWAYS_TRANSLATE, language);
+ AddChildView(always_translate_button_);
+ }
+
UpdateOriginalButtonText();
}
@@ -89,6 +107,20 @@ void BeforeTranslateInfoBar::Layout() {
deny_button_->SetBounds(
accept_button_->bounds().right() + InfoBar::kButtonButtonSpacing,
OffsetY(this, pref_size), pref_size.width(), pref_size.height());
+
+ if (never_translate_button_) {
+ pref_size = never_translate_button_->GetPreferredSize();
+ never_translate_button_->SetBounds(
+ deny_button_->bounds().right() + InfoBar::kButtonButtonSpacing,
+ OffsetY(this, pref_size), pref_size.width(), pref_size.height());
+ }
+ if (always_translate_button_) {
+ DCHECK(!never_translate_button_);
+ pref_size = always_translate_button_->GetPreferredSize();
+ always_translate_button_->SetBounds(
+ deny_button_->bounds().right() + InfoBar::kButtonButtonSpacing,
+ OffsetY(this, pref_size), pref_size.width(), pref_size.height());
+ }
}
void BeforeTranslateInfoBar::ButtonPressed(views::Button* sender,
@@ -97,6 +129,11 @@ void BeforeTranslateInfoBar::ButtonPressed(views::Button* sender,
GetDelegate()->Translate();
} else if (sender == deny_button_) {
RemoveInfoBar();
+ GetDelegate()->TranslationDeclined();
+ } else if (sender == never_translate_button_) {
+ GetDelegate()->NeverTranslatePageLanguage();
+ } else if (sender == always_translate_button_) {
+ GetDelegate()->AlwaysTranslatePageLanguage();
} else {
TranslateInfoBarBase::ButtonPressed(sender, event);
}
diff --git a/chrome/browser/views/infobars/before_translate_infobar.h b/chrome/browser/views/infobars/before_translate_infobar.h
index 610fa0e..a89a6f2 100644
--- a/chrome/browser/views/infobars/before_translate_infobar.h
+++ b/chrome/browser/views/infobars/before_translate_infobar.h
@@ -63,6 +63,8 @@ class BeforeTranslateInfoBar
views::MenuButton* options_menu_button_;
InfoBarTextButton* accept_button_;
InfoBarTextButton* deny_button_;
+ InfoBarTextButton* never_translate_button_;
+ InfoBarTextButton* always_translate_button_;
scoped_ptr<views::Menu2> languages_menu_;
LanguagesMenuModel2 languages_menu_model_;
diff --git a/chrome/browser/views/infobars/infobar_text_button.cc b/chrome/browser/views/infobars/infobar_text_button.cc
index 35726d0..ebf5d22 100644
--- a/chrome/browser/views/infobars/infobar_text_button.cc
+++ b/chrome/browser/views/infobars/infobar_text_button.cc
@@ -22,6 +22,13 @@ InfoBarTextButton* InfoBarTextButton::CreateWithMessageID(
l10n_util::GetStringUTF16(message_id));
}
+// static
+InfoBarTextButton* InfoBarTextButton::CreateWithMessageIDAndParam(
+ views::ButtonListener* listener, int message_id, const string16& param) {
+ return new InfoBarTextButton(listener,
+ l10n_util::GetStringFUTF16(message_id, param));
+}
+
InfoBarTextButton::~InfoBarTextButton() {
}
diff --git a/chrome/browser/views/infobars/infobar_text_button.h b/chrome/browser/views/infobars/infobar_text_button.h
index 698d2a4..221b5de 100644
--- a/chrome/browser/views/infobars/infobar_text_button.h
+++ b/chrome/browser/views/infobars/infobar_text_button.h
@@ -19,6 +19,8 @@ class InfoBarTextButton : public views::TextButton {
// |message_id|.
static InfoBarTextButton* CreateWithMessageID(views::ButtonListener* listener,
int message_id);
+ static InfoBarTextButton* CreateWithMessageIDAndParam(
+ views::ButtonListener* listener, int message_id, const string16& param);
virtual ~InfoBarTextButton();