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 #include "ui/app_list/views/contents_view.h" | 5 #include "ui/app_list/views/contents_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/app_list/app_list_constants.h" | 10 #include "ui/app_list/app_list_constants.h" |
| 11 #include "ui/app_list/app_list_view_delegate.h" | 11 #include "ui/app_list/app_list_view_delegate.h" |
| 12 #include "ui/app_list/pagination_model.h" | 12 #include "ui/app_list/pagination_model.h" |
| 13 #include "ui/app_list/views/app_list_folder_view.h" | |
| 13 #include "ui/app_list/views/app_list_main_view.h" | 14 #include "ui/app_list/views/app_list_main_view.h" |
| 14 #include "ui/app_list/views/apps_grid_view.h" | 15 #include "ui/app_list/views/apps_grid_view.h" |
| 15 #include "ui/app_list/views/search_result_list_view.h" | 16 #include "ui/app_list/views/search_result_list_view.h" |
| 16 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
| 17 #include "ui/views/animation/bounds_animator.h" | 18 #include "ui/views/animation/bounds_animator.h" |
| 18 #include "ui/views/view_model.h" | 19 #include "ui/views/view_model.h" |
| 19 #include "ui/views/view_model_utils.h" | 20 #include "ui/views/view_model_utils.h" |
| 20 | 21 |
| 21 namespace app_list { | 22 namespace app_list { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 const int kPreferredIconDimension = 48; | |
| 26 | |
| 27 // Indexes of interesting views in ViewModel of ContentsView. | 26 // Indexes of interesting views in ViewModel of ContentsView. |
| 28 const int kIndexAppsGrid = 0; | 27 const int kIndexAppsGrid = 0; |
| 29 const int kIndexSearchResults = 1; | 28 const int kIndexSearchResults = 1; |
| 29 const int kIndexFolderContent = 2; | |
| 30 | 30 |
| 31 const int kMinMouseWheelToSwitchPage = 20; | 31 const int kMinMouseWheelToSwitchPage = 20; |
| 32 const int kMinScrollToSwitchPage = 20; | 32 const int kMinScrollToSwitchPage = 20; |
| 33 const int kMinHorizVelocityToSwitchPage = 800; | 33 const int kMinHorizVelocityToSwitchPage = 800; |
| 34 | 34 |
| 35 const double kFinishTransitionThreshold = 0.33; | 35 const double kFinishTransitionThreshold = 0.33; |
| 36 | 36 |
| 37 // Helpers to get certain child view from |model|. | 37 // Helpers to get certain child view from |model|. |
| 38 AppsGridView* GetAppsGridView(views::ViewModel* model) { | 38 AppsGridView* GetAppsGridView(views::ViewModel* model) { |
| 39 return static_cast<AppsGridView*>(model->view_at(kIndexAppsGrid)); | 39 return static_cast<AppsGridView*>(model->view_at(kIndexAppsGrid)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 SearchResultListView* GetSearchResultListView(views::ViewModel* model) { | 42 SearchResultListView* GetSearchResultListView(views::ViewModel* model) { |
| 43 return static_cast<SearchResultListView*>( | 43 return static_cast<SearchResultListView*>( |
| 44 model->view_at(kIndexSearchResults)); | 44 model->view_at(kIndexSearchResults)); |
| 45 } | 45 } |
| 46 | 46 |
| 47 AppListFolderView* GetAppListFolderView(views::ViewModel* model) { | |
| 48 return static_cast<AppListFolderView*>(model->view_at(kIndexFolderContent)); | |
| 49 } | |
| 50 | |
| 47 } // namespace | 51 } // namespace |
| 48 | 52 |
| 49 ContentsView::ContentsView(AppListMainView* app_list_main_view, | 53 ContentsView::ContentsView(AppListMainView* app_list_main_view, |
| 50 PaginationModel* pagination_model, | 54 PaginationModel* pagination_model, |
| 51 AppListModel* model, | 55 AppListModel* model, |
| 52 content::WebContents* start_page_contents) | 56 content::WebContents* start_page_contents) |
| 53 : show_state_(SHOW_APPS), | 57 : show_state_(SHOW_APPS), |
| 58 previous_show_state_(show_state_), | |
| 54 pagination_model_(pagination_model), | 59 pagination_model_(pagination_model), |
| 55 view_model_(new views::ViewModel), | 60 view_model_(new views::ViewModel), |
| 56 bounds_animator_(new views::BoundsAnimator(this)) { | 61 bounds_animator_(new views::BoundsAnimator(this)) { |
| 57 DCHECK(model); | 62 DCHECK(model); |
| 58 pagination_model_->SetTransitionDurations( | 63 pagination_model_->SetTransitionDurations( |
| 59 kPageTransitionDurationInMs, | 64 kPageTransitionDurationInMs, |
| 60 kOverscrollPageTransitionDurationMs); | 65 kOverscrollPageTransitionDurationMs); |
| 61 | 66 |
| 62 apps_grid_view_ = new AppsGridView( | 67 apps_grid_view_ = new AppsGridView( |
| 63 app_list_main_view, pagination_model, start_page_contents); | 68 app_list_main_view, pagination_model, start_page_contents); |
| 64 apps_grid_view_->SetLayout(kPreferredIconDimension, | 69 apps_grid_view_->SetLayout(kPreferredIconDimension, |
| 65 kPreferredCols, | 70 kPreferredCols, |
| 66 kPreferredRows); | 71 kPreferredRows); |
| 67 AddChildView(apps_grid_view_); | 72 AddChildView(apps_grid_view_); |
| 68 view_model_->Add(apps_grid_view_, kIndexAppsGrid); | 73 view_model_->Add(apps_grid_view_, kIndexAppsGrid); |
| 69 | 74 |
| 70 SearchResultListView* search_results_view = new SearchResultListView( | 75 SearchResultListView* search_results_view = new SearchResultListView( |
| 71 app_list_main_view); | 76 app_list_main_view); |
| 72 AddChildView(search_results_view); | 77 AddChildView(search_results_view); |
| 73 view_model_->Add(search_results_view, kIndexSearchResults); | 78 view_model_->Add(search_results_view, kIndexSearchResults); |
| 74 | 79 |
| 75 GetAppsGridView(view_model_.get())->SetModel(model); | 80 GetAppsGridView(view_model_.get())->SetModel(model); |
| 81 if (model) | |
| 82 GetAppsGridView(view_model_.get())->SetApps(model->apps()); | |
| 76 GetSearchResultListView(view_model_.get())->SetResults(model->results()); | 83 GetSearchResultListView(view_model_.get())->SetResults(model->results()); |
| 84 | |
| 85 AppListFolderView* folder_view = new AppListFolderView( | |
| 86 this, | |
| 87 model, | |
| 88 app_list_main_view, | |
| 89 pagination_model, | |
| 90 start_page_contents); | |
| 91 AddChildView(folder_view); | |
| 92 view_model_->Add(folder_view, kIndexFolderContent); | |
|
xiyuan
2013/10/17 23:50:30
Suggest to put folder view and root grid view into
jennyz
2013/10/18 22:09:02
Added a new AppsContainerView to achieve the above
| |
| 77 } | 93 } |
| 78 | 94 |
| 79 ContentsView::~ContentsView() { | 95 ContentsView::~ContentsView() { |
| 80 } | 96 } |
| 81 | 97 |
| 82 void ContentsView::CancelDrag() { | 98 void ContentsView::CancelDrag() { |
| 83 if (apps_grid_view_ && apps_grid_view_->has_dragged_view()) | 99 if (apps_grid_view_ && apps_grid_view_->has_dragged_view()) |
| 84 apps_grid_view_->EndDrag(true); | 100 apps_grid_view_->EndDrag(true); |
| 85 } | 101 } |
| 86 | 102 |
| 87 void ContentsView::SetDragAndDropHostOfCurrentAppList( | 103 void ContentsView::SetDragAndDropHostOfCurrentAppList( |
| 88 ApplicationDragAndDropHost* drag_and_drop_host) { | 104 ApplicationDragAndDropHost* drag_and_drop_host) { |
| 89 apps_grid_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | 105 apps_grid_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); |
| 90 } | 106 } |
| 91 | 107 |
| 92 void ContentsView::SetShowState(ShowState show_state) { | 108 void ContentsView::SetShowState(ShowState show_state) { |
| 93 if (show_state_ == show_state) | 109 if (show_state_ == show_state) |
| 94 return; | 110 return; |
| 95 | 111 |
| 112 previous_show_state_ = show_state_; | |
| 96 show_state_ = show_state; | 113 show_state_ = show_state; |
| 97 ShowStateChanged(); | 114 ShowStateChanged(); |
| 98 } | 115 } |
| 99 | 116 |
| 100 void ContentsView::ShowStateChanged() { | 117 void ContentsView::ShowStateChanged() { |
| 101 if (show_state_ == SHOW_SEARCH_RESULTS) { | 118 if (show_state_ == SHOW_SEARCH_RESULTS) { |
| 102 // TODO(xiyuan): Highlight default match instead of the first. | 119 // TODO(xiyuan): Highlight default match instead of the first. |
| 103 SearchResultListView* results_view = | 120 SearchResultListView* results_view = |
| 104 GetSearchResultListView(view_model_.get()); | 121 GetSearchResultListView(view_model_.get()); |
| 105 if (results_view->visible()) | 122 if (results_view->visible()) |
| 106 results_view->SetSelectedIndex(0); | 123 results_view->SetSelectedIndex(0); |
| 107 } | 124 } |
| 108 | 125 |
| 109 AnimateToIdealBounds(); | 126 AnimateToIdealBounds(); |
| 110 } | 127 } |
| 111 | 128 |
| 112 void ContentsView::CalculateIdealBounds() { | 129 void ContentsView::CalculateIdealBounds() { |
| 113 gfx::Rect rect(GetContentsBounds()); | 130 gfx::Rect rect(GetContentsBounds()); |
| 114 if (rect.IsEmpty()) | 131 if (rect.IsEmpty()) |
| 115 return; | 132 return; |
| 116 | 133 |
| 117 gfx::Rect grid_frame(rect); | 134 gfx::Rect grid_frame(rect); |
| 118 gfx::Rect results_frame(rect); | 135 gfx::Rect results_frame(rect); |
| 136 gfx::Rect folder_frame(rect); | |
| 119 | 137 |
| 120 // Offsets apps grid and result list based on |show_state_|. | 138 // Offsets apps grid and result list based on |show_state_|. |
| 121 // SearchResultListView is on top of apps grid. Visible view is left in | 139 // SearchResultListView is on top of apps grid. Visible view is left in |
| 122 // visible area and invisible ones is put out of the visible area. | 140 // visible area and invisible ones is put out of the visible area. |
| 123 int contents_area_height = rect.height(); | 141 int contents_area_height = rect.height(); |
| 124 switch (show_state_) { | 142 switch (show_state_) { |
| 125 case SHOW_APPS: | 143 case SHOW_APPS: |
| 126 results_frame.Offset(0, -contents_area_height); | 144 results_frame.Offset(0, -contents_area_height); |
| 145 folder_frame.Offset(0, -contents_area_height); | |
| 127 break; | 146 break; |
| 128 case SHOW_SEARCH_RESULTS: | 147 case SHOW_SEARCH_RESULTS: |
| 129 grid_frame.Offset(0, contents_area_height); | 148 grid_frame.Offset(0, contents_area_height); |
| 149 folder_frame.Offset(0, -contents_area_height); | |
| 150 break; | |
| 151 case SHOW_FOLDER_CONTENT: | |
| 152 results_frame.Offset(0, -contents_area_height); | |
| 153 grid_frame.Offset(0, contents_area_height); | |
| 130 break; | 154 break; |
| 131 default: | 155 default: |
| 132 NOTREACHED() << "Unknown show_state_ " << show_state_; | 156 NOTREACHED() << "Unknown show_state_ " << show_state_; |
| 133 break; | 157 break; |
| 134 } | 158 } |
| 135 | 159 |
| 136 view_model_->set_ideal_bounds(kIndexAppsGrid, grid_frame); | 160 view_model_->set_ideal_bounds(kIndexAppsGrid, grid_frame); |
| 137 view_model_->set_ideal_bounds(kIndexSearchResults, results_frame); | 161 view_model_->set_ideal_bounds(kIndexSearchResults, results_frame); |
| 162 view_model_->set_ideal_bounds(kIndexFolderContent, folder_frame); | |
| 138 } | 163 } |
| 139 | 164 |
| 140 void ContentsView::AnimateToIdealBounds() { | 165 void ContentsView::AnimateToIdealBounds() { |
| 141 CalculateIdealBounds(); | 166 CalculateIdealBounds(); |
| 142 for (int i = 0; i < view_model_->view_size(); ++i) { | 167 for (int i = 0; i < view_model_->view_size(); ++i) { |
| 143 bounds_animator_->AnimateViewTo(view_model_->view_at(i), | 168 bounds_animator_->AnimateViewTo(view_model_->view_at(i), |
| 144 view_model_->ideal_bounds(i)); | 169 view_model_->ideal_bounds(i)); |
| 145 } | 170 } |
| 146 } | 171 } |
| 147 | 172 |
| 148 void ContentsView::ShowSearchResults(bool show) { | 173 void ContentsView::ShowSearchResults(bool show) { |
| 149 SetShowState(show ? SHOW_SEARCH_RESULTS : SHOW_APPS); | 174 SetShowState(show ? SHOW_SEARCH_RESULTS : previous_show_state_); |
| 175 } | |
| 176 | |
| 177 void ContentsView::ShowFolderContent(AppListFolderItem* item) { | |
| 178 GetAppListFolderView(view_model_.get())->SetAppListFolderItem(item); | |
| 179 SetShowState(SHOW_FOLDER_CONTENT); | |
| 180 } | |
| 181 | |
| 182 void ContentsView::ShowApps() { | |
| 183 SetShowState(SHOW_APPS); | |
| 150 } | 184 } |
| 151 | 185 |
| 152 void ContentsView::Prerender() { | 186 void ContentsView::Prerender() { |
| 153 const int selected_page = std::max(0, pagination_model_->selected_page()); | 187 const int selected_page = std::max(0, pagination_model_->selected_page()); |
| 154 GetAppsGridView(view_model_.get())->Prerender(selected_page); | 188 GetAppsGridView(view_model_.get())->Prerender(selected_page); |
| 155 } | 189 } |
| 156 | 190 |
| 157 gfx::Size ContentsView::GetPreferredSize() { | 191 gfx::Size ContentsView::GetPreferredSize() { |
| 158 const gfx::Size grid_size = | 192 const gfx::Size grid_size = |
| 159 GetAppsGridView(view_model_.get())->GetPreferredSize(); | 193 GetAppsGridView(view_model_.get())->GetPreferredSize(); |
| 160 const gfx::Size results_size = | 194 const gfx::Size results_size = |
| 161 GetSearchResultListView(view_model_.get())->GetPreferredSize(); | 195 GetSearchResultListView(view_model_.get())->GetPreferredSize(); |
| 162 | 196 |
| 163 int width = std::max(grid_size.width(), results_size.width()); | 197 int width = std::max(grid_size.width(), results_size.width()); |
| 164 int height = std::max(grid_size.height(), results_size.height()); | 198 int height = std::max(grid_size.height(), results_size.height()); |
| 165 return gfx::Size(width, height); | 199 return gfx::Size(width, height); |
| 166 } | 200 } |
| 167 | 201 |
| 168 void ContentsView::Layout() { | 202 void ContentsView::Layout() { |
| 169 CalculateIdealBounds(); | 203 CalculateIdealBounds(); |
| 170 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); | 204 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); |
| 171 } | 205 } |
| 172 | 206 |
| 173 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { | 207 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { |
| 174 switch (show_state_) { | 208 switch (show_state_) { |
| 175 case SHOW_APPS: | 209 case SHOW_APPS: |
| 176 return GetAppsGridView(view_model_.get())->OnKeyPressed(event); | 210 return GetAppsGridView(view_model_.get())->OnKeyPressed(event); |
| 177 case SHOW_SEARCH_RESULTS: | 211 case SHOW_SEARCH_RESULTS: |
| 178 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event); | 212 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event); |
| 213 case SHOW_FOLDER_CONTENT: | |
| 214 return GetAppListFolderView(view_model_.get())->OnKeyPressed(event); | |
| 179 default: | 215 default: |
| 180 NOTREACHED() << "Unknown show state " << show_state_; | 216 NOTREACHED() << "Unknown show state " << show_state_; |
| 181 } | 217 } |
| 182 return false; | 218 return false; |
| 183 } | 219 } |
| 184 | 220 |
| 185 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 221 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
| 186 if (show_state_ != SHOW_APPS) | 222 if (show_state_ != SHOW_APPS) |
| 187 return false; | 223 return false; |
| 188 | 224 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 if (!pagination_model_->has_transition()) { | 291 if (!pagination_model_->has_transition()) { |
| 256 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1, | 292 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1, |
| 257 true); | 293 true); |
| 258 } | 294 } |
| 259 event->SetHandled(); | 295 event->SetHandled(); |
| 260 event->StopPropagation(); | 296 event->StopPropagation(); |
| 261 } | 297 } |
| 262 } | 298 } |
| 263 | 299 |
| 264 } // namespace app_list | 300 } // namespace app_list |
| OLD | NEW |