Commit 793ed6d6 authored by Angela Yoeurng's avatar Angela Yoeurng Committed by Commit Bot

[omnibox] Make Enter/Space trigger Suggestion Button Row buttons

There was no case to handle KeyEvents for the Button Row buttons
previously. This was added so Enter and Space will trigger the button's
actions.

This CL moves some of the business logic to PopupModel, merging the
handling of Mouse/ButtonPressed events and Key events

Keyword entry method was also changed to Tab rather than Keyboard shortcut.

Bug: 1091351
Change-Id: I2818e47860d8993bbb99836c40d60197b8ef7e6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2233780
Commit-Queue: Angela Yoeurng <yoangela@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Reviewed-by: default avatarmanuk hovanesian <manukh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#777957}
parent 6ff616c7
...@@ -90,19 +90,24 @@ void OmniboxSuggestionButtonRowView::OnStyleRefresh() { ...@@ -90,19 +90,24 @@ void OmniboxSuggestionButtonRowView::OnStyleRefresh() {
void OmniboxSuggestionButtonRowView::ButtonPressed(views::Button* button, void OmniboxSuggestionButtonRowView::ButtonPressed(views::Button* button,
const ui::Event& event) { const ui::Event& event) {
OmniboxPopupModel* popup_model = popup_contents_view_->model();
if (!popup_model)
return;
if (button == tab_switch_button_) { if (button == tab_switch_button_) {
popup_contents_view_->OpenMatch( popup_model->TriggerSelectionAction(
model_index_, WindowOpenDisposition::SWITCH_TO_TAB, event.time_stamp()); OmniboxPopupModel::Selection(
model_index_, OmniboxPopupModel::FOCUSED_BUTTON_TAB_SWITCH),
event.time_stamp());
} else if (button == keyword_button_) { } else if (button == keyword_button_) {
// TODO(yoangela): Port to PopupModel and merge with keyEvent
// TODO(orinj): Clear out existing suggestions, particularly this one, as // TODO(orinj): Clear out existing suggestions, particularly this one, as
// once we AcceptKeyword, we are really in a new scope state and holding // once we AcceptKeyword, we are really in a new scope state and holding
// onto old suggestions is confusing and error prone. Without this check, // onto old suggestions is confusing and error prone. Without this check,
// a second click of the button violates assumptions in |AcceptKeyword|. // a second click of the button violates assumptions in |AcceptKeyword|.
if (model()->edit_model()->is_keyword_hint()) { if (model()->edit_model()->is_keyword_hint()) {
auto method = metrics::OmniboxEventProto::INVALID; auto method = metrics::OmniboxEventProto::INVALID;
if (event.IsKeyEvent()) { if (event.IsMouseEvent()) {
method = metrics::OmniboxEventProto::KEYBOARD_SHORTCUT;
} else if (event.IsMouseEvent()) {
method = metrics::OmniboxEventProto::CLICK_HINT_VIEW; method = metrics::OmniboxEventProto::CLICK_HINT_VIEW;
} else if (event.IsGestureEvent()) { } else if (event.IsGestureEvent()) {
method = metrics::OmniboxEventProto::TAP_HINT_VIEW; method = metrics::OmniboxEventProto::TAP_HINT_VIEW;
...@@ -111,9 +116,10 @@ void OmniboxSuggestionButtonRowView::ButtonPressed(views::Button* button, ...@@ -111,9 +116,10 @@ void OmniboxSuggestionButtonRowView::ButtonPressed(views::Button* button,
model()->edit_model()->AcceptKeyword(method); model()->edit_model()->AcceptKeyword(method);
} }
} else if (button == pedal_button_) { } else if (button == pedal_button_) {
DCHECK(match().pedal); popup_model->TriggerSelectionAction(
// Pedal action intent means we execute the match instead of opening it. OmniboxPopupModel::Selection(model_index_,
model()->edit_model()->ExecutePedal(match(), event.time_stamp()); OmniboxPopupModel::FOCUSED_BUTTON_PEDAL),
event.time_stamp());
} }
} }
......
...@@ -1725,8 +1725,8 @@ bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield, ...@@ -1725,8 +1725,8 @@ bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield,
switch (event.key_code()) { switch (event.key_code()) {
case ui::VKEY_RETURN: { case ui::VKEY_RETURN: {
OmniboxPopupModel* popup_model = model()->popup_model(); OmniboxPopupModel* popup_model = model()->popup_model();
if (popup_model && if (popup_model && popup_model->TriggerSelectionAction(
popup_model->TriggerSelectionAction(popup_model->selection())) { popup_model->selection(), event.time_stamp())) {
return true; return true;
} else if (MaybeTriggerSecondaryButton(event)) { } else if (MaybeTriggerSecondaryButton(event)) {
return true; return true;
...@@ -1881,8 +1881,8 @@ bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield, ...@@ -1881,8 +1881,8 @@ bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield,
case ui::VKEY_SPACE: { case ui::VKEY_SPACE: {
if (!control && !alt && !shift && SelectionAtEnd()) { if (!control && !alt && !shift && SelectionAtEnd()) {
OmniboxPopupModel* popup_model = model()->popup_model(); OmniboxPopupModel* popup_model = model()->popup_model();
if (popup_model && if (popup_model && popup_model->TriggerSelectionAction(
popup_model->TriggerSelectionAction(popup_model->selection())) { popup_model->selection(), event.time_stamp())) {
return true; return true;
} }
......
...@@ -554,21 +554,54 @@ bool OmniboxPopupModel::IsControlPresentOnMatch(Selection selection) const { ...@@ -554,21 +554,54 @@ bool OmniboxPopupModel::IsControlPresentOnMatch(Selection selection) const {
return false; return false;
} }
bool OmniboxPopupModel::TriggerSelectionAction(Selection selection) { bool OmniboxPopupModel::TriggerSelectionAction(Selection selection,
base::TimeTicks timestamp) {
// Early exit for the kNoMatch case. Also exits if the calling UI passes in // Early exit for the kNoMatch case. Also exits if the calling UI passes in
// an invalid |selection|. // an invalid |selection|.
if (selection.line >= result().size()) if (selection.line >= result().size())
return false; return false;
auto& match = result().match_at(selection.line); auto& match = result().match_at(selection.line);
if (selection.state == HEADER_BUTTON_FOCUSED && switch (selection.state) {
match.suggestion_group_id.has_value()) { case HEADER_BUTTON_FOCUSED:
omnibox::ToggleSuggestionGroupIdVisibility( DCHECK(match.suggestion_group_id.has_value());
pref_service_, match.suggestion_group_id.value()); omnibox::ToggleSuggestionGroupIdVisibility(
return true; pref_service_, match.suggestion_group_id.value());
break;
case FOCUSED_BUTTON_KEYWORD:
// TODO(yoangela): Merge logic with mouse/gesture events in
// OmniboxSuggestionButtonRowView::ButtonPressed - This case currently
// is only reached by the call in OmniboxViewViews::HandleKeyEvent.
if (edit_model()->is_keyword_hint()) {
// TODO(yoangela): Rename once tab to keyword search is deprecated
// Accept/ClearKeyword() has special conditions to handle searches
// initiated by pressing Tab. Since tab+enter on this button behaves
// more similar to a Tab than a Keyboard shortcut, it's easier
// for now to treat it as a Tab entry method, otherwise the
// autocomplete results will reset, leaving us in an unknown state.
edit_model()->AcceptKeyword(metrics::OmniboxEventProto::TAB);
}
break;
case FOCUSED_BUTTON_TAB_SWITCH:
DCHECK(timestamp != base::TimeTicks());
edit_model()->AcceptInput(WindowOpenDisposition::SWITCH_TO_TAB,
timestamp);
break;
case FOCUSED_BUTTON_PEDAL:
DCHECK(timestamp != base::TimeTicks());
DCHECK(match.pedal);
edit_model()->ExecutePedal(match, timestamp);
break;
default:
// Behavior is not yet supported, return false.
return false;
} }
return false; return true;
} }
base::string16 OmniboxPopupModel::GetAccessibilityLabelForCurrentSelection( base::string16 OmniboxPopupModel::GetAccessibilityLabelForCurrentSelection(
......
...@@ -242,7 +242,10 @@ class OmniboxPopupModel { ...@@ -242,7 +242,10 @@ class OmniboxPopupModel {
// Triggers the action on |selection| (usually an auxiliary button). // Triggers the action on |selection| (usually an auxiliary button).
// If the popup model supports the action and performs it, this returns true. // If the popup model supports the action and performs it, this returns true.
// This can't handle all actions currently, and returns false in those cases. // This can't handle all actions currently, and returns false in those cases.
bool TriggerSelectionAction(Selection selection); // The timestamp parameter is currently only used by FOCUSED_BUTTON_TAB_SWITCH
// and FOCUSED_BUTTON_PEDAL, so is set by default for other use cases.
bool TriggerSelectionAction(Selection selection,
base::TimeTicks timestamp = base::TimeTicks());
// This returns the accessibility label for current selection. This is an // This returns the accessibility label for current selection. This is an
// extended version of AutocompleteMatchType::ToAccessibilityLabel() which // extended version of AutocompleteMatchType::ToAccessibilityLabel() which
......
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