OLD | NEW |
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/view_stack.h" | 5 #include "chrome/browser/ui/views/payments/view_stack.h" |
6 | 6 |
7 #include "ui/views/layout/fill_layout.h" | 7 #include "ui/views/layout/fill_layout.h" |
8 | 8 |
9 ViewStack::ViewStack() | 9 ViewStack::ViewStack() |
10 : slide_in_animator_(base::MakeUnique<views::BoundsAnimator>(this)), | 10 : slide_in_animator_(base::MakeUnique<views::BoundsAnimator>(this)), |
11 slide_out_animator_(base::MakeUnique<views::BoundsAnimator>(this)) { | 11 slide_out_animator_(base::MakeUnique<views::BoundsAnimator>(this)) { |
12 SetLayoutManager(new views::FillLayout()); | 12 SetLayoutManager(new views::FillLayout()); |
13 | 13 |
14 slide_out_animator_->AddObserver(this); | 14 slide_out_animator_->AddObserver(this); |
| 15 // Paint to a layer and Mask to Bounds, otherwise descendant views that paint |
| 16 // to a layer themselves will still paint while they're being animated out and |
| 17 // are out of bounds of their parent. |
| 18 SetPaintToLayer(true); |
| 19 layer()->SetMasksToBounds(true); |
15 } | 20 } |
16 | 21 |
17 ViewStack::~ViewStack() {} | 22 ViewStack::~ViewStack() {} |
18 | 23 |
19 void ViewStack::Push(std::unique_ptr<views::View> view, bool animate) { | 24 void ViewStack::Push(std::unique_ptr<views::View> view, bool animate) { |
20 gfx::Rect destination = bounds(); | 25 gfx::Rect destination = bounds(); |
21 destination.set_origin(gfx::Point(0, 0)); | 26 destination.set_origin(gfx::Point(0, 0)); |
| 27 |
22 if (animate) { | 28 if (animate) { |
23 // First add the new view out of bounds since it'll slide in from right to | 29 // First add the new view out of bounds since it'll slide in from right to |
24 // left. | 30 // left. |
25 view->SetBounds(width(), 0, width(), height()); | 31 view->SetBounds(width(), 0, width(), height()); |
26 view->Layout(); | 32 view->Layout(); |
27 | 33 |
28 AddChildView(view.get()); | 34 AddChildView(view.get()); |
29 | 35 |
30 // Animate the new view to be right on top of this one. | 36 // Animate the new view to be right on top of this one. |
31 slide_in_animator_->AnimateViewTo(view.get(), destination); | 37 slide_in_animator_->AnimateViewTo(view.get(), destination); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 89 } |
84 | 90 |
85 void ViewStack::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { | 91 void ViewStack::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { |
86 // This should only be called from slide_out_animator_ when the views going | 92 // This should only be called from slide_out_animator_ when the views going |
87 // out are done animating. | 93 // out are done animating. |
88 DCHECK_EQ(animator, slide_out_animator_.get()); | 94 DCHECK_EQ(animator, slide_out_animator_.get()); |
89 | 95 |
90 stack_.pop_back(); | 96 stack_.pop_back(); |
91 DCHECK(!stack_.empty()) << "State stack should never be empty"; | 97 DCHECK(!stack_.empty()) << "State stack should never be empty"; |
92 } | 98 } |
OLD | NEW |