OLD | NEW |
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 { |
97 // TODO(anthonyvd): Check for card completedness. | 98 // If an instrument can't be selected, PerformSelectionFallback is called, |
98 return true; | 99 // where the instrument can be made complete. |
| 100 return instrument_->IsCompleteForPayment(); |
99 } | 101 } |
100 | 102 |
101 void PerformSelectionFallback() override { | 103 void PerformSelectionFallback() override { |
102 // TODO(anthonyvd): Open the editor pre-populated with this card's data. | 104 switch (instrument_->type()) { |
| 105 case PaymentInstrument::Type::AUTOFILL: |
| 106 dialog_->ShowCreditCardEditor( |
| 107 static_cast<AutofillPaymentInstrument*>(instrument_) |
| 108 ->credit_card()); |
| 109 return; |
| 110 } |
| 111 NOTREACHED(); |
103 } | 112 } |
104 | 113 |
105 PaymentInstrument* instrument_; | 114 PaymentInstrument* instrument_; |
106 PaymentRequestDialogView* dialog_; | 115 PaymentRequestDialogView* dialog_; |
107 | 116 |
108 DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem); | 117 DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem); |
109 }; | 118 }; |
110 | 119 |
111 } // namespace | 120 } // namespace |
112 | 121 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON): | 178 PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON): |
170 dialog()->ShowCreditCardEditor(); | 179 dialog()->ShowCreditCardEditor(); |
171 break; | 180 break; |
172 default: | 181 default: |
173 PaymentRequestSheetController::ButtonPressed(sender, event); | 182 PaymentRequestSheetController::ButtonPressed(sender, event); |
174 break; | 183 break; |
175 } | 184 } |
176 } | 185 } |
177 | 186 |
178 } // namespace payments | 187 } // namespace payments |
OLD | NEW |