| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ |
| 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ | 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "chrome/browser/infobars/infobar_delegate.h" | 14 #include "chrome/browser/infobars/infobar_delegate.h" |
| 15 #include "chrome/browser/translate/translate_prefs.h" | 15 #include "chrome/browser/translate/translate_prefs.h" |
| 16 #include "chrome/browser/translate/translate_ui_delegate.h" |
| 16 #include "chrome/common/chrome_constants.h" | 17 #include "chrome/common/chrome_constants.h" |
| 17 #include "chrome/common/translate/translate_errors.h" | 18 #include "chrome/common/translate/translate_errors.h" |
| 18 | 19 |
| 19 class PrefService; | 20 class PrefService; |
| 20 | 21 |
| 21 // The defaults after which extra shortcuts for options | 22 // The defaults after which extra shortcuts for options |
| 22 // can be shown. | 23 // can be shown. |
| 23 struct ShortcutConfiguration { | 24 struct ShortcutConfiguration { |
| 24 int always_translate_min_count; | 25 int always_translate_min_count; |
| 25 int never_translate_min_count; | 26 int never_translate_min_count; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 static void Create(bool replace_existing_infobar, | 63 static void Create(bool replace_existing_infobar, |
| 63 InfoBarService* infobar_service, | 64 InfoBarService* infobar_service, |
| 64 Type infobar_type, | 65 Type infobar_type, |
| 65 const std::string& original_language, | 66 const std::string& original_language, |
| 66 const std::string& target_language, | 67 const std::string& target_language, |
| 67 TranslateErrors::Type error_type, | 68 TranslateErrors::Type error_type, |
| 68 PrefService* prefs, | 69 PrefService* prefs, |
| 69 const ShortcutConfiguration& shortcut_config); | 70 const ShortcutConfiguration& shortcut_config); |
| 70 | 71 |
| 71 // Returns the number of languages supported. | 72 // Returns the number of languages supported. |
| 72 size_t num_languages() const { return languages_.size(); } | 73 size_t num_languages() const { return ui_delegate_.num_languages(); } |
| 73 | 74 |
| 74 // Returns the ISO code for the language at |index|. | 75 // Returns the ISO code for the language at |index|. |
| 75 std::string language_code_at(size_t index) const { | 76 std::string language_code_at(size_t index) const { |
| 76 DCHECK_LT(index, num_languages()); | 77 return ui_delegate_.language_code_at(index); |
| 77 return languages_[index].first; | |
| 78 } | 78 } |
| 79 | 79 |
| 80 // Returns the displayable name for the language at |index|. | 80 // Returns the displayable name for the language at |index|. |
| 81 string16 language_name_at(size_t index) const { | 81 string16 language_name_at(size_t index) const { |
| 82 if (index == kNoIndex) | 82 return ui_delegate_.language_name_at(index); |
| 83 return string16(); | |
| 84 DCHECK_LT(index, num_languages()); | |
| 85 return languages_[index].second; | |
| 86 } | 83 } |
| 87 | 84 |
| 88 Type infobar_type() const { return infobar_type_; } | 85 Type infobar_type() const { return infobar_type_; } |
| 89 | 86 |
| 90 TranslateErrors::Type error_type() const { return error_type_; } | 87 TranslateErrors::Type error_type() const { return error_type_; } |
| 91 | 88 |
| 92 size_t original_language_index() const { return original_language_index_; } | 89 size_t original_language_index() const { |
| 90 return ui_delegate_.original_language_index(); |
| 91 } |
| 93 void set_original_language_index(size_t language_index) { | 92 void set_original_language_index(size_t language_index) { |
| 94 DCHECK_LT(language_index, num_languages()); | 93 ui_delegate_.set_original_language_index(language_index); |
| 95 original_language_index_ = language_index; | |
| 96 } | 94 } |
| 97 size_t target_language_index() const { return target_language_index_; } | 95 size_t target_language_index() const { |
| 96 return ui_delegate_.target_language_index(); |
| 97 } |
| 98 void set_target_language_index(size_t language_index) { | 98 void set_target_language_index(size_t language_index) { |
| 99 DCHECK_LT(language_index, num_languages()); | 99 ui_delegate_.set_target_language_index(language_index); |
| 100 target_language_index_ = language_index; | |
| 101 } | 100 } |
| 102 | 101 |
| 103 // Convenience methods. | 102 // Convenience methods. |
| 104 std::string original_language_code() const { | 103 std::string original_language_code() const { |
| 105 return (original_language_index() == kNoIndex) ? | 104 return ui_delegate_.original_language_code(); |
| 106 chrome::kUnknownLanguageCode : | |
| 107 language_code_at(original_language_index()); | |
| 108 } | 105 } |
| 109 std::string target_language_code() const { | 106 std::string target_language_code() const { |
| 110 return language_code_at(target_language_index()); | 107 return ui_delegate_.target_language_code(); |
| 111 } | 108 } |
| 112 | 109 |
| 113 // Returns true if the current infobar indicates an error (in which case it | 110 // Returns true if the current infobar indicates an error (in which case it |
| 114 // should get a yellow background instead of a blue one). | 111 // should get a yellow background instead of a blue one). |
| 115 bool is_error() const { return infobar_type_ == TRANSLATION_ERROR; } | 112 bool is_error() const { return infobar_type_ == TRANSLATION_ERROR; } |
| 116 | 113 |
| 117 // Returns what kind of background fading effect the infobar should use when | 114 // Returns what kind of background fading effect the infobar should use when |
| 118 // its is shown. | 115 // its is shown. |
| 119 BackgroundAnimationType background_animation_type() const { | 116 BackgroundAnimationType background_animation_type() const { |
| 120 return background_animation_; | 117 return background_animation_; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 | 189 |
| 193 // InfoBarDelegate: | 190 // InfoBarDelegate: |
| 194 virtual InfoBar* CreateInfoBar(InfoBarService* infobar_service) OVERRIDE; | 191 virtual InfoBar* CreateInfoBar(InfoBarService* infobar_service) OVERRIDE; |
| 195 virtual void InfoBarDismissed() OVERRIDE; | 192 virtual void InfoBarDismissed() OVERRIDE; |
| 196 virtual int GetIconID() const OVERRIDE; | 193 virtual int GetIconID() const OVERRIDE; |
| 197 virtual InfoBarDelegate::Type GetInfoBarType() const OVERRIDE; | 194 virtual InfoBarDelegate::Type GetInfoBarType() const OVERRIDE; |
| 198 virtual bool ShouldExpire( | 195 virtual bool ShouldExpire( |
| 199 const content::LoadCommittedDetails& details) const OVERRIDE; | 196 const content::LoadCommittedDetails& details) const OVERRIDE; |
| 200 virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate() OVERRIDE; | 197 virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate() OVERRIDE; |
| 201 | 198 |
| 202 // Gets the host of the page being translated, or an empty string if no URL is | |
| 203 // associated with the current page. | |
| 204 std::string GetPageHost(); | |
| 205 | |
| 206 Type infobar_type_; | 199 Type infobar_type_; |
| 207 | 200 |
| 208 // The type of fading animation if any that should be used when showing this | 201 // The type of fading animation if any that should be used when showing this |
| 209 // infobar. | 202 // infobar. |
| 210 BackgroundAnimationType background_animation_; | 203 BackgroundAnimationType background_animation_; |
| 211 | 204 |
| 212 // The list supported languages for translation. | 205 TranslateUIDelegate ui_delegate_; |
| 213 // The pair first string is the language ISO code (ex: en, fr...), the second | |
| 214 // string is the displayable name on the current locale. | |
| 215 // The languages are sorted alphabetically based on the displayable name. | |
| 216 std::vector<LanguageNamePair> languages_; | |
| 217 | |
| 218 // The index for language the page is originally in. | |
| 219 size_t original_language_index_; | |
| 220 | |
| 221 // The index for language the page is originally in that was originally | |
| 222 // reported (original_language_index_ changes if the user selects a new | |
| 223 // original language, but this one does not). This is necessary to report | |
| 224 // language detection errors with the right original language even if the user | |
| 225 // changed the original language. | |
| 226 size_t initial_original_language_index_; | |
| 227 | |
| 228 // The index for language the page should be translated to. | |
| 229 size_t target_language_index_; | |
| 230 | 206 |
| 231 // The error that occurred when trying to translate (NONE if no error). | 207 // The error that occurred when trying to translate (NONE if no error). |
| 232 TranslateErrors::Type error_type_; | 208 TranslateErrors::Type error_type_; |
| 233 | 209 |
| 234 // The translation related preferences. | 210 // The translation related preferences. |
| 235 TranslatePrefs prefs_; | 211 TranslatePrefs prefs_; |
| 236 | 212 |
| 237 // Translation shortcut configuration | 213 // Translation shortcut configuration |
| 238 ShortcutConfiguration shortcut_config_; | 214 ShortcutConfiguration shortcut_config_; |
| 239 DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate); | 215 DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate); |
| 240 }; | 216 }; |
| 241 | 217 |
| 242 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ | 218 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ |
| OLD | NEW |