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

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

Issue 2528503002: [WebPayments] Implement state transitions in desktop WebPayments dialog. (Closed)
Patch Set: Make PaymentDialogState own the view returned through GetView Created 4 years 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"
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/payment_dialog_state.h"
10 #include "chrome/browser/ui/views/payments/payment_sheet_state.h"
8 #include "components/constrained_window/constrained_window_views.h" 11 #include "components/constrained_window/constrained_window_views.h"
9 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "ui/views/animation/bounds_animator_observer.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
27 // Observes the Slide Out state animation and removes the view when it's done
28 // being animated, then deletes itself. This takes ownership of the state so
29 // it's garanteed to be properly disposed of when the animation is over.
30 class SlideOutObserver : public views::BoundsAnimatorObserver {
31 public:
32 SlideOutObserver(std::unique_ptr<PaymentDialogState> state_animating_out,
33 views::View* parent_view)
34 : state_animating_out_(std::move(state_animating_out)),
35 parent_view_(parent_view) {}
36
37 views::View* GetAnimatedView() {
38 return state_animating_out_->GetView();
39 }
40
41 private:
42 // views::BoundsAnimatorObserver:
43 void OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) override {}
44
45 void OnBoundsAnimatorDone(views::BoundsAnimator* animator) override {
46 animator->RemoveObserver(this);
47 parent_view_->RemoveChildView(state_animating_out_->GetView());
sky 2016/12/08 03:58:17 Is this necessary?
anthonyvd 2016/12/08 20:31:22 Ahh, it's not! Because the state being deleted als
48 delete this;
49 }
50
51 std::unique_ptr<PaymentDialogState> state_animating_out_;
52 views::View* parent_view_;
53 };
sky 2016/12/08 03:58:17 DISALLOW...
anthonyvd 2016/12/08 20:31:22 Done.
54
23 PaymentRequestDialog::PaymentRequestDialog(PaymentRequestImpl* impl) 55 PaymentRequestDialog::PaymentRequestDialog(PaymentRequestImpl* impl)
24 : impl_(impl), 56 : impl_(impl),
25 label_(new views::Label(base::ASCIIToUTF16("Payments dialog"))) { 57 slide_in_animator_(new views::BoundsAnimator(this)),
58 slide_out_animator_(new views::BoundsAnimator(this)) {
26 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 59 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
27 SetLayoutManager(new views::FillLayout()); 60 SetLayoutManager(new views::FillLayout());
28 AddChildView(label_.get()); 61
62 std::unique_ptr<PaymentSheetState> initial_state =
63 base::MakeUnique<PaymentSheetState>();
64 initial_state->AddObserver(this);
65 state_stack_.push(std::move(initial_state));
66
67 AddChildView(state_stack_.top()->GetView());
29 } 68 }
30 69
31 PaymentRequestDialog::~PaymentRequestDialog() {} 70 PaymentRequestDialog::~PaymentRequestDialog() {
71 // Cancel animations to make sure their observer's OnBoundsAnimatorDone is
72 // called.
73 slide_in_animator_->Cancel();
sky 2016/12/08 03:58:17 Are you sure cancel resluts in OnBoundsAnimatorDon
anthonyvd 2016/12/08 20:31:22 Yes, Cancel() ends up calling BoundsAnimator::Ani
74 slide_out_animator_->Cancel();
75 }
76
77 void PaymentRequestDialog::PushState(
78 std::unique_ptr<PaymentDialogState> state) {
79 state_stack_.top()->SetInteractable(false);
80
81 // First add the new view out of bounds since it'll slide in from right to
82 // left.
83 state->GetView()->SetPosition(gfx::Point(x() + width(), y()));
sky 2016/12/08 03:58:17 I would expect this to SetBounds, by which I mean
anthonyvd 2016/12/08 20:31:22 Done.
84
85 AddChildView(state->GetView());
86 // Animate the new view to be right on top of this one.
87 slide_in_animator_->AnimateViewTo(state->GetView(), bounds());
sky 2016/12/08 03:58:17 bounds() is relative to the parent, where as the v
anthonyvd 2016/12/08 20:31:22 Ah yes, so this only worked because the parent was
88
89 // Add the new state to the stack so it can be popped later when navigating
90 // back to the previous screen.
91 state_stack_.push(std::move(state));
92 state_stack_.top()->SetInteractable(true);
93 }
94
95 void PaymentRequestDialog::PopState() {
96 state_stack_.top()->SetInteractable(false);
97
98 gfx::Rect destination = bounds();
sky 2016/12/08 03:58:17 Similar comment about bounds here, you want a orig
anthonyvd 2016/12/08 20:31:22 Done.
99 destination.Offset(width(), 0);
100
101 // This deletes itself.
102 SlideOutObserver* observer =
103 new SlideOutObserver(std::move(state_stack_.top()), this);
104 slide_out_animator_->AddObserver(observer);
105
106 state_stack_.pop();
107 DCHECK(!state_stack_.empty()) << "State stack should never be empty";
108
109 slide_out_animator_->AnimateViewTo(observer->GetAnimatedView(), destination);
110 state_stack_.top()->SetInteractable(true);
111 }
32 112
33 ui::ModalType PaymentRequestDialog::GetModalType() const { 113 ui::ModalType PaymentRequestDialog::GetModalType() const {
34 return ui::MODAL_TYPE_CHILD; 114 return ui::MODAL_TYPE_CHILD;
35 } 115 }
36 116
37 gfx::Size PaymentRequestDialog::GetPreferredSize() const { 117 gfx::Size PaymentRequestDialog::GetPreferredSize() const {
38 gfx::Size ps = label_->GetPreferredSize(); 118 return gfx::Size(300, 300);
sky 2016/12/08 03:58:17 How do you know 300x300 is going to be enough?
anthonyvd 2016/12/08 20:31:22 I don't, this is a temporary value until we figure
39 ps.Enlarge(200, 200);
40 return ps;
41 } 119 }
42 120
43 bool PaymentRequestDialog::Cancel() { 121 bool PaymentRequestDialog::Cancel() {
44 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 122 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
45 impl_->Cancel(); 123 impl_->Cancel();
46 return true; 124 return true;
47 } 125 }
48 126
127 void PaymentRequestDialog::OnOrderSummaryClicked() {
128 std::unique_ptr<OrderSummaryState> order_summary =
129 base::MakeUnique<OrderSummaryState>();
130 order_summary->AddObserver(this);
131 PushState(std::move(order_summary));
132 }
133
134 void PaymentRequestDialog::OnBackClicked() {
135 PopState();
136 }
137
49 } // namespace payments 138 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698