| 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"; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } | 88 } |
| 84 | 89 |
| 85 void AvatarMenuButton::SetAvatarIcon(const gfx::Image& icon, | 90 void AvatarMenuButton::SetAvatarIcon(const gfx::Image& icon, |
| 86 bool is_rectangle) { | 91 bool is_rectangle) { |
| 87 icon_.reset(new gfx::Image(icon)); | 92 icon_.reset(new gfx::Image(icon)); |
| 88 button_icon_ = gfx::ImageSkia(); | 93 button_icon_ = gfx::ImageSkia(); |
| 89 is_rectangle_ = is_rectangle; | 94 is_rectangle_ = is_rectangle; |
| 90 SchedulePaint(); | 95 SchedulePaint(); |
| 91 } | 96 } |
| 92 | 97 |
| 98 // static |
| 99 void AvatarMenuButton::GetAvatarImages(Profile* profile, |
| 100 gfx::Image* avatar, |
| 101 gfx::Image* taskbar_badge_avatar, |
| 102 bool *is_rectangle) { |
| 103 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 104 if (profile->GetProfileType() == Profile::GUEST_PROFILE) { |
| 105 *avatar = rb. |
| 106 GetImageNamed(profiles::GetPlaceholderAvatarIconResourceID()); |
| 107 } else if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE) { |
| 108 *avatar = rb.GetImageNamed(IDR_OTR_ICON); |
| 109 // TODO(nkostylev): Allow this on ChromeOS once the ChromeOS test |
| 110 // environment handles profile directories correctly. |
| 111 #if !defined(OS_CHROMEOS) |
| 112 bool is_badge_rectangle = false; |
| 113 // The taskbar badge should be the profile avatar, not the OTR avatar. |
| 114 AvatarMenu::GetImageForMenuButton(profile, |
| 115 taskbar_badge_avatar, |
| 116 &is_badge_rectangle); |
| 117 #endif |
| 118 } else if (AvatarMenu::ShouldShowAvatarMenu()) { |
| 119 ProfileInfoCache& cache = |
| 120 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 121 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 122 if (index == std::string::npos) |
| 123 return; |
| 124 |
| 125 if (switches::IsNewAvatarMenu()) { |
| 126 *avatar = cache.GetAvatarIconOfProfileAtIndex(index); |
| 127 } else { |
| 128 AvatarMenu::GetImageForMenuButton(profile, avatar, is_rectangle); |
| 129 } |
| 130 } |
| 131 } |
| 132 |
| 93 // views::ViewTargeterDelegate: | 133 // views::ViewTargeterDelegate: |
| 94 bool AvatarMenuButton::DoesIntersectRect(const views::View* target, | 134 bool AvatarMenuButton::DoesIntersectRect(const views::View* target, |
| 95 const gfx::Rect& rect) const { | 135 const gfx::Rect& rect) const { |
| 96 CHECK_EQ(target, this); | 136 CHECK_EQ(target, this); |
| 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 |