OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/avatar_menu_button.h" | 5 #include "chrome/browser/ui/views/avatar_menu_button.h" |
6 | 6 |
7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/command_updater.h" | 8 #include "chrome/browser/command_updater.h" |
9 #include "chrome/browser/managed_mode/managed_mode.h" | 9 #include "chrome/browser/managed_mode/managed_mode.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
11 #include "chrome/browser/profiles/avatar_menu_model.h" | 11 #include "chrome/browser/profiles/avatar_menu_model.h" |
12 #include "chrome/browser/profiles/profile_info_util.h" | 12 #include "chrome/browser/profiles/profile_info_util.h" |
13 #include "chrome/browser/profiles/profile_metrics.h" | 13 #include "chrome/browser/profiles/profile_metrics.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" | 15 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" |
16 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
19 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
20 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
21 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
22 | 22 |
23 | |
24 #if defined(OS_WIN) | |
25 #include <shobjidl.h> | |
26 #include "base/win/scoped_comptr.h" | |
27 #include "base/win/windows_version.h" | |
28 #include "skia/ext/image_operations.h" | |
29 #include "ui/gfx/icon_util.h" | |
30 #endif | |
31 | |
32 static inline int Round(double x) { | 23 static inline int Round(double x) { |
33 return static_cast<int>(x + 0.5); | 24 return static_cast<int>(x + 0.5); |
34 } | 25 } |
35 | 26 |
36 // The Windows 7 taskbar supports dynamic overlays and effects, we use this | |
37 // to ovelay the avatar icon there. The overlay only applies if the taskbar | |
38 // is in "default large icon mode". This function is a best effort deal so | |
39 // we bail out silently at any error condition. | |
40 // See http://msdn.microsoft.com/en-us/library/dd391696(VS.85).aspx for | |
41 // more information. | |
42 void DrawTaskBarDecoration(gfx::NativeWindow window, const gfx::Image* image) { | |
43 #if defined(OS_WIN) && !defined(USE_AURA) | |
44 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
45 return; | |
46 | |
47 // SetOverlayIcon does nothing if the window is not visible so testing | |
48 // here avoids all the wasted effort of the image resizing. | |
49 if (!::IsWindowVisible(window)) | |
50 return; | |
51 | |
52 base::win::ScopedComPtr<ITaskbarList3> taskbar; | |
53 HRESULT result = taskbar.CreateInstance(CLSID_TaskbarList, NULL, | |
54 CLSCTX_INPROC_SERVER); | |
55 if (FAILED(result) || FAILED(taskbar->HrInit())) | |
56 return; | |
57 HICON icon = NULL; | |
58 if (image) { | |
59 const SkBitmap* bitmap = image->ToSkBitmap(); | |
60 const SkBitmap* source_bitmap = NULL; | |
61 SkBitmap squarer_bitmap; | |
62 if ((bitmap->width() == profiles::kAvatarIconWidth) && | |
63 (bitmap->height() == profiles::kAvatarIconHeight)) { | |
64 // Shave a couple of columns so the bitmap is more square. So when | |
65 // resized to a square aspect ratio it looks pretty. | |
66 int x = 2; | |
67 bitmap->extractSubset(&squarer_bitmap, SkIRect::MakeXYWH(x, 0, | |
68 profiles::kAvatarIconWidth - x * 2, profiles::kAvatarIconHeight)); | |
69 source_bitmap = &squarer_bitmap; | |
70 } else { | |
71 // The image's size has changed. Resize what we have. | |
72 source_bitmap = bitmap; | |
73 } | |
74 // Since the target size is so small, we use our best resizer. Never pass | |
75 // windows a different size because it will badly hammer it to 16x16. | |
76 SkBitmap sk_icon = skia::ImageOperations::Resize( | |
77 *source_bitmap, | |
78 skia::ImageOperations::RESIZE_LANCZOS3, | |
79 16, 16); | |
80 icon = IconUtil::CreateHICONFromSkBitmap(sk_icon); | |
81 if (!icon) | |
82 return; | |
83 } | |
84 taskbar->SetOverlayIcon(window, icon, L""); | |
85 if (icon) | |
86 DestroyIcon(icon); | |
87 #endif | |
88 } | |
89 | |
90 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool incognito) | 27 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool incognito) |
91 : MenuButton(NULL, string16(), this, false), | 28 : MenuButton(NULL, string16(), this, false), |
92 browser_(browser), | 29 browser_(browser), |
93 incognito_(incognito), | 30 incognito_(incognito), |
94 is_gaia_picture_(false), | 31 is_gaia_picture_(false), |
95 old_height_(0) { | 32 old_height_(0) { |
96 // In RTL mode, the avatar icon should be looking the opposite direction. | 33 // In RTL mode, the avatar icon should be looking the opposite direction. |
97 EnableCanvasFlippingForRTLUI(true); | 34 EnableCanvasFlippingForRTLUI(true); |
98 } | 35 } |
99 | 36 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 96 |
160 void AvatarMenuButton::ShowAvatarBubble() { | 97 void AvatarMenuButton::ShowAvatarBubble() { |
161 gfx::Point origin; | 98 gfx::Point origin; |
162 views::View::ConvertPointToScreen(this, &origin); | 99 views::View::ConvertPointToScreen(this, &origin); |
163 gfx::Rect bounds(origin, size()); | 100 gfx::Rect bounds(origin, size()); |
164 AvatarMenuBubbleView::ShowBubble(this, views::BubbleBorder::TOP_LEFT, | 101 AvatarMenuBubbleView::ShowBubble(this, views::BubbleBorder::TOP_LEFT, |
165 views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, bounds, browser_); | 102 views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, bounds, browser_); |
166 | 103 |
167 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); | 104 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); |
168 } | 105 } |
OLD | NEW |