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

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

Issue 2649683002: [Payments] Improve the closing of the PR dialog. (Closed)
Patch Set: addressed comments from sky Created 3 years, 11 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 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_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/order_summary_view_controller.h" 11 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h"
12 #include "chrome/browser/ui/views/payments/payment_method_view_controller.h" 12 #include "chrome/browser/ui/views/payments/payment_method_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 "components/payments/payment_request.h" 16 #include "components/payments/payment_request.h"
17 #include "components/payments/payment_request_dialog.h"
17 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/views/layout/fill_layout.h" 20 #include "ui/views/layout/fill_layout.h"
20 21
21 namespace chrome { 22 namespace chrome {
22 23
23 void ShowPaymentRequestDialog(payments::PaymentRequest* request) { 24 payments::PaymentRequestDialog* CreatePaymentRequestDialog(
24 payments::PaymentRequestDialog::ShowWebModalPaymentDialog( 25 payments::PaymentRequest* request) {
25 new payments::PaymentRequestDialog(request, /* no observer */ nullptr), 26 return new payments::PaymentRequestDialogView(request,
26 request); 27 /* no observer */ nullptr);
27 } 28 }
28 29
29 } // namespace chrome 30 } // namespace chrome
30 31
31 namespace payments { 32 namespace payments {
32 namespace { 33 namespace {
33 34
34 // This function creates an instance of a PaymentRequestSheetController 35 // This function creates an instance of a PaymentRequestSheetController
35 // subclass of concrete type |Controller|, passing it non-owned pointers to 36 // subclass of concrete type |Controller|, passing it non-owned pointers to
36 // |dialog| and the |request| that initiated that dialog. |map| should be owned 37 // |dialog| and the |request| that initiated that dialog. |map| should be owned
37 // by |dialog|. 38 // by |dialog|.
38 template <typename Controller> 39 template <typename Controller>
39 std::unique_ptr<views::View> CreateViewAndInstallController( 40 std::unique_ptr<views::View> CreateViewAndInstallController(
40 payments::ControllerMap* map, 41 payments::ControllerMap* map,
41 payments::PaymentRequest* request, 42 payments::PaymentRequest* request,
42 payments::PaymentRequestDialog* dialog) { 43 payments::PaymentRequestDialogView* dialog) {
43 std::unique_ptr<Controller> controller = 44 std::unique_ptr<Controller> controller =
44 base::MakeUnique<Controller>(request, dialog); 45 base::MakeUnique<Controller>(request, dialog);
45 std::unique_ptr<views::View> view = controller->CreateView(); 46 std::unique_ptr<views::View> view = controller->CreateView();
46 (*map)[view.get()] = std::move(controller); 47 (*map)[view.get()] = std::move(controller);
47 return view; 48 return view;
48 } 49 }
49 50
50 } // namespace 51 } // namespace
51 52
52 PaymentRequestDialog::PaymentRequestDialog( 53 PaymentRequestDialogView::PaymentRequestDialogView(
53 PaymentRequest* request, 54 PaymentRequest* request,
54 PaymentRequestDialog::ObserverForTest* observer) 55 PaymentRequestDialogView::ObserverForTest* observer)
55 : request_(request), observer_(observer) { 56 : request_(request), observer_for_testing_(observer) {
56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 57 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
57 SetLayoutManager(new views::FillLayout()); 58 SetLayoutManager(new views::FillLayout());
58 59
59 view_stack_.set_owned_by_client(); 60 view_stack_.set_owned_by_client();
60 AddChildView(&view_stack_); 61 AddChildView(&view_stack_);
61 62
62 ShowInitialPaymentSheet(); 63 ShowInitialPaymentSheet();
63 } 64 }
64 65
65 PaymentRequestDialog::~PaymentRequestDialog() {} 66 PaymentRequestDialogView::~PaymentRequestDialogView() {}
66 67
67 ui::ModalType PaymentRequestDialog::GetModalType() const { 68 ui::ModalType PaymentRequestDialogView::GetModalType() const {
68 return ui::MODAL_TYPE_CHILD; 69 return ui::MODAL_TYPE_CHILD;
69 } 70 }
70 71
71 bool PaymentRequestDialog::Cancel() { 72 bool PaymentRequestDialogView::Cancel() {
73 // Called when the widget is about to close. We send a message to the
74 // PaymentRequest object to signal user cancellation.
72 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 75 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
73 request_->Cancel(); 76 request_->UserCancelled();
74 return true; 77 return true;
75 } 78 }
76 79
77 bool PaymentRequestDialog::ShouldShowCloseButton() const { 80 bool PaymentRequestDialogView::ShouldShowCloseButton() const {
78 // Don't show the normal close button on the dialog. This is because the 81 // Don't show the normal close button on the dialog. This is because the
79 // typical dialog header doesn't allow displaying anything other that the 82 // typical dialog header doesn't allow displaying anything other that the
80 // title and the close button. This is insufficient for the PaymentRequest 83 // title and the close button. This is insufficient for the PaymentRequest
81 // dialog, which must sometimes show the back arrow next to the title. 84 // dialog, which must sometimes show the back arrow next to the title.
82 // Moreover, the title (and back arrow) should animate with the view they're 85 // Moreover, the title (and back arrow) should animate with the view they're
83 // attached to. 86 // attached to.
84 return false; 87 return false;
85 } 88 }
86 89
87 int PaymentRequestDialog::GetDialogButtons() const { 90 int PaymentRequestDialogView::GetDialogButtons() const {
88 // The buttons should animate along with the different dialog sheets since 91 // The buttons should animate along with the different dialog sheets since
89 // each sheet presents a different set of buttons. Because of this, hide the 92 // each sheet presents a different set of buttons. Because of this, hide the
90 // usual dialog buttons. 93 // usual dialog buttons.
91 return ui::DIALOG_BUTTON_NONE; 94 return ui::DIALOG_BUTTON_NONE;
92 } 95 }
93 96
94 void PaymentRequestDialog::GoBack() { 97 void PaymentRequestDialogView::GoBack() {
95 view_stack_.Pop(); 98 view_stack_.Pop();
96 } 99 }
97 100
98 void PaymentRequestDialog::ShowOrderSummary() { 101 void PaymentRequestDialogView::ShowOrderSummary() {
99 view_stack_.Push(CreateViewAndInstallController<OrderSummaryViewController>( 102 view_stack_.Push(CreateViewAndInstallController<OrderSummaryViewController>(
100 &controller_map_, request_, this), 103 &controller_map_, request_, this),
101 true); 104 true);
102 } 105 }
103 106
104 void PaymentRequestDialog::ShowPaymentMethodSheet() { 107 void PaymentRequestDialogView::ShowPaymentMethodSheet() {
105 view_stack_.Push( 108 view_stack_.Push(CreateViewAndInstallController<PaymentMethodViewController>(
106 CreateViewAndInstallController<PaymentMethodViewController>( 109 &controller_map_, request_, this),
107 &controller_map_, request_, this), 110 true);
108 true);
109 } 111 }
110 112
111 void PaymentRequestDialog::CloseDialog() { 113 void PaymentRequestDialogView::ShowDialog() {
114 constrained_window::ShowWebModalDialogViews(this, request_->web_contents());
115 }
116
117 void PaymentRequestDialogView::CloseDialog() {
118 // This calls PaymentRequestDialogView::Cancel() before closing.
112 GetWidget()->Close(); 119 GetWidget()->Close();
113 } 120 }
114 121
115 // static 122 void PaymentRequestDialogView::ShowInitialPaymentSheet() {
116 void PaymentRequestDialog::ShowWebModalPaymentDialog(
117 PaymentRequestDialog* dialog,
118 PaymentRequest* request) {
119 constrained_window::ShowWebModalDialogViews(dialog, request->web_contents());
120 }
121
122 void PaymentRequestDialog::ShowInitialPaymentSheet() {
123 view_stack_.Push(CreateViewAndInstallController<PaymentSheetViewController>( 123 view_stack_.Push(CreateViewAndInstallController<PaymentSheetViewController>(
124 &controller_map_, request_, this), 124 &controller_map_, request_, this),
125 false); 125 false);
126 if (observer_) 126 if (observer_for_testing_)
127 observer_->OnDialogOpened(); 127 observer_for_testing_->OnDialogOpened();
128 } 128 }
129 129
130 gfx::Size PaymentRequestDialog::GetPreferredSize() const { 130 gfx::Size PaymentRequestDialogView::GetPreferredSize() const {
131 return gfx::Size(450, 450); 131 return gfx::Size(450, 450);
132 } 132 }
133 133
134 void PaymentRequestDialog::ViewHierarchyChanged( 134 void PaymentRequestDialogView::ViewHierarchyChanged(
135 const ViewHierarchyChangedDetails& details) { 135 const ViewHierarchyChangedDetails& details) {
136 // When a view that is associated with a controller is removed from this 136 // When a view that is associated with a controller is removed from this
137 // view's descendants, dispose of the controller. 137 // view's descendants, dispose of the controller.
138 if (!details.is_add && 138 if (!details.is_add &&
139 controller_map_.find(details.child) != controller_map_.end()) { 139 controller_map_.find(details.child) != controller_map_.end()) {
140 DCHECK(!details.move_view); 140 DCHECK(!details.move_view);
141 controller_map_.erase(details.child); 141 controller_map_.erase(details.child);
142 } 142 }
143 } 143 }
144 144
145 } // namespace payments 145 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698