Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: chrome/common/icon_with_badge_image_source.cc

Issue 1472863004: [MD] re-skin extension browser action badges (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: undo file move Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/common/icon_with_badge_image_source.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "chrome/common/icon_with_badge_image_source.h"
6
7 #include <algorithm>
8
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"
13
14 IconWithBadgeImageSource::Badge::Badge(const std::string& text,
15 SkColor text_color,
16 SkColor background_color)
17 : text(text), text_color(text_color), background_color(background_color) {}
18
19 IconWithBadgeImageSource::Badge::~Badge() {}
20
21 IconWithBadgeImageSource::IconWithBadgeImageSource(const gfx::Size& size)
22 : gfx::CanvasImageSource(size, false),
23 grayscale_(false),
24 paint_decoration_(false) {
25 }
26
27 IconWithBadgeImageSource::~IconWithBadgeImageSource() {
28 }
29
30 void IconWithBadgeImageSource::SetIcon(const gfx::Image& icon) {
31 icon_ = icon;
32 }
33
34 void IconWithBadgeImageSource::SetBadge(scoped_ptr<Badge> badge) {
35 badge_ = badge.Pass();
36 }
37
38 void IconWithBadgeImageSource::Draw(gfx::Canvas* canvas) {
39 if (icon_.IsEmpty())
40 return;
41
42 int x_offset = std::floor((size().width() - icon_.Width()) / 2.0);
43 int y_offset = std::floor((size().height() - icon_.Height()) / 2.0);
44 gfx::ImageSkia skia = icon_.AsImageSkia();
45 if (grayscale_)
46 skia = gfx::ImageSkiaOperations::CreateHSLShiftedImage(skia, {-1, 0, 0.6});
47 canvas->DrawImageInt(skia, x_offset, y_offset);
48
49 // Draw a badge on the provided browser action icon's canvas.
50 // TODO(devlin): Pull PaintBadge() into here.
51 if (badge_) {
52 badge_util::PaintBadge(canvas, gfx::Rect(size()), badge_->text,
53 badge_->text_color, badge_->background_color,
54 size().width());
55 }
56
57 if (paint_decoration_)
58 PaintDecoration(canvas);
59 }
60
61 void IconWithBadgeImageSource::PaintDecoration(gfx::Canvas* canvas) {
62 static const SkColor decoration_color = SkColorSetARGB(255, 70, 142, 226);
63
64 int major_radius = std::ceil(size().width() / 5.0);
65 int minor_radius = std::ceil(major_radius / 2.0);
66 gfx::Point center_point(major_radius + 1,
67 size().height() - (major_radius) - 1);
68 SkPaint paint;
69 paint.setAntiAlias(true);
70 paint.setStyle(SkPaint::kFill_Style);
71 paint.setColor(SK_ColorTRANSPARENT);
72 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
73 canvas->DrawCircle(center_point,
74 major_radius,
75 paint);
76 paint.setColor(decoration_color);
77 canvas->DrawCircle(center_point,
78 minor_radius,
79 paint);
80 }
81
OLDNEW
« no previous file with comments | « chrome/common/icon_with_badge_image_source.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698