| 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; | 
|   27 }; |   26 }; | 
|   28  |   27  | 
 |   28 // NOTE: TranslateUIDelegate should be updated if this implementation is | 
 |   29 // updated. | 
|   29 class TranslateInfoBarDelegate : public InfoBarDelegate { |   30 class TranslateInfoBarDelegate : public InfoBarDelegate { | 
|   30  public: |   31  public: | 
|   31   // The different types of infobars that can be shown for translation. |   32   // The different types of infobars that can be shown for translation. | 
|   32   enum Type { |   33   enum Type { | 
|   33     BEFORE_TRANSLATE, |   34     BEFORE_TRANSLATE, | 
|   34     TRANSLATING, |   35     TRANSLATING, | 
|   35     AFTER_TRANSLATE, |   36     AFTER_TRANSLATE, | 
|   36     TRANSLATION_ERROR |   37     TRANSLATION_ERROR | 
|   37   }; |   38   }; | 
|   38  |   39  | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
|   63   static void Create(bool replace_existing_infobar, |   64   static void Create(bool replace_existing_infobar, | 
|   64                      InfoBarService* infobar_service, |   65                      InfoBarService* infobar_service, | 
|   65                      Type infobar_type, |   66                      Type infobar_type, | 
|   66                      const std::string& original_language, |   67                      const std::string& original_language, | 
|   67                      const std::string& target_language, |   68                      const std::string& target_language, | 
|   68                      TranslateErrors::Type error_type, |   69                      TranslateErrors::Type error_type, | 
|   69                      PrefService* prefs, |   70                      PrefService* prefs, | 
|   70                      const ShortcutConfiguration& shortcut_config); |   71                      const ShortcutConfiguration& shortcut_config); | 
|   71  |   72  | 
|   72   // Returns the number of languages supported. |   73   // Returns the number of languages supported. | 
|   73   size_t num_languages() const { return ui_delegate_.GetNumberOfLanguages(); } |   74   size_t num_languages() const { | 
 |   75  | 
 |   76     return languages_.size(); | 
 |   77   } | 
|   74  |   78  | 
|   75   // Returns the ISO code for the language at |index|. |   79   // Returns the ISO code for the language at |index|. | 
|   76   std::string language_code_at(size_t index) const { |   80   std::string language_code_at(size_t index) const { | 
|   77     return ui_delegate_.GetLanguageCodeAt(index); |   81     DCHECK_LT(index, num_languages()); | 
 |   82     return languages_[index].first; | 
|   78   } |   83   } | 
|   79  |   84  | 
|   80   // Returns the displayable name for the language at |index|. |   85   // Returns the displayable name for the language at |index|. | 
|   81   string16 language_name_at(size_t index) const { |   86   string16 language_name_at(size_t index) const { | 
|   82     return ui_delegate_.GetLanguageNameAt(index); |   87     if (index == static_cast<size_t>(kNoIndex)) | 
 |   88       return string16(); | 
 |   89     DCHECK_LT(index, num_languages()); | 
 |   90     return languages_[index].second; | 
|   83   } |   91   } | 
|   84  |   92  | 
|   85   Type infobar_type() const { return infobar_type_; } |   93   Type infobar_type() const { return infobar_type_; } | 
|   86  |   94  | 
|   87   TranslateErrors::Type error_type() const { return error_type_; } |   95   TranslateErrors::Type error_type() const { return error_type_; } | 
|   88  |   96  | 
|   89   size_t original_language_index() const { |   97   size_t original_language_index() const { return original_language_index_; } | 
|   90     return ui_delegate_.GetOriginalLanguageIndex(); |   98  | 
|   91   } |  | 
|   92   void UpdateOriginalLanguageIndex(size_t language_index); |   99   void UpdateOriginalLanguageIndex(size_t language_index); | 
|   93  |  100  | 
|   94   size_t target_language_index() const { |  101   size_t target_language_index() const { return target_language_index_; } | 
|   95     return ui_delegate_.GetTargetLanguageIndex(); |  102  | 
|   96   } |  | 
|   97   void UpdateTargetLanguageIndex(size_t language_index); |  103   void UpdateTargetLanguageIndex(size_t language_index); | 
|   98  |  104  | 
|   99   // Convenience methods. |  105   // Convenience methods. | 
|  100   std::string original_language_code() const { |  106   std::string original_language_code() const { | 
|  101     return ui_delegate_.GetOriginalLanguageCode(); |  107     return (original_language_index() == static_cast<size_t>(kNoIndex)) ? | 
 |  108         translate::kUnknownLanguageCode : | 
 |  109         language_code_at(original_language_index()); | 
|  102   } |  110   } | 
|  103   std::string target_language_code() const { |  111   std::string target_language_code() const { | 
|  104     return ui_delegate_.GetTargetLanguageCode(); |  112     return language_code_at(target_language_index()); | 
|  105   } |  113   } | 
|  106  |  114  | 
|  107   // Returns true if the current infobar indicates an error (in which case it |  115   // Returns true if the current infobar indicates an error (in which case it | 
|  108   // should get a yellow background instead of a blue one). |  116   // should get a yellow background instead of a blue one). | 
|  109   bool is_error() const { return infobar_type_ == TRANSLATION_ERROR; } |  117   bool is_error() const { return infobar_type_ == TRANSLATION_ERROR; } | 
|  110  |  118  | 
|  111   // Returns what kind of background fading effect the infobar should use when |  119   // Returns what kind of background fading effect the infobar should use when | 
|  112   // its is shown. |  120   // its is shown. | 
|  113   BackgroundAnimationType background_animation_type() const { |  121   BackgroundAnimationType background_animation_type() const { | 
|  114     return background_animation_; |  122     return background_animation_; | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  192   virtual bool ShouldExpire( |  200   virtual bool ShouldExpire( | 
|  193        const content::LoadCommittedDetails& details) const OVERRIDE; |  201        const content::LoadCommittedDetails& details) const OVERRIDE; | 
|  194   virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate() OVERRIDE; |  202   virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate() OVERRIDE; | 
|  195  |  203  | 
|  196   Type infobar_type_; |  204   Type infobar_type_; | 
|  197  |  205  | 
|  198   // The type of fading animation if any that should be used when showing this |  206   // The type of fading animation if any that should be used when showing this | 
|  199   // infobar. |  207   // infobar. | 
|  200   BackgroundAnimationType background_animation_; |  208   BackgroundAnimationType background_animation_; | 
|  201  |  209  | 
|  202   TranslateUIDelegate ui_delegate_; |  210   // The list of the languages supported for translation. | 
 |  211   std::vector<LanguageNamePair> languages_; | 
 |  212  | 
 |  213   // The index of the webpage's original language. | 
 |  214   size_t original_language_index_; | 
 |  215  | 
 |  216   // The index of the language the webpage will be translated into. | 
 |  217   size_t target_language_index_; | 
|  203  |  218  | 
|  204   // The error that occurred when trying to translate (NONE if no error). |  219   // The error that occurred when trying to translate (NONE if no error). | 
|  205   TranslateErrors::Type error_type_; |  220   TranslateErrors::Type error_type_; | 
|  206  |  221  | 
|  207   // The translation related preferences. |  222   // The translation related preferences. | 
|  208   TranslatePrefs prefs_; |  223   TranslatePrefs prefs_; | 
|  209  |  224  | 
|  210   // Translation shortcut configuration |  225   // Translation shortcut configuration | 
|  211   ShortcutConfiguration shortcut_config_; |  226   ShortcutConfiguration shortcut_config_; | 
|  212   DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate); |  227   DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate); | 
|  213 }; |  228 }; | 
|  214  |  229  | 
|  215 #endif  // CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ |  230 #endif  // CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ | 
| OLD | NEW |