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

Side by Side 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, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/payments/payment_method_view_controller.h" 5 #include "chrome/browser/ui/views/payments/payment_method_view_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 25 matching lines...) Expand all
36 36
37 enum class PaymentMethodViewControllerTags : int { 37 enum class PaymentMethodViewControllerTags : int {
38 // The tag for the button that triggers the "add card" flow. Starts at 38 // The tag for the button that triggers the "add card" flow. Starts at
39 // |kFirstTagValue| not to conflict with tags common to all views. 39 // |kFirstTagValue| not to conflict with tags common to all views.
40 ADD_CREDIT_CARD_BUTTON = kFirstTagValue, 40 ADD_CREDIT_CARD_BUTTON = kFirstTagValue,
41 }; 41 };
42 42
43 class PaymentMethodListItem : public payments::PaymentRequestItemList::Item, 43 class PaymentMethodListItem : public payments::PaymentRequestItemList::Item,
44 public views::ButtonListener { 44 public views::ButtonListener {
45 public: 45 public:
46 // Does not take ownership of |card|, which should not be null and should 46 // 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.
47 // outlive this object. 47 // outlive this object.
48 explicit PaymentMethodListItem(autofill::CreditCard* card) : card_(card) {} 48 PaymentMethodListItem(autofill::CreditCard* card,
49 PaymentRequestItemList* list,
50 bool selected)
51 : payments::PaymentRequestItemList::Item(list, selected), card_(card) {}
49 ~PaymentMethodListItem() override {} 52 ~PaymentMethodListItem() override {}
50 53
51 private: 54 private:
52 // payments::PaymentRequestItemList::Item: 55 // payments::PaymentRequestItemList::Item:
53 std::unique_ptr<views::View> CreateItemView() override { 56 std::unique_ptr<views::View> CreateItemView() override {
54 std::unique_ptr<PaymentRequestRowView> row = 57 std::unique_ptr<PaymentRequestRowView> row =
55 base::MakeUnique<PaymentRequestRowView>(this); 58 base::MakeUnique<PaymentRequestRowView>(this);
56 views::GridLayout* layout = new views::GridLayout(row.get()); 59 views::GridLayout* layout = new views::GridLayout(row.get());
57 layout->SetInsets( 60 layout->SetInsets(
58 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets, 61 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets,
59 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets); 62 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets);
60 row->SetLayoutManager(layout); 63 row->SetLayoutManager(layout);
61 views::ColumnSet* columns = layout->AddColumnSet(0); 64 views::ColumnSet* columns = layout->AddColumnSet(0);
62 65
63 // A column for the masked number and name on card 66 // A column for the masked number and name on card
64 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, 67 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0,
65 views::GridLayout::USE_PREF, 0, 0); 68 views::GridLayout::USE_PREF, 0, 0);
66 69
67 // A padding column that resizes to take up the empty space between the 70 // A padding column that resizes to take up the empty space between the
68 // leading and trailing parts. 71 // leading and trailing parts.
69 columns->AddPaddingColumn(1, 0); 72 columns->AddPaddingColumn(1, 0);
70 73
71 // A column for the checkmark when the row is selected. 74 // A column for the checkmark when the row is selected.
72 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 75 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
73 0, views::GridLayout::USE_PREF, 0, 0); 76 0, views::GridLayout::USE_PREF, 0, 0);
74 77
78 columns->AddPaddingColumn(0, kPaymentRequestButtonSpacing);
79
75 // A column for the card icon 80 // A column for the card icon
76 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 81 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
77 0, views::GridLayout::USE_PREF, 0, 0); 82 0, views::GridLayout::USE_PREF, 0, 0);
78 83
79 // A column for the edit button 84 // A column for the edit button
80 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 85 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
81 0, views::GridLayout::USE_PREF, 0, 0); 86 0, views::GridLayout::USE_PREF, 0, 0);
82 87
83 layout->StartRow(0, 0); 88 layout->StartRow(0, 0);
84 std::unique_ptr<views::View> card_info_container = 89 std::unique_ptr<views::View> card_info_container =
85 base::MakeUnique<views::View>(); 90 base::MakeUnique<views::View>();
86 card_info_container->set_can_process_events_within_subtree(false); 91 card_info_container->set_can_process_events_within_subtree(false);
87 92
88 std::unique_ptr<views::BoxLayout> box_layout = 93 std::unique_ptr<views::BoxLayout> box_layout =
89 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 94 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0,
90 kPaymentRequestRowVerticalInsets, 0); 95 kPaymentRequestRowVerticalInsets, 0);
91 box_layout->set_cross_axis_alignment( 96 box_layout->set_cross_axis_alignment(
92 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); 97 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START);
93 card_info_container->SetLayoutManager(box_layout.release()); 98 card_info_container->SetLayoutManager(box_layout.release());
94 99
95 card_info_container->AddChildView( 100 card_info_container->AddChildView(
96 new views::Label(card_->TypeAndLastFourDigits())); 101 new views::Label(card_->TypeAndLastFourDigits()));
97 card_info_container->AddChildView(new views::Label( 102 card_info_container->AddChildView(new views::Label(
98 card_->GetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), 103 card_->GetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL),
99 g_browser_process->GetApplicationLocale()))); 104 g_browser_process->GetApplicationLocale())));
105 // TODO(anthonyvd): Add the "card is incomplete" label once the
106 // completedness logic is implemented.
100 layout->AddView(card_info_container.release()); 107 layout->AddView(card_info_container.release());
101 108
102 std::unique_ptr<views::ImageView> checkmark = 109 checkmark_ = base::MakeUnique<views::ImageView>();
103 base::MakeUnique<views::ImageView>(); 110 checkmark_->set_owned_by_client();
104 checkmark->set_interactive(false); 111 checkmark_->set_interactive(false);
105 checkmark->SetImage( 112 checkmark_->SetImage(
106 gfx::CreateVectorIcon(views::kMenuCheckIcon, 0xFF609265)); 113 gfx::CreateVectorIcon(views::kMenuCheckIcon, 0xFF609265));
107 layout->AddView(checkmark.release()); 114 layout->AddView(checkmark_.get());
115 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.
116 checkmark_->SetVisible(false);
117 }
108 118
109 std::unique_ptr<views::ImageView> card_icon_view = 119 std::unique_ptr<views::ImageView> card_icon_view =
110 CreateCardIconView(card_->type()); 120 CreateCardIconView(card_->type());
111 card_icon_view->SetImageSize(gfx::Size(32, 20)); 121 card_icon_view->SetImageSize(gfx::Size(32, 20));
112 layout->AddView(card_icon_view.release()); 122 layout->AddView(card_icon_view.release());
113 123
114 return std::move(row); 124 return std::move(row);
115 } 125 }
116 126
127 void SelectedStateChanged() override { checkmark_->SetVisible(selected()); }
128
117 // views::ButtonListener: 129 // views::ButtonListener:
118 void ButtonPressed(views::Button* sender, const ui::Event& event) override {} 130 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
131 if (IsComplete()) {
132 list()->SelectItem(this);
133 } else {
134 // TODO(anthonyvd): Display the editor, pre-populated with the data that
135 // already exists in |card|.
136 }
137 }
138
139 bool IsComplete() const {
140 // TODO(anthonyvd): Hook this up to the card completedness logic when it's
141 // implemented in PaymentRequest.
142 return true;
143 }
119 144
120 autofill::CreditCard* card_; 145 autofill::CreditCard* card_;
146 std::unique_ptr<views::ImageView> checkmark_;
121 147
122 DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem); 148 DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem);
123 }; 149 };
124 150
125 } // namespace 151 } // namespace
126 152
127 PaymentMethodViewController::PaymentMethodViewController( 153 PaymentMethodViewController::PaymentMethodViewController(
128 PaymentRequest* request, 154 PaymentRequest* request,
129 PaymentRequestDialogView* dialog) 155 PaymentRequestDialogView* dialog)
130 : PaymentRequestSheetController(request, dialog) { 156 : PaymentRequestSheetController(request, dialog) {
131 const std::vector<autofill::CreditCard*>& available_cards = 157 const std::vector<autofill::CreditCard*>& available_cards =
132 request->credit_cards(); 158 request->credit_cards();
133 159
134 for (autofill::CreditCard* card : available_cards) { 160 for (autofill::CreditCard* card : available_cards) {
135 payment_method_list_.AddItem(base::MakeUnique<PaymentMethodListItem>(card)); 161 std::unique_ptr<PaymentMethodListItem> item =
162 base::MakeUnique<PaymentMethodListItem>(
163 card, &payment_method_list_,
164 card == request->selected_credit_card());
165 payment_method_list_.AddItem(std::move(item));
136 } 166 }
137 } 167 }
138 168
139 PaymentMethodViewController::~PaymentMethodViewController() {} 169 PaymentMethodViewController::~PaymentMethodViewController() {}
140 170
141 std::unique_ptr<views::View> PaymentMethodViewController::CreateView() { 171 std::unique_ptr<views::View> PaymentMethodViewController::CreateView() {
142 return CreatePaymentView( 172 return CreatePaymentView(
143 CreateSheetHeaderView( 173 CreateSheetHeaderView(
144 true, l10n_util::GetStringUTF16( 174 true, l10n_util::GetStringUTF16(
145 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), 175 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME),
(...skipping 27 matching lines...) Expand all
173 PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON): 203 PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON):
174 dialog()->ShowCreditCardEditor(); 204 dialog()->ShowCreditCardEditor();
175 break; 205 break;
176 default: 206 default:
177 PaymentRequestSheetController::ButtonPressed(sender, event); 207 PaymentRequestSheetController::ButtonPressed(sender, event);
178 break; 208 break;
179 } 209 }
180 } 210 }
181 211
182 } // namespace payments 212 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698