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. 4 5 #ifndef UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_ 6 #define UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_ 7 8 #include <map> 9 10 #include "base/basictypes.h" 11 #include "base/compiler_specific.h" 12 #include "base/memory/scoped_ptr.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" 16 #include "ui/views/view.h" 17 18 namespace gfx { 19 class Rect; 20 } 21 22 namespace views { 23 class ViewModel; 24 } 25 26 namespace app_list { 27 28 class AppsGridView; 29 class ApplicationDragAndDropHost; 30 class AppListFolderItem; 31 class AppListMainView; 32 class AppListModel; 33 class AppListViewDelegate; 34 class AppsContainerView; 35 class ContentsSwitcherView; 36 class PaginationModel; 37 class SearchResultListView; 38 class StartPageView; 39 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 44 // between them. 45 class APP_LIST_EXPORT ContentsView : public views::View, 46 public PaginationModelObserver { 47 public: 48 // Values of this enum denote special launcher pages that require hard-coding. 49 // Launcher pages are not required to have a NamedPage enum value. 50 enum NamedPage { 51 NAMED_PAGE_APPS, 52 NAMED_PAGE_SEARCH_RESULTS, 53 NAMED_PAGE_START, 54 }; 55 56 ContentsView(AppListMainView* app_list_main_view); 57 virtual ~ContentsView(); 58 59 // Initialize the named (special) pages of the launcher. In the experimental 60 // launcher, should be called after set_contents_switcher_view(), or switcher 61 // buttons will not be created. 62 void InitNamedPages(AppListModel* model, AppListViewDelegate* view_delegate); 63 64 // The app list gets closed and drag and drop operations need to be cancelled. 65 void CancelDrag(); 66 67 // If |drag_and_drop| is not NULL it will be called upon drag and drop 68 // operations outside the application list. 69 void SetDragAndDropHostOfCurrentAppList( 70 ApplicationDragAndDropHost* drag_and_drop_host); 71 72 void SetContentsSwitcherView(ContentsSwitcherView* contents_switcher_view); 73 74 // Shows/hides the search results. Hiding the search results will cause the 75 // app list to return to the page that was displayed before 76 // ShowSearchResults(true) was invoked. 77 void ShowSearchResults(bool show); 78 bool IsShowingSearchResults() const; 79 80 void ShowFolderContent(AppListFolderItem* folder); 81 82 // Sets the active launcher page and animates the pages into place. 83 void SetActivePage(int page_index); 84 85 // The index of the currently active launcher page. 86 int GetActivePageIndex() const; 87 88 // True if |named_page| is the current active laucher page. 89 bool IsNamedPageActive(NamedPage named_page) const; 90 91 // Gets the index of a launcher page in |view_model_|, by NamedPage. Returns 92 // -1 if there is no view for |named_page|. 93 int GetPageIndexForNamedPage(NamedPage named_page) const; 94 95 int NumLauncherPages() const; 96 97 void Prerender(); 98 apps_container_view()99 AppsContainerView* apps_container_view() { return apps_container_view_; } start_page_view()100 StartPageView* start_page_view() { return start_page_view_; } search_results_view()101 SearchResultListView* search_results_view() { return search_results_view_; } 102 views::View* GetPageView(int index); 103 104 // Adds a blank launcher page. For use in tests only. 105 void AddBlankPageForTesting(); 106 107 // Overridden from views::View: 108 virtual gfx::Size GetPreferredSize() const OVERRIDE; 109 virtual void Layout() OVERRIDE; 110 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; 111 112 // Overridden from PaginationModelObserver: 113 virtual void TotalPagesChanged() OVERRIDE; 114 virtual void SelectedPageChanged(int old_selected, int new_selected) OVERRIDE; 115 virtual void TransitionStarted() OVERRIDE; 116 virtual void TransitionChanged() OVERRIDE; 117 118 // Returns the pagination model for the ContentsView. pagination_model()119 const PaginationModel& pagination_model() { return pagination_model_; } 120 121 private: 122 // Sets the active launcher page, accounting for whether the change is for 123 // search results. 124 void SetActivePageInternal(int page_index, bool show_search_results); 125 126 // Invoked when active view is changed. 127 void ActivePageChanged(bool show_search_results); 128 129 // Gets the origin (the off-screen resting place) for a given launcher page 130 // with index |page_index|. 131 gfx::Rect GetOffscreenPageBounds(int page_index) const; 132 133 // Calculates and sets the bounds for the subviews. If there is currently an 134 // animation, this positions the views as appropriate for the current frame. 135 void UpdatePageBounds(); 136 137 // Adds |view| as a new page to the end of the list of launcher pages. The 138 // view is inserted as a child of the ContentsView, and a button with 139 // |resource_id| is added to the ContentsSwitcherView. There is no name 140 // associated with the page. Returns the index of the new page. 141 int AddLauncherPage(views::View* view, int resource_id); 142 143 // Adds |view| as a new page to the end of the list of launcher pages. The 144 // view is inserted as a child of the ContentsView, and a button with 145 // |resource_id| is added to the ContentsSwitcherView. The page is associated 146 // with the name |named_page|. Returns the index of the new page. 147 int AddLauncherPage(views::View* view, int resource_id, NamedPage named_page); 148 149 // Gets the PaginationModel owned by the AppsGridView. 150 // Note: This is different to |pagination_model_|, which manages top-level 151 // launcher-page pagination. 152 PaginationModel* GetAppsPaginationModel(); 153 154 // Special sub views of the ContentsView. All owned by the views hierarchy. 155 AppsContainerView* apps_container_view_; 156 SearchResultListView* search_results_view_; 157 StartPageView* start_page_view_; 158 159 AppListMainView* app_list_main_view_; // Parent view, owns this. 160 // Sibling view, owned by |app_list_main_view_|. 161 ContentsSwitcherView* contents_switcher_view_; 162 163 scoped_ptr<views::ViewModel> view_model_; 164 // Maps NamedPage onto |view_model_| indices. 165 std::map<NamedPage, int> named_page_to_view_; 166 167 // The page that was showing before ShowSearchResults(true) was invoked. 168 int page_before_search_; 169 170 // Manages the pagination for the launcher pages. 171 PaginationModel pagination_model_; 172 173 DISALLOW_COPY_AND_ASSIGN(ContentsView); 174 }; 175 176 } // namespace app_list 177 178 #endif // UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_ 179