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

Side by Side Diff: chrome/browser/tab_contents/language_state.h

Issue 25373009: Translate: New Bubble UX (for the view toolkit) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add the browser test Created 7 years, 2 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
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_TAB_CONTENTS_LANGUAGE_STATE_H_ 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_
6 #define CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ 6 #define CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 11
12 namespace content { 12 namespace content {
13 struct LoadCommittedDetails;
13 class NavigationController; 14 class NavigationController;
14 struct LoadCommittedDetails; 15 class WebContents;
15 } 16 }
16 17
17 // This class holds the language state of the current page. 18 // This class holds the language state of the current page.
18 // There is one LanguageState instance per WebContents. 19 // There is one LanguageState instance per WebContents.
19 // It is used to determine when navigating to a new page whether it should 20 // It is used to determine when navigating to a new page whether it should
20 // automatically be translated. 21 // automatically be translated.
21 // This auto-translate behavior is the expected behavior when: 22 // This auto-translate behavior is the expected behavior when:
22 // - user is on page in language A that they had translated to language B. 23 // - user is on page in language A that they had translated to language B.
23 // - user clicks a link in that page that takes them to a page also in language 24 // - user clicks a link in that page that takes them to a page also in language
24 // A. 25 // A.
25 26
26 class LanguageState { 27 class LanguageState {
27 public: 28 public:
29 class Observer {
30 public:
31 virtual void OnTranslateEnabledChanged(content::WebContents* source) = 0;
sky 2013/10/18 14:31:10 Add description. Also, I would prefer this in its
hajimehoshi 2013/10/21 10:29:12 Done.
32
33 protected:
34 virtual ~Observer() {}
35 };
36
28 explicit LanguageState(content::NavigationController* nav_controller); 37 explicit LanguageState(content::NavigationController* nav_controller);
29 ~LanguageState(); 38 ~LanguageState();
30 39
31 // Should be called when the page did a new navigation (whether it is a main 40 // Should be called when the page did a new navigation (whether it is a main
32 // frame or sub-frame navigation). 41 // frame or sub-frame navigation).
33 void DidNavigate(const content::LoadCommittedDetails& details); 42 void DidNavigate(const content::LoadCommittedDetails& details);
34 43
35 // Should be called when the language of the page has been determined. 44 // Should be called when the language of the page has been determined.
36 // |page_needs_translation| when false indicates that the browser should not 45 // |page_needs_translation| when false indicates that the browser should not
37 // offer to translate the page. 46 // offer to translate the page.
(...skipping 26 matching lines...) Expand all
64 void set_translation_pending(bool value) { translation_pending_ = value; } 73 void set_translation_pending(bool value) { translation_pending_ = value; }
65 74
66 // Whether the user has already declined to translate the page. 75 // Whether the user has already declined to translate the page.
67 bool translation_declined() const { return translation_declined_; } 76 bool translation_declined() const { return translation_declined_; }
68 void set_translation_declined(bool value) { translation_declined_ = value; } 77 void set_translation_declined(bool value) { translation_declined_ = value; }
69 78
70 // Whether the current page was navigated through an in-page (fragment) 79 // Whether the current page was navigated through an in-page (fragment)
71 // navigation. 80 // navigation.
72 bool in_page_navigation() const { return in_page_navigation_; } 81 bool in_page_navigation() const { return in_page_navigation_; }
73 82
83 bool translate_enabled() const { return translate_enabled_; }
84 void SetTranslateEnabled(bool value);
85
86 // Whether the current page's language is different from the previous
87 // language.
88 bool IsLanguageChanged() const;
sky 2013/10/18 14:31:10 HasLanguageChanged
hajimehoshi 2013/10/21 10:29:12 Done.
89
90 void set_observer(Observer* observer) { observer_ = observer; }
91
74 private: 92 private:
75 // The languages this page is in. Note that current_lang_ is different from 93 // The languages this page is in. Note that current_lang_ is different from
76 // original_lang_ when the page has been translated. 94 // original_lang_ when the page has been translated.
77 // Note that these might be empty if the page language has not been determined 95 // Note that these might be empty if the page language has not been determined
78 // yet. 96 // yet.
79 std::string original_lang_; 97 std::string original_lang_;
80 std::string current_lang_; 98 std::string current_lang_;
81 99
82 // Same as above but for the previous page. 100 // Same as above but for the previous page.
83 std::string prev_original_lang_; 101 std::string prev_original_lang_;
(...skipping 18 matching lines...) Expand all
102 bool translation_pending_; 120 bool translation_pending_;
103 121
104 // Whether the user has declined to translate the page (by closing the infobar 122 // Whether the user has declined to translate the page (by closing the infobar
105 // for example). This is necessary as a new infobar could be shown if a new 123 // for example). This is necessary as a new infobar could be shown if a new
106 // load happens in the page after the user closed the infobar. 124 // load happens in the page after the user closed the infobar.
107 bool translation_declined_; 125 bool translation_declined_;
108 126
109 // Whether the current navigation is a fragment navigation (in page). 127 // Whether the current navigation is a fragment navigation (in page).
110 bool in_page_navigation_; 128 bool in_page_navigation_;
111 129
130 // Whether the Translate is enabled.
131 bool translate_enabled_;
132
133 Observer* observer_;
134
112 DISALLOW_COPY_AND_ASSIGN(LanguageState); 135 DISALLOW_COPY_AND_ASSIGN(LanguageState);
113 }; 136 };
114 137
115 #endif // CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ 138 #endif // CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698