Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / app_list / views / contents_view.h
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/app_list_model.h"
15 #include "ui/app_list/pagination_model.h"
16 #include "ui/app_list/pagination_model_observer.h"
17 #include "ui/views/view.h"
18 #include "ui/views/view_model.h"
19
20 namespace gfx {
21 class Rect;
22 }
23
24 namespace app_list {
25
26 class AppsGridView;
27 class ApplicationDragAndDropHost;
28 class AppListFolderItem;
29 class AppListMainView;
30 class AppListModel;
31 class AppListViewDelegate;
32 class AppsContainerView;
33 class ContentsSwitcherView;
34 class PaginationModel;
35 class SearchResultListView;
36 class StartPageView;
37
38 // A view to manage launcher pages within the Launcher (eg. start page, apps
39 // grid view, search results). There can be any number of launcher pages, only
40 // one of which can be active at a given time. ContentsView provides the user
41 // interface for switching between launcher pages, and animates the transition
42 // between them.
43 class APP_LIST_EXPORT ContentsView : public views::View,
44                                      public PaginationModelObserver {
45  public:
46   ContentsView(AppListMainView* app_list_main_view);
47   ~ContentsView() override;
48
49   // Initialize the pages of the launcher. In the experimental launcher, should
50   // be called after set_contents_switcher_view(), or switcher buttons will not
51   // be created.
52   void Init(AppListModel* model, AppListViewDelegate* view_delegate);
53
54   // The app list gets closed and drag and drop operations need to be cancelled.
55   void CancelDrag();
56
57   // If |drag_and_drop| is not NULL it will be called upon drag and drop
58   // operations outside the application list.
59   void SetDragAndDropHostOfCurrentAppList(
60       ApplicationDragAndDropHost* drag_and_drop_host);
61
62   void SetContentsSwitcherView(ContentsSwitcherView* contents_switcher_view);
63
64   // Shows/hides the search results. Hiding the search results will cause the
65   // app list to return to the page that was displayed before
66   // ShowSearchResults(true) was invoked.
67   void ShowSearchResults(bool show);
68   bool IsShowingSearchResults() const;
69
70   void ShowFolderContent(AppListFolderItem* folder);
71
72   // Sets the active launcher page and animates the pages into place.
73   void SetActivePage(int page_index);
74
75   // The index of the currently active launcher page.
76   int GetActivePageIndex() const;
77
78   // True if |state| is the current active laucher page.
79   bool IsStateActive(AppListModel::State state) const;
80
81   // Gets the index of a launcher page in |view_model_|, by State. Returns
82   // -1 if there is no view for |state|.
83   int GetPageIndexForState(AppListModel::State state) const;
84
85   int NumLauncherPages() const;
86
87   void Prerender();
88
89   AppsContainerView* apps_container_view() { return apps_container_view_; }
90   StartPageView* start_page_view() { return start_page_view_; }
91   SearchResultListView* search_results_view() { return search_results_view_; }
92   views::View* GetPageView(int index);
93
94   // Adds a blank launcher page. For use in tests only.
95   void AddBlankPageForTesting();
96
97   // Returns the pagination model for the ContentsView.
98   const PaginationModel& pagination_model() { return pagination_model_; }
99
100   // Returns search box bounds to use for content views that do not specify
101   // their own custom layout.
102   gfx::Rect GetDefaultSearchBoxBounds() const;
103
104   // Returns the content area bounds to use for content views that do not
105   // specify their own custom layout.
106   gfx::Rect GetDefaultContentsBounds() const;
107
108   // Overridden from views::View:
109   gfx::Size GetPreferredSize() const override;
110   void Layout() override;
111   bool OnKeyPressed(const ui::KeyEvent& event) override;
112
113   // Overridden from PaginationModelObserver:
114   void TotalPagesChanged() override;
115   void SelectedPageChanged(int old_selected, int new_selected) override;
116   void TransitionStarted() override;
117   void TransitionChanged() override;
118
119  private:
120   // Sets the active launcher page, accounting for whether the change is for
121   // search results.
122   void SetActivePageInternal(int page_index, bool show_search_results);
123
124   // Invoked when active view is changed.
125   void ActivePageChanged(bool show_search_results);
126
127   // Returns the size of the default content area.
128   gfx::Size GetDefaultContentsSize() const;
129
130   // Gets the origin (the off-screen resting place) for a given launcher page
131   // with index |page_index|.
132   gfx::Rect GetOffscreenPageBounds(int page_index) const;
133
134   // Calculates and sets the bounds for the subviews. If there is currently an
135   // animation, this positions the views as appropriate for the current frame.
136   void UpdatePageBounds();
137
138   // Adds |view| as a new page to the end of the list of launcher pages. The
139   // view is inserted as a child of the ContentsView, and a button with
140   // |resource_id| is added to the ContentsSwitcherView. There is no name
141   // associated with the page. Returns the index of the new page.
142   int AddLauncherPage(views::View* view, int resource_id);
143
144   // Adds |view| as a new page to the end of the list of launcher pages. The
145   // view is inserted as a child of the ContentsView, and a button with
146   // |resource_id| is added to the ContentsSwitcherView. The page is associated
147   // with the name |state|. Returns the index of the new page.
148   int AddLauncherPage(views::View* view,
149                       int resource_id,
150                       AppListModel::State state);
151
152   // Gets the PaginationModel owned by the AppsGridView.
153   // Note: This is different to |pagination_model_|, which manages top-level
154   // launcher-page pagination.
155   PaginationModel* GetAppsPaginationModel();
156
157   // Special sub views of the ContentsView. All owned by the views hierarchy.
158   AppsContainerView* apps_container_view_;
159   SearchResultListView* search_results_view_;
160   StartPageView* start_page_view_;
161
162   AppListMainView* app_list_main_view_;     // Parent view, owns this.
163   // Sibling view, owned by |app_list_main_view_|.
164   ContentsSwitcherView* contents_switcher_view_;
165
166   scoped_ptr<views::ViewModel> view_model_;
167
168   // Maps State onto |view_model_| indices.
169   std::map<AppListModel::State, int> state_to_view_;
170
171   // Maps |view_model_| indices onto State.
172   std::map<int, AppListModel::State> view_to_state_;
173
174   // The page that was showing before ShowSearchResults(true) was invoked.
175   int page_before_search_;
176
177   // Manages the pagination for the launcher pages.
178   PaginationModel pagination_model_;
179
180   DISALLOW_COPY_AND_ASSIGN(ContentsView);
181 };
182
183 }  // namespace app_list
184
185 #endif  // UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_