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 <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/payments/payment_request_impl.h" | 11 #include "chrome/browser/payments/payment_request_impl.h" |
12 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h" | 12 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h" |
13 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h" | 13 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h" |
14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
15 #include "components/constrained_window/constrained_window_views.h" | 15 #include "components/constrained_window/constrained_window_views.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/views/layout/fill_layout.h" | 18 #include "ui/views/layout/fill_layout.h" |
19 | 19 |
20 namespace chrome { | |
21 | |
22 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) { | |
23 constrained_window::ShowWebModalDialogViews( | |
24 new payments::PaymentRequestDialog(impl), impl->web_contents()); | |
25 } | |
26 | |
27 } // namespace chrome | |
28 | |
29 namespace payments { | |
30 | |
please use gerrit instead
2017/01/04 19:17:11
nit: no blank line
anthonyvd
2017/01/05 16:45:42
Done.
| |
20 namespace { | 31 namespace { |
21 | 32 |
22 // This function creates an instance of a PaymentRequestSheetController | 33 // This function creates an instance of a PaymentRequestSheetController |
23 // subclass of concrete type |Controller|, passing it non-owned pointers to | 34 // subclass of concrete type |Controller|, passing it non-owned pointers to |
24 // |dialog| and the |impl| that initiated that dialog. |map| should be owned by | 35 // |dialog| and the |impl| that initiated that dialog. |map| should be owned by |
25 // |dialog|. | 36 // |dialog|. |
26 template<typename Controller> | 37 template<typename Controller> |
27 std::unique_ptr<views::View> CreateViewAndInstallController( | 38 std::unique_ptr<views::View> CreateViewAndInstallController( |
28 payments::ControllerMap* map, | 39 payments::ControllerMap* map, |
29 payments::PaymentRequestImpl* impl, | 40 payments::PaymentRequestImpl* impl, |
30 payments::PaymentRequestDialog* dialog) { | 41 payments::PaymentRequestDialog* dialog) { |
31 std::unique_ptr<Controller> controller = | 42 std::unique_ptr<Controller> controller = |
32 base::MakeUnique<Controller>(impl, dialog); | 43 base::MakeUnique<Controller>(impl, dialog); |
33 std::unique_ptr<views::View> view = controller->CreateView(); | 44 std::unique_ptr<views::View> view = controller->CreateView(); |
34 (*map)[view.get()] = std::move(controller); | 45 (*map)[view.get()] = std::move(controller); |
35 return view; | 46 return view; |
36 } | 47 } |
37 | 48 |
38 } // namespace | 49 } // namespace |
39 | 50 |
40 namespace chrome { | |
41 | |
42 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) { | |
43 constrained_window::ShowWebModalDialogViews( | |
44 new payments::PaymentRequestDialog(impl), impl->web_contents()); | |
45 } | |
46 | |
47 } // namespace chrome | |
48 | |
49 namespace payments { | |
50 | |
51 PaymentRequestDialog::PaymentRequestDialog(PaymentRequestImpl* impl) | 51 PaymentRequestDialog::PaymentRequestDialog(PaymentRequestImpl* impl) |
52 : impl_(impl) { | 52 : impl_(impl) { |
53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
54 SetLayoutManager(new views::FillLayout()); | 54 SetLayoutManager(new views::FillLayout()); |
55 | 55 |
56 view_stack_.set_owned_by_client(); | 56 view_stack_.set_owned_by_client(); |
57 AddChildView(&view_stack_); | 57 AddChildView(&view_stack_); |
58 | 58 |
59 ShowInitialPaymentSheet(); | 59 ShowInitialPaymentSheet(); |
60 } | 60 } |
61 | 61 |
62 PaymentRequestDialog::~PaymentRequestDialog() {} | 62 PaymentRequestDialog::~PaymentRequestDialog() {} |
63 | 63 |
64 ui::ModalType PaymentRequestDialog::GetModalType() const { | 64 ui::ModalType PaymentRequestDialog::GetModalType() const { |
65 return ui::MODAL_TYPE_CHILD; | 65 return ui::MODAL_TYPE_CHILD; |
66 } | 66 } |
67 | 67 |
68 bool PaymentRequestDialog::Cancel() { | 68 bool PaymentRequestDialog::Cancel() { |
69 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 69 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
70 impl_->Cancel(); | 70 impl_->Cancel(); |
71 return true; | 71 return true; |
72 } | 72 } |
73 | 73 |
74 bool PaymentRequestDialog::ShouldShowCloseButton() const { | |
75 // Don't show the normal close button on the dialog. This is because the | |
76 // typical dialog header doesn't allow displaying anything other that the | |
77 // title and the close button. This is insufficient for the PaymentRequest | |
78 // dialog, which must sometimes show the back arrow next to the title. | |
79 // Moreover, the title (and back arrow) should animate with the view they're | |
80 // attached to. | |
81 return false; | |
82 } | |
83 | |
84 int PaymentRequestDialog::GetDialogButtons() const { | |
85 // The buttons should animate along with the different dialog sheets since | |
86 // each sheet presents a different set of buttons. Because of this, hide the | |
87 // usual dialog buttons. | |
88 return ui::DIALOG_BUTTON_NONE; | |
89 } | |
90 | |
74 void PaymentRequestDialog::GoBack() { | 91 void PaymentRequestDialog::GoBack() { |
75 view_stack_.Pop(); | 92 view_stack_.Pop(); |
76 } | 93 } |
77 | 94 |
78 void PaymentRequestDialog::ShowOrderSummary() { | 95 void PaymentRequestDialog::ShowOrderSummary() { |
79 view_stack_.Push( | 96 view_stack_.Push( |
80 CreateViewAndInstallController<OrderSummaryViewController>( | 97 CreateViewAndInstallController<OrderSummaryViewController>( |
81 &controller_map_, impl_, this), | 98 &controller_map_, impl_, this), |
82 true); | 99 true); |
83 } | 100 } |
84 | 101 |
102 void PaymentRequestDialog::CloseDialog() { | |
103 GetWidget()->Close(); | |
104 } | |
105 | |
85 void PaymentRequestDialog::ShowInitialPaymentSheet() { | 106 void PaymentRequestDialog::ShowInitialPaymentSheet() { |
86 view_stack_.Push( | 107 view_stack_.Push( |
87 CreateViewAndInstallController<PaymentSheetViewController>( | 108 CreateViewAndInstallController<PaymentSheetViewController>( |
88 &controller_map_, impl_, this), | 109 &controller_map_, impl_, this), |
89 false); | 110 false); |
90 } | 111 } |
91 | 112 |
92 gfx::Size PaymentRequestDialog::GetPreferredSize() const { | 113 gfx::Size PaymentRequestDialog::GetPreferredSize() const { |
93 return gfx::Size(450, 450); | 114 return gfx::Size(450, 450); |
94 } | 115 } |
95 | 116 |
96 void PaymentRequestDialog::ViewHierarchyChanged( | 117 void PaymentRequestDialog::ViewHierarchyChanged( |
97 const ViewHierarchyChangedDetails& details) { | 118 const ViewHierarchyChangedDetails& details) { |
98 // When a view that is associated with a controller is removed from this | 119 // When a view that is associated with a controller is removed from this |
99 // view's descendants, dispose of the controller. | 120 // view's descendants, dispose of the controller. |
100 if (!details.is_add && | 121 if (!details.is_add && |
101 controller_map_.find(details.child) != controller_map_.end()) { | 122 controller_map_.find(details.child) != controller_map_.end()) { |
102 DCHECK(!details.move_view); | 123 DCHECK(!details.move_view); |
103 controller_map_.erase(details.child); | 124 controller_map_.erase(details.child); |
104 } | 125 } |
105 } | 126 } |
106 | 127 |
107 } // namespace payments | 128 } // namespace payments |
OLD | NEW |