OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/profiles/avatar_menu_button.h" | 5 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/profiles/avatar_menu.h" | 11 #include "chrome/browser/profiles/avatar_menu.h" |
12 #include "chrome/browser/profiles/profile.h" | |
12 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 13 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
14 #include "chrome/browser/profiles/profile_info_cache.h" | |
15 #include "chrome/browser/profiles/profile_manager.h" | |
13 #include "chrome/browser/profiles/profile_metrics.h" | 16 #include "chrome/browser/profiles/profile_metrics.h" |
14 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_commands.h" | 18 #include "chrome/browser/ui/browser_commands.h" |
16 #include "chrome/browser/ui/views/frame/browser_view.h" | 19 #include "chrome/browser/ui/views/frame/browser_view.h" |
17 #include "chrome/browser/ui/views/profiles/avatar_menu_bubble_view.h" | 20 #include "chrome/browser/ui/views/profiles/avatar_menu_bubble_view.h" |
18 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" | 21 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" |
19 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
20 #include "components/signin/core/common/profile_management_switches.h" | 23 #include "components/signin/core/common/profile_management_switches.h" |
21 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
25 #include "grit/theme_resources.h" | |
26 #include "ui/base/resource/resource_bundle.h" | |
22 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
23 #include "ui/views/view_targeter.h" | 28 #include "ui/views/view_targeter.h" |
24 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
25 | 30 |
26 static inline int Round(double x) { | 31 static inline int Round(double x) { |
27 return static_cast<int>(x + 0.5); | 32 return static_cast<int>(x + 0.5); |
28 } | 33 } |
29 | 34 |
30 // static | 35 // static |
31 const char AvatarMenuButton::kViewClassName[] = "AvatarMenuButton"; | 36 const char AvatarMenuButton::kViewClassName[] = "AvatarMenuButton"; |
32 | 37 |
38 // static | |
39 void AvatarMenuButton::GetAvatarImages(Profile* profile, | |
sky
2014/10/27 14:45:37
This looks platform independent. You should you do
| |
40 gfx::Image* avatar, | |
41 gfx::Image* taskbar_badge_avatar, | |
42 bool *is_rectangle) { | |
43 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
44 if (profile->GetProfileType() == Profile::GUEST_PROFILE) { | |
45 *avatar = rb. | |
46 GetImageNamed(profiles::GetPlaceholderAvatarIconResourceID()); | |
47 } else if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE) { | |
48 *avatar = rb.GetImageNamed(IDR_OTR_ICON); | |
49 // TODO(nkostylev): Allow this on ChromeOS once the ChromeOS test | |
50 // environment handles profile directories correctly. | |
51 #if !defined(OS_CHROMEOS) | |
52 bool is_badge_rectangle = false; | |
53 // The taskbar badge should be the profile avatar, not the OTR avatar. | |
54 AvatarMenu::GetImageForMenuButton(profile, | |
55 taskbar_badge_avatar, | |
56 &is_badge_rectangle); | |
57 #endif | |
58 } else if (AvatarMenu::ShouldShowAvatarMenu()) { | |
59 ProfileInfoCache& cache = | |
60 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
61 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | |
62 if (index == std::string::npos) | |
63 return; | |
64 | |
65 if (switches::IsNewAvatarMenu()) { | |
66 *avatar = cache.GetAvatarIconOfProfileAtIndex(index); | |
67 } else { | |
68 AvatarMenu::GetImageForMenuButton(profile, avatar, is_rectangle); | |
69 } | |
70 } | |
71 } | |
72 | |
33 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool disabled) | 73 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool disabled) |
34 : MenuButton(NULL, base::string16(), this, false), | 74 : MenuButton(NULL, base::string16(), this, false), |
35 browser_(browser), | 75 browser_(browser), |
36 disabled_(disabled), | 76 disabled_(disabled), |
37 is_rectangle_(false), | 77 is_rectangle_(false), |
38 old_height_(0), | 78 old_height_(0), |
39 button_on_right_(false) { | 79 button_on_right_(false) { |
40 // In RTL mode, the avatar icon should be looking the opposite direction. | 80 // In RTL mode, the avatar icon should be looking the opposite direction. |
41 EnableCanvasFlippingForRTLUI(true); | 81 EnableCanvasFlippingForRTLUI(true); |
42 | 82 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 return !disabled_ && | 137 return !disabled_ && |
98 views::ViewTargeterDelegate::DoesIntersectRect(target, rect); | 138 views::ViewTargeterDelegate::DoesIntersectRect(target, rect); |
99 } | 139 } |
100 | 140 |
101 // views::MenuButtonListener implementation | 141 // views::MenuButtonListener implementation |
102 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, | 142 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, |
103 const gfx::Point& point) { | 143 const gfx::Point& point) { |
104 if (!disabled_) | 144 if (!disabled_) |
105 chrome::ShowAvatarMenu(browser_); | 145 chrome::ShowAvatarMenu(browser_); |
106 } | 146 } |
OLD | NEW |