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 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "ui/app_list/app_list_constants.h" | 11 #include "ui/app_list/app_list_constants.h" |
| 12 #include "ui/app_list/app_list_switches.h" | 12 #include "ui/app_list/app_list_switches.h" |
| 13 #include "ui/app_list/app_list_view_delegate.h" | 13 #include "ui/app_list/app_list_view_delegate.h" |
| 14 #include "ui/app_list/views/app_list_folder_view.h" | 14 #include "ui/app_list/views/app_list_folder_view.h" |
| 15 #include "ui/app_list/views/app_list_main_view.h" | 15 #include "ui/app_list/views/app_list_main_view.h" |
| 16 #include "ui/app_list/views/apps_container_view.h" | 16 #include "ui/app_list/views/apps_container_view.h" |
| 17 #include "ui/app_list/views/apps_grid_view.h" | 17 #include "ui/app_list/views/apps_grid_view.h" |
| 18 #include "ui/app_list/views/contents_switcher_view.h" | 18 #include "ui/app_list/views/contents_switcher_view.h" |
| 19 #include "ui/app_list/views/search_box_view.h" | |
| 19 #include "ui/app_list/views/search_result_list_view.h" | 20 #include "ui/app_list/views/search_result_list_view.h" |
| 20 #include "ui/app_list/views/start_page_view.h" | 21 #include "ui/app_list/views/start_page_view.h" |
| 21 #include "ui/events/event.h" | 22 #include "ui/events/event.h" |
| 22 #include "ui/gfx/animation/tween.h" | 23 #include "ui/gfx/animation/tween.h" |
| 23 #include "ui/resources/grit/ui_resources.h" | 24 #include "ui/resources/grit/ui_resources.h" |
| 24 #include "ui/views/view_model.h" | 25 #include "ui/views/view_model.h" |
| 25 #include "ui/views/view_model_utils.h" | 26 #include "ui/views/view_model_utils.h" |
| 26 | 27 |
| 27 namespace app_list { | 28 namespace app_list { |
| 28 | 29 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 AddLauncherPage( | 74 AddLauncherPage( |
| 74 apps_container_view_, IDR_APP_LIST_APPS_ICON, NAMED_PAGE_APPS); | 75 apps_container_view_, IDR_APP_LIST_APPS_ICON, NAMED_PAGE_APPS); |
| 75 | 76 |
| 76 int initial_page_index = app_list::switches::IsExperimentalAppListEnabled() | 77 int initial_page_index = app_list::switches::IsExperimentalAppListEnabled() |
| 77 ? GetPageIndexForNamedPage(NAMED_PAGE_START) | 78 ? GetPageIndexForNamedPage(NAMED_PAGE_START) |
| 78 : GetPageIndexForNamedPage(NAMED_PAGE_APPS); | 79 : GetPageIndexForNamedPage(NAMED_PAGE_APPS); |
| 79 DCHECK_GE(initial_page_index, 0); | 80 DCHECK_GE(initial_page_index, 0); |
| 80 | 81 |
| 81 page_before_search_ = initial_page_index; | 82 page_before_search_ = initial_page_index; |
| 82 pagination_model_.SelectPage(initial_page_index, false); | 83 pagination_model_.SelectPage(initial_page_index, false); |
| 83 | |
| 84 // Needed to update the main search box visibility. | |
| 85 ActivePageChanged(false); | |
| 86 } | 84 } |
| 87 | 85 |
| 88 void ContentsView::CancelDrag() { | 86 void ContentsView::CancelDrag() { |
| 89 if (apps_container_view_->apps_grid_view()->has_dragged_view()) | 87 if (apps_container_view_->apps_grid_view()->has_dragged_view()) |
| 90 apps_container_view_->apps_grid_view()->EndDrag(true); | 88 apps_container_view_->apps_grid_view()->EndDrag(true); |
| 91 if (apps_container_view_->app_list_folder_view() | 89 if (apps_container_view_->app_list_folder_view() |
| 92 ->items_grid_view() | 90 ->items_grid_view() |
| 93 ->has_dragged_view()) { | 91 ->has_dragged_view()) { |
| 94 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( | 92 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( |
| 95 true); | 93 true); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 const PaginationModel::Transition& transition = | 207 const PaginationModel::Transition& transition = |
| 210 pagination_model_.transition(); | 208 pagination_model_.transition(); |
| 211 if (pagination_model_.is_valid_page(transition.target_page)) { | 209 if (pagination_model_.is_valid_page(transition.target_page)) { |
| 212 target_page = transition.target_page; | 210 target_page = transition.target_page; |
| 213 progress = transition.progress; | 211 progress = transition.progress; |
| 214 } | 212 } |
| 215 } | 213 } |
| 216 | 214 |
| 217 // Move |current_page| from 0 to its origin. Move |target_page| from its | 215 // Move |current_page| from 0 to its origin. Move |target_page| from its |
| 218 // origin to 0. | 216 // origin to 0. |
| 219 gfx::Rect on_screen(GetContentsBounds()); | 217 gfx::Rect on_screen(GetDefaultContentsBounds()); |
|
Matt Giuca
2014/10/24 03:21:40
like it.
calamity
2014/10/24 06:13:08
Acknowledged.
| |
| 220 gfx::Rect current_page_origin(GetOffscreenPageBounds(current_page)); | 218 gfx::Rect current_page_origin(GetOffscreenPageBounds(current_page)); |
| 221 gfx::Rect target_page_origin(GetOffscreenPageBounds(target_page)); | 219 gfx::Rect target_page_origin(GetOffscreenPageBounds(target_page)); |
| 222 gfx::Rect current_page_rect( | 220 gfx::Rect current_page_rect( |
| 223 gfx::Tween::RectValueBetween(progress, on_screen, current_page_origin)); | 221 gfx::Tween::RectValueBetween(progress, on_screen, current_page_origin)); |
| 224 gfx::Rect target_page_rect( | 222 gfx::Rect target_page_rect( |
| 225 gfx::Tween::RectValueBetween(progress, target_page_origin, on_screen)); | 223 gfx::Tween::RectValueBetween(progress, target_page_origin, on_screen)); |
| 226 | 224 |
| 227 view_model_->view_at(current_page)->SetBoundsRect(current_page_rect); | 225 view_model_->view_at(current_page)->SetBoundsRect(current_page_rect); |
| 228 view_model_->view_at(target_page)->SetBoundsRect(target_page_rect); | 226 view_model_->view_at(target_page)->SetBoundsRect(target_page_rect); |
| 229 } | 227 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 259 } | 257 } |
| 260 | 258 |
| 261 int ContentsView::AddLauncherPage(views::View* view, | 259 int ContentsView::AddLauncherPage(views::View* view, |
| 262 int resource_id, | 260 int resource_id, |
| 263 NamedPage named_page) { | 261 NamedPage named_page) { |
| 264 int page_index = AddLauncherPage(view, resource_id); | 262 int page_index = AddLauncherPage(view, resource_id); |
| 265 named_page_to_view_.insert(std::pair<NamedPage, int>(named_page, page_index)); | 263 named_page_to_view_.insert(std::pair<NamedPage, int>(named_page, page_index)); |
| 266 return page_index; | 264 return page_index; |
| 267 } | 265 } |
| 268 | 266 |
| 269 gfx::Size ContentsView::GetPreferredSize() const { | 267 gfx::Rect ContentsView::GetDefaultSearchBoxBounds() const { |
| 268 gfx::Rect search_box_bounds( | |
| 269 0, | |
| 270 0, | |
| 271 GetDefaultContentsSize().width(), | |
| 272 app_list_main_view_->search_box_view()->GetPreferredSize().height()); | |
| 273 if (switches::IsExperimentalAppListEnabled()) { | |
| 274 search_box_bounds.set_y(kExperimentalWindowPadding); | |
| 275 search_box_bounds.Inset(kExperimentalWindowPadding, 0); | |
| 276 } | |
| 277 return search_box_bounds; | |
| 278 } | |
| 279 | |
| 280 gfx::Rect ContentsView::GetDefaultContentsBounds() const { | |
| 281 gfx::Rect bounds(gfx::Point(0, GetDefaultSearchBoxBounds().bottom()), | |
| 282 GetDefaultContentsSize()); | |
| 283 return bounds; | |
| 284 } | |
| 285 | |
| 286 gfx::Size ContentsView::GetDefaultContentsSize() const { | |
| 270 const gfx::Size container_size = | 287 const gfx::Size container_size = |
| 271 apps_container_view_->apps_grid_view()->GetPreferredSize(); | 288 apps_container_view_->apps_grid_view()->GetPreferredSize(); |
| 272 const gfx::Size results_size = search_results_view_ | 289 const gfx::Size results_size = search_results_view_ |
| 273 ? search_results_view_->GetPreferredSize() | 290 ? search_results_view_->GetPreferredSize() |
| 274 : gfx::Size(); | 291 : gfx::Size(); |
| 275 | 292 |
| 276 int width = std::max(container_size.width(), results_size.width()); | 293 int width = std::max(container_size.width(), results_size.width()); |
| 277 int height = std::max(container_size.height(), results_size.height()); | 294 int height = std::max(container_size.height(), results_size.height()); |
| 278 return gfx::Size(width, height); | 295 return gfx::Size(width, height); |
| 279 } | 296 } |
| 280 | 297 |
| 298 gfx::Size ContentsView::GetPreferredSize() const { | |
| 299 gfx::Rect search_box_bounds = GetDefaultSearchBoxBounds(); | |
| 300 gfx::Rect default_contents_bounds = GetDefaultContentsBounds(); | |
| 301 return gfx::Size( | |
|
Matt Giuca
2014/10/24 03:21:40
default_contents_bounds.Union(search_box_bounds);
calamity
2014/10/24 06:13:08
Nope. search_box_bounds doesn't have 0, 0 origin.
| |
| 302 std::max(search_box_bounds.right(), default_contents_bounds.right()), | |
| 303 std::max(search_box_bounds.bottom(), default_contents_bounds.bottom())); | |
| 304 } | |
| 305 | |
| 281 void ContentsView::Layout() { | 306 void ContentsView::Layout() { |
| 282 // Immediately finish all current animations. | 307 // Immediately finish all current animations. |
| 283 pagination_model_.FinishAnimation(); | 308 pagination_model_.FinishAnimation(); |
| 284 | 309 |
| 285 // Move the current view onto the screen, and all other views off screen to | 310 // Move the current view onto the screen, and all other views off screen to |
| 286 // the left. (Since we are not animating, we don't need to be careful about | 311 // the left. (Since we are not animating, we don't need to be careful about |
| 287 // which side we place the off-screen views onto.) | 312 // which side we place the off-screen views onto.) |
| 288 gfx::Rect rect(GetContentsBounds()); | 313 gfx::Rect rect(GetDefaultContentsBounds()); |
| 289 if (rect.IsEmpty()) | 314 if (rect.IsEmpty()) |
| 290 return; | 315 return; |
| 291 | 316 |
| 292 gfx::Rect offscreen_target(rect); | 317 gfx::Rect offscreen_target(rect); |
| 293 offscreen_target.set_x(-rect.width()); | 318 offscreen_target.set_x(-rect.width()); |
| 294 | 319 |
| 295 for (int i = 0; i < view_model_->view_size(); ++i) { | 320 for (int i = 0; i < view_model_->view_size(); ++i) { |
| 296 view_model_->view_at(i)->SetBoundsRect( | 321 view_model_->view_at(i)->SetBoundsRect( |
| 297 i == pagination_model_.SelectedTargetPage() ? rect : offscreen_target); | 322 i == pagination_model_.SelectedTargetPage() ? rect : offscreen_target); |
| 298 } | 323 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 309 } | 334 } |
| 310 | 335 |
| 311 void ContentsView::TransitionStarted() { | 336 void ContentsView::TransitionStarted() { |
| 312 } | 337 } |
| 313 | 338 |
| 314 void ContentsView::TransitionChanged() { | 339 void ContentsView::TransitionChanged() { |
| 315 UpdatePageBounds(); | 340 UpdatePageBounds(); |
| 316 } | 341 } |
| 317 | 342 |
| 318 } // namespace app_list | 343 } // namespace app_list |
| OLD | NEW |