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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/payments/view_stack.h"
6
7 #include "ui/views/layout/fill_layout.h"
8
9 ViewStack::ViewStack()
10 : slide_in_animator_(base::MakeUnique<views::BoundsAnimator>(this)),
11 slide_out_animator_(base::MakeUnique<views::BoundsAnimator>(this)) {
12 SetLayoutManager(new views::FillLayout());
13
14 slide_out_animator_->AddObserver(this);
15 }
16
17 ViewStack::~ViewStack() {}
18
19 void ViewStack::Push(std::unique_ptr<views::View> view, bool animate) {
20 gfx::Rect destination = bounds();
21 destination.set_origin(gfx::Point(0, 0));
22 if (animate) {
23 // First add the new view out of bounds since it'll slide in from right to
24 // left.
25 view->SetBounds(width(), 0, width(), height());
26 view->Layout();
27
28 AddChildView(view.get());
29
30 // Animate the new view to be right on top of this one.
31 slide_in_animator_->AnimateViewTo(view.get(), destination);
32 } else {
33 view->SetBoundsRect(destination);
34 view->Layout();
35 AddChildView(view.get());
36 }
37
38 view->set_owned_by_client();
39 // Add the new view to the stack so it can be popped later when navigating
40 // back to the previous screen.
41 stack_.push(std::move(view));
42 }
43
44 void ViewStack::Pop() {
45 gfx::Rect destination = bounds();
46 destination.set_origin(gfx::Point(width(), 0));
47
48 slide_out_animator_->AnimateViewTo(
49 stack_.top().get(), destination);
50 }
51
52 bool ViewStack::CanProcessEventsWithinSubtree() const {
53 return !slide_in_animator_->IsAnimating() &&
54 !slide_out_animator_->IsAnimating();
55 }
56
57 void ViewStack::OnBoundsAnimatorDone(views::BoundsAnimator* animator) {
58 // This should only be called from slide_out_animator_ when the views going
59 // out are done animating.
60 DCHECK_EQ(animator, slide_out_animator_.get());
61
62 stack_.pop();
63 DCHECK(!stack_.empty()) << "State stack should never be empty";
64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698