Commit dd116903 authored by Thanh Nguyen's avatar Thanh Nguyen Committed by Commit Bot

Using vector icons for launcher search provider

Currently LauncherSearchProvider use png as the format for the result.
This CL changes the format to vector icons (.icon).

Bug: 1067326
Change-Id: I55fb11ed50906a5199bc28339de42d4903433b36
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2352290Reviewed-by: default avatarAustin Tankiang <austinct@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarJia Meng <jiameng@chromium.org>
Reviewed-by: default avatarTony Yeoman <tby@chromium.org>
Commit-Queue: Thanh Nguyen <thanhdng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798087}
parent 2930f9c5
...@@ -131,8 +131,9 @@ void Service::SetSearchResults( ...@@ -131,8 +131,9 @@ void Service::SetSearchResults(
for (const auto& result : results) { for (const auto& result : results) {
const int relevance = const int relevance =
base::ClampToRange(result.relevance, 0, kMaxSearchResultScore); base::ClampToRange(result.relevance, 0, kMaxSearchResultScore);
const GURL icon_url =
result.icon_url ? GURL(*result.icon_url.get()) : GURL(); const std::string icon_type =
result.icon_type ? *result.icon_type.get() : std::string();
// Calculate the relevance score by matching the query with the title. // Calculate the relevance score by matching the query with the title.
// Results with a match score of 0 are discarded. This will also be used to // Results with a match score of 0 are discarded. This will also be used to
...@@ -146,7 +147,7 @@ void Service::SetSearchResults( ...@@ -146,7 +147,7 @@ void Service::SetSearchResults(
continue; continue;
auto search_result = std::make_unique<app_list::LauncherSearchResult>( auto search_result = std::make_unique<app_list::LauncherSearchResult>(
result.item_id, icon_url, relevance, profile_, extension, result.item_id, icon_type, relevance, profile_, extension,
error_reporter->Duplicate()); error_reporter->Duplicate());
search_result->UpdateFromMatch(tokenized_title, match); search_result->UpdateFromMatch(tokenized_title, match);
search_results.push_back(std::move(search_result)); search_results.push_back(std::move(search_result));
......
...@@ -7,18 +7,35 @@ ...@@ -7,18 +7,35 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "ash/public/cpp/app_list/vector_icons/vector_icons.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/chromeos/resources/grit/ui_chromeos_resources.h" #include "ui/chromeos/resources/grit/ui_chromeos_resources.h"
#include "ui/file_manager/file_manager_resource_util.h" #include "ui/file_manager/file_manager_resource_util.h"
#include "ui/file_manager/grit/file_manager_resources.h" #include "ui/file_manager/grit/file_manager_resources.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/gfx/paint_vector_icon.h"
#include "chrome/browser/ui/app_list/search/launcher_search/launcher_search_icon_image_loader.h" namespace {
// Hex color: #796EEE
constexpr SkColor kFiletypeGsiteColor = SkColorSetRGB(121, 110, 238);
// Hex color: #FF7537
constexpr SkColor kFiletypePptColor = SkColorSetRGB(255, 117, 55);
// Hex color: #796EEE
constexpr SkColor kFiletypeSitesColor = SkColorSetRGB(121, 110, 238);
constexpr int kIconDipSize = 20;
} // namespace
namespace app_list { namespace app_list {
namespace internal { namespace internal {
...@@ -221,4 +238,64 @@ gfx::ImageSkia GetChipIconForPath(const base::FilePath& filepath) { ...@@ -221,4 +238,64 @@ gfx::ImageSkia GetChipIconForPath(const base::FilePath& filepath) {
internal::GetIconTypeForPath(filepath))); internal::GetIconTypeForPath(filepath)));
} }
gfx::ImageSkia GetIconFromType(const std::string& icon_type) {
static const base::NoDestructor<std::map<std::string, gfx::IconDescription>>
type_to_icon_description(
{{"archive", gfx::IconDescription(ash::kFiletypeArchiveIcon,
kIconDipSize, gfx::kGoogleGrey700)},
{"audio", gfx::IconDescription(ash::kFiletypeAudioIcon, kIconDipSize,
gfx::kGoogleRed500)},
{"chart", gfx::IconDescription(ash::kFiletypeChartIcon, kIconDipSize,
gfx::kGoogleGreen500)},
{"excel", gfx::IconDescription(ash::kFiletypeExcelIcon, kIconDipSize,
gfx::kGoogleGreen500)},
{"folder", gfx::IconDescription(ash::kFiletypeFolderIcon,
kIconDipSize, gfx::kGoogleGrey700)},
{"gdoc", gfx::IconDescription(ash::kFiletypeGdocIcon, kIconDipSize,
gfx::kGoogleBlue500)},
{"gdraw", gfx::IconDescription(ash::kFiletypeGdrawIcon, kIconDipSize,
gfx::kGoogleRed500)},
{"generic", gfx::IconDescription(ash::kFiletypeGenericIcon,
kIconDipSize, gfx::kGoogleGrey700)},
{"gform", gfx::IconDescription(ash::kFiletypeGformIcon, kIconDipSize,
gfx::kGoogleGreen500)},
{"gmap", gfx::IconDescription(ash::kFiletypeGmapIcon, kIconDipSize,
gfx::kGoogleRed500)},
{"gsheet", gfx::IconDescription(ash::kFiletypeGsheetIcon,
kIconDipSize, gfx::kGoogleGreen500)},
{"gsite", gfx::IconDescription(ash::kFiletypeGsiteIcon, kIconDipSize,
kFiletypeGsiteColor)},
{"gslides",
gfx::IconDescription(ash::kFiletypeGslidesIcon, kIconDipSize,
gfx::kGoogleYellow500)},
{"gtable", gfx::IconDescription(ash::kFiletypeGtableIcon,
kIconDipSize, gfx::kGoogleGreen500)},
{"image", gfx::IconDescription(ash::kFiletypeImageIcon, kIconDipSize,
gfx::kGoogleRed500)},
{"linux", gfx::IconDescription(ash::kFiletypeLinuxIcon, kIconDipSize,
gfx::kGoogleGrey700)},
{"pdf", gfx::IconDescription(ash::kFiletypePdfIcon, kIconDipSize,
gfx::kGoogleRed500)},
{"ppt", gfx::IconDescription(ash::kFiletypePptIcon, kIconDipSize,
kFiletypePptColor)},
{"script", gfx::IconDescription(ash::kFiletypeScriptIcon,
kIconDipSize, gfx::kGoogleBlue500)},
{"shared", gfx::IconDescription(ash::kFiletypeSharedIcon,
kIconDipSize, gfx::kGoogleGrey700)},
{"sites", gfx::IconDescription(ash::kFiletypeSitesIcon, kIconDipSize,
kFiletypeSitesColor)},
{"tini", gfx::IconDescription(ash::kFiletypeTiniIcon, kIconDipSize,
gfx::kGoogleBlue500)},
{"video", gfx::IconDescription(ash::kFiletypeVideoIcon, kIconDipSize,
gfx::kGoogleRed500)},
{"word", gfx::IconDescription(ash::kFiletypeWordIcon, kIconDipSize,
gfx::kGoogleBlue500)}});
const auto& it = type_to_icon_description->find(icon_type);
if (it == type_to_icon_description->end())
return gfx::CreateVectorIcon(ash::kFiletypeGenericIcon, kIconDipSize,
gfx::kGoogleGrey700);
return gfx::CreateVectorIcon(it->second);
}
} // namespace app_list } // namespace app_list
...@@ -47,6 +47,7 @@ int GetChipResourceIdForIconType(IconType icon); ...@@ -47,6 +47,7 @@ int GetChipResourceIdForIconType(IconType icon);
gfx::ImageSkia GetIconForPath(const base::FilePath& filepath); gfx::ImageSkia GetIconForPath(const base::FilePath& filepath);
gfx::ImageSkia GetChipIconForPath(const base::FilePath& filepath); gfx::ImageSkia GetChipIconForPath(const base::FilePath& filepath);
gfx::ImageSkia GetIconFromType(const std::string& icon_type);
} // namespace app_list } // namespace app_list
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/launcher_search_provider/launcher_search_provider_service.h" #include "chrome/browser/chromeos/launcher_search_provider/launcher_search_provider_service.h"
#include "chrome/browser/ui/app_list/search/launcher_search/launcher_search_icon_image_loader_impl.h" #include "chrome/browser/ui/app_list/search/common/file_icon_util.h"
using chromeos::launcher_search_provider::Service; using chromeos::launcher_search_provider::Service;
...@@ -25,13 +25,14 @@ namespace app_list { ...@@ -25,13 +25,14 @@ namespace app_list {
LauncherSearchResult::LauncherSearchResult( LauncherSearchResult::LauncherSearchResult(
const std::string& item_id, const std::string& item_id,
const GURL& icon_url, const std::string& icon_type,
const int discrete_value_relevance, const int discrete_value_relevance,
Profile* profile, Profile* profile,
const extensions::Extension* extension, const extensions::Extension* extension,
std::unique_ptr<chromeos::launcher_search_provider::ErrorReporter> std::unique_ptr<chromeos::launcher_search_provider::ErrorReporter>
error_reporter) error_reporter)
: item_id_(item_id), : item_id_(item_id),
icon_type_(icon_type),
discrete_value_relevance_(discrete_value_relevance), discrete_value_relevance_(discrete_value_relevance),
profile_(profile), profile_(profile),
extension_(extension) { extension_(extension) {
...@@ -39,23 +40,12 @@ LauncherSearchResult::LauncherSearchResult( ...@@ -39,23 +40,12 @@ LauncherSearchResult::LauncherSearchResult(
DCHECK_LE(discrete_value_relevance, DCHECK_LE(discrete_value_relevance,
chromeos::launcher_search_provider::kMaxSearchResultScore); chromeos::launcher_search_provider::kMaxSearchResultScore);
icon_image_loader_ = base::MakeRefCounted<LauncherSearchIconImageLoaderImpl>(
icon_url, profile, extension,
ash::AppListConfig::instance().GetPreferredIconDimension(display_type()),
std::move(error_reporter));
icon_image_loader_->LoadResources();
Initialize(); Initialize();
} }
LauncherSearchResult::~LauncherSearchResult() {
icon_image_loader_->RemoveObserver(this);
}
std::unique_ptr<LauncherSearchResult> LauncherSearchResult::Duplicate() const { std::unique_ptr<LauncherSearchResult> LauncherSearchResult::Duplicate() const {
LauncherSearchResult* duplicated_result = LauncherSearchResult* duplicated_result = new LauncherSearchResult(
new LauncherSearchResult(item_id_, discrete_value_relevance_, profile_, item_id_, icon_type_, discrete_value_relevance_, profile_, extension_);
extension_, icon_image_loader_);
duplicated_result->set_model_updater(model_updater()); duplicated_result->set_model_updater(model_updater());
duplicated_result->SetMetadata(CloneMetadata()); duplicated_result->SetMetadata(CloneMetadata());
return base::WrapUnique(duplicated_result); return base::WrapUnique(duplicated_result);
...@@ -70,30 +60,17 @@ ash::SearchResultType LauncherSearchResult::GetSearchResultType() const { ...@@ -70,30 +60,17 @@ ash::SearchResultType LauncherSearchResult::GetSearchResultType() const {
return ash::LAUNCHER_SEARCH_PROVIDER_RESULT; return ash::LAUNCHER_SEARCH_PROVIDER_RESULT;
} }
void LauncherSearchResult::OnIconImageChanged(
LauncherSearchIconImageLoader* image_loader) {
DCHECK_EQ(image_loader, icon_image_loader_.get());
SetIcon(icon_image_loader_->GetIconImage());
}
void LauncherSearchResult::OnBadgeIconImageChanged(
LauncherSearchIconImageLoader* image_loader) {
DCHECK_EQ(image_loader, icon_image_loader_.get());
// No badging is required.
}
LauncherSearchResult::LauncherSearchResult( LauncherSearchResult::LauncherSearchResult(
const std::string& item_id, const std::string& item_id,
const std::string& icon_type,
const int discrete_value_relevance, const int discrete_value_relevance,
Profile* profile, Profile* profile,
const extensions::Extension* extension, const extensions::Extension* extension)
const scoped_refptr<LauncherSearchIconImageLoader>& icon_image_loader)
: item_id_(item_id), : item_id_(item_id),
icon_type_(icon_type),
discrete_value_relevance_(discrete_value_relevance), discrete_value_relevance_(discrete_value_relevance),
profile_(profile), profile_(profile),
extension_(extension), extension_(extension) {
icon_image_loader_(icon_image_loader) {
DCHECK(icon_image_loader_);
Initialize(); Initialize();
} }
...@@ -105,9 +82,7 @@ void LauncherSearchResult::Initialize() { ...@@ -105,9 +82,7 @@ void LauncherSearchResult::Initialize() {
SetDetails(base::UTF8ToUTF16(extension_->name())); SetDetails(base::UTF8ToUTF16(extension_->name()));
SetResultType(ResultType::kLauncher); SetResultType(ResultType::kLauncher);
icon_image_loader_->AddObserver(this); SetIcon(GetIconFromType(icon_type_));
SetIcon(icon_image_loader_->GetIconImage());
} }
std::string LauncherSearchResult::GetSearchResultId() { std::string LauncherSearchResult::GetSearchResultId() {
......
...@@ -11,44 +11,36 @@ ...@@ -11,44 +11,36 @@
#include "ash/public/cpp/app_list/app_list_metrics.h" #include "ash/public/cpp/app_list/app_list_metrics.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "chrome/browser/chromeos/launcher_search_provider/error_reporter.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/search/chrome_search_result.h" #include "chrome/browser/ui/app_list/search/chrome_search_result.h"
#include "chrome/browser/ui/app_list/search/launcher_search/launcher_search_icon_image_loader.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "url/gurl.h"
namespace app_list { namespace app_list {
class LauncherSearchResult : public ChromeSearchResult, class LauncherSearchResult : public ChromeSearchResult {
public LauncherSearchIconImageLoader::Observer {
public: public:
LauncherSearchResult( LauncherSearchResult(
const std::string& item_id, const std::string& item_id,
const GURL& icon_url, const std::string& icon_type,
const int discrete_value_relevance, const int discrete_value_relevance,
Profile* profile, Profile* profile,
const extensions::Extension* extension, const extensions::Extension* extension,
std::unique_ptr<chromeos::launcher_search_provider::ErrorReporter> std::unique_ptr<chromeos::launcher_search_provider::ErrorReporter>
error_reporter); error_reporter);
~LauncherSearchResult() override;
std::unique_ptr<LauncherSearchResult> Duplicate() const; std::unique_ptr<LauncherSearchResult> Duplicate() const;
// ChromeSearchResult overrides: // ChromeSearchResult overrides:
void Open(int event_flags) override; void Open(int event_flags) override;
ash::SearchResultType GetSearchResultType() const override; ash::SearchResultType GetSearchResultType() const override;
void OnIconImageChanged(LauncherSearchIconImageLoader* image_loader) override;
void OnBadgeIconImageChanged(
LauncherSearchIconImageLoader* image_loader) override;
private: private:
// Constructor for duplicating a result. // Constructor for duplicating a result.
LauncherSearchResult( LauncherSearchResult(const std::string& item_id,
const std::string& item_id, const std::string& icon_type,
const int discrete_value_relevance, const int discrete_value_relevance,
Profile* profile, Profile* profile,
const extensions::Extension* extension, const extensions::Extension* extension);
const scoped_refptr<LauncherSearchIconImageLoader>& icon_image_loader);
void Initialize(); void Initialize();
// Returns search result ID. The search result ID is comprised of the // Returns search result ID. The search result ID is comprised of the
...@@ -57,11 +49,11 @@ class LauncherSearchResult : public ChromeSearchResult, ...@@ -57,11 +49,11 @@ class LauncherSearchResult : public ChromeSearchResult,
std::string GetSearchResultId(); std::string GetSearchResultId();
const std::string item_id_; const std::string item_id_;
const std::string icon_type_;
// Must be between 0 and kMaxSearchResultScore. // Must be between 0 and kMaxSearchResultScore.
const int discrete_value_relevance_; const int discrete_value_relevance_;
Profile* profile_; Profile* profile_;
const extensions::Extension* extension_; const extensions::Extension* extension_;
scoped_refptr<LauncherSearchIconImageLoader> icon_image_loader_;
DISALLOW_COPY_AND_ASSIGN(LauncherSearchResult); DISALLOW_COPY_AND_ASSIGN(LauncherSearchResult);
}; };
......
...@@ -11,8 +11,8 @@ namespace launcherSearchProvider { ...@@ -11,8 +11,8 @@ namespace launcherSearchProvider {
dictionary SearchResult { dictionary SearchResult {
DOMString itemId; DOMString itemId;
DOMString title; DOMString title;
// If iconUrl is not provided, app/extension icon is used automatically. // If iconType is not provided, a generic icon is used automatically.
DOMString? iconUrl; DOMString? iconType;
// Relevance ranges from 0 to 4. 0 is the lowest relevance, 4 is highest. // Relevance ranges from 0 to 4. 0 is the lowest relevance, 4 is highest.
long relevance; long relevance;
}; };
......
...@@ -320,17 +320,12 @@ class LauncherSearch { ...@@ -320,17 +320,12 @@ class LauncherSearch {
createSearchResult_(entry) { createSearchResult_(entry) {
// TODO(yawano): Use filetype_folder_shared.png for a shared // TODO(yawano): Use filetype_folder_shared.png for a shared
// folder. // folder.
// TODO(yawano): Add archive launcher filetype icon.
let icon = FileType.getIcon(entry); let icon = FileType.getIcon(entry);
if (icon === 'UNKNOWN' || icon === 'archive') {
if (icon === 'UNKNOWN') {
icon = 'generic'; icon = 'generic';
} }
const useHighDpiIcon = window.devicePixelRatio > 1.0;
const iconUrl = chrome.runtime.getURL(
'foreground/images/launcher_filetypes/' +
(useHighDpiIcon ? '2x/' : '') + 'launcher_filetype_' + icon + '.png');
// Hide extensions for hosted files. // Hide extensions for hosted files.
const title = FileType.isHosted(entry) ? const title = FileType.isHosted(entry) ?
entry.name.substr( entry.name.substr(
...@@ -340,7 +335,7 @@ class LauncherSearch { ...@@ -340,7 +335,7 @@ class LauncherSearch {
return { return {
itemId: entry.toURL(), itemId: entry.toURL(),
title: title, title: title,
iconUrl: iconUrl, iconType: icon,
// Relevance is set as 2 for all results as a temporary // Relevance is set as 2 for all results as a temporary
// implementation. 2 is the middle value. // implementation. 2 is the middle value.
// TODO(yawano): Implement practical relevance calculation. // TODO(yawano): Implement practical relevance calculation.
......
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