1 // Copyright (c) 2012 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_VIEW_H_
6 #define UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "ui/app_list/app_list_export.h"
16 #include "ui/app_list/app_list_model.h"
17 #include "ui/app_list/pagination_model.h"
18 #include "ui/app_list/pagination_model_observer.h"
19 #include "ui/views/view.h"
20 #include "ui/views/view_model.h"
29 class ApplicationDragAndDropHost
;
30 class AppListFolderItem
;
31 class AppListMainView
;
32 class AppListViewDelegate
;
33 class AppsContainerView
;
34 class ContentsAnimator
;
35 class PaginationModel
;
37 class SearchResultPageView
;
40 // A view to manage launcher pages within the Launcher (eg. start page, apps
41 // grid view, search results). There can be any number of launcher pages, only
42 // one of which can be active at a given time. ContentsView provides the user
43 // interface for switching between launcher pages, and animates the transition
45 class APP_LIST_EXPORT ContentsView
: public views::View
,
46 public PaginationModelObserver
{
48 explicit ContentsView(AppListMainView
* app_list_main_view
);
49 ~ContentsView() override
;
51 // Initialize the pages of the launcher. In the experimental launcher, should
52 // be called after set_contents_switcher_view(), or switcher buttons will not
54 void Init(AppListModel
* model
);
56 // The app list gets closed and drag and drop operations need to be cancelled.
59 // If |drag_and_drop| is not NULL it will be called upon drag and drop
60 // operations outside the application list.
61 void SetDragAndDropHostOfCurrentAppList(
62 ApplicationDragAndDropHost
* drag_and_drop_host
);
64 // Shows/hides the search results. Hiding the search results will cause the
65 // app list to return to the page that was displayed before
66 // ShowSearchResults(true) was invoked.
67 void ShowSearchResults(bool show
);
68 bool IsShowingSearchResults() const;
70 void ShowFolderContent(AppListFolderItem
* folder
);
72 // Sets the active launcher page and animates the pages into place.
73 void SetActivePage(int page_index
);
74 void SetActivePage(int page_index
, bool animate
);
76 // The index of the currently active launcher page.
77 int GetActivePageIndex() const;
79 // The currently active state.
80 AppListModel::State
GetActiveState() const;
82 // True if |state| is the current active laucher page.
83 bool IsStateActive(AppListModel::State state
) const;
85 // Gets the index of a launcher page in |view_model_|, by State. Returns
86 // -1 if there is no view for |state|.
87 int GetPageIndexForState(AppListModel::State state
) const;
89 // Gets the state of a launcher page in |view_model_|, by index. Returns
90 // INVALID_STATE if there is no state for |index|.
91 AppListModel::State
GetStateForPageIndex(int index
) const;
93 int NumLauncherPages() const;
97 AppsContainerView
* apps_container_view() const {
98 return apps_container_view_
;
100 StartPageView
* start_page_view() const { return start_page_view_
; }
101 views::View
* custom_page_view() const { return custom_page_view_
; }
102 SearchResultPageView
* search_results_page_view() {
103 return search_results_page_view_
;
105 views::View
* GetPageView(int index
) const;
107 SearchBoxView
* GetSearchBoxView() const;
109 AppListMainView
* app_list_main_view() const { return app_list_main_view_
; }
111 // Adds a blank launcher page. For use in tests only.
112 void AddBlankPageForTesting();
114 // Returns the pagination model for the ContentsView.
115 const PaginationModel
& pagination_model() { return pagination_model_
; }
117 // Gets the on-screen page bounds for a given launcher page with index
119 gfx::Rect
GetOnscreenPageBounds(int page_index
) const;
121 // Gets the the off-screen resting place for a given launcher page with index
123 gfx::Rect
GetOffscreenPageBounds(int page_index
) const;
125 // Returns search box bounds to use for content views that do not specify
126 // their own custom layout.
127 gfx::Rect
GetDefaultSearchBoxBounds() const;
129 // Returns search box bounds to use for a given state.
130 gfx::Rect
GetSearchBoxBoundsForState(AppListModel::State state
) const;
132 // Returns search box bounds to use for a given page index.
133 gfx::Rect
GetSearchBoxBoundsForPageIndex(int index
) const;
135 // Returns the content area bounds to use for content views that do not
136 // specify their own custom layout.
137 gfx::Rect
GetDefaultContentsBounds() const;
139 // Gets the location of the custom launcher page in "collapsed" state. This is
140 // where the page is peeking in from the bottom of the launcher (neither full
141 // on-screen or off-screen).
142 gfx::Rect
GetCustomPageCollapsedBounds() const;
144 // Exposes GetAnimatorForTransition for tests.
145 ContentsAnimator
* GetAnimatorForTransitionForTests(int from_page
,
147 bool* reverse
) const {
148 return GetAnimatorForTransition(from_page
, to_page
, reverse
);
151 // Performs the 'back' action for the active page. Returns whether the action
155 // Overridden from views::View:
156 gfx::Size
GetPreferredSize() const override
;
157 void Layout() override
;
158 bool OnKeyPressed(const ui::KeyEvent
& event
) override
;
160 // Overridden from PaginationModelObserver:
161 void TotalPagesChanged() override
;
162 void SelectedPageChanged(int old_selected
, int new_selected
) override
;
163 void TransitionStarted() override
;
164 void TransitionChanged() override
;
167 // Sets the active launcher page, accounting for whether the change is for
169 void SetActivePageInternal(int page_index
,
170 bool show_search_results
,
173 // Invoked when active view is changed.
174 void ActivePageChanged();
176 // Returns the size of the default content area.
177 gfx::Size
GetDefaultContentsSize() const;
179 // Notifies the view delegate that the custom launcher page's animation has
181 void NotifyCustomLauncherPageAnimationChanged(double progress
,
185 // Calculates and sets the bounds for the subviews. If there is currently an
186 // animation, this positions the views as appropriate for the current frame.
187 void UpdatePageBounds();
189 // Adds |view| as a new page to the end of the list of launcher pages. The
190 // view is inserted as a child of the ContentsView. There is no name
191 // associated with the page. Returns the index of the new page.
192 int AddLauncherPage(views::View
* view
);
194 // Adds |view| as a new page to the end of the list of launcher pages. The
195 // view is inserted as a child of the ContentsView. The page is associated
196 // with the name |state|. Returns the index of the new page.
197 int AddLauncherPage(views::View
* view
, AppListModel::State state
);
199 // Gets the PaginationModel owned by the AppsGridView.
200 // Note: This is different to |pagination_model_|, which manages top-level
201 // launcher-page pagination.
202 PaginationModel
* GetAppsPaginationModel();
204 // Adds a ContentsAnimator for a transition from |from_state| to |to_state|.
205 void AddAnimator(AppListModel::State from_state
,
206 AppListModel::State to_state
,
207 scoped_ptr
<ContentsAnimator
> animator
);
209 // Gets a ContentsAnimator for a transition from |from_page| to |to_page|. If
210 // the animator should be run in reverse (because it is a |to_page| to
211 // |from_page| animator), |reverse| is set to true; otherwise it is set to
213 ContentsAnimator
* GetAnimatorForTransition(int from_page
,
215 bool* reverse
) const;
217 // Special sub views of the ContentsView. All owned by the views hierarchy.
218 AppsContainerView
* apps_container_view_
;
220 SearchResultPageView
* search_results_page_view_
;
222 // Only used in the experimental app list.
223 StartPageView
* start_page_view_
;
224 views::View
* custom_page_view_
;
226 AppListMainView
* app_list_main_view_
; // Parent view, owns this.
228 scoped_ptr
<views::ViewModel
> view_model_
;
230 // Maps State onto |view_model_| indices.
231 std::map
<AppListModel::State
, int> state_to_view_
;
233 // Maps |view_model_| indices onto State.
234 std::map
<int, AppListModel::State
> view_to_state_
;
236 // The page that was showing before ShowSearchResults(true) was invoked.
237 int page_before_search_
;
239 // Manages the pagination for the launcher pages.
240 PaginationModel pagination_model_
;
242 // Maps from {A, B} pair to ContentsAnimator, where A and B are page
243 // |view_model_| indices for an animation from A to B.
244 std::map
<std::pair
<int, int>, linked_ptr
<ContentsAnimator
>>
247 // The animator for transitions not found in |contents_animators_|.
248 scoped_ptr
<ContentsAnimator
> default_animator_
;
250 DISALLOW_COPY_AND_ASSIGN(ContentsView
);
253 } // namespace app_list
255 #endif // UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_