Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: chrome/browser/translate/translate_infobar_delegate.h

Issue 107303002: Make the TranslateInfoBarDelegate once again use the TranslateUIDelegate. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.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/translate/translate_errors.h" 17 #include "chrome/common/translate/translate_errors.h"
17 #include "components/translate/common/translate_constants.h" 18 #include "components/translate/common/translate_constants.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;
26 }; 27 };
27 28
28 // NOTE: TranslateUIDelegate should be updated if this implementation is
29 // updated.
30 class TranslateInfoBarDelegate : public InfoBarDelegate { 29 class TranslateInfoBarDelegate : public InfoBarDelegate {
31 public: 30 public:
32 // The different types of infobars that can be shown for translation. 31 // The different types of infobars that can be shown for translation.
33 enum Type { 32 enum Type {
34 BEFORE_TRANSLATE, 33 BEFORE_TRANSLATE,
35 TRANSLATING, 34 TRANSLATING,
36 AFTER_TRANSLATE, 35 AFTER_TRANSLATE,
37 TRANSLATION_ERROR 36 TRANSLATION_ERROR
38 }; 37 };
39 38
(...skipping 24 matching lines...) Expand all
64 static void Create(bool replace_existing_infobar, 63 static void Create(bool replace_existing_infobar,
65 content::WebContents* web_contents, 64 content::WebContents* web_contents,
66 Type infobar_type, 65 Type infobar_type,
67 const std::string& original_language, 66 const std::string& original_language,
68 const std::string& target_language, 67 const std::string& target_language,
69 TranslateErrors::Type error_type, 68 TranslateErrors::Type error_type,
70 PrefService* prefs, 69 PrefService* prefs,
71 const ShortcutConfiguration& shortcut_config); 70 const ShortcutConfiguration& shortcut_config);
72 71
73 // Returns the number of languages supported. 72 // Returns the number of languages supported.
74 size_t num_languages() const { 73 size_t num_languages() const { return ui_delegate_.GetNumberOfLanguages(); }
75
76 return languages_.size();
77 }
78 74
79 // Returns the ISO code for the language at |index|. 75 // Returns the ISO code for the language at |index|.
80 std::string language_code_at(size_t index) const { 76 std::string language_code_at(size_t index) const {
81 DCHECK_LT(index, num_languages()); 77 return ui_delegate_.GetLanguageCodeAt(index);
82 return languages_[index].first;
83 } 78 }
84 79
85 // Returns the displayable name for the language at |index|. 80 // Returns the displayable name for the language at |index|.
86 string16 language_name_at(size_t index) const { 81 string16 language_name_at(size_t index) const {
87 if (index == static_cast<size_t>(kNoIndex)) 82 return ui_delegate_.GetLanguageNameAt(index);
88 return string16();
89 DCHECK_LT(index, num_languages());
90 return languages_[index].second;
91 } 83 }
92 84
93 Type infobar_type() const { return infobar_type_; } 85 Type infobar_type() const { return infobar_type_; }
94 86
95 TranslateErrors::Type error_type() const { return error_type_; } 87 TranslateErrors::Type error_type() const { return error_type_; }
96 88
97 size_t original_language_index() const { return original_language_index_; } 89 size_t original_language_index() const {
98 90 return ui_delegate_.GetOriginalLanguageIndex();
91 }
99 void UpdateOriginalLanguageIndex(size_t language_index); 92 void UpdateOriginalLanguageIndex(size_t language_index);
100 93
101 size_t target_language_index() const { return target_language_index_; } 94 size_t target_language_index() const {
102 95 return ui_delegate_.GetTargetLanguageIndex();
96 }
103 void UpdateTargetLanguageIndex(size_t language_index); 97 void UpdateTargetLanguageIndex(size_t language_index);
104 98
105 // Convenience methods. 99 // Convenience methods.
106 std::string original_language_code() const { 100 std::string original_language_code() const {
107 return (original_language_index() == static_cast<size_t>(kNoIndex)) ? 101 return ui_delegate_.GetOriginalLanguageCode();
108 translate::kUnknownLanguageCode :
109 language_code_at(original_language_index());
110 } 102 }
111 std::string target_language_code() const { 103 std::string target_language_code() const {
112 return language_code_at(target_language_index()); 104 return ui_delegate_.GetTargetLanguageCode();
113 } 105 }
114 106
115 // Returns true if the current infobar indicates an error (in which case it 107 // Returns true if the current infobar indicates an error (in which case it
116 // should get a yellow background instead of a blue one). 108 // should get a yellow background instead of a blue one).
117 bool is_error() const { return infobar_type_ == TRANSLATION_ERROR; } 109 bool is_error() const { return infobar_type_ == TRANSLATION_ERROR; }
118 110
119 // Returns what kind of background fading effect the infobar should use when 111 // Returns what kind of background fading effect the infobar should use when
120 // its is shown. 112 // its is shown.
121 BackgroundAnimationType background_animation_type() const { 113 BackgroundAnimationType background_animation_type() const {
122 return background_animation_; 114 return background_animation_;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // text is split in 2 or 3 chunks. |swap_languages| is set to true if 165 // text is split in 2 or 3 chunks. |swap_languages| is set to true if
174 // |autodetermined_source_language| is false, and <lang1> and <lang2> 166 // |autodetermined_source_language| is false, and <lang1> and <lang2>
175 // should be inverted (some languages express the sentense as "The page has 167 // should be inverted (some languages express the sentense as "The page has
176 // been translate to <lang2> from <lang1>."). It is ignored if 168 // been translate to <lang2> from <lang1>."). It is ignored if
177 // |autodetermined_source_language| is true. 169 // |autodetermined_source_language| is true.
178 static void GetAfterTranslateStrings(std::vector<string16>* strings, 170 static void GetAfterTranslateStrings(std::vector<string16>* strings,
179 bool* swap_languages, 171 bool* swap_languages,
180 bool autodetermined_source_language); 172 bool autodetermined_source_language);
181 173
182 protected: 174 protected:
183 TranslateInfoBarDelegate(Type infobar_type, 175 TranslateInfoBarDelegate(content::WebContents* web_contents,
176 Type infobar_type,
184 TranslateInfoBarDelegate* old_delegate, 177 TranslateInfoBarDelegate* old_delegate,
185 const std::string& original_language, 178 const std::string& original_language,
186 const std::string& target_language, 179 const std::string& target_language,
187 TranslateErrors::Type error_type, 180 TranslateErrors::Type error_type,
188 PrefService* prefs, 181 PrefService* prefs,
189 ShortcutConfiguration shortcut_config); 182 ShortcutConfiguration shortcut_config);
190 183
191 private: 184 private:
192 friend class TranslationInfoBarTest; 185 friend class TranslationInfoBarTest;
193 typedef std::pair<std::string, string16> LanguageNamePair; 186 typedef std::pair<std::string, string16> LanguageNamePair;
194 187
195 // Returns a translate infobar that owns |delegate|. 188 // Returns a translate infobar that owns |delegate|.
196 static scoped_ptr<InfoBar> CreateInfoBar( 189 static scoped_ptr<InfoBar> CreateInfoBar(
197 scoped_ptr<TranslateInfoBarDelegate> delegate); 190 scoped_ptr<TranslateInfoBarDelegate> delegate);
198 191
199 // InfoBarDelegate: 192 // InfoBarDelegate:
200 virtual void InfoBarDismissed() OVERRIDE; 193 virtual void InfoBarDismissed() OVERRIDE;
201 virtual int GetIconID() const OVERRIDE; 194 virtual int GetIconID() const OVERRIDE;
202 virtual InfoBarDelegate::Type GetInfoBarType() const OVERRIDE; 195 virtual InfoBarDelegate::Type GetInfoBarType() const OVERRIDE;
203 virtual bool ShouldExpire( 196 virtual bool ShouldExpire(
204 const content::LoadCommittedDetails& details) const OVERRIDE; 197 const content::LoadCommittedDetails& details) const OVERRIDE;
205 virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate() OVERRIDE; 198 virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate() OVERRIDE;
206 199
207 Type infobar_type_; 200 Type infobar_type_;
208 201
209 // The type of fading animation if any that should be used when showing this 202 // The type of fading animation if any that should be used when showing this
210 // infobar. 203 // infobar.
211 BackgroundAnimationType background_animation_; 204 BackgroundAnimationType background_animation_;
212 205
213 // The list of the languages supported for translation. 206 TranslateUIDelegate ui_delegate_;
214 std::vector<LanguageNamePair> languages_;
215
216 // The index of the webpage's original language.
217 size_t original_language_index_;
218
219 // The index of the language the webpage will be translated into.
220 size_t target_language_index_;
221 207
222 // The error that occurred when trying to translate (NONE if no error). 208 // The error that occurred when trying to translate (NONE if no error).
223 TranslateErrors::Type error_type_; 209 TranslateErrors::Type error_type_;
224 210
225 // The translation related preferences. 211 // The translation related preferences.
226 TranslatePrefs prefs_; 212 TranslatePrefs prefs_;
227 213
228 // Translation shortcut configuration 214 // Translation shortcut configuration
229 ShortcutConfiguration shortcut_config_; 215 ShortcutConfiguration shortcut_config_;
230 DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate); 216 DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate);
231 }; 217 };
232 218
233 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ 219 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_
OLDNEW
« no previous file with comments | « chrome/browser/translate/translate_browser_metrics.cc ('k') | chrome/browser/translate/translate_infobar_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698