Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6454)

Unified Diff: chrome/browser/ui/views/payments/payment_method_view_controller.cc

Issue 2711973002: [Web Payments] Implement the credit card selection UI functionality. (Closed)
Patch Set: Address comments. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/payments/payment_method_view_controller.cc
diff --git a/chrome/browser/ui/views/payments/payment_method_view_controller.cc b/chrome/browser/ui/views/payments/payment_method_view_controller.cc
index 438237e4ac337794fff59ca26654fe22b46ff1b0..945115adaebbc40549efd1838e78944ce0afb851 100644
--- a/chrome/browser/ui/views/payments/payment_method_view_controller.cc
+++ b/chrome/browser/ui/views/payments/payment_method_view_controller.cc
@@ -45,7 +45,10 @@ class PaymentMethodListItem : public payments::PaymentRequestItemList::Item,
public:
// Does not take ownership of |card|, which should not be null and should
please use gerrit instead 2017/02/24 14:56:52 Please update the comment to mention that |list| w
anthonyvd 2017/02/24 16:36:57 Ah, missed that one. Done.
// outlive this object.
- explicit PaymentMethodListItem(autofill::CreditCard* card) : card_(card) {}
+ PaymentMethodListItem(autofill::CreditCard* card,
+ PaymentRequestItemList* list,
+ bool selected)
+ : payments::PaymentRequestItemList::Item(list, selected), card_(card) {}
~PaymentMethodListItem() override {}
private:
@@ -72,6 +75,8 @@ class PaymentMethodListItem : public payments::PaymentRequestItemList::Item,
columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
0, views::GridLayout::USE_PREF, 0, 0);
+ columns->AddPaddingColumn(0, kPaymentRequestButtonSpacing);
+
// A column for the card icon
columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
0, views::GridLayout::USE_PREF, 0, 0);
@@ -97,14 +102,19 @@ class PaymentMethodListItem : public payments::PaymentRequestItemList::Item,
card_info_container->AddChildView(new views::Label(
card_->GetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL),
g_browser_process->GetApplicationLocale())));
+ // TODO(anthonyvd): Add the "card is incomplete" label once the
+ // completedness logic is implemented.
layout->AddView(card_info_container.release());
- std::unique_ptr<views::ImageView> checkmark =
- base::MakeUnique<views::ImageView>();
- checkmark->set_interactive(false);
- checkmark->SetImage(
+ checkmark_ = base::MakeUnique<views::ImageView>();
+ checkmark_->set_owned_by_client();
+ checkmark_->set_interactive(false);
+ checkmark_->SetImage(
gfx::CreateVectorIcon(views::kMenuCheckIcon, 0xFF609265));
- layout->AddView(checkmark.release());
+ layout->AddView(checkmark_.get());
+ if (!selected()) {
please use gerrit instead 2017/02/24 14:56:52 nit: No {} for single-line if body.
anthonyvd 2017/02/24 16:36:57 Done.
+ checkmark_->SetVisible(false);
+ }
std::unique_ptr<views::ImageView> card_icon_view =
CreateCardIconView(card_->type());
@@ -114,10 +124,26 @@ class PaymentMethodListItem : public payments::PaymentRequestItemList::Item,
return std::move(row);
}
+ void SelectedStateChanged() override { checkmark_->SetVisible(selected()); }
+
// views::ButtonListener:
- void ButtonPressed(views::Button* sender, const ui::Event& event) override {}
+ void ButtonPressed(views::Button* sender, const ui::Event& event) override {
+ if (IsComplete()) {
+ list()->SelectItem(this);
+ } else {
+ // TODO(anthonyvd): Display the editor, pre-populated with the data that
+ // already exists in |card|.
+ }
+ }
+
+ bool IsComplete() const {
+ // TODO(anthonyvd): Hook this up to the card completedness logic when it's
+ // implemented in PaymentRequest.
+ return true;
+ }
autofill::CreditCard* card_;
+ std::unique_ptr<views::ImageView> checkmark_;
DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem);
};
@@ -132,7 +158,11 @@ PaymentMethodViewController::PaymentMethodViewController(
request->credit_cards();
for (autofill::CreditCard* card : available_cards) {
- payment_method_list_.AddItem(base::MakeUnique<PaymentMethodListItem>(card));
+ std::unique_ptr<PaymentMethodListItem> item =
+ base::MakeUnique<PaymentMethodListItem>(
+ card, &payment_method_list_,
+ card == request->selected_credit_card());
+ payment_method_list_.AddItem(std::move(item));
}
}

Powered by Google App Engine
This is Rietveld 408576698