Commit 23a5f86b authored by Orin Jaworski's avatar Orin Jaworski Committed by Commit Bot

[omnibox] Conditionally keep pedal on triggering match

This CL partially revives the logic from crrev.com/c/1471251 :
[omnibox] Eliminate side-button Pedal suggestion mode

Note that only the match handling part is restored and the code for
handling the Pedals button is ignored. The is due to the conditional
nature of application of this logic. When the button row feature is
enabled, we will use the button row on the triggering suggestion to
show the pedal on the same suggestion. When disabled, the existing
dedicated Pedal suggestion logic will be kept.

For now, the button row work is in progress, and until the row is
actually presented, enabling both Pedals and the row will
effectively hide the pedal in the triggering suggestion.

Bug: 1046523
Change-Id: Iacb1e02158ee054b877dd0095f3ddd3a0b533b1a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2027900
Commit-Queue: Orin Jaworski <orinj@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736625}
parent 700aca34
...@@ -580,12 +580,17 @@ void AutocompleteController::UpdateResult( ...@@ -580,12 +580,17 @@ void AutocompleteController::UpdateResult(
i != providers_.end(); ++i) i != providers_.end(); ++i)
result_.AppendMatches(input_, (*i)->matches()); result_.AppendMatches(input_, (*i)->matches());
if (OmniboxFieldTrial::IsPedalSuggestionsEnabled())
result_.AppendDedicatedPedalMatches(provider_client_.get(), input_);
if (OmniboxFieldTrial::IsTabSwitchSuggestionsEnabled()) if (OmniboxFieldTrial::IsTabSwitchSuggestionsEnabled())
result_.ConvertOpenTabMatches(provider_client_.get(), &input_); result_.ConvertOpenTabMatches(provider_client_.get(), &input_);
if (OmniboxFieldTrial::IsPedalSuggestionsEnabled()) {
if (OmniboxFieldTrial::IsSuggestionButtonRowEnabled()) {
result_.ConvertInSuggestionPedalMatches(provider_client_.get());
} else {
result_.AppendDedicatedPedalMatches(provider_client_.get(), input_);
}
}
// Sort the matches and trim to a small number of "best" matches. // Sort the matches and trim to a small number of "best" matches.
const AutocompleteMatch* preserve_default_match = nullptr; const AutocompleteMatch* preserve_default_match = nullptr;
if (!in_start_ && last_default_match && if (!in_start_ && last_default_match &&
......
...@@ -380,6 +380,27 @@ void AutocompleteResult::AppendDedicatedPedalMatches( ...@@ -380,6 +380,27 @@ void AutocompleteResult::AppendDedicatedPedalMatches(
} }
} }
void AutocompleteResult::ConvertInSuggestionPedalMatches(
AutocompleteProviderClient* client) {
const OmniboxPedalProvider* provider = client->GetPedalProvider();
// Used to ensure we keep only one Pedal of each kind.
std::unordered_set<OmniboxPedal*> pedals_found;
for (auto& match : matches_) {
// Skip matches that will not show Pedal because they already
// have a tab match or associated keyword. Also skip matches
// that have already detected their Pedal.
if (match.has_tab_match || match.associated_keyword || match.pedal)
continue;
OmniboxPedal* const pedal = provider->FindPedalMatch(match.contents);
if (pedal) {
const auto result = pedals_found.insert(pedal);
if (result.second)
match.pedal = pedal;
}
}
}
void AutocompleteResult::ConvertOpenTabMatches( void AutocompleteResult::ConvertOpenTabMatches(
AutocompleteProviderClient* client, AutocompleteProviderClient* client,
const AutocompleteInput* input) { const AutocompleteInput* input) {
......
...@@ -69,6 +69,9 @@ class AutocompleteResult { ...@@ -69,6 +69,9 @@ class AutocompleteResult {
void AppendDedicatedPedalMatches(AutocompleteProviderClient* client, void AppendDedicatedPedalMatches(AutocompleteProviderClient* client,
const AutocompleteInput& input); const AutocompleteInput& input);
// Sets |pedal| in matches that have Pedal-triggering text.
void ConvertInSuggestionPedalMatches(AutocompleteProviderClient* client);
// Sets |has_tab_match| in matches whose URL matches an open tab's URL. // Sets |has_tab_match| in matches whose URL matches an open tab's URL.
// Also, fixes up the description if not using another UI element to // Also, fixes up the description if not using another UI element to
// annotate (e.g. tab switch button). |input| can be null; if provided, // annotate (e.g. tab switch button). |input| can be null; if provided,
......
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