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

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

Issue 64823005: Copy the implementations of TranslateUIDelegate to TransalteInfobarDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 7 years, 1 month 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_UI_DELEGATE_H_ 5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "chrome/common/chrome_constants.h" 14 #include "chrome/common/chrome_constants.h"
15 15
16 class TranslatePrefs; 16 class TranslatePrefs;
17 17
18 namespace content { 18 namespace content {
19 class WebContents; 19 class WebContents;
20 } // namespace content 20 } // namespace content
21 21
22 // The TranslateUIDelegate is a generic delegate for UI which offers Translate 22 // The TranslateUIDelegate is a generic delegate for UI which offers Translate
23 // feature to the user. 23 // feature to the user.
24 class TranslateUIDelegate { 24 class TranslateUIDelegate {
25 public: 25 public:
26 enum { 26 enum {
27 NO_INDEX = -1, 27 NO_INDEX = -1,
28 }; 28 };
29 29
30 // A pair whose key is a language code and value is a language displyayable
Peter Kasting 2013/11/08 23:47:47 Nit: a language displyayable -> the language's dis
hajimehoshi 2013/11/11 04:01:02 Done.
31 // name.
32 typedef std::pair<std::string, string16> LanguageNamePair;
33
30 TranslateUIDelegate(content::WebContents* web_contents, 34 TranslateUIDelegate(content::WebContents* web_contents,
31 const std::string& original_language, 35 const std::string& original_language,
32 const std::string& target_language); 36 const std::string& target_language);
33 virtual ~TranslateUIDelegate(); 37 virtual ~TranslateUIDelegate();
34 38
39 // Gets the language names. The result is set |language_names| and is sorted
40 // in alphabetical order taking |locale| into account.
Peter Kasting 2013/11/08 23:47:47 I have no idea what language names this is returni
hajimehoshi 2013/11/11 04:01:02 Done.
41 static void GetSortedLanguageNames(
42 const std::string& locale,
43 std::vector<LanguageNamePair>* language_names);
Peter Kasting 2013/11/08 23:47:47 Don't return via outparam, return by value. RVO w
hajimehoshi 2013/11/11 04:01:02 Done.
44
45 // Gets the host of the page of |web_content|, or an empty string if no URL is
Peter Kasting 2013/11/08 23:47:47 Nit: Call this |web_contents|
hajimehoshi 2013/11/11 04:01:02 Done.
46 // associated with the current page.
47 static std::string GetPageHost(content::WebContents* web_content);
48
35 content::WebContents* web_contents() { return web_contents_; } 49 content::WebContents* web_contents() { return web_contents_; }
36 50
37 // Returns the number of languages supported. 51 // Returns the number of languages supported.
38 size_t GetNumberOfLanguages() const; 52 size_t GetNumberOfLanguages() const;
39 53
40 // Returns the original language index. 54 // Returns the original language index.
41 size_t GetOriginalLanguageIndex() const; 55 size_t GetOriginalLanguageIndex() const;
42 56
43 // Updates the original language index. 57 // Updates the original language index.
44 void UpdateOriginalLanguageIndex(size_t language_index); 58 void UpdateOriginalLanguageIndex(size_t language_index);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 98
85 // Returns true if the webpage in the current original language should be 99 // Returns true if the webpage in the current original language should be
86 // translated into the current target language automatically. 100 // translated into the current target language automatically.
87 bool ShouldAlwaysTranslate(); 101 bool ShouldAlwaysTranslate();
88 102
89 // Sets the value if the webpage in the current original language should be 103 // Sets the value if the webpage in the current original language should be
90 // translated into the current target language automatically. 104 // translated into the current target language automatically.
91 void SetAlwaysTranslate(bool value); 105 void SetAlwaysTranslate(bool value);
92 106
93 private: 107 private:
94 // Gets the host of the page being translated, or an empty string if no URL is
95 // associated with the current page.
96 std::string GetPageHost();
97
98 content::WebContents* web_contents_; 108 content::WebContents* web_contents_;
99 109
100 typedef std::pair<std::string, string16> LanguageNamePair;
101
102 // The list supported languages for translation. 110 // The list supported languages for translation.
103 // The pair first string is the language ISO code (ex: en, fr...), the second 111 // The pair first string is the language ISO code (ex: en, fr...), the second
104 // string is the displayable name on the current locale. 112 // string is the displayable name on the current locale.
105 // The languages are sorted alphabetically based on the displayable name. 113 // The languages are sorted alphabetically based on the displayable name.
106 std::vector<LanguageNamePair> languages_; 114 std::vector<LanguageNamePair> languages_;
107 115
108 // The index for language the page is originally in. 116 // The index for language the page is originally in.
109 size_t original_language_index_; 117 size_t original_language_index_;
110 118
111 // The index for language the page is originally in that was originally
112 // reported (original_language_index_ changes if the user selects a new
113 // original language, but this one does not). This is necessary to report
114 // language detection errors with the right original language even if the user
115 // changed the original language.
116 size_t initial_original_language_index_;
117
118 // The index for language the page should be translated to. 119 // The index for language the page should be translated to.
119 size_t target_language_index_; 120 size_t target_language_index_;
120 121
121 // The translation related preferences. 122 // The translation related preferences.
122 scoped_ptr<TranslatePrefs> prefs_; 123 scoped_ptr<TranslatePrefs> prefs_;
123 124
124 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate); 125 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate);
125 }; 126 };
126 127
127 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ 128 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698