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