Commit cae4dadb authored by Orin Jaworski's avatar Orin Jaworski Committed by Commit Bot

[omnibox] Update pedal attachment and execution for button row

This CL updates pedal logic to work with and without the button row
feature enabled. Pedals may attach to matches that also have tab-switch
and keyword buttons. ExecutePedal is used instead of OpenMatch when
the intent is to perform the pedal action.

Bug: 1046523
Change-Id: I5a46383ca716df2f41f21eec3ffcf2969e7ab593
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2032189Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Commit-Queue: Orin Jaworski <orinj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737451}
parent 3585e8a6
...@@ -361,9 +361,9 @@ void OmniboxResultView::ButtonPressed(views::Button* button, ...@@ -361,9 +361,9 @@ void OmniboxResultView::ButtonPressed(views::Button* button,
// TODO(orinj): Implement. // TODO(orinj): Implement.
} else if (button == pedal_button_) { } else if (button == pedal_button_) {
DCHECK(match_.pedal); DCHECK(match_.pedal);
// TODO(orinj): Open the match in a way that does not conflict with search // Pedal action intent means we execute the match instead of opening it.
// or tab switch. Various dispositions are now possible from a single match. popup_contents_view_->model()->edit_model()->ExecutePedal(
OpenMatch(WindowOpenDisposition::SWITCH_TO_TAB, event.time_stamp()); match_, event.time_stamp());
} else { } else {
NOTREACHED(); NOTREACHED();
} }
......
...@@ -386,11 +386,19 @@ void AutocompleteResult::ConvertInSuggestionPedalMatches( ...@@ -386,11 +386,19 @@ void AutocompleteResult::ConvertInSuggestionPedalMatches(
// Used to ensure we keep only one Pedal of each kind. // Used to ensure we keep only one Pedal of each kind.
std::unordered_set<OmniboxPedal*> pedals_found; std::unordered_set<OmniboxPedal*> pedals_found;
for (auto& match : matches_) { for (auto& match : matches_) {
if (OmniboxFieldTrial::IsSuggestionButtonRowEnabled()) {
// Skip only matches that have already detected their pedal. With the
// button row enabled, a pedal may attach along with tab switch and
// associated keyword buttons.
if (match.pedal)
continue;
} else {
// Skip matches that will not show Pedal because they already // Skip matches that will not show Pedal because they already
// have a tab match or associated keyword. Also skip matches // have a tab match or associated keyword. Also skip matches
// that have already detected their Pedal. // that have already detected their Pedal.
if (match.has_tab_match || match.associated_keyword || match.pedal) if (match.has_tab_match || match.associated_keyword || match.pedal)
continue; continue;
}
OmniboxPedal* const pedal = provider->FindPedalMatch(match.contents); OmniboxPedal* const pedal = provider->FindPedalMatch(match.contents);
if (pedal) { if (pedal) {
......
...@@ -719,6 +719,21 @@ void OmniboxEditModel::EnterKeywordModeForDefaultSearchProvider( ...@@ -719,6 +719,21 @@ void OmniboxEditModel::EnterKeywordModeForDefaultSearchProvider(
EmitKeywordHistogram(entry_method); EmitKeywordHistogram(entry_method);
} }
void OmniboxEditModel::ExecutePedal(const AutocompleteMatch& match,
base::TimeTicks match_selection_timestamp) {
CHECK(match.pedal);
{
// This block resets omnibox to unedited state and closes popup, which
// may not seem necessary in cases of navigation but makes sense for
// taking Pedal actions in general.
base::AutoReset<bool> tmp(&in_revert_, true);
view_->RevertAll();
}
OmniboxPedal::ExecutionContext context(*client_, *controller_,
match_selection_timestamp);
match.pedal->Execute(context);
}
void OmniboxEditModel::OpenMatch(AutocompleteMatch match, void OmniboxEditModel::OpenMatch(AutocompleteMatch match,
WindowOpenDisposition disposition, WindowOpenDisposition disposition,
const GURL& alternate_nav_url, const GURL& alternate_nav_url,
...@@ -731,17 +746,11 @@ void OmniboxEditModel::OpenMatch(AutocompleteMatch match, ...@@ -731,17 +746,11 @@ void OmniboxEditModel::OpenMatch(AutocompleteMatch match,
autocomplete_controller()->UpdateMatchDestinationURLWithQueryFormulationTime( autocomplete_controller()->UpdateMatchDestinationURLWithQueryFormulationTime(
elapsed_time_since_user_first_modified_omnibox, &match); elapsed_time_since_user_first_modified_omnibox, &match);
if (match.pedal) { // Matches with |pedal| may be opened normally or executed, but when a match
{ // is a dedicated Pedal suggestion, it should always be executed. This only
// This block resets omnibox to unedited state and closes popup, which // happens when the button row feature is disabled.
// may not seem necessary in cases of navigation but makes sense for if (match.pedal && !OmniboxFieldTrial::IsSuggestionButtonRowEnabled()) {
// taking Pedal actions in general. ExecutePedal(match, match_selection_timestamp);
base::AutoReset<bool> tmp(&in_revert_, true);
view_->RevertAll();
}
OmniboxPedal::ExecutionContext context(*client_, *controller_,
match_selection_timestamp);
match.pedal->Execute(context);
return; return;
} }
......
...@@ -215,6 +215,10 @@ class OmniboxEditModel { ...@@ -215,6 +215,10 @@ class OmniboxEditModel {
WindowOpenDisposition disposition, WindowOpenDisposition disposition,
base::TimeTicks match_selection_timestamp = base::TimeTicks()); base::TimeTicks match_selection_timestamp = base::TimeTicks());
// Executes the |pedal| associated with given match.
void ExecutePedal(const AutocompleteMatch& match,
base::TimeTicks match_selection_timestamp);
// Asks the browser to load |match|. |index| is only used for logging, and // Asks the browser to load |match|. |index| is only used for logging, and
// can be kNoMatch if the popup was closed, or if none of the suggestions // can be kNoMatch if the popup was closed, or if none of the suggestions
// in the popup were used (in the unusual no-default-match case). In that // in the popup were used (in the unusual no-default-match case). In that
......
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