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

Unified Diff: chrome/browser/ui/views/payments/view_stack.cc

Issue 2528503002: [WebPayments] Implement state transitions in desktop WebPayments dialog. (Closed)
Patch Set: Address comments 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/view_stack.cc
diff --git a/chrome/browser/ui/views/payments/view_stack.cc b/chrome/browser/ui/views/payments/view_stack.cc
new file mode 100644
index 0000000000000000000000000000000000000000..94b0b55305e4ad443fdbc7166a98e2abb01cef95
--- /dev/null
+++ b/chrome/browser/ui/views/payments/view_stack.cc
@@ -0,0 +1,64 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// 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/view_stack.h"
+
+#include "ui/views/layout/fill_layout.h"
+
+ViewStack::ViewStack()
+ : slide_in_animator_(base::MakeUnique<views::BoundsAnimator>(this)),
+ slide_out_animator_(base::MakeUnique<views::BoundsAnimator>(this)) {
+ SetLayoutManager(new views::FillLayout());
+
+ slide_out_animator_->AddObserver(this);
+}
+
+ViewStack::~ViewStack() {}
+
+void ViewStack::Push(std::unique_ptr<views::View> view, bool animate) {
+ gfx::Rect destination = bounds();
+ destination.set_origin(gfx::Point(0, 0));
+ if (animate) {
+ // First add the new view out of bounds since it'll slide in from right to
+ // left.
+ view->SetBounds(width(), 0, width(), height());
+ view->Layout();
+
+ AddChildView(view.get());
+
+ // Animate the new view to be right on top of this one.
+ slide_in_animator_->AnimateViewTo(view.get(), destination);
+ } else {
+ view->SetBoundsRect(destination);
+ view->Layout();
+ AddChildView(view.get());
+ }
+
+ view->set_owned_by_client();
+ // Add the new view to the stack so it can be popped later when navigating
+ // back to the previous screen.
+ stack_.push(std::move(view));
+}
+
+void ViewStack::Pop() {
+ gfx::Rect destination = bounds();
+ destination.set_origin(gfx::Point(width(), 0));
+
+ slide_out_animator_->AnimateViewTo(
+ stack_.top().get(), destination);
+}
+
+bool ViewStack::CanProcessEventsWithinSubtree() const {
+ return !slide_in_animator_->IsAnimating() &&
+ !slide_out_animator_->IsAnimating();
+}
+
+void ViewStack::OnBoundsAnimatorDone(views::BoundsAnimator* animator) {
+ // This should only be called from slide_out_animator_ when the views going
+ // out are done animating.
+ DCHECK_EQ(animator, slide_out_animator_.get());
+
+ stack_.pop();
+ DCHECK(!stack_.empty()) << "State stack should never be empty";
+}

Powered by Google App Engine
This is Rietveld 408576698