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

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

Issue 2759253002: [Web Payments] Implement item selection in lists. (Closed)
Patch Set: Assert back navigation in browser tests. 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 #include <vector>
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 class PaymentMethodListItem : public payments::PaymentRequestItemList::Item { 43 class PaymentMethodListItem : public payments::PaymentRequestItemList::Item {
44 public: 44 public:
45 // Does not take ownership of |instrument|, which should not be null and 45 // Does not take ownership of |instrument|, which should not be null and
46 // should outlive this object. |list| is the PaymentRequestItemList object 46 // should outlive this object. |list| is the PaymentRequestItemList object
47 // that will own this. 47 // that will own this.
48 PaymentMethodListItem(PaymentInstrument* instrument, 48 PaymentMethodListItem(PaymentInstrument* instrument,
49 PaymentRequestSpec* spec, 49 PaymentRequestSpec* spec,
50 PaymentRequestState* state, 50 PaymentRequestState* state,
51 PaymentRequestItemList* list, 51 PaymentRequestItemList* list,
52 PaymentRequestDialogView* dialog,
52 bool selected) 53 bool selected)
53 : payments::PaymentRequestItemList::Item(spec, state, list, selected), 54 : payments::PaymentRequestItemList::Item(spec, state, list, selected),
54 instrument_(instrument) {} 55 instrument_(instrument),
56 dialog_(dialog) {}
55 ~PaymentMethodListItem() override {} 57 ~PaymentMethodListItem() override {}
56 58
57 private: 59 private:
58 // payments::PaymentRequestItemList::Item: 60 // payments::PaymentRequestItemList::Item:
59 std::unique_ptr<views::View> CreateExtraView() override { 61 std::unique_ptr<views::View> CreateExtraView() override {
60 std::unique_ptr<views::ImageView> card_icon_view = CreateInstrumentIconView( 62 std::unique_ptr<views::ImageView> card_icon_view = CreateInstrumentIconView(
61 instrument_->icon_resource_id(), instrument_->label()); 63 instrument_->icon_resource_id(), instrument_->label());
62 card_icon_view->SetImageSize(gfx::Size(32, 20)); 64 card_icon_view->SetImageSize(gfx::Size(32, 20));
63 return std::move(card_icon_view); 65 return std::move(card_icon_view);
64 } 66 }
(...skipping 12 matching lines...) Expand all
77 79
78 card_info_container->AddChildView(new views::Label(instrument_->label())); 80 card_info_container->AddChildView(new views::Label(instrument_->label()));
79 card_info_container->AddChildView( 81 card_info_container->AddChildView(
80 new views::Label(instrument_->sublabel())); 82 new views::Label(instrument_->sublabel()));
81 // TODO(anthonyvd): Add the "card is incomplete" label once the 83 // TODO(anthonyvd): Add the "card is incomplete" label once the
82 // completedness logic is implemented. 84 // completedness logic is implemented.
83 return card_info_container; 85 return card_info_container;
84 } 86 }
85 87
86 void SelectedStateChanged() override { 88 void SelectedStateChanged() override {
87 state()->SetSelectedInstrument(instrument_); 89 if (selected()) {
90 state()->SetSelectedInstrument(instrument_);
91 dialog_->GoBack();
92 }
88 } 93 }
89 94
90 bool CanBeSelected() const override { 95 bool CanBeSelected() const override {
91 // TODO(anthonyvd): Check for card completedness. 96 // TODO(anthonyvd): Check for card completedness.
92 return true; 97 return true;
93 } 98 }
94 99
95 void PerformSelectionFallback() override { 100 void PerformSelectionFallback() override {
96 // TODO(anthonyvd): Open the editor pre-populated with this card's data. 101 // TODO(anthonyvd): Open the editor pre-populated with this card's data.
97 } 102 }
98 103
99 PaymentInstrument* instrument_; 104 PaymentInstrument* instrument_;
100 std::unique_ptr<views::ImageView> checkmark_; 105 PaymentRequestDialogView* dialog_;
101 106
102 DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem); 107 DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem);
103 }; 108 };
104 109
105 } // namespace 110 } // namespace
106 111
107 PaymentMethodViewController::PaymentMethodViewController( 112 PaymentMethodViewController::PaymentMethodViewController(
108 PaymentRequestSpec* spec, 113 PaymentRequestSpec* spec,
109 PaymentRequestState* state, 114 PaymentRequestState* state,
110 PaymentRequestDialogView* dialog) 115 PaymentRequestDialogView* dialog)
111 : PaymentRequestSheetController(spec, state, dialog) { 116 : PaymentRequestSheetController(spec, state, dialog) {
112 const std::vector<std::unique_ptr<PaymentInstrument>>& available_instruments = 117 const std::vector<std::unique_ptr<PaymentInstrument>>& available_instruments =
113 state->available_instruments(); 118 state->available_instruments();
114 119
115 for (const std::unique_ptr<PaymentInstrument>& instrument : 120 for (const std::unique_ptr<PaymentInstrument>& instrument :
116 available_instruments) { 121 available_instruments) {
117 std::unique_ptr<PaymentMethodListItem> item = 122 std::unique_ptr<PaymentMethodListItem> item =
118 base::MakeUnique<PaymentMethodListItem>( 123 base::MakeUnique<PaymentMethodListItem>(
119 instrument.get(), spec, state, &payment_method_list_, 124 instrument.get(), spec, state, &payment_method_list_, dialog,
120 instrument.get() == state->selected_instrument()); 125 instrument.get() == state->selected_instrument());
121 payment_method_list_.AddItem(std::move(item)); 126 payment_method_list_.AddItem(std::move(item));
122 } 127 }
123 } 128 }
124 129
125 PaymentMethodViewController::~PaymentMethodViewController() {} 130 PaymentMethodViewController::~PaymentMethodViewController() {}
126 131
127 std::unique_ptr<views::View> PaymentMethodViewController::CreateView() { 132 std::unique_ptr<views::View> PaymentMethodViewController::CreateView() {
128 std::unique_ptr<views::View> list_view = 133 std::unique_ptr<views::View> list_view =
129 payment_method_list_.CreateListView(); 134 payment_method_list_.CreateListView();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON): 168 PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON):
164 dialog()->ShowCreditCardEditor(); 169 dialog()->ShowCreditCardEditor();
165 break; 170 break;
166 default: 171 default:
167 PaymentRequestSheetController::ButtonPressed(sender, event); 172 PaymentRequestSheetController::ButtonPressed(sender, event);
168 break; 173 break;
169 } 174 }
170 } 175 }
171 176
172 } // namespace payments 177 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698