Commit 53fa1c99 authored by Christopher Grant's avatar Christopher Grant Committed by Commit Bot

Do not rely directly on autocomplete code in the UI

This allows future UI library module to have one less needless
dependency.  There's no reason the UI needs to look up the icon for a
given omnibox suggestion.

BUG=
R=acondor

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:linux_vr;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I6fd8152ed64dd2201a4d1ad1fef139ce309965b0
Reviewed-on: https://chromium-review.googlesource.com/1180162
Commit-Queue: Christopher Grant <cjgrant@chromium.org>
Reviewed-by: default avatarAldo Culquicondor <acondor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584195}
parent f572f527
...@@ -74,9 +74,11 @@ std::tuple<GURL, bool> AutocompleteController::GetUrlFromVoiceInput( ...@@ -74,9 +74,11 @@ std::tuple<GURL, bool> AutocompleteController::GetUrlFromVoiceInput(
void AutocompleteController::OnResultChanged(bool default_match_changed) { void AutocompleteController::OnResultChanged(bool default_match_changed) {
auto suggestions = std::make_unique<OmniboxSuggestions>(); auto suggestions = std::make_unique<OmniboxSuggestions>();
for (const auto& match : autocomplete_controller_->result()) { for (const auto& match : autocomplete_controller_->result()) {
const gfx::VectorIcon* icon =
&AutocompleteMatch::TypeToVectorIcon(match.type, false, false);
suggestions->suggestions.emplace_back(OmniboxSuggestion( suggestions->suggestions.emplace_back(OmniboxSuggestion(
match.contents, match.description, match.contents_class, match.contents, match.description, match.contents_class,
match.description_class, match.type, match.destination_url, match.description_class, icon, match.destination_url,
last_request_.text, match.inline_autocompletion)); last_request_.text, match.inline_autocompletion));
if (suggestions->suggestions.size() >= kMaxNumberOfSuggestions) if (suggestions->suggestions.size() >= kMaxNumberOfSuggestions)
break; break;
......
...@@ -25,7 +25,7 @@ OmniboxSuggestion::OmniboxSuggestion( ...@@ -25,7 +25,7 @@ OmniboxSuggestion::OmniboxSuggestion(
new_contents_classifications, new_contents_classifications,
const AutocompleteMatch::ACMatchClassifications& const AutocompleteMatch::ACMatchClassifications&
new_description_classifications, new_description_classifications,
AutocompleteMatch::Type new_type, const gfx::VectorIcon* new_icon,
GURL new_destination, GURL new_destination,
const base::string16& new_input, const base::string16& new_input,
const base::string16& new_inline_autocompletion) const base::string16& new_inline_autocompletion)
...@@ -33,7 +33,7 @@ OmniboxSuggestion::OmniboxSuggestion( ...@@ -33,7 +33,7 @@ OmniboxSuggestion::OmniboxSuggestion(
description(new_description), description(new_description),
contents_classifications(new_contents_classifications), contents_classifications(new_contents_classifications),
description_classifications(new_description_classifications), description_classifications(new_description_classifications),
type(new_type), icon(new_icon),
destination(new_destination), destination(new_destination),
autocompletion(Autocompletion(new_input, new_inline_autocompletion)) {} autocompletion(Autocompletion(new_input, new_inline_autocompletion)) {}
...@@ -44,7 +44,7 @@ OmniboxSuggestion::OmniboxSuggestion(const OmniboxSuggestion& other) { ...@@ -44,7 +44,7 @@ OmniboxSuggestion::OmniboxSuggestion(const OmniboxSuggestion& other) {
contents_classifications = other.contents_classifications; contents_classifications = other.contents_classifications;
description = other.description; description = other.description;
description_classifications = other.description_classifications; description_classifications = other.description_classifications;
type = other.type; icon = other.icon;
destination = other.destination; destination = other.destination;
autocompletion = other.autocompletion; autocompletion = other.autocompletion;
} }
......
...@@ -37,7 +37,7 @@ struct VR_EXPORT OmniboxSuggestion { ...@@ -37,7 +37,7 @@ struct VR_EXPORT OmniboxSuggestion {
new_contents_classifications, new_contents_classifications,
const AutocompleteMatch::ACMatchClassifications& const AutocompleteMatch::ACMatchClassifications&
new_description_classifications, new_description_classifications,
AutocompleteMatch::Type new_type, const gfx::VectorIcon* icon,
GURL new_destination, GURL new_destination,
const base::string16& new_input, const base::string16& new_input,
const base::string16& new_inline_autocompletion); const base::string16& new_inline_autocompletion);
...@@ -48,7 +48,7 @@ struct VR_EXPORT OmniboxSuggestion { ...@@ -48,7 +48,7 @@ struct VR_EXPORT OmniboxSuggestion {
base::string16 description; base::string16 description;
AutocompleteMatch::ACMatchClassifications contents_classifications; AutocompleteMatch::ACMatchClassifications contents_classifications;
AutocompleteMatch::ACMatchClassifications description_classifications; AutocompleteMatch::ACMatchClassifications description_classifications;
AutocompleteMatch::Type type = AutocompleteMatchType::URL_WHAT_YOU_TYPED; const gfx::VectorIcon* icon = nullptr;
GURL destination; GURL destination;
Autocompletion autocompletion; Autocompletion autocompletion;
}; };
......
...@@ -32,6 +32,7 @@ executable("vr_testapp") { ...@@ -32,6 +32,7 @@ executable("vr_testapp") {
"//components/security_state/core", "//components/security_state/core",
"//components/toolbar:vector_icons", "//components/toolbar:vector_icons",
"//components/tracing:startup_tracing", "//components/tracing:startup_tracing",
"//components/vector_icons:vector_icons",
"//ui/display/types", "//ui/display/types",
"//ui/events", "//ui/events",
"//ui/events:dom_keycode_converter", "//ui/events:dom_keycode_converter",
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "components/omnibox/browser/vector_icons.h" #include "components/omnibox/browser/vector_icons.h"
#include "components/security_state/core/security_state.h" #include "components/security_state/core/security_state.h"
#include "components/toolbar/vector_icons.h" #include "components/toolbar/vector_icons.h"
#include "components/vector_icons/vector_icons.h"
#include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkSurface.h" #include "third_party/skia/include/core/SkSurface.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
...@@ -663,14 +664,14 @@ void VrTestContext::StartAutocomplete(const AutocompleteRequest& request) { ...@@ -663,14 +664,14 @@ void VrTestContext::StartAutocomplete(const AutocompleteRequest& request) {
full_string.find(request.text) == 0) { full_string.find(request.text) == 0) {
result->suggestions.emplace_back(OmniboxSuggestion( result->suggestions.emplace_back(OmniboxSuggestion(
full_string, base::string16(), ACMatchClassifications(), full_string, base::string16(), ACMatchClassifications(),
ACMatchClassifications(), AutocompleteMatch::Type::VOICE_SUGGEST, ACMatchClassifications(), &vector_icons::kSearchIcon, GURL(),
GURL(), request.text, full_string.substr(request.text.size()))); request.text, full_string.substr(request.text.size())));
} }
// Supply a verbatim search match. // Supply a verbatim search match.
result->suggestions.emplace_back(OmniboxSuggestion( result->suggestions.emplace_back(OmniboxSuggestion(
request.text, base::string16(), ACMatchClassifications(), request.text, base::string16(), ACMatchClassifications(),
ACMatchClassifications(), AutocompleteMatch::Type::VOICE_SUGGEST, GURL(), ACMatchClassifications(), &vector_icons::kSearchIcon, GURL(),
base::string16(), base::string16())); base::string16(), base::string16()));
// Add a suggestion to exercise classification text styling. // Add a suggestion to exercise classification text styling.
...@@ -685,7 +686,7 @@ void VrTestContext::StartAutocomplete(const AutocompleteRequest& request) { ...@@ -685,7 +686,7 @@ void VrTestContext::StartAutocomplete(const AutocompleteRequest& request) {
ACMatchClassification(15, ACMatchClassification::DIM), ACMatchClassification(15, ACMatchClassification::DIM),
ACMatchClassification(19, ACMatchClassification::INVISIBLE), ACMatchClassification(19, ACMatchClassification::INVISIBLE),
}, },
AutocompleteMatch::Type::VOICE_SUGGEST, GURL("http://www.test.com/"), &vector_icons::kSearchIcon, GURL("http://www.test.com/"),
base::string16(), base::string16())); base::string16(), base::string16()));
while (result->suggestions.size() < 4) { while (result->suggestions.size() < 4) {
...@@ -695,7 +696,7 @@ void VrTestContext::StartAutocomplete(const AutocompleteRequest& request) { ...@@ -695,7 +696,7 @@ void VrTestContext::StartAutocomplete(const AutocompleteRequest& request) {
"Very lengthy description of the suggestion that would wrap " "Very lengthy description of the suggestion that would wrap "
"if not truncated through some other means."), "if not truncated through some other means."),
ACMatchClassifications(), ACMatchClassifications(), ACMatchClassifications(), ACMatchClassifications(),
AutocompleteMatch::Type::VOICE_SUGGEST, GURL("http://www.test.com/"), &vector_icons::kSearchIcon, GURL("http://www.test.com/"),
base::string16(), base::string16())); base::string16(), base::string16()));
} }
......
...@@ -270,10 +270,8 @@ void OnSuggestionModelAdded(UiScene* scene, ...@@ -270,10 +270,8 @@ void OnSuggestionModelAdded(UiScene* scene,
}, },
base::Unretained(p_description_text)))); base::Unretained(p_description_text))));
element_binding->bindings().push_back( element_binding->bindings().push_back(
VR_BIND(AutocompleteMatch::Type, SuggestionBinding, element_binding, VR_BIND(const gfx::VectorIcon*, SuggestionBinding, element_binding,
model->model()->type, VectorIcon, p_icon, model->model()->icon, VectorIcon, p_icon, view->SetIcon(*value)));
view->SetIcon(AutocompleteMatch::TypeToVectorIcon(
value, /*is_bookmark=*/false, /*is_tab_match=*/false))));
element_binding->set_view(background.get()); element_binding->set_view(background.get());
scene->AddUiElement(kOmniboxSuggestions, std::move(background)); scene->AddUiElement(kOmniboxSuggestions, std::move(background));
} }
......
...@@ -929,10 +929,10 @@ TEST_F(UiTest, OmniboxSuggestionBindings) { ...@@ -929,10 +929,10 @@ TEST_F(UiTest, OmniboxSuggestionBindings) {
EXPECT_EQ(container->children().size(), 0u); EXPECT_EQ(container->children().size(), 0u);
EXPECT_EQ(NumVisibleInTree(kOmniboxSuggestions), 0); EXPECT_EQ(NumVisibleInTree(kOmniboxSuggestions), 0);
model_->omnibox_suggestions.emplace_back(OmniboxSuggestion( model_->omnibox_suggestions.emplace_back(
base::string16(), base::string16(), ACMatchClassifications(), OmniboxSuggestion(base::string16(), base::string16(),
ACMatchClassifications(), AutocompleteMatch::Type::VOICE_SUGGEST, GURL(), ACMatchClassifications(), ACMatchClassifications(),
base::string16(), base::string16())); nullptr, GURL(), base::string16(), base::string16()));
OnBeginFrame(); OnBeginFrame();
EXPECT_EQ(container->children().size(), 1u); EXPECT_EQ(container->children().size(), 1u);
EXPECT_GT(NumVisibleInTree(kOmniboxSuggestions), 1); EXPECT_GT(NumVisibleInTree(kOmniboxSuggestions), 1);
...@@ -947,10 +947,10 @@ TEST_F(UiTest, OmniboxSuggestionNavigates) { ...@@ -947,10 +947,10 @@ TEST_F(UiTest, OmniboxSuggestionNavigates) {
CreateScene(kNotInWebVr); CreateScene(kNotInWebVr);
GURL gurl("http://test.com/"); GURL gurl("http://test.com/");
model_->push_mode(kModeEditingOmnibox); model_->push_mode(kModeEditingOmnibox);
model_->omnibox_suggestions.emplace_back(OmniboxSuggestion( model_->omnibox_suggestions.emplace_back(
base::string16(), base::string16(), ACMatchClassifications(), OmniboxSuggestion(base::string16(), base::string16(),
ACMatchClassifications(), AutocompleteMatch::Type::VOICE_SUGGEST, gurl, ACMatchClassifications(), ACMatchClassifications(),
base::string16(), base::string16())); nullptr, gurl, base::string16(), base::string16()));
OnBeginFrame(); OnBeginFrame();
// Let the omnibox fade in. // Let the omnibox fade in.
......
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