Commit f5f8d99b authored by Gang Wu's avatar Gang Wu Committed by Commit Bot

[Omnibox] All the Clipboard should on top of zero suggestions

This CL marks clipboard suggestions and query tile suggestions as
special suggestions, skip them for search vs url partitions.
So clipboard suggestion can on top of search suggestions.

This CL partial revert
https://chromium-review.googlesource.com/c/chromium/src/+/2259380
because search type suggestion needs to have keyword, but image search
is different with other search suggestion, cannot have keyword. So in
this CL, we create a special category for clipboard and query tile,
and skip them for search vs url partitions.

Bug:1091952

Change-Id: I454b5774602c4da9f8f0907bc570ad84be9e0a1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2266012
Commit-Queue: Gang Wu <gangwu@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Reviewed-by: default avatarEnder <ender@google.com>
Cr-Commit-Position: refs/heads/master@{#782759}
parent 729fc64f
...@@ -626,9 +626,7 @@ bool AutocompleteMatch::IsSpecializedSearchType(Type type) { ...@@ -626,9 +626,7 @@ bool AutocompleteMatch::IsSpecializedSearchType(Type type) {
type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL || type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL ||
type == AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED || type == AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED ||
type == AutocompleteMatchType::TILE_SUGGESTION || type == AutocompleteMatchType::TILE_SUGGESTION ||
type == AutocompleteMatchType::SEARCH_SUGGEST_PROFILE || type == AutocompleteMatchType::SEARCH_SUGGEST_PROFILE;
type == AutocompleteMatchType::CLIPBOARD_TEXT ||
type == AutocompleteMatchType::CLIPBOARD_IMAGE;
} }
// static // static
...@@ -637,6 +635,14 @@ bool AutocompleteMatch::IsSearchHistoryType(Type type) { ...@@ -637,6 +635,14 @@ bool AutocompleteMatch::IsSearchHistoryType(Type type) {
type == AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED; type == AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED;
} }
// static
bool AutocompleteMatch::ShouldBeSkippedForGroupBySearchVsUrl(Type type) {
return type == AutocompleteMatchType::CLIPBOARD_URL ||
type == AutocompleteMatchType::CLIPBOARD_TEXT ||
type == AutocompleteMatchType::CLIPBOARD_IMAGE ||
type == AutocompleteMatchType::TILE_SUGGESTION;
}
AutocompleteMatch::Type AutocompleteMatch::GetDemotionType() const { AutocompleteMatch::Type AutocompleteMatch::GetDemotionType() const {
if (!IsSubMatch()) if (!IsSubMatch())
return type; return type;
......
...@@ -245,6 +245,11 @@ struct AutocompleteMatch { ...@@ -245,6 +245,11 @@ struct AutocompleteMatch {
// usually this surfaces a clock icon to the user. // usually this surfaces a clock icon to the user.
static bool IsSearchHistoryType(Type type); static bool IsSearchHistoryType(Type type);
// Convenience function to check if |type| is one of the suggest types we
// need to skip for search vs url partitions - url, text or image in the
// clipboard or query tile.
static bool ShouldBeSkippedForGroupBySearchVsUrl(Type type);
// If this match is a submatch, returns the parent's type, otherwise this // If this match is a submatch, returns the parent's type, otherwise this
// match's type. // match's type.
Type GetDemotionType() const; Type GetDemotionType() const;
......
...@@ -277,11 +277,16 @@ void AutocompleteResult::SortAndCull( ...@@ -277,11 +277,16 @@ void AutocompleteResult::SortAndCull(
// Skip over default match. // Skip over default match.
auto next = std::next(matches_.begin()); auto next = std::next(matches_.begin());
// If it has submatches, skip them too. // If it has submatches, skip them too.
if (matches_.front().subrelevance != 0) { if (matches_.front().subrelevance != 0 ||
AutocompleteMatch::ShouldBeSkippedForGroupBySearchVsUrl(
matches_.front().type)) {
while (next != matches_.end() && while (next != matches_.end() &&
AutocompleteMatch::IsSameFamily(matches_.front().subrelevance, (AutocompleteMatch::IsSameFamily(matches_.front().subrelevance,
next->subrelevance)) next->subrelevance) ||
AutocompleteMatch::ShouldBeSkippedForGroupBySearchVsUrl(
matches_.front().type))) {
next = std::next(next); next = std::next(next);
}
} }
GroupSuggestionsBySearchVsURL(next, matches_.end()); GroupSuggestionsBySearchVsURL(next, matches_.end());
} }
......
...@@ -1998,3 +1998,44 @@ TEST_F(AutocompleteResultTest, CalculateNumMatchesTest) { ...@@ -1998,3 +1998,44 @@ TEST_F(AutocompleteResultTest, CalculateNumMatchesTest) {
EXPECT_EQ(num_matches, test.num_matches); EXPECT_EQ(num_matches, test.num_matches);
} }
} }
TEST_F(AutocompleteResultTest, ClipboardSuggestionOnTopOfSearchSuggestionTest) {
// clang-format off
TestData data[] = {
{1, 1, 500, false},
{2, 2, 1100, false},
{3, 2, 1000, false},
{4, 1, 1300, false},
{5, 1, 1500, false},
};
// clang-format on
ACMatches matches;
PopulateAutocompleteMatches(data, base::size(data), &matches);
matches[0].type = AutocompleteMatchType::SEARCH_SUGGEST;
static_cast<FakeAutocompleteProvider*>(matches[0].provider)
->SetType(AutocompleteProvider::Type::TYPE_ZERO_SUGGEST_LOCAL_HISTORY);
matches[1].type = AutocompleteMatchType::SEARCH_SUGGEST;
static_cast<FakeAutocompleteProvider*>(matches[1].provider)
->SetType(AutocompleteProvider::Type::TYPE_ZERO_SUGGEST_LOCAL_HISTORY);
matches[2].type = AutocompleteMatchType::SEARCH_SUGGEST;
static_cast<FakeAutocompleteProvider*>(matches[2].provider)
->SetType(AutocompleteProvider::Type::TYPE_ZERO_SUGGEST_LOCAL_HISTORY);
matches[3].type = AutocompleteMatchType::SEARCH_SUGGEST;
static_cast<FakeAutocompleteProvider*>(matches[3].provider)
->SetType(AutocompleteProvider::Type::TYPE_ZERO_SUGGEST_LOCAL_HISTORY);
matches[4].type = AutocompleteMatchType::CLIPBOARD_URL;
static_cast<FakeAutocompleteProvider*>(matches[4].provider)
->SetType(AutocompleteProvider::Type::TYPE_CLIPBOARD);
AutocompleteInput input(base::ASCIIToUTF16(""),
metrics::OmniboxEventProto::OTHER,
TestSchemeClassifier());
AutocompleteResult result;
result.AppendMatches(input, matches);
result.SortAndCull(input, template_url_service_.get());
EXPECT_EQ(result.size(), 5u);
EXPECT_EQ(result.match_at(0)->relevance, 1500);
EXPECT_EQ(AutocompleteMatchType::CLIPBOARD_URL, result.match_at(0)->type);
}
...@@ -432,7 +432,6 @@ void ClipboardProvider::ConstructImageMatchCallback( ...@@ -432,7 +432,6 @@ void ClipboardProvider::ConstructImageMatchCallback(
match.post_content = match.post_content =
std::make_unique<TemplateURLRef::PostContent>(post_content); std::make_unique<TemplateURLRef::PostContent>(post_content);
match.keyword = default_url->keyword();
match.transition = ui::PAGE_TRANSITION_GENERATED; match.transition = ui::PAGE_TRANSITION_GENERATED;
field_trial_triggered_ = true; field_trial_triggered_ = true;
......
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