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

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

Issue 8744010: Revert 112171 - 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
===================================================================
--- chrome/browser/ui/views/avatar_menu_button.cc (revision 112173)
+++ chrome/browser/ui/views/avatar_menu_button.cc (working copy)
@@ -5,7 +5,6 @@
#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"
@@ -32,7 +31,7 @@
// 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 gfx::Image* image) {
+void DrawTaskBarDecoration(const Browser* browser, const SkBitmap* bitmap) {
#if defined(OS_WIN) && !defined(USE_AURA)
if (base::win::GetVersion() < base::win::VERSION_WIN7)
return;
@@ -49,17 +48,13 @@
if (FAILED(result) || FAILED(taskbar->HrInit()))
return;
HICON icon = NULL;
- if (image) {
- const SkBitmap* bitmap = image->ToSkBitmap();
+ if (bitmap) {
const SkBitmap* source_bitmap = NULL;
SkBitmap squarer_bitmap;
- if ((bitmap->width() == profiles::kAvatarIconWidth) &&
- (bitmap->height() == profiles::kAvatarIconHeight)) {
+ if ((bitmap->width() == 38) && (bitmap->height() == 31)) {
// Shave a couple of columns so the bitmap is more square. So when
// resized to a square aspect ratio it looks pretty.
- int x = 2;
- bitmap->extractSubset(&squarer_bitmap, SkIRect::MakeXYWH(x, 0,
- profiles::kAvatarIconWidth - x * 2, profiles::kAvatarIconHeight));
+ bitmap->extractSubset(&squarer_bitmap, SkIRect::MakeXYWH(2, 0, 34, 31));
source_bitmap = &squarer_bitmap;
} else {
// The bitmaps size has changed. Resize what we have.
@@ -85,9 +80,7 @@
: MenuButton(NULL, string16(), this, false),
browser_(browser),
has_menu_(has_menu),
- set_taskbar_decoration_(false),
- is_gaia_picture_(false),
- old_height_(0) {
+ set_taskbar_decoration_(false) {
// In RTL mode, the avatar icon should be looking the opposite direction.
EnableCanvasFlippingForRTLUI(true);
}
@@ -101,17 +94,12 @@
}
void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) {
- if (!icon_.get())
+ const SkBitmap& icon = GetImageToPaint();
+ if (icon.isNull())
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(button_icon_.width(), width());
+ int dst_width = std::min(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;
@@ -119,21 +107,22 @@
// 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>(button_icon_.width());
+ static_cast<float>(dst_width) / static_cast<float>(icon.width());
// Round here so that we minimize the aspect ratio drift.
- int dst_height = Round(button_icon_.height() * scale);
+ int dst_height = Round(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(button_icon_, 0, 0, button_icon_.width(),
- button_icon_.height(), dst_x, dst_y, dst_width, dst_height, false);
+ canvas->DrawBitmapInt(icon, 0, 0, icon.width(), 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_.get());
+ DrawTaskBarDecoration(browser_, &icon);
set_taskbar_decoration_ = false;
}
}
@@ -144,11 +133,9 @@
return views::MenuButton::HitTest(point);
}
-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.
+// If the icon changes, we need to set the taskbar decoration again.
+void AvatarMenuButton::SetIcon(const SkBitmap& icon) {
+ views::MenuButton::SetIcon(icon);
set_taskbar_decoration_ = true;
}
« no previous file with comments | « chrome/browser/ui/views/avatar_menu_button.h ('k') | chrome/browser/ui/views/frame/browser_non_client_frame_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698