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

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

Issue 2872623002: [Web Payments] Add "pencil" edit button to lists. (Closed)
Patch Set: Address comments, icon changes Created 3 years, 7 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 public: 50 public:
51 // Does not take ownership of |instrument|, which should not be null and 51 // Does not take ownership of |instrument|, which should not be null and
52 // should outlive this object. |list| is the PaymentRequestItemList object 52 // should outlive this object. |list| is the PaymentRequestItemList object
53 // that will own this. 53 // that will own this.
54 PaymentMethodListItem(PaymentInstrument* instrument, 54 PaymentMethodListItem(PaymentInstrument* instrument,
55 PaymentRequestSpec* spec, 55 PaymentRequestSpec* spec,
56 PaymentRequestState* state, 56 PaymentRequestState* state,
57 PaymentRequestItemList* list, 57 PaymentRequestItemList* list,
58 PaymentRequestDialogView* dialog, 58 PaymentRequestDialogView* dialog,
59 bool selected) 59 bool selected)
60 : payments::PaymentRequestItemList::Item(spec, state, list, selected), 60 : payments::PaymentRequestItemList::Item(spec,
61 state,
62 list,
63 selected,
64 /*show_edit_button=*/true),
61 instrument_(instrument), 65 instrument_(instrument),
62 dialog_(dialog) {} 66 dialog_(dialog) {}
63 ~PaymentMethodListItem() override {} 67 ~PaymentMethodListItem() override {}
64 68
65 private: 69 private:
70 void ShowEditor() {
71 switch (instrument_->type()) {
72 case PaymentInstrument::Type::AUTOFILL:
73 // Since we are a list item, we only care about the on_edited callback.
74 dialog_->ShowCreditCardEditor(
75 /*on_edited=*/base::BindOnce(
Evan Stade 2017/05/10 16:06:25 nit: is this the correct format for documenting pa
anthonyvd 2017/05/10 16:39:26 The style guide doesn't specify and there's other
76 &PaymentRequestState::SetSelectedInstrument,
77 base::Unretained(state()), instrument_),
78 /*on_added=*/
79 base::OnceCallback<void(const autofill::CreditCard&)>(),
80 static_cast<AutofillPaymentInstrument*>(instrument_)
81 ->credit_card());
82 return;
83 }
84 NOTREACHED();
85 }
86
66 // payments::PaymentRequestItemList::Item: 87 // payments::PaymentRequestItemList::Item:
67 std::unique_ptr<views::View> CreateExtraView() override { 88 std::unique_ptr<views::View> CreateExtraView() override {
68 std::unique_ptr<views::ImageView> card_icon_view = CreateInstrumentIconView( 89 std::unique_ptr<views::ImageView> card_icon_view = CreateInstrumentIconView(
69 instrument_->icon_resource_id(), instrument_->label()); 90 instrument_->icon_resource_id(), instrument_->label());
70 card_icon_view->SetImageSize(gfx::Size(32, 20)); 91 card_icon_view->SetImageSize(gfx::Size(32, 20));
71 return std::move(card_icon_view); 92 return std::move(card_icon_view);
72 } 93 }
73 94
74 std::unique_ptr<views::View> CreateContentView() override { 95 std::unique_ptr<views::View> CreateContentView() override {
75 std::unique_ptr<views::View> card_info_container = 96 std::unique_ptr<views::View> card_info_container =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // All items are enabled. 135 // All items are enabled.
115 return true; 136 return true;
116 } 137 }
117 138
118 bool CanBeSelected() override { 139 bool CanBeSelected() override {
119 // If an instrument can't be selected, PerformSelectionFallback is called, 140 // If an instrument can't be selected, PerformSelectionFallback is called,
120 // where the instrument can be made complete. 141 // where the instrument can be made complete.
121 return instrument_->IsCompleteForPayment(); 142 return instrument_->IsCompleteForPayment();
122 } 143 }
123 144
124 void PerformSelectionFallback() override { 145 void PerformSelectionFallback() override { ShowEditor(); }
125 switch (instrument_->type()) { 146
126 case PaymentInstrument::Type::AUTOFILL: 147 void EditButtonPressed() override { ShowEditor(); }
127 // Since we are a list item, we only care about the on_edited callback.
128 dialog_->ShowCreditCardEditor(
129 /*on_edited=*/base::BindOnce(
130 &PaymentRequestState::SetSelectedInstrument,
131 base::Unretained(state()), instrument_),
132 /*on_added=*/
133 base::OnceCallback<void(const autofill::CreditCard&)>(),
134 static_cast<AutofillPaymentInstrument*>(instrument_)
135 ->credit_card());
136 return;
137 }
138 NOTREACHED();
139 }
140 148
141 PaymentInstrument* instrument_; 149 PaymentInstrument* instrument_;
142 PaymentRequestDialogView* dialog_; 150 PaymentRequestDialogView* dialog_;
143 151
144 DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem); 152 DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem);
145 }; 153 };
146 154
147 } // namespace 155 } // namespace
148 156
149 PaymentMethodViewController::PaymentMethodViewController( 157 PaymentMethodViewController::PaymentMethodViewController(
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 base::Unretained(state()), /*selected=*/true), 218 base::Unretained(state()), /*selected=*/true),
211 /*credit_card=*/nullptr); 219 /*credit_card=*/nullptr);
212 break; 220 break;
213 default: 221 default:
214 PaymentRequestSheetController::ButtonPressed(sender, event); 222 PaymentRequestSheetController::ButtonPressed(sender, event);
215 break; 223 break;
216 } 224 }
217 } 225 }
218 226
219 } // namespace payments 227 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698