Commit 79fe037f authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Change ButtonPressed overrides to callbacks: c/b/ui/views/sync/

Bug: 772945
Change-Id: I5c4f19ddc8bbfe9aa4b533d04243ff59bfcf88bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2473587
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Mihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817468}
parent 11d39517
......@@ -54,37 +54,31 @@ DiceBubbleSyncPromoView::DiceBubbleSyncPromoView(
AddChildView(title);
}
views::Button::PressedCallback callback = base::BindRepeating(
[](DiceBubbleSyncPromoView* promo) {
promo->EnableSync(true, promo->signin_button_view_->account());
},
base::Unretained(this));
if (account.IsEmpty()) {
signin_button_view_ =
new DiceSigninButtonView(this, signin_button_prominent);
signin_button_view_ = AddChildView(std::make_unique<DiceSigninButtonView>(
std::move(callback), signin_button_prominent));
} else {
gfx::Image account_icon = account.account_image;
if (account_icon.IsEmpty()) {
account_icon = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
profiles::GetPlaceholderAvatarIconResourceID());
}
signin_button_view_ =
new DiceSigninButtonView(account, account_icon, this,
/*use_account_name_as_title=*/true);
signin_button_view_ = AddChildView(std::make_unique<DiceSigninButtonView>(
account, account_icon, std::move(callback),
/*use_account_name_as_title=*/true));
}
signin_metrics::RecordSigninImpressionUserActionForAccessPoint(access_point);
signin_metrics::RecordSigninImpressionWithAccountUserActionForAccessPoint(
access_point, !account.IsEmpty() /* with_account */);
AddChildView(signin_button_view_);
}
DiceBubbleSyncPromoView::~DiceBubbleSyncPromoView() = default;
void DiceBubbleSyncPromoView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender == signin_button_view_->signin_button()) {
EnableSync(true /* is_default_promo_account */,
signin_button_view_->account());
return;
}
NOTREACHED();
}
views::View* DiceBubbleSyncPromoView::GetSigninButtonForTesting() {
return signin_button_view_ ? signin_button_view_->signin_button() : nullptr;
}
......
......@@ -11,7 +11,6 @@
#include "base/macros.h"
#include "chrome/browser/ui/sync/bubble_sync_promo_delegate.h"
#include "components/signin/public/base/signin_metrics.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/style/typography.h"
#include "ui/views/view.h"
......@@ -26,8 +25,7 @@ class DiceSigninButtonView;
// the user to sign in to Chrome.
// * If Chrome has at least one account, then the promo button is personalized
// with the user full name and avatar icon and allows the user to enable sync.
class DiceBubbleSyncPromoView : public views::View,
public views::ButtonListener {
class DiceBubbleSyncPromoView : public views::View {
public:
// Creates a personalized sync promo view.
// |delegate| is not owned by DiceBubbleSyncPromoView.
......@@ -46,9 +44,6 @@ class DiceBubbleSyncPromoView : public views::View,
int text_style = views::style::STYLE_PRIMARY);
~DiceBubbleSyncPromoView() override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// Returns the sign-in button.
views::View* GetSigninButtonForTesting();
......
......@@ -22,13 +22,13 @@
#include "ui/views/layout/grid_layout.h"
DiceSigninButtonView::DiceSigninButtonView(
views::ButtonListener* button_listener,
views::Button::PressedCallback callback,
bool prominent)
: account_(base::nullopt) {
SetLayoutManager(std::make_unique<views::FillLayout>());
// Regular MD text button when there is no account.
auto button = std::make_unique<views::MdTextButton>(
button_listener,
std::move(callback),
l10n_util::GetStringUTF16(IDS_PROFILES_DICE_SIGNIN_BUTTON));
button->SetProminent(prominent);
signin_button_ = AddChildView(std::move(button));
......@@ -37,7 +37,7 @@ DiceSigninButtonView::DiceSigninButtonView(
DiceSigninButtonView::DiceSigninButtonView(
const AccountInfo& account,
const gfx::Image& account_icon,
views::ButtonListener* button_listener,
views::Button::PressedCallback callback,
bool use_account_name_as_title)
: account_(account) {
views::GridLayout* grid_layout =
......@@ -57,8 +57,8 @@ DiceSigninButtonView::DiceSigninButtonView(
? base::UTF8ToUTF16(account.full_name)
: l10n_util::GetStringUTF16(IDS_PROFILES_DICE_NOT_SYNCING_TITLE);
auto account_card = std::make_unique<HoverButton>(
button_listener, std::move(account_icon_view), card_title,
base::ASCIIToUTF16(account_->email));
views::Button::PressedCallback(), std::move(account_icon_view),
card_title, base::ASCIIToUTF16(account_->email));
account_card->SetBorder(nullptr);
account_card->SetEnabled(false);
grid_layout->AddView(std::move(account_card));
......@@ -70,7 +70,7 @@ DiceSigninButtonView::DiceSigninButtonView(
columns->AddColumn(views::GridLayout::FILL, views::GridLayout::TRAILING, 1.0,
views::GridLayout::ColumnSize::kUsePreferred, 0, 0);
auto signin_button = std::make_unique<views::MdTextButton>(
button_listener,
std::move(callback),
l10n_util::GetStringUTF16(IDS_PROFILES_DICE_SIGNIN_BUTTON));
signin_button->SetProminent(true);
signin_button_ = grid_layout->AddView(std::move(signin_button));
......
......@@ -21,19 +21,17 @@
class DiceSigninButtonView : public views::View {
public:
// Create a non-personalized sign-in button.
// |button_listener| is called every time the user interacts with this button.
// |callback| is called every time the user interacts with this button.
// The button is prominent by default but can be made non-prominent by setting
// |prominent| to false.
explicit DiceSigninButtonView(views::ButtonListener* button_listener,
explicit DiceSigninButtonView(views::Button::PressedCallback callback,
bool prominent = true);
// 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|. The drop down arrow will only be shown if
// |show_drop_down_arrow| is true.
// |callback| is called every time the user interacts with this button.
DiceSigninButtonView(const AccountInfo& account_info,
const gfx::Image& account_icon,
views::ButtonListener* button_listener,
views::Button::PressedCallback callback,
bool use_account_name_as_title = false);
~DiceSigninButtonView() override;
......
......@@ -66,7 +66,10 @@ ProfileSigninConfirmationDialogViews::ProfileSigninConfirmationDialogViews(
if (prompt_for_new_profile) {
SetExtraView(std::make_unique<views::MdTextButton>(
this, l10n_util::GetStringUTF16(IDS_ENTERPRISE_SIGNIN_CONTINUE)));
base::BindRepeating(
&ProfileSigninConfirmationDialogViews::ContinueSigninButtonPressed,
base::Unretained(this)),
l10n_util::GetStringUTF16(IDS_ENTERPRISE_SIGNIN_CONTINUE)));
}
using Delegate = ui::ProfileSigninConfirmationDelegate;
......@@ -246,9 +249,7 @@ void ProfileSigninConfirmationDialogViews::ViewHierarchyChanged(
kPreferredWidth, explanation_label_height);
}
void ProfileSigninConfirmationDialogViews::ButtonPressed(
views::Button* sender,
const ui::Event& event) {
void ProfileSigninConfirmationDialogViews::ContinueSigninButtonPressed() {
DCHECK(prompt_for_new_profile_);
if (delegate_) {
delegate_->OnContinueSignin();
......
......@@ -10,7 +10,6 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/window/dialog_delegate.h"
class Browser;
......@@ -18,8 +17,7 @@ class Profile;
// A tab-modal dialog to allow a user signing in with a managed account
// to create a new Chrome profile.
class ProfileSigninConfirmationDialogViews : public views::DialogDelegateView,
public views::ButtonListener {
class ProfileSigninConfirmationDialogViews : public views::DialogDelegateView {
public:
// Create and show the dialog, which owns itself.
static void ShowDialog(
......@@ -47,8 +45,7 @@ class ProfileSigninConfirmationDialogViews : public views::DialogDelegateView,
void ViewHierarchyChanged(
const views::ViewHierarchyChangedDetails& details) override;
// views::ButtonListener:
void ButtonPressed(views::Button*, const ui::Event& event) override;
void ContinueSigninButtonPressed();
// Called when the "learn more" link is clicked.
void LearnMoreClicked(const ui::Event& event);
......
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