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

Side by Side Diff: chrome/browser/ui/views/avatar_menu_button.cc

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

Powered by Google App Engine
This is Rietveld 408576698