| 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/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/payments/payment_request_impl.h" | 8 #include "chrome/browser/payments/payment_request_impl.h" |
| 9 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h" |
| 10 #include "chrome/browser/ui/views/payments/payment_request_views_util.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 #include "ui/views/layout/grid_layout.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 // The tag for the button that navigates back to the payment sheet. | 21 template<typename Controller> |
| 21 constexpr int kBackButtonTag = 0; | 22 std::unique_ptr<views::View> CreateViewAndInstallController( |
| 22 | 23 payments::ControllerMap* map, |
| 23 // The tag for the button that navigates to the Order Summary sheet. | 24 payments::PaymentRequestImpl* impl, |
| 24 constexpr int kOrderSummaryTag = 1; | 25 payments::PaymentRequestDialog* dialog) { |
| 25 | 26 std::unique_ptr<Controller> controller = |
| 26 std::unique_ptr<views::View> CreateOrderSummaryView( | 27 base::MakeUnique<Controller>(impl, dialog); |
| 27 views::ButtonListener* button_listener) { | 28 std::unique_ptr<views::View> view = controller->CreateView(); |
| 28 std::unique_ptr<views::View> view = base::MakeUnique<views::View>(); | 29 (*map)[view.get()] = std::move(controller); |
| 29 | |
| 30 views::GridLayout* layout = new views::GridLayout(view.get()); | |
| 31 view->SetLayoutManager(layout); | |
| 32 views::ColumnSet* columns = layout->AddColumnSet(0); | |
| 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; | 30 return view; |
| 48 } | 31 } |
| 49 | 32 |
| 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 | 33 } // namespace |
| 75 | 34 |
| 76 namespace chrome { | 35 namespace chrome { |
| 77 | 36 |
| 78 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) { | 37 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) { |
| 79 constrained_window::ShowWebModalDialogViews( | 38 constrained_window::ShowWebModalDialogViews( |
| 80 new payments::PaymentRequestDialog(impl), impl->web_contents()); | 39 new payments::PaymentRequestDialog(impl), impl->web_contents()); |
| 81 } | 40 } |
| 82 | 41 |
| 83 } // namespace chrome | 42 } // namespace chrome |
| (...skipping 10 matching lines...) Expand all Loading... |
| 94 | 53 |
| 95 ShowInitialPaymentSheet(); | 54 ShowInitialPaymentSheet(); |
| 96 } | 55 } |
| 97 | 56 |
| 98 PaymentRequestDialog::~PaymentRequestDialog() {} | 57 PaymentRequestDialog::~PaymentRequestDialog() {} |
| 99 | 58 |
| 100 ui::ModalType PaymentRequestDialog::GetModalType() const { | 59 ui::ModalType PaymentRequestDialog::GetModalType() const { |
| 101 return ui::MODAL_TYPE_CHILD; | 60 return ui::MODAL_TYPE_CHILD; |
| 102 } | 61 } |
| 103 | 62 |
| 104 gfx::Size PaymentRequestDialog::GetPreferredSize() const { | |
| 105 return gfx::Size(300, 300); | |
| 106 } | |
| 107 | |
| 108 bool PaymentRequestDialog::Cancel() { | 63 bool PaymentRequestDialog::Cancel() { |
| 109 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 64 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 110 impl_->Cancel(); | 65 impl_->Cancel(); |
| 111 return true; | 66 return true; |
| 112 } | 67 } |
| 113 | 68 |
| 114 void PaymentRequestDialog::ShowInitialPaymentSheet() { | 69 void PaymentRequestDialog::ShowInitialPaymentSheet() { |
| 115 view_stack_.Push(CreatePaymentSheetView(this), false); | 70 view_stack_.Push( |
| 71 CreateViewAndInstallController<PaymentSheetViewController>( |
| 72 &controller_map_, impl_, this), |
| 73 false); |
| 116 } | 74 } |
| 117 | 75 |
| 118 void PaymentRequestDialog::ShowOrderSummary() { | 76 void PaymentRequestDialog::ShowOrderSummary() { |
| 119 view_stack_.Push(CreateOrderSummaryView(this), true); | 77 view_stack_.Push( |
| 78 CreateViewAndInstallController<OrderSummaryViewController>( |
| 79 &controller_map_, impl_, this), |
| 80 true); |
| 120 } | 81 } |
| 121 | 82 |
| 122 void PaymentRequestDialog::GoBack() { | 83 void PaymentRequestDialog::GoBack() { |
| 123 view_stack_.Pop(); | 84 view_stack_.Pop(); |
| 124 } | 85 } |
| 125 | 86 |
| 126 void PaymentRequestDialog::ButtonPressed( | 87 gfx::Size PaymentRequestDialog::GetPreferredSize() const { |
| 127 views::Button* sender, const ui::Event& event) { | 88 return gfx::Size(450, 450); |
| 128 if (sender->tag() == kBackButtonTag) { | 89 } |
| 129 GoBack(); | 90 |
| 130 } else if (sender->tag() == kOrderSummaryTag) { | 91 void PaymentRequestDialog::ViewHierarchyChanged( |
| 131 ShowOrderSummary(); | 92 const ViewHierarchyChangedDetails& details) { |
| 93 // When a view that is associated with a controller is removed from this |
| 94 // view's descendants, dispose of the controller. |
| 95 if (!details.is_add && |
| 96 controller_map_.find(details.child) != controller_map_.end()) { |
| 97 DCHECK(!details.move_view); |
| 98 controller_map_.erase(details.child); |
| 132 } | 99 } |
| 133 } | 100 } |
| 134 | 101 |
| 135 } // namespace payments | 102 } // namespace payments |
| OLD | NEW |