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

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

Issue 25373009: Translate: New Bubble UX (for the view toolkit) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Bug fix: view id on tests 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 (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 #include "chrome/browser/tab_contents/language_state.h" 5 #include "chrome/browser/tab_contents/language_state.h"
6 6
7 #include "chrome/browser/tab_contents/language_state_observer.h"
7 #include "content/public/browser/navigation_controller.h" 8 #include "content/public/browser/navigation_controller.h"
8 #include "content/public/browser/navigation_details.h" 9 #include "content/public/browser/navigation_details.h"
9 #include "content/public/browser/navigation_entry.h" 10 #include "content/public/browser/navigation_entry.h"
11 #include "content/public/browser/web_contents.h"
10 12
11 using content::NavigationController; 13 using content::NavigationController;
12 14
13 LanguageState::LanguageState(NavigationController* nav_controller) 15 LanguageState::LanguageState(NavigationController* nav_controller)
14 : navigation_controller_(nav_controller), 16 : navigation_controller_(nav_controller),
15 page_needs_translation_(false), 17 page_needs_translation_(false),
16 translation_pending_(false), 18 translation_pending_(false),
17 translation_declined_(false), 19 translation_declined_(false),
18 in_page_navigation_(false) { 20 in_page_navigation_(false),
21 translate_enabled_(false),
22 observer_(NULL) {
19 } 23 }
20 24
21 LanguageState::~LanguageState() { 25 LanguageState::~LanguageState() {
22 } 26 }
23 27
24 void LanguageState::DidNavigate( 28 void LanguageState::DidNavigate(
25 const content::LoadCommittedDetails& details) { 29 const content::LoadCommittedDetails& details) {
26 in_page_navigation_ = details.is_in_page; 30 in_page_navigation_ = details.is_in_page;
27 if (in_page_navigation_ || !details.is_main_frame) 31 if (in_page_navigation_ || !details.is_main_frame)
28 return; // Don't reset our states, the page has not changed. 32 return; // Don't reset our states, the page has not changed.
29 33
30 bool reload = 34 bool reload =
31 details.entry->GetTransitionType() == content::PAGE_TRANSITION_RELOAD || 35 details.entry->GetTransitionType() == content::PAGE_TRANSITION_RELOAD ||
32 details.type == content::NAVIGATION_TYPE_SAME_PAGE; 36 details.type == content::NAVIGATION_TYPE_SAME_PAGE;
33 if (reload) { 37 if (reload) {
34 // We might not get a LanguageDetermined notifications on reloads. Make sure 38 // We might not get a LanguageDetermined notifications on reloads. Make sure
35 // to keep the original language and to set current_lang_ so 39 // to keep the original language and to set current_lang_ so
36 // IsPageTranslated() returns false. 40 // IsPageTranslated() returns false.
37 current_lang_ = original_lang_; 41 current_lang_ = original_lang_;
38 } else { 42 } else {
39 prev_original_lang_ = original_lang_; 43 prev_original_lang_ = original_lang_;
40 prev_current_lang_ = current_lang_; 44 prev_current_lang_ = current_lang_;
41 original_lang_.clear(); 45 original_lang_.clear();
42 current_lang_.clear(); 46 current_lang_.clear();
43 } 47 }
44 48
45 translation_pending_ = false; 49 translation_pending_ = false;
46 translation_declined_ = false; 50 translation_declined_ = false;
51
52 SetTranslateEnabled(false);
47 } 53 }
48 54
49 void LanguageState::LanguageDetermined(const std::string& page_language, 55 void LanguageState::LanguageDetermined(const std::string& page_language,
50 bool page_needs_translation) { 56 bool page_needs_translation) {
51 if (in_page_navigation_ && !original_lang_.empty()) { 57 if (in_page_navigation_ && !original_lang_.empty()) {
52 // In-page navigation, we don't expect our states to change. 58 // In-page navigation, we don't expect our states to change.
53 // Note that we'll set the languages if original_lang_ is empty. This might 59 // Note that we'll set the languages if original_lang_ is empty. This might
54 // happen if the we did not get called on the top-page. 60 // happen if the we did not get called on the top-page.
55 return; 61 return;
56 } 62 }
(...skipping 20 matching lines...) Expand all
77 83
78 std::string LanguageState::AutoTranslateTo() const { 84 std::string LanguageState::AutoTranslateTo() const {
79 if (InTranslateNavigation() && 85 if (InTranslateNavigation() &&
80 // The page is not yet translated. 86 // The page is not yet translated.
81 original_lang_ == current_lang_ ) { 87 original_lang_ == current_lang_ ) {
82 return prev_current_lang_; 88 return prev_current_lang_;
83 } 89 }
84 90
85 return std::string(); 91 return std::string();
86 } 92 }
93
94 void LanguageState::SetTranslateEnabled(bool value) {
95 if (translate_enabled_ == value)
96 return;
97
98 translate_enabled_ = value;
99 if (observer_) {
100 content::WebContents* web_contents =
101 navigation_controller_->GetWebContents();
102 observer_->OnTranslateEnabledChanged(web_contents);
103 }
104 }
105
106 bool LanguageState::HasLanguageChanged() const {
107 return original_lang_ != prev_original_lang_;
108 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/language_state.h ('k') | chrome/browser/tab_contents/language_state_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698