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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/icon_with_badge_image_source.h" 5 #include "chrome/common/icon_with_badge_image_source.h"
6 6
7 #include "chrome/common/badge_util.h" 7 #include "chrome/common/badge_util.h"
8 //#include "ui/base/layout.h"
9 #include "ui/gfx/canvas.h" 8 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/geometry/rect.h" 9 #include "ui/gfx/geometry/rect.h"
11 10
12 IconWithBadgeImageSource::IconWithBadgeImageSource( 11 IconWithBadgeImageSource::Badge::Badge(std::string text,
13 const gfx::ImageSkia& icon, 12 SkColor text_color,
14 const gfx::Size& icon_size, 13 SkColor background_color)
15 const gfx::Size& spacing, 14 : text(text), text_color(text_color), background_color(background_color) {
16 const std::string& text,
17 const SkColor& text_color,
18 const SkColor& background_color,
19 extensions::ActionInfo::Type action_type)
20 : gfx::CanvasImageSource(icon_size, false),
21 icon_(icon),
22 spacing_(spacing),
23 text_(text),
24 text_color_(text_color),
25 background_color_(background_color),
26 action_type_(action_type) {
27 } 15 }
28 16
29 IconWithBadgeImageSource::~IconWithBadgeImageSource() {} 17 IconWithBadgeImageSource::Badge::~Badge() {}
18
19 IconWithBadgeImageSource::IconWithBadgeImageSource(const gfx::Size& size)
20 : gfx::CanvasImageSource(size, false) {
21 }
22
23 IconWithBadgeImageSource::~IconWithBadgeImageSource() {
24 }
25
26 void IconWithBadgeImageSource::SetIcon(const gfx::Image& icon) {
27 icon_ = icon;
28 }
29
30 void IconWithBadgeImageSource::SetBadge(scoped_ptr<Badge> badge) {
31 badge_ = badge.Pass();
32 }
30 33
31 void IconWithBadgeImageSource::Draw(gfx::Canvas* canvas) { 34 void IconWithBadgeImageSource::Draw(gfx::Canvas* canvas) {
32 canvas->DrawImageInt(icon_, 0, 0, SkPaint()); 35 if (icon_.IsEmpty())
33 gfx::Rect bounds(size_.width() + spacing_.width(), 36 return;
34 size_.height() + spacing_.height()); 37
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);
35 42
36 // Draw a badge on the provided browser action icon's canvas. 43 // Draw a badge on the provided browser action icon's canvas.
37 badge_util::PaintBadge(canvas, bounds, text_, text_color_, 44 // TODO(devlin): Pull PaintBadge() into here.
38 background_color_, size_.width(), 45 if (badge_) {
39 action_type_); 46 badge_util::PaintBadge(canvas, gfx::Rect(size()), badge_->text,
47 badge_->text_color, badge_->background_color,
48 size().width());
49 }
40 } 50 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698