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

Unified Diff: chrome/browser/ui/views/avatar_menu_button.cc

Issue 8709001: Views: Custom drawing for GAIA avatar pictures (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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/browser/ui/views/avatar_menu_button.cc
diff --git a/chrome/browser/ui/views/avatar_menu_button.cc b/chrome/browser/ui/views/avatar_menu_button.cc
index affbd68e87bb1e201e1fe78b8a0020da13d541af..d8af9c820bcfef91eb260f99881606663f7bc752 100644
--- a/chrome/browser/ui/views/avatar_menu_button.cc
+++ b/chrome/browser/ui/views/avatar_menu_button.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/ui/views/avatar_menu_button.h"
#include "chrome/browser/profiles/profile_metrics.h"
+#include "chrome/browser/profiles/profile_info_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/views/avatar_menu_bubble_view.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
@@ -31,7 +32,7 @@ static inline int Round(double x) {
// we bail out silently at any error condition.
// See http://msdn.microsoft.com/en-us/library/dd391696(VS.85).aspx for
// more information.
-void DrawTaskBarDecoration(const Browser* browser, const SkBitmap* bitmap) {
+void DrawTaskBarDecoration(const Browser* browser, const gfx::Image* image) {
#if defined(OS_WIN) && !defined(USE_AURA)
if (base::win::GetVersion() < base::win::VERSION_WIN7)
return;
@@ -48,13 +49,17 @@ void DrawTaskBarDecoration(const Browser* browser, const SkBitmap* bitmap) {
if (FAILED(result) || FAILED(taskbar->HrInit()))
return;
HICON icon = NULL;
- if (bitmap) {
+ if (image) {
+ const SkBitmap* bitmap = image->ToSkBitmap();
const SkBitmap* source_bitmap = NULL;
SkBitmap squarer_bitmap;
- if ((bitmap->width() == 38) && (bitmap->height() == 31)) {
+ if ((bitmap->width() == profiles::kAvatarIconWidth) &&
+ (bitmap->height() == profiles::kAvatarIconHeight)) {
// Shave a couple of columns so the bitmap is more square. So when
// resized to a square aspect ratio it looks pretty.
- bitmap->extractSubset(&squarer_bitmap, SkIRect::MakeXYWH(2, 0, 34, 31));
+ int x = 2;
Peter Kasting 2011/11/28 22:01:36 Nit: Wouldn't it make more sense to do something l
sail 2011/11/28 23:09:36 I think that's a good idea. I'm working on a separ
+ bitmap->extractSubset(&squarer_bitmap, SkIRect::MakeXYWH(x, 0,
+ profiles::kAvatarIconWidth - x * 2, profiles::kAvatarIconHeight));
source_bitmap = &squarer_bitmap;
} else {
// The bitmaps size has changed. Resize what we have.
@@ -80,7 +85,9 @@ AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu)
: MenuButton(NULL, string16(), this, false),
browser_(browser),
has_menu_(has_menu),
- set_taskbar_decoration_(false) {
+ set_taskbar_decoration_(false),
+ is_gaia_picture_(false),
+ old_height_(0) {
// In RTL mode, the avatar icon should be looking the opposite direction.
EnableCanvasFlippingForRTLUI(true);
}
@@ -94,12 +101,17 @@ AvatarMenuButton::~AvatarMenuButton() {
}
void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) {
- const SkBitmap& icon = GetImageToPaint();
- if (icon.isNull())
+ if (!icon_.get())
return;
+ if (old_height_ != height() || button_icon_.isNull()) {
+ old_height_ = height();
+ button_icon_ = profiles::GetAvatarIconForTitleBar(
+ *icon_, is_gaia_picture_, width(), height());
+ }
+
// Scale the image to fit the width of the button.
- int dst_width = std::min(icon.width(), width());
+ int dst_width = std::min(button_icon_.width(), width());
// Truncate rather than rounding, so that for odd widths we put the extra
// pixel on the left.
int dst_x = (width() - dst_width) / 2;
@@ -107,22 +119,21 @@ void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) {
// Scale the height and maintain aspect ratio. This means that the
// icon may not fit in the view. That's ok, we just vertically center it.
float scale =
- static_cast<float>(dst_width) / static_cast<float>(icon.width());
+ static_cast<float>(dst_width) / static_cast<float>(button_icon_.width());
// Round here so that we minimize the aspect ratio drift.
- int dst_height = Round(icon.height() * scale);
+ int dst_height = Round(button_icon_.height() * scale);
// Round rather than truncating, so that for odd heights we select an extra
// pixel below the image center rather than above. This is because the
// incognito image has shadows at the top that make the apparent center below
// the real center.
int dst_y = Round((height() - dst_height) / 2.0);
-
- canvas->DrawBitmapInt(icon, 0, 0, icon.width(), icon.height(),
- dst_x, dst_y, dst_width, dst_height, false);
+ canvas->DrawBitmapInt(button_icon_, 0, 0, button_icon_.width(),
+ button_icon_.height(), dst_x, dst_y, dst_width, dst_height, false);
if (set_taskbar_decoration_) {
// Drawing the taskbar decoration uses lanczos resizing so we really
// want to do it only once.
- DrawTaskBarDecoration(browser_, &icon);
+ DrawTaskBarDecoration(browser_, icon_.get());
set_taskbar_decoration_ = false;
}
}
@@ -133,9 +144,11 @@ bool AvatarMenuButton::HitTest(const gfx::Point& point) const {
return views::MenuButton::HitTest(point);
}
-// If the icon changes, we need to set the taskbar decoration again.
-void AvatarMenuButton::SetIcon(const SkBitmap& icon) {
- views::MenuButton::SetIcon(icon);
+void AvatarMenuButton::SetIcon(const gfx::Image& icon, bool is_gaia_picture) {
+ icon_.reset(new gfx::Image(icon));
Peter Kasting 2011/11/28 22:01:36 Nit: Why use a scoped_ptr here? Why not just use
sail 2011/11/28 23:09:36 gfx::Image doesn't have a default constructor so i
+ button_icon_ = SkBitmap();
+ is_gaia_picture_ = is_gaia_picture;
+ // If the icon changes, we need to set the taskbar decoration again.
set_taskbar_decoration_ = true;
}

Powered by Google App Engine
This is Rietveld 408576698