Commit d14478bd authored by Tommy Li's avatar Tommy Li Committed by Commit Bot

[omnibox] Show ZeroSuggest on-click when omnibox already focused on NTP

Currently, we trigger on-focus suggestions (ZeroSuggest) when the
omnibox receives focus.

But what about the case where the omnibox starts with focus, like the
NTP? In the status quo, the user would have to blur and then re-focus
the omnibox.

This CL allows users to get on-focus suggestions by clicking or tapping
the omnibox while already focused, assuming the textfield is empty.
We restrict it to empty textfield because:

 1) The only known use-case is the NTP so far.

 2) We want to be conservative and not disrupt any user text selection
    or editing.

Bug: 1010368, 996516
Change-Id: I2681c297c1372a5421f742bd0f18657f3c8603ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1863589
Commit-Queue: Tommy Li <tommycli@chromium.org>
Reviewed-by: default avatarmanuk hovanesian <manukh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706185}
parent a9e984ab
...@@ -1106,6 +1106,13 @@ bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) { ...@@ -1106,6 +1106,13 @@ bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) {
filter_drag_events_for_unelision_ = true; filter_drag_events_for_unelision_ = true;
} }
// This is intended to cover the NTP case where the omnibox starts focused.
// The user can explicitly request on-focus suggestions by clicking or tapping
// the omnibox. Restricted to empty textfield to avoid disrupting selections.
if (HasFocus() && GetText().empty() && event.IsOnlyLeftMouseButton()) {
model()->ShowOnFocusSuggestionsIfAutocompleteIdle();
}
return handled; return handled;
} }
...@@ -1171,6 +1178,13 @@ void OmniboxViewViews::OnGestureEvent(ui::GestureEvent* event) { ...@@ -1171,6 +1178,13 @@ void OmniboxViewViews::OnGestureEvent(ui::GestureEvent* event) {
event->type() == ui::ET_GESTURE_LONG_TAP) { event->type() == ui::ET_GESTURE_LONG_TAP) {
select_all_on_gesture_tap_ = false; select_all_on_gesture_tap_ = false;
} }
// This is intended to cover the NTP case where the omnibox starts focused.
// The user can explicitly request on-focus suggestions by clicking or tapping
// the omnibox. Restricted to empty textfield to avoid disrupting selections.
if (HasFocus() && GetText().empty() && event->type() == ui::ET_GESTURE_TAP) {
model()->ShowOnFocusSuggestionsIfAutocompleteIdle();
}
} }
void OmniboxViewViews::AboutToRequestFocusFromTabTraversal(bool reverse) { void OmniboxViewViews::AboutToRequestFocusFromTabTraversal(bool reverse) {
......
...@@ -1069,25 +1069,37 @@ void OmniboxEditModel::OnSetFocus(bool control_down) { ...@@ -1069,25 +1069,37 @@ void OmniboxEditModel::OnSetFocus(bool control_down) {
// example, if the user presses ctrl-l to focus the omnibox. // example, if the user presses ctrl-l to focus the omnibox.
control_key_state_ = control_down ? DOWN_AND_CONSUMED : UP; control_key_state_ = control_down ? DOWN_AND_CONSUMED : UP;
// Try to get ZeroSuggest suggestions if a page is loaded and the user has ShowOnFocusSuggestionsIfAutocompleteIdle();
// not been typing in the omnibox. The |user_input_in_progress_| check is
// used to prevent on-focus suggestions from appearing if the user already
// has a navigation or search query in mind.
if (client_->CurrentPageExists() && !user_input_in_progress_) {
// Send the textfield contents exactly as-is, as otherwise the verbatim
// match can be wrong. The full page URL is anyways in set_current_url().
input_ = AutocompleteInput(view_->GetText(), GetPageClassification(),
client_->GetSchemeClassifier());
input_.set_current_url(client_->GetURL());
input_.set_current_title(client_->GetTitle());
input_.set_from_omnibox_focus(true);
autocomplete_controller()->Start(input_);
}
if (user_input_in_progress_ || !in_revert_) if (user_input_in_progress_ || !in_revert_)
client_->OnInputStateChanged(); client_->OnInputStateChanged();
} }
void OmniboxEditModel::ShowOnFocusSuggestionsIfAutocompleteIdle() {
// Early exit if a query is already in progress or the popup is already open.
// This is what allows this method to be called multiple times in multiple
// code locations without harm.
if (query_in_progress() || PopupIsOpen())
return;
// Early exit if the page has not loaded yet, so we don't annoy users.
if (!client_->CurrentPageExists())
return;
// Early exit if the user already has a navigation or search query in mind.
if (user_input_in_progress_)
return;
// Send the textfield contents exactly as-is, as otherwise the verbatim
// match can be wrong. The full page URL is anyways in set_current_url().
input_ = AutocompleteInput(view_->GetText(), GetPageClassification(),
client_->GetSchemeClassifier());
input_.set_current_url(client_->GetURL());
input_.set_current_title(client_->GetTitle());
input_.set_from_omnibox_focus(true);
autocomplete_controller()->Start(input_);
}
void OmniboxEditModel::SetCaretVisibility(bool visible) { void OmniboxEditModel::SetCaretVisibility(bool visible) {
// Caret visibility only matters if the omnibox has focus. // Caret visibility only matters if the omnibox has focus.
if (focus_state_ != OMNIBOX_FOCUS_NONE) { if (focus_state_ != OMNIBOX_FOCUS_NONE) {
......
...@@ -293,6 +293,11 @@ class OmniboxEditModel { ...@@ -293,6 +293,11 @@ class OmniboxEditModel {
// control key is down (at the time we're gaining focus). // control key is down (at the time we're gaining focus).
void OnSetFocus(bool control_down); void OnSetFocus(bool control_down);
// Shows On-Focus Suggestions (ZeroSuggest) if no query is currently running
// and the popup is closed. This can be called multiple times without harm,
// since it will early-exit if an earlier request is in progress (or done).
void ShowOnFocusSuggestionsIfAutocompleteIdle();
// Sets the visibility of the caret in the omnibox, if it has focus. The // Sets the visibility of the caret in the omnibox, if it has focus. The
// visibility of the caret is reset to visible if either // visibility of the caret is reset to visible if either
// - The user starts typing, or // - The user starts typing, or
......
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