Chromium Code Reviews| 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 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 public: | 52 public: |
| 53 // Does not take ownership of |instrument|, which should not be null and | 53 // Does not take ownership of |instrument|, which should not be null and |
| 54 // should outlive this object. |list| is the PaymentRequestItemList object | 54 // should outlive this object. |list| is the PaymentRequestItemList object |
| 55 // that will own this. | 55 // that will own this. |
| 56 PaymentMethodListItem(PaymentInstrument* instrument, | 56 PaymentMethodListItem(PaymentInstrument* instrument, |
| 57 PaymentRequestSpec* spec, | 57 PaymentRequestSpec* spec, |
| 58 PaymentRequestState* state, | 58 PaymentRequestState* state, |
| 59 PaymentRequestItemList* list, | 59 PaymentRequestItemList* list, |
| 60 PaymentRequestDialogView* dialog, | 60 PaymentRequestDialogView* dialog, |
| 61 bool selected) | 61 bool selected) |
| 62 : payments::PaymentRequestItemList::Item(spec, state, list, selected), | 62 : payments::PaymentRequestItemList::Item(spec, |
| 63 state, | |
| 64 list, | |
| 65 selected, | |
| 66 /*show_edit_button=*/true), | |
| 63 instrument_(instrument), | 67 instrument_(instrument), |
| 64 dialog_(dialog) {} | 68 dialog_(dialog) {} |
| 65 ~PaymentMethodListItem() override {} | 69 ~PaymentMethodListItem() override {} |
| 66 | 70 |
| 67 private: | 71 private: |
| 72 void ShowEditor() { | |
| 73 switch (instrument_->type()) { | |
| 74 case PaymentInstrument::Type::AUTOFILL: | |
|
Evan Stade
2017/05/15 17:14:55
are you going to add other types soon? You might j
anthonyvd
2017/05/15 17:27:40
Yes, web payment apps are in the pipeline and ther
| |
| 75 // Since we are a list item, we only care about the on_edited callback. | |
| 76 dialog_->ShowCreditCardEditor( | |
| 77 BackNavigationType::kPaymentSheet, | |
| 78 static_cast<int>(PaymentMethodViewControllerTags::MAX_TAG), | |
| 79 /*on_edited=*/ | |
| 80 base::BindOnce(&PaymentRequestState::SetSelectedInstrument, | |
| 81 base::Unretained(state()), instrument_), | |
| 82 /*on_added=*/ | |
| 83 base::OnceCallback<void(const autofill::CreditCard&)>(), | |
| 84 static_cast<AutofillPaymentInstrument*>(instrument_) | |
| 85 ->credit_card()); | |
| 86 return; | |
| 87 } | |
| 88 NOTREACHED(); | |
| 89 } | |
| 90 | |
| 68 // payments::PaymentRequestItemList::Item: | 91 // payments::PaymentRequestItemList::Item: |
| 69 std::unique_ptr<views::View> CreateExtraView() override { | 92 std::unique_ptr<views::View> CreateExtraView() override { |
| 70 std::unique_ptr<views::ImageView> card_icon_view = CreateInstrumentIconView( | 93 std::unique_ptr<views::ImageView> card_icon_view = CreateInstrumentIconView( |
| 71 instrument_->icon_resource_id(), instrument_->label()); | 94 instrument_->icon_resource_id(), instrument_->label()); |
| 72 card_icon_view->SetImageSize(gfx::Size(32, 20)); | 95 card_icon_view->SetImageSize(gfx::Size(32, 20)); |
| 73 return std::move(card_icon_view); | 96 return std::move(card_icon_view); |
| 74 } | 97 } |
| 75 | 98 |
| 76 std::unique_ptr<views::View> CreateContentView() override { | 99 std::unique_ptr<views::View> CreateContentView() override { |
| 77 std::unique_ptr<views::View> card_info_container = | 100 std::unique_ptr<views::View> card_info_container = |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 // All items are enabled. | 139 // All items are enabled. |
| 117 return true; | 140 return true; |
| 118 } | 141 } |
| 119 | 142 |
| 120 bool CanBeSelected() override { | 143 bool CanBeSelected() override { |
| 121 // If an instrument can't be selected, PerformSelectionFallback is called, | 144 // If an instrument can't be selected, PerformSelectionFallback is called, |
| 122 // where the instrument can be made complete. | 145 // where the instrument can be made complete. |
| 123 return instrument_->IsCompleteForPayment(); | 146 return instrument_->IsCompleteForPayment(); |
| 124 } | 147 } |
| 125 | 148 |
| 126 void PerformSelectionFallback() override { | 149 void PerformSelectionFallback() override { ShowEditor(); } |
| 127 switch (instrument_->type()) { | 150 |
| 128 case PaymentInstrument::Type::AUTOFILL: | 151 void EditButtonPressed() override { ShowEditor(); } |
| 129 // Since we are a list item, we only care about the on_edited callback. | |
| 130 dialog_->ShowCreditCardEditor( | |
| 131 BackNavigationType::kPaymentSheet, | |
| 132 static_cast<int>(PaymentMethodViewControllerTags::MAX_TAG), | |
| 133 /*on_edited=*/ | |
| 134 base::BindOnce(&PaymentRequestState::SetSelectedInstrument, | |
| 135 base::Unretained(state()), instrument_), | |
| 136 /*on_added=*/ | |
| 137 base::OnceCallback<void(const autofill::CreditCard&)>(), | |
| 138 static_cast<AutofillPaymentInstrument*>(instrument_) | |
| 139 ->credit_card()); | |
| 140 return; | |
| 141 } | |
| 142 NOTREACHED(); | |
| 143 } | |
| 144 | 152 |
| 145 PaymentInstrument* instrument_; | 153 PaymentInstrument* instrument_; |
| 146 PaymentRequestDialogView* dialog_; | 154 PaymentRequestDialogView* dialog_; |
| 147 | 155 |
| 148 DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem); | 156 DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem); |
| 149 }; | 157 }; |
| 150 | 158 |
| 151 } // namespace | 159 } // namespace |
| 152 | 160 |
| 153 PaymentMethodViewController::PaymentMethodViewController( | 161 PaymentMethodViewController::PaymentMethodViewController( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 base::Unretained(state()), /*selected=*/true), | 224 base::Unretained(state()), /*selected=*/true), |
| 217 /*credit_card=*/nullptr); | 225 /*credit_card=*/nullptr); |
| 218 break; | 226 break; |
| 219 default: | 227 default: |
| 220 PaymentRequestSheetController::ButtonPressed(sender, event); | 228 PaymentRequestSheetController::ButtonPressed(sender, event); |
| 221 break; | 229 break; |
| 222 } | 230 } |
| 223 } | 231 } |
| 224 | 232 |
| 225 } // namespace payments | 233 } // namespace payments |
| OLD | NEW |