Commit 0b16ce69 authored by Thomas Tangl's avatar Thomas Tangl Committed by Commit Bot

[profile-menu] Add identity title/subtitle

This is part of the profile menu revamp.

Bug: 995720
Change-Id: Ia81eb5b18c7f8d29e7c14ec42df1e46171afecf3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1786443Reviewed-by: default avatarRamin Halavati <rhalavati@chromium.org>
Commit-Queue: Thomas Tangl <tangltom@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693654}
parent a10285d3
......@@ -72,8 +72,13 @@ void IncognitoMenuView::BuildMenu() {
base::Unretained(this)));
return;
}
SetIdentityImage(
gfx::Image(gfx::CreateVectorIcon(kIncognitoProfileIcon, icon_color)));
SetIdentityInfo(
gfx::Image(gfx::CreateVectorIcon(kIncognitoProfileIcon, icon_color)),
l10n_util::GetStringUTF16(IDS_INCOGNITO_PROFILE_MENU_TITLE),
incognito_window_count > 1
? l10n_util::GetPluralStringFUTF16(IDS_INCOGNITO_WINDOW_COUNT_MESSAGE,
incognito_window_count)
: base::string16());
}
base::string16 IncognitoMenuView::GetAccessibleWindowTitle() const {
......
......@@ -168,7 +168,7 @@ void ProfileMenuView::BuildMenu() {
AddProfileMenuView(avatar_menu_.get());
return;
}
SetIdentity();
BuildIdentity();
}
void ProfileMenuView::OnAvatarMenuChanged(
......@@ -368,7 +368,7 @@ void ProfileMenuView::RecordClick(ActionableItem item) {
base::UmaHistogramEnumeration("Profile.Menu.ClickedActionableItem", item);
}
void ProfileMenuView::SetIdentity() {
void ProfileMenuView::BuildIdentity() {
Profile* profile = browser()->profile();
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile);
......@@ -379,9 +379,15 @@ void ProfileMenuView::SetIdentity() {
account);
if (account_info.has_value()) {
SetIdentityImage(account_info.value().account_image);
SetIdentityInfo(account_info.value().account_image,
base::UTF8ToUTF16(account_info.value().full_name),
base::UTF8ToUTF16(account_info.value().email));
} else {
SetIdentityImage(GetProfileAttributesEntry(profile)->GetAvatarIcon());
ProfileAttributesEntry* profile_attributes =
GetProfileAttributesEntry(profile);
SetIdentityInfo(
profile_attributes->GetAvatarIcon(), profile_attributes->GetName(),
l10n_util::GetStringUTF16(IDS_PROFILES_LOCAL_PROFILE_STATE));
}
}
......
......@@ -98,7 +98,7 @@ class ProfileMenuView : public ProfileMenuViewBase, public AvatarMenuObserver {
static bool close_on_deactivate_for_testing_;
// Helper methods for building the menu.
void SetIdentity();
void BuildIdentity();
// Adds the profile chooser view.
void AddProfileMenuView(AvatarMenu* avatar_menu);
......
......@@ -149,18 +149,33 @@ ProfileMenuViewBase::~ProfileMenuViewBase() {
DCHECK(menu_item_groups_.empty());
}
void ProfileMenuViewBase::SetIdentityImage(const gfx::Image& image) {
identity_image_container_->RemoveAllChildViews(/*delete_children=*/true);
identity_image_container_->SetLayoutManager(
void ProfileMenuViewBase::SetIdentityInfo(const gfx::Image& image,
const base::string16& title,
const base::string16& subtitle) {
constexpr int kImageToLabelSpacing = 4;
identity_info_container_->RemoveAllChildViews(/*delete_children=*/true);
identity_info_container_->SetLayoutManager(
CreateBoxLayout(views::BoxLayout::Orientation::kVertical,
views::BoxLayout::CrossAxisAlignment::kCenter));
views::ImageView* image_view = identity_image_container_->AddChildView(
views::ImageView* image_view = identity_info_container_->AddChildView(
std::make_unique<views::ImageView>());
image_view->SetImage(profiles::GetSizedAvatarIcon(
image, /*is_rectangle=*/true, kIdentityImageSize,
kIdentityImageSize, profiles::SHAPE_CIRCLE)
.AsImageSkia());
views::View* title_label =
identity_info_container_->AddChildView(std::make_unique<views::Label>(
title, views::style::CONTEXT_DIALOG_TITLE));
title_label->SetBorder(
views::CreateEmptyBorder(kImageToLabelSpacing, 0, 0, 0));
if (!subtitle.empty()) {
identity_info_container_->AddChildView(std::make_unique<views::Label>(
subtitle, views::style::CONTEXT_LABEL, views::style::STYLE_SECONDARY));
}
}
ax::mojom::Role ProfileMenuViewBase::GetAccessibleWindowRole() {
......@@ -249,7 +264,7 @@ void ProfileMenuViewBase::Reset() {
views::BoxLayout::Orientation::kVertical));
// Create and add new component containers in the correct order.
identity_image_container_ =
identity_info_container_ =
components->AddChildView(std::make_unique<views::View>());
// Create a scroll view to hold the components.
......
......@@ -94,7 +94,9 @@ class ProfileMenuViewBase : public content::WebContentsDelegate,
virtual void BuildMenu() = 0;
// API to build the profile menu.
void SetIdentityImage(const gfx::Image& image);
void SetIdentityInfo(const gfx::Image& image,
const base::string16& title,
const base::string16& subtitle);
// Initializes a new group of menu items. A separator is added before them if
// |add_separator| is true.
......@@ -193,7 +195,7 @@ class ProfileMenuViewBase : public content::WebContentsDelegate,
std::map<views::View*, base::RepeatingClosure> click_actions_;
// Component containers.
views::View* identity_image_container_ = nullptr;
views::View* identity_info_container_ = nullptr;
CloseBubbleOnTabActivationHelper close_bubble_helper_;
......
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