Workaround for xkbcommon dead keys.
[chromium-blink-merge.git] / ui / app_list / views / contents_view.h
blob1b7b0cb9f79371bfbf30cd9f284cc537840d8afd
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 ApplicationDragAndDropHost;
30 class AppListFolderItem;
31 class AppListMainView;
32 class AppListViewDelegate;
33 class AppsContainerView;
34 class ContentsAnimator;
35 class PaginationModel;
36 class SearchBoxView;
37 class SearchResultListView;
38 class SearchResultPageView;
39 class StartPageView;
41 // A view to manage launcher pages within the Launcher (eg. start page, apps
42 // grid view, search results). There can be any number of launcher pages, only
43 // one of which can be active at a given time. ContentsView provides the user
44 // interface for switching between launcher pages, and animates the transition
45 // between them.
46 class APP_LIST_EXPORT ContentsView : public views::View,
47 public PaginationModelObserver {
48 public:
49 explicit ContentsView(AppListMainView* app_list_main_view);
50 ~ContentsView() override;
52 // Initialize the pages of the launcher. In the experimental launcher, should
53 // be called after set_contents_switcher_view(), or switcher buttons will not
54 // be created.
55 void Init(AppListModel* model);
57 // The app list gets closed and drag and drop operations need to be cancelled.
58 void CancelDrag();
60 // If |drag_and_drop| is not NULL it will be called upon drag and drop
61 // operations outside the application list.
62 void SetDragAndDropHostOfCurrentAppList(
63 ApplicationDragAndDropHost* drag_and_drop_host);
65 // Shows/hides the search results. Hiding the search results will cause the
66 // app list to return to the page that was displayed before
67 // ShowSearchResults(true) was invoked.
68 void ShowSearchResults(bool show);
69 bool IsShowingSearchResults() const;
71 void ShowFolderContent(AppListFolderItem* folder);
73 // Sets the active launcher page and animates the pages into place.
74 void SetActivePage(int page_index);
75 void SetActivePage(int page_index, bool animate);
77 // The index of the currently active launcher page.
78 int GetActivePageIndex() const;
80 // The currently active state.
81 AppListModel::State GetActiveState() const;
83 // True if |state| is the current active laucher page.
84 bool IsStateActive(AppListModel::State state) const;
86 // Gets the index of a launcher page in |view_model_|, by State. Returns
87 // -1 if there is no view for |state|.
88 int GetPageIndexForState(AppListModel::State state) const;
90 // Gets the state of a launcher page in |view_model_|, by index. Returns
91 // INVALID_STATE if there is no state for |index|.
92 AppListModel::State GetStateForPageIndex(int index) const;
94 int NumLauncherPages() const;
96 void Prerender();
98 AppsContainerView* apps_container_view() const {
99 return apps_container_view_;
101 StartPageView* start_page_view() const { return start_page_view_; }
102 views::View* custom_page_view() const { return custom_page_view_; }
103 SearchResultListView* search_results_list_view() const {
104 return search_results_list_view_;
106 SearchResultPageView* search_results_page_view() {
107 return search_results_page_view_;
109 views::View* GetPageView(int index) const;
111 SearchBoxView* GetSearchBoxView() const;
113 AppListMainView* app_list_main_view() const { return app_list_main_view_; }
115 // Adds a blank launcher page. For use in tests only.
116 void AddBlankPageForTesting();
118 // Returns the pagination model for the ContentsView.
119 const PaginationModel& pagination_model() { return pagination_model_; }
121 // Returns search box bounds to use for content views that do not specify
122 // their own custom layout.
123 gfx::Rect GetDefaultSearchBoxBounds() const;
125 // Returns search box bounds to use for a given state.
126 gfx::Rect GetSearchBoxBoundsForState(AppListModel::State state) const;
128 // Returns search box bounds to use for a given page index.
129 gfx::Rect GetSearchBoxBoundsForPageIndex(int index) const;
131 // Returns the content area bounds to use for content views that do not
132 // specify their own custom layout.
133 gfx::Rect GetDefaultContentsBounds() const;
135 // Gets the location of the custom launcher page in "collapsed" state. This is
136 // where the page is peeking in from the bottom of the launcher (neither full
137 // on-screen or off-screen).
138 gfx::Rect GetCustomPageCollapsedBounds() const;
140 // Exposes GetAnimatorForTransition for tests.
141 ContentsAnimator* GetAnimatorForTransitionForTests(int from_page,
142 int to_page,
143 bool* reverse) const {
144 return GetAnimatorForTransition(from_page, to_page, reverse);
147 // Determines whether the custom page clickzone widget should be displayed.
148 bool ShouldShowCustomPageClickzone() const;
150 // Performs the 'back' action for the active page. Returns whether the action
151 // was handled.
152 bool Back();
154 // Overridden from views::View:
155 gfx::Size GetPreferredSize() const override;
156 void Layout() override;
157 bool OnKeyPressed(const ui::KeyEvent& event) override;
159 // Overridden from PaginationModelObserver:
160 void TotalPagesChanged() override;
161 void SelectedPageChanged(int old_selected, int new_selected) override;
162 void TransitionStarted() override;
163 void TransitionChanged() override;
165 private:
166 // Sets the active launcher page, accounting for whether the change is for
167 // search results.
168 void SetActivePageInternal(int page_index,
169 bool show_search_results,
170 bool animate);
172 // Invoked when active view is changed.
173 void ActivePageChanged();
175 // Returns the size of the default content area.
176 gfx::Size GetDefaultContentsSize() const;
178 // Notifies the view delegate that the custom launcher page's animation has
179 // changed.
180 void NotifyCustomLauncherPageAnimationChanged(double progress,
181 int current_page,
182 int target_page);
184 // Calculates and sets the bounds for the subviews. If there is currently an
185 // animation, this positions the views as appropriate for the current frame.
186 void UpdatePageBounds();
188 // Adds |view| as a new page to the end of the list of launcher pages. The
189 // view is inserted as a child of the ContentsView. There is no name
190 // associated with the page. Returns the index of the new page.
191 int AddLauncherPage(views::View* view);
193 // Adds |view| as a new page to the end of the list of launcher pages. The
194 // view is inserted as a child of the ContentsView. The page is associated
195 // with the name |state|. Returns the index of the new page.
196 int AddLauncherPage(views::View* view, AppListModel::State state);
198 // Gets the PaginationModel owned by the AppsGridView.
199 // Note: This is different to |pagination_model_|, which manages top-level
200 // launcher-page pagination.
201 PaginationModel* GetAppsPaginationModel();
203 // Adds a ContentsAnimator for a transition from |from_state| to |to_state|.
204 void AddAnimator(AppListModel::State from_state,
205 AppListModel::State to_state,
206 scoped_ptr<ContentsAnimator> animator);
208 // Gets a ContentsAnimator for a transition from |from_page| to |to_page|. If
209 // the animator should be run in reverse (because it is a |to_page| to
210 // |from_page| animator), |reverse| is set to true; otherwise it is set to
211 // false.
212 ContentsAnimator* GetAnimatorForTransition(int from_page,
213 int to_page,
214 bool* reverse) const;
216 // Special sub views of the ContentsView. All owned by the views hierarchy.
217 AppsContainerView* apps_container_view_;
219 // Only used in the normal app list.
220 SearchResultListView* search_results_list_view_;
222 // Only used in the experimental app list.
223 SearchResultPageView* search_results_page_view_;
224 StartPageView* start_page_view_;
225 views::View* custom_page_view_;
227 AppListMainView* app_list_main_view_; // Parent view, owns this.
229 scoped_ptr<views::ViewModel> view_model_;
231 // Maps State onto |view_model_| indices.
232 std::map<AppListModel::State, int> state_to_view_;
234 // Maps |view_model_| indices onto State.
235 std::map<int, AppListModel::State> view_to_state_;
237 // The page that was showing before ShowSearchResults(true) was invoked.
238 int page_before_search_;
240 // Manages the pagination for the launcher pages.
241 PaginationModel pagination_model_;
243 // Maps from {A, B} pair to ContentsAnimator, where A and B are page
244 // |view_model_| indices for an animation from A to B.
245 std::map<std::pair<int, int>, linked_ptr<ContentsAnimator>>
246 contents_animators_;
248 // The animator for transitions not found in |contents_animators_|.
249 scoped_ptr<ContentsAnimator> default_animator_;
251 DISALLOW_COPY_AND_ASSIGN(ContentsView);
254 } // namespace app_list
256 #endif // UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_