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

Fix icon issues for FAR recommendations

1. Adds an icon as the badge icon for the FAR recommendations
2. Make the icon consistent with arc playstore search result.
3. Move EncircledImageSource to ImageSkiaOperations so that it can be
reused (no logic changed)

Bug: 1028373
Change-Id: Ieabf6f39e63472f6d1b0eee70b6bc9841dbbd13f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2402472
Commit-Queue: Thanh Nguyen <thanhdng@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Reviewed-by: default avatarJia Meng <jiameng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809149}
parent 42cab552
......@@ -6,10 +6,18 @@
#include <utility>
#include "ash/public/cpp/app_list/app_list_config.h"
#include "ash/public/cpp/vector_icons/vector_icons.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/apps/app_service/app_icon_factory.h"
#include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
#include "components/vector_icons/vector_icons.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/native_theme/native_theme.h"
namespace app_list {
......@@ -21,11 +29,35 @@ constexpr char kPlayStoreAppUrlPrefix[] =
// app result as a top result typically.
constexpr float kAppReinstallRelevance = 0.7;
// Create a badge icon with a white circle background image.
gfx::ImageSkia CreateBadgeIcon(const gfx::VectorIcon& vector_icon) {
// TODO(thanhdng): Once ChromeSearchResult has access to a View pointer, get
// the NativeTheme from there instead.
const SkColor badge_icon_color =
ui::NativeTheme::GetInstanceForNativeUi()->GetSystemColor(
ui::NativeTheme::kColorId_DefaultIconColor);
const int badge_size =
ash::AppListConfig::instance().search_tile_badge_icon_dimension();
const auto& badge_icon =
gfx::CreateVectorIcon(vector_icon, badge_size, badge_icon_color);
return gfx::ImageSkiaOperations::CreateImageWithCircleBackground(
badge_size / 2, SK_ColorWHITE, badge_icon);
}
// Apply background and mask to make the icon similar to the icon of
// ArcPlaystoreSearchResult.
gfx::ImageSkia ApplyBackgroundAndMask(const gfx::ImageSkia& image) {
return gfx::ImageSkiaOperations::CreateResizedImage(
apps::ApplyBackgroundAndMask(image),
skia::ImageOperations::RESIZE_LANCZOS3,
gfx::Size(ash::AppListConfig::instance().search_tile_icon_dimension(),
ash::AppListConfig::instance().search_tile_icon_dimension()));
}
} // namespace
ArcAppReinstallAppResult::ArcAppReinstallAppResult(
const arc::mojom::AppReinstallCandidatePtr& mojom_data,
const gfx::ImageSkia& skia_icon,
const gfx::ImageSkia& app_icon,
Observer* observer)
: observer_(observer), package_name_(mojom_data->package_name) {
DCHECK(observer_);
......@@ -38,8 +70,10 @@ ArcAppReinstallAppResult::ArcAppReinstallAppResult(
SetIsRecommendation(true);
set_relevance(kAppReinstallRelevance);
SetNotifyVisibilityChange(true);
SetIcon(skia_icon);
SetChipIcon(skia_icon);
const gfx::ImageSkia masked_app_icon(ApplyBackgroundAndMask(app_icon));
SetIcon(masked_app_icon);
SetChipIcon(masked_app_icon);
SetBadgeIcon(CreateBadgeIcon(vector_icons::kCloudDownloadIcon));
SetNotifyVisibilityChange(true);
if (mojom_data->star_rating != 0.0f) {
......
......@@ -169,11 +169,19 @@ void RecordUmaResponseParseResult(arc::mojom::AppReinstallState result) {
UMA_HISTOGRAM_ENUMERATION("Apps.AppListRecommendedResponse", result);
}
// Limits icon size to be downloaded with FIFE. The input |icon_dimension| is in
// dip and the FIFE requires pixel value. Thus, we need to multiply
// |icon_dimension| with the maximum device scale factor to avoid potential
// issues.
std::string LimitIconSizeWithFife(const std::string& icon_url,
int icon_dimension) {
// We append a suffix to icon url
DCHECK_GT(icon_dimension, 0);
return base::StrCat({icon_url, "=s", base::NumberToString(icon_dimension)});
// Maximum device scale factor (DSF).
static const int kMaxDeviceScaleFactor = 3;
// We append a suffix to icon url
return base::StrCat(
{icon_url, "=s",
base::NumberToString(icon_dimension * kMaxDeviceScaleFactor)});
}
} // namespace
......
......@@ -51,11 +51,11 @@ void UrlIconSource::StartIconFetch() {
semantics {
sender: "URL Icon Source"
description:
"Chrome OS downloads an icon for a web store result."
"Chrome OS downloads an app icon for display in the app list."
trigger:
"When a user initiates a web store search and views results. "
"An icon/image needs to be downloaded to be displayed."
data:
"URL of the icon. "
"URL of the icon/image. "
"No user information is sent."
destination: WEBSITE
}
......@@ -99,11 +99,8 @@ void UrlIconSource::OnSimpleLoaderComplete(
}
void UrlIconSource::OnImageDecoded(const SkBitmap& decoded_image) {
icon_ = gfx::ImageSkiaOperations::CreateResizedImage(
gfx::ImageSkia::CreateFrom1xBitmap(decoded_image),
skia::ImageOperations::RESIZE_BEST,
gfx::Size(icon_size_, icon_size_));
const float scale = decoded_image.width() / icon_size_;
icon_ = gfx::ImageSkia(gfx::ImageSkiaRep(decoded_image, scale));
icon_loaded_callback_.Run();
}
......
......@@ -23,6 +23,7 @@
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/canvas_image_source.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/render_text.h"
#include "ui/views/border.h"
......@@ -69,44 +70,6 @@ void PlaceholderImageSource::Draw(gfx::Canvas* canvas) {
corner_radius, corner_radius, flags);
}
////////////////////////////////////////////////////////////////////////////////
// EncircledImageSource:
class EncircledImageSource : public gfx::CanvasImageSource {
public:
EncircledImageSource(int radius, SkColor color, const gfx::ImageSkia& image);
~EncircledImageSource() override = default;
// gfx::CanvasImageSource:
void Draw(gfx::Canvas* canvas) override;
private:
const int radius_;
const SkColor color_;
const gfx::ImageSkia image_;
DISALLOW_COPY_AND_ASSIGN(EncircledImageSource);
};
EncircledImageSource::EncircledImageSource(int radius,
SkColor color,
const gfx::ImageSkia& image)
: gfx::CanvasImageSource(gfx::Size(radius * 2, radius * 2)),
radius_(radius),
color_(color),
image_(image) {}
void EncircledImageSource::Draw(gfx::Canvas* canvas) {
cc::PaintFlags flags;
flags.setAntiAlias(true);
flags.setStyle(cc::PaintFlags::kFill_Style);
flags.setColor(color_);
canvas->DrawCircle(gfx::Point(radius_, radius_), radius_, flags);
const int x = radius_ - image_.width() / 2;
const int y = radius_ - image_.height() / 2;
canvas->DrawImageInt(image_, x, y);
}
////////////////////////////////////////////////////////////////////////////////
// RoundedCornerImageView:
......@@ -184,7 +147,7 @@ void OmniboxMatchCellView::OnMatchUpdate(const OmniboxResultView* result_view,
answer_image_view_->SetImageSize(
gfx::Size(kAnswerImageSize, kAnswerImageSize));
answer_image_view_->SetImage(
gfx::CanvasImageSource::MakeImageSkia<EncircledImageSource>(
gfx::ImageSkiaOperations::CreateImageWithCircleBackground(
kAnswerImageSize / 2, gfx::kGoogleBlue600, icon));
};
if (match.type == AutocompleteMatchType::CALCULATOR) {
......
......@@ -21,6 +21,7 @@ aggregate_vector_icons("components_vector_icons") {
"check_circle.icon",
"close.icon",
"close_rounded.icon",
"cloud_download.icon",
"code.icon",
"content_paste.icon",
"cookie.icon",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
CANVAS_DIMENSIONS, 24,
MOVE_TO, 17.92f, 10.02f,
CUBIC_TO, 17.45f, 7.18f, 14.97f, 5, 12, 5,
CUBIC_TO, 9.82f, 5, 7.83f, 6.18f, 6.78f, 8.06f,
CUBIC_TO, 4.09f, 8.41f, 2, 10.74f, 2, 13.5f,
CUBIC_TO, 2, 16.53f, 4.47f, 19, 7.5f, 19,
R_H_LINE_TO, 10,
R_CUBIC_TO, 2.48f, 0, 4.5f, -2.02f, 4.5f, -4.5f,
R_CUBIC_TO, 0, -2.34f, -1.79f, -4.27f, -4.08f, -4.48f,
CLOSE,
MOVE_TO, 17.5f, 17,
R_H_LINE_TO, -10,
CUBIC_TO, 5.57f, 17, 4, 15.43f, 4, 13.5f,
R_CUBIC_TO, 0, -1.89f, 1.54f, -3.46f, 3.44f, -3.49f,
R_LINE_TO, 0.64f, -0.01f,
R_LINE_TO, 0.26f, -0.59f,
CUBIC_TO, 8.97f, 7.94f, 10.41f, 7, 12, 7,
R_CUBIC_TO, 2.21f, 0, 4, 1.79f, 4, 4,
R_V_LINE_TO, 1,
R_H_LINE_TO, 1.5f,
R_CUBIC_TO, 1.38f, 0, 2.5f, 1.12f, 2.5f, 2.5f,
CUBIC_TO_SHORTHAND, 18.88f, 17, 17.5f, 17,
CLOSE,
R_MOVE_TO, -3.41f, -5.91f,
R_LINE_TO, 1.41f, 1.41f,
R_LINE_TO, -2.79f, 2.79f,
LINE_TO, 12, 16,
R_LINE_TO, -0.71f, -0.71f,
LINE_TO, 8.5f, 12.5f,
R_LINE_TO, 1.41f, -1.41f,
LINE_TO, 11, 12.17f,
V_LINE_TO, 9.5f,
R_H_LINE_TO, 2,
R_V_LINE_TO, 2.67f,
R_LINE_TO, 1.09f, -1.08f,
CLOSE
......@@ -499,6 +499,38 @@ class ColorMaskSource : public gfx::ImageSkiaSource {
DISALLOW_COPY_AND_ASSIGN(ColorMaskSource);
};
// Image source to create an image with a circle background.
class ImageWithCircleBackgroundSource : public gfx::CanvasImageSource {
public:
ImageWithCircleBackgroundSource(int radius,
SkColor color,
const gfx::ImageSkia& image)
: gfx::CanvasImageSource(gfx::Size(radius * 2, radius * 2)),
radius_(radius),
color_(color),
image_(image) {}
~ImageWithCircleBackgroundSource() override = default;
// gfx::CanvasImageSource:
void Draw(gfx::Canvas* canvas) override {
cc::PaintFlags flags;
flags.setAntiAlias(true);
flags.setStyle(cc::PaintFlags::kFill_Style);
flags.setColor(color_);
canvas->DrawCircle(gfx::Point(radius_, radius_), radius_, flags);
const int x = radius_ - image_.width() / 2;
const int y = radius_ - image_.height() / 2;
canvas->DrawImageInt(image_, x, y);
}
private:
const int radius_;
const SkColor color_;
const gfx::ImageSkia image_;
DISALLOW_COPY_AND_ASSIGN(ImageWithCircleBackgroundSource);
};
} // namespace
// static
......@@ -664,4 +696,14 @@ ImageSkia ImageSkiaOperations::CreateColorMask(const ImageSkia& image,
return ImageSkia(std::make_unique<ColorMaskSource>(image, color),
image.size());
}
ImageSkia ImageSkiaOperations::CreateImageWithCircleBackground(
int radius,
SkColor color,
const ImageSkia& image) {
DCHECK_GE(radius * 2, image.width());
DCHECK_GE(radius * 2, image.height());
return gfx::CanvasImageSource::MakeImageSkia<ImageWithCircleBackgroundSource>(
radius, color, image);
}
} // namespace gfx
......@@ -113,6 +113,12 @@ class GFX_EXPORT ImageSkiaOperations {
// The image must use the kARGB_8888_Config config.
static ImageSkia CreateColorMask(const gfx::ImageSkia& image, SkColor color);
// Creates an image with a circle background. |color| and |radius| is the
// color and radius of the circle background.
static ImageSkia CreateImageWithCircleBackground(int radius,
SkColor color,
const ImageSkia& image);
private:
ImageSkiaOperations(); // Class for scoping only.
};
......
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