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 a12c75925e7d6adefd011775ea476978e88d15f2..ccea35aec6e88d6330c1ed4d8f25f1a78a8cc8a3 100644 |
--- a/chrome/browser/ui/views/avatar_menu_button.cc |
+++ b/chrome/browser/ui/views/avatar_menu_button.cc |
@@ -10,13 +10,13 @@ |
#include "chrome/browser/ui/views/frame/browser_view.h" |
#include "ui/gfx/canvas_skia.h" |
#include "views/widget/widget.h" |
+#include "skia/ext/image_operations.h" |
#if defined(OS_WIN) |
#include <shobjidl.h> |
#include "base/win/scoped_comptr.h" |
#include "base/win/windows_version.h" |
-#include "skia/ext/image_operations.h" |
#include "ui/gfx/icon_util.h" |
#endif |
@@ -31,6 +31,7 @@ static inline int Round(double x) { |
// See http://msdn.microsoft.com/en-us/library/dd391696(VS.85).aspx for |
// more information. |
void DrawTaskBarDecoration(const Browser* browser, const SkBitmap* bitmap) { |
+ return; |
#if defined(OS_WIN) && !defined(USE_AURA) |
if (base::win::GetVersion() < base::win::VERSION_WIN7) |
return; |
@@ -100,26 +101,68 @@ void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { |
if (icon.isNull()) |
return; |
- // Scale the image to fit the width of the button. |
- 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; |
- |
- // 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()); |
- // Round here so that we minimize the aspect ratio drift. |
- 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(icon, 0, 0, icon.width(), icon.height(), |
- dst_x, dst_y, dst_width, dst_height, false); |
+ if (icon.width() != icon.height()) { |
+ // Scale the image to fit the width of the button. |
+ 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; |
+ |
+ // 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()); |
+ // Round here so that we minimize the aspect ratio drift. |
+ 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(icon, 0, 0, icon.width(), icon.height(), |
+ dst_x, dst_y, dst_width, dst_height, false); |
+ } else { |
+ int dst_width = 28; |
+ int dst_x = (width() - dst_width) / 2 + 2; |
+ int dst_height = 28; |
+ int dst_y = height() - dst_height; |
+ canvas->DrawBitmapInt(icon, 0, 0, icon.width(), icon.height(), |
+ dst_x, dst_y, dst_width, dst_height, false); |
+ |
+ int x1 = dst_x; |
+ int x2 = dst_x + dst_width; |
+ int y1 = dst_y; |
+ int y2 = dst_y + dst_height; |
+ |
+ // Top highlight |
+ canvas->DrawLineInt(SkColorSetARGB(58, 0xff, 0xff, 0xff), |
+ x1, y1, x2, y1); |
+ |
+ // Left Border |
+ canvas->DrawLineInt(SkColorSetARGB(28, 0, 0, 0), |
+ x1, y1 + 1, x1, y2); |
+ |
+ // Right Border |
+ canvas->DrawLineInt(SkColorSetARGB(28, 0, 0, 0), |
+ x2 - 1, y1 + 1, x2 - 1, y2); |
+ |
+ // Dark Shadow Top |
+ canvas->DrawLineInt(SkColorSetARGB(89, 0, 0, 0), |
+ x1 - 1, y1 - 1, x2 + 1, y1 - 1); |
+ canvas->DrawLineInt(SkColorSetARGB(89, 0, 0, 0), |
+ x1 - 1, y1, x1 - 1, y2); |
+ canvas->DrawLineInt(SkColorSetARGB(89, 0, 0, 0), |
+ x2, y1, x2, y2); |
+ |
+ // Light Shadow Top |
+ canvas->DrawLineInt(SkColorSetARGB(29, 0, 0, 0), |
+ x1 - 2, y1 - 2, x2 + 2, y1 - 2); |
+ canvas->DrawLineInt(SkColorSetARGB(29, 0, 0, 0), |
+ x1 - 2, y1 - 1, x1 - 2, y2); |
+ canvas->DrawLineInt(SkColorSetARGB(29, 0, 0, 0), |
+ x2 + 1, y1 - 1, x2 + 1, y2); |
+ } |
if (set_taskbar_decoration_) { |
// Drawing the taskbar decoration uses lanczos resizing so we really |
@@ -137,7 +180,13 @@ bool AvatarMenuButton::HitTest(const gfx::Point& point) const { |
// If the icon changes, we need to set the taskbar decoration again. |
void AvatarMenuButton::SetIcon(const SkBitmap& icon) { |
- views::MenuButton::SetIcon(icon); |
+ if (icon.width() == icon.height()) { |
+ SkBitmap resized_image = skia::ImageOperations::Resize( |
+ icon, skia::ImageOperations::RESIZE_BEST, 28, 28); |
+ views::MenuButton::SetIcon(resized_image); |
+ } else { |
+ views::MenuButton::SetIcon(icon); |
+ } |
set_taskbar_decoration_ = true; |
} |