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" | |
6 | |
5 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
6 #include "chrome/browser/payments/payment_request_impl.h" | 8 #include "chrome/browser/payments/payment_request_impl.h" |
7 #include "chrome/browser/ui/views/payments/payment_request_dialog.h" | 9 #include "chrome/browser/ui/views/payments/order_summary_state.h" |
10 #include "chrome/browser/ui/views/payments/payment_sheet_state.h" | |
11 #include "chrome/browser/ui/views/payments/view_stack.h" | |
8 #include "components/constrained_window/constrained_window_views.h" | 12 #include "components/constrained_window/constrained_window_views.h" |
9 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
10 #include "ui/views/layout/fill_layout.h" | 14 #include "ui/views/layout/fill_layout.h" |
11 | 15 |
12 namespace chrome { | 16 namespace chrome { |
13 | 17 |
14 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) { | 18 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) { |
15 constrained_window::ShowWebModalDialogViews( | 19 constrained_window::ShowWebModalDialogViews( |
16 new payments::PaymentRequestDialog(impl), impl->web_contents()); | 20 new payments::PaymentRequestDialog(impl), impl->web_contents()); |
17 } | 21 } |
18 | 22 |
19 } | 23 } |
20 | 24 |
21 namespace payments { | 25 namespace payments { |
22 | 26 |
23 PaymentRequestDialog::PaymentRequestDialog(PaymentRequestImpl* impl) | 27 PaymentRequestDialog::PaymentRequestDialog(PaymentRequestImpl* impl) |
24 : impl_(impl), | 28 : impl_(impl) { |
25 label_(new views::Label(base::ASCIIToUTF16("Payments dialog"))) { | |
26 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 29 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
27 SetLayoutManager(new views::FillLayout()); | 30 SetLayoutManager(new views::FillLayout()); |
28 AddChildView(label_.get()); | 31 |
32 std::unique_ptr<PaymentSheetState> initial_state = | |
33 base::MakeUnique<PaymentSheetState>(); | |
34 initial_state->AddObserver(this); | |
35 view_stack_.reset(new ViewStack(std::move(initial_state))); | |
sky
2016/12/12 01:54:32
Can you elaborate on why ViewStack can't operate s
anthonyvd
2016/12/12 17:01:56
I felt like encapsulating event handling in the st
| |
36 view_stack_->set_owned_by_client(); | |
37 AddChildView(view_stack_.get()); | |
29 } | 38 } |
30 | 39 |
31 PaymentRequestDialog::~PaymentRequestDialog() {} | 40 PaymentRequestDialog::~PaymentRequestDialog() {} |
32 | 41 |
33 ui::ModalType PaymentRequestDialog::GetModalType() const { | 42 ui::ModalType PaymentRequestDialog::GetModalType() const { |
34 return ui::MODAL_TYPE_CHILD; | 43 return ui::MODAL_TYPE_CHILD; |
35 } | 44 } |
36 | 45 |
37 gfx::Size PaymentRequestDialog::GetPreferredSize() const { | 46 gfx::Size PaymentRequestDialog::GetPreferredSize() const { |
38 gfx::Size ps = label_->GetPreferredSize(); | 47 return gfx::Size(300, 300); |
39 ps.Enlarge(200, 200); | |
40 return ps; | |
41 } | 48 } |
42 | 49 |
43 bool PaymentRequestDialog::Cancel() { | 50 bool PaymentRequestDialog::Cancel() { |
44 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 51 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
45 impl_->Cancel(); | 52 impl_->Cancel(); |
46 return true; | 53 return true; |
47 } | 54 } |
48 | 55 |
56 void PaymentRequestDialog::OnOrderSummaryClicked() { | |
57 std::unique_ptr<OrderSummaryState> order_summary = | |
58 base::MakeUnique<OrderSummaryState>(); | |
59 order_summary->AddObserver(this); | |
60 view_stack_->PushState(std::move(order_summary)); | |
61 } | |
62 | |
63 void PaymentRequestDialog::OnBackClicked() { | |
64 view_stack_->PopState(); | |
65 } | |
66 | |
49 } // namespace payments | 67 } // namespace payments |
OLD | NEW |