From 5a24ca6788c61a71cb28089d4b2ab80e506cc50d Mon Sep 17 00:00:00 2001 From: "ajith.v" Date: Mon, 25 Jul 2016 21:12:21 -0700 Subject: [PATCH] Dismissing suggestion window upon receiving BACK key. Currently Tab is consuming the device BACK key even when suggestion window is visible and doing page navigation instead of dismissing suggestion window. Added changes to consume BACK key at suggestion window, so that it can consume BACK key and execute respective actions. BUG=630633 Review-Url: https://codereview.chromium.org/2174633004 Cr-Commit-Position: refs/heads/master@{#407703} --- .../browser/omnibox/LocationBarLayout.java | 16 +++++++++-- .../chrome/browser/omnibox/UrlBar.java | 28 +------------------ .../browser/toolbar/CustomTabToolbar.java | 3 -- 3 files changed, 14 insertions(+), 33 deletions(-) diff --git a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarLayout.java b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarLayout.java index e5425bf3b22d12..2de0a7c38e0167 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarLayout.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarLayout.java @@ -321,8 +321,19 @@ public void run() { }); } return true; + } else if (keyCode == KeyEvent.KEYCODE_BACK) { + if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { + // Tell the framework to start tracking this event. + getKeyDispatcherState().startTracking(event, this); + return true; + } else if (event.getAction() == KeyEvent.ACTION_UP) { + getKeyDispatcherState().handleUpEvent(event); + if (event.isTracking() && !event.isCanceled()) { + backKeyPressed(); + return true; + } + } } - return false; } @@ -1952,8 +1963,7 @@ public void run() { } } - @Override - public void backKeyPressed() { + private void backKeyPressed() { hideSuggestions(); UiUtils.hideKeyboard(mUrlBar); // Revert the URL to match the current page. diff --git a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/UrlBar.java b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/UrlBar.java index 45dae29e8e5065..ef895eef94f325 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/UrlBar.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/UrlBar.java @@ -20,10 +20,8 @@ import android.text.style.ReplacementSpan; import android.util.AttributeSet; import android.view.GestureDetector; -import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; -import android.view.View.OnKeyListener; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityNodeInfo; @@ -52,7 +50,7 @@ /** * The URL text entry view for the Omnibox. */ -public class UrlBar extends VerticallyFixedEditText implements OnKeyListener { +public class UrlBar extends VerticallyFixedEditText { private static final String TAG = "UrlBar"; // TextView becomes very slow on long strings, so we limit maximum length @@ -165,11 +163,6 @@ public interface UrlBarDelegate { */ void onTextChangedForAutocomplete(boolean textDeleted); - /** - * Called to notify that back key has been pressed while the focus in on the url bar. - */ - void backKeyPressed(); - /** * @return Whether the light security theme should be used. */ @@ -225,7 +218,6 @@ public boolean onSingleTapUp(MotionEvent e) { mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); - setOnKeyListener(this); } /** @@ -508,24 +500,6 @@ public View focusSearch(int direction) { } } - @Override - public boolean onKey(View v, int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { - // Tell the framework to start tracking this event. - getKeyDispatcherState().startTracking(event, this); - return true; - } else if (event.getAction() == KeyEvent.ACTION_UP) { - getKeyDispatcherState().handleUpEvent(event); - if (event.isTracking() && !event.isCanceled()) { - mUrlBarDelegate.backKeyPressed(); - return true; - } - } - } - return false; - } - @Override public boolean onTouchEvent(MotionEvent event) { if (!mFocused) { diff --git a/chrome/android/java/src/org/chromium/chrome/browser/toolbar/CustomTabToolbar.java b/chrome/android/java/src/org/chromium/chrome/browser/toolbar/CustomTabToolbar.java index 6e5ebf279662df..340b20fc72065f 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/toolbar/CustomTabToolbar.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/toolbar/CustomTabToolbar.java @@ -729,9 +729,6 @@ public void onTabLoadingNTP(NewTabPage ntp) {} @Override public void setAutocompleteProfile(Profile profile) {} - @Override - public void backKeyPressed() {} - @Override public void showAppMenuUpdateBadge() {}