| 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 "chrome/browser/api/infobars/infobar_delegate.h" | 14 #include "chrome/browser/api/infobars/infobar_delegate.h" |
| 14 #include "chrome/browser/translate/translate_prefs.h" | 15 #include "chrome/browser/translate/translate_prefs.h" |
| 16 #include "chrome/common/chrome_constants.h" |
| 15 #include "chrome/common/translate_errors.h" | 17 #include "chrome/common/translate_errors.h" |
| 16 | 18 |
| 17 class InfoBarTabHelper; | 19 class InfoBarTabHelper; |
| 18 class PrefService; | 20 class PrefService; |
| 19 class TranslateInfoBarView; | |
| 20 | 21 |
| 21 class TranslateInfoBarDelegate : public InfoBarDelegate { | 22 class TranslateInfoBarDelegate : public InfoBarDelegate { |
| 22 public: | 23 public: |
| 23 // The different types of infobars that can be shown for translation. | 24 // The different types of infobars that can be shown for translation. |
| 24 enum Type { | 25 enum Type { |
| 25 BEFORE_TRANSLATE, | 26 BEFORE_TRANSLATE, |
| 26 TRANSLATING, | 27 TRANSLATING, |
| 27 AFTER_TRANSLATE, | 28 AFTER_TRANSLATE, |
| 28 TRANSLATION_ERROR | 29 TRANSLATION_ERROR |
| 29 }; | 30 }; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 54 static TranslateInfoBarDelegate* CreateErrorDelegate( | 55 static TranslateInfoBarDelegate* CreateErrorDelegate( |
| 55 TranslateErrors::Type error_type, | 56 TranslateErrors::Type error_type, |
| 56 InfoBarTabHelper* infobar_helper, | 57 InfoBarTabHelper* infobar_helper, |
| 57 PrefService* prefs, | 58 PrefService* prefs, |
| 58 const std::string& original_language, | 59 const std::string& original_language, |
| 59 const std::string& target_language); | 60 const std::string& target_language); |
| 60 | 61 |
| 61 virtual ~TranslateInfoBarDelegate(); | 62 virtual ~TranslateInfoBarDelegate(); |
| 62 | 63 |
| 63 // Returns the number of languages supported. | 64 // Returns the number of languages supported. |
| 64 size_t GetLanguageCount() const { return languages_.size(); } | 65 size_t num_languages() const { return languages_.size(); } |
| 65 | 66 |
| 66 // Returns the ISO code for the language at |index|. | 67 // Returns the ISO code for the language at |index|. |
| 67 std::string GetLanguageCodeAt(size_t index) const; | 68 std::string language_code_at(size_t index) const { |
| 69 DCHECK_LT(index, num_languages()); |
| 70 return languages_[index].first; |
| 71 } |
| 68 | 72 |
| 69 // Returns the displayable name for the language at |index|. | 73 // Returns the displayable name for the language at |index|. |
| 70 string16 GetLanguageDisplayableNameAt(size_t index) const; | 74 string16 language_name_at(size_t index) const { |
| 75 DCHECK_LT(index, num_languages()); |
| 76 return languages_[index].second; |
| 77 } |
| 71 | 78 |
| 72 Type type() const { return type_; } | 79 Type type() const { return type_; } |
| 73 | 80 |
| 74 TranslateErrors::Type error() const { return error_; } | 81 TranslateErrors::Type error() const { return error_; } |
| 75 | 82 |
| 76 size_t original_language_index() const { return original_language_index_; } | 83 size_t original_language_index() const { return original_language_index_; } |
| 84 void set_original_language_index(size_t language_index) { |
| 85 DCHECK_LT(language_index, num_languages()); |
| 86 original_language_index_ = language_index; |
| 87 } |
| 77 size_t target_language_index() const { return target_language_index_; } | 88 size_t target_language_index() const { return target_language_index_; } |
| 89 void set_target_language_index(size_t language_index) { |
| 90 DCHECK_LT(language_index, num_languages()); |
| 91 target_language_index_ = language_index; |
| 92 } |
| 78 | 93 |
| 79 // Convenience methods. | 94 // Convenience methods. |
| 80 std::string GetOriginalLanguageCode() const; | 95 std::string original_language_code() const { |
| 81 std::string GetTargetLanguageCode() const; | 96 return (original_language_index() == kNoIndex) ? |
| 82 | 97 chrome::kUnknownLanguageCode : |
| 83 // Called by the InfoBar to notify that the original/target language has | 98 language_code_at(original_language_index()); |
| 84 // changed and is now the language at |language_index|. | 99 } |
| 85 virtual void SetOriginalLanguage(size_t language_index); | 100 std::string target_language_code() const { |
| 86 virtual void SetTargetLanguage(size_t language_index); | 101 return language_code_at(target_language_index()); |
| 102 } |
| 87 | 103 |
| 88 // Returns true if the current infobar indicates an error (in which case it | 104 // Returns true if the current infobar indicates an error (in which case it |
| 89 // should get a yellow background instead of a blue one). | 105 // should get a yellow background instead of a blue one). |
| 90 bool IsError() const { return type_ == TRANSLATION_ERROR; } | 106 bool IsError() const { return type_ == TRANSLATION_ERROR; } |
| 91 | 107 |
| 92 // Returns what kind of background fading effect the infobar should use when | 108 // Returns what kind of background fading effect the infobar should use when |
| 93 // its is shown. | 109 // its is shown. |
| 94 BackgroundAnimationType background_animation_type() const { | 110 BackgroundAnimationType background_animation_type() const { |
| 95 return background_animation_; | 111 return background_animation_; |
| 96 } | 112 } |
| 97 | 113 |
| 98 virtual void Translate(); | 114 virtual void Translate(); |
| 99 virtual void RevertTranslation(); | 115 virtual void RevertTranslation(); |
| 100 virtual void ReportLanguageDetectionError(); | 116 void ReportLanguageDetectionError(); |
| 101 | 117 |
| 102 // Called when the user declines to translate a page, by either closing the | 118 // Called when the user declines to translate a page, by either closing the |
| 103 // infobar or pressing the "Don't translate" button. | 119 // infobar or pressing the "Don't translate" button. |
| 104 void TranslationDeclined(); | 120 virtual void TranslationDeclined(); |
| 105 | 121 |
| 106 // Methods called by the Options menu delegate. | 122 // Methods called by the Options menu delegate. |
| 107 virtual bool IsLanguageBlacklisted(); | 123 virtual bool IsLanguageBlacklisted(); |
| 108 virtual void ToggleLanguageBlacklist(); | 124 virtual void ToggleLanguageBlacklist(); |
| 109 virtual bool IsSiteBlacklisted(); | 125 virtual bool IsSiteBlacklisted(); |
| 110 virtual void ToggleSiteBlacklist(); | 126 virtual void ToggleSiteBlacklist(); |
| 111 virtual bool ShouldAlwaysTranslate(); | 127 virtual bool ShouldAlwaysTranslate(); |
| 112 virtual void ToggleAlwaysTranslate(); | 128 virtual void ToggleAlwaysTranslate(); |
| 113 | 129 |
| 114 // Methods called by the extra-buttons that can appear on the "before | 130 // Methods called by the extra-buttons that can appear on the "before |
| 115 // translate" infobar (when the user has accepted/declined the translation | 131 // translate" infobar (when the user has accepted/declined the translation |
| 116 // several times). | 132 // several times). |
| 117 virtual void AlwaysTranslatePageLanguage(); | 133 void AlwaysTranslatePageLanguage(); |
| 118 virtual void NeverTranslatePageLanguage(); | 134 void NeverTranslatePageLanguage(); |
| 119 | 135 |
| 120 // The following methods are called by the infobar that displays the status | 136 // The following methods are called by the infobar that displays the status |
| 121 // while translating and also the one displaying the error message. | 137 // while translating and also the one displaying the error message. |
| 122 string16 GetMessageInfoBarText(); | 138 string16 GetMessageInfoBarText(); |
| 123 string16 GetMessageInfoBarButtonText(); | 139 string16 GetMessageInfoBarButtonText(); |
| 124 void MessageInfoBarButtonPressed(); | 140 void MessageInfoBarButtonPressed(); |
| 125 bool ShouldShowMessageInfoBarButton(); | 141 bool ShouldShowMessageInfoBarButton(); |
| 126 | 142 |
| 127 // Called by the before translate infobar to figure-out if it should show | 143 // Called by the before translate infobar to figure-out if it should show |
| 128 // an extra button to let the user black-list/white-list that language (based | 144 // an extra button to let the user black-list/white-list that language (based |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 // language detection errors with the right original language even if the user | 210 // language detection errors with the right original language even if the user |
| 195 // changed the original language. | 211 // changed the original language. |
| 196 size_t initial_original_language_index_; | 212 size_t initial_original_language_index_; |
| 197 | 213 |
| 198 // The index for language the page should be translated to. | 214 // The index for language the page should be translated to. |
| 199 size_t target_language_index_; | 215 size_t target_language_index_; |
| 200 | 216 |
| 201 // The error that occurred when trying to translate (NONE if no error). | 217 // The error that occurred when trying to translate (NONE if no error). |
| 202 TranslateErrors::Type error_; | 218 TranslateErrors::Type error_; |
| 203 | 219 |
| 204 // The current infobar view. | |
| 205 TranslateInfoBarView* infobar_view_; | |
| 206 | |
| 207 // The translation related preferences. | 220 // The translation related preferences. |
| 208 TranslatePrefs prefs_; | 221 TranslatePrefs prefs_; |
| 209 | 222 |
| 210 DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate); | 223 DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate); |
| 211 }; | 224 }; |
| 212 | 225 |
| 213 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ | 226 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ |
| OLD | NEW |