| 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_view.h" | 5 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "chrome/browser/ui/views/payments/credit_card_editor_view_controller.h" |
| 11 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h" | 12 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h" |
| 12 #include "chrome/browser/ui/views/payments/payment_method_view_controller.h" | 13 #include "chrome/browser/ui/views/payments/payment_method_view_controller.h" |
| 13 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h" | 14 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h" |
| 14 #include "chrome/browser/ui/views/payments/shipping_list_view_controller.h" | 15 #include "chrome/browser/ui/views/payments/shipping_list_view_controller.h" |
| 15 #include "chrome/grit/generated_resources.h" | |
| 16 #include "components/constrained_window/constrained_window_views.h" | 16 #include "components/constrained_window/constrained_window_views.h" |
| 17 #include "components/payments/payment_request.h" | 17 #include "components/payments/payment_request.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | |
| 20 #include "ui/views/layout/fill_layout.h" | 19 #include "ui/views/layout/fill_layout.h" |
| 21 | 20 |
| 22 namespace chrome { | 21 namespace chrome { |
| 23 | 22 |
| 24 payments::PaymentRequestDialog* CreatePaymentRequestDialog( | 23 payments::PaymentRequestDialog* CreatePaymentRequestDialog( |
| 25 payments::PaymentRequest* request) { | 24 payments::PaymentRequest* request) { |
| 26 return new payments::PaymentRequestDialogView(request, | 25 return new payments::PaymentRequestDialogView(request, |
| 27 /* no observer */ nullptr); | 26 /* no observer */ nullptr); |
| 28 } | 27 } |
| 29 | 28 |
| 30 } // namespace chrome | 29 } // namespace chrome |
| 31 | 30 |
| 32 namespace payments { | 31 namespace payments { |
| 33 namespace { | 32 namespace { |
| 34 | 33 |
| 35 // This function creates an instance of a PaymentRequestSheetController | 34 // This function creates an instance of a PaymentRequestSheetController |
| 36 // subclass of concrete type |Controller|, passing it non-owned pointers to | 35 // subclass of concrete type |Controller|, passing it non-owned pointers to |
| 37 // |dialog| and the |request| that initiated that dialog. |map| should be owned | 36 // |dialog| and the |request| that initiated that dialog. |map| should be owned |
| 38 // by |dialog|. | 37 // by |dialog|. |
| 39 template <typename Controller> | |
| 40 std::unique_ptr<views::View> CreateViewAndInstallController( | 38 std::unique_ptr<views::View> CreateViewAndInstallController( |
| 41 payments::ControllerMap* map, | 39 std::unique_ptr<PaymentRequestSheetController> controller, |
| 42 payments::PaymentRequest* request, | 40 payments::ControllerMap* map) { |
| 43 payments::PaymentRequestDialogView* dialog) { | |
| 44 std::unique_ptr<Controller> controller = | |
| 45 base::MakeUnique<Controller>(request, dialog); | |
| 46 std::unique_ptr<views::View> view = controller->CreateView(); | 41 std::unique_ptr<views::View> view = controller->CreateView(); |
| 47 (*map)[view.get()] = std::move(controller); | 42 (*map)[view.get()] = std::move(controller); |
| 48 return view; | 43 return view; |
| 49 } | 44 } |
| 50 | 45 |
| 51 } // namespace | 46 } // namespace |
| 52 | 47 |
| 53 PaymentRequestDialogView::PaymentRequestDialogView( | 48 PaymentRequestDialogView::PaymentRequestDialogView( |
| 54 PaymentRequest* request, | 49 PaymentRequest* request, |
| 55 PaymentRequestDialogView::ObserverForTest* observer) | 50 PaymentRequestDialogView::ObserverForTest* observer) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 84 |
| 90 int PaymentRequestDialogView::GetDialogButtons() const { | 85 int PaymentRequestDialogView::GetDialogButtons() const { |
| 91 // The buttons should animate along with the different dialog sheets since | 86 // The buttons should animate along with the different dialog sheets since |
| 92 // each sheet presents a different set of buttons. Because of this, hide the | 87 // each sheet presents a different set of buttons. Because of this, hide the |
| 93 // usual dialog buttons. | 88 // usual dialog buttons. |
| 94 return ui::DIALOG_BUTTON_NONE; | 89 return ui::DIALOG_BUTTON_NONE; |
| 95 } | 90 } |
| 96 | 91 |
| 97 void PaymentRequestDialogView::GoBack() { | 92 void PaymentRequestDialogView::GoBack() { |
| 98 view_stack_.Pop(); | 93 view_stack_.Pop(); |
| 94 |
| 95 if (observer_for_testing_) |
| 96 observer_for_testing_->OnBackNavigation(); |
| 99 } | 97 } |
| 100 | 98 |
| 101 void PaymentRequestDialogView::ShowOrderSummary() { | 99 void PaymentRequestDialogView::ShowOrderSummary() { |
| 102 view_stack_.Push(CreateViewAndInstallController<OrderSummaryViewController>( | 100 view_stack_.Push( |
| 103 &controller_map_, request_, this), | 101 CreateViewAndInstallController( |
| 104 /* animate = */ true); | 102 base::MakeUnique<OrderSummaryViewController>(request_, this), |
| 105 | 103 &controller_map_), |
| 104 /* animate = */ true); |
| 106 if (observer_for_testing_) | 105 if (observer_for_testing_) |
| 107 observer_for_testing_->OnOrderSummaryOpened(); | 106 observer_for_testing_->OnOrderSummaryOpened(); |
| 108 } | 107 } |
| 109 | 108 |
| 110 void PaymentRequestDialogView::ShowPaymentMethodSheet() { | 109 void PaymentRequestDialogView::ShowPaymentMethodSheet() { |
| 111 view_stack_.Push(CreateViewAndInstallController<PaymentMethodViewController>( | 110 view_stack_.Push( |
| 112 &controller_map_, request_, this), | 111 CreateViewAndInstallController( |
| 113 /* animate = */ true); | 112 base::MakeUnique<PaymentMethodViewController>(request_, this), |
| 113 &controller_map_), |
| 114 /* animate = */ true); |
| 115 if (observer_for_testing_) |
| 116 observer_for_testing_->OnPaymentMethodOpened(); |
| 114 } | 117 } |
| 115 | 118 |
| 116 void PaymentRequestDialogView::ShowShippingListSheet() { | 119 void PaymentRequestDialogView::ShowShippingListSheet() { |
| 117 view_stack_.Push(CreateViewAndInstallController<ShippingListViewController>( | 120 view_stack_.Push( |
| 118 &controller_map_, request_, this), | 121 CreateViewAndInstallController( |
| 119 /* animate = */ true); | 122 base::MakeUnique<ShippingListViewController>(request_, this), |
| 123 &controller_map_), |
| 124 /* animate = */ true); |
| 125 } |
| 126 |
| 127 void PaymentRequestDialogView::ShowCreditCardEditor() { |
| 128 view_stack_.Push( |
| 129 CreateViewAndInstallController( |
| 130 base::MakeUnique<CreditCardEditorViewController>(request_, this), |
| 131 &controller_map_), |
| 132 /* animate = */ true); |
| 133 if (observer_for_testing_) |
| 134 observer_for_testing_->OnCreditCardEditorOpened(); |
| 120 } | 135 } |
| 121 | 136 |
| 122 void PaymentRequestDialogView::ShowDialog() { | 137 void PaymentRequestDialogView::ShowDialog() { |
| 123 constrained_window::ShowWebModalDialogViews(this, request_->web_contents()); | 138 constrained_window::ShowWebModalDialogViews(this, request_->web_contents()); |
| 124 } | 139 } |
| 125 | 140 |
| 126 void PaymentRequestDialogView::CloseDialog() { | 141 void PaymentRequestDialogView::CloseDialog() { |
| 127 // This calls PaymentRequestDialogView::Cancel() before closing. | 142 // This calls PaymentRequestDialogView::Cancel() before closing. |
| 128 GetWidget()->Close(); | 143 GetWidget()->Close(); |
| 129 } | 144 } |
| 130 | 145 |
| 131 void PaymentRequestDialogView::ShowInitialPaymentSheet() { | 146 void PaymentRequestDialogView::ShowInitialPaymentSheet() { |
| 132 view_stack_.Push(CreateViewAndInstallController<PaymentSheetViewController>( | 147 view_stack_.Push( |
| 133 &controller_map_, request_, this), | 148 CreateViewAndInstallController( |
| 134 /* animate = */ false); | 149 base::MakeUnique<PaymentSheetViewController>(request_, this), |
| 150 &controller_map_), |
| 151 /* animate = */ false); |
| 135 if (observer_for_testing_) | 152 if (observer_for_testing_) |
| 136 observer_for_testing_->OnDialogOpened(); | 153 observer_for_testing_->OnDialogOpened(); |
| 137 } | 154 } |
| 138 | 155 |
| 139 gfx::Size PaymentRequestDialogView::GetPreferredSize() const { | 156 gfx::Size PaymentRequestDialogView::GetPreferredSize() const { |
| 140 return gfx::Size(450, 450); | 157 return gfx::Size(450, 450); |
| 141 } | 158 } |
| 142 | 159 |
| 143 void PaymentRequestDialogView::ViewHierarchyChanged( | 160 void PaymentRequestDialogView::ViewHierarchyChanged( |
| 144 const ViewHierarchyChangedDetails& details) { | 161 const ViewHierarchyChangedDetails& details) { |
| 145 // When a view that is associated with a controller is removed from this | 162 // When a view that is associated with a controller is removed from this |
| 146 // view's descendants, dispose of the controller. | 163 // view's descendants, dispose of the controller. |
| 147 if (!details.is_add && | 164 if (!details.is_add && |
| 148 controller_map_.find(details.child) != controller_map_.end()) { | 165 controller_map_.find(details.child) != controller_map_.end()) { |
| 149 DCHECK(!details.move_view); | 166 DCHECK(!details.move_view); |
| 150 controller_map_.erase(details.child); | 167 controller_map_.erase(details.child); |
| 151 } | 168 } |
| 152 } | 169 } |
| 153 | 170 |
| 154 } // namespace payments | 171 } // namespace payments |
| OLD | NEW |