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

Side by Side Diff: chrome/browser/ui/views/payments/payment_request_dialog.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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/payments/payment_request_dialog.h"
6
7 #include <utility>
8
9 #include "base/logging.h"
10 #include "base/memory/ptr_util.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"
13 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "components/constrained_window/constrained_window_views.h"
16 #include "components/payments/payment_request.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/views/layout/fill_layout.h"
20
21 namespace chrome {
22
23 void ShowPaymentRequestDialog(payments::PaymentRequest* request) {
24 payments::PaymentRequestDialog::ShowWebModalPaymentDialog(
25 new payments::PaymentRequestDialog(request, /* no observer */ nullptr),
26 request);
27 }
28
29 } // namespace chrome
30
31 namespace payments {
32 namespace {
33
34 // This function creates an instance of a PaymentRequestSheetController
35 // 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 // by |dialog|.
38 template <typename Controller>
39 std::unique_ptr<views::View> CreateViewAndInstallController(
40 payments::ControllerMap* map,
41 payments::PaymentRequest* request,
42 payments::PaymentRequestDialog* dialog) {
43 std::unique_ptr<Controller> controller =
44 base::MakeUnique<Controller>(request, dialog);
45 std::unique_ptr<views::View> view = controller->CreateView();
46 (*map)[view.get()] = std::move(controller);
47 return view;
48 }
49
50 } // namespace
51
52 PaymentRequestDialog::PaymentRequestDialog(
53 PaymentRequest* request,
54 PaymentRequestDialog::ObserverForTest* observer)
55 : request_(request), observer_(observer) {
56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
57 SetLayoutManager(new views::FillLayout());
58
59 view_stack_.set_owned_by_client();
60 AddChildView(&view_stack_);
61
62 ShowInitialPaymentSheet();
63 }
64
65 PaymentRequestDialog::~PaymentRequestDialog() {}
66
67 ui::ModalType PaymentRequestDialog::GetModalType() const {
68 return ui::MODAL_TYPE_CHILD;
69 }
70
71 bool PaymentRequestDialog::Cancel() {
72 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
73 request_->Cancel();
74 return true;
75 }
76
77 bool PaymentRequestDialog::ShouldShowCloseButton() const {
78 // 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
80 // title and the close button. This is insufficient for the PaymentRequest
81 // 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
83 // attached to.
84 return false;
85 }
86
87 int PaymentRequestDialog::GetDialogButtons() const {
88 // 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
90 // usual dialog buttons.
91 return ui::DIALOG_BUTTON_NONE;
92 }
93
94 void PaymentRequestDialog::GoBack() {
95 view_stack_.Pop();
96 }
97
98 void PaymentRequestDialog::ShowOrderSummary() {
99 view_stack_.Push(CreateViewAndInstallController<OrderSummaryViewController>(
100 &controller_map_, request_, this),
101 true);
102 }
103
104 void PaymentRequestDialog::ShowPaymentMethodSheet() {
105 view_stack_.Push(
106 CreateViewAndInstallController<PaymentMethodViewController>(
107 &controller_map_, request_, this),
108 true);
109 }
110
111 void PaymentRequestDialog::CloseDialog() {
112 GetWidget()->Close();
113 }
114
115 // static
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>(
124 &controller_map_, request_, this),
125 false);
126 if (observer_)
127 observer_->OnDialogOpened();
128 }
129
130 gfx::Size PaymentRequestDialog::GetPreferredSize() const {
131 return gfx::Size(450, 450);
132 }
133
134 void PaymentRequestDialog::ViewHierarchyChanged(
135 const ViewHierarchyChangedDetails& details) {
136 // When a view that is associated with a controller is removed from this
137 // view's descendants, dispose of the controller.
138 if (!details.is_add &&
139 controller_map_.find(details.child) != controller_map_.end()) {
140 DCHECK(!details.move_view);
141 controller_map_.erase(details.child);
142 }
143 }
144
145 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698