summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorkuan@chromium.org <kuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-03 17:21:50 +0000
committerkuan@chromium.org <kuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-03 17:21:50 +0000
commit5e90f82f1121ec44022d60f3645c8105cc8a6271 (patch)
tree7ea2bb9574b57514eab65121b427e3d16641bd02 /chrome
parent79a087a3332e71e674d954a868244f671ab22a22 (diff)
downloadchromium_src-5e90f82f1121ec44022d60f3645c8105cc8a6271.zip
chromium_src-5e90f82f1121ec44022d60f3645c8105cc8a6271.tar.gz
chromium_src-5e90f82f1121ec44022d60f3645c8105cc8a6271.tar.bz2
a little code cleanup for translate infobars
- use index of selected language menu item (which corresponds to index in array of languages) to check if selection has changed; was retrieving, converting and comparing text, which is more expensive and slower - only call backend to translate when source and target languages are different BUG=31297 TEST=verify that selection of languages in translate infobars still work as expected. Review URL: http://codereview.chromium.org/563018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37979 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/translate/translate_infobars_delegates.cc3
-rw-r--r--chrome/browser/translate/translate_infobars_delegates.h6
-rw-r--r--chrome/browser/views/infobars/translate_infobars.cc15
3 files changed, 17 insertions, 7 deletions
diff --git a/chrome/browser/translate/translate_infobars_delegates.cc b/chrome/browser/translate/translate_infobars_delegates.cc
index 3dba0ca..7bf2a4f 100644
--- a/chrome/browser/translate/translate_infobars_delegates.cc
+++ b/chrome/browser/translate/translate_infobars_delegates.cc
@@ -53,7 +53,8 @@ void TranslateInfoBarDelegate::GetAvailableTargetLanguages(
}
void TranslateInfoBarDelegate::Translate() {
- tab_contents_->TranslatePage(original_lang_code(), target_lang_code());
+ if (original_lang_index_ != target_lang_index_)
+ tab_contents_->TranslatePage(original_lang_code(), target_lang_code());
}
bool TranslateInfoBarDelegate::IsLanguageBlacklisted() {
diff --git a/chrome/browser/translate/translate_infobars_delegates.h b/chrome/browser/translate/translate_infobars_delegates.h
index 18416c4..5b10f3f 100644
--- a/chrome/browser/translate/translate_infobars_delegates.h
+++ b/chrome/browser/translate/translate_infobars_delegates.h
@@ -28,6 +28,12 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
virtual bool ShouldAlwaysTranslate();
virtual void ToggleAlwaysTranslate();
+ int original_lang_index() const {
+ return original_lang_index_;
+ }
+ int target_lang_index() const {
+ return target_lang_index_;
+ }
const std::string& original_lang_code() const {
return supported_languages_[original_lang_index_];
}
diff --git a/chrome/browser/views/infobars/translate_infobars.cc b/chrome/browser/views/infobars/translate_infobars.cc
index c65bea4..d20d844 100644
--- a/chrome/browser/views/infobars/translate_infobars.cc
+++ b/chrome/browser/views/infobars/translate_infobars.cc
@@ -455,15 +455,18 @@ gfx::Point TranslateInfoBar::DetermineMenuPositionAndAlignment(
void TranslateInfoBar::OnLanguageModified(views::MenuButton* menu_button,
int new_language_index) {
// Only proceed if a different language has been selected.
- string16 new_language = TranslateInfoBarDelegate::GetDisplayNameForLocale(
- GetDelegate()->GetLocaleFromIndex(new_language_index));
- if (new_language == WideToUTF16(menu_button->text()))
- return;
- if (menu_button == original_language_menu_button_)
+ if (menu_button == original_language_menu_button_) {
+ if (new_language_index == GetDelegate()->original_lang_index())
+ return;
GetDelegate()->ModifyOriginalLanguage(new_language_index);
- else
+ } else {
+ if (new_language_index == GetDelegate()->target_lang_index())
+ return;
GetDelegate()->ModifyTargetLanguage(new_language_index);
+ }
+ string16 new_language = TranslateInfoBarDelegate::GetDisplayNameForLocale(
+ GetDelegate()->GetLocaleFromIndex(new_language_index));
menu_button->SetText(UTF16ToWideHack(new_language));
menu_button->ClearMaxTextSize();
menu_button->SizeToPreferredSize();