| 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" | 
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 103   if (profile->GetProfileType() == Profile::GUEST_PROFILE) { | 103   if (profile->GetProfileType() == Profile::GUEST_PROFILE) { | 
| 104     *avatar = rb. | 104     *avatar = rb. | 
| 105         GetImageNamed(profiles::GetPlaceholderAvatarIconResourceID()); | 105         GetImageNamed(profiles::GetPlaceholderAvatarIconResourceID()); | 
| 106   } else if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE) { | 106   } else if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE) { | 
| 107     *avatar = rb.GetImageNamed(IDR_OTR_ICON); | 107     *avatar = rb.GetImageNamed(IDR_OTR_ICON); | 
| 108     // TODO(nkostylev): Allow this on ChromeOS once the ChromeOS test | 108     // TODO(nkostylev): Allow this on ChromeOS once the ChromeOS test | 
| 109     // environment handles profile directories correctly. | 109     // environment handles profile directories correctly. | 
| 110 #if !defined(OS_CHROMEOS) | 110 #if !defined(OS_CHROMEOS) | 
| 111     bool is_badge_rectangle = false; | 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     profiles::GetTransparentBackgroundProfileAvatar( | 
| 114                                       taskbar_badge_avatar, | 114         profile->GetPath(), taskbar_badge_avatar, &is_badge_rectangle); | 
| 115                                       &is_badge_rectangle); |  | 
| 116 #endif | 115 #endif | 
| 117   } else if (AvatarMenu::ShouldShowAvatarMenu()) { | 116   } else if (AvatarMenu::ShouldShowAvatarMenu()) { | 
| 118     ProfileInfoCache& cache = | 117     ProfileInfoCache& cache = | 
| 119         g_browser_process->profile_manager()->GetProfileInfoCache(); | 118         g_browser_process->profile_manager()->GetProfileInfoCache(); | 
| 120     size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 119     size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 
| 121     if (index == std::string::npos) | 120     if (index == std::string::npos) | 
| 122       return; | 121       return; | 
| 123 | 122 | 
| 124     if (switches::IsNewAvatarMenu()) { | 123     if (switches::IsNewAvatarMenu()) { | 
| 125       *avatar = cache.GetAvatarIconOfProfileAtIndex(index); | 124       *avatar = cache.GetAvatarIconOfProfileAtIndex(index); | 
| 126       // TODO(noms): Once the code for the old avatar menu button is removed, | 125       // TODO(noms): Once the code for the old avatar menu button is removed, | 
| 127       // this function will only be called for badging the taskbar icon.  The | 126       // this function will only be called for badging the taskbar icon.  The | 
| 128       // function can be renamed to something like GetAvatarImageForBadging() | 127       // function can be renamed to something like GetAvatarImageForBadging() | 
| 129       // and only needs to return the avatar from | 128       // and only needs to return the avatar from | 
| 130       // AvatarMenu::GetImageForMenuButton(). | 129       // profiles::GetTransparentBackgroundProfileAvatar. | 
| 131 #if !defined(OS_CHROMEOS) | 130 #if !defined(OS_CHROMEOS) | 
| 132       bool is_badge_rectangle = false; | 131       bool is_badge_rectangle = false; | 
| 133       AvatarMenu::GetImageForMenuButton(profile, | 132       profiles::GetTransparentBackgroundProfileAvatar( | 
| 134                                         taskbar_badge_avatar, | 133           profile->GetPath(), taskbar_badge_avatar, &is_badge_rectangle); | 
| 135                                         &is_badge_rectangle); |  | 
| 136 #endif | 134 #endif | 
| 137     } else { | 135     } else { | 
| 138       AvatarMenu::GetImageForMenuButton(profile, avatar, is_rectangle); | 136       profiles::GetTransparentBackgroundProfileAvatar( | 
|  | 137           profile->GetPath(), avatar, is_rectangle); | 
| 139     } | 138     } | 
| 140   } | 139   } | 
| 141 } | 140 } | 
| 142 | 141 | 
| 143 // views::ViewTargeterDelegate: | 142 // views::ViewTargeterDelegate: | 
| 144 bool AvatarMenuButton::DoesIntersectRect(const views::View* target, | 143 bool AvatarMenuButton::DoesIntersectRect(const views::View* target, | 
| 145                                          const gfx::Rect& rect) const { | 144                                          const gfx::Rect& rect) const { | 
| 146   CHECK_EQ(target, this); | 145   CHECK_EQ(target, this); | 
| 147   return !disabled_ && | 146   return !disabled_ && | 
| 148          views::ViewTargeterDelegate::DoesIntersectRect(target, rect); | 147          views::ViewTargeterDelegate::DoesIntersectRect(target, rect); | 
| 149 } | 148 } | 
| 150 | 149 | 
| 151 // views::MenuButtonListener implementation | 150 // views::MenuButtonListener implementation | 
| 152 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, | 151 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, | 
| 153                                            const gfx::Point& point) { | 152                                            const gfx::Point& point) { | 
| 154   if (!disabled_) | 153   if (!disabled_) | 
| 155     chrome::ShowAvatarMenu(browser_); | 154     chrome::ShowAvatarMenu(browser_); | 
| 156 } | 155 } | 
| OLD | NEW | 
|---|