Skip to content

Commit

Permalink
Dismissing suggestion window upon receiving BACK key.
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
ajith.v authored and Commit bot committed Jul 26, 2016
1 parent 36bb2be commit 5a24ca6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -225,7 +218,6 @@ public boolean onSingleTapUp(MotionEvent e) {

mAccessibilityManager =
(AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
setOnKeyListener(this);
}

/**
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,6 @@ public void onTabLoadingNTP(NewTabPage ntp) {}
@Override
public void setAutocompleteProfile(Profile profile) {}

@Override
public void backKeyPressed() {}

@Override
public void showAppMenuUpdateBadge() {}

Expand Down

0 comments on commit 5a24ca6

Please sign in to comment.