Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / app_list / views / contents_view.h
blobb828490ad942a4b8eb18b46eb10d6d0fd33b7047
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>
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"
18 namespace views {
19 class ViewModel;
22 namespace app_list {
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;
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,
52 ContentsView(AppListMainView* app_list_main_view);
53 virtual ~ContentsView();
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);
60 // The app list gets closed and drag and drop operations need to be cancelled.
61 void CancelDrag();
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);
68 void SetContentsSwitcherView(ContentsSwitcherView* contents_switcher_view);
70 // Shows/hides the search results. Hiding the search results will cause the
71 // app list to return to the page that was displayed before
72 // ShowSearchResults(true) was invoked.
73 void ShowSearchResults(bool show);
74 bool IsShowingSearchResults() const;
76 void ShowFolderContent(AppListFolderItem* folder);
78 // Sets the active launcher page and animates the pages into place.
79 void SetActivePage(int page_index);
81 // The index of the currently active launcher page.
82 int GetActivePageIndex() const;
84 // True if |named_page| is the current active laucher page.
85 bool IsNamedPageActive(NamedPage named_page) const;
87 // Gets the index of a launcher page in |view_model_|, by NamedPage.
88 int GetPageIndexForNamedPage(NamedPage named_page) const;
90 int NumLauncherPages() const;
92 void Prerender();
94 AppsContainerView* apps_container_view() { return apps_container_view_; }
95 StartPageView* start_page_view() { return start_page_view_; }
96 SearchResultListView* search_results_view() { return search_results_view_; }
97 views::View* GetPageView(int index);
99 // Adds a blank launcher page. For use in tests only.
100 void AddBlankPageForTesting();
102 // Overridden from views::View:
103 virtual gfx::Size GetPreferredSize() const OVERRIDE;
104 virtual void Layout() OVERRIDE;
105 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
106 virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE;
108 // Overridden from PaginationModelObserver:
109 virtual void TotalPagesChanged() OVERRIDE;
110 virtual void SelectedPageChanged(int old_selected, int new_selected) OVERRIDE;
111 virtual void TransitionStarted() OVERRIDE;
112 virtual void TransitionChanged() OVERRIDE;
114 // Returns the pagination model for the ContentsView.
115 const PaginationModel& pagination_model() { return pagination_model_; }
117 private:
118 // Sets the active launcher page, accounting for whether the change is for
119 // search results.
120 void SetActivePageInternal(int page_index, bool show_search_results);
122 // Invoked when active view is changed.
123 void ActivePageChanged(bool show_search_results);
125 // Calculates and sets the bounds for the subviews. If there is currently an
126 // animation, this positions the views as appropriate for the current frame.
127 void UpdatePageBounds();
129 // Adds |view| as a new page to the end of the list of launcher pages. The
130 // view is inserted as a child of the ContentsView, and a button with
131 // |resource_id| is added to the ContentsSwitcherView. There is no name
132 // associated with the page. Returns the index of the new page.
133 int AddLauncherPage(views::View* view, int resource_id);
135 // Adds |view| as a new page to the end of the list of launcher pages. The
136 // view is inserted as a child of the ContentsView, and a button with
137 // |resource_id| is added to the ContentsSwitcherView. The page is associated
138 // with the name |named_page|. Returns the index of the new page.
139 int AddLauncherPage(views::View* view, int resource_id, NamedPage named_page);
141 // Gets the PaginationModel owned by the AppsGridView.
142 // Note: This is different to |pagination_model_|, which manages top-level
143 // launcher-page pagination.
144 PaginationModel* GetAppsPaginationModel();
146 // Overridden from ui::EventHandler:
147 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
148 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
150 // Special sub views of the ContentsView. All owned by the views hierarchy.
151 AppsContainerView* apps_container_view_;
152 SearchResultListView* search_results_view_;
153 StartPageView* start_page_view_;
155 AppListMainView* app_list_main_view_; // Parent view, owns this.
156 // Sibling view, owned by |app_list_main_view_|.
157 ContentsSwitcherView* contents_switcher_view_;
159 scoped_ptr<views::ViewModel> view_model_;
160 // Maps NamedPage onto |view_model_| indices.
161 std::map<NamedPage, int> named_page_to_view_;
163 // The page that was showing before ShowSearchResults(true) was invoked.
164 int page_before_search_;
166 // Manages the pagination for the launcher pages.
167 PaginationModel pagination_model_;
169 DISALLOW_COPY_AND_ASSIGN(ContentsView);
172 } // namespace app_list
174 #endif // UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_