Chromium Code Reviews| Index: chrome/browser/ui/views/payments/shipping_options_view_controller.cc |
| diff --git a/chrome/browser/ui/views/payments/shipping_options_view_controller.cc b/chrome/browser/ui/views/payments/shipping_options_view_controller.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a49e1d7b124aa32628a728e18dcdb2a3ea4d102c |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/payments/shipping_options_view_controller.cc |
| @@ -0,0 +1,75 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/views/payments/shipping_options_view_controller.h" |
| + |
| +#include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| +#include "components/payments/content/payment_request.h" |
| + |
| +namespace payments { |
| + |
| +namespace { |
| + |
| +class ShippingOptionItem : public PaymentRequestItemList::Item { |
| + public: |
| + ShippingOptionItem(payments::mojom::PaymentShippingOption* shipping_option, |
| + PaymentRequest* request, |
| + PaymentRequestItemList* parent_list, |
| + bool selected) |
| + : PaymentRequestItemList::Item(request, parent_list, selected), |
| + shipping_option_(shipping_option) {} |
| + ~ShippingOptionItem() override {} |
| + |
| + private: |
| + // payments::PaymentRequestItemList::Item: |
| + std::unique_ptr<views::View> CreateItemView() override { |
| + return CreateShippingOptionLabel( |
| + shipping_option_, |
| + request()->GetFormattedCurrencyAmount(shipping_option_->amount->value)); |
| + } |
| + |
| + void SelectedStateChanged() override {} |
| + |
| + payments::mojom::PaymentShippingOption* shipping_option_; |
|
Mathieu
2017/03/14 20:17:12
No need for payments::
anthonyvd
2017/03/14 20:26:16
Done.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(ShippingOptionItem); |
| +}; |
| + |
| +} // namespace |
| + |
| +ShippingOptionsViewController::ShippingOptionsViewController( |
| + PaymentRequest* request, |
| + PaymentRequestDialogView* dialog) |
| + : PaymentRequestSheetController(request, dialog) { |
| + for (const auto& option : request->details()->shipping_options) { |
| + shipping_option_list_.AddItem(base::MakeUnique<ShippingOptionItem>( |
| + option.get(), request, &shipping_option_list_, |
| + option.get() == request->selected_shipping_option())); |
| + } |
| +} |
| + |
| +ShippingOptionsViewController::~ShippingOptionsViewController() {} |
| + |
| +std::unique_ptr<views::View> ShippingOptionsViewController::CreateView() { |
| + std::unique_ptr<views::View> list_view = |
| + shipping_option_list_.CreateListView(); |
| + return CreatePaymentView( |
| + CreateSheetHeaderView( |
| + true, |
| + GetShippingOptionSectionString(request()->options()->shipping_type), |
| + this), |
| + std::move(list_view)); |
| +} |
| + |
| +std::unique_ptr<views::View> |
| +ShippingOptionsViewController::CreateExtraFooterView() { |
| + return nullptr; |
| +} |
| + |
| +void ShippingOptionsViewController::ButtonPressed(views::Button* sender, |
| + const ui::Event& event) { |
| + PaymentRequestSheetController::ButtonPressed(sender, event); |
| +} |
| + |
| +} // namespace payments |