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

Unified Diff: chrome/common/icon_with_badge_image_source.cc

Issue 1214243003: [Extensions UI] Clean up extension icon generation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/skia/ImageSkia Created 5 years, 5 months 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 side-by-side diff with in-line comments
Download patch
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());
+ }
}

Powered by Google App Engine
This is Rietveld 408576698