Commit 4cda1d40 authored by Orin Jaworski's avatar Orin Jaworski Committed by Commit Bot

[omnibox] Enable AutocompleteMatch instance to select its vector icon

This CL makes vector icon selection for AutocompleteMatch instances more
direct and simple by moving some of the complexity out of a static
method that was increasingly requiring callers to examine fields of the
instance to compose the call.  By empowering instances to use available
state for icon selection, it is now easy to specialize.  This was done
first for Drive document icons, and will also be used to differentiate
Pedals.  This CL only specializes one using an omnibox icon but all
Pedals will get their own.

Bug: 893183
Change-Id: I460c6202f1220b18091a9178f471464943190072
Reviewed-on: https://chromium-review.googlesource.com/c/1329895
Commit-Queue: Orin Jaworski <orinj@chromium.org>
Reviewed-by: default avatarChristopher Grant <cjgrant@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608144}
parent 92644e19
......@@ -74,8 +74,7 @@ std::tuple<GURL, bool> AutocompleteController::GetUrlFromVoiceInput(
void AutocompleteController::OnResultChanged(bool default_match_changed) {
auto suggestions = std::make_unique<OmniboxSuggestions>();
for (const auto& match : autocomplete_controller_->result()) {
const gfx::VectorIcon* icon = &AutocompleteMatch::TypeToVectorIcon(
match.type, false, match.document_type);
const gfx::VectorIcon* icon = &match.GetVectorIcon(false);
suggestions->suggestions.emplace_back(OmniboxSuggestion(
match.contents, match.description, match.contents_class,
match.description_class, icon, match.destination_url,
......
......@@ -204,10 +204,8 @@ AutocompleteMatch& AutocompleteMatch::operator=(
#if (!defined(OS_ANDROID) || BUILDFLAG(ENABLE_VR)) && !defined(OS_IOS)
// static
const gfx::VectorIcon& AutocompleteMatch::TypeToVectorIcon(
Type type,
bool is_bookmark,
DocumentType document_type) {
const gfx::VectorIcon& AutocompleteMatch::TypeToVectorIcon(Type type,
bool is_bookmark) {
if (is_bookmark)
return omnibox::kBookmarkIcon;
......@@ -224,23 +222,8 @@ const gfx::VectorIcon& AutocompleteMatch::TypeToVectorIcon(
case Type::PHYSICAL_WEB_DEPRECATED:
case Type::PHYSICAL_WEB_OVERFLOW_DEPRECATED:
case Type::TAB_SEARCH_DEPRECATED:
return omnibox::kPageIcon;
case Type::DOCUMENT_SUGGESTION:
switch (document_type) {
case DocumentType::DRIVE_DOCS:
return omnibox::kDriveDocsIcon;
case DocumentType::DRIVE_FORMS:
return omnibox::kDriveFormsIcon;
case DocumentType::DRIVE_SHEETS:
return omnibox::kDriveSheetsIcon;
case DocumentType::DRIVE_SLIDES:
return omnibox::kDriveSlidesIcon;
case DocumentType::DRIVE_OTHER:
return omnibox::kDriveLogoIcon;
default:
return omnibox::kPageIcon;
}
return omnibox::kPageIcon;
case Type::SEARCH_WHAT_YOU_TYPED:
case Type::SEARCH_HISTORY:
......@@ -272,6 +255,33 @@ const gfx::VectorIcon& AutocompleteMatch::TypeToVectorIcon(
static const gfx::VectorIcon dummy = {};
return dummy;
}
const gfx::VectorIcon& AutocompleteMatch::GetVectorIcon(
bool is_bookmark) const {
if (is_bookmark)
return omnibox::kBookmarkIcon;
switch (type) {
case Type::DOCUMENT_SUGGESTION:
switch (document_type) {
case DocumentType::DRIVE_DOCS:
return omnibox::kDriveDocsIcon;
case DocumentType::DRIVE_FORMS:
return omnibox::kDriveFormsIcon;
case DocumentType::DRIVE_SHEETS:
return omnibox::kDriveSheetsIcon;
case DocumentType::DRIVE_SLIDES:
return omnibox::kDriveSlidesIcon;
case DocumentType::DRIVE_OTHER:
return omnibox::kDriveLogoIcon;
default:
return omnibox::kPageIcon;
}
case Type::PEDAL:
return (pedal ? pedal->GetVectorIcon() : omnibox::kPedalIcon);
default:
return TypeToVectorIcon(type, is_bookmark);
}
}
#endif
// static
......
......@@ -139,9 +139,12 @@ struct AutocompleteMatch {
// Gets the vector icon identifier for the icon to be shown for |type|. If
// |is_bookmark| is true, returns a bookmark icon rather than what the type
// would determine.
static const gfx::VectorIcon& TypeToVectorIcon(Type type,
bool is_bookmark,
DocumentType document_type);
static const gfx::VectorIcon& TypeToVectorIcon(Type type, bool is_bookmark);
// Gets the VectorIcon to be shown for a match, which may depend on match
// contents. This is preferable to using TypeToVectorIcon when a match
// instance is available because it can make a more informed choice.
const gfx::VectorIcon& GetVectorIcon(bool is_bookmark) const;
#endif
// Comparison function for determining when one match is better than another.
......
......@@ -10,6 +10,10 @@
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "ui/base/l10n/l10n_util.h"
#if (!defined(OS_ANDROID) || BUILDFLAG(ENABLE_VR)) && !defined(OS_IOS)
#include "components/omnibox/browser/vector_icons.h" // nogncheck
#endif
OmniboxPedal::LabelStrings::LabelStrings(int id_hint,
int id_hint_short,
int id_suggestion_contents)
......@@ -56,6 +60,12 @@ bool OmniboxPedal::IsReadyToTrigger(
return true;
}
#if (!defined(OS_ANDROID) || BUILDFLAG(ENABLE_VR)) && !defined(OS_IOS)
const gfx::VectorIcon& OmniboxPedal::GetVectorIcon() const {
return omnibox::kPedalIcon;
}
#endif
bool OmniboxPedal::IsTriggerMatch(const base::string16& match_text) const {
return triggers_.find(match_text) != triggers_.end();
}
......
......@@ -9,8 +9,16 @@
#include "base/strings/string16.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/omnibox/browser/buildflags.h"
#include "url/gurl.h"
#if (!defined(OS_ANDROID) || BUILDFLAG(ENABLE_VR)) && !defined(OS_IOS)
namespace gfx {
struct VectorIcon;
}
#endif
class AutocompleteProviderClient;
class OmniboxEditController;
class OmniboxClient;
......@@ -86,6 +94,11 @@ class OmniboxPedal {
// Pedal may not be ready to trigger if no update is available.)
virtual bool IsReadyToTrigger(const AutocompleteProviderClient& client) const;
#if (!defined(OS_ANDROID) || BUILDFLAG(ENABLE_VR)) && !defined(OS_IOS)
// Returns the vector icon to represent this Pedal's action in suggestion.
virtual const gfx::VectorIcon& GetVectorIcon() const;
#endif
// Returns true if the preprocessed match suggestion text triggers
// presentation of this Pedal. This is not intended for general use,
// and only OmniboxPedalProvider should need to call this method.
......
......@@ -5,11 +5,17 @@
#include "components/omnibox/browser/omnibox_pedal_implementations.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "components/omnibox/browser/autocomplete_provider_client.h"
#include "components/omnibox/browser/buildflags.h"
#include "components/omnibox/browser/omnibox_client.h"
#include "components/omnibox/browser/omnibox_pedal.h"
#include "components/strings/grit/components_strings.h"
#if (!defined(OS_ANDROID) || BUILDFLAG(ENABLE_VR)) && !defined(OS_IOS)
#include "components/omnibox/browser/vector_icons.h" // nogncheck
#endif
// A small convenience wrapper for the common implementation pattern below.
class OmniboxPedalCommon : public OmniboxPedal {
public:
......@@ -56,6 +62,12 @@ class OmniboxPedalClearBrowsingData : public OmniboxPedalCommon {
"history clear",
"history clear chrome",
}) {}
#if (!defined(OS_ANDROID) || BUILDFLAG(ENABLE_VR)) && !defined(OS_IOS)
const gfx::VectorIcon& GetVectorIcon() const override {
return omnibox::kAnswerWhenIsIcon;
}
#endif
};
// =============================================================================
......
......@@ -323,8 +323,7 @@ gfx::Image OmniboxPopupModel::GetMatchIcon(const AutocompleteMatch& match,
return edit_model_->client()->GetSizedIcon(favicon);
}
const auto& vector_icon_type = AutocompleteMatch::TypeToVectorIcon(
match.type, IsStarredMatch(match), match.document_type);
const auto& vector_icon_type = match.GetVectorIcon(IsStarredMatch(match));
return edit_model_->client()->GetSizedIcon(vector_icon_type,
vector_icon_color);
......
......@@ -134,8 +134,7 @@ gfx::ImageSkia OmniboxView::GetIcon(int dip_size,
// For tests, model_ will be null.
if (!model_) {
const gfx::VectorIcon& vector_icon = AutocompleteMatch::TypeToVectorIcon(
AutocompleteMatchType::URL_WHAT_YOU_TYPED, false /*is_bookmark*/,
AutocompleteMatch::DocumentType::NONE);
AutocompleteMatchType::URL_WHAT_YOU_TYPED, /*is_bookmark=*/false);
return gfx::CreateVectorIcon(vector_icon, dip_size, color);
}
......@@ -165,8 +164,7 @@ gfx::ImageSkia OmniboxView::GetIcon(int dip_size,
const bool is_bookmarked =
bookmark_model && bookmark_model->IsBookmarked(match.destination_url);
const gfx::VectorIcon& vector_icon = AutocompleteMatch::TypeToVectorIcon(
match.type, is_bookmarked, match.document_type);
const gfx::VectorIcon& vector_icon = match.GetVectorIcon(is_bookmarked);
return gfx::CreateVectorIcon(vector_icon, dip_size, color);
#endif // defined(OS_ANDROID) || defined(OS_IOS)
}
......
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