OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_ | 5 #ifndef UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_ |
6 #define UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_ | 6 #define UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "ui/app_list/app_list_export.h" | 13 #include "ui/app_list/app_list_export.h" |
| 14 #include "ui/app_list/pagination_model.h" |
| 15 #include "ui/app_list/pagination_model_observer.h" |
14 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
15 | 17 |
16 namespace views { | 18 namespace views { |
17 class BoundsAnimator; | |
18 class ViewModel; | 19 class ViewModel; |
19 } | 20 } |
20 | 21 |
21 namespace app_list { | 22 namespace app_list { |
22 | 23 |
23 class AppsGridView; | 24 class AppsGridView; |
24 class ApplicationDragAndDropHost; | 25 class ApplicationDragAndDropHost; |
25 class AppListFolderItem; | 26 class AppListFolderItem; |
26 class AppListMainView; | 27 class AppListMainView; |
27 class AppListModel; | 28 class AppListModel; |
28 class AppListViewDelegate; | 29 class AppListViewDelegate; |
29 class AppsContainerView; | 30 class AppsContainerView; |
30 class PaginationModel; | 31 class PaginationModel; |
31 class SearchResultListView; | 32 class SearchResultListView; |
32 class StartPageView; | 33 class StartPageView; |
33 | 34 |
34 // A view to manage launcher pages within the Launcher (eg. start page, apps | 35 // A view to manage launcher pages within the Launcher (eg. start page, apps |
35 // grid view, search results). There can be any number of launcher pages, only | 36 // grid view, search results). There can be any number of launcher pages, only |
36 // one of which can be active at a given time. ContentsView provides the user | 37 // one of which can be active at a given time. ContentsView provides the user |
37 // interface for switching between launcher pages, and animates the transition | 38 // interface for switching between launcher pages, and animates the transition |
38 // between them. | 39 // between them. |
39 class APP_LIST_EXPORT ContentsView : public views::View { | 40 class APP_LIST_EXPORT ContentsView : public views::View, |
| 41 public PaginationModelObserver { |
40 public: | 42 public: |
41 // Values of this enum denote special launcher pages that require hard-coding. | 43 // Values of this enum denote special launcher pages that require hard-coding. |
42 // Launcher pages are not required to have a NamedPage enum value. | 44 // Launcher pages are not required to have a NamedPage enum value. |
43 enum NamedPage { | 45 enum NamedPage { |
44 NAMED_PAGE_APPS, | 46 NAMED_PAGE_APPS, |
45 NAMED_PAGE_SEARCH_RESULTS, | 47 NAMED_PAGE_SEARCH_RESULTS, |
46 NAMED_PAGE_START, | 48 NAMED_PAGE_START, |
47 }; | 49 }; |
48 | 50 |
49 ContentsView(AppListMainView* app_list_main_view, | 51 ContentsView(AppListMainView* app_list_main_view, |
(...skipping 10 matching lines...) Expand all Loading... |
60 ApplicationDragAndDropHost* drag_and_drop_host); | 62 ApplicationDragAndDropHost* drag_and_drop_host); |
61 | 63 |
62 void ShowSearchResults(bool show); | 64 void ShowSearchResults(bool show); |
63 void ShowFolderContent(AppListFolderItem* folder); | 65 void ShowFolderContent(AppListFolderItem* folder); |
64 bool IsShowingSearchResults() const; | 66 bool IsShowingSearchResults() const; |
65 | 67 |
66 // Sets the active launcher page and animates the pages into place. | 68 // Sets the active launcher page and animates the pages into place. |
67 void SetActivePage(int page_index); | 69 void SetActivePage(int page_index); |
68 | 70 |
69 // The index of the currently active launcher page. | 71 // The index of the currently active launcher page. |
70 int active_page_index() const { return active_page_; } | 72 int GetActivePageIndex() const; |
71 | 73 |
72 // True if |named_page| is the current active laucher page. | 74 // True if |named_page| is the current active laucher page. |
73 bool IsNamedPageActive(NamedPage named_page) const; | 75 bool IsNamedPageActive(NamedPage named_page) const; |
74 | 76 |
75 // Gets the index of a launcher page in |view_model_|, by NamedPage. | 77 // Gets the index of a launcher page in |view_model_|, by NamedPage. |
76 int GetPageIndexForNamedPage(NamedPage named_page) const; | 78 int GetPageIndexForNamedPage(NamedPage named_page) const; |
77 | 79 |
| 80 int NumLauncherPages() const; |
| 81 |
78 void Prerender(); | 82 void Prerender(); |
79 | 83 |
80 AppsContainerView* apps_container_view() { return apps_container_view_; } | 84 AppsContainerView* apps_container_view() { return apps_container_view_; } |
81 StartPageView* start_page_view() { return start_page_view_; } | 85 StartPageView* start_page_view() { return start_page_view_; } |
82 SearchResultListView* search_results_view() { return search_results_view_; } | 86 SearchResultListView* search_results_view() { return search_results_view_; } |
| 87 views::View* GetPageView(int index); |
| 88 |
| 89 // Adds a blank launcher page. For use in tests only. |
| 90 void AddBlankPageForTesting(); |
83 | 91 |
84 // Overridden from views::View: | 92 // Overridden from views::View: |
85 virtual gfx::Size GetPreferredSize() const OVERRIDE; | 93 virtual gfx::Size GetPreferredSize() const OVERRIDE; |
86 virtual void Layout() OVERRIDE; | 94 virtual void Layout() OVERRIDE; |
87 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; | 95 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; |
88 virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE; | 96 virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE; |
89 | 97 |
| 98 // Overridden from PaginationModelObserver: |
| 99 virtual void TotalPagesChanged() OVERRIDE; |
| 100 virtual void SelectedPageChanged(int old_selected, int new_selected) OVERRIDE; |
| 101 virtual void TransitionStarted() OVERRIDE; |
| 102 virtual void TransitionChanged() OVERRIDE; |
| 103 |
90 private: | 104 private: |
91 // Sets the active launcher page, accounting for whether the change is for | 105 // Sets the active launcher page, accounting for whether the change is for |
92 // search results. | 106 // search results. |
93 void SetActivePageInternal(int page_index, bool show_search_results); | 107 void SetActivePageInternal(int page_index, bool show_search_results); |
94 | 108 |
95 // Invoked when active view is changed. | 109 // Invoked when active view is changed. |
96 void ActivePageChanged(bool show_search_results); | 110 void ActivePageChanged(bool show_search_results); |
97 | 111 |
98 void CalculateIdealBounds(); | 112 // Calculates and sets the bounds for the subviews. If there is currently an |
99 void AnimateToIdealBounds(); | 113 // animation, this positions the views as appropriate for the current frame. |
| 114 void UpdatePageBounds(); |
100 | 115 |
101 // Adds |view| as a new page to the end of the list of launcher pages. The | 116 // Adds |view| as a new page to the end of the list of launcher pages. The |
102 // view is inserted as a child of the ContentsView. There is no name | 117 // view is inserted as a child of the ContentsView. There is no name |
103 // associated with the page. Returns the index of the new page. | 118 // associated with the page. Returns the index of the new page. |
104 int AddLauncherPage(views::View* view); | 119 int AddLauncherPage(views::View* view); |
105 | 120 |
106 // Adds |view| as a new page to the end of the list of launcher pages. The | 121 // Adds |view| as a new page to the end of the list of launcher pages. The |
107 // view is inserted as a child of the ContentsView. The page is associated | 122 // view is inserted as a child of the ContentsView. The page is associated |
108 // with the name |named_page|. Returns the index of the new page. | 123 // with the name |named_page|. Returns the index of the new page. |
109 int AddLauncherPage(views::View* view, NamedPage named_page); | 124 int AddLauncherPage(views::View* view, NamedPage named_page); |
110 | 125 |
111 // Gets the PaginationModel owned by the AppsGridView. | 126 // Gets the PaginationModel owned by the AppsGridView. |
| 127 // Note: This is different to |pagination_model_|, which manages top-level |
| 128 // launcher-page pagination. |
112 PaginationModel* GetAppsPaginationModel(); | 129 PaginationModel* GetAppsPaginationModel(); |
113 | 130 |
114 // Overridden from ui::EventHandler: | 131 // Overridden from ui::EventHandler: |
115 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 132 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
116 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; | 133 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; |
117 | 134 |
118 // Index into |view_model_| of the currently active page. | |
119 int active_page_; | |
120 | |
121 // Special sub views of the ContentsView. All owned by the views hierarchy. | 135 // Special sub views of the ContentsView. All owned by the views hierarchy. |
122 AppsContainerView* apps_container_view_; | 136 AppsContainerView* apps_container_view_; |
123 SearchResultListView* search_results_view_; | 137 SearchResultListView* search_results_view_; |
124 StartPageView* start_page_view_; | 138 StartPageView* start_page_view_; |
125 | 139 |
126 AppListMainView* app_list_main_view_; // Parent view, owns this. | 140 AppListMainView* app_list_main_view_; // Parent view, owns this. |
127 | 141 |
128 scoped_ptr<views::ViewModel> view_model_; | 142 scoped_ptr<views::ViewModel> view_model_; |
129 // Maps NamedPage onto |view_model_| indices. | 143 // Maps NamedPage onto |view_model_| indices. |
130 std::map<NamedPage, int> named_page_to_view_; | 144 std::map<NamedPage, int> named_page_to_view_; |
131 scoped_ptr<views::BoundsAnimator> bounds_animator_; | 145 |
| 146 // Manages the pagination for the launcher pages. |
| 147 PaginationModel pagination_model_; |
132 | 148 |
133 DISALLOW_COPY_AND_ASSIGN(ContentsView); | 149 DISALLOW_COPY_AND_ASSIGN(ContentsView); |
134 }; | 150 }; |
135 | 151 |
136 } // namespace app_list | 152 } // namespace app_list |
137 | 153 |
138 #endif // UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_ | 154 #endif // UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_ |
OLD | NEW |