Commit 66a41d97 authored by Robbie Gibson's avatar Robbie Gibson Committed by Commit Bot

Add fill_into_edit to clipboard matches for iOS

On iOS, if there is no text in the Omnibox text field, the "Go" button
and the return key (on bluetooth keyboards) are disabled. This means
that when using the keyboard to select matches, the return key doesn't
work for the clipboard matches because no text is filled into the
omnibox.

This adds the following fill_into_edit:
URL match -> URL
text match -> Text
image match -> Search Copied Image (the same as the match's
  description)

Fixed: 1026595
Change-Id: I04686bc4b0cd38651d33b54113c97001a3a30eea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1937074
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719541}
parent 66d5723e
......@@ -258,6 +258,7 @@ base::Optional<AutocompleteMatch> ClipboardProvider::CreateURLMatch(
AutocompleteMatch match(this, 800, IsMatchDeletionEnabled(),
AutocompleteMatchType::CLIPBOARD_URL);
match.destination_url = url;
// Because the user did not type a related input to get this clipboard
// suggestion, preserve the subdomain so the user has extra context.
auto format_types = AutocompleteMatch::GetFormatTypes(false, true);
......@@ -265,6 +266,9 @@ base::Optional<AutocompleteMatch> ClipboardProvider::CreateURLMatch(
url, format_types, net::UnescapeRule::SPACES, nullptr, nullptr, nullptr));
if (!match.contents.empty())
match.contents_class.push_back({0, ACMatchClassification::URL});
match.fill_into_edit =
AutocompleteInput::FormattedStringWithEquivalentMeaning(
url, match.contents, client_->GetSchemeClassifier(), nullptr);
match.description.assign(l10n_util::GetStringUTF16(IDS_LINK_FROM_CLIPBOARD));
if (!match.description.empty())
......@@ -300,6 +304,8 @@ base::Optional<AutocompleteMatch> ClipboardProvider::CreateTextMatch(
// Add the clipboard match. The relevance is 800 to beat ZeroSuggest results.
AutocompleteMatch match(this, 800, IsMatchDeletionEnabled(),
AutocompleteMatchType::CLIPBOARD_TEXT);
match.fill_into_edit = text;
TemplateURLService* url_service = client_->GetTemplateURLService();
const TemplateURL* default_url = url_service->GetDefaultSearchProvider();
if (!default_url)
......@@ -396,6 +402,12 @@ void ClipboardProvider::ConstructImageMatchCallback(
if (!match.description.empty())
match.description_class.push_back({0, ACMatchClassification::NONE});
// This will end up being something like "Search for Copied Image." This may
// seem strange to use for |fill_into_edit, but it is because iOS requires
// some text in the text field for the Enter key to work when using keyboard
// navigation.
match.fill_into_edit = match.description;
TemplateURLRef::SearchTermsArgs search_args(base::ASCIIToUTF16(""));
search_args.image_thumbnail_content.assign(image_bytes->front_as<char>(),
image_bytes->size());
......
......@@ -111,6 +111,8 @@ TEST_F(ClipboardProviderTest, ClipboardIsCurrentURL) {
}
TEST_F(ClipboardProviderTest, HasMultipleMatches) {
EXPECT_CALL(*client_.get(), GetSchemeClassifier())
.WillOnce(testing::ReturnRef(classifier_));
provider_->Start(CreateAutocompleteInput(true), false);
ASSERT_GE(provider_->matches().size(), 1U);
EXPECT_EQ(GURL(kClipboardURL), provider_->matches().back().destination_url);
......@@ -128,6 +130,8 @@ TEST_F(ClipboardProviderTest, MatchesText) {
ASSERT_GE(provider_->matches().size(), 1U);
EXPECT_EQ(base::UTF8ToUTF16(kClipboardTitleText),
provider_->matches().back().contents);
EXPECT_EQ(base::UTF8ToUTF16(kClipboardText),
provider_->matches().back().fill_into_edit);
}
TEST_F(ClipboardProviderTest, MatchesImage) {
......
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