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; |
+ 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)); |
+ 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; |
} |