Chromium Code Reviews| 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" | |
| 17 #include "chrome/common/translate/translate_errors.h" | 16 #include "chrome/common/translate/translate_errors.h" |
| 18 #include "components/translate/common/translate_constants.h" | 17 #include "components/translate/common/translate_constants.h" |
| 19 | 18 |
| 20 class PrefService; | 19 class PrefService; |
| 21 | 20 |
| 22 // The defaults after which extra shortcuts for options | 21 // The defaults after which extra shortcuts for options |
| 23 // can be shown. | 22 // can be shown. |
| 24 struct ShortcutConfiguration { | 23 struct ShortcutConfiguration { |
| 25 int always_translate_min_count; | 24 int always_translate_min_count; |
| 26 int never_translate_min_count; | 25 int never_translate_min_count; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 static void Create(bool replace_existing_infobar, | 62 static void Create(bool replace_existing_infobar, |
| 64 InfoBarService* infobar_service, | 63 InfoBarService* infobar_service, |
| 65 Type infobar_type, | 64 Type infobar_type, |
| 66 const std::string& original_language, | 65 const std::string& original_language, |
| 67 const std::string& target_language, | 66 const std::string& target_language, |
| 68 TranslateErrors::Type error_type, | 67 TranslateErrors::Type error_type, |
| 69 PrefService* prefs, | 68 PrefService* prefs, |
| 70 const ShortcutConfiguration& shortcut_config); | 69 const ShortcutConfiguration& shortcut_config); |
| 71 | 70 |
| 72 // Returns the number of languages supported. | 71 // Returns the number of languages supported. |
| 73 size_t num_languages() const { return ui_delegate_.GetNumberOfLanguages(); } | 72 size_t num_languages() const { |
| 73 // Note: TranslateUIDelegate should be updated if this implementation is | |
| 74 // updated. | |
|
Peter Kasting
2013/11/08 23:47:47
Let's not put these comments into every function i
hajimehoshi
2013/11/11 04:01:02
Done.
| |
| 75 return languages_.size(); | |
| 76 } | |
| 74 | 77 |
| 75 // Returns the ISO code for the language at |index|. | 78 // Returns the ISO code for the language at |index|. |
| 76 std::string language_code_at(size_t index) const { | 79 std::string language_code_at(size_t index) const { |
| 77 return ui_delegate_.GetLanguageCodeAt(index); | 80 // Note: TranslateUIDelegate should be updated if this implementation is |
| 81 // updated. | |
| 82 DCHECK_LT(index, num_languages()); | |
| 83 return languages_[index].first; | |
| 78 } | 84 } |
| 79 | 85 |
| 80 // Returns the displayable name for the language at |index|. | 86 // Returns the displayable name for the language at |index|. |
| 81 string16 language_name_at(size_t index) const { | 87 string16 language_name_at(size_t index) const { |
| 82 return ui_delegate_.GetLanguageNameAt(index); | 88 // Note: TranslateUIDelegate should be updated if this implementation is |
| 89 // updated. | |
| 90 if (index == static_cast<size_t>(kNoIndex)) | |
| 91 return string16(); | |
| 92 DCHECK_LT(index, num_languages()); | |
| 93 return languages_[index].second; | |
| 83 } | 94 } |
| 84 | 95 |
| 85 Type infobar_type() const { return infobar_type_; } | 96 Type infobar_type() const { return infobar_type_; } |
| 86 | 97 |
| 87 TranslateErrors::Type error_type() const { return error_type_; } | 98 TranslateErrors::Type error_type() const { return error_type_; } |
| 88 | 99 |
| 89 size_t original_language_index() const { | 100 size_t original_language_index() const { return original_language_index_; } |
| 90 return ui_delegate_.GetOriginalLanguageIndex(); | 101 |
| 91 } | |
| 92 void UpdateOriginalLanguageIndex(size_t language_index); | 102 void UpdateOriginalLanguageIndex(size_t language_index); |
| 93 | 103 |
| 94 size_t target_language_index() const { | 104 size_t target_language_index() const { return target_language_index_; } |
| 95 return ui_delegate_.GetTargetLanguageIndex(); | 105 |
| 96 } | |
| 97 void UpdateTargetLanguageIndex(size_t language_index); | 106 void UpdateTargetLanguageIndex(size_t language_index); |
| 98 | 107 |
| 99 // Convenience methods. | 108 // Convenience methods. |
| 100 std::string original_language_code() const { | 109 std::string original_language_code() const { |
| 101 return ui_delegate_.GetOriginalLanguageCode(); | 110 // Note: TranslateUIDelegate should be updated if this implementation is |
| 111 // updated. | |
| 112 return (original_language_index() == static_cast<size_t>(kNoIndex)) ? | |
| 113 translate::kUnknownLanguageCode : | |
| 114 language_code_at(original_language_index()); | |
| 102 } | 115 } |
| 103 std::string target_language_code() const { | 116 std::string target_language_code() const { |
| 104 return ui_delegate_.GetTargetLanguageCode(); | 117 // Note: TranslateUIDelegate should be updated if this implementation is |
| 118 // updated. | |
| 119 return language_code_at(target_language_index()); | |
| 105 } | 120 } |
| 106 | 121 |
| 107 // Returns true if the current infobar indicates an error (in which case it | 122 // Returns true if the current infobar indicates an error (in which case it |
| 108 // should get a yellow background instead of a blue one). | 123 // should get a yellow background instead of a blue one). |
| 109 bool is_error() const { return infobar_type_ == TRANSLATION_ERROR; } | 124 bool is_error() const { return infobar_type_ == TRANSLATION_ERROR; } |
| 110 | 125 |
| 111 // Returns what kind of background fading effect the infobar should use when | 126 // Returns what kind of background fading effect the infobar should use when |
| 112 // its is shown. | 127 // its is shown. |
| 113 BackgroundAnimationType background_animation_type() const { | 128 BackgroundAnimationType background_animation_type() const { |
| 114 return background_animation_; | 129 return background_animation_; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 virtual bool ShouldExpire( | 207 virtual bool ShouldExpire( |
| 193 const content::LoadCommittedDetails& details) const OVERRIDE; | 208 const content::LoadCommittedDetails& details) const OVERRIDE; |
| 194 virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate() OVERRIDE; | 209 virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate() OVERRIDE; |
| 195 | 210 |
| 196 Type infobar_type_; | 211 Type infobar_type_; |
| 197 | 212 |
| 198 // The type of fading animation if any that should be used when showing this | 213 // The type of fading animation if any that should be used when showing this |
| 199 // infobar. | 214 // infobar. |
| 200 BackgroundAnimationType background_animation_; | 215 BackgroundAnimationType background_animation_; |
| 201 | 216 |
| 202 TranslateUIDelegate ui_delegate_; | 217 // The list supported languages for translation. |
|
Peter Kasting
2013/11/08 23:47:47
Nit: All three of these comments have grammar issu
hajimehoshi
2013/11/11 04:01:02
Done. They were original.: https://codereview.chro
| |
| 218 std::vector<LanguageNamePair> languages_; | |
| 219 | |
| 220 // The index for language the page is originally in. | |
| 221 size_t original_language_index_; | |
| 222 | |
| 223 // The index for language the page should be translated to. | |
| 224 size_t target_language_index_; | |
| 203 | 225 |
| 204 // The error that occurred when trying to translate (NONE if no error). | 226 // The error that occurred when trying to translate (NONE if no error). |
| 205 TranslateErrors::Type error_type_; | 227 TranslateErrors::Type error_type_; |
| 206 | 228 |
| 207 // The translation related preferences. | 229 // The translation related preferences. |
| 208 TranslatePrefs prefs_; | 230 TranslatePrefs prefs_; |
| 209 | 231 |
| 210 // Translation shortcut configuration | 232 // Translation shortcut configuration |
| 211 ShortcutConfiguration shortcut_config_; | 233 ShortcutConfiguration shortcut_config_; |
| 212 DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate); | 234 DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate); |
| 213 }; | 235 }; |
| 214 | 236 |
| 215 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ | 237 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ |
| OLD | NEW |