OLD | NEW |
(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 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_VIEW_STACK_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_VIEW_STACK_H_ |
| 7 |
| 8 #include "ui/views/view.h" |
| 9 #include "ui/views/animation/bounds_animator.h" |
| 10 #include "ui/views/animation/bounds_animator_observer.h" |
| 11 |
| 12 // This view represents a stack of views that slide in over one another from |
| 13 // left to right. It manages the animation and lifetime of views that are |
| 14 // pushed and popped on it. To use this class, add it to a view hierarchy, and |
| 15 // call Push/Pop to animate views in and out. |
| 16 class ViewStack : public views::BoundsAnimatorObserver, |
| 17 public views::View { |
| 18 public: |
| 19 ViewStack(); |
| 20 ~ViewStack() override; |
| 21 |
| 22 // Adds a view to the stack and starts animating it in from the right. This |
| 23 // takes ownership of the view and calls set_owned_by_client() on it. |
| 24 // If |animate| is false, the view will simply be added to the hierarchy |
| 25 // without the sliding animation. |
| 26 void Push(std::unique_ptr<views::View> state, bool animate); |
| 27 |
| 28 // Removes a view from the stack, animates it out of view, and makes sure |
| 29 // it's properly deleted after the animation. |
| 30 void Pop(); |
| 31 |
| 32 // views::View: |
| 33 // The children of this view must not be able to process events when the views |
| 34 // are being animated so this returns false when an animation is in progress. |
| 35 bool CanProcessEventsWithinSubtree() const override; |
| 36 void Layout() override; |
| 37 |
| 38 private: |
| 39 FRIEND_TEST_ALL_PREFIXES( |
| 40 ViewStackTest, TestPopStateRemovesChildViewAndCleansUpState); |
| 41 FRIEND_TEST_ALL_PREFIXES(ViewStackTest, TestDeletingViewCleansUpState); |
| 42 FRIEND_TEST_ALL_PREFIXES(ViewStackTest, TestInitialStateAddedAsChildView); |
| 43 FRIEND_TEST_ALL_PREFIXES(ViewStackTest, TestPushStateAddsViewToChildren); |
| 44 FRIEND_TEST_ALL_PREFIXES(ViewStackTest, TestLayoutUpdatesAnimations); |
| 45 friend class ViewStackTest; |
| 46 |
| 47 // Returns the top state of the stack, used in tests. |
| 48 views::View* top() { return stack_.back().get(); } |
| 49 |
| 50 void UpdateAnimatorBounds( |
| 51 views::BoundsAnimator* animator, const gfx::Rect& target); |
| 52 |
| 53 // views::BoundsAnimatorObserver: |
| 54 void OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) override {} |
| 55 void OnBoundsAnimatorDone(views::BoundsAnimator* animator) override; |
| 56 |
| 57 std::vector<std::unique_ptr<views::View>> stack_; |
| 58 |
| 59 std::unique_ptr<views::BoundsAnimator> slide_in_animator_; |
| 60 std::unique_ptr<views::BoundsAnimator> slide_out_animator_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(ViewStack); |
| 63 }; |
| 64 |
| 65 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_VIEW_STACK_H_ |
OLD | NEW |