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

[Dice] Use DiceSigninButton in user menu

This CL changes the implementation of the dice sign-in button in the
user menu. Instead of a HoverButton the newly implemented
DiceSigninButton is used.

Changes to DiceSigninButton:
 - The account icon is passed to the constructor.
 - An option to not show the drop down arrow is added.

Bug: 786369
Change-Id: Ideadb6674ebd356374883968eabfd53cba9e1167
Reviewed-on: https://chromium-review.googlesource.com/891319
Commit-Queue: Thomas Tangl <tangltom@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534051}
parent 5b56f01b
......@@ -48,6 +48,7 @@
#include "chrome/browser/ui/views/profiles/badged_profile_photo.h"
#include "chrome/browser/ui/views/profiles/signin_view_controller_delegate_views.h"
#include "chrome/browser/ui/views/profiles/user_manager_view.h"
#include "chrome/browser/ui/views/sync/dice_signin_button.h"
#include "chrome/browser/ui/webui/signin/login_ui_service.h"
#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
#include "chrome/common/pref_names.h"
......@@ -665,9 +666,11 @@ void ProfileChooserView::ButtonPressed(views::Button* sender,
} else if (sender == signin_current_profile_button_) {
ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN);
} else if (sender == signin_with_gaia_account_button_) {
DCHECK(!dice_sync_promo_accounts_.empty());
signin_ui_util::EnableSync(browser_, dice_sync_promo_accounts_[0],
access_point_);
DCHECK(signin_with_gaia_account_button_->account());
Hide();
signin_ui_util::EnableSync(
browser_, signin_with_gaia_account_button_->account().value(),
access_point_);
} else if (sender == sync_to_another_account_button_) {
// Display a submenu listing the GAIA web accounts (without the first one).
std::vector<AccountInfo> accounts(dice_sync_promo_accounts_.begin() + 1,
......@@ -1072,9 +1075,7 @@ views::View* ProfileChooserView::CreateDiceSigninView() {
if (dice_sync_promo_accounts_.empty()) {
// When there is no signed in web account, just display a sign-in button.
signin_current_profile_button_ =
views::MdTextButton::CreateSecondaryUiBlueButton(
this, l10n_util::GetStringUTF16(IDS_PROFILES_DICE_SIGNIN_BUTTON));
signin_current_profile_button_ = new DiceSigninButton(this);
signin_button_view->AddChildView(signin_current_profile_button_);
promo_button_container->AddChildView(signin_button_view);
......@@ -1092,24 +1093,12 @@ views::View* ProfileChooserView::CreateDiceSigninView() {
account_icon = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
profiles::GetPlaceholderAvatarIconResourceID());
}
auto account_photo = std::make_unique<BadgedProfilePhoto>(
BadgedProfilePhoto::BADGE_TYPE_NONE, account_icon);
base::string16 first_account_button_title =
dice_promo_default_account.full_name.empty()
? l10n_util::GetStringUTF16(
IDS_PROFILES_DICE_SIGNIN_FIRST_ACCOUNT_BUTTON_NO_NAME)
: l10n_util::GetStringFUTF16(
IDS_PROFILES_DICE_SIGNIN_FIRST_ACCOUNT_BUTTON,
base::UTF8ToUTF16(dice_promo_default_account.full_name));
HoverButton* first_account_button = new HoverButton(
this, std::move(account_photo), first_account_button_title,
base::UTF8ToUTF16(dice_promo_default_account.email));
first_account_button->SetStyle(HoverButton::STYLE_PROMINENT);
signin_button_view->AddChildView(first_account_button);
promo_button_container->AddChildView(signin_button_view);
signin_with_gaia_account_button_ =
new DiceSigninButton(dice_promo_default_account, account_icon, this,
false /* show drop down arrow */);
signin_with_gaia_account_button_ = first_account_button;
signin_button_view->AddChildView(signin_with_gaia_account_button_);
promo_button_container->AddChildView(signin_button_view);
constexpr int kSmallMenuIconSize = 16;
sync_to_another_account_button_ = new HoverButton(
......
......@@ -35,6 +35,7 @@ class LabelButton;
}
class Browser;
class DiceSigninButton;
// This bubble view is displayed when the user clicks on the avatar button.
// It displays a list of profiles and allows users to switch between profiles.
......@@ -197,8 +198,8 @@ class ProfileChooserView : public content::WebContentsDelegate,
views::Link* manage_accounts_link_;
views::LabelButton* manage_accounts_button_;
views::LabelButton* signin_current_profile_button_;
views::LabelButton* signin_with_gaia_account_button_;
views::LabelButton* sync_to_another_account_button_;
DiceSigninButton* signin_with_gaia_account_button_;
// For material design user menu, the active profile card owns the profile
// name and photo.
......
......@@ -10,11 +10,15 @@
#include "base/logging.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/signin/account_consistency_mode_manager.h"
#include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/signin_ui_util.h"
#include "chrome/browser/ui/views/harmony/chrome_layout_provider.h"
#include "chrome/browser/ui/views/sync/dice_signin_button.h"
#include "components/signin/core/browser/account_tracker_service.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
......@@ -43,8 +47,18 @@ DiceBubbleSyncPromoView::DiceBubbleSyncPromoView(
title->SetMultiLine(true);
AddChildView(title);
signin_button_ = accounts.empty() ? new DiceSigninButton(this)
: new DiceSigninButton(accounts[0], this);
if (accounts.empty()) {
signin_button_ = new DiceSigninButton(this);
} else {
gfx::Image account_icon =
AccountTrackerServiceFactory::GetForProfile(profile)->GetAccountImage(
accounts[0].account_id);
if (account_icon.IsEmpty()) {
account_icon = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
profiles::GetPlaceholderAvatarIconResourceID());
}
signin_button_ = new DiceSigninButton(accounts[0], account_icon, this);
}
AddChildView(signin_button_);
}
......
......@@ -11,7 +11,7 @@
#include "chrome/grit/generated_resources.h"
#include "components/vector_icons/vector_icons.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
......@@ -45,7 +45,9 @@ DiceSigninButton::DiceSigninButton(views::ButtonListener* button_listener)
}
DiceSigninButton::DiceSigninButton(const AccountInfo& account,
views::ButtonListener* button_listener)
const gfx::Image& account_icon,
views::ButtonListener* button_listener,
bool show_drop_down_arrow)
: views::MdTextButton(button_listener, views::style::CONTEXT_BUTTON),
account_(account) {
// First create the child views.
......@@ -55,22 +57,24 @@ DiceSigninButton::DiceSigninButton(const AccountInfo& account,
subtitle_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
AddChildView(subtitle_);
divider_ = new views::View();
divider_->SetBackground(views::CreateSolidBackground(SK_ColorWHITE));
AddChildView(divider_);
arrow_ = new views::ImageButton(button_listener);
arrow_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
views::ImageButton ::ALIGN_MIDDLE);
arrow_->SetInkDropMode(views::InkDropHostView::InkDropMode::ON);
arrow_->set_has_ink_drop_action_on_click(true);
arrow_->SetFocusForPlatform();
arrow_->SetFocusPainter(nullptr);
arrow_->SetImage(
views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kSigninButtonDropDownArrowIcon,
kDropDownArrowIconSize, SK_ColorWHITE));
AddChildView(arrow_);
if (show_drop_down_arrow) {
divider_ = new views::View();
divider_->SetBackground(views::CreateSolidBackground(SK_ColorWHITE));
AddChildView(divider_);
arrow_ = new views::ImageButton(button_listener);
arrow_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
views::ImageButton ::ALIGN_MIDDLE);
arrow_->SetInkDropMode(views::InkDropHostView::InkDropMode::ON);
arrow_->set_has_ink_drop_action_on_click(true);
arrow_->SetFocusForPlatform();
arrow_->SetFocusPainter(nullptr);
arrow_->SetImage(
views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kSigninButtonDropDownArrowIcon,
kDropDownArrowIconSize, SK_ColorWHITE));
AddChildView(arrow_);
}
// Set the title text for main Sign-in button.
base::string16 button_title =
......@@ -86,9 +90,6 @@ DiceSigninButton::DiceSigninButton(const AccountInfo& account,
SetHorizontalAlignment(gfx::ALIGN_LEFT);
// Set the image
gfx::Image account_icon =
ui::ResourceBundle::GetSharedInstance().GetImageNamed(
profiles::GetPlaceholderAvatarIconResourceID());
gfx::Image profile_photo_circular = profiles::GetSizedAvatarIcon(
account_icon, true, 40, 40, profiles::SHAPE_CIRCLE);
SetImage(views::Button::STATE_NORMAL, *profile_photo_circular.ToImageSkia());
......@@ -98,7 +99,7 @@ DiceSigninButton::~DiceSigninButton() = default;
gfx::Rect DiceSigninButton::GetChildAreaBounds() {
gfx::Rect child_area = MdTextButton::GetChildAreaBounds();
if (!account_)
if (!arrow_)
return child_area;
// Make room on the right for the divider and the drop-down arrow.
......@@ -120,11 +121,23 @@ int DiceSigninButton::GetHeightForWidth(int width) const {
}
gfx::Size DiceSigninButton::CalculatePreferredSize() const {
NOTREACHED() << "DiceSigninButton is only used in bubbles that place "
" child views using |GetHeightForWidth|. This method is "
" intentionally not implemented to avoid confusion about "
" the way this button is being layed out.";
return MdTextButton::CalculatePreferredSize();
gfx::Size parent_pref_size = MdTextButton::CalculatePreferredSize();
if (!account_)
return parent_pref_size;
int pref_width = parent_pref_size.width();
if (arrow_) {
// Additional width is needed for the divider and the drop-down arrow.
pref_width += GetDividerAndArrowReservedWidth();
}
// Additional height is needed for the subtitle.
int pref_height_with_subtitle = label()->CalculatePreferredSize().height() +
subtitle_->CalculatePreferredSize().height() +
GetInsets().height();
int pref_height =
std::max(parent_pref_size.height(), pref_height_with_subtitle);
return gfx::Size(pref_width, pref_height);
}
void DiceSigninButton::Layout() {
......@@ -132,7 +145,7 @@ void DiceSigninButton::Layout() {
if (!account_)
return;
// By default, |title| takes the entire height of the button. Shink |title|
// By default, |title| takes the entire height of the button. Shrink |title|
// to make space for |subtitle_|.
views::Label* title = label();
gfx::Size initial_title_size = title->size();
......@@ -148,6 +161,8 @@ void DiceSigninButton::Layout() {
subtitle_->SetBounds(title_x, title->bounds().bottom(), subtitle_width,
subtitle_height);
if (!arrow_)
return;
// Lay the divider and the arrow on the right.
gfx::Rect bounds = GetLocalBounds();
int divider_x = bounds.width() - GetDividerAndArrowReservedWidth() +
......
......@@ -26,9 +26,12 @@ class DiceSigninButton : public views::MdTextButton {
// Creates a sign-in button personalized with the data from |account|.
// |button_listener| will be called for events originating from |this| or from
// |drop_down_arrow|.
// |drop_down_arrow|. The drop down arrow will only be shown when
// |show_drop_down_arrow| is true.
DiceSigninButton(const AccountInfo& account_info,
views::ButtonListener* button_listener);
const gfx::Image& account_icon,
views::ButtonListener* button_listener,
bool show_drop_down_arrow = true);
~DiceSigninButton() override;
const views::Button* drop_down_arrow() const { return arrow_; }
......
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