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" |
| 8 #include "chrome/browser/managed_mode.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" |
7 #include "chrome/browser/profiles/avatar_menu_model.h" | 10 #include "chrome/browser/profiles/avatar_menu_model.h" |
8 #include "chrome/browser/profiles/profile_info_util.h" | 11 #include "chrome/browser/profiles/profile_info_util.h" |
9 #include "chrome/browser/profiles/profile_metrics.h" | 12 #include "chrome/browser/profiles/profile_metrics.h" |
10 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" | 14 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" |
12 #include "chrome/browser/ui/views/frame/browser_view.h" | 15 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 16 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "chrome/common/pref_names.h" |
| 18 #include "content/public/browser/notification_service.h" |
13 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
14 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
15 | 21 |
16 | 22 |
17 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
18 #include <shobjidl.h> | 24 #include <shobjidl.h> |
19 #include "base/win/scoped_comptr.h" | 25 #include "base/win/scoped_comptr.h" |
20 #include "base/win/windows_version.h" | 26 #include "base/win/windows_version.h" |
21 #include "skia/ext/image_operations.h" | 27 #include "skia/ext/image_operations.h" |
22 #include "ui/gfx/icon_util.h" | 28 #include "ui/gfx/icon_util.h" |
23 #endif | 29 #endif |
24 | 30 |
25 static inline int Round(double x) { | 31 static inline int Round(double x) { |
26 return static_cast<int>(x + 0.5); | 32 return static_cast<int>(x + 0.5); |
27 } | 33 } |
28 | 34 |
29 // The Windows 7 taskbar supports dynamic overlays and effects, we use this | 35 // The Windows 7 taskbar supports dynamic overlays and effects, we use this |
30 // to ovelay the avatar icon there. The overlay only applies if the taskbar | 36 // to ovelay the avatar icon there. The overlay only applies if the taskbar |
31 // is in "default large icon mode". This function is a best effort deal so | 37 // is in "default large icon mode". This function is a best effort deal so |
32 // we bail out silently at any error condition. | 38 // we bail out silently at any error condition. |
33 // See http://msdn.microsoft.com/en-us/library/dd391696(VS.85).aspx for | 39 // See http://msdn.microsoft.com/en-us/library/dd391696(VS.85).aspx for |
34 // more information. | 40 // more information. |
35 void DrawTaskBarDecoration(gfx::NativeWindow window, const gfx::Image* image) { | 41 void DrawTaskBarDecoration(gfx::NativeWindow window, const gfx::Image* image) { |
36 #if defined(OS_WIN) && !defined(USE_AURA) | 42 #if defined(OS_WIN) && !defined(USE_AURA) |
37 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 43 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
38 return; | 44 return; |
39 // Don't badge the task bar in the single profile case to match the behavior | 45 |
40 // of the title bar. | |
41 if (!AvatarMenuModel::ShouldShowAvatarMenu()) | |
42 return; | |
43 // SetOverlayIcon does nothing if the window is not visible so testing | 46 // SetOverlayIcon does nothing if the window is not visible so testing |
44 // here avoids all the wasted effort of the image resizing. | 47 // here avoids all the wasted effort of the image resizing. |
45 if (!::IsWindowVisible(window)) | 48 if (!::IsWindowVisible(window)) |
46 return; | 49 return; |
47 | 50 |
48 base::win::ScopedComPtr<ITaskbarList3> taskbar; | 51 base::win::ScopedComPtr<ITaskbarList3> taskbar; |
49 HRESULT result = taskbar.CreateInstance(CLSID_TaskbarList, NULL, | 52 HRESULT result = taskbar.CreateInstance(CLSID_TaskbarList, NULL, |
50 CLSCTX_INPROC_SERVER); | 53 CLSCTX_INPROC_SERVER); |
51 if (FAILED(result) || FAILED(taskbar->HrInit())) | 54 if (FAILED(result) || FAILED(taskbar->HrInit())) |
52 return; | 55 return; |
(...skipping 23 matching lines...) Expand all Loading... |
76 icon = IconUtil::CreateHICONFromSkBitmap(sk_icon); | 79 icon = IconUtil::CreateHICONFromSkBitmap(sk_icon); |
77 if (!icon) | 80 if (!icon) |
78 return; | 81 return; |
79 } | 82 } |
80 taskbar->SetOverlayIcon(window, icon, L""); | 83 taskbar->SetOverlayIcon(window, icon, L""); |
81 if (icon) | 84 if (icon) |
82 DestroyIcon(icon); | 85 DestroyIcon(icon); |
83 #endif | 86 #endif |
84 } | 87 } |
85 | 88 |
86 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu) | 89 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool incognito) |
87 : MenuButton(NULL, string16(), this, false), | 90 : MenuButton(NULL, string16(), this, false), |
88 browser_(browser), | 91 browser_(browser), |
89 has_menu_(has_menu), | 92 incognito_(incognito), |
90 is_gaia_picture_(false), | 93 is_gaia_picture_(false), |
91 old_height_(0) { | 94 old_height_(0) { |
92 // In RTL mode, the avatar icon should be looking the opposite direction. | 95 // In RTL mode, the avatar icon should be looking the opposite direction. |
93 EnableCanvasFlippingForRTLUI(true); | 96 EnableCanvasFlippingForRTLUI(true); |
94 } | 97 } |
95 | 98 |
96 AvatarMenuButton::~AvatarMenuButton() { | 99 AvatarMenuButton::~AvatarMenuButton() { |
97 } | 100 } |
98 | 101 |
99 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { | 102 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { |
(...skipping 21 matching lines...) Expand all Loading... |
121 // Round rather than truncating, so that for odd heights we select an extra | 124 // Round rather than truncating, so that for odd heights we select an extra |
122 // pixel below the image center rather than above. This is because the | 125 // pixel below the image center rather than above. This is because the |
123 // incognito image has shadows at the top that make the apparent center below | 126 // incognito image has shadows at the top that make the apparent center below |
124 // the real center. | 127 // the real center. |
125 int dst_y = Round((height() - dst_height) / 2.0); | 128 int dst_y = Round((height() - dst_height) / 2.0); |
126 canvas->DrawBitmapInt(button_icon_, 0, 0, button_icon_.width(), | 129 canvas->DrawBitmapInt(button_icon_, 0, 0, button_icon_.width(), |
127 button_icon_.height(), dst_x, dst_y, dst_width, dst_height, false); | 130 button_icon_.height(), dst_x, dst_y, dst_width, dst_height, false); |
128 } | 131 } |
129 | 132 |
130 bool AvatarMenuButton::HitTest(const gfx::Point& point) const { | 133 bool AvatarMenuButton::HitTest(const gfx::Point& point) const { |
131 if (!has_menu_) | 134 if (incognito_) |
132 return false; | 135 return false; |
133 return views::MenuButton::HitTest(point); | 136 return views::MenuButton::HitTest(point); |
134 } | 137 } |
135 | 138 |
136 void AvatarMenuButton::SetAvatarIcon(const gfx::Image& icon, | 139 void AvatarMenuButton::SetAvatarIcon(const gfx::Image& icon, |
137 bool is_gaia_picture) { | 140 bool is_gaia_picture) { |
138 icon_.reset(new gfx::Image(icon)); | 141 icon_.reset(new gfx::Image(icon)); |
139 button_icon_ = SkBitmap(); | 142 button_icon_ = SkBitmap(); |
140 is_gaia_picture_ = is_gaia_picture; | 143 is_gaia_picture_ = is_gaia_picture; |
141 SchedulePaint(); | 144 SchedulePaint(); |
142 } | 145 } |
143 | 146 |
144 // views::MenuButtonListener implementation | 147 // views::MenuButtonListener implementation |
145 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, | 148 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, |
146 const gfx::Point& point) { | 149 const gfx::Point& point) { |
147 ShowAvatarBubble(); | 150 if (incognito_) |
| 151 return; |
| 152 |
| 153 if (ManagedMode::IsInManagedMode()) |
| 154 ManagedMode::LeaveManagedMode(); |
| 155 else |
| 156 ShowAvatarBubble(); |
148 } | 157 } |
149 | 158 |
150 void AvatarMenuButton::ShowAvatarBubble() { | 159 void AvatarMenuButton::ShowAvatarBubble() { |
151 if (!has_menu_) | 160 DCHECK(!incognito_); |
152 return; | |
153 | 161 |
154 gfx::Point origin; | 162 gfx::Point origin; |
155 views::View::ConvertPointToScreen(this, &origin); | 163 views::View::ConvertPointToScreen(this, &origin); |
156 gfx::Rect bounds(origin, size()); | 164 gfx::Rect bounds(origin, size()); |
157 | 165 |
158 AvatarMenuBubbleView* bubble = new AvatarMenuBubbleView(this, | 166 AvatarMenuBubbleView* bubble = new AvatarMenuBubbleView(this, |
159 views::BubbleBorder::TOP_LEFT, bounds, browser_); | 167 views::BubbleBorder::TOP_LEFT, bounds, browser_); |
160 views::BubbleDelegateView::CreateBubble(bubble); | 168 views::BubbleDelegateView::CreateBubble(bubble); |
161 bubble->Show(); | 169 bubble->Show(); |
162 | 170 |
163 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); | 171 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); |
164 } | 172 } |
OLD | NEW |