1 // Copyright 2014 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.
5 #ifndef UI_APP_LIST_VIEWS_CONTENTS_ANIMATOR_H_
6 #define UI_APP_LIST_VIEWS_CONTENTS_ANIMATOR_H_
10 #include "base/macros.h"
20 // Manages an animation between two specific pages of the ContentsView.
21 // Different subclasses implement different animations, so we can have a custom
22 // animation for each pair of pages. Animations are reversible (if A -> B is
23 // implemented, B -> A will implicitly be the inverse animation).
24 class ContentsAnimator
{
26 explicit ContentsAnimator(ContentsView
* contents_view
);
28 virtual ~ContentsAnimator();
30 // Gets the name of the animator, for testing.
31 virtual std::string
NameForTests() const = 0;
33 // Updates the state of the ContentsView. |progress| is the amount of progress
34 // made on the animation, where 0.0 is the beginning and 1.0 is the end. The
35 // animation should be linear (not eased in or out) so that it can be played
36 // forwards or reversed. Easing will be applied by the PaginationModel.
37 virtual void Update(double progress
, int from_page
, int to_page
) = 0;
40 const ContentsView
* contents_view() const { return contents_view_
; }
42 // Gets the on-screen page bounds for a given launcher page with index
44 gfx::Rect
GetOnscreenPageBounds(int page_index
) const;
46 // Gets the origin (the off-screen resting place) for a given launcher page
47 // with index |page_index|.
48 gfx::Rect
GetOffscreenPageBounds(int page_index
) const;
50 // Updates the position of the custom launcher page view (if it exists), in
51 // the default way for start page <-> other page transitions. This places it
52 // into collapsed state on the start page, and hidden on any other page. Any
53 // other behaviour should be implemented with a custom animator. |progress|,
54 // |from_page| and |to_page| are parameters from Update().
55 void UpdateCustomPageForDefaultAnimation(double progress
,
59 // Updates the position of the search box view, placing it in the correct
60 // position for the transition from |from_page| to |to_page|.
61 void UpdateSearchBoxForDefaultAnimation(double progress
,
65 // Clips the drawing of the search results page to its onscreen bounds.
66 void ClipSearchResultsPageToOnscreenBounds(int page_index
,
67 const gfx::Rect
& current_bounds
,
68 const gfx::Rect
& onscreen_bounds
);
71 ContentsView
* contents_view_
;
73 DISALLOW_COPY_AND_ASSIGN(ContentsAnimator
);
76 // Simple animator that slides pages in and out vertically. Appropriate for any
78 class DefaultAnimator
: public ContentsAnimator
{
80 explicit DefaultAnimator(ContentsView
* contents_view
);
82 ~DefaultAnimator() override
{}
84 // ContentsAnimator overrides:
85 std::string
NameForTests() const override
;
86 void Update(double progress
, int from_page
, int to_page
) override
;
89 DISALLOW_COPY_AND_ASSIGN(DefaultAnimator
);
92 // Animator between the start page and apps grid page.
93 class StartToAppsAnimator
: public ContentsAnimator
{
95 explicit StartToAppsAnimator(ContentsView
* contents_view
);
97 ~StartToAppsAnimator() override
{}
99 // ContentsAnimator overrides:
100 std::string
NameForTests() const override
;
101 void Update(double progress
, int start_page
, int apps_page
) override
;
104 DISALLOW_COPY_AND_ASSIGN(StartToAppsAnimator
);
107 // Animator from start page to custom page.
108 class StartToCustomAnimator
: public ContentsAnimator
{
110 explicit StartToCustomAnimator(ContentsView
* contents_view
);
112 std::string
NameForTests() const override
;
113 void Update(double progress
, int start_page
, int custom_page
) override
;
116 DISALLOW_COPY_AND_ASSIGN(StartToCustomAnimator
);
119 } // namespace app_list
121 #endif // UI_APP_LIST_VIEWS_CONTENTS_ANIMATOR_H_