Chromium Code Reviews| 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 #include <utility> | |
| 9 | 10 |
| 10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/linked_ptr.h" | |
| 12 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 13 #include "ui/app_list/app_list_export.h" | 15 #include "ui/app_list/app_list_export.h" |
| 14 #include "ui/app_list/app_list_model.h" | 16 #include "ui/app_list/app_list_model.h" |
| 15 #include "ui/app_list/pagination_model.h" | 17 #include "ui/app_list/pagination_model.h" |
| 16 #include "ui/app_list/pagination_model_observer.h" | 18 #include "ui/app_list/pagination_model_observer.h" |
| 17 #include "ui/views/view.h" | 19 #include "ui/views/view.h" |
| 18 #include "ui/views/view_model.h" | 20 #include "ui/views/view_model.h" |
| 19 | 21 |
| 20 namespace gfx { | 22 namespace gfx { |
| 21 class Rect; | 23 class Rect; |
| 22 } | 24 } |
| 23 | 25 |
| 24 namespace app_list { | 26 namespace app_list { |
| 25 | 27 |
| 26 class AppsGridView; | 28 class AppsGridView; |
| 27 class ApplicationDragAndDropHost; | 29 class ApplicationDragAndDropHost; |
| 28 class AppListFolderItem; | 30 class AppListFolderItem; |
| 29 class AppListMainView; | 31 class AppListMainView; |
| 30 class AppListModel; | 32 class AppListModel; |
| 31 class AppListViewDelegate; | 33 class AppListViewDelegate; |
| 32 class AppsContainerView; | 34 class AppsContainerView; |
| 35 class ContentsAnimator; | |
| 33 class ContentsSwitcherView; | 36 class ContentsSwitcherView; |
| 34 class PaginationModel; | 37 class PaginationModel; |
| 35 class SearchResultListView; | 38 class SearchResultListView; |
| 36 class StartPageView; | 39 class StartPageView; |
| 37 | 40 |
| 38 // A view to manage launcher pages within the Launcher (eg. start page, apps | 41 // 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 | 42 // 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 | 43 // 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 | 44 // interface for switching between launcher pages, and animates the transition |
| 42 // between them. | 45 // between them. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 const PaginationModel& pagination_model() { return pagination_model_; } | 101 const PaginationModel& pagination_model() { return pagination_model_; } |
| 99 | 102 |
| 100 // Returns search box bounds to use for content views that do not specify | 103 // Returns search box bounds to use for content views that do not specify |
| 101 // their own custom layout. | 104 // their own custom layout. |
| 102 gfx::Rect GetDefaultSearchBoxBounds() const; | 105 gfx::Rect GetDefaultSearchBoxBounds() const; |
| 103 | 106 |
| 104 // Returns the content area bounds to use for content views that do not | 107 // Returns the content area bounds to use for content views that do not |
| 105 // specify their own custom layout. | 108 // specify their own custom layout. |
| 106 gfx::Rect GetDefaultContentsBounds() const; | 109 gfx::Rect GetDefaultContentsBounds() const; |
| 107 | 110 |
| 111 // Exposes GetAnimatorForTransition for tests. | |
| 112 ContentsAnimator* GetAnimatorForTransitionForTests(int from_page, | |
| 113 int to_page, | |
| 114 bool* reverse) const { | |
| 115 return GetAnimatorForTransition(from_page, to_page, reverse); | |
| 116 } | |
| 117 | |
| 108 // Overridden from views::View: | 118 // Overridden from views::View: |
| 109 gfx::Size GetPreferredSize() const override; | 119 gfx::Size GetPreferredSize() const override; |
| 110 void Layout() override; | 120 void Layout() override; |
| 111 bool OnKeyPressed(const ui::KeyEvent& event) override; | 121 bool OnKeyPressed(const ui::KeyEvent& event) override; |
| 112 | 122 |
| 113 // Overridden from PaginationModelObserver: | 123 // Overridden from PaginationModelObserver: |
| 114 void TotalPagesChanged() override; | 124 void TotalPagesChanged() override; |
| 115 void SelectedPageChanged(int old_selected, int new_selected) override; | 125 void SelectedPageChanged(int old_selected, int new_selected) override; |
| 116 void TransitionStarted() override; | 126 void TransitionStarted() override; |
| 117 void TransitionChanged() override; | 127 void TransitionChanged() override; |
| 118 | 128 |
| 119 private: | 129 private: |
| 120 // Sets the active launcher page, accounting for whether the change is for | 130 // Sets the active launcher page, accounting for whether the change is for |
| 121 // search results. | 131 // search results. |
| 122 void SetActivePageInternal(int page_index, bool show_search_results); | 132 void SetActivePageInternal(int page_index, bool show_search_results); |
| 123 | 133 |
| 124 // Invoked when active view is changed. | 134 // Invoked when active view is changed. |
| 125 void ActivePageChanged(bool show_search_results); | 135 void ActivePageChanged(bool show_search_results); |
| 126 | 136 |
| 127 // Returns the size of the default content area. | 137 // Returns the size of the default content area. |
| 128 gfx::Size GetDefaultContentsSize() const; | 138 gfx::Size GetDefaultContentsSize() const; |
| 129 | 139 |
| 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 | 140 // 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. | 141 // animation, this positions the views as appropriate for the current frame. |
| 136 void UpdatePageBounds(); | 142 void UpdatePageBounds(); |
| 137 | 143 |
| 138 // Adds |view| as a new page to the end of the list of launcher pages. The | 144 // 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 | 145 // 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 | 146 // |resource_id| is added to the ContentsSwitcherView. There is no name |
| 141 // associated with the page. Returns the index of the new page. | 147 // associated with the page. Returns the index of the new page. |
| 142 int AddLauncherPage(views::View* view, int resource_id); | 148 int AddLauncherPage(views::View* view, int resource_id); |
| 143 | 149 |
| 144 // Adds |view| as a new page to the end of the list of launcher pages. The | 150 // 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 | 151 // 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 | 152 // |resource_id| is added to the ContentsSwitcherView. The page is associated |
| 147 // with the name |state|. Returns the index of the new page. | 153 // with the name |state|. Returns the index of the new page. |
| 148 int AddLauncherPage(views::View* view, | 154 int AddLauncherPage(views::View* view, |
| 149 int resource_id, | 155 int resource_id, |
| 150 AppListModel::State state); | 156 AppListModel::State state); |
| 151 | 157 |
| 152 // Gets the PaginationModel owned by the AppsGridView. | 158 // Gets the PaginationModel owned by the AppsGridView. |
| 153 // Note: This is different to |pagination_model_|, which manages top-level | 159 // Note: This is different to |pagination_model_|, which manages top-level |
| 154 // launcher-page pagination. | 160 // launcher-page pagination. |
| 155 PaginationModel* GetAppsPaginationModel(); | 161 PaginationModel* GetAppsPaginationModel(); |
| 156 | 162 |
| 163 // Adds a ContentsAnimator for a transition from |from_page| to |to_page|. | |
| 164 // Takes ownership of |animator|. | |
| 165 void AddAnimator(int from_page, int to_page, ContentsAnimator* animator); | |
|
calamity
2014/11/05 06:29:07
If this takes ownership, shouldn't it take a scope
Matt Giuca
2014/11/06 00:32:59
s/scoped_ptr/linked_ptr/ yeah... probably should.
calamity
2014/11/06 05:34:47
I think it would still be scoped_ptr and then made
Matt Giuca
2014/11/10 04:08:26
Sort of depends on https://codereview.chromium.org
| |
| 166 | |
| 167 // Gets a ContentsAnimator for a transition from |from_page| to |to_page|. If | |
| 168 // the animator is should be run in reverse (because it is a |to_page| to | |
|
calamity
2014/11/05 06:29:07
s/is//
Matt Giuca
2014/11/06 00:32:59
Done.
| |
| 169 // |from_page| animator), |reverse| is set to true; otherwise it is set to | |
| 170 // false. | |
| 171 ContentsAnimator* GetAnimatorForTransition(int from_page, | |
| 172 int to_page, | |
| 173 bool* reverse) const; | |
| 174 | |
| 157 // Special sub views of the ContentsView. All owned by the views hierarchy. | 175 // Special sub views of the ContentsView. All owned by the views hierarchy. |
| 158 AppsContainerView* apps_container_view_; | 176 AppsContainerView* apps_container_view_; |
| 159 SearchResultListView* search_results_view_; | 177 SearchResultListView* search_results_view_; |
| 160 StartPageView* start_page_view_; | 178 StartPageView* start_page_view_; |
| 161 | 179 |
| 162 AppListMainView* app_list_main_view_; // Parent view, owns this. | 180 AppListMainView* app_list_main_view_; // Parent view, owns this. |
| 163 // Sibling view, owned by |app_list_main_view_|. | 181 // Sibling view, owned by |app_list_main_view_|. |
| 164 ContentsSwitcherView* contents_switcher_view_; | 182 ContentsSwitcherView* contents_switcher_view_; |
| 165 | 183 |
| 166 scoped_ptr<views::ViewModel> view_model_; | 184 scoped_ptr<views::ViewModel> view_model_; |
| 167 | 185 |
| 168 // Maps State onto |view_model_| indices. | 186 // Maps State onto |view_model_| indices. |
| 169 std::map<AppListModel::State, int> state_to_view_; | 187 std::map<AppListModel::State, int> state_to_view_; |
| 170 | 188 |
| 171 // Maps |view_model_| indices onto State. | 189 // Maps |view_model_| indices onto State. |
| 172 std::map<int, AppListModel::State> view_to_state_; | 190 std::map<int, AppListModel::State> view_to_state_; |
| 173 | 191 |
| 174 // The page that was showing before ShowSearchResults(true) was invoked. | 192 // The page that was showing before ShowSearchResults(true) was invoked. |
| 175 int page_before_search_; | 193 int page_before_search_; |
| 176 | 194 |
| 177 // Manages the pagination for the launcher pages. | 195 // Manages the pagination for the launcher pages. |
| 178 PaginationModel pagination_model_; | 196 PaginationModel pagination_model_; |
| 179 | 197 |
| 198 // Maps from {A, B} pair to ContentsAnimator, where A and B are page | |
| 199 // |view_model_| indices for an animation from A to B. | |
| 200 std::map<std::pair<int, int>, linked_ptr<ContentsAnimator>> | |
| 201 contents_animators_; | |
| 202 | |
| 203 // The animator for a transition not found in |contents_animators_|. | |
|
calamity
2014/11/05 06:29:07
s/for a transition/for transitions/
Matt Giuca
2014/11/06 00:32:59
Done.
| |
| 204 scoped_ptr<ContentsAnimator> default_animator_; | |
| 205 | |
| 180 DISALLOW_COPY_AND_ASSIGN(ContentsView); | 206 DISALLOW_COPY_AND_ASSIGN(ContentsView); |
| 181 }; | 207 }; |
| 182 | 208 |
| 183 } // namespace app_list | 209 } // namespace app_list |
| 184 | 210 |
| 185 #endif // UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_ | 211 #endif // UI_APP_LIST_VIEWS_CONTENTS_VIEW_H_ |
| OLD | NEW |