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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/payments/payment_request_dialog.cc
diff --git a/chrome/browser/ui/views/payments/payment_request_dialog.cc b/chrome/browser/ui/views/payments/payment_request_dialog.cc
index 04f6d69fd020e445bfc09fdaf5db74f6eecfc172..19ee25c3fc38d59fe475289dfd0bd3f1e8d63e0c 100644
--- a/chrome/browser/ui/views/payments/payment_request_dialog.cc
+++ b/chrome/browser/ui/views/payments/payment_request_dialog.cc
@@ -2,11 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "chrome/browser/ui/views/payments/payment_request_dialog.h"
+
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/payments/payment_request_impl.h"
-#include "chrome/browser/ui/views/payments/payment_request_dialog.h"
+#include "chrome/browser/ui/views/payments/payment_dialog_state.h"
+#include "chrome/browser/ui/views/payments/payment_sheet_state.h"
#include "components/constrained_window/constrained_window_views.h"
#include "content/public/browser/browser_thread.h"
+#include "ui/views/animation/bounds_animator_observer.h"
#include "ui/views/layout/fill_layout.h"
namespace chrome {
@@ -20,24 +24,98 @@ void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) {
namespace payments {
+// Observes the Slide Out state animation and removes the view when it's done
+// being animated, then deletes itself. This takes ownership of the state so
+// it's garanteed to be properly disposed of when the animation is over.
+class SlideOutObserver : public views::BoundsAnimatorObserver {
+ public:
+ SlideOutObserver(std::unique_ptr<PaymentDialogState> state_animating_out,
+ views::View* parent_view)
+ : state_animating_out_(std::move(state_animating_out)),
+ parent_view_(parent_view) {}
+
+ views::View* GetAnimatedView() {
+ return state_animating_out_->GetView();
+ }
+
+ private:
+ // views::BoundsAnimatorObserver:
+ void OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) override {}
+
+ void OnBoundsAnimatorDone(views::BoundsAnimator* animator) override {
+ animator->RemoveObserver(this);
+ 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
+ delete this;
+ }
+
+ std::unique_ptr<PaymentDialogState> state_animating_out_;
+ views::View* parent_view_;
+};
sky 2016/12/08 03:58:17 DISALLOW...
anthonyvd 2016/12/08 20:31:22 Done.
+
PaymentRequestDialog::PaymentRequestDialog(PaymentRequestImpl* impl)
: impl_(impl),
- label_(new views::Label(base::ASCIIToUTF16("Payments dialog"))) {
+ slide_in_animator_(new views::BoundsAnimator(this)),
+ slide_out_animator_(new views::BoundsAnimator(this)) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
SetLayoutManager(new views::FillLayout());
- AddChildView(label_.get());
+
+ std::unique_ptr<PaymentSheetState> initial_state =
+ base::MakeUnique<PaymentSheetState>();
+ initial_state->AddObserver(this);
+ state_stack_.push(std::move(initial_state));
+
+ AddChildView(state_stack_.top()->GetView());
+}
+
+PaymentRequestDialog::~PaymentRequestDialog() {
+ // Cancel animations to make sure their observer's OnBoundsAnimatorDone is
+ // called.
+ 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
+ slide_out_animator_->Cancel();
+}
+
+void PaymentRequestDialog::PushState(
+ std::unique_ptr<PaymentDialogState> state) {
+ state_stack_.top()->SetInteractable(false);
+
+ // First add the new view out of bounds since it'll slide in from right to
+ // left.
+ 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.
+
+ AddChildView(state->GetView());
+ // Animate the new view to be right on top of this one.
+ 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
+
+ // Add the new state to the stack so it can be popped later when navigating
+ // back to the previous screen.
+ state_stack_.push(std::move(state));
+ state_stack_.top()->SetInteractable(true);
}
-PaymentRequestDialog::~PaymentRequestDialog() {}
+void PaymentRequestDialog::PopState() {
+ state_stack_.top()->SetInteractable(false);
+
+ 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.
+ destination.Offset(width(), 0);
+
+ // This deletes itself.
+ SlideOutObserver* observer =
+ new SlideOutObserver(std::move(state_stack_.top()), this);
+ slide_out_animator_->AddObserver(observer);
+
+ state_stack_.pop();
+ DCHECK(!state_stack_.empty()) << "State stack should never be empty";
+
+ slide_out_animator_->AnimateViewTo(observer->GetAnimatedView(), destination);
+ state_stack_.top()->SetInteractable(true);
+}
ui::ModalType PaymentRequestDialog::GetModalType() const {
return ui::MODAL_TYPE_CHILD;
}
gfx::Size PaymentRequestDialog::GetPreferredSize() const {
- gfx::Size ps = label_->GetPreferredSize();
- ps.Enlarge(200, 200);
- return ps;
+ 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
}
bool PaymentRequestDialog::Cancel() {
@@ -46,4 +124,15 @@ bool PaymentRequestDialog::Cancel() {
return true;
}
+void PaymentRequestDialog::OnOrderSummaryClicked() {
+ std::unique_ptr<OrderSummaryState> order_summary =
+ base::MakeUnique<OrderSummaryState>();
+ order_summary->AddObserver(this);
+ PushState(std::move(order_summary));
+}
+
+void PaymentRequestDialog::OnBackClicked() {
+ PopState();
+}
+
} // namespace payments

Powered by Google App Engine
This is Rietveld 408576698