Commit de0865cf authored by Thomas Tangl's avatar Thomas Tangl Committed by Commit Bot

[profile-menu] Always show heading

... for regular profiles.

Additionally:
 - Make heading clickable and link to 'Edit person' page.
 - Remove identity title when profile is not signed-in.
 - Add horizontal margin to identity text.

Screenshot:
https://drive.google.com/file/d/1y4ewSqp2Uw3c4DFH3HgwspOS8a4u0i5C/view?usp=sharing
https://drive.google.com/file/d/1IK4tjzTewrTd-Ane9forYL377538IvBL/view?usp=sharing

Bug: 995720
Change-Id: I608fdc7a6d6aec31def7f8bfde1f9ef355c4de16
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1868876Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Thomas Tangl <tangltom@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707391}
parent fa018c93
......@@ -427,10 +427,12 @@ void ProfileMenuView::BuildIdentity() {
ProfileAttributesEntry* profile_attributes =
GetProfileAttributesEntry(profile);
base::string16 heading;
SetHeading(profile_attributes->GetLocalProfileName(),
l10n_util::GetStringUTF16(IDS_SETTINGS_EDIT_PERSON),
base::BindRepeating(&ProfileMenuView::OnEditProfileButtonClicked,
base::Unretained(this)));
if (account_info.has_value()) {
heading = profile_attributes->GetLocalProfileName();
SetIdentityInfo(account_info.value().account_image.AsImageSkia(),
GetSyncIcon(),
base::UTF8ToUTF16(account_info.value().full_name),
......@@ -438,15 +440,9 @@ void ProfileMenuView::BuildIdentity() {
} else {
SetIdentityInfo(
profile_attributes->GetAvatarIcon().AsImageSkia(), GetSyncIcon(),
profile_attributes->GetName(),
/*title=*/base::string16(),
l10n_util::GetStringUTF16(IDS_PROFILES_LOCAL_PROFILE_STATE));
}
SetHeading(heading,
ImageForMenu(vector_icons::kEditIcon, kShortcutIconToImageRatio),
l10n_util::GetStringUTF16(IDS_SETTINGS_EDIT_PERSON),
base::BindRepeating(&ProfileMenuView::OnEditProfileButtonClicked,
base::Unretained(this)));
}
void ProfileMenuView::BuildGuestIdentity() {
......
......@@ -250,7 +250,6 @@ ProfileMenuViewBase::~ProfileMenuViewBase() {
}
void ProfileMenuViewBase::SetHeading(const base::string16& heading,
const gfx::ImageSkia& clickable_icon,
const base::string16& tooltip_text,
base::RepeatingClosure action) {
constexpr int kInsidePadding = 4;
......@@ -259,46 +258,29 @@ void ProfileMenuViewBase::SetHeading(const base::string16& heading,
ui::NativeTheme::kColorId_HighlightedMenuItemBackgroundColor);
heading_container_->RemoveAllChildViews(/*delete_children=*/true);
views::BoxLayout* heading_layout = heading_container_->SetLayoutManager(
CreateBoxLayout(views::BoxLayout::Orientation::kHorizontal,
views::BoxLayout::CrossAxisAlignment::kCenter,
gfx::Insets(kInsidePadding)));
if (!heading.empty()) {
heading_container_->SetBackground(
views::CreateSolidBackground(kBackgroundColor));
}
heading_container_->SetLayoutManager(std::make_unique<views::FillLayout>());
heading_container_->SetBackground(
views::CreateSolidBackground(kBackgroundColor));
heading_container_->SetBorder(
views::CreateEmptyBorder(gfx::Insets(kInsidePadding)));
// Add the label even if |heading| is empty. This needs to be done so the icon
// button gets pushed to the right.
views::Label* label =
heading_container_->AddChildView(std::make_unique<views::Label>(
heading, views::style::CONTEXT_LABEL, STYLE_HINT));
label->SetHandlesTooltips(false);
// Stretch the label.
heading_layout->SetFlexForView(label, 1);
// Add icon button.
views::Button* button =
heading_container_->AddChildView(CreateCircularImageButton(
this, clickable_icon, tooltip_text, /*show_border=*/false));
// Don't stretch the button, so it only takes the space it needs.
heading_layout->SetFlexForView(button, 0);
RegisterClickAction(button, std::move(action));
// Center the label by adding a left padding.
button->SizeToPreferredSize();
int left_label_padding = button->GetContentsBounds().width();
label->SetBorder(
views::CreateEmptyBorder(gfx::Insets(0, left_label_padding, 0, 0)));
views::Link* link =
heading_container_->AddChildView(std::make_unique<views::Link>(heading));
link->SetEnabledColor(views::style::GetColor(
*this, views::style::CONTEXT_LABEL, views::style::STYLE_SECONDARY));
link->SetTooltipText(tooltip_text);
link->set_listener(this);
RegisterClickAction(link, std::move(action));
}
void ProfileMenuViewBase::SetIdentityInfo(const gfx::ImageSkia& image,
const gfx::ImageSkia& badge,
const base::string16& title,
const base::string16& subtitle) {
constexpr int kTopMargin = 16;
constexpr int kBottomMargin = 8;
constexpr int kImageToLabelSpacing = 4;
constexpr int kTopMargin = kMenuEdgeMargin;
constexpr int kBottomMargin = kDefaultVerticalMargin;
constexpr int kHorizontalMargin = kMenuEdgeMargin;
constexpr int kImageBottomMargin = 8;
constexpr int kBadgeSize = 16;
constexpr int kBadgePadding = 1;
......@@ -306,7 +288,8 @@ void ProfileMenuViewBase::SetIdentityInfo(const gfx::ImageSkia& image,
identity_info_container_->SetLayoutManager(
CreateBoxLayout(views::BoxLayout::Orientation::kVertical,
views::BoxLayout::CrossAxisAlignment::kCenter,
gfx::Insets(kTopMargin, 0, kBottomMargin, 0)));
gfx::Insets(kTopMargin, kHorizontalMargin, kBottomMargin,
kHorizontalMargin)));
views::ImageView* image_view = identity_info_container_->AddChildView(
std::make_unique<views::ImageView>());
......@@ -323,12 +306,12 @@ void ProfileMenuViewBase::SetIdentityInfo(const gfx::ImageSkia& image,
gfx::ImageSkia badged_image =
gfx::ImageSkiaOperations::CreateIconWithBadge(sized_image, sized_badge);
image_view->SetImage(badged_image);
image_view->SetBorder(views::CreateEmptyBorder(0, 0, kImageBottomMargin, 0));
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 (!title.empty()) {
identity_info_container_->AddChildView(std::make_unique<views::Label>(
title, views::style::CONTEXT_DIALOG_TITLE));
}
if (!subtitle.empty()) {
identity_info_container_->AddChildView(std::make_unique<views::Label>(
......
......@@ -121,7 +121,6 @@ class ProfileMenuViewBase : public content::WebContentsDelegate,
// API to build the profile menu.
void SetHeading(const base::string16& heading,
const gfx::ImageSkia& clickable_icon,
const base::string16& tooltip_text,
base::RepeatingClosure action);
void SetIdentityInfo(const gfx::ImageSkia& image,
......
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