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 content { | 18 namespace content { |
17 class WebContents; | 19 class WebContents; |
18 } | 20 } |
19 | 21 |
20 namespace views { | 22 namespace views { |
21 class BoundsAnimator; | |
22 class ViewModel; | 23 class ViewModel; |
23 } | 24 } |
24 | 25 |
25 namespace app_list { | 26 namespace app_list { |
26 | 27 |
27 class AppsGridView; | 28 class AppsGridView; |
28 class ApplicationDragAndDropHost; | 29 class ApplicationDragAndDropHost; |
29 class AppListFolderItem; | 30 class AppListFolderItem; |
30 class AppListMainView; | 31 class AppListMainView; |
31 class AppListModel; | 32 class AppListModel; |
32 class AppListViewDelegate; | 33 class AppListViewDelegate; |
33 class AppsContainerView; | 34 class AppsContainerView; |
34 class PaginationModel; | 35 class PaginationModel; |
35 class SearchResultListView; | 36 class SearchResultListView; |
36 class StartPageView; | 37 class StartPageView; |
37 | 38 |
38 // A view to manage launcher pages within the Launcher (eg. start page, apps | 39 // 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 // 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 // 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 // interface for switching between launcher pages, and animates the transition |
42 // between them. | 43 // between them. |
43 class APP_LIST_EXPORT ContentsView : public views::View { | 44 class APP_LIST_EXPORT ContentsView : public views::View, |
45 public PaginationModelObserver { | |
44 public: | 46 public: |
45 // Values of this enum denote special launcher pages that require hard-coding. | 47 // Values of this enum denote special launcher pages that require hard-coding. |
46 // Launcher pages are not required to have a NamedPage enum value. | 48 // Launcher pages are not required to have a NamedPage enum value. |
47 enum NamedPage { | 49 enum NamedPage { |
48 NAMED_PAGE_APPS, | 50 NAMED_PAGE_APPS, |
49 NAMED_PAGE_SEARCH_RESULTS, | 51 NAMED_PAGE_SEARCH_RESULTS, |
50 NAMED_PAGE_START, | 52 NAMED_PAGE_START, |
51 }; | 53 }; |
52 | 54 |
53 ContentsView(AppListMainView* app_list_main_view, | 55 ContentsView(AppListMainView* app_list_main_view, |
54 AppListModel* model, | 56 AppListModel* model, |
55 AppListViewDelegate* view_delegate); | 57 AppListViewDelegate* view_delegate); |
56 virtual ~ContentsView(); | 58 virtual ~ContentsView(); |
57 | 59 |
58 // The app list gets closed and drag and drop operations need to be cancelled. | 60 // The app list gets closed and drag and drop operations need to be cancelled. |
59 void CancelDrag(); | 61 void CancelDrag(); |
60 | 62 |
61 // If |drag_and_drop| is not NULL it will be called upon drag and drop | 63 // If |drag_and_drop| is not NULL it will be called upon drag and drop |
62 // operations outside the application list. | 64 // operations outside the application list. |
63 void SetDragAndDropHostOfCurrentAppList( | 65 void SetDragAndDropHostOfCurrentAppList( |
64 ApplicationDragAndDropHost* drag_and_drop_host); | 66 ApplicationDragAndDropHost* drag_and_drop_host); |
65 | 67 |
66 void ShowSearchResults(bool show); | 68 void ShowSearchResults(bool show); |
67 void ShowFolderContent(AppListFolderItem* folder); | 69 void ShowFolderContent(AppListFolderItem* folder); |
68 | 70 |
69 // Sets the active launcher page and animates the pages into place. | 71 // Sets the active launcher page and animates the pages into place. |
70 void SetActivePage(int page_index); | 72 void SetActivePage(int page_index); |
71 | 73 |
72 // The index of the currently active launcher page. | 74 // The index of the currently active launcher page. |
73 int active_page_index() const { return active_page_; } | 75 int GetActivePageIndex() const; |
74 | 76 |
75 // True if |named_page| is the current active laucher page. | 77 // True if |named_page| is the current active laucher page. |
76 bool IsNamedPageActive(NamedPage named_page) const; | 78 bool IsNamedPageActive(NamedPage named_page) const; |
77 | 79 |
78 // Gets the index of a launcher page in |view_model_|, by NamedPage. | 80 // Gets the index of a launcher page in |view_model_|, by NamedPage. |
79 int GetPageIndexForNamedPage(NamedPage named_page) const; | 81 int GetPageIndexForNamedPage(NamedPage named_page) const; |
80 | 82 |
81 void Prerender(); | 83 void Prerender(); |
82 | 84 |
83 AppsContainerView* apps_container_view() { return apps_container_view_; } | 85 AppsContainerView* apps_container_view() { return apps_container_view_; } |
84 StartPageView* start_page_view() { return start_page_view_; } | 86 StartPageView* start_page_view() { return start_page_view_; } |
85 | 87 |
88 // Ends the current animation abruptly (for use in tests). | |
89 void FinishCurrentAnimationForTests(); | |
90 | |
86 // Overridden from views::View: | 91 // Overridden from views::View: |
87 virtual gfx::Size GetPreferredSize() const OVERRIDE; | 92 virtual gfx::Size GetPreferredSize() const OVERRIDE; |
88 virtual void Layout() OVERRIDE; | 93 virtual void Layout() OVERRIDE; |
89 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; | 94 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; |
90 virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE; | 95 virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE; |
91 | 96 |
97 // Overridden from PaginationModelObserver: | |
98 virtual void TotalPagesChanged() OVERRIDE; | |
99 virtual void SelectedPageChanged(int old_selected, int new_selected) OVERRIDE; | |
100 virtual void TransitionStarted() OVERRIDE; | |
101 virtual void TransitionChanged() OVERRIDE; | |
102 | |
92 private: | 103 private: |
93 // Invoked when active view is changed. | 104 // Invoked when active view is changed. |
94 void ActivePageChanged(); | 105 void ActivePageChanged(); |
95 | 106 |
96 void CalculateIdealBounds(); | 107 // Calculates and sets the bounds for the subviews. If |ideal| is true, this |
97 void AnimateToIdealBounds(); | 108 // calculates the ideal bounds (for after the current animation completes), |
109 // which will be used when Layout() is called; otherwise, calculates the | |
110 // actual bounds (potentially mid-animation) and directly moves the views. | |
111 void CalculateAndSetBounds(bool ideal); | |
calamity
2014/06/12 03:05:08
Doesn't the ideal=true case go against the method
Matt Giuca
2014/06/16 00:59:05
The implication was that "SetBounds" was non-speci
Matt Giuca
2014/06/16 07:20:28
OK as discussed, no more ideal bounds. This method
| |
98 | 112 |
99 // Adds |view| as a new page to the end of the list of launcher pages. The | 113 // Adds |view| as a new page to the end of the list of launcher pages. The |
100 // view is inserted as a child of the ContentsView. There is no name | 114 // view is inserted as a child of the ContentsView. There is no name |
101 // associated with the page. Returns the index of the new page. | 115 // associated with the page. Returns the index of the new page. |
102 int AddLauncherPage(views::View* view); | 116 int AddLauncherPage(views::View* view); |
103 | 117 |
104 // Adds |view| as a new page to the end of the list of launcher pages. The | 118 // Adds |view| as a new page to the end of the list of launcher pages. The |
105 // view is inserted as a child of the ContentsView. The page is associated | 119 // view is inserted as a child of the ContentsView. The page is associated |
106 // with the name |named_page|. Returns the index of the new page. | 120 // with the name |named_page|. Returns the index of the new page. |
107 int AddLauncherPage(views::View* view, NamedPage named_page); | 121 int AddLauncherPage(views::View* view, NamedPage named_page); |
108 | 122 |
109 // Gets the PaginationModel owned by the AppsGridView. | 123 // Gets the PaginationModel owned by the AppsGridView. |
124 // Note: This is different to |pagination_model_|, which manages top-level | |
125 // launcher-page pagination. | |
110 PaginationModel* GetAppsPaginationModel(); | 126 PaginationModel* GetAppsPaginationModel(); |
111 | 127 |
112 // Overridden from ui::EventHandler: | 128 // Overridden from ui::EventHandler: |
113 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 129 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
114 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; | 130 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; |
115 | 131 |
116 // Index into |view_model_| of the currently active page. | |
117 int active_page_; | |
118 | |
119 // Special sub views of the ContentsView. All owned by the views hierarchy. | 132 // Special sub views of the ContentsView. All owned by the views hierarchy. |
120 AppsContainerView* apps_container_view_; | 133 AppsContainerView* apps_container_view_; |
121 SearchResultListView* search_results_view_; | 134 SearchResultListView* search_results_view_; |
122 StartPageView* start_page_view_; | 135 StartPageView* start_page_view_; |
123 | 136 |
124 AppListMainView* app_list_main_view_; // Parent view, owns this. | 137 AppListMainView* app_list_main_view_; // Parent view, owns this. |
125 | 138 |
126 scoped_ptr<views::ViewModel> view_model_; | 139 scoped_ptr<views::ViewModel> view_model_; |
127 // Maps NamedPage onto |view_model_| indices. | 140 // Maps NamedPage onto |view_model_| indices. |
128 std::map<NamedPage, int> named_page_to_view_; | 141 std::map<NamedPage, int> named_page_to_view_; |
129 scoped_ptr<views::BoundsAnimator> bounds_animator_; | 142 |
143 // Manages the pagination for the launcher pages. | |
144 PaginationModel pagination_model_; | |
130 | 145 |
131 DISALLOW_COPY_AND_ASSIGN(ContentsView); | 146 DISALLOW_COPY_AND_ASSIGN(ContentsView); |
132 }; | 147 }; |
133 | 148 |
134 } // namespace app_list | 149 } // namespace app_list |
135 | 150 |
136 #endif // UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_ | 151 #endif // UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_ |
OLD | NEW |