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

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

Issue 2805263003: [Payments] Selecting incomplete items will open editors (Closed)
Patch Set: Initial Created 3 years, 8 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
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" 13 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
14 #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"
15 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" 15 #include "chrome/browser/ui/views/payments/payment_request_row_view.h"
16 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" 16 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
17 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
18 #include "components/payments/content/payment_request_state.h" 18 #include "components/payments/content/payment_request_state.h"
19 #include "components/payments/core/autofill_payment_instrument.h"
19 #include "components/payments/core/payment_instrument.h" 20 #include "components/payments/core/payment_instrument.h"
20 #include "components/strings/grit/components_strings.h" 21 #include "components/strings/grit/components_strings.h"
21 #include "third_party/skia/include/core/SkColor.h" 22 #include "third_party/skia/include/core/SkColor.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/gfx/paint_vector_icon.h" 24 #include "ui/gfx/paint_vector_icon.h"
24 #include "ui/views/controls/button/label_button.h" 25 #include "ui/views/controls/button/label_button.h"
25 #include "ui/views/controls/button/md_text_button.h" 26 #include "ui/views/controls/button/md_text_button.h"
26 #include "ui/views/layout/box_layout.h" 27 #include "ui/views/layout/box_layout.h"
27 #include "ui/views/layout/fill_layout.h" 28 #include "ui/views/layout/fill_layout.h"
28 #include "ui/views/layout/grid_layout.h" 29 #include "ui/views/layout/grid_layout.h"
(...skipping 10 matching lines...) Expand all
39 // The tag for the button that triggers the "add card" flow. Starts at 40 // The tag for the button that triggers the "add card" flow. Starts at
40 // |kFirstTagValue| not to conflict with tags common to all views. 41 // |kFirstTagValue| not to conflict with tags common to all views.
41 ADD_CREDIT_CARD_BUTTON = kFirstTagValue, 42 ADD_CREDIT_CARD_BUTTON = kFirstTagValue,
42 }; 43 };
43 44
44 class PaymentMethodListItem : public payments::PaymentRequestItemList::Item { 45 class PaymentMethodListItem : public payments::PaymentRequestItemList::Item {
45 public: 46 public:
46 // Does not take ownership of |instrument|, which should not be null and 47 // Does not take ownership of |instrument|, which should not be null and
47 // should outlive this object. |list| is the PaymentRequestItemList object 48 // should outlive this object. |list| is the PaymentRequestItemList object
48 // that will own this. 49 // that will own this.
49 PaymentMethodListItem(PaymentInstrument* instrument, 50 PaymentMethodListItem(AutofillPaymentInstrument* instrument,
50 PaymentRequestSpec* spec, 51 PaymentRequestSpec* spec,
51 PaymentRequestState* state, 52 PaymentRequestState* state,
52 PaymentRequestItemList* list, 53 PaymentRequestItemList* list,
53 PaymentRequestDialogView* dialog, 54 PaymentRequestDialogView* dialog,
54 bool selected) 55 bool selected)
55 : payments::PaymentRequestItemList::Item(spec, state, list, selected), 56 : payments::PaymentRequestItemList::Item(spec, state, list, selected),
56 instrument_(instrument), 57 instrument_(instrument),
57 dialog_(dialog) {} 58 dialog_(dialog) {}
58 ~PaymentMethodListItem() override {} 59 ~PaymentMethodListItem() override {}
59 60
(...skipping 26 matching lines...) Expand all
86 return card_info_container; 87 return card_info_container;
87 } 88 }
88 89
89 void SelectedStateChanged() override { 90 void SelectedStateChanged() override {
90 if (selected()) { 91 if (selected()) {
91 state()->SetSelectedInstrument(instrument_); 92 state()->SetSelectedInstrument(instrument_);
92 dialog_->GoBack(); 93 dialog_->GoBack();
93 } 94 }
94 } 95 }
95 96
96 bool CanBeSelected() const override { 97 bool CanBeSelected() const override { return instrument_->IsValid(); }
97 // TODO(anthonyvd): Check for card completedness. 98
98 return true; 99 void PerformSelectionFallback() override {
100 dialog_->ShowCreditCardEditor(instrument_->credit_card());
99 } 101 }
100 102
101 void PerformSelectionFallback() override { 103 AutofillPaymentInstrument* instrument_;
anthonyvd 2017/04/07 20:08:09 I don't think we want this, even if it's a tempora
Mathieu 2017/04/09 00:35:45 You're right! Added a switch on the type() so that
102 // TODO(anthonyvd): Open the editor pre-populated with this card's data.
103 }
104
105 PaymentInstrument* instrument_;
106 PaymentRequestDialogView* dialog_; 104 PaymentRequestDialogView* dialog_;
107 105
108 DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem); 106 DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem);
109 }; 107 };
110 108
111 } // namespace 109 } // namespace
112 110
113 PaymentMethodViewController::PaymentMethodViewController( 111 PaymentMethodViewController::PaymentMethodViewController(
114 PaymentRequestSpec* spec, 112 PaymentRequestSpec* spec,
115 PaymentRequestState* state, 113 PaymentRequestState* state,
116 PaymentRequestDialogView* dialog) 114 PaymentRequestDialogView* dialog)
117 : PaymentRequestSheetController(spec, state, dialog) { 115 : PaymentRequestSheetController(spec, state, dialog) {
118 const std::vector<std::unique_ptr<PaymentInstrument>>& available_instruments = 116 const std::vector<std::unique_ptr<PaymentInstrument>>& available_instruments =
119 state->available_instruments(); 117 state->available_instruments();
120 118
121 for (const std::unique_ptr<PaymentInstrument>& instrument : 119 for (const std::unique_ptr<PaymentInstrument>& instrument :
122 available_instruments) { 120 available_instruments) {
121 // TODO(crbug.com/709194): When this feature supports instruments that are
122 // not credit cards, the cast below is invalid.
123 std::unique_ptr<PaymentMethodListItem> item = 123 std::unique_ptr<PaymentMethodListItem> item =
124 base::MakeUnique<PaymentMethodListItem>( 124 base::MakeUnique<PaymentMethodListItem>(
125 instrument.get(), spec, state, &payment_method_list_, dialog, 125 static_cast<AutofillPaymentInstrument*>(instrument.get()), spec,
126 state, &payment_method_list_, dialog,
126 instrument.get() == state->selected_instrument()); 127 instrument.get() == state->selected_instrument());
127 payment_method_list_.AddItem(std::move(item)); 128 payment_method_list_.AddItem(std::move(item));
128 } 129 }
129 } 130 }
130 131
131 PaymentMethodViewController::~PaymentMethodViewController() {} 132 PaymentMethodViewController::~PaymentMethodViewController() {}
132 133
133 base::string16 PaymentMethodViewController::GetSheetTitle() { 134 base::string16 PaymentMethodViewController::GetSheetTitle() {
134 return l10n_util::GetStringUTF16( 135 return l10n_util::GetStringUTF16(
135 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME); 136 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON): 170 PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON):
170 dialog()->ShowCreditCardEditor(); 171 dialog()->ShowCreditCardEditor();
171 break; 172 break;
172 default: 173 default:
173 PaymentRequestSheetController::ButtonPressed(sender, event); 174 PaymentRequestSheetController::ButtonPressed(sender, event);
174 break; 175 break;
175 } 176 }
176 } 177 }
177 178
178 } // namespace payments 179 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698