Chromium Code Reviews| Index: chrome/browser/ui/views/avatar_menu_button.cc |
| =================================================================== |
| --- chrome/browser/ui/views/avatar_menu_button.cc (revision 98713) |
| +++ chrome/browser/ui/views/avatar_menu_button.cc (working copy) |
| @@ -11,14 +11,62 @@ |
| #include "ui/gfx/canvas_skia.h" |
| #include "views/widget/widget.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 |
| + |
| static inline int Round(double x) { |
| return static_cast<int>(x + 0.5); |
| } |
| +// The Windows 7 taskbar supports dynamic overlays and effects, we use this |
| +// to ovelay the avatar icon there. The overlay only applies if the taskbar |
| +// is in "default large icon mode". This function is a best effort deal so |
| +// 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& avatar) { |
| +#if defined(OS_WIN) |
| + if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| + return; |
| + |
| + base::win::ScopedComPtr<ITaskbarList3> taskbar; |
| + HRESULT result = taskbar.CreateInstance(CLSID_TaskbarList, NULL, |
|
Peter Kasting
2011/08/31 16:59:46
Nit: Shorter:
if (FAILED(taskbar.CreateInstance
|
| + CLSCTX_INPROC_SERVER); |
| + if (FAILED(result)) |
| + return; |
| + result = taskbar->HrInit(); |
| + if (FAILED(result)) |
| + return; |
| + BrowserWindow* bw = browser->window(); |
|
Peter Kasting
2011/08/31 16:59:46
Nit: Do we really need to check window() and GetNa
|
| + if (!bw) |
| + return; |
| + gfx::NativeWindow window = bw->GetNativeHandle(); |
| + if (!window) |
| + return; |
| + // Since the target size is so small, we use our best resizer. |
| + SkBitmap sk_icon = skia::ImageOperations::Resize( |
| + avatar, |
| + skia::ImageOperations::RESIZE_LANCZOS3, |
| + 16, 16); |
| + HICON icon = IconUtil::CreateHICONFromSkBitmap(sk_icon); |
| + if (!icon) |
| + return; |
| + taskbar->SetOverlayIcon(window, icon, L""); |
| + ::DestroyIcon(icon); |
|
Peter Kasting
2011/08/31 16:59:46
Nit: I think you can get away without :: here
|
| +#endif |
| +} |
| + |
| AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu) |
| : MenuButton(NULL, std::wstring(), this, false), |
| browser_(browser), |
| - has_menu_(has_menu) { |
| + has_menu_(has_menu), |
| + first_time_(true) { |
| // In RTL mode, the avatar icon should be looking the opposite direction. |
| EnableCanvasFlippingForRTLUI(true); |
| } |
| @@ -50,6 +98,13 @@ |
| canvas->DrawBitmapInt(icon, 0, 0, icon.width(), icon.height(), |
| dst_x, dst_y, dst_width, dst_height, false); |
| + |
| + if (first_time_) { |
|
Peter Kasting
2011/08/31 16:59:46
Nit: Sounds like this variable should be named |sh
|
| + // Drawing the taskbar decoration uses lanczos resizing so we really |
| + // want to do it only once. |
| + DrawTaskBarDecoration(browser_, icon); |
| + first_time_ = false; |
| + } |
| } |
| bool AvatarMenuButton::HitTest(const gfx::Point& point) const { |