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

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

Issue 2602003: Refactored the translate infobars. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Synced Created 10 years, 6 months 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
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE2_H
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE2_H
7
8 #include <string>
9 #include <vector>
10
11 #include "chrome/browser/tab_contents/infobar_delegate.h"
12 #include "chrome/browser/translate/translate_prefs.h"
13 #include "chrome/common/translate_errors.h"
14
15 class SkBitmap;
16 class TranslateInfoBarView;
17
18 class TranslateInfoBarDelegate2 : public InfoBarDelegate {
19 public:
20 // The different types of infobars that can be shown for translation.
21 enum Type {
22 BEFORE_TRANSLATE,
23 TRANSLATING,
24 AFTER_TRANSLATE,
25 TRANSLATION_ERROR
26 };
27
28 // The types of background color animations.
29 enum BackgroundAnimationType {
30 NONE,
31 NORMAL_TO_ERROR,
32 ERROR_TO_NORMAL
33 };
34
35 // Factory method.
36 // The original and target language specified are the ASCII language codes
37 // (ex: en, fr...).
38 // Returns NULL if it failed, typically if |original_language| or
39 // |target_language| is not a supported language.
40 // |error| should be set to NONE if |infobar_type| is not TRANSLATION_ERROR.
41 static TranslateInfoBarDelegate2* CreateInstance(
42 Type infobar_type,
43 TranslateErrors::Type error,
44 TabContents* tab_contents,
45 const std::string& original_language,
46 const std::string& target_language);
47
48 // Returns the number of languages supported.
49 int GetLanguageCount() const;
50
51 // Returns the ISO code for the language at |index|.
52 const std::string& GetLanguageCodeAt(int index) const;
53
54 // Returns the displayable name for the language at |index|.
55 const string16& GetLanguageDisplayableNameAt(int index) const;
56
57 TabContents* tab_contents() const { return tab_contents_; }
58
59 Type type() const { return type_; }
60
61 int original_language_index() const { return original_language_index_; }
62 int target_language_index() const { return target_language_index_; }
63
64 // Convenience methods.
65 const std::string& GetOriginalLanguageCode() const;
66 const std::string& GetTargetLanguageCode() const;
67
68 // Called by the InfoBar to notify that the original/target language has
69 // changed and is now the language at |language_index|.
70 virtual void SetOriginalLanguage(int language_index);
71 virtual void SetTargetLanguage(int language_index);
72
73 // Returns true if the current infobar indicates an error (in which case it
74 // should get a yellow background instead of a blue one).
75 bool IsError();
76
77 // Returns what kind of background fading effect the infobar should use when
78 // its is shown.
79 BackgroundAnimationType background_animation_type() const {
80 return background_animation_;
81 }
82
83 virtual void Translate();
84 virtual void RevertTranslation();
85
86 // Called when the user declines to translate a page, by either closing the
87 // infobar or pressing the "Don't translate" button.
88 void TranslationDeclined();
89
90 // InfoBarDelegate implementation:
91 virtual InfoBar* CreateInfoBar();
92 void InfoBarDismissed();
93 virtual SkBitmap* GetIcon() const;
94 virtual InfoBarDelegate::Type GetInfoBarType();
95 virtual TranslateInfoBarDelegate2* AsTranslateInfoBarDelegate2() {
96 return this;
97 }
98
99 // Methods called by the Options menu delegate.
100 virtual bool IsLanguageBlacklisted();
101 virtual void ToggleLanguageBlacklist();
102 virtual bool IsSiteBlacklisted();
103 virtual void ToggleSiteBlacklist();
104 virtual bool ShouldAlwaysTranslate();
105 virtual void ToggleAlwaysTranslate();
106
107 // The following methods are called by the infobar that displays the status
108 // while translating and also the one displaying the error message.
109 string16 GetMessageInfoBarText();
110 string16 GetMessageInfoBarButtonText();
111 void MessageInfoBarButtonPressed();
112
113 // Sets this infobar background animation based on the previous infobar shown.
114 // A fading background effect is used when transitioning from a normal state
115 // to an error state (and vice-versa).
116 void UpdateBackgroundAnimation(TranslateInfoBarDelegate2* previous_infobar);
117
118 // Convenience method that returns the displayable language name for
119 // |language_code| in the current application locale.
120 static string16 GetLanguageDisplayableName(const std::string& language_code);
121
122 // Adds the strings that should be displayed in the after translate infobar to
123 // |strings|. The text in that infobar is:
124 // "The page has been translated from <lang1> to <lang2>."
125 // Because <lang1> and <lang2> are displayed in menu buttons, the text is
126 // split in 3 chunks. |swap_languages| is set to true if <lang1> and <lang2>
127 // should be inverted (some languages express the sentense as "The page has
128 // been translate to <lang2> from <lang1>.").
129 static void GetAfterTranslateStrings(std::vector<string16>* strings,
130 bool* swap_languages);
131
132 private:
133 typedef std::pair<std::string, string16> LanguageNamePair;
134
135 // Gets the host of the page being translated, or an empty string if no URL is
136 // associated with the current page.
137 std::string GetPageHost();
138
139 TranslateInfoBarDelegate2(Type infobar_type,
140 TranslateErrors::Type error,
141 TabContents* tab_contents,
142 const std::string& original_language,
143 const std::string& target_language);
144
145 Type type_;
146
147 // The type of fading animation if any that should be used when showing this
148 // infobar.
149 BackgroundAnimationType background_animation_;
150
151 TabContents* tab_contents_;
152
153 // The list supported languages for translation.
154 // The pair first string is the language ISO code (ex: en, fr...), the second
155 // string is the displayable name on the current locale.
156 // The languages are sorted alphabetically based on the displayable name.
157 std::vector<LanguageNamePair> languages_;
158
159 // The index for language the page is originally in.
160 int original_language_index_;
161
162 // The index for language the page should be translated to.
163 int target_language_index_;
164
165 // The error that occurred when trying to translate (NONE if no error).
166 TranslateErrors::Type error_;
167
168 // The current infobar view.
169 TranslateInfoBarView* infobar_view_;
170
171 // The translation related preferences.
172 TranslatePrefs prefs_;
173
174 DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate2);
175 };
176
177 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE2_H
178
OLDNEW
« no previous file with comments | « chrome/browser/translate/options_menu_model2.cc ('k') | chrome/browser/translate/translate_infobar_delegate2.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698