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