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 "chrome/common/badge_util.h"
8 #include "ui/gfx/canvas.h"
9 #include "ui/gfx/geometry/rect.h"
11 IconWithBadgeImageSource::Badge::Badge(std::string text
,
13 SkColor background_color
)
14 : text(text
), text_color(text_color
), background_color(background_color
) {
17 IconWithBadgeImageSource::Badge::~Badge() {}
19 IconWithBadgeImageSource::IconWithBadgeImageSource(const gfx::Size
& size
)
20 : gfx::CanvasImageSource(size
, false) {
23 IconWithBadgeImageSource::~IconWithBadgeImageSource() {
26 void IconWithBadgeImageSource::SetIcon(const gfx::Image
& icon
) {
30 void IconWithBadgeImageSource::SetBadge(scoped_ptr
<Badge
> badge
) {
31 badge_
= badge
.Pass();
34 void IconWithBadgeImageSource::Draw(gfx::Canvas
* canvas
) {
38 int x_offset
= std::floor((size().width() - icon_
.Width()) / 2.0);
39 int y_offset
= std::floor((size().height() - icon_
.Height()) / 2.0);
40 gfx::ImageSkia skia
= icon_
.AsImageSkia();
41 canvas
->DrawImageInt(icon_
.AsImageSkia(), x_offset
, y_offset
);
43 // Draw a badge on the provided browser action icon's canvas.
44 // TODO(devlin): Pull PaintBadge() into here.
46 badge_util::PaintBadge(canvas
, gfx::Rect(size()), badge_
->text
,
47 badge_
->text_color
, badge_
->background_color
,