Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / chrome / common / icon_with_badge_image_source.cc
blob1afdbeee9830d53db8b3d4f8cb0e881b1c8afe37
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/common/icon_with_badge_image_source.h"
7 #include <algorithm>
9 #include "chrome/common/badge_util.h"
10 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/geometry/rect.h"
12 #include "ui/gfx/image/image_skia_operations.h"
14 IconWithBadgeImageSource::Badge::Badge(std::string text,
15 SkColor text_color,
16 SkColor background_color)
17 : text(text), text_color(text_color), background_color(background_color) {
20 IconWithBadgeImageSource::Badge::~Badge() {}
22 IconWithBadgeImageSource::IconWithBadgeImageSource(const gfx::Size& size)
23 : gfx::CanvasImageSource(size, false),
24 grayscale_(false),
25 paint_decoration_(false) {
28 IconWithBadgeImageSource::~IconWithBadgeImageSource() {
31 void IconWithBadgeImageSource::SetIcon(const gfx::Image& icon) {
32 icon_ = icon;
35 void IconWithBadgeImageSource::SetBadge(scoped_ptr<Badge> badge) {
36 badge_ = badge.Pass();
39 void IconWithBadgeImageSource::Draw(gfx::Canvas* canvas) {
40 if (icon_.IsEmpty())
41 return;
43 int x_offset = std::floor((size().width() - icon_.Width()) / 2.0);
44 int y_offset = std::floor((size().height() - icon_.Height()) / 2.0);
45 gfx::ImageSkia skia = icon_.AsImageSkia();
46 if (grayscale_)
47 skia = gfx::ImageSkiaOperations::CreateHSLShiftedImage(skia, {-1, 0, 0.6});
48 canvas->DrawImageInt(skia, x_offset, y_offset);
50 // Draw a badge on the provided browser action icon's canvas.
51 // TODO(devlin): Pull PaintBadge() into here.
52 if (badge_) {
53 badge_util::PaintBadge(canvas, gfx::Rect(size()), badge_->text,
54 badge_->text_color, badge_->background_color,
55 size().width());
58 if (paint_decoration_)
59 PaintDecoration(canvas);
62 void IconWithBadgeImageSource::PaintDecoration(gfx::Canvas* canvas) {
63 static const SkColor decoration_color = SkColorSetARGB(255, 70, 142, 226);
65 int major_radius = std::ceil(size().width() / 5.0);
66 int minor_radius = std::ceil(major_radius / 2.0);
67 gfx::Point center_point(major_radius + 1,
68 size().height() - (major_radius) - 1);
69 SkPaint paint;
70 paint.setAntiAlias(true);
71 paint.setStyle(SkPaint::kFill_Style);
72 paint.setColor(SK_ColorTRANSPARENT);
73 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
74 canvas->DrawCircle(center_point,
75 major_radius,
76 paint);
77 paint.setColor(decoration_color);
78 canvas->DrawCircle(center_point,
79 minor_radius,
80 paint);