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

[profile-menu] Add profile shortcut feature buttons

The "Manage profiles" button is added as a profile shortcut
feature button.

Screenshot:
https://drive.google.com/file/d/14OgB985dHUyEM18_peTN1dheH9fHnx7k/view?usp=sharing

Flag: profile-menu-revamp

Bug: 995720
Change-Id: I5860c248945bc3e567f8d917320d86055c36fd71
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1811219
Commit-Queue: Thomas Tangl <tangltom@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697967}
parent 0e48ae0b
......@@ -511,20 +511,19 @@ void ProfileMenuView::BuildSelectableProfiles() {
}
void ProfileMenuView::BuildProfileFeatureButtons() {
constexpr float kIconToImageRatio = 0.75;
AddProfileShortcutFeatureButton(
ImageForMenu(vector_icons::kSettingsIcon, /*icon_to_image_ratio=*/0.625),
l10n_util::GetStringUTF16(IDS_PROFILES_MANAGE_USERS_BUTTON),
base::BindRepeating(&ProfileMenuView::OnManageProfilesButtonClicked,
base::Unretained(this)));
constexpr float kIconToImageRatio = 0.75;
AddProfileFeatureButton(
ImageForMenu(kUserMenuGuestIcon, kIconToImageRatio),
l10n_util::GetStringUTF16(IDS_PROFILES_OPEN_GUEST_PROFILE_BUTTON),
base::BindRepeating(&ProfileMenuView::OnGuestProfileButtonClicked,
base::Unretained(this)));
AddProfileFeatureButton(
ImageForMenu(vector_icons::kSettingsIcon, kIconToImageRatio),
l10n_util::GetStringUTF16(IDS_PROFILES_MANAGE_USERS_BUTTON),
base::BindRepeating(&ProfileMenuView::OnManageProfilesButtonClicked,
base::Unretained(this)));
AddProfileFeatureButton(
ImageForMenu(kAddIcon, kIconToImageRatio),
l10n_util::GetStringUTF16(IDS_ADD_USER_BUTTON),
......
......@@ -71,8 +71,9 @@ gfx::ImageSkia ColorImage(const gfx::ImageSkia& image, SkColor color) {
std::unique_ptr<views::BoxLayout> CreateBoxLayout(
views::BoxLayout::Orientation orientation,
views::BoxLayout::CrossAxisAlignment cross_axis_alignment) {
auto layout = std::make_unique<views::BoxLayout>(orientation);
views::BoxLayout::CrossAxisAlignment cross_axis_alignment,
gfx::Insets insets = gfx::Insets()) {
auto layout = std::make_unique<views::BoxLayout>(orientation, insets);
layout->set_cross_axis_alignment(cross_axis_alignment);
return layout;
}
......@@ -366,6 +367,29 @@ void ProfileMenuViewBase::AddSelectableProfile(const gfx::Image& image,
RegisterClickAction(button, std::move(action));
}
void ProfileMenuViewBase::AddProfileShortcutFeatureButton(
const gfx::ImageSkia& icon,
const base::string16& text,
base::RepeatingClosure action) {
constexpr int kIconSize = 28;
// Initialize layout if this is the first time a button is added.
if (!profile_shortcut_features_container_->GetLayoutManager()) {
profile_shortcut_features_container_->SetLayoutManager(
CreateBoxLayout(views::BoxLayout::Orientation::kHorizontal,
views::BoxLayout::CrossAxisAlignment::kCenter,
gfx::Insets(0, 0, 0, /*right=*/kMenuEdgeMargin)));
}
views::Button* button = profile_shortcut_features_container_->AddChildView(
std::make_unique<HoverButton>(this, SizeImage(icon, kIconSize),
base::string16()));
button->SetTooltipText(text);
button->SetBorder(nullptr);
RegisterClickAction(button, std::move(action));
}
void ProfileMenuViewBase::AddProfileFeatureButton(
const gfx::ImageSkia& icon,
const base::string16& text,
......@@ -488,6 +512,7 @@ void ProfileMenuViewBase::Reset() {
views::BoxLayout::Orientation::kVertical));
// Create and add new component containers in the correct order.
// First, add the bordered box with the identity and feature buttons.
auto bordered_box_container = std::make_unique<views::View>();
identity_info_container_ =
bordered_box_container->AddChildView(std::make_unique<views::View>());
......@@ -499,9 +524,20 @@ void ProfileMenuViewBase::Reset() {
bordered_box_container->AddChildView(std::make_unique<views::View>());
components->AddChildView(
CreateBorderedBoxView(std::move(bordered_box_container)));
// Second, add the profile header.
auto profile_header = std::make_unique<views::View>();
views::BoxLayout* profile_header_layout =
profile_header->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal));
profile_heading_container_ =
components->AddChildView(std::make_unique<views::View>());
profile_header->AddChildView(std::make_unique<views::View>());
profile_header_layout->SetFlexForView(profile_heading_container_, 1);
profile_shortcut_features_container_ =
profile_header->AddChildView(std::make_unique<views::View>());
profile_header_layout->SetFlexForView(profile_shortcut_features_container_,
0);
components->AddChildView(std::move(profile_header));
// Third, add the profile buttons at the bottom.
selectable_profiles_container_ =
components->AddChildView(std::make_unique<views::View>());
profile_features_container_ =
......
......@@ -111,6 +111,9 @@ class ProfileMenuViewBase : public content::WebContentsDelegate,
void AddSelectableProfile(const gfx::Image& image,
const base::string16& name,
base::RepeatingClosure action);
void AddProfileShortcutFeatureButton(const gfx::ImageSkia& icon,
const base::string16& text,
base::RepeatingClosure action);
void AddProfileFeatureButton(const gfx::ImageSkia& icon,
const base::string16& text,
base::RepeatingClosure action);
......@@ -226,6 +229,7 @@ class ProfileMenuViewBase : public content::WebContentsDelegate,
views::View* account_features_container_ = nullptr;
views::View* profile_heading_container_ = nullptr;
views::View* selectable_profiles_container_ = nullptr;
views::View* profile_shortcut_features_container_ = nullptr;
views::View* profile_features_container_ = nullptr;
CloseBubbleOnTabActivationHelper close_bubble_helper_;
......
......@@ -674,10 +674,10 @@ class ProfileMenuClickTest_MultipleProfiles : public ProfileMenuClickTest {
ProfileMenuView::ActionableItem::kCreditCardsButton,
ProfileMenuView::ActionableItem::kAddressesButton,
ProfileMenuView::ActionableItem::kSigninButton,
ProfileMenuView::ActionableItem::kManageProfilesButton,
ProfileMenuView::ActionableItem::kOtherProfileButton,
ProfileMenuView::ActionableItem::kOtherProfileButton,
ProfileMenuView::ActionableItem::kGuestProfileButton,
ProfileMenuView::ActionableItem::kManageProfilesButton,
ProfileMenuView::ActionableItem::kAddNewProfileButton,
ProfileMenuView::ActionableItem::kExitProfileButton,
// The first button is added again to finish the cycle and test that
......@@ -722,8 +722,8 @@ class ProfileMenuClickTest_WithPrimaryAccount : public ProfileMenuClickTest {
ProfileMenuView::ActionableItem::kCreditCardsButton,
ProfileMenuView::ActionableItem::kAddressesButton,
ProfileMenuView::ActionableItem::kManageGoogleAccountButton,
ProfileMenuView::ActionableItem::kGuestProfileButton,
ProfileMenuView::ActionableItem::kManageProfilesButton,
ProfileMenuView::ActionableItem::kGuestProfileButton,
ProfileMenuView::ActionableItem::kAddNewProfileButton,
ProfileMenuView::ActionableItem::kExitProfileButton,
// The first button is added again to finish the cycle and test that
......@@ -774,8 +774,8 @@ class ProfileMenuClickTest_WithUnconsentedPrimaryAccount
ProfileMenuView::ActionableItem::kSigninAccountButton,
ProfileMenuView::ActionableItem::kManageGoogleAccountButton,
ProfileMenuView::ActionableItem::kSignoutButton,
ProfileMenuView::ActionableItem::kGuestProfileButton,
ProfileMenuView::ActionableItem::kManageProfilesButton,
ProfileMenuView::ActionableItem::kGuestProfileButton,
ProfileMenuView::ActionableItem::kAddNewProfileButton,
ProfileMenuView::ActionableItem::kExitProfileButton,
// The first button is added again to finish the cycle and test that
......
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