OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_request_dialog.h" | 5 #include "chrome/browser/ui/views/payments/payment_request_dialog.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ptr_util.h" | |
8 #include "chrome/browser/payments/payment_request_impl.h" | 9 #include "chrome/browser/payments/payment_request_impl.h" |
10 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h" | |
11 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h" | |
9 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
10 #include "components/constrained_window/constrained_window_views.h" | 13 #include "components/constrained_window/constrained_window_views.h" |
11 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
12 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
13 #include "ui/views/controls/button/md_text_button.h" | |
14 #include "ui/views/controls/label.h" | |
15 #include "ui/views/layout/fill_layout.h" | 16 #include "ui/views/layout/fill_layout.h" |
16 #include "ui/views/layout/grid_layout.h" | |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // The tag for the button that navigates back to the payment sheet. | 20 // This function creates an instance of a PaymentRequestSheetController |
21 constexpr int kBackButtonTag = 0; | 21 // subclass of concrete type |Controller|, passing it non-owned pointers to |
22 | 22 // |dialog| and the |impl| that initiated that dialog. |map| should be owned by |
23 // The tag for the button that navigates to the Order Summary sheet. | 23 // |dialog|. |
24 constexpr int kOrderSummaryTag = 1; | 24 template<typename Controller> |
25 | 25 std::unique_ptr<views::View> CreateViewAndInstallController( |
26 std::unique_ptr<views::View> CreateOrderSummaryView( | 26 payments::ControllerMap* map, |
27 views::ButtonListener* button_listener) { | 27 payments::PaymentRequestImpl* impl, |
28 std::unique_ptr<views::View> view = base::MakeUnique<views::View>(); | 28 payments::PaymentRequestDialog* dialog) { |
29 | 29 std::unique_ptr<Controller> controller = |
30 views::GridLayout* layout = new views::GridLayout(view.get()); | 30 base::MakeUnique<Controller>(impl, dialog); |
31 view->SetLayoutManager(layout); | 31 std::unique_ptr<views::View> view = controller->CreateView(); |
32 views::ColumnSet* columns = layout->AddColumnSet(0); | 32 (*map)[view.get()] = std::move(controller); |
please use gerrit instead
2016/12/15 20:29:33
#inclued <utility>
anthonyvd
2016/12/15 20:58:08
Done.
| |
33 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | |
34 0, views::GridLayout::USE_PREF, 0, 0); | |
35 | |
36 layout->StartRow(0, 0); | |
37 layout->AddView(new views::Label( | |
38 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_TITLE))); | |
39 | |
40 layout->StartRow(0, 0); | |
41 views::LabelButton* back_button = | |
42 views::MdTextButton::CreateSecondaryUiBlueButton( | |
43 button_listener, base::ASCIIToUTF16("Back")); | |
44 back_button->set_tag(kBackButtonTag); | |
45 layout->AddView(back_button); | |
46 | |
47 return view; | 33 return view; |
48 } | 34 } |
49 | 35 |
50 std::unique_ptr<views::View> CreatePaymentSheetView( | |
51 views::ButtonListener* button_listener) { | |
52 std::unique_ptr<views::View> view = base::MakeUnique<views::View>(); | |
53 | |
54 views::GridLayout* layout = new views::GridLayout(view.get()); | |
55 view->SetLayoutManager(layout); | |
56 views::ColumnSet* columns = layout->AddColumnSet(0); | |
57 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | |
58 0, views::GridLayout::USE_PREF, 0, 0); | |
59 | |
60 layout->StartRow(0, 0); | |
61 layout->AddView(new views::Label( | |
62 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE))); | |
63 | |
64 layout->StartRow(0, 0); | |
65 views::LabelButton* order_summary_button = | |
66 views::MdTextButton::CreateSecondaryUiBlueButton( | |
67 button_listener, base::ASCIIToUTF16("Order Summary")); | |
68 order_summary_button->set_tag(kOrderSummaryTag); | |
69 layout->AddView(order_summary_button); | |
70 | |
71 return view; | |
72 } | |
73 | |
74 } // namespace | 36 } // namespace |
75 | 37 |
76 namespace chrome { | 38 namespace chrome { |
77 | 39 |
78 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) { | 40 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) { |
79 constrained_window::ShowWebModalDialogViews( | 41 constrained_window::ShowWebModalDialogViews( |
80 new payments::PaymentRequestDialog(impl), impl->web_contents()); | 42 new payments::PaymentRequestDialog(impl), impl->web_contents()); |
81 } | 43 } |
82 | 44 |
83 } // namespace chrome | 45 } // namespace chrome |
(...skipping 10 matching lines...) Expand all Loading... | |
94 | 56 |
95 ShowInitialPaymentSheet(); | 57 ShowInitialPaymentSheet(); |
96 } | 58 } |
97 | 59 |
98 PaymentRequestDialog::~PaymentRequestDialog() {} | 60 PaymentRequestDialog::~PaymentRequestDialog() {} |
99 | 61 |
100 ui::ModalType PaymentRequestDialog::GetModalType() const { | 62 ui::ModalType PaymentRequestDialog::GetModalType() const { |
101 return ui::MODAL_TYPE_CHILD; | 63 return ui::MODAL_TYPE_CHILD; |
102 } | 64 } |
103 | 65 |
104 gfx::Size PaymentRequestDialog::GetPreferredSize() const { | |
105 return gfx::Size(300, 300); | |
106 } | |
107 | |
108 bool PaymentRequestDialog::Cancel() { | 66 bool PaymentRequestDialog::Cancel() { |
109 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 67 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
110 impl_->Cancel(); | 68 impl_->Cancel(); |
111 return true; | 69 return true; |
112 } | 70 } |
113 | 71 |
114 void PaymentRequestDialog::ShowInitialPaymentSheet() { | |
115 view_stack_.Push(CreatePaymentSheetView(this), false); | |
116 } | |
117 | |
118 void PaymentRequestDialog::ShowOrderSummary() { | |
119 view_stack_.Push(CreateOrderSummaryView(this), true); | |
120 } | |
121 | |
122 void PaymentRequestDialog::GoBack() { | 72 void PaymentRequestDialog::GoBack() { |
123 view_stack_.Pop(); | 73 view_stack_.Pop(); |
124 } | 74 } |
125 | 75 |
126 void PaymentRequestDialog::ButtonPressed( | 76 void PaymentRequestDialog::ShowOrderSummary() { |
127 views::Button* sender, const ui::Event& event) { | 77 view_stack_.Push( |
128 if (sender->tag() == kBackButtonTag) { | 78 CreateViewAndInstallController<OrderSummaryViewController>( |
129 GoBack(); | 79 &controller_map_, impl_, this), |
130 } else if (sender->tag() == kOrderSummaryTag) { | 80 true); |
131 ShowOrderSummary(); | 81 } |
82 | |
83 void PaymentRequestDialog::ShowInitialPaymentSheet() { | |
84 view_stack_.Push( | |
85 CreateViewAndInstallController<PaymentSheetViewController>( | |
86 &controller_map_, impl_, this), | |
87 false); | |
88 } | |
89 | |
90 gfx::Size PaymentRequestDialog::GetPreferredSize() const { | |
91 return gfx::Size(450, 450); | |
92 } | |
93 | |
94 void PaymentRequestDialog::ViewHierarchyChanged( | |
95 const ViewHierarchyChangedDetails& details) { | |
96 // When a view that is associated with a controller is removed from this | |
97 // view's descendants, dispose of the controller. | |
98 if (!details.is_add && | |
99 controller_map_.find(details.child) != controller_map_.end()) { | |
100 DCHECK(!details.move_view); | |
101 controller_map_.erase(details.child); | |
132 } | 102 } |
133 } | 103 } |
134 | 104 |
135 } // namespace payments | 105 } // namespace payments |
OLD | NEW |