| 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/shipping_option_view_controller.h" | 5 #include "chrome/browser/ui/views/payments/shipping_option_view_controller.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 7 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| 8 #include "components/payments/content/payment_request.h" | |
| 9 #include "components/payments/content/payment_request_spec.h" | 8 #include "components/payments/content/payment_request_spec.h" |
| 9 #include "components/payments/content/payment_request_state.h" |
| 10 | 10 |
| 11 namespace payments { | 11 namespace payments { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 class ShippingOptionItem : public PaymentRequestItemList::Item { | 15 class ShippingOptionItem : public PaymentRequestItemList::Item { |
| 16 public: | 16 public: |
| 17 ShippingOptionItem(payments::mojom::PaymentShippingOption* shipping_option, | 17 ShippingOptionItem(payments::mojom::PaymentShippingOption* shipping_option, |
| 18 PaymentRequest* request, | 18 PaymentRequestSpec* spec, |
| 19 PaymentRequestState* state, |
| 19 PaymentRequestItemList* parent_list, | 20 PaymentRequestItemList* parent_list, |
| 20 bool selected) | 21 bool selected) |
| 21 : PaymentRequestItemList::Item(request, parent_list, selected), | 22 : PaymentRequestItemList::Item(spec, state, parent_list, selected), |
| 22 shipping_option_(shipping_option) {} | 23 shipping_option_(shipping_option) {} |
| 23 ~ShippingOptionItem() override {} | 24 ~ShippingOptionItem() override {} |
| 24 | 25 |
| 25 private: | 26 private: |
| 26 // payments::PaymentRequestItemList::Item: | 27 // payments::PaymentRequestItemList::Item: |
| 27 std::unique_ptr<views::View> CreateItemView() override { | 28 std::unique_ptr<views::View> CreateItemView() override { |
| 28 return CreateShippingOptionLabel( | 29 return CreateShippingOptionLabel( |
| 29 shipping_option_, request()->spec()->GetFormattedCurrencyAmount( | 30 shipping_option_, |
| 30 shipping_option_->amount->value)); | 31 spec()->GetFormattedCurrencyAmount(shipping_option_->amount->value)); |
| 31 } | 32 } |
| 32 | 33 |
| 33 void SelectedStateChanged() override {} | 34 void SelectedStateChanged() override {} |
| 34 | 35 |
| 35 mojom::PaymentShippingOption* shipping_option_; | 36 mojom::PaymentShippingOption* shipping_option_; |
| 36 | 37 |
| 37 DISALLOW_COPY_AND_ASSIGN(ShippingOptionItem); | 38 DISALLOW_COPY_AND_ASSIGN(ShippingOptionItem); |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 } // namespace | 41 } // namespace |
| 41 | 42 |
| 42 ShippingOptionViewController::ShippingOptionViewController( | 43 ShippingOptionViewController::ShippingOptionViewController( |
| 43 PaymentRequest* request, | 44 PaymentRequestSpec* spec, |
| 45 PaymentRequestState* state, |
| 44 PaymentRequestDialogView* dialog) | 46 PaymentRequestDialogView* dialog) |
| 45 : PaymentRequestSheetController(request, dialog) { | 47 : PaymentRequestSheetController(spec, state, dialog) { |
| 46 for (const auto& option : request->spec()->details().shipping_options) { | 48 for (const auto& option : spec->details().shipping_options) { |
| 47 shipping_option_list_.AddItem(base::MakeUnique<ShippingOptionItem>( | 49 shipping_option_list_.AddItem(base::MakeUnique<ShippingOptionItem>( |
| 48 option.get(), request, &shipping_option_list_, | 50 option.get(), spec, state, &shipping_option_list_, |
| 49 option.get() == request->state()->selected_shipping_option())); | 51 option.get() == state->selected_shipping_option())); |
| 50 } | 52 } |
| 51 } | 53 } |
| 52 | 54 |
| 53 ShippingOptionViewController::~ShippingOptionViewController() {} | 55 ShippingOptionViewController::~ShippingOptionViewController() {} |
| 54 | 56 |
| 55 std::unique_ptr<views::View> ShippingOptionViewController::CreateView() { | 57 std::unique_ptr<views::View> ShippingOptionViewController::CreateView() { |
| 56 std::unique_ptr<views::View> list_view = | 58 std::unique_ptr<views::View> list_view = |
| 57 shipping_option_list_.CreateListView(); | 59 shipping_option_list_.CreateListView(); |
| 58 return CreatePaymentView( | 60 return CreatePaymentView( |
| 59 CreateSheetHeaderView(true, | 61 CreateSheetHeaderView( |
| 60 GetShippingOptionSectionString( | 62 true, GetShippingOptionSectionString(spec()->options().shipping_type), |
| 61 request()->spec()->options().shipping_type), | 63 this), |
| 62 this), | |
| 63 std::move(list_view)); | 64 std::move(list_view)); |
| 64 } | 65 } |
| 65 | 66 |
| 66 std::unique_ptr<views::View> | 67 std::unique_ptr<views::View> |
| 67 ShippingOptionViewController::CreateExtraFooterView() { | 68 ShippingOptionViewController::CreateExtraFooterView() { |
| 68 return nullptr; | 69 return nullptr; |
| 69 } | 70 } |
| 70 | 71 |
| 71 } // namespace payments | 72 } // namespace payments |
| OLD | NEW |