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

Side by Side Diff: chrome/browser/ui/views/payments/payment_method_view_controller.cc

Issue 2755493005: [Web Payments] Consolidate list code. (Closed)
Patch Set: Move selection logic to base. 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 #include <vector>
9 10
10 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
11 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" 13 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
13 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" 14 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
14 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" 15 #include "chrome/browser/ui/views/payments/payment_request_row_view.h"
15 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" 16 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
16 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
17 #include "components/autofill/core/browser/autofill_type.h" 18 #include "components/autofill/core/browser/autofill_type.h"
18 #include "components/autofill/core/browser/credit_card.h" 19 #include "components/autofill/core/browser/credit_card.h"
(...skipping 30 matching lines...) Expand all
49 PaymentRequestSpec* spec, 50 PaymentRequestSpec* spec,
50 PaymentRequestState* state, 51 PaymentRequestState* state,
51 PaymentRequestItemList* list, 52 PaymentRequestItemList* list,
52 bool selected) 53 bool selected)
53 : payments::PaymentRequestItemList::Item(spec, state, list, selected), 54 : payments::PaymentRequestItemList::Item(spec, state, list, selected),
54 card_(card) {} 55 card_(card) {}
55 ~PaymentMethodListItem() override {} 56 ~PaymentMethodListItem() override {}
56 57
57 private: 58 private:
58 // payments::PaymentRequestItemList::Item: 59 // payments::PaymentRequestItemList::Item:
59 std::unique_ptr<views::View> CreateItemView() override { 60 std::unique_ptr<views::View> CreateExtraView() override {
60 std::unique_ptr<PaymentRequestRowView> row = 61 std::unique_ptr<views::ImageView> card_icon_view =
61 base::MakeUnique<PaymentRequestRowView>(this); 62 CreateCardIconView(card_->type());
62 views::GridLayout* layout = new views::GridLayout(row.get()); 63 card_icon_view->SetImageSize(gfx::Size(32, 20));
63 layout->SetInsets( 64 return std::move(card_icon_view);
64 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets, 65 }
65 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets);
66 row->SetLayoutManager(layout);
67 views::ColumnSet* columns = layout->AddColumnSet(0);
68 66
69 // A column for the masked number and name on card 67 std::unique_ptr<views::View> CreateContentView() override {
70 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0,
71 views::GridLayout::USE_PREF, 0, 0);
72
73 // A padding column that resizes to take up the empty space between the
74 // leading and trailing parts.
75 columns->AddPaddingColumn(1, 0);
76
77 // A column for the checkmark when the row is selected.
78 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
79 0, views::GridLayout::USE_PREF, 0, 0);
80
81 columns->AddPaddingColumn(0, kPaymentRequestButtonSpacing);
82
83 // A column for the card icon
84 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
85 0, views::GridLayout::USE_PREF, 0, 0);
86
87 // A column for the edit button
88 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
89 0, views::GridLayout::USE_PREF, 0, 0);
90
91 layout->StartRow(0, 0);
92 std::unique_ptr<views::View> card_info_container = 68 std::unique_ptr<views::View> card_info_container =
93 base::MakeUnique<views::View>(); 69 base::MakeUnique<views::View>();
94 card_info_container->set_can_process_events_within_subtree(false); 70 card_info_container->set_can_process_events_within_subtree(false);
95 71
96 std::unique_ptr<views::BoxLayout> box_layout = 72 std::unique_ptr<views::BoxLayout> box_layout =
97 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 73 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0,
98 kPaymentRequestRowVerticalInsets, 0); 74 kPaymentRequestRowVerticalInsets, 0);
99 box_layout->set_cross_axis_alignment( 75 box_layout->set_cross_axis_alignment(
100 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); 76 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START);
101 card_info_container->SetLayoutManager(box_layout.release()); 77 card_info_container->SetLayoutManager(box_layout.release());
102 78
103 card_info_container->AddChildView( 79 card_info_container->AddChildView(
104 new views::Label(card_->TypeAndLastFourDigits())); 80 new views::Label(card_->TypeAndLastFourDigits()));
105 card_info_container->AddChildView(new views::Label( 81 card_info_container->AddChildView(new views::Label(
106 card_->GetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), 82 card_->GetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL),
107 g_browser_process->GetApplicationLocale()))); 83 g_browser_process->GetApplicationLocale())));
108 // TODO(anthonyvd): Add the "card is incomplete" label once the 84 // TODO(anthonyvd): Add the "card is incomplete" label once the
109 // completedness logic is implemented. 85 // completedness logic is implemented.
110 layout->AddView(card_info_container.release()); 86 return card_info_container;
111
112 checkmark_ = CreateCheckmark(selected());
113 layout->AddView(checkmark_.get());
114
115 std::unique_ptr<views::ImageView> card_icon_view =
116 CreateCardIconView(card_->type());
117 card_icon_view->SetImageSize(gfx::Size(32, 20));
118 layout->AddView(card_icon_view.release());
119
120 return std::move(row);
121 } 87 }
122 88
123 void SelectedStateChanged() override { 89 void SelectedStateChanged() override {
124 // This could be called before CreateItemView, so before |checkmark_| is
125 // instantiated.
126 if (checkmark_)
127 checkmark_->SetVisible(selected());
128
129 state()->SetSelectedCreditCard(card_); 90 state()->SetSelectedCreditCard(card_);
130 } 91 }
131 92
132 // views::ButtonListener: 93 bool CanBeSelected() const override {
133 void ButtonPressed(views::Button* sender, const ui::Event& event) override { 94 // TODO(anthonyvd): Check for card completedness.
134 if (IsComplete()) {
135 list()->SelectItem(this);
136 } else {
137 // TODO(anthonyvd): Display the editor, pre-populated with the data that
138 // already exists in |card|.
139 }
140 }
141
142 bool IsComplete() const {
143 // TODO(anthonyvd): Hook this up to the card completedness logic when it's
144 // implemented in PaymentRequest.
145 return true; 95 return true;
146 } 96 }
147 97
98 void PerformSelectionFallback() override {
99 // TODO(anthonyvd): Open the editor pre-populated with this card's data.
100 }
101
148 autofill::CreditCard* card_; 102 autofill::CreditCard* card_;
149 std::unique_ptr<views::ImageView> checkmark_; 103 std::unique_ptr<views::ImageView> checkmark_;
150 104
151 DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem); 105 DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem);
152 }; 106 };
153 107
154 } // namespace 108 } // namespace
155 109
156 PaymentMethodViewController::PaymentMethodViewController( 110 PaymentMethodViewController::PaymentMethodViewController(
157 PaymentRequestSpec* spec, 111 PaymentRequestSpec* spec,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON): 165 PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON):
212 dialog()->ShowCreditCardEditor(); 166 dialog()->ShowCreditCardEditor();
213 break; 167 break;
214 default: 168 default:
215 PaymentRequestSheetController::ButtonPressed(sender, event); 169 PaymentRequestSheetController::ButtonPressed(sender, event);
216 break; 170 break;
217 } 171 }
218 } 172 }
219 173
220 } // namespace payments 174 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698