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

Unified Diff: chrome/browser/ui/android/infobars/translate_compact_infobar.cc

Issue 2899893004: Code cleanup for Translate Compact Infobar. (Closed)
Patch Set: Merge branch 'master' into code-cleanup-5 Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/android/infobars/translate_compact_infobar.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/android/infobars/translate_compact_infobar.cc
diff --git a/chrome/browser/ui/android/infobars/translate_compact_infobar.cc b/chrome/browser/ui/android/infobars/translate_compact_infobar.cc
index db83575d2667f4ea2746f808a17021f630027b9b..c7470dd76216c0c3b81dcee60f3771b1e527b2c0 100644
--- a/chrome/browser/ui/android/infobars/translate_compact_infobar.cc
+++ b/chrome/browser/ui/android/infobars/translate_compact_infobar.cc
@@ -24,6 +24,10 @@ TranslateCompactInfoBar::TranslateCompactInfoBar(
std::unique_ptr<translate::TranslateInfoBarDelegate> delegate)
: InfoBarAndroid(std::move(delegate)), action_flags_(FLAG_NONE) {
GetDelegate()->SetObserver(this);
+
+ // Flip the translate bit if auto translate is enabled.
+ if (GetDelegate()->translate_step() == translate::TRANSLATE_STEP_TRANSLATING)
+ action_flags_ |= FLAG_TRANSLATE;
}
TranslateCompactInfoBar::~TranslateCompactInfoBar() {
@@ -59,7 +63,6 @@ void TranslateCompactInfoBar::ProcessButton(int action) {
if (!owner())
return; // We're closing; don't call anything, it might access the owner.
- // TODO(ramyasharma): Handle other button clicks.
translate::TranslateInfoBarDelegate* delegate = GetDelegate();
if (action == InfoBarAndroid::ACTION_TRANSLATE) {
action_flags_ |= FLAG_TRANSLATE;
@@ -72,8 +75,6 @@ void TranslateCompactInfoBar::ProcessButton(int action) {
} else if (action == InfoBarAndroid::ACTION_TRANSLATE_SHOW_ORIGINAL) {
action_flags_ |= FLAG_REVERT;
delegate->RevertWithoutClosingInfobar();
- } else if (action == InfoBarAndroid::ACTION_CANCEL) {
- delegate->TranslationDeclined();
} else {
DCHECK_EQ(InfoBarAndroid::ACTION_NONE, action);
}
@@ -141,8 +142,21 @@ bool TranslateCompactInfoBar::ShouldAutoAlwaysTranslate() {
jboolean TranslateCompactInfoBar::ShouldAutoNeverTranslate(
JNIEnv* env,
- const base::android::JavaParamRef<jobject>& obj) {
+ const base::android::JavaParamRef<jobject>& obj,
+ jboolean menu_expanded) {
+ // Flip menu expanded bit.
+ if (menu_expanded)
+ action_flags_ |= FLAG_EXPAND_MENU;
+
+ if (!IsDeclinedByUser())
+ return false;
+
translate::TranslateInfoBarDelegate* delegate = GetDelegate();
+ // Don't trigger if it's off the record or already blocked.
+ if (delegate->is_off_the_record() ||
+ !delegate->IsTranslatableLanguageByPrefs())
+ return false;
+
return (delegate->GetTranslationDeniedCount() == kDeniedCountThreshold);
}
@@ -165,8 +179,9 @@ void TranslateCompactInfoBar::OnTranslateStepChanged(
}
bool TranslateCompactInfoBar::IsDeclinedByUser() {
+ // Whether there is any affirmative action bit.
return action_flags_ == FLAG_NONE;
-};
+}
// Native JNI methods ---------------------------------------------------------
« no previous file with comments | « chrome/browser/ui/android/infobars/translate_compact_infobar.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698