OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_INFOBAR_DELEGATE_H_ | 5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_INFOBAR_DELEGATE_H_ |
6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_INFOBAR_DELEGATE_H_ | 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_INFOBAR_DELEGATE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 19 matching lines...) Expand all Loading... |
30 namespace translate { | 30 namespace translate { |
31 | 31 |
32 // Feature flag for "Translate Compact Infobar UI" project. | 32 // Feature flag for "Translate Compact Infobar UI" project. |
33 extern const base::Feature kTranslateCompactUI; | 33 extern const base::Feature kTranslateCompactUI; |
34 | 34 |
35 class TranslateDriver; | 35 class TranslateDriver; |
36 class TranslateManager; | 36 class TranslateManager; |
37 | 37 |
38 class TranslateInfoBarDelegate : public infobars::InfoBarDelegate { | 38 class TranslateInfoBarDelegate : public infobars::InfoBarDelegate { |
39 public: | 39 public: |
| 40 // An observer to handle different translate steps' UI changes. |
| 41 class Observer { |
| 42 public: |
| 43 // Handles UI changes on the translate step given. |
| 44 virtual void OnTranslateStepChanged(translate::TranslateStep step, |
| 45 TranslateErrors::Type error_type){}; |
| 46 // Return whether user declined translate service. |
| 47 virtual bool IsDeclinedByUser(); |
| 48 |
| 49 protected: |
| 50 virtual ~Observer() {} |
| 51 }; |
| 52 |
40 static const size_t kNoIndex; | 53 static const size_t kNoIndex; |
41 | 54 |
42 ~TranslateInfoBarDelegate() override; | 55 ~TranslateInfoBarDelegate() override; |
43 | 56 |
44 // Factory method to create a translate infobar. |error_type| must be | 57 // Factory method to create a translate infobar. |error_type| must be |
45 // specified iff |step| == TRANSLATION_ERROR. For other translate steps, | 58 // specified iff |step| == TRANSLATION_ERROR. For other translate steps, |
46 // |original_language| and |target_language| must be ASCII language codes | 59 // |original_language| and |target_language| must be ASCII language codes |
47 // (e.g. "en", "fr", etc.) for languages the TranslateManager supports | 60 // (e.g. "en", "fr", etc.) for languages the TranslateManager supports |
48 // translating. The lone exception is when the user initiates translation | 61 // translating. The lone exception is when the user initiates translation |
49 // from the context menu, in which case it's legal to call this with | 62 // from the context menu, in which case it's legal to call this with |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // been translate to <lang2> from <lang1>."). It is ignored if | 188 // been translate to <lang2> from <lang1>."). It is ignored if |
176 // |autodetermined_source_language| is true. | 189 // |autodetermined_source_language| is true. |
177 static void GetAfterTranslateStrings(std::vector<base::string16>* strings, | 190 static void GetAfterTranslateStrings(std::vector<base::string16>* strings, |
178 bool* swap_languages, | 191 bool* swap_languages, |
179 bool autodetermined_source_language); | 192 bool autodetermined_source_language); |
180 | 193 |
181 // Gets the TranslateDriver associated with this object. | 194 // Gets the TranslateDriver associated with this object. |
182 // May return NULL if the driver has been destroyed. | 195 // May return NULL if the driver has been destroyed. |
183 TranslateDriver* GetTranslateDriver(); | 196 TranslateDriver* GetTranslateDriver(); |
184 | 197 |
| 198 // Set a observer. |
| 199 void SetObserver(Observer* observer); |
| 200 |
185 protected: | 201 protected: |
186 TranslateInfoBarDelegate( | 202 TranslateInfoBarDelegate( |
187 const base::WeakPtr<TranslateManager>& translate_manager, | 203 const base::WeakPtr<TranslateManager>& translate_manager, |
188 bool is_off_the_record, | 204 bool is_off_the_record, |
189 translate::TranslateStep step, | 205 translate::TranslateStep step, |
190 const std::string& original_language, | 206 const std::string& original_language, |
191 const std::string& target_language, | 207 const std::string& target_language, |
192 TranslateErrors::Type error_type, | 208 TranslateErrors::Type error_type, |
193 bool triggered_from_menu); | 209 bool triggered_from_menu); |
194 | 210 |
(...skipping 17 matching lines...) Expand all Loading... |
212 // The error that occurred when trying to translate (NONE if no error). | 228 // The error that occurred when trying to translate (NONE if no error). |
213 TranslateErrors::Type error_type_; | 229 TranslateErrors::Type error_type_; |
214 | 230 |
215 // The translation related preferences. | 231 // The translation related preferences. |
216 std::unique_ptr<TranslatePrefs> prefs_; | 232 std::unique_ptr<TranslatePrefs> prefs_; |
217 | 233 |
218 // Whether the translation was triggered via a menu click vs automatically | 234 // Whether the translation was triggered via a menu click vs automatically |
219 // (due to language detection, preferences...) | 235 // (due to language detection, preferences...) |
220 bool triggered_from_menu_; | 236 bool triggered_from_menu_; |
221 | 237 |
| 238 // A observer to handle front-end changes on different steps. |
| 239 // It's only used when we try to reuse the existing UI. |
| 240 Observer* observer_; |
| 241 |
222 DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate); | 242 DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate); |
223 }; | 243 }; |
224 | 244 |
225 } // namespace translate | 245 } // namespace translate |
226 | 246 |
227 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_INFOBAR_DELEGATE_H_ | 247 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_INFOBAR_DELEGATE_H_ |
OLD | NEW |