Commit 1331ec22 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

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

Bug: 772945
Change-Id: I29af810a0b850c6e5d267dfa6f725865fe0de835
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2456486
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Vasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815107}
parent 992b7316
......@@ -41,7 +41,7 @@ MigratableCardView::MigratableCardView(
provider->GetDistanceMetric(DISTANCE_CONTENT_LIST_VERTICAL_MULTI)));
AddChildView(GetMigratableCardDescriptionView(migratable_credit_card,
should_show_checkbox, this)
should_show_checkbox)
.release());
checkbox_uncheck_text_container_ = new views::View();
......@@ -73,11 +73,11 @@ MigratableCardView::MigratableCardView(
MigratableCardView::~MigratableCardView() = default;
bool MigratableCardView::IsSelected() {
bool MigratableCardView::IsSelected() const {
return !checkbox_ || checkbox_->GetChecked();
}
std::string MigratableCardView::GetGuid() {
std::string MigratableCardView::GetGuid() const {
return migratable_credit_card_.credit_card().guid();
}
......@@ -86,11 +86,14 @@ base::string16 MigratableCardView::GetCardIdentifierString() const {
.CardIdentifierStringForAutofillDisplay();
}
const char* MigratableCardView::GetClassName() const {
return kViewClassName;
}
std::unique_ptr<views::View>
MigratableCardView::GetMigratableCardDescriptionView(
const MigratableCreditCard& migratable_credit_card,
bool should_show_checkbox,
ButtonListener* listener) {
bool should_show_checkbox) {
auto migratable_card_description_view = std::make_unique<views::View>();
ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
......@@ -112,14 +115,17 @@ MigratableCardView::GetMigratableCardDescriptionView(
switch (migratable_credit_card.migration_status()) {
case MigratableCreditCard::MigrationStatus::UNKNOWN: {
if (should_show_checkbox) {
checkbox_ = new views::Checkbox(base::string16(), listener);
checkbox_ = migratable_card_description_view->AddChildView(
std::make_unique<views::Checkbox>(
base::string16(),
base::BindRepeating(&MigratableCardView::CheckboxPressed,
base::Unretained(this))));
checkbox_->SetChecked(true);
// TODO(crbug/867194): Currently the ink drop animation circle is
// cropped by the border of scroll bar view. Find a way to adjust the
// format.
checkbox_->SetInkDropMode(views::InkDropHostView::InkDropMode::OFF);
checkbox_->SetAssociatedLabel(card_description.get());
migratable_card_description_view->AddChildView(checkbox_);
}
break;
}
......@@ -183,7 +189,14 @@ MigratableCardView::GetMigratableCardDescriptionView(
views::style::CONTEXT_LABEL, ChromeTextStyle::STYLE_RED));
auto delete_card_from_local_button =
views::CreateVectorImageButtonWithNativeTheme(listener, kTrashCanIcon);
views::CreateVectorImageButtonWithNativeTheme(
base::BindRepeating(
[](LocalCardMigrationDialogView* parent_dialog,
std::string guid) {
parent_dialog->DeleteCard(std::move(guid));
},
parent_dialog_, GetGuid()),
kTrashCanIcon);
delete_card_from_local_button->SetTooltipText(l10n_util::GetStringUTF16(
IDS_AUTOFILL_LOCAL_CARD_MIGRATION_DIALOG_TRASH_CAN_BUTTON_TOOLTIP));
delete_card_from_local_button_ =
......@@ -194,13 +207,7 @@ MigratableCardView::GetMigratableCardDescriptionView(
return migratable_card_description_view;
}
const char* MigratableCardView::GetClassName() const {
return kViewClassName;
}
void MigratableCardView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender == checkbox_) {
void MigratableCardView::CheckboxPressed() {
// If the button clicked is a checkbox. Enable/disable the save
// button if needed.
parent_dialog_->DialogModelChanged();
......@@ -208,12 +215,6 @@ void MigratableCardView::ButtonPressed(views::Button* sender,
checkbox_uncheck_text_container_->SetVisible(!checkbox_->GetChecked());
InvalidateLayout();
parent_dialog_->UpdateLayout();
} else {
// Otherwise it is the trash can button clicked. Delete the corresponding
// card from local storage.
DCHECK_EQ(sender, delete_card_from_local_button_);
parent_dialog_->DeleteCard(GetGuid());
}
}
} // namespace autofill
......@@ -7,11 +7,9 @@
#include "base/macros.h"
#include "components/autofill/core/browser/payments/local_card_migration_manager.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/view.h"
namespace views {
class ButtonListener;
class Checkbox;
class ImageButton;
} // namespace views
......@@ -25,7 +23,7 @@ class MigratableCreditCard;
// A view composed of a checkbox or an image indicating migration results, card
// network image, card network, last four digits of card number and card
// expiration date. Used by LocalCardMigrationDialogView.
class MigratableCardView : public views::View, public views::ButtonListener {
class MigratableCardView : public views::View {
public:
static const char kViewClassName[];
......@@ -34,23 +32,21 @@ class MigratableCardView : public views::View, public views::ButtonListener {
bool should_show_checkbox);
~MigratableCardView() override;
bool IsSelected();
std::string GetGuid();
bool IsSelected() const;
std::string GetGuid() const;
base::string16 GetCardIdentifierString() const;
std::unique_ptr<views::View> GetMigratableCardDescriptionView(
const MigratableCreditCard& migratable_credit_card,
bool should_show_checkbox,
ButtonListener* listener);
// views::View
const char* GetClassName() const override;
// views::ButtonListener
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private:
MigratableCreditCard migratable_credit_card_;
std::unique_ptr<views::View> GetMigratableCardDescriptionView(
const MigratableCreditCard& migratable_credit_card,
bool should_show_checkbox);
void CheckboxPressed();
const MigratableCreditCard migratable_credit_card_;
// The checkbox_ can remain null if the card list in the local
// card migration dialog contains only one card.
......
......@@ -21,18 +21,6 @@
#include "chrome/browser/ui/views/sync/dice_bubble_sync_promo_view.h"
#endif
namespace {
std::unique_ptr<views::View> CreateManageCardsButton(
views::ButtonListener* listener) {
auto manage_cards_button = std::make_unique<views::MdTextButton>(
listener, l10n_util::GetStringUTF16(IDS_AUTOFILL_MANAGE_CARDS));
manage_cards_button->SetID(autofill::DialogViewId::MANAGE_CARDS_BUTTON);
return manage_cards_button;
}
} // namespace
namespace autofill {
SaveCardManageCardsBubbleViews::SaveCardManageCardsBubbleViews(
......@@ -41,7 +29,15 @@ SaveCardManageCardsBubbleViews::SaveCardManageCardsBubbleViews(
SaveCardBubbleController* controller)
: SaveCardBubbleViews(anchor_view, web_contents, controller) {
SetButtons(ui::DIALOG_BUTTON_OK);
SetExtraView(CreateManageCardsButton(this));
SetExtraView(std::make_unique<views::MdTextButton>(
base::BindRepeating(
[](SaveCardManageCardsBubbleViews* bubble) {
bubble->controller()->OnManageCardsClicked();
bubble->CloseBubble();
},
base::Unretained(this)),
l10n_util::GetStringUTF16(IDS_AUTOFILL_MANAGE_CARDS)))
->SetID(autofill::DialogViewId::MANAGE_CARDS_BUTTON);
SetFootnoteView(CreateSigninPromoView());
}
......@@ -78,14 +74,6 @@ SaveCardManageCardsBubbleViews::CreateSigninPromoView() {
#endif
}
void SaveCardManageCardsBubbleViews::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender->GetViewByID(DialogViewId::MANAGE_CARDS_BUTTON)) {
controller()->OnManageCardsClicked();
CloseBubble();
}
}
SaveCardManageCardsBubbleViews::~SaveCardManageCardsBubbleViews() = default;
} // namespace autofill
......@@ -6,7 +6,6 @@
#define CHROME_BROWSER_UI_VIEWS_AUTOFILL_PAYMENTS_SAVE_CARD_MANAGE_CARDS_BUBBLE_VIEWS_H_
#include "chrome/browser/ui/views/autofill/payments/save_card_bubble_views.h"
#include "ui/views/controls/button/button.h"
namespace autofill {
......@@ -16,8 +15,7 @@ namespace autofill {
// clicking on the omnibox credit card icon. It contains a description of the
// credit card that was just saved, a [Manage cards] button that links to the
// Autofill settings page, and a [Done] button that closes the bubble.
class SaveCardManageCardsBubbleViews : public SaveCardBubbleViews,
public views::ButtonListener {
class SaveCardManageCardsBubbleViews : public SaveCardBubbleViews {
public:
// Bubble will be anchored to |anchor_view|.
SaveCardManageCardsBubbleViews(views::View* anchor_view,
......@@ -28,11 +26,6 @@ class SaveCardManageCardsBubbleViews : public SaveCardBubbleViews,
std::unique_ptr<views::View> CreateMainContentView() override;
std::unique_ptr<views::View> CreateSigninPromoView();
// views::ButtonListener:
// The button listener method for the extra view that contains
// the Manage cards button.
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
~SaveCardManageCardsBubbleViews() override;
DISALLOW_COPY_AND_ASSIGN(SaveCardManageCardsBubbleViews);
......
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