| Index: chrome/common/icon_with_badge_image_source.cc
|
| diff --git a/chrome/common/icon_with_badge_image_source.cc b/chrome/common/icon_with_badge_image_source.cc
|
| index d3d785b9fcd8fb33897b86269bf881799bd5ba03..1b699364f879380c32e455050227bb0371f7c51e 100644
|
| --- a/chrome/common/icon_with_badge_image_source.cc
|
| +++ b/chrome/common/icon_with_badge_image_source.cc
|
| @@ -5,36 +5,46 @@
|
| #include "chrome/common/icon_with_badge_image_source.h"
|
|
|
| #include "chrome/common/badge_util.h"
|
| -//#include "ui/base/layout.h"
|
| #include "ui/gfx/canvas.h"
|
| #include "ui/gfx/geometry/rect.h"
|
|
|
| -IconWithBadgeImageSource::IconWithBadgeImageSource(
|
| - const gfx::ImageSkia& icon,
|
| - const gfx::Size& icon_size,
|
| - const gfx::Size& spacing,
|
| - const std::string& text,
|
| - const SkColor& text_color,
|
| - const SkColor& background_color,
|
| - extensions::ActionInfo::Type action_type)
|
| - : gfx::CanvasImageSource(icon_size, false),
|
| - icon_(icon),
|
| - spacing_(spacing),
|
| - text_(text),
|
| - text_color_(text_color),
|
| - background_color_(background_color),
|
| - action_type_(action_type) {
|
| +IconWithBadgeImageSource::Badge::Badge(std::string text,
|
| + SkColor text_color,
|
| + SkColor background_color)
|
| + : text(text), text_color(text_color), background_color(background_color) {
|
| }
|
|
|
| -IconWithBadgeImageSource::~IconWithBadgeImageSource() {}
|
| +IconWithBadgeImageSource::Badge::~Badge() {}
|
| +
|
| +IconWithBadgeImageSource::IconWithBadgeImageSource(const gfx::Size& size)
|
| + : gfx::CanvasImageSource(size, false) {
|
| +}
|
| +
|
| +IconWithBadgeImageSource::~IconWithBadgeImageSource() {
|
| +}
|
| +
|
| +void IconWithBadgeImageSource::SetIcon(const gfx::Image& icon) {
|
| + icon_ = icon;
|
| +}
|
| +
|
| +void IconWithBadgeImageSource::SetBadge(scoped_ptr<Badge> badge) {
|
| + badge_ = badge.Pass();
|
| +}
|
|
|
| void IconWithBadgeImageSource::Draw(gfx::Canvas* canvas) {
|
| - canvas->DrawImageInt(icon_, 0, 0, SkPaint());
|
| - gfx::Rect bounds(size_.width() + spacing_.width(),
|
| - size_.height() + spacing_.height());
|
| + if (icon_.IsEmpty())
|
| + return;
|
| +
|
| + int x_offset = std::floor((size().width() - icon_.Width()) / 2.0);
|
| + int y_offset = std::floor((size().height() - icon_.Height()) / 2.0);
|
| + gfx::ImageSkia skia = icon_.AsImageSkia();
|
| + canvas->DrawImageInt(icon_.AsImageSkia(), x_offset, y_offset);
|
|
|
| // Draw a badge on the provided browser action icon's canvas.
|
| - badge_util::PaintBadge(canvas, bounds, text_, text_color_,
|
| - background_color_, size_.width(),
|
| - action_type_);
|
| + // TODO(devlin): Pull PaintBadge() into here.
|
| + if (badge_) {
|
| + badge_util::PaintBadge(canvas, gfx::Rect(size()), badge_->text,
|
| + badge_->text_color, badge_->background_color,
|
| + size().width());
|
| + }
|
| }
|
|
|