Commit c40a0262 authored by Yusuf Ozuysal's avatar Yusuf Ozuysal Committed by Commit Bot

Revert "[StartSurface] Add long press behavior for the fake box"

This reverts commit 14f7eff8.

Reason for revert: Crashes on Canary with voice input

Original change's description:
> [StartSurface] Add long press behavior for the fake box
> 
> This CL is based on
> https://chromium-review.googlesource.com/c/chromium/src/+/1824554/3
> 
> It is the fourth patch of splitting the bigger one
> https://chromium-review.googlesource.com/c/chromium/src/+/1797069
> 
> It also unifies the record of the 'Android.OmniboxFocusReason' metrics.
> 
> Screenshot:
> https://drive.google.com/file/d/1YlxcF40SYtGVj9K0YgviQtnt5tdGFm-m/view?usp=sharing
> 
> Bug: 982018, 1012275
> Change-Id: I16d045777164d49d72356af474e5c186c8318370
> Binary-Size: crbug.com/998206
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1824126
> Commit-Queue: Ganggui Tang <gogerald@chromium.org>
> Reviewed-by: Yusuf Ozuysal <yusufo@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#705264}

TBR=yusufo@chromium.org,gogerald@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 982018, 1012275, 1013943
Change-Id: I4a48866d15dc65e8f939fe1c86867754eea87604
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1860598Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Commit-Queue: Yusuf Ozuysal <yusufo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705727}
parent 1d5cb12a
...@@ -22,10 +22,7 @@ class StartSurfaceLocationBarDelegate ...@@ -22,10 +22,7 @@ class StartSurfaceLocationBarDelegate
// Implements TasksSurface.FakeSearchBoxDelegate. // Implements TasksSurface.FakeSearchBoxDelegate.
@Override @Override
public void requestUrlFocus(@Nullable String pastedText) { public void requestUrlFocus(@Nullable String pastedText) {
mLocationBar.setUrlBarFocus(true, pastedText, mLocationBar.setUrlBarFocus(true);
pastedText == null
? LocationBar.OmniboxFocusReason.TASKS_SURFACE_FAKE_BOX_TAP
: LocationBar.OmniboxFocusReason.TASKS_SURFACE_FAKE_BOX_LONG_PRESS);
} }
// Implements StartSurfaceMediator.Delegate. // Implements StartSurfaceMediator.Delegate.
......
...@@ -5,15 +5,12 @@ ...@@ -5,15 +5,12 @@
package org.chromium.chrome.browser.tasks; package org.chromium.chrome.browser.tasks;
import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.FAKE_SEARCH_BOX_CLICK_LISTENER; import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.FAKE_SEARCH_BOX_CLICK_LISTENER;
import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.FAKE_SEARCH_BOX_TEXT_WATCHER;
import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.IS_FAKE_SEARCH_BOX_VISIBLE; import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.IS_FAKE_SEARCH_BOX_VISIBLE;
import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.IS_TAB_CAROUSEL; import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.IS_TAB_CAROUSEL;
import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.IS_VOICE_RECOGNITION_BUTTON_VISIBLE; import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.IS_VOICE_RECOGNITION_BUTTON_VISIBLE;
import android.content.Context; import android.content.Context;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View; import android.view.View;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
...@@ -39,28 +36,13 @@ class TasksSurfaceMediator { ...@@ -39,28 +36,13 @@ class TasksSurfaceMediator {
mFakeSearchBoxDelegate.requestUrlFocus(null); mFakeSearchBoxDelegate.requestUrlFocus(null);
} }
}); });
mModel.set(FAKE_SEARCH_BOX_TEXT_WATCHER, new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
if (s.length() == 0) return;
mFakeSearchBoxDelegate.requestUrlFocus(s.toString());
// This won't cause infinite loop since we checked s.length() == 0 above.
s.clear();
}
});
// Set the initial state. // Set the initial state.
mModel.set(IS_FAKE_SEARCH_BOX_VISIBLE, true); mModel.set(IS_FAKE_SEARCH_BOX_VISIBLE, true);
mModel.set(IS_VOICE_RECOGNITION_BUTTON_VISIBLE, false); mModel.set(IS_VOICE_RECOGNITION_BUTTON_VISIBLE, false);
// TODO(crbug.com/982018): Enable voice recognition button in the fake search box. // TODO(crbug.com/982018): Enable voice recognition button in the fake search box.
// TODO(crbug.com/982018): Enable long press and paste search in the fake search box.
// TODO(crbug.com/982018): Change the fake search box in dark mode. // TODO(crbug.com/982018): Change the fake search box in dark mode.
} }
} }
...@@ -6,7 +6,6 @@ package org.chromium.chrome.browser.tasks; ...@@ -6,7 +6,6 @@ package org.chromium.chrome.browser.tasks;
import static org.chromium.chrome.browser.tasks.MostVisitedListProperties.IS_VISIBLE; import static org.chromium.chrome.browser.tasks.MostVisitedListProperties.IS_VISIBLE;
import android.text.TextWatcher;
import android.view.View; import android.view.View;
import org.chromium.ui.modelutil.PropertyKey; import org.chromium.ui.modelutil.PropertyKey;
...@@ -28,15 +27,11 @@ public class TasksSurfaceProperties { ...@@ -28,15 +27,11 @@ public class TasksSurfaceProperties {
public static final PropertyModel public static final PropertyModel
.WritableObjectPropertyKey<View.OnClickListener> FAKE_SEARCH_BOX_CLICK_LISTENER = .WritableObjectPropertyKey<View.OnClickListener> FAKE_SEARCH_BOX_CLICK_LISTENER =
new PropertyModel.WritableObjectPropertyKey<View.OnClickListener>(); new PropertyModel.WritableObjectPropertyKey<View.OnClickListener>();
public static final PropertyModel
.WritableObjectPropertyKey<TextWatcher> FAKE_SEARCH_BOX_TEXT_WATCHER =
new PropertyModel.WritableObjectPropertyKey<TextWatcher>();
public static final PropertyModel public static final PropertyModel
.WritableObjectPropertyKey<View.OnClickListener> MORE_TABS_CLICK_LISTENER = .WritableObjectPropertyKey<View.OnClickListener> MORE_TABS_CLICK_LISTENER =
new PropertyModel.WritableObjectPropertyKey<View.OnClickListener>(); new PropertyModel.WritableObjectPropertyKey<View.OnClickListener>();
public static final PropertyModel.WritableBooleanPropertyKey MV_TILES_VISIBLE = IS_VISIBLE; public static final PropertyModel.WritableBooleanPropertyKey MV_TILES_VISIBLE = IS_VISIBLE;
public static final PropertyKey[] ALL_KEYS = public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {IS_FAKE_SEARCH_BOX_VISIBLE,
new PropertyKey[] {IS_FAKE_SEARCH_BOX_VISIBLE, IS_INCOGNITO, IS_TAB_CAROUSEL, IS_INCOGNITO, IS_TAB_CAROUSEL, IS_VOICE_RECOGNITION_BUTTON_VISIBLE,
IS_VOICE_RECOGNITION_BUTTON_VISIBLE, FAKE_SEARCH_BOX_CLICK_LISTENER, FAKE_SEARCH_BOX_CLICK_LISTENER, MORE_TABS_CLICK_LISTENER, MV_TILES_VISIBLE};
FAKE_SEARCH_BOX_TEXT_WATCHER, MORE_TABS_CLICK_LISTENER, MV_TILES_VISIBLE};
} }
...@@ -7,7 +7,6 @@ package org.chromium.chrome.browser.tasks; ...@@ -7,7 +7,6 @@ package org.chromium.chrome.browser.tasks;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.support.v4.view.MarginLayoutParamsCompat; import android.support.v4.view.MarginLayoutParamsCompat;
import android.text.TextWatcher;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -76,14 +75,6 @@ class TasksView extends LinearLayout { ...@@ -76,14 +75,6 @@ class TasksView extends LinearLayout {
mSearchBoxText.setOnClickListener(listener); mSearchBoxText.setOnClickListener(listener);
} }
/**
* Set the given watcher for the fake search box.
* @param textWatcher The given {@link TextWatcher}.
*/
void setFakeSearchBoxTextWatcher(TextWatcher textWatcher) {
mSearchBoxText.addTextChangedListener(textWatcher);
}
/** /**
* Set the visibility of the fake search box. * Set the visibility of the fake search box.
* @param isVisible Whether it's visible. * @param isVisible Whether it's visible.
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package org.chromium.chrome.browser.tasks; package org.chromium.chrome.browser.tasks;
import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.FAKE_SEARCH_BOX_CLICK_LISTENER; import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.FAKE_SEARCH_BOX_CLICK_LISTENER;
import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.FAKE_SEARCH_BOX_TEXT_WATCHER;
import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.IS_FAKE_SEARCH_BOX_VISIBLE; import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.IS_FAKE_SEARCH_BOX_VISIBLE;
import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.IS_INCOGNITO; import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.IS_INCOGNITO;
import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.IS_TAB_CAROUSEL; import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.IS_TAB_CAROUSEL;
...@@ -23,8 +22,6 @@ class TasksViewBinder { ...@@ -23,8 +22,6 @@ class TasksViewBinder {
public static void bind(PropertyModel model, TasksView view, PropertyKey propertyKey) { public static void bind(PropertyModel model, TasksView view, PropertyKey propertyKey) {
if (propertyKey == FAKE_SEARCH_BOX_CLICK_LISTENER) { if (propertyKey == FAKE_SEARCH_BOX_CLICK_LISTENER) {
view.setFakeSearchBoxClickListener(model.get(FAKE_SEARCH_BOX_CLICK_LISTENER)); view.setFakeSearchBoxClickListener(model.get(FAKE_SEARCH_BOX_CLICK_LISTENER));
} else if (propertyKey == FAKE_SEARCH_BOX_TEXT_WATCHER) {
view.setFakeSearchBoxTextWatcher(model.get(FAKE_SEARCH_BOX_TEXT_WATCHER));
} else if (propertyKey == IS_FAKE_SEARCH_BOX_VISIBLE) { } else if (propertyKey == IS_FAKE_SEARCH_BOX_VISIBLE) {
view.setFakeSearchBoxVisibility(model.get(IS_FAKE_SEARCH_BOX_VISIBLE)); view.setFakeSearchBoxVisibility(model.get(IS_FAKE_SEARCH_BOX_VISIBLE));
} else if (propertyKey == IS_INCOGNITO) { } else if (propertyKey == IS_INCOGNITO) {
......
...@@ -106,7 +106,6 @@ import org.chromium.chrome.browser.night_mode.WebContentsDarkModeController; ...@@ -106,7 +106,6 @@ import org.chromium.chrome.browser.night_mode.WebContentsDarkModeController;
import org.chromium.chrome.browser.ntp.NewTabPage; import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.ntp.NewTabPageUma; import org.chromium.chrome.browser.ntp.NewTabPageUma;
import org.chromium.chrome.browser.omaha.OmahaBase; import org.chromium.chrome.browser.omaha.OmahaBase;
import org.chromium.chrome.browser.omnibox.LocationBar;
import org.chromium.chrome.browser.partnercustomizations.HomepageManager; import org.chromium.chrome.browser.partnercustomizations.HomepageManager;
import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomizations; import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomizations;
import org.chromium.chrome.browser.preferences.ChromePreferenceManager; import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
...@@ -1533,9 +1532,7 @@ public class ChromeTabbedActivity extends ChromeActivity implements ScreenshotMo ...@@ -1533,9 +1532,7 @@ public class ChromeTabbedActivity extends ChromeActivity implements ScreenshotMo
assert false : "Unknown TabOpenType: " + tabOpenType; assert false : "Unknown TabOpenType: " + tabOpenType;
break; break;
} }
getToolbarManager().setUrlBarFocusOnceNativeInitialized(focus, getToolbarManager().setUrlBarFocusOnceNativeInitialized(focus);
focus ? LocationBar.OmniboxFocusReason.LAUNCH_NEW_INCOGNITO_TAB
: LocationBar.OmniboxFocusReason.UNFOCUS);
} }
@Override @Override
...@@ -1831,8 +1828,7 @@ public class ChromeTabbedActivity extends ChromeActivity implements ScreenshotMo ...@@ -1831,8 +1828,7 @@ public class ChromeTabbedActivity extends ChromeActivity implements ScreenshotMo
boolean isUrlBarVisible = !mOverviewModeController.overviewVisible() boolean isUrlBarVisible = !mOverviewModeController.overviewVisible()
&& (!isTablet() || getCurrentTabModel().getCount() != 0); && (!isTablet() || getCurrentTabModel().getCount() != 0);
if (isUrlBarVisible) { if (isUrlBarVisible) {
getToolbarManager().setUrlBarFocus( getToolbarManager().setUrlBarFocus(true);
true, LocationBar.OmniboxFocusReason.MENU_OR_KEYBOARD_ACTION);
} }
} else if (id == R.id.downloads_menu_id) { } else if (id == R.id.downloads_menu_id) {
DownloadUtils.showDownloadManager(this, currentTab, DownloadOpenSource.MENU); DownloadUtils.showDownloadManager(this, currentTab, DownloadOpenSource.MENU);
......
...@@ -22,7 +22,6 @@ import org.chromium.chrome.browser.ChromeActivity; ...@@ -22,7 +22,6 @@ import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel; import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel;
import org.chromium.chrome.browser.contextualsearch.ContextualSearchManager; import org.chromium.chrome.browser.contextualsearch.ContextualSearchManager;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager; import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
import org.chromium.chrome.browser.omnibox.LocationBar;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabAttributeKeys; import org.chromium.chrome.browser.tab.TabAttributeKeys;
import org.chromium.chrome.browser.tab.TabAttributes; import org.chromium.chrome.browser.tab.TabAttributes;
...@@ -325,8 +324,7 @@ public class TabModalPresenter ...@@ -325,8 +324,7 @@ public class TabModalPresenter
// Force toolbar to show and disable overflow menu. // Force toolbar to show and disable overflow menu.
onTabModalDialogStateChanged(true); onTabModalDialogStateChanged(true);
mChromeActivity.getToolbarManager().setUrlBarFocus( mChromeActivity.getToolbarManager().setUrlBarFocus(false);
false, LocationBar.OmniboxFocusReason.UNFOCUS);
menuButton.setEnabled(false); menuButton.setEnabled(false);
} else { } else {
......
...@@ -9,9 +9,6 @@ import android.view.View; ...@@ -9,9 +9,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import org.chromium.chrome.browser.ActivityTabProvider; import org.chromium.chrome.browser.ActivityTabProvider;
import org.chromium.chrome.browser.WindowDelegate; import org.chromium.chrome.browser.WindowDelegate;
import org.chromium.chrome.browser.ntp.NewTabPage; import org.chromium.chrome.browser.ntp.NewTabPage;
...@@ -23,41 +20,10 @@ import org.chromium.chrome.browser.toolbar.top.Toolbar; ...@@ -23,41 +20,10 @@ import org.chromium.chrome.browser.toolbar.top.Toolbar;
import org.chromium.chrome.browser.toolbar.top.ToolbarActionModeCallback; import org.chromium.chrome.browser.toolbar.top.ToolbarActionModeCallback;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/** /**
* Container that holds the {@link UrlBar} and SSL state related with the current {@link Tab}. * Container that holds the {@link UrlBar} and SSL state related with the current {@link Tab}.
*/ */
public interface LocationBar extends UrlBarDelegate { public interface LocationBar extends UrlBarDelegate {
/** A means of tracking which mechanism is being used to focus the omnibox. */
@IntDef({OmniboxFocusReason.OMNIBOX_TAP, OmniboxFocusReason.OMNIBOX_LONG_PRESS,
OmniboxFocusReason.FAKE_BOX_TAP, OmniboxFocusReason.FAKE_BOX_LONG_PRESS,
OmniboxFocusReason.ACCELERATOR_TAP, OmniboxFocusReason.TAB_SWITCHER_OMNIBOX_TAP,
OmniboxFocusReason.TASKS_SURFACE_FAKE_BOX_TAP,
OmniboxFocusReason.TASKS_SURFACE_FAKE_BOX_LONG_PRESS,
OmniboxFocusReason.DEFAULT_WITH_HARDWARE_KEYBOARD, OmniboxFocusReason.SEARCH_QUERY,
OmniboxFocusReason.LAUNCH_NEW_INCOGNITO_TAB, OmniboxFocusReason.MENU_OR_KEYBOARD_ACTION,
OmniboxFocusReason.UNFOCUS})
@Retention(RetentionPolicy.SOURCE)
public @interface OmniboxFocusReason {
int OMNIBOX_TAP = 0;
int OMNIBOX_LONG_PRESS = 1;
int FAKE_BOX_TAP = 2;
int FAKE_BOX_LONG_PRESS = 3;
int ACCELERATOR_TAP = 4;
// TAB_SWITCHER_OMNIBOX_TAP has not been used anymore, keep it for record for now.
int TAB_SWITCHER_OMNIBOX_TAP = 5;
int TASKS_SURFACE_FAKE_BOX_TAP = 6;
int TASKS_SURFACE_FAKE_BOX_LONG_PRESS = 7;
int DEFAULT_WITH_HARDWARE_KEYBOARD = 8;
int SEARCH_QUERY = 9;
int LAUNCH_NEW_INCOGNITO_TAB = 10;
int MENU_OR_KEYBOARD_ACTION = 11;
int UNFOCUS = 12;
int NUM_ENTRIES = 13;
}
/** /**
* Cleanup resources when this goes out of scope. * Cleanup resources when this goes out of scope.
*/ */
...@@ -156,11 +122,8 @@ public interface LocationBar extends UrlBarDelegate { ...@@ -156,11 +122,8 @@ public interface LocationBar extends UrlBarDelegate {
* Signal a {@link UrlBar} focus change request. * Signal a {@link UrlBar} focus change request.
* @param shouldBeFocused Whether the focus should be requested or cleared. True requests focus * @param shouldBeFocused Whether the focus should be requested or cleared. True requests focus
* and False clears focus. * and False clears focus.
* @param pastedText The given pasted text when focus, which could be null.
* @param reason The given reason.
*/ */
void setUrlBarFocus( void setUrlBarFocus(boolean shouldBeFocused);
boolean shouldBeFocused, @Nullable String pastedText, @OmniboxFocusReason int reason);
/** /**
* Triggers the cursor to be visible in the UrlBar without triggering any of the focus animation * Triggers the cursor to be visible in the UrlBar without triggering any of the focus animation
......
...@@ -30,7 +30,6 @@ import org.chromium.base.ApiCompatibilityUtils; ...@@ -30,7 +30,6 @@ import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.CommandLine; import org.chromium.base.CommandLine;
import org.chromium.base.ObserverList; import org.chromium.base.ObserverList;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.CachedMetrics.EnumeratedHistogramSample;
import org.chromium.base.metrics.RecordUserAction; import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ActivityTabProvider; import org.chromium.chrome.browser.ActivityTabProvider;
...@@ -42,7 +41,6 @@ import org.chromium.chrome.browser.native_page.NativePageFactory; ...@@ -42,7 +41,6 @@ import org.chromium.chrome.browser.native_page.NativePageFactory;
import org.chromium.chrome.browser.ntp.NewTabPage; import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.ntp.NewTabPage.FakeboxDelegate; import org.chromium.chrome.browser.ntp.NewTabPage.FakeboxDelegate;
import org.chromium.chrome.browser.ntp.NewTabPageUma; import org.chromium.chrome.browser.ntp.NewTabPageUma;
import org.chromium.chrome.browser.omnibox.LocationBar.OmniboxFocusReason;
import org.chromium.chrome.browser.omnibox.UrlBar.ScrollType; import org.chromium.chrome.browser.omnibox.UrlBar.ScrollType;
import org.chromium.chrome.browser.omnibox.UrlBarCoordinator.SelectionState; import org.chromium.chrome.browser.omnibox.UrlBarCoordinator.SelectionState;
import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader; import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader;
...@@ -58,6 +56,7 @@ import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory; ...@@ -58,6 +56,7 @@ import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tasks.ReturnToChromeExperimentsUtil; import org.chromium.chrome.browser.tasks.ReturnToChromeExperimentsUtil;
import org.chromium.chrome.browser.toolbar.ToolbarDataProvider; import org.chromium.chrome.browser.toolbar.ToolbarDataProvider;
import org.chromium.chrome.browser.toolbar.ToolbarManager;
import org.chromium.chrome.browser.toolbar.top.ToolbarActionModeCallback; import org.chromium.chrome.browser.toolbar.top.ToolbarActionModeCallback;
import org.chromium.chrome.browser.ui.widget.CompositeTouchDelegate; import org.chromium.chrome.browser.ui.widget.CompositeTouchDelegate;
import org.chromium.chrome.browser.util.AccessibilityUtil; import org.chromium.chrome.browser.util.AccessibilityUtil;
...@@ -78,10 +77,6 @@ import java.util.List; ...@@ -78,10 +77,6 @@ import java.util.List;
public class LocationBarLayout extends FrameLayout public class LocationBarLayout extends FrameLayout
implements OnClickListener, LocationBar, AutocompleteDelegate, FakeboxDelegate, implements OnClickListener, LocationBar, AutocompleteDelegate, FakeboxDelegate,
LocationBarVoiceRecognitionHandler.Delegate { LocationBarVoiceRecognitionHandler.Delegate {
private static final EnumeratedHistogramSample ENUMERATED_FOCUS_REASON =
new EnumeratedHistogramSample(
"Android.OmniboxFocusReason", OmniboxFocusReason.NUM_ENTRIES);
protected ImageButton mDeleteButton; protected ImageButton mDeleteButton;
protected ImageButton mMicButton; protected ImageButton mMicButton;
protected UrlBar mUrlBar; protected UrlBar mUrlBar;
...@@ -264,7 +259,7 @@ public class LocationBarLayout extends FrameLayout ...@@ -264,7 +259,7 @@ public class LocationBarLayout extends FrameLayout
&& newConfig.keyboard != Configuration.KEYBOARD_QWERTY) { && newConfig.keyboard != Configuration.KEYBOARD_QWERTY) {
// If we lose the hardware keyboard and the focus animations were not run, then the // If we lose the hardware keyboard and the focus animations were not run, then the
// user has not typed any text, so we will just clear the focus instead. // user has not typed any text, so we will just clear the focus instead.
setUrlBarFocus(false, null, LocationBar.OmniboxFocusReason.UNFOCUS); setUrlBarFocus(false);
} }
} }
...@@ -371,35 +366,13 @@ public class LocationBarLayout extends FrameLayout ...@@ -371,35 +366,13 @@ public class LocationBarLayout extends FrameLayout
} }
@Override @Override
public void setUrlBarFocus( public void setUrlBarFocus(boolean shouldBeFocused) {
boolean shouldBeFocused, @Nullable String pastedText, @OmniboxFocusReason int reason) {
if (shouldBeFocused) { if (shouldBeFocused) {
if (!mUrlHasFocus) recordOmniboxFocusReason(reason); mUrlBar.requestFocus();
if (reason == LocationBar.OmniboxFocusReason.FAKE_BOX_TAP
|| reason == LocationBar.OmniboxFocusReason.FAKE_BOX_LONG_PRESS
|| reason == LocationBar.OmniboxFocusReason.TASKS_SURFACE_FAKE_BOX_LONG_PRESS
|| reason == LocationBar.OmniboxFocusReason.TASKS_SURFACE_FAKE_BOX_TAP) {
mUrlFocusedFromFakebox = true;
}
if (mUrlHasFocus && mUrlFocusedWithoutAnimations) {
handleUrlFocusAnimation(mUrlHasFocus);
} else {
mUrlBar.requestFocus();
}
} else { } else {
assert pastedText == null;
hideKeyboard(); hideKeyboard();
mUrlBar.clearFocus(); mUrlBar.clearFocus();
} }
if (pastedText != null) {
// This must be happen after requestUrlFocus(), which changes the selection.
mUrlCoordinator.setUrlBarData(UrlBarData.forNonUrlText(pastedText),
UrlBar.ScrollType.NO_SCROLL, UrlBarCoordinator.SelectionState.SELECT_END);
forceOnTextChanged();
}
} }
@Override @Override
...@@ -409,7 +382,7 @@ public class LocationBarLayout extends FrameLayout ...@@ -409,7 +382,7 @@ public class LocationBarLayout extends FrameLayout
@Override @Override
public void clearOmniboxFocus() { public void clearOmniboxFocus() {
setUrlBarFocus(false, null, LocationBar.OmniboxFocusReason.UNFOCUS); setUrlBarFocus(false);
} }
@Override @Override
...@@ -562,11 +535,23 @@ public class LocationBarLayout extends FrameLayout ...@@ -562,11 +535,23 @@ public class LocationBarLayout extends FrameLayout
@Override @Override
public void requestUrlFocusFromFakebox(String pastedText) { public void requestUrlFocusFromFakebox(String pastedText) {
// TODO(crbug.com/1013693): Get rid of requestUrlFocusFromFakebox to let the caller uses mUrlFocusedFromFakebox = true;
// setUrlBarFocus directly. if (mUrlHasFocus && mUrlFocusedWithoutAnimations) {
setUrlBarFocus(true, pastedText, handleUrlFocusAnimation(mUrlHasFocus);
pastedText == null ? LocationBar.OmniboxFocusReason.FAKE_BOX_TAP } else {
: LocationBar.OmniboxFocusReason.FAKE_BOX_LONG_PRESS); setUrlBarFocus(true);
}
if (pastedText != null) {
ToolbarManager.recordOmniboxFocusReason(
ToolbarManager.OmniboxFocusReason.FAKE_BOX_LONG_PRESS);
// This must be happen after requestUrlFocus(), which changes the selection.
mUrlCoordinator.setUrlBarData(UrlBarData.forNonUrlText(pastedText),
UrlBar.ScrollType.NO_SCROLL, UrlBarCoordinator.SelectionState.SELECT_END);
forceOnTextChanged();
} else {
ToolbarManager.recordOmniboxFocusReason(ToolbarManager.OmniboxFocusReason.FAKE_BOX_TAP);
}
} }
@Override @Override
...@@ -585,10 +570,7 @@ public class LocationBarLayout extends FrameLayout ...@@ -585,10 +570,7 @@ public class LocationBarLayout extends FrameLayout
if (mUrlHasFocus || mUrlFocusedFromFakebox) return; if (mUrlHasFocus || mUrlFocusedFromFakebox) return;
mUrlFocusedWithoutAnimations = true; mUrlFocusedWithoutAnimations = true;
setUrlBarFocus(true);
// This interface should only be called to devices with a hardware keyboard attached as
// described in the LocationBar.
setUrlBarFocus(true, null, LocationBar.OmniboxFocusReason.DEFAULT_WITH_HARDWARE_KEYBOARD);
} }
/** /**
...@@ -817,7 +799,7 @@ public class LocationBarLayout extends FrameLayout ...@@ -817,7 +799,7 @@ public class LocationBarLayout extends FrameLayout
setUrlBarText(UrlBarData.forNonUrlText(query), UrlBar.ScrollType.NO_SCROLL, setUrlBarText(UrlBarData.forNonUrlText(query), UrlBar.ScrollType.NO_SCROLL,
SelectionState.SELECT_ALL); SelectionState.SELECT_ALL);
setUrlBarFocus(true, null, LocationBar.OmniboxFocusReason.SEARCH_QUERY); setUrlBarFocus(true);
mAutocompleteCoordinator.startAutocompleteForQuery(query); mAutocompleteCoordinator.startAutocompleteForQuery(query);
post(new Runnable() { post(new Runnable() {
@Override @Override
...@@ -844,7 +826,7 @@ public class LocationBarLayout extends FrameLayout ...@@ -844,7 +826,7 @@ public class LocationBarLayout extends FrameLayout
@Override @Override
public void backKeyPressed() { public void backKeyPressed() {
setUrlBarFocus(false, null, LocationBar.OmniboxFocusReason.UNFOCUS); setUrlBarFocus(false);
// Revert the URL to match the current page. // Revert the URL to match the current page.
setUrlToPageUrl(); setUrlToPageUrl();
focusCurrentTab(); focusCurrentTab();
...@@ -863,12 +845,6 @@ public class LocationBarLayout extends FrameLayout ...@@ -863,12 +845,6 @@ public class LocationBarLayout extends FrameLayout
return mToolbarDataProvider.getDisplaySearchTerms() != null; return mToolbarDataProvider.getDisplaySearchTerms() != null;
} }
@Override
public void gestureDetected(boolean isLongPress) {
recordOmniboxFocusReason(isLongPress ? LocationBar.OmniboxFocusReason.OMNIBOX_LONG_PRESS
: LocationBar.OmniboxFocusReason.OMNIBOX_TAP);
}
/** /**
* @return Returns the original url of the page. * @return Returns the original url of the page.
*/ */
...@@ -894,7 +870,7 @@ public class LocationBarLayout extends FrameLayout ...@@ -894,7 +870,7 @@ public class LocationBarLayout extends FrameLayout
// If we did not run the focus animations, then the user has not typed any text. // If we did not run the focus animations, then the user has not typed any text.
// So, clear the focus and accept whatever URL the page is currently attempting to // So, clear the focus and accept whatever URL the page is currently attempting to
// display. If the NTP is showing, the current page's URL should not be displayed. // display. If the NTP is showing, the current page's URL should not be displayed.
setUrlBarFocus(false, null, LocationBar.OmniboxFocusReason.UNFOCUS); setUrlBarFocus(false);
} else { } else {
return; return;
} }
...@@ -1143,8 +1119,4 @@ public class LocationBarLayout extends FrameLayout ...@@ -1143,8 +1119,4 @@ public class LocationBarLayout extends FrameLayout
String textWithAutocomplete = mUrlCoordinator.getTextWithAutocomplete(); String textWithAutocomplete = mUrlCoordinator.getTextWithAutocomplete();
mAutocompleteCoordinator.onTextChanged(textWithoutAutocomplete, textWithAutocomplete); mAutocompleteCoordinator.onTextChanged(textWithoutAutocomplete, textWithAutocomplete);
} }
private void recordOmniboxFocusReason(@OmniboxFocusReason int reason) {
ENUMERATED_FOCUS_REASON.record(reason);
}
} }
...@@ -42,6 +42,7 @@ import org.chromium.base.SysUtils; ...@@ -42,6 +42,7 @@ import org.chromium.base.SysUtils;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.metrics.CachedMetrics; import org.chromium.base.metrics.CachedMetrics;
import org.chromium.chrome.browser.WindowDelegate; import org.chromium.chrome.browser.WindowDelegate;
import org.chromium.chrome.browser.toolbar.ToolbarManager;
import org.chromium.ui.KeyboardVisibilityDelegate; import org.chromium.ui.KeyboardVisibilityDelegate;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
...@@ -209,12 +210,6 @@ public abstract class UrlBar extends AutocompleteEditText { ...@@ -209,12 +210,6 @@ public abstract class UrlBar extends AutocompleteEditText {
* whatever's in the URL bar verbatim. * whatever's in the URL bar verbatim.
*/ */
boolean shouldCutCopyVerbatim(); boolean shouldCutCopyVerbatim();
/**
* Called to notify that a tap or long press gesture has been detected.
* @param isLongPress Whether or not is a long press gesture.
*/
void gestureDetected(boolean isLongPress);
} }
/** Provides updates about the URL text changes. */ /** Provides updates about the URL text changes. */
...@@ -277,14 +272,16 @@ public abstract class UrlBar extends AutocompleteEditText { ...@@ -277,14 +272,16 @@ public abstract class UrlBar extends AutocompleteEditText {
new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() { new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
@Override @Override
public void onLongPress(MotionEvent e) { public void onLongPress(MotionEvent e) {
mUrlBarDelegate.gestureDetected(true); ToolbarManager.recordOmniboxFocusReason(
ToolbarManager.OmniboxFocusReason.OMNIBOX_LONG_PRESS);
performLongClick(); performLongClick();
} }
@Override @Override
public boolean onSingleTapUp(MotionEvent e) { public boolean onSingleTapUp(MotionEvent e) {
requestFocus(); requestFocus();
mUrlBarDelegate.gestureDetected(false); ToolbarManager.recordOmniboxFocusReason(
ToolbarManager.OmniboxFocusReason.OMNIBOX_TAP);
return true; return true;
} }
}, ThreadUtils.getUiThreadHandler()); }, ThreadUtils.getUiThreadHandler());
......
...@@ -19,6 +19,7 @@ import android.view.View.OnClickListener; ...@@ -19,6 +19,7 @@ import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener; import android.view.View.OnLongClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
...@@ -26,6 +27,7 @@ import org.chromium.base.ApiCompatibilityUtils; ...@@ -26,6 +27,7 @@ import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.CachedMetrics.ActionEvent; import org.chromium.base.metrics.CachedMetrics.ActionEvent;
import org.chromium.base.metrics.CachedMetrics.EnumeratedHistogramSample;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction; import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R; import org.chromium.chrome.R;
...@@ -123,6 +125,8 @@ import org.chromium.ui.base.PageTransition; ...@@ -123,6 +125,8 @@ import org.chromium.ui.base.PageTransition;
import org.chromium.ui.widget.Toast; import org.chromium.ui.widget.Toast;
import org.chromium.ui.widget.ViewRectProvider; import org.chromium.ui.widget.ViewRectProvider;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List; import java.util.List;
/** /**
...@@ -143,6 +147,23 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF ...@@ -143,6 +147,23 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
void updateReloadButtonState(boolean isLoading); void updateReloadButtonState(boolean isLoading);
} }
/** A means of tracking which mechanism is being used to focus the omnibox. */
@IntDef({OmniboxFocusReason.OMNIBOX_TAP, OmniboxFocusReason.OMNIBOX_LONG_PRESS,
OmniboxFocusReason.FAKE_BOX_TAP, OmniboxFocusReason.FAKE_BOX_LONG_PRESS,
OmniboxFocusReason.ACCELERATOR_TAP, OmniboxFocusReason.TAB_SWITCHER_OMNIBOX_TAP})
@Retention(RetentionPolicy.SOURCE)
public @interface OmniboxFocusReason {
int OMNIBOX_TAP = 0;
int OMNIBOX_LONG_PRESS = 1;
int FAKE_BOX_TAP = 2;
int FAKE_BOX_LONG_PRESS = 3;
int ACCELERATOR_TAP = 4;
int TAB_SWITCHER_OMNIBOX_TAP = 5;
int NUM_ENTRIES = 6;
}
private static final EnumeratedHistogramSample ENUMERATED_FOCUS_REASON =
new EnumeratedHistogramSample(
"Android.OmniboxFocusReason", OmniboxFocusReason.NUM_ENTRIES);
private static final ActionEvent ACCELERATOR_BUTTON_TAP_ACTION = private static final ActionEvent ACCELERATOR_BUTTON_TAP_ACTION =
new ActionEvent("MobileToolbarOmniboxAcceleratorTap"); new ActionEvent("MobileToolbarOmniboxAcceleratorTap");
...@@ -725,7 +746,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF ...@@ -725,7 +746,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
@Override @Override
public void onScrimClick() { public void onScrimClick() {
setUrlBarFocus(false, LocationBar.OmniboxFocusReason.UNFOCUS); setUrlBarFocus(false);
} }
/** /**
...@@ -735,6 +756,17 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF ...@@ -735,6 +756,17 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
return mLocationBar.isUrlBarFocused(); return mLocationBar.isUrlBarFocused();
} }
/**
* @param reason A {@link OmniboxFocusReason} that the omnibox was focused.
*/
public static void recordOmniboxFocusReason(@OmniboxFocusReason int reason) {
if (OmniboxFocusReason.OMNIBOX_TAP == reason
&& ReturnToChromeExperimentsUtil.isInOverviewWithOmnibox()) {
reason = OmniboxFocusReason.TAB_SWITCHER_OMNIBOX_TAP;
}
ENUMERATED_FOCUS_REASON.record(reason);
}
/** /**
* Enable the bottom toolbar. * Enable the bottom toolbar.
*/ */
...@@ -747,8 +779,9 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF ...@@ -747,8 +779,9 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
final OnClickListener searchAcceleratorListener = v -> { final OnClickListener searchAcceleratorListener = v -> {
recordBottomToolbarUseForIPH(); recordBottomToolbarUseForIPH();
recordOmniboxFocusReason(OmniboxFocusReason.ACCELERATOR_TAP);
ACCELERATOR_BUTTON_TAP_ACTION.record(); ACCELERATOR_BUTTON_TAP_ACTION.record();
setUrlBarFocus(true, LocationBar.OmniboxFocusReason.ACCELERATOR_TAP); setUrlBarFocus(true);
}; };
final OnClickListener shareButtonListener = v -> { final OnClickListener shareButtonListener = v -> {
...@@ -1341,7 +1374,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF ...@@ -1341,7 +1374,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
if (isVisible) { if (isVisible) {
// Defocus here to avoid handling focus in multiple places, e.g., when the // Defocus here to avoid handling focus in multiple places, e.g., when the
// forward button is pressed. (see crbug.com/414219) // forward button is pressed. (see crbug.com/414219)
setUrlBarFocus(false, LocationBar.OmniboxFocusReason.UNFOCUS); setUrlBarFocus(false);
if (!mActivity.isInOverviewMode() && isShowingAppMenuUpdateBadge()) { if (!mActivity.isInOverviewMode() && isShowingAppMenuUpdateBadge()) {
// The app menu badge should be removed the first time the menu is opened. // The app menu badge should be removed the first time the menu is opened.
...@@ -1642,12 +1675,11 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF ...@@ -1642,12 +1675,11 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
* If you request focus and the UrlBar was already focused, this will select all of the text. * If you request focus and the UrlBar was already focused, this will select all of the text.
* *
* @param focused Whether URL bar should be focused. * @param focused Whether URL bar should be focused.
* @param reason The given reason.
*/ */
public void setUrlBarFocus(boolean focused, @LocationBar.OmniboxFocusReason int reason) { public void setUrlBarFocus(boolean focused) {
if (!isInitialized()) return; if (!isInitialized()) return;
boolean wasFocused = mLocationBar.isUrlBarFocused(); boolean wasFocused = mLocationBar.isUrlBarFocused();
mLocationBar.setUrlBarFocus(focused, null, reason); mLocationBar.setUrlBarFocus(focused);
if (wasFocused && focused) { if (wasFocused && focused) {
mLocationBar.selectAll(); mLocationBar.selectAll();
} }
...@@ -1657,10 +1689,9 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF ...@@ -1657,10 +1689,9 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
* See {@link #setUrlBarFocus}, but if native is not loaded it will queue the request instead * See {@link #setUrlBarFocus}, but if native is not loaded it will queue the request instead
* of dropping it. * of dropping it.
*/ */
public void setUrlBarFocusOnceNativeInitialized( public void setUrlBarFocusOnceNativeInitialized(boolean focused) {
boolean focused, @LocationBar.OmniboxFocusReason int reason) {
if (isInitialized()) { if (isInitialized()) {
setUrlBarFocus(focused, reason); setUrlBarFocus(focused);
return; return;
} }
...@@ -1669,7 +1700,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF ...@@ -1669,7 +1700,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
// initialized. This is important for the Launch to Incognito Tab flow (see // initialized. This is important for the Launch to Incognito Tab flow (see
// IncognitoTabLauncher. // IncognitoTabLauncher.
mOnInitializedRunnable = () -> { mOnInitializedRunnable = () -> {
setUrlBarFocus(focused, reason); setUrlBarFocus(focused);
}; };
} else { } else {
mOnInitializedRunnable = null; mOnInitializedRunnable = null;
...@@ -1828,7 +1859,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF ...@@ -1828,7 +1859,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
// Ensure the URL bar loses focus if the tab it was interacting with is changed from // Ensure the URL bar loses focus if the tab it was interacting with is changed from
// underneath it. // underneath it.
setUrlBarFocus(false, LocationBar.OmniboxFocusReason.UNFOCUS); setUrlBarFocus(false);
// Place the cursor in the Omnibox if applicable. We always clear the focus above to // Place the cursor in the Omnibox if applicable. We always clear the focus above to
// ensure the shield placed over the content is dismissed when switching tabs. But if // ensure the shield placed over the content is dismissed when switching tabs. But if
......
...@@ -608,9 +608,6 @@ public class CustomTabToolbar extends ToolbarLayout implements View.OnLongClickL ...@@ -608,9 +608,6 @@ public class CustomTabToolbar extends ToolbarLayout implements View.OnLongClickL
return false; return false;
} }
@Override
public void gestureDetected(boolean isLongPress) {}
@Override @Override
public void setShowTitle(boolean showTitle) { public void setShowTitle(boolean showTitle) {
if (showTitle) { if (showTitle) {
...@@ -806,8 +803,7 @@ public class CustomTabToolbar extends ToolbarLayout implements View.OnLongClickL ...@@ -806,8 +803,7 @@ public class CustomTabToolbar extends ToolbarLayout implements View.OnLongClickL
} }
@Override @Override
public void setUrlBarFocus(boolean shouldBeFocused, @Nullable String pastedText, public void setUrlBarFocus(boolean shouldBeFocused) {}
@LocationBar.OmniboxFocusReason int reason) {}
@Override @Override
public void showUrlBarCursorWithoutFocusAnimations() {} public void showUrlBarCursorWithoutFocusAnimations() {}
......
...@@ -797,9 +797,7 @@ public abstract class ToolbarLayout ...@@ -797,9 +797,7 @@ public abstract class ToolbarLayout
* @return Whether or not the current Tab did go back. * @return Whether or not the current Tab did go back.
*/ */
boolean back() { boolean back() {
if (getLocationBar() != null) { if (getLocationBar() != null) getLocationBar().setUrlBarFocus(false);
getLocationBar().setUrlBarFocus(false, null, LocationBar.OmniboxFocusReason.UNFOCUS);
}
return mToolbarTabController != null && mToolbarTabController.back() != null; return mToolbarTabController != null && mToolbarTabController.back() != null;
} }
...@@ -808,9 +806,7 @@ public abstract class ToolbarLayout ...@@ -808,9 +806,7 @@ public abstract class ToolbarLayout
* @return Whether or not the current Tab did go forward. * @return Whether or not the current Tab did go forward.
*/ */
boolean forward() { boolean forward() {
if (getLocationBar() != null) { if (getLocationBar() != null) getLocationBar().setUrlBarFocus(false);
getLocationBar().setUrlBarFocus(false, null, LocationBar.OmniboxFocusReason.UNFOCUS);
}
return mToolbarTabController != null ? mToolbarTabController.forward() : false; return mToolbarTabController != null ? mToolbarTabController.forward() : false;
} }
...@@ -821,9 +817,7 @@ public abstract class ToolbarLayout ...@@ -821,9 +817,7 @@ public abstract class ToolbarLayout
* <p>The buttons of the toolbar will be updated as a result of making this call. * <p>The buttons of the toolbar will be updated as a result of making this call.
*/ */
void stopOrReloadCurrentTab() { void stopOrReloadCurrentTab() {
if (getLocationBar() != null) { if (getLocationBar() != null) getLocationBar().setUrlBarFocus(false);
getLocationBar().setUrlBarFocus(false, null, LocationBar.OmniboxFocusReason.UNFOCUS);
}
if (mToolbarTabController != null) mToolbarTabController.stopOrReloadCurrentTab(); if (mToolbarTabController != null) mToolbarTabController.stopOrReloadCurrentTab();
} }
...@@ -831,9 +825,7 @@ public abstract class ToolbarLayout ...@@ -831,9 +825,7 @@ public abstract class ToolbarLayout
* Opens hompage in the current tab. * Opens hompage in the current tab.
*/ */
void openHomepage() { void openHomepage() {
if (getLocationBar() != null) { if (getLocationBar() != null) getLocationBar().setUrlBarFocus(false);
getLocationBar().setUrlBarFocus(false, null, LocationBar.OmniboxFocusReason.UNFOCUS);
}
if (mToolbarTabController != null) mToolbarTabController.openHomepage(); if (mToolbarTabController != null) mToolbarTabController.openHomepage();
} }
......
...@@ -2199,6 +2199,10 @@ public class ToolbarPhone extends ToolbarLayout implements Invalidator.Client, O ...@@ -2199,6 +2199,10 @@ public class ToolbarPhone extends ToolbarLayout implements Invalidator.Client, O
if (getToolbarDataProvider().shouldShowLocationBarInOverviewMode()) { if (getToolbarDataProvider().shouldShowLocationBarInOverviewMode()) {
mLocationBar.updateStatusIcon(); mLocationBar.updateStatusIcon();
if (getToolbarDataProvider().isInOverviewAndShowingOmnibox()) {
mUrlBar.setText("");
}
} }
} }
}); });
......
...@@ -20,7 +20,6 @@ import org.junit.Test; ...@@ -20,7 +20,6 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.Restriction; import org.chromium.base.test.util.Restriction;
...@@ -251,48 +250,4 @@ public class LocationBarLayoutTest { ...@@ -251,48 +250,4 @@ public class LocationBarLayoutTest {
onView(withId(R.id.location_bar_status)) onView(withId(R.id.location_bar_status))
.check((view, e) -> Assert.assertEquals(iconView.getVisibility(), GONE)); .check((view, e) -> Assert.assertEquals(iconView.getVisibility(), GONE));
} }
@Test
@SmallTest
public void testSetUrlBarFocus() {
final LocationBarLayout locationBar = getLocationBar();
Assert.assertEquals(
0, RecordHistogram.getHistogramTotalCountForTesting("Android.OmniboxFocusReason"));
TestThreadUtils.runOnUiThreadBlocking(() -> {
locationBar.setUrlBarFocus(
true, SEARCH_TERMS_URL, LocationBar.OmniboxFocusReason.FAKE_BOX_LONG_PRESS);
});
Assert.assertTrue(locationBar.isUrlBarFocused());
Assert.assertTrue(locationBar.didFocusUrlFromFakebox());
Assert.assertEquals(SEARCH_TERMS_URL, getUrlText(getUrlBar()));
Assert.assertEquals(
1, RecordHistogram.getHistogramTotalCountForTesting("Android.OmniboxFocusReason"));
TestThreadUtils.runOnUiThreadBlocking(() -> {
locationBar.setUrlBarFocus(
true, SEARCH_TERMS, LocationBar.OmniboxFocusReason.SEARCH_QUERY);
});
Assert.assertTrue(locationBar.isUrlBarFocused());
Assert.assertTrue(locationBar.didFocusUrlFromFakebox());
Assert.assertEquals(SEARCH_TERMS, getUrlText(getUrlBar()));
Assert.assertEquals(
1, RecordHistogram.getHistogramTotalCountForTesting("Android.OmniboxFocusReason"));
TestThreadUtils.runOnUiThreadBlocking(() -> {
locationBar.setUrlBarFocus(false, null, LocationBar.OmniboxFocusReason.UNFOCUS);
});
Assert.assertFalse(locationBar.isUrlBarFocused());
Assert.assertFalse(locationBar.didFocusUrlFromFakebox());
Assert.assertEquals(
1, RecordHistogram.getHistogramTotalCountForTesting("Android.OmniboxFocusReason"));
TestThreadUtils.runOnUiThreadBlocking(() -> {
locationBar.setUrlBarFocus(true, null, LocationBar.OmniboxFocusReason.OMNIBOX_TAP);
});
Assert.assertTrue(locationBar.isUrlBarFocused());
Assert.assertFalse(locationBar.didFocusUrlFromFakebox());
Assert.assertEquals(
2, RecordHistogram.getHistogramTotalCountForTesting("Android.OmniboxFocusReason"));
}
} }
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