Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / app_list / views / contents_view.h
blob14c462e0116ff6b6972c0781ae951dd8dde2d99c
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_
8 #include <map>
9 #include <utility>
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"
22 namespace gfx {
23 class Rect;
26 namespace app_list {
28 class AppsGridView;
29 class AppListPage;
30 class ApplicationDragAndDropHost;
31 class AppListFolderItem;
32 class AppListMainView;
33 class AppListViewDelegate;
34 class AppsContainerView;
35 class CustomLauncherPageView;
36 class ContentsAnimator;
37 class PaginationModel;
38 class SearchBoxView;
39 class SearchResultPageView;
40 class StartPageView;
42 // A view to manage launcher pages within the Launcher (eg. start page, apps
43 // grid view, search results). There can be any number of launcher pages, only
44 // one of which can be active at a given time. ContentsView provides the user
45 // interface for switching between launcher pages, and animates the transition
46 // between them.
47 class APP_LIST_EXPORT ContentsView : public views::View,
48 public PaginationModelObserver {
49 public:
50 explicit ContentsView(AppListMainView* app_list_main_view);
51 ~ContentsView() override;
53 // Initialize the pages of the launcher. In the experimental launcher, should
54 // be called after set_contents_switcher_view(), or switcher buttons will not
55 // be created.
56 void Init(AppListModel* model);
58 // The app list gets closed and drag and drop operations need to be cancelled.
59 void CancelDrag();
61 // If |drag_and_drop| is not NULL it will be called upon drag and drop
62 // operations outside the application list.
63 void SetDragAndDropHostOfCurrentAppList(
64 ApplicationDragAndDropHost* drag_and_drop_host);
66 // Shows/hides the search results. Hiding the search results will cause the
67 // app list to return to the page that was displayed before
68 // ShowSearchResults(true) was invoked.
69 void ShowSearchResults(bool show);
70 bool IsShowingSearchResults() const;
72 void ShowFolderContent(AppListFolderItem* folder);
74 // Sets the active launcher page and animates the pages into place.
75 void SetActiveState(AppListModel::State state);
76 void SetActiveState(AppListModel::State state, bool animate);
78 // The index of the currently active launcher page.
79 int GetActivePageIndex() const;
81 // The currently active state.
82 AppListModel::State GetActiveState() const;
84 // True if |state| is the current active laucher page.
85 bool IsStateActive(AppListModel::State state) const;
87 // Gets the index of a launcher page in |view_model_|, by State. Returns
88 // -1 if there is no view for |state|.
89 int GetPageIndexForState(AppListModel::State state) const;
91 // Gets the state of a launcher page in |view_model_|, by index. Returns
92 // INVALID_STATE if there is no state for |index|.
93 AppListModel::State GetStateForPageIndex(int index) const;
95 int NumLauncherPages() const;
97 void Prerender();
99 AppsContainerView* apps_container_view() const {
100 return apps_container_view_;
102 StartPageView* start_page_view() const { return start_page_view_; }
103 CustomLauncherPageView* custom_page_view() const { return custom_page_view_; }
104 SearchResultPageView* search_results_page_view() {
105 return search_results_page_view_;
107 AppListPage* GetPageView(int index) const;
109 SearchBoxView* GetSearchBoxView() const;
111 AppListMainView* app_list_main_view() const { return app_list_main_view_; }
113 // Returns the pagination model for the ContentsView.
114 const PaginationModel& pagination_model() { return pagination_model_; }
116 // Returns search box bounds to use for content views that do not specify
117 // their own custom layout.
118 gfx::Rect GetDefaultSearchBoxBounds() const;
120 // Returns search box bounds to use for a given state.
121 gfx::Rect GetSearchBoxBoundsForState(AppListModel::State state) const;
123 // Returns the content area bounds to use for content views that do not
124 // specify their own custom layout.
125 gfx::Rect GetDefaultContentsBounds() const;
127 // Performs the 'back' action for the active page. Returns whether the action
128 // was handled.
129 bool Back();
131 // Overridden from views::View:
132 gfx::Size GetPreferredSize() const override;
133 void Layout() override;
134 bool OnKeyPressed(const ui::KeyEvent& event) override;
136 // Overridden from PaginationModelObserver:
137 void TotalPagesChanged() override;
138 void SelectedPageChanged(int old_selected, int new_selected) override;
139 void TransitionStarted() override;
140 void TransitionChanged() override;
142 private:
143 // Sets the active launcher page, accounting for whether the change is for
144 // search results.
145 void SetActiveStateInternal(int page_index,
146 bool show_search_results,
147 bool animate);
149 // Invoked when active view is changed.
150 void ActivePageChanged();
152 // Returns the size of the default content area.
153 gfx::Size GetDefaultContentsSize() const;
155 // Notifies the view delegate that the custom launcher page's animation has
156 // changed.
157 void NotifyCustomLauncherPageAnimationChanged(double progress,
158 int current_page,
159 int target_page);
161 // Calculates and sets the bounds for the subviews. If there is currently an
162 // animation, this positions the views as appropriate for the current frame.
163 void UpdatePageBounds();
165 void UpdateSearchBox(double progress,
166 AppListModel::State current_state,
167 AppListModel::State target_state);
169 // Adds |view| as a new page to the end of the list of launcher pages. The
170 // view is inserted as a child of the ContentsView. There is no name
171 // associated with the page. Returns the index of the new page.
172 int AddLauncherPage(AppListPage* view);
174 // Adds |view| as a new page to the end of the list of launcher pages. The
175 // view is inserted as a child of the ContentsView. The page is associated
176 // with the name |state|. Returns the index of the new page.
177 int AddLauncherPage(AppListPage* view, AppListModel::State state);
179 // Gets the PaginationModel owned by the AppsGridView.
180 // Note: This is different to |pagination_model_|, which manages top-level
181 // launcher-page pagination.
182 PaginationModel* GetAppsPaginationModel();
184 // Special sub views of the ContentsView. All owned by the views hierarchy.
185 AppsContainerView* apps_container_view_;
186 SearchResultPageView* search_results_page_view_;
188 // Only used in the experimental app list.
189 StartPageView* start_page_view_;
190 CustomLauncherPageView* custom_page_view_;
192 // The child page views. Owned by the views hierarchy.
193 std::vector<AppListPage*> app_list_pages_;
195 // Parent view. Owned by the views hierarchy.
196 AppListMainView* app_list_main_view_;
198 // Maps State onto |view_model_| indices.
199 std::map<AppListModel::State, int> state_to_view_;
201 // Maps |view_model_| indices onto State.
202 std::map<int, AppListModel::State> view_to_state_;
204 // The page that was showing before ShowSearchResults(true) was invoked.
205 int page_before_search_;
207 // Manages the pagination for the launcher pages.
208 PaginationModel pagination_model_;
210 DISALLOW_COPY_AND_ASSIGN(ContentsView);
213 } // namespace app_list
215 #endif // UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_