Skip to content

Commit

Permalink
Add icon background to promise icons
Browse files Browse the repository at this point in the history
Bug: b:304383596
Change-Id: I9ab30adf9cd40f321d1a9c2e719ab7bd4a8e5b9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4953505
Reviewed-by: Toni Barzic <tbarzic@chromium.org>
Commit-Queue: Ana Salazar <anasalazar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1213074}
  • Loading branch information
Ana Salazar authored and Chromium LUCI CQ committed Oct 21, 2023
1 parent 6b490dc commit 79371c8
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions ash/app_list/views/app_list_item_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/gfx/geometry/transform_util.h"
Expand Down Expand Up @@ -110,6 +111,9 @@ constexpr float kDragDropAppIconScale = 1.2f;
constexpr float kPromiseIconScalePending = 24.0f / 36.0f;
constexpr float kPromiseIconScaleInstalling = 28.0f / 36.0f;

// The amount of space between the progress ring and the promise app background.
constexpr gfx::Insets kProgressRingMargin = gfx::Insets(-2);

// The drag and drop icon scaling up or down animation transition duration.
constexpr int kDragDropAppIconScaleTransitionInMs = 200;

Expand Down Expand Up @@ -191,6 +195,44 @@ class ClippedFolderIconImageSource : public gfx::CanvasImageSource {
const gfx::ImageSkia image_;
};

// Draws a circular background for a promise icon view.
class PromiseIconBackground : public views::Background {
public:
PromiseIconBackground(ui::ColorId color_id,
const gfx::Rect& icon_bounds,
const gfx::Insets& insets)
: color_id_(color_id), icon_bounds_(icon_bounds), insets_(insets) {}

PromiseIconBackground(const PromiseIconBackground&) = delete;
PromiseIconBackground& operator=(const PromiseIconBackground&) = delete;
~PromiseIconBackground() override = default;

// views::Background:
void Paint(gfx::Canvas* canvas, views::View* view) const override {
gfx::Rect bounds = icon_bounds_;
bounds.Inset(insets_);

const float radius =
std::min(bounds.size().width(), bounds.size().height()) / 2.f;

cc::PaintFlags flags;
flags.setAntiAlias(true);
flags.setColor(get_color());

canvas->DrawCircle(bounds.CenterPoint(), radius, flags);
}

void OnViewThemeChanged(views::View* view) override {
SetNativeControlColor(view->GetColorProvider()->GetColor(color_id_));
view->SchedulePaint();
}

private:
const ui::ColorId color_id_;
const gfx::Rect icon_bounds_;
const gfx::Insets insets_;
};

// Draws a dot with no shadow.
class DotView : public views::View {
public:
Expand Down Expand Up @@ -1913,15 +1955,17 @@ void AppListItemView::UpdateProgressRingBounds() {

CHECK(!is_folder_);

gfx::Size progress_indicator_size = app_list_config_->grid_icon_size();
const gfx::Size progress_indicator_size =
gfx::ScaleToRoundedSize(app_list_config_->grid_icon_size(), icon_scale_);

const gfx::Rect progress_bounds = GetIconBoundsForTargetViewBounds(
app_list_config_, rect,
gfx::ScaleToRoundedSize(progress_indicator_size, icon_scale_),
icon_scale_);
app_list_config_, rect, progress_indicator_size, icon_scale_);
progress_indicator_->layer()->SetBounds(progress_bounds);
layer()->StackAtBottom(progress_indicator_->layer());
progress_indicator_->InvalidateLayer();

SetBackground(std::make_unique<PromiseIconBackground>(
cros_tokens::kCrosSysSystemOnBase, progress_bounds, kProgressRingMargin));
}

void AppListItemView::SetBackgroundExtendedState(bool extend_icon,
Expand Down

0 comments on commit 79371c8

Please sign in to comment.