Index: chrome/browser/payments/ui/payment_request_dialog.cc |
diff --git a/chrome/browser/payments/ui/payment_request_dialog.cc b/chrome/browser/payments/ui/payment_request_dialog.cc |
index 4c4c48091afe26575416f24c5a6e8eb3e0adc429..72c5d05c4b7b68004381c213db0749f35788cd1d 100644 |
--- a/chrome/browser/payments/ui/payment_request_dialog.cc |
+++ b/chrome/browser/payments/ui/payment_request_dialog.cc |
@@ -5,29 +5,104 @@ |
#include "base/strings/utf_string_conversions.h" |
#include "chrome/browser/payments/ui/payment_request_dialog.h" |
#include "content/public/browser/browser_thread.h" |
+#include "ui/views/animation/bounds_animator_observer.h" |
#include "ui/views/layout/fill_layout.h" |
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()); |
+ delete this; |
+ } |
+ |
+ std::unique_ptr<PaymentDialogState> state_animating_out_; |
+ views::View* parent_view_; |
+}; |
+ |
PaymentRequestDialog::PaymentRequestDialog( |
payments::mojom::PaymentRequestClientPtr client) |
: client_(std::move(client)), |
- 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(); |
+ slide_out_animator_->Cancel(); |
} |
-PaymentRequestDialog::~PaymentRequestDialog() {} |
+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())); |
+ |
+ AddChildView(state->GetView()); |
+ // Animate the new view to be right on top of this one. |
+ slide_in_animator_->AnimateViewTo(state->GetView(), bounds()); |
+ |
+ // 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); |
+} |
+ |
+void PaymentRequestDialog::PopState() { |
+ state_stack_.top()->SetInteractable(false); |
+ |
+ gfx::Rect destination = bounds(); |
+ 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); |
} |
bool PaymentRequestDialog::Cancel() { |
@@ -36,4 +111,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 |