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() { ...@@ -427,10 +427,12 @@ void ProfileMenuView::BuildIdentity() {
ProfileAttributesEntry* profile_attributes = ProfileAttributesEntry* profile_attributes =
GetProfileAttributesEntry(profile); 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()) { if (account_info.has_value()) {
heading = profile_attributes->GetLocalProfileName();
SetIdentityInfo(account_info.value().account_image.AsImageSkia(), SetIdentityInfo(account_info.value().account_image.AsImageSkia(),
GetSyncIcon(), GetSyncIcon(),
base::UTF8ToUTF16(account_info.value().full_name), base::UTF8ToUTF16(account_info.value().full_name),
...@@ -438,15 +440,9 @@ void ProfileMenuView::BuildIdentity() { ...@@ -438,15 +440,9 @@ void ProfileMenuView::BuildIdentity() {
} else { } else {
SetIdentityInfo( SetIdentityInfo(
profile_attributes->GetAvatarIcon().AsImageSkia(), GetSyncIcon(), profile_attributes->GetAvatarIcon().AsImageSkia(), GetSyncIcon(),
profile_attributes->GetName(), /*title=*/base::string16(),
l10n_util::GetStringUTF16(IDS_PROFILES_LOCAL_PROFILE_STATE)); 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() { void ProfileMenuView::BuildGuestIdentity() {
......
...@@ -250,7 +250,6 @@ ProfileMenuViewBase::~ProfileMenuViewBase() { ...@@ -250,7 +250,6 @@ ProfileMenuViewBase::~ProfileMenuViewBase() {
} }
void ProfileMenuViewBase::SetHeading(const base::string16& heading, void ProfileMenuViewBase::SetHeading(const base::string16& heading,
const gfx::ImageSkia& clickable_icon,
const base::string16& tooltip_text, const base::string16& tooltip_text,
base::RepeatingClosure action) { base::RepeatingClosure action) {
constexpr int kInsidePadding = 4; constexpr int kInsidePadding = 4;
...@@ -259,46 +258,29 @@ void ProfileMenuViewBase::SetHeading(const base::string16& heading, ...@@ -259,46 +258,29 @@ void ProfileMenuViewBase::SetHeading(const base::string16& heading,
ui::NativeTheme::kColorId_HighlightedMenuItemBackgroundColor); ui::NativeTheme::kColorId_HighlightedMenuItemBackgroundColor);
heading_container_->RemoveAllChildViews(/*delete_children=*/true); heading_container_->RemoveAllChildViews(/*delete_children=*/true);
views::BoxLayout* heading_layout = heading_container_->SetLayoutManager( heading_container_->SetLayoutManager(std::make_unique<views::FillLayout>());
CreateBoxLayout(views::BoxLayout::Orientation::kHorizontal, heading_container_->SetBackground(
views::BoxLayout::CrossAxisAlignment::kCenter, views::CreateSolidBackground(kBackgroundColor));
gfx::Insets(kInsidePadding))); heading_container_->SetBorder(
if (!heading.empty()) { views::CreateEmptyBorder(gfx::Insets(kInsidePadding)));
heading_container_->SetBackground(
views::CreateSolidBackground(kBackgroundColor));
}
// Add the label even if |heading| is empty. This needs to be done so the icon views::Link* link =
// button gets pushed to the right. heading_container_->AddChildView(std::make_unique<views::Link>(heading));
views::Label* label = link->SetEnabledColor(views::style::GetColor(
heading_container_->AddChildView(std::make_unique<views::Label>( *this, views::style::CONTEXT_LABEL, views::style::STYLE_SECONDARY));
heading, views::style::CONTEXT_LABEL, STYLE_HINT)); link->SetTooltipText(tooltip_text);
label->SetHandlesTooltips(false); link->set_listener(this);
// Stretch the label. RegisterClickAction(link, std::move(action));
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)));
} }
void ProfileMenuViewBase::SetIdentityInfo(const gfx::ImageSkia& image, void ProfileMenuViewBase::SetIdentityInfo(const gfx::ImageSkia& image,
const gfx::ImageSkia& badge, const gfx::ImageSkia& badge,
const base::string16& title, const base::string16& title,
const base::string16& subtitle) { const base::string16& subtitle) {
constexpr int kTopMargin = 16; constexpr int kTopMargin = kMenuEdgeMargin;
constexpr int kBottomMargin = 8; constexpr int kBottomMargin = kDefaultVerticalMargin;
constexpr int kImageToLabelSpacing = 4; constexpr int kHorizontalMargin = kMenuEdgeMargin;
constexpr int kImageBottomMargin = 8;
constexpr int kBadgeSize = 16; constexpr int kBadgeSize = 16;
constexpr int kBadgePadding = 1; constexpr int kBadgePadding = 1;
...@@ -306,7 +288,8 @@ void ProfileMenuViewBase::SetIdentityInfo(const gfx::ImageSkia& image, ...@@ -306,7 +288,8 @@ void ProfileMenuViewBase::SetIdentityInfo(const gfx::ImageSkia& image,
identity_info_container_->SetLayoutManager( identity_info_container_->SetLayoutManager(
CreateBoxLayout(views::BoxLayout::Orientation::kVertical, CreateBoxLayout(views::BoxLayout::Orientation::kVertical,
views::BoxLayout::CrossAxisAlignment::kCenter, views::BoxLayout::CrossAxisAlignment::kCenter,
gfx::Insets(kTopMargin, 0, kBottomMargin, 0))); gfx::Insets(kTopMargin, kHorizontalMargin, kBottomMargin,
kHorizontalMargin)));
views::ImageView* image_view = identity_info_container_->AddChildView( views::ImageView* image_view = identity_info_container_->AddChildView(
std::make_unique<views::ImageView>()); std::make_unique<views::ImageView>());
...@@ -323,12 +306,12 @@ void ProfileMenuViewBase::SetIdentityInfo(const gfx::ImageSkia& image, ...@@ -323,12 +306,12 @@ void ProfileMenuViewBase::SetIdentityInfo(const gfx::ImageSkia& image,
gfx::ImageSkia badged_image = gfx::ImageSkia badged_image =
gfx::ImageSkiaOperations::CreateIconWithBadge(sized_image, sized_badge); gfx::ImageSkiaOperations::CreateIconWithBadge(sized_image, sized_badge);
image_view->SetImage(badged_image); image_view->SetImage(badged_image);
image_view->SetBorder(views::CreateEmptyBorder(0, 0, kImageBottomMargin, 0));
views::View* title_label = if (!title.empty()) {
identity_info_container_->AddChildView(std::make_unique<views::Label>( identity_info_container_->AddChildView(std::make_unique<views::Label>(
title, views::style::CONTEXT_DIALOG_TITLE)); title, views::style::CONTEXT_DIALOG_TITLE));
title_label->SetBorder( }
views::CreateEmptyBorder(kImageToLabelSpacing, 0, 0, 0));
if (!subtitle.empty()) { if (!subtitle.empty()) {
identity_info_container_->AddChildView(std::make_unique<views::Label>( identity_info_container_->AddChildView(std::make_unique<views::Label>(
......
...@@ -121,7 +121,6 @@ class ProfileMenuViewBase : public content::WebContentsDelegate, ...@@ -121,7 +121,6 @@ class ProfileMenuViewBase : public content::WebContentsDelegate,
// API to build the profile menu. // API to build the profile menu.
void SetHeading(const base::string16& heading, void SetHeading(const base::string16& heading,
const gfx::ImageSkia& clickable_icon,
const base::string16& tooltip_text, const base::string16& tooltip_text,
base::RepeatingClosure action); base::RepeatingClosure action);
void SetIdentityInfo(const gfx::ImageSkia& image, 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