Commit 1d69f2c4 authored by Thanh Nguyen's avatar Thanh Nguyen Committed by Commit Bot

Reland "Using vector icons for launcher search provider"

This is a reland of dd116903

The original CL was reverted because mac-arm64-rel was failing.
It works fine now.

TBR=xiyuan@chromium.org,jiameng@chromium.org,tby@chromium.org,austinct@chromium.org

Original change's description:
> 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/+/2352290
> Reviewed-by: Austin Tankiang <austinct@chromium.org>
> Reviewed-by: Noel Gordon <noel@chromium.org>
> Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
> Reviewed-by: Jia Meng <jiameng@chromium.org>
> Reviewed-by: Tony Yeoman <tby@chromium.org>
> Commit-Queue: Thanh Nguyen <thanhdng@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#798087}

Bug: 1067326
Change-Id: I3558b2f0b023227d06893eda14b88fe3fe967b0b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2358936Reviewed-by: default avatarThanh Nguyen <thanhdng@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: Thanh Nguyen <thanhdng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798513}
parent 6c29bd6c
......@@ -131,8 +131,9 @@ void Service::SetSearchResults(
for (const auto& result : results) {
const int relevance =
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.
// Results with a match score of 0 are discarded. This will also be used to
......@@ -146,7 +147,7 @@ void Service::SetSearchResults(
continue;
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());
search_result->UpdateFromMatch(tokenized_title, match);
search_results.push_back(std::move(search_result));
......
......@@ -7,18 +7,35 @@
#include <string>
#include <utility>
#include "ash/public/cpp/app_list/vector_icons/vector_icons.h"
#include "base/files/file_path.h"
#include "base/no_destructor.h"
#include "base/strings/string_util.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/chromeos/resources/grit/ui_chromeos_resources.h"
#include "ui/file_manager/file_manager_resource_util.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_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 internal {
......@@ -221,4 +238,64 @@ gfx::ImageSkia GetChipIconForPath(const base::FilePath& 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
......@@ -47,6 +47,7 @@ int GetChipResourceIdForIconType(IconType icon);
gfx::ImageSkia GetIconForPath(const base::FilePath& filepath);
gfx::ImageSkia GetChipIconForPath(const base::FilePath& filepath);
gfx::ImageSkia GetIconFromType(const std::string& icon_type);
} // namespace app_list
......
......@@ -11,7 +11,7 @@
#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.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;
......@@ -25,13 +25,14 @@ namespace app_list {
LauncherSearchResult::LauncherSearchResult(
const std::string& item_id,
const GURL& icon_url,
const std::string& icon_type,
const int discrete_value_relevance,
Profile* profile,
const extensions::Extension* extension,
std::unique_ptr<chromeos::launcher_search_provider::ErrorReporter>
error_reporter)
: item_id_(item_id),
icon_type_(icon_type),
discrete_value_relevance_(discrete_value_relevance),
profile_(profile),
extension_(extension) {
......@@ -39,23 +40,12 @@ LauncherSearchResult::LauncherSearchResult(
DCHECK_LE(discrete_value_relevance,
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();
}
LauncherSearchResult::~LauncherSearchResult() {
icon_image_loader_->RemoveObserver(this);
}
std::unique_ptr<LauncherSearchResult> LauncherSearchResult::Duplicate() const {
LauncherSearchResult* duplicated_result =
new LauncherSearchResult(item_id_, discrete_value_relevance_, profile_,
extension_, icon_image_loader_);
LauncherSearchResult* duplicated_result = new LauncherSearchResult(
item_id_, icon_type_, discrete_value_relevance_, profile_, extension_);
duplicated_result->set_model_updater(model_updater());
duplicated_result->SetMetadata(CloneMetadata());
return base::WrapUnique(duplicated_result);
......@@ -70,30 +60,17 @@ ash::SearchResultType LauncherSearchResult::GetSearchResultType() const {
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(
const std::string& item_id,
const std::string& icon_type,
const int discrete_value_relevance,
Profile* profile,
const extensions::Extension* extension,
const scoped_refptr<LauncherSearchIconImageLoader>& icon_image_loader)
const extensions::Extension* extension)
: item_id_(item_id),
icon_type_(icon_type),
discrete_value_relevance_(discrete_value_relevance),
profile_(profile),
extension_(extension),
icon_image_loader_(icon_image_loader) {
DCHECK(icon_image_loader_);
extension_(extension) {
Initialize();
}
......@@ -105,9 +82,7 @@ void LauncherSearchResult::Initialize() {
SetDetails(base::UTF8ToUTF16(extension_->name()));
SetResultType(ResultType::kLauncher);
icon_image_loader_->AddObserver(this);
SetIcon(icon_image_loader_->GetIconImage());
SetIcon(GetIconFromType(icon_type_));
}
std::string LauncherSearchResult::GetSearchResultId() {
......
......@@ -11,44 +11,36 @@
#include "ash/public/cpp/app_list/app_list_metrics.h"
#include "base/macros.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/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 "url/gurl.h"
namespace app_list {
class LauncherSearchResult : public ChromeSearchResult,
public LauncherSearchIconImageLoader::Observer {
class LauncherSearchResult : public ChromeSearchResult {
public:
LauncherSearchResult(
const std::string& item_id,
const GURL& icon_url,
const std::string& icon_type,
const int discrete_value_relevance,
Profile* profile,
const extensions::Extension* extension,
std::unique_ptr<chromeos::launcher_search_provider::ErrorReporter>
error_reporter);
~LauncherSearchResult() override;
std::unique_ptr<LauncherSearchResult> Duplicate() const;
// ChromeSearchResult overrides:
void Open(int event_flags) override;
ash::SearchResultType GetSearchResultType() const override;
void OnIconImageChanged(LauncherSearchIconImageLoader* image_loader) override;
void OnBadgeIconImageChanged(
LauncherSearchIconImageLoader* image_loader) override;
private:
// Constructor for duplicating a result.
LauncherSearchResult(
const std::string& item_id,
LauncherSearchResult(const std::string& item_id,
const std::string& icon_type,
const int discrete_value_relevance,
Profile* profile,
const extensions::Extension* extension,
const scoped_refptr<LauncherSearchIconImageLoader>& icon_image_loader);
const extensions::Extension* extension);
void Initialize();
// Returns search result ID. The search result ID is comprised of the
......@@ -57,11 +49,11 @@ class LauncherSearchResult : public ChromeSearchResult,
std::string GetSearchResultId();
const std::string item_id_;
const std::string icon_type_;
// Must be between 0 and kMaxSearchResultScore.
const int discrete_value_relevance_;
Profile* profile_;
const extensions::Extension* extension_;
scoped_refptr<LauncherSearchIconImageLoader> icon_image_loader_;
DISALLOW_COPY_AND_ASSIGN(LauncherSearchResult);
};
......
......@@ -11,8 +11,8 @@ namespace launcherSearchProvider {
dictionary SearchResult {
DOMString itemId;
DOMString title;
// If iconUrl is not provided, app/extension icon is used automatically.
DOMString? iconUrl;
// If iconType is not provided, a generic icon is used automatically.
DOMString? iconType;
// Relevance ranges from 0 to 4. 0 is the lowest relevance, 4 is highest.
long relevance;
};
......
......@@ -320,17 +320,12 @@ class LauncherSearch {
createSearchResult_(entry) {
// TODO(yawano): Use filetype_folder_shared.png for a shared
// folder.
// TODO(yawano): Add archive launcher filetype icon.
let icon = FileType.getIcon(entry);
if (icon === 'UNKNOWN' || icon === 'archive') {
if (icon === 'UNKNOWN') {
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.
const title = FileType.isHosted(entry) ?
entry.name.substr(
......@@ -340,7 +335,7 @@ class LauncherSearch {
return {
itemId: entry.toURL(),
title: title,
iconUrl: iconUrl,
iconType: icon,
// Relevance is set as 2 for all results as a temporary
// implementation. 2 is the middle value.
// 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