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 // Updates the position of the custom launcher page view (if it exists), in
43 // the default way for start page <-> other page transitions. This places it
44 // into collapsed state on the start page, and hidden on any other page. Any
45 // other behaviour should be implemented with a custom animator. |progress|,
46 // |from_page| and |to_page| are parameters from Update().
47 void UpdateCustomPageForDefaultAnimation(double progress
,
51 // Updates the position of the search box view, placing it in the correct
52 // position for the transition from |from_page| to |to_page|.
53 void UpdateSearchBoxForDefaultAnimation(double progress
,
57 // Clips the drawing of the search results page to its onscreen bounds.
58 void ClipSearchResultsPageToOnscreenBounds(int page_index
,
59 const gfx::Rect
& current_bounds
,
60 const gfx::Rect
& onscreen_bounds
);
63 ContentsView
* contents_view_
;
65 DISALLOW_COPY_AND_ASSIGN(ContentsAnimator
);
68 // Simple animator that slides pages in and out vertically. Appropriate for any
70 class DefaultAnimator
: public ContentsAnimator
{
72 explicit DefaultAnimator(ContentsView
* contents_view
);
74 ~DefaultAnimator() override
{}
76 // ContentsAnimator overrides:
77 std::string
NameForTests() const override
;
78 void Update(double progress
, int from_page
, int to_page
) override
;
81 DISALLOW_COPY_AND_ASSIGN(DefaultAnimator
);
84 // Animator between the start page and apps grid page.
85 class StartToAppsAnimator
: public ContentsAnimator
{
87 explicit StartToAppsAnimator(ContentsView
* contents_view
);
89 ~StartToAppsAnimator() override
{}
91 // ContentsAnimator overrides:
92 std::string
NameForTests() const override
;
93 void Update(double progress
, int start_page
, int apps_page
) override
;
96 DISALLOW_COPY_AND_ASSIGN(StartToAppsAnimator
);
99 // Animator from start page to custom page.
100 class StartToCustomAnimator
: public ContentsAnimator
{
102 explicit StartToCustomAnimator(ContentsView
* contents_view
);
104 std::string
NameForTests() const override
;
105 void Update(double progress
, int start_page
, int custom_page
) override
;
108 DISALLOW_COPY_AND_ASSIGN(StartToCustomAnimator
);
111 } // namespace app_list
113 #endif // UI_APP_LIST_VIEWS_CONTENTS_ANIMATOR_H_