Commit f250ade2 authored by Peter Boström's avatar Peter Boström Committed by Commit Bot

Additional icon fixes for avatar toolbar button

This change:

* Displays the generic avatar icon instead of profile icon when there's
  only one non-signed-in user. This matches the current AvatarButton
  behavior.
* Displays the guest badge instead of the generic avatar icon when the
  user is in guest mode.
* Replaces the avatar icon getter to use entry->GetAvatarIcon() instead
  of AvatarMenu::GetImageForMenuButton. The image retrieved for
  MenuButton was non-square and didn't fill the entire circle icon. Now
  the avatar profile icon is instead cropped and fills the circle. This
  matches the icons displayed in ProfileChooserView.

Bug: chromium:822070
Change-Id: I3599ca708e7f866d9c2f437f33c0d8cc141f5c13
Reviewed-on: https://chromium-review.googlesource.com/1026093Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Commit-Queue: Peter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553370}
parent ace6726b
......@@ -12,9 +12,11 @@
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/grit/generated_resources.h"
#include "components/signin/core/browser/signin_manager.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/models/menu_model.h"
......@@ -33,6 +35,7 @@ AvatarToolbarButton::AvatarToolbarButton(Profile* profile,
SetImageAlignment(HorizontalAlignment::ALIGN_CENTER,
VerticalAlignment::ALIGN_MIDDLE);
set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON |
ui::EF_MIDDLE_MOUSE_BUTTON);
set_tag(IDC_SHOW_AVATAR_MENU);
......@@ -52,29 +55,7 @@ AvatarToolbarButton::AvatarToolbarButton(Profile* profile,
AvatarToolbarButton::~AvatarToolbarButton() = default;
void AvatarToolbarButton::UpdateIcon() {
const bool is_touch =
ui::MaterialDesignController::IsTouchOptimizedUiEnabled();
// TODO(pbos): Move these constants to LayoutProvider or LayoutConstants.
const int icon_size = is_touch ? 24 : 20;
const SkColor icon_color =
GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON);
gfx::Image avatar_icon;
if (IsIncognito()) {
SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kIncognitoIcon, icon_size, icon_color));
} else if (AvatarMenu::GetImageForMenuButton(profile_->GetPath(),
&avatar_icon) ==
AvatarMenu::ImageLoadStatus::LOADED) {
avatar_icon = profiles::GetSizedAvatarIcon(
avatar_icon, true, icon_size, icon_size, profiles::SHAPE_CIRCLE);
SetImage(views::Button::STATE_NORMAL, avatar_icon.ToImageSkia());
} else {
SetImage(
views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kUserAccountAvatarIcon, icon_size, icon_color));
}
SetImage(views::Button::STATE_NORMAL, GetAvatarIcon());
}
void AvatarToolbarButton::UpdateTooltipText() {
......@@ -109,3 +90,62 @@ void AvatarToolbarButton::OnProfileNameChanged(
bool AvatarToolbarButton::IsIncognito() const {
return profile_->IsOffTheRecord() && !profile_->IsGuestSession();
}
bool AvatarToolbarButton::ShouldShowGenericIcon() const {
return g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetNumberOfProfiles() == 1 &&
!SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated();
}
gfx::ImageSkia AvatarToolbarButton::GetAvatarIcon() const {
const bool is_touch =
ui::MaterialDesignController::IsTouchOptimizedUiEnabled();
// TODO(pbos): Move these constants to LayoutProvider or LayoutConstants.
const int icon_size = is_touch ? 24 : 20;
const SkColor icon_color =
GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON);
if (IsIncognito())
return gfx::CreateVectorIcon(kIncognitoIcon, icon_size, icon_color);
if (profile_->IsGuestSession())
return gfx::CreateVectorIcon(kUserMenuGuestIcon, icon_size, icon_color);
gfx::Image avatar_icon;
if (!ShouldShowGenericIcon())
avatar_icon = GetIconImageFromProfile();
if (!avatar_icon.IsEmpty()) {
return profiles::GetSizedAvatarIcon(avatar_icon, true, icon_size, icon_size,
profiles::SHAPE_CIRCLE)
.AsImageSkia();
}
return gfx::CreateVectorIcon(kUserAccountAvatarIcon, icon_size, icon_color);
}
gfx::Image AvatarToolbarButton::GetIconImageFromProfile() const {
ProfileAttributesEntry* entry;
if (!g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetProfileAttributesWithPath(profile_->GetPath(), &entry)) {
// This can happen if the user deletes the current profile.
return gfx::Image();
}
// If there is a GAIA image available, try to use that.
if (entry->IsUsingGAIAPicture()) {
// TODO(chengx): The GetGAIAPicture API call will trigger an async image
// load from disk if it has not been loaded. This is non-obvious and
// dependency should be avoided. We should come with a better idea to handle
// this.
const gfx::Image* gaia_image = entry->GetGAIAPicture();
if (gaia_image)
return *gaia_image;
return gfx::Image();
}
return entry->GetAvatarIcon();
}
......@@ -34,6 +34,9 @@ class AvatarToolbarButton : public ToolbarButton,
const base::string16& old_profile_name) override;
bool IsIncognito() const;
bool ShouldShowGenericIcon() const;
gfx::ImageSkia GetAvatarIcon() const;
gfx::Image GetIconImageFromProfile() const;
Profile* const profile_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment