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.h" |
13 #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" | 14 #include "chrome/browser/profiles/profile_info_cache.h" |
15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
16 #include "chrome/browser/profiles/profile_metrics.h" | 16 #include "chrome/browser/profiles/profile_metrics.h" |
17 #include "chrome/browser/profiles/profile_shortcut_manager_win.h" | |
17 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_commands.h" | 19 #include "chrome/browser/ui/browser_commands.h" |
19 #include "chrome/browser/ui/views/frame/browser_view.h" | 20 #include "chrome/browser/ui/views/frame/browser_view.h" |
20 #include "chrome/browser/ui/views/profiles/avatar_menu_bubble_view.h" | 21 #include "chrome/browser/ui/views/profiles/avatar_menu_bubble_view.h" |
21 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" | 22 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" |
22 #include "components/signin/core/common/profile_management_switches.h" | 23 #include "components/signin/core/common/profile_management_switches.h" |
23 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
24 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
25 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
26 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 | 89 |
89 void AvatarMenuButton::SetAvatarIcon(const gfx::Image& icon, | 90 void AvatarMenuButton::SetAvatarIcon(const gfx::Image& icon, |
90 bool is_rectangle) { | 91 bool is_rectangle) { |
91 icon_.reset(new gfx::Image(icon)); | 92 icon_.reset(new gfx::Image(icon)); |
92 button_icon_ = gfx::ImageSkia(); | 93 button_icon_ = gfx::ImageSkia(); |
93 is_rectangle_ = is_rectangle; | 94 is_rectangle_ = is_rectangle; |
94 SchedulePaint(); | 95 SchedulePaint(); |
95 } | 96 } |
96 | 97 |
97 // static | 98 // static |
98 void AvatarMenuButton::GetAvatarImages(Profile* profile, | 99 void AvatarMenuButton::GetAvatarImages(Profile* profile, |
noms (inactive)
2014/10/30 17:39:08
I wonder if this belongs in profile_avatar_icon_ut
Roger Tawa OOO till Jul 10th
2014/10/31 19:44:39
The OTR windows *do* care about badging. OTR wind
| |
99 gfx::Image* avatar, | 100 gfx::Image* avatar, |
100 gfx::Image* taskbar_badge_avatar, | 101 gfx::Image* taskbar_badge_avatar, |
101 bool *is_rectangle) { | 102 bool *is_rectangle) { |
102 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 103 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
103 if (profile->GetProfileType() == Profile::GUEST_PROFILE) { | 104 if (profile->GetProfileType() == Profile::GUEST_PROFILE) { |
104 *avatar = rb. | 105 *avatar = rb. |
105 GetImageNamed(profiles::GetPlaceholderAvatarIconResourceID()); | 106 GetImageNamed(profiles::GetPlaceholderAvatarIconResourceID()); |
106 } else if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE) { | 107 } else if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE) { |
107 *avatar = rb.GetImageNamed(IDR_OTR_ICON); | 108 *avatar = rb.GetImageNamed(IDR_OTR_ICON); |
108 // TODO(nkostylev): Allow this on ChromeOS once the ChromeOS test | 109 // TODO(nkostylev): Allow this on ChromeOS once the ChromeOS test |
109 // environment handles profile directories correctly. | 110 // environment handles profile directories correctly. |
110 #if !defined(OS_CHROMEOS) | 111 #if defined(OS_WIN) |
111 bool is_badge_rectangle = false; | |
112 // The taskbar badge should be the profile avatar, not the OTR avatar. | 112 // The taskbar badge should be the profile avatar, not the OTR avatar. |
113 AvatarMenu::GetImageForMenuButton(profile, | 113 if (switches::IsNewAvatarMenu()) { |
114 taskbar_badge_avatar, | 114 ProfileShortcutManagerWin::GetBadgingAvatarImages( |
noms (inactive)
2014/10/30 17:39:08
I don't think this should do different things base
Roger Tawa OOO till Jul 10th
2014/10/31 19:44:39
Done.
| |
115 &is_badge_rectangle); | 115 g_browser_process->profile_manager(), profile->GetPath(), |
116 taskbar_badge_avatar, NULL); | |
117 } else { | |
118 bool is_badge_rectangle = false; | |
119 AvatarMenu::GetImageForMenuButton(profile, | |
120 taskbar_badge_avatar, | |
121 &is_badge_rectangle); | |
122 } | |
116 #endif | 123 #endif |
117 } else if (AvatarMenu::ShouldShowAvatarMenu()) { | 124 } else if (AvatarMenu::ShouldShowAvatarMenu()) { |
118 ProfileInfoCache& cache = | 125 ProfileInfoCache& cache = |
119 g_browser_process->profile_manager()->GetProfileInfoCache(); | 126 g_browser_process->profile_manager()->GetProfileInfoCache(); |
120 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 127 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
121 if (index == std::string::npos) | 128 if (index == std::string::npos) |
122 return; | 129 return; |
123 | 130 |
124 if (switches::IsNewAvatarMenu()) { | 131 if (switches::IsNewAvatarMenu()) { |
125 *avatar = cache.GetAvatarIconOfProfileAtIndex(index); | 132 *avatar = cache.GetAvatarIconOfProfileAtIndex(index); |
133 #if defined(OS_WIN) | |
134 ProfileShortcutManagerWin::GetBadgingAvatarImages( | |
135 g_browser_process->profile_manager(), profile->GetPath(), | |
136 taskbar_badge_avatar, NULL); | |
137 #endif | |
126 } else { | 138 } else { |
127 AvatarMenu::GetImageForMenuButton(profile, avatar, is_rectangle); | 139 AvatarMenu::GetImageForMenuButton(profile, avatar, is_rectangle); |
128 } | 140 } |
129 } | 141 } |
130 } | 142 } |
131 | 143 |
132 // views::ViewTargeterDelegate: | 144 // views::ViewTargeterDelegate: |
133 bool AvatarMenuButton::DoesIntersectRect(const views::View* target, | 145 bool AvatarMenuButton::DoesIntersectRect(const views::View* target, |
134 const gfx::Rect& rect) const { | 146 const gfx::Rect& rect) const { |
135 CHECK_EQ(target, this); | 147 CHECK_EQ(target, this); |
136 return !disabled_ && | 148 return !disabled_ && |
137 views::ViewTargeterDelegate::DoesIntersectRect(target, rect); | 149 views::ViewTargeterDelegate::DoesIntersectRect(target, rect); |
138 } | 150 } |
139 | 151 |
140 // views::MenuButtonListener implementation | 152 // views::MenuButtonListener implementation |
141 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, | 153 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, |
142 const gfx::Point& point) { | 154 const gfx::Point& point) { |
143 if (!disabled_) | 155 if (!disabled_) |
144 chrome::ShowAvatarMenu(browser_); | 156 chrome::ShowAvatarMenu(browser_); |
145 } | 157 } |
OLD | NEW |