Commit c3867b23 authored by Ted Choc's avatar Ted Choc Committed by Commit Bot

Fix zero suggestion for suggestions.

This CL:
https://chromium.googlesource.com/chromium/src/+/e9d6060f509e6a7b3a4f0bd944b1303a783f4a94
fixed an issue where suggestions were triggered on URL de-focus,
but it broke zero suggest because we trigger zero suggest on
focus before the animation completes.

To address this, this introduces a tri-state of allowed
suggestion visibility.  When focusing, we can request suggestions
but they won't be shown until the animation is complete.

When de-focusing, we disallow any suggestions being shown.

BUG=904367

Change-Id: I0a1b166158bc08bcc1f8d94b4fe15c6f4e663b02
Reviewed-on: https://chromium-review.googlesource.com/c/1331574Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607326}
parent aa553244
...@@ -9,6 +9,7 @@ import android.content.Context; ...@@ -9,6 +9,7 @@ import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.Handler; import android.os.Handler;
import android.os.SystemClock; import android.os.SystemClock;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
...@@ -47,6 +48,8 @@ import org.chromium.ui.base.DeviceFormFactor; ...@@ -47,6 +48,8 @@ import org.chromium.ui.base.DeviceFormFactor;
import org.chromium.ui.base.PageTransition; import org.chromium.ui.base.PageTransition;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -75,7 +78,17 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener { ...@@ -75,7 +78,17 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener {
private ToolbarDataProvider mDataProvider; private ToolbarDataProvider mDataProvider;
private boolean mNativeInitialized; private boolean mNativeInitialized;
private AutocompleteController mAutocomplete; private AutocompleteController mAutocomplete;
private boolean mCanShowSuggestions;
@IntDef({SuggestionVisibilityState.DISALLOWED, SuggestionVisibilityState.PENDING_ALLOW,
SuggestionVisibilityState.ALLOWED})
@Retention(RetentionPolicy.SOURCE)
private @interface SuggestionVisibilityState {
int DISALLOWED = 0;
int PENDING_ALLOW = 1;
int ALLOWED = 2;
}
@SuggestionVisibilityState
private int mSuggestionVisibilityState;
// The timestamp (using SystemClock.elapsedRealtime()) at the point when the user started // The timestamp (using SystemClock.elapsedRealtime()) at the point when the user started
// modifying the omnibox with new input. // modifying the omnibox with new input.
...@@ -491,6 +504,7 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener { ...@@ -491,6 +504,7 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener {
/** @see org.chromium.chrome.browser.omnibox.UrlFocusChangeListener#onUrlFocusChange(boolean) */ /** @see org.chromium.chrome.browser.omnibox.UrlFocusChangeListener#onUrlFocusChange(boolean) */
void onUrlFocusChange(boolean hasFocus) { void onUrlFocusChange(boolean hasFocus) {
if (hasFocus) { if (hasFocus) {
mSuggestionVisibilityState = SuggestionVisibilityState.PENDING_ALLOW;
if (mNativeInitialized) { if (mNativeInitialized) {
startZeroSuggest(); startZeroSuggest();
} else { } else {
...@@ -501,7 +515,7 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener { ...@@ -501,7 +515,7 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener {
}); });
} }
} else { } else {
mCanShowSuggestions = false; mSuggestionVisibilityState = SuggestionVisibilityState.DISALLOWED;
mHasStartedNewOmniboxEditSession = false; mHasStartedNewOmniboxEditSession = false;
mNewOmniboxEditSessionTimestamp = -1; mNewOmniboxEditSessionTimestamp = -1;
// Prevent any upcoming omnibox suggestions from showing once a URL is loaded (and as // Prevent any upcoming omnibox suggestions from showing once a URL is loaded (and as
...@@ -516,7 +530,8 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener { ...@@ -516,7 +530,8 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener {
* org.chromium.chrome.browser.omnibox.UrlFocusChangeListener#onUrlAnimationFinished(boolean) * org.chromium.chrome.browser.omnibox.UrlFocusChangeListener#onUrlAnimationFinished(boolean)
*/ */
void onUrlAnimationFinished(boolean hasFocus) { void onUrlAnimationFinished(boolean hasFocus) {
mCanShowSuggestions = hasFocus; mSuggestionVisibilityState =
hasFocus ? SuggestionVisibilityState.ALLOWED : SuggestionVisibilityState.DISALLOWED;
updateOmniboxSuggestionsVisibility(); updateOmniboxSuggestionsVisibility();
} }
...@@ -840,7 +855,10 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener { ...@@ -840,7 +855,10 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener {
@Override @Override
public void onSuggestionsReceived( public void onSuggestionsReceived(
List<OmniboxSuggestion> newSuggestions, String inlineAutocompleteText) { List<OmniboxSuggestion> newSuggestions, String inlineAutocompleteText) {
if (mShouldPreventOmniboxAutocomplete || !mCanShowSuggestions) return; if (mShouldPreventOmniboxAutocomplete
|| mSuggestionVisibilityState == SuggestionVisibilityState.DISALLOWED) {
return;
}
// This is a callback from a listener that is set up by onNativeLibraryReady, // This is a callback from a listener that is set up by onNativeLibraryReady,
// so can only be called once the native side is set up unless we are showing // so can only be called once the native side is set up unless we are showing
...@@ -1014,7 +1032,8 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener { ...@@ -1014,7 +1032,8 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener {
* Update whether the omnibox suggestions are visible. * Update whether the omnibox suggestions are visible.
*/ */
private void updateOmniboxSuggestionsVisibility() { private void updateOmniboxSuggestionsVisibility() {
boolean shouldBeVisible = mCanShowSuggestions && getSuggestionCount() > 0; boolean shouldBeVisible = mSuggestionVisibilityState == SuggestionVisibilityState.ALLOWED
&& getSuggestionCount() > 0;
boolean wasVisible = mListPropertyModel.get(SuggestionListProperties.VISIBLE); boolean wasVisible = mListPropertyModel.get(SuggestionListProperties.VISIBLE);
mListPropertyModel.set(SuggestionListProperties.VISIBLE, shouldBeVisible); mListPropertyModel.set(SuggestionListProperties.VISIBLE, shouldBeVisible);
if (shouldBeVisible && !wasVisible) { if (shouldBeVisible && !wasVisible) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment