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

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

Issue 2759253002: [Web Payments] Implement item selection in lists. (Closed)
Patch Set: Assert back navigation in browser tests. Created 3 years, 9 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/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_dialog_view.h"
7 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" 8 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
8 #include "components/payments/content/payment_request_spec.h" 9 #include "components/payments/content/payment_request_spec.h"
9 #include "components/payments/content/payment_request_state.h" 10 #include "components/payments/content/payment_request_state.h"
10 11
11 namespace payments { 12 namespace payments {
12 13
13 namespace { 14 namespace {
14 15
15 class ShippingOptionItem : public PaymentRequestItemList::Item { 16 class ShippingOptionItem : public PaymentRequestItemList::Item {
16 public: 17 public:
17 ShippingOptionItem(payments::mojom::PaymentShippingOption* shipping_option, 18 ShippingOptionItem(payments::mojom::PaymentShippingOption* shipping_option,
18 PaymentRequestSpec* spec, 19 PaymentRequestSpec* spec,
19 PaymentRequestState* state, 20 PaymentRequestState* state,
20 PaymentRequestItemList* parent_list, 21 PaymentRequestItemList* parent_list,
22 PaymentRequestDialogView* dialog,
21 bool selected) 23 bool selected)
22 : PaymentRequestItemList::Item(spec, state, parent_list, selected), 24 : PaymentRequestItemList::Item(spec, state, parent_list, selected),
23 shipping_option_(shipping_option) {} 25 shipping_option_(shipping_option),
26 dialog_(dialog) {}
24 ~ShippingOptionItem() override {} 27 ~ShippingOptionItem() override {}
25 28
26 private: 29 private:
27 // payments::PaymentRequestItemList::Item: 30 // payments::PaymentRequestItemList::Item:
28 std::unique_ptr<views::View> CreateContentView() override { 31 std::unique_ptr<views::View> CreateContentView() override {
29 return CreateShippingOptionLabel( 32 return CreateShippingOptionLabel(
30 shipping_option_, 33 shipping_option_,
31 spec()->GetFormattedCurrencyAmount(shipping_option_->amount->value)); 34 spec()->GetFormattedCurrencyAmount(shipping_option_->amount->value));
32 } 35 }
33 36
34 void SelectedStateChanged() override {} 37 void SelectedStateChanged() override {
38 if (selected()) {
39 state()->SetSelectedShippingOption(shipping_option_);
40 dialog_->GoBack();
41 }
42 }
35 43
36 bool CanBeSelected() const override { 44 bool CanBeSelected() const override {
37 // Shipping options are vetted by the website; they're all OK to select. 45 // Shipping options are vetted by the website; they're all OK to select.
38 return true; 46 return true;
39 } 47 }
40 48
41 void PerformSelectionFallback() override { 49 void PerformSelectionFallback() override {
42 // Since CanBeSelected() is always true, this should never be called. 50 // Since CanBeSelected() is always true, this should never be called.
43 NOTREACHED(); 51 NOTREACHED();
44 } 52 }
45 53
46 mojom::PaymentShippingOption* shipping_option_; 54 mojom::PaymentShippingOption* shipping_option_;
55 PaymentRequestDialogView* dialog_;
47 56
48 DISALLOW_COPY_AND_ASSIGN(ShippingOptionItem); 57 DISALLOW_COPY_AND_ASSIGN(ShippingOptionItem);
49 }; 58 };
50 59
51 } // namespace 60 } // namespace
52 61
53 ShippingOptionViewController::ShippingOptionViewController( 62 ShippingOptionViewController::ShippingOptionViewController(
54 PaymentRequestSpec* spec, 63 PaymentRequestSpec* spec,
55 PaymentRequestState* state, 64 PaymentRequestState* state,
56 PaymentRequestDialogView* dialog) 65 PaymentRequestDialogView* dialog)
57 : PaymentRequestSheetController(spec, state, dialog) { 66 : PaymentRequestSheetController(spec, state, dialog) {
58 for (const auto& option : spec->details().shipping_options) { 67 for (const auto& option : spec->details().shipping_options) {
59 shipping_option_list_.AddItem(base::MakeUnique<ShippingOptionItem>( 68 shipping_option_list_.AddItem(base::MakeUnique<ShippingOptionItem>(
60 option.get(), spec, state, &shipping_option_list_, 69 option.get(), spec, state, &shipping_option_list_, dialog,
61 option.get() == state->selected_shipping_option())); 70 option.get() == state->selected_shipping_option()));
62 } 71 }
63 } 72 }
64 73
65 ShippingOptionViewController::~ShippingOptionViewController() {} 74 ShippingOptionViewController::~ShippingOptionViewController() {}
66 75
67 std::unique_ptr<views::View> ShippingOptionViewController::CreateView() { 76 std::unique_ptr<views::View> ShippingOptionViewController::CreateView() {
68 std::unique_ptr<views::View> list_view = 77 std::unique_ptr<views::View> list_view =
69 shipping_option_list_.CreateListView(); 78 shipping_option_list_.CreateListView();
70 return CreatePaymentView( 79 return CreatePaymentView(
71 CreateSheetHeaderView( 80 CreateSheetHeaderView(
72 true, GetShippingOptionSectionString(spec()->options().shipping_type), 81 true, GetShippingOptionSectionString(spec()->options().shipping_type),
73 this), 82 this),
74 std::move(list_view)); 83 std::move(list_view));
75 } 84 }
76 85
77 std::unique_ptr<views::View> 86 std::unique_ptr<views::View>
78 ShippingOptionViewController::CreateExtraFooterView() { 87 ShippingOptionViewController::CreateExtraFooterView() {
79 return nullptr; 88 return nullptr;
80 } 89 }
81 90
82 } // namespace payments 91 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698