Commit 999163ce authored by Gang Wu's avatar Gang Wu Committed by Commit Bot

Fix the race condition between focusTextBox and onWindowFocusChanged

This CL to make sure that we request Urlbar focus after
onWindowFocusChanged, then UrlBar can receive clipboard suggestions.

Bug: 1104055
Change-Id: I3d0d7cccead1c348105dab50337e4575a46865bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2291321
Commit-Queue: Gang Wu <gangwu@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#787466}
parent 6bbe37f8
......@@ -38,6 +38,8 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout {
private boolean mPendingSearchPromoDecision;
private boolean mPendingBeginQuery;
private boolean mNativeLibraryReady;
private boolean mHasWindowFocus;
private boolean mUrlBarFocusRequested;
public SearchActivityLocationBarLayout(Context context, AttributeSet attrs) {
super(context, attrs, R.layout.location_bar_base);
......@@ -159,9 +161,8 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout {
// we don't start processing non-cached suggestion requests until that state
// is finalized after native has been initialized.
private void focusTextBox() {
if (!mUrlBar.hasFocus()) mUrlBar.requestFocus();
// Use cached suggestions only if native is not yet ready.
getAutocompleteCoordinator().setShowCachedZeroSuggestResults(!mNativeLibraryReady);
mUrlBarFocusRequested |= !mUrlBar.hasFocus();
ensureUrlBarFocusedAndTriggerZeroSuggest();
new Handler().post(new Runnable() {
@Override
......@@ -174,6 +175,26 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout {
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (!hasFocus) mUrlBar.clearFocus();
mHasWindowFocus = hasFocus;
if (hasFocus) {
ensureUrlBarFocusedAndTriggerZeroSuggest();
} else {
mUrlBar.clearFocus();
}
}
/**
* Since there is a race condition between {@link #focusTextBox()} and {@link
* #onWindowFocusChanged(boolean)}, if call mUrlBar.requestFocus() before onWindowFocusChanged
* is called, clipboard data will not been received since receive clipboard data needs focus
* (https://developer.android.com/reference/android/content/ClipboardManager#getPrimaryClip()).
*/
private void ensureUrlBarFocusedAndTriggerZeroSuggest() {
if (mUrlBarFocusRequested && mHasWindowFocus) {
mUrlBar.requestFocus();
mUrlBarFocusRequested = false;
}
// Use cached suggestions only if native is not yet ready.
getAutocompleteCoordinator().setShowCachedZeroSuggestResults(!mNativeLibraryReady);
}
}
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