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( ...@@ -41,7 +41,7 @@ MigratableCardView::MigratableCardView(
provider->GetDistanceMetric(DISTANCE_CONTENT_LIST_VERTICAL_MULTI))); provider->GetDistanceMetric(DISTANCE_CONTENT_LIST_VERTICAL_MULTI)));
AddChildView(GetMigratableCardDescriptionView(migratable_credit_card, AddChildView(GetMigratableCardDescriptionView(migratable_credit_card,
should_show_checkbox, this) should_show_checkbox)
.release()); .release());
checkbox_uncheck_text_container_ = new views::View(); checkbox_uncheck_text_container_ = new views::View();
...@@ -73,11 +73,11 @@ MigratableCardView::MigratableCardView( ...@@ -73,11 +73,11 @@ MigratableCardView::MigratableCardView(
MigratableCardView::~MigratableCardView() = default; MigratableCardView::~MigratableCardView() = default;
bool MigratableCardView::IsSelected() { bool MigratableCardView::IsSelected() const {
return !checkbox_ || checkbox_->GetChecked(); return !checkbox_ || checkbox_->GetChecked();
} }
std::string MigratableCardView::GetGuid() { std::string MigratableCardView::GetGuid() const {
return migratable_credit_card_.credit_card().guid(); return migratable_credit_card_.credit_card().guid();
} }
...@@ -86,11 +86,14 @@ base::string16 MigratableCardView::GetCardIdentifierString() const { ...@@ -86,11 +86,14 @@ base::string16 MigratableCardView::GetCardIdentifierString() const {
.CardIdentifierStringForAutofillDisplay(); .CardIdentifierStringForAutofillDisplay();
} }
const char* MigratableCardView::GetClassName() const {
return kViewClassName;
}
std::unique_ptr<views::View> std::unique_ptr<views::View>
MigratableCardView::GetMigratableCardDescriptionView( MigratableCardView::GetMigratableCardDescriptionView(
const MigratableCreditCard& migratable_credit_card, const MigratableCreditCard& migratable_credit_card,
bool should_show_checkbox, bool should_show_checkbox) {
ButtonListener* listener) {
auto migratable_card_description_view = std::make_unique<views::View>(); auto migratable_card_description_view = std::make_unique<views::View>();
ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
...@@ -112,14 +115,17 @@ MigratableCardView::GetMigratableCardDescriptionView( ...@@ -112,14 +115,17 @@ MigratableCardView::GetMigratableCardDescriptionView(
switch (migratable_credit_card.migration_status()) { switch (migratable_credit_card.migration_status()) {
case MigratableCreditCard::MigrationStatus::UNKNOWN: { case MigratableCreditCard::MigrationStatus::UNKNOWN: {
if (should_show_checkbox) { 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); checkbox_->SetChecked(true);
// TODO(crbug/867194): Currently the ink drop animation circle is // TODO(crbug/867194): Currently the ink drop animation circle is
// cropped by the border of scroll bar view. Find a way to adjust the // cropped by the border of scroll bar view. Find a way to adjust the
// format. // format.
checkbox_->SetInkDropMode(views::InkDropHostView::InkDropMode::OFF); checkbox_->SetInkDropMode(views::InkDropHostView::InkDropMode::OFF);
checkbox_->SetAssociatedLabel(card_description.get()); checkbox_->SetAssociatedLabel(card_description.get());
migratable_card_description_view->AddChildView(checkbox_);
} }
break; break;
} }
...@@ -183,7 +189,14 @@ MigratableCardView::GetMigratableCardDescriptionView( ...@@ -183,7 +189,14 @@ MigratableCardView::GetMigratableCardDescriptionView(
views::style::CONTEXT_LABEL, ChromeTextStyle::STYLE_RED)); views::style::CONTEXT_LABEL, ChromeTextStyle::STYLE_RED));
auto delete_card_from_local_button = 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( delete_card_from_local_button->SetTooltipText(l10n_util::GetStringUTF16(
IDS_AUTOFILL_LOCAL_CARD_MIGRATION_DIALOG_TRASH_CAN_BUTTON_TOOLTIP)); IDS_AUTOFILL_LOCAL_CARD_MIGRATION_DIALOG_TRASH_CAN_BUTTON_TOOLTIP));
delete_card_from_local_button_ = delete_card_from_local_button_ =
...@@ -194,26 +207,14 @@ MigratableCardView::GetMigratableCardDescriptionView( ...@@ -194,26 +207,14 @@ MigratableCardView::GetMigratableCardDescriptionView(
return migratable_card_description_view; return migratable_card_description_view;
} }
const char* MigratableCardView::GetClassName() const { void MigratableCardView::CheckboxPressed() {
return kViewClassName; // If the button clicked is a checkbox. Enable/disable the save
} // button if needed.
parent_dialog_->DialogModelChanged();
void MigratableCardView::ButtonPressed(views::Button* sender, // The warning text will be visible only when user unchecks the checkbox.
const ui::Event& event) { checkbox_uncheck_text_container_->SetVisible(!checkbox_->GetChecked());
if (sender == checkbox_) { InvalidateLayout();
// If the button clicked is a checkbox. Enable/disable the save parent_dialog_->UpdateLayout();
// button if needed.
parent_dialog_->DialogModelChanged();
// The warning text will be visible only when user unchecks the checkbox.
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 } // namespace autofill
...@@ -7,11 +7,9 @@ ...@@ -7,11 +7,9 @@
#include "base/macros.h" #include "base/macros.h"
#include "components/autofill/core/browser/payments/local_card_migration_manager.h" #include "components/autofill/core/browser/payments/local_card_migration_manager.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace views { namespace views {
class ButtonListener;
class Checkbox; class Checkbox;
class ImageButton; class ImageButton;
} // namespace views } // namespace views
...@@ -25,7 +23,7 @@ class MigratableCreditCard; ...@@ -25,7 +23,7 @@ class MigratableCreditCard;
// A view composed of a checkbox or an image indicating migration results, card // 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 // network image, card network, last four digits of card number and card
// expiration date. Used by LocalCardMigrationDialogView. // expiration date. Used by LocalCardMigrationDialogView.
class MigratableCardView : public views::View, public views::ButtonListener { class MigratableCardView : public views::View {
public: public:
static const char kViewClassName[]; static const char kViewClassName[];
...@@ -34,23 +32,21 @@ class MigratableCardView : public views::View, public views::ButtonListener { ...@@ -34,23 +32,21 @@ class MigratableCardView : public views::View, public views::ButtonListener {
bool should_show_checkbox); bool should_show_checkbox);
~MigratableCardView() override; ~MigratableCardView() override;
bool IsSelected(); bool IsSelected() const;
std::string GetGuid(); std::string GetGuid() const;
base::string16 GetCardIdentifierString() const; base::string16 GetCardIdentifierString() const;
std::unique_ptr<views::View> GetMigratableCardDescriptionView(
const MigratableCreditCard& migratable_credit_card,
bool should_show_checkbox,
ButtonListener* listener);
// views::View // views::View
const char* GetClassName() const override; const char* GetClassName() const override;
// views::ButtonListener
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private: 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 // The checkbox_ can remain null if the card list in the local
// card migration dialog contains only one card. // card migration dialog contains only one card.
......
...@@ -21,18 +21,6 @@ ...@@ -21,18 +21,6 @@
#include "chrome/browser/ui/views/sync/dice_bubble_sync_promo_view.h" #include "chrome/browser/ui/views/sync/dice_bubble_sync_promo_view.h"
#endif #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 { namespace autofill {
SaveCardManageCardsBubbleViews::SaveCardManageCardsBubbleViews( SaveCardManageCardsBubbleViews::SaveCardManageCardsBubbleViews(
...@@ -41,7 +29,15 @@ SaveCardManageCardsBubbleViews::SaveCardManageCardsBubbleViews( ...@@ -41,7 +29,15 @@ SaveCardManageCardsBubbleViews::SaveCardManageCardsBubbleViews(
SaveCardBubbleController* controller) SaveCardBubbleController* controller)
: SaveCardBubbleViews(anchor_view, web_contents, controller) { : SaveCardBubbleViews(anchor_view, web_contents, controller) {
SetButtons(ui::DIALOG_BUTTON_OK); 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()); SetFootnoteView(CreateSigninPromoView());
} }
...@@ -78,14 +74,6 @@ SaveCardManageCardsBubbleViews::CreateSigninPromoView() { ...@@ -78,14 +74,6 @@ SaveCardManageCardsBubbleViews::CreateSigninPromoView() {
#endif #endif
} }
void SaveCardManageCardsBubbleViews::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender->GetViewByID(DialogViewId::MANAGE_CARDS_BUTTON)) {
controller()->OnManageCardsClicked();
CloseBubble();
}
}
SaveCardManageCardsBubbleViews::~SaveCardManageCardsBubbleViews() = default; SaveCardManageCardsBubbleViews::~SaveCardManageCardsBubbleViews() = default;
} // namespace autofill } // namespace autofill
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define CHROME_BROWSER_UI_VIEWS_AUTOFILL_PAYMENTS_SAVE_CARD_MANAGE_CARDS_BUBBLE_VIEWS_H_ #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 "chrome/browser/ui/views/autofill/payments/save_card_bubble_views.h"
#include "ui/views/controls/button/button.h"
namespace autofill { namespace autofill {
...@@ -16,8 +15,7 @@ namespace autofill { ...@@ -16,8 +15,7 @@ namespace autofill {
// clicking on the omnibox credit card icon. It contains a description of the // 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 // 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. // Autofill settings page, and a [Done] button that closes the bubble.
class SaveCardManageCardsBubbleViews : public SaveCardBubbleViews, class SaveCardManageCardsBubbleViews : public SaveCardBubbleViews {
public views::ButtonListener {
public: public:
// Bubble will be anchored to |anchor_view|. // Bubble will be anchored to |anchor_view|.
SaveCardManageCardsBubbleViews(views::View* anchor_view, SaveCardManageCardsBubbleViews(views::View* anchor_view,
...@@ -28,11 +26,6 @@ class SaveCardManageCardsBubbleViews : public SaveCardBubbleViews, ...@@ -28,11 +26,6 @@ class SaveCardManageCardsBubbleViews : public SaveCardBubbleViews,
std::unique_ptr<views::View> CreateMainContentView() override; std::unique_ptr<views::View> CreateMainContentView() override;
std::unique_ptr<views::View> CreateSigninPromoView(); 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; ~SaveCardManageCardsBubbleViews() override;
DISALLOW_COPY_AND_ASSIGN(SaveCardManageCardsBubbleViews); 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