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/apps_grid_view.h" | 5 #include "ui/app_list/views/apps_grid_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 // Distance a drag needs to be from the app grid to be considered 'outside', at | 56 // Distance a drag needs to be from the app grid to be considered 'outside', at |
57 // which point we rearrange the apps to their pre-drag configuration, as a drop | 57 // which point we rearrange the apps to their pre-drag configuration, as a drop |
58 // then would be canceled. We have a buffer to make it easier to drag apps to | 58 // then would be canceled. We have a buffer to make it easier to drag apps to |
59 // other pages. | 59 // other pages. |
60 const int kDragBufferPx = 20; | 60 const int kDragBufferPx = 20; |
61 | 61 |
62 // Padding space in pixels for fixed layout. | 62 // Padding space in pixels for fixed layout. |
63 const int kLeftRightPadding = 20; | 63 const int kLeftRightPadding = 20; |
64 const int kTopPadding = 1; | 64 const int kTopPadding = 1; |
| 65 const int kBottomPadding = 24; |
65 | 66 |
66 // Padding space in pixels between pages. | 67 // Padding space in pixels between pages. |
67 const int kPagePadding = 40; | 68 const int kPagePadding = 40; |
68 | 69 |
69 // Preferred tile size when showing in fixed layout. | 70 // Preferred tile size when showing in fixed layout. |
70 const int kPreferredTileWidth = 88; | 71 const int kPreferredTileWidth = 88; |
71 const int kPreferredTileHeight = 98; | 72 const int kPreferredTileHeight = 98; |
72 | 73 |
73 // Width in pixels of the area on the sides that triggers a page flip. | 74 // Width in pixels of the area on the sides that triggers a page flip. |
74 const int kPageFlipZoneSize = 40; | 75 const int kPageFlipZoneSize = 40; |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 kOverscrollPageTransitionDurationMs); | 366 kOverscrollPageTransitionDurationMs); |
366 | 367 |
367 pagination_model_.AddObserver(this); | 368 pagination_model_.AddObserver(this); |
368 // The experimental app list transitions vertically. | 369 // The experimental app list transitions vertically. |
369 PaginationController::ScrollAxis scroll_axis = | 370 PaginationController::ScrollAxis scroll_axis = |
370 app_list::switches::IsExperimentalAppListEnabled() | 371 app_list::switches::IsExperimentalAppListEnabled() |
371 ? PaginationController::SCROLL_AXIS_VERTICAL | 372 ? PaginationController::SCROLL_AXIS_VERTICAL |
372 : PaginationController::SCROLL_AXIS_HORIZONTAL; | 373 : PaginationController::SCROLL_AXIS_HORIZONTAL; |
373 pagination_controller_.reset( | 374 pagination_controller_.reset( |
374 new PaginationController(&pagination_model_, scroll_axis)); | 375 new PaginationController(&pagination_model_, scroll_axis)); |
375 page_switcher_view_ = new PageSwitcher(&pagination_model_); | 376 if (!switches::IsExperimentalAppListEnabled()) { |
376 AddChildView(page_switcher_view_); | 377 page_switcher_view_ = new PageSwitcher(&pagination_model_); |
| 378 AddChildView(page_switcher_view_); |
| 379 } |
377 } | 380 } |
378 | 381 |
379 AppsGridView::~AppsGridView() { | 382 AppsGridView::~AppsGridView() { |
380 // Coming here |drag_view_| should already be canceled since otherwise the | 383 // Coming here |drag_view_| should already be canceled since otherwise the |
381 // drag would disappear after the app list got animated away and closed, | 384 // drag would disappear after the app list got animated away and closed, |
382 // which would look odd. | 385 // which would look odd. |
383 DCHECK(!drag_view_); | 386 DCHECK(!drag_view_); |
384 if (drag_view_) | 387 if (drag_view_) |
385 EndDrag(true); | 388 EndDrag(true); |
386 | 389 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 last_drag_point_ = point; | 618 last_drag_point_ = point; |
616 const Index last_drop_target = drop_target_; | 619 const Index last_drop_target = drop_target_; |
617 DropAttempt last_drop_attempt = drop_attempt_; | 620 DropAttempt last_drop_attempt = drop_attempt_; |
618 CalculateDropTarget(last_drag_point_, false); | 621 CalculateDropTarget(last_drag_point_, false); |
619 | 622 |
620 if (IsPointWithinDragBuffer(last_drag_point_)) | 623 if (IsPointWithinDragBuffer(last_drag_point_)) |
621 MaybeStartPageFlipTimer(last_drag_point_); | 624 MaybeStartPageFlipTimer(last_drag_point_); |
622 else | 625 else |
623 StopPageFlipTimer(); | 626 StopPageFlipTimer(); |
624 | 627 |
625 gfx::Point page_switcher_point(last_drag_point_); | 628 if (page_switcher_view_) { |
626 views::View::ConvertPointToTarget(this, page_switcher_view_, | 629 gfx::Point page_switcher_point(last_drag_point_); |
627 &page_switcher_point); | 630 views::View::ConvertPointToTarget( |
628 page_switcher_view_->UpdateUIForDragPoint(page_switcher_point); | 631 this, page_switcher_view_, &page_switcher_point); |
| 632 page_switcher_view_->UpdateUIForDragPoint(page_switcher_point); |
| 633 } |
629 | 634 |
630 if (!EnableFolderDragDropUI()) { | 635 if (!EnableFolderDragDropUI()) { |
631 if (last_drop_target != drop_target_) | 636 if (last_drop_target != drop_target_) |
632 AnimateToIdealBounds(); | 637 AnimateToIdealBounds(); |
633 drag_view_->SetPosition(drag_view_start_ + drag_vector); | 638 drag_view_->SetPosition(drag_view_start_ + drag_vector); |
634 return; | 639 return; |
635 } | 640 } |
636 | 641 |
637 // Update drag with folder UI enabled. | 642 // Update drag with folder UI enabled. |
638 if (last_drop_target != drop_target_ || | 643 if (last_drop_target != drop_target_ || |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 } | 873 } |
869 | 874 |
870 bool AppsGridView::IsAnimatingView(views::View* view) { | 875 bool AppsGridView::IsAnimatingView(views::View* view) { |
871 return bounds_animator_.IsAnimating(view); | 876 return bounds_animator_.IsAnimating(view); |
872 } | 877 } |
873 | 878 |
874 gfx::Size AppsGridView::GetPreferredSize() const { | 879 gfx::Size AppsGridView::GetPreferredSize() const { |
875 const gfx::Insets insets(GetInsets()); | 880 const gfx::Insets insets(GetInsets()); |
876 const gfx::Size tile_size = gfx::Size(kPreferredTileWidth, | 881 const gfx::Size tile_size = gfx::Size(kPreferredTileWidth, |
877 kPreferredTileHeight); | 882 kPreferredTileHeight); |
878 const int page_switcher_height = | 883 int page_switcher_height = kBottomPadding; |
879 page_switcher_view_->GetPreferredSize().height(); | 884 if (page_switcher_view_) |
| 885 page_switcher_height = page_switcher_view_->GetPreferredSize().height(); |
880 return gfx::Size( | 886 return gfx::Size( |
881 tile_size.width() * cols_ + insets.width(), | 887 tile_size.width() * cols_ + insets.width(), |
882 tile_size.height() * rows_per_page_ + | 888 tile_size.height() * rows_per_page_ + |
883 page_switcher_height + insets.height()); | 889 page_switcher_height + insets.height()); |
884 } | 890 } |
885 | 891 |
886 bool AppsGridView::GetDropFormats( | 892 bool AppsGridView::GetDropFormats( |
887 int* formats, | 893 int* formats, |
888 std::set<OSExchangeData::CustomFormat>* custom_formats) { | 894 std::set<OSExchangeData::CustomFormat>* custom_formats) { |
889 // TODO(koz): Only accept a specific drag type for app shortcuts. | 895 // TODO(koz): Only accept a specific drag type for app shortcuts. |
(...skipping 14 matching lines...) Expand all Loading... |
904 bounds_animator_.Cancel(); | 910 bounds_animator_.Cancel(); |
905 | 911 |
906 CalculateIdealBounds(); | 912 CalculateIdealBounds(); |
907 for (int i = 0; i < view_model_.view_size(); ++i) { | 913 for (int i = 0; i < view_model_.view_size(); ++i) { |
908 views::View* view = view_model_.view_at(i); | 914 views::View* view = view_model_.view_at(i); |
909 if (view != drag_view_) | 915 if (view != drag_view_) |
910 view->SetBoundsRect(view_model_.ideal_bounds(i)); | 916 view->SetBoundsRect(view_model_.ideal_bounds(i)); |
911 } | 917 } |
912 views::ViewModelUtils::SetViewBoundsToIdealBounds(pulsing_blocks_model_); | 918 views::ViewModelUtils::SetViewBoundsToIdealBounds(pulsing_blocks_model_); |
913 | 919 |
914 const int page_switcher_height = | 920 if (page_switcher_view_) { |
915 page_switcher_view_->GetPreferredSize().height(); | 921 const int page_switcher_height = |
916 gfx::Rect rect(GetContentsBounds()); | 922 page_switcher_view_->GetPreferredSize().height(); |
917 rect.set_y(rect.bottom() - page_switcher_height); | 923 gfx::Rect rect(GetContentsBounds()); |
918 rect.set_height(page_switcher_height); | 924 rect.set_y(rect.bottom() - page_switcher_height); |
919 page_switcher_view_->SetBoundsRect(rect); | 925 rect.set_height(page_switcher_height); |
| 926 page_switcher_view_->SetBoundsRect(rect); |
| 927 } |
920 } | 928 } |
921 | 929 |
922 bool AppsGridView::OnKeyPressed(const ui::KeyEvent& event) { | 930 bool AppsGridView::OnKeyPressed(const ui::KeyEvent& event) { |
923 bool handled = false; | 931 bool handled = false; |
924 if (selected_view_) | 932 if (selected_view_) |
925 handled = selected_view_->OnKeyPressed(event); | 933 handled = selected_view_->OnKeyPressed(event); |
926 | 934 |
927 if (!handled) { | 935 if (!handled) { |
928 const int forward_dir = base::i18n::IsRTL() ? -1 : 1; | 936 const int forward_dir = base::i18n::IsRTL() ? -1 : 1; |
929 switch (event.key_code()) { | 937 switch (event.key_code()) { |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1357 return; | 1365 return; |
1358 } | 1366 } |
1359 | 1367 |
1360 int current_page = pagination_model_.selected_page(); | 1368 int current_page = pagination_model_.selected_page(); |
1361 gfx::Point point(drag_point); | 1369 gfx::Point point(drag_point); |
1362 if (!IsPointWithinDragBuffer(drag_point)) { | 1370 if (!IsPointWithinDragBuffer(drag_point)) { |
1363 point = drag_start_grid_view_; | 1371 point = drag_start_grid_view_; |
1364 current_page = drag_start_page_; | 1372 current_page = drag_start_page_; |
1365 } | 1373 } |
1366 | 1374 |
1367 if (use_page_button_hovering && | 1375 if (use_page_button_hovering && page_switcher_view_ && |
1368 page_switcher_view_->bounds().Contains(point)) { | 1376 page_switcher_view_->bounds().Contains(point)) { |
1369 gfx::Point page_switcher_point(point); | 1377 gfx::Point page_switcher_point(point); |
1370 views::View::ConvertPointToTarget(this, page_switcher_view_, | 1378 views::View::ConvertPointToTarget(this, page_switcher_view_, |
1371 &page_switcher_point); | 1379 &page_switcher_point); |
1372 int page = page_switcher_view_->GetPageForPoint(page_switcher_point); | 1380 int page = page_switcher_view_->GetPageForPoint(page_switcher_point); |
1373 if (pagination_model_.is_valid_page(page)) { | 1381 if (pagination_model_.is_valid_page(page)) { |
1374 drop_target_.page = page; | 1382 drop_target_.page = page; |
1375 drop_target_.slot = tiles_per_page() - 1; | 1383 drop_target_.slot = tiles_per_page() - 1; |
1376 } | 1384 } |
1377 } else { | 1385 } else { |
(...skipping 18 matching lines...) Expand all Loading... |
1396 | 1404 |
1397 | 1405 |
1398 void AppsGridView::CalculateDropTargetWithFolderEnabled( | 1406 void AppsGridView::CalculateDropTargetWithFolderEnabled( |
1399 const gfx::Point& drag_point, | 1407 const gfx::Point& drag_point, |
1400 bool use_page_button_hovering) { | 1408 bool use_page_button_hovering) { |
1401 gfx::Point point(drag_point); | 1409 gfx::Point point(drag_point); |
1402 if (!IsPointWithinDragBuffer(drag_point)) { | 1410 if (!IsPointWithinDragBuffer(drag_point)) { |
1403 point = drag_start_grid_view_; | 1411 point = drag_start_grid_view_; |
1404 } | 1412 } |
1405 | 1413 |
1406 if (use_page_button_hovering && | 1414 if (use_page_button_hovering && page_switcher_view_ && |
1407 page_switcher_view_->bounds().Contains(point)) { | 1415 page_switcher_view_->bounds().Contains(point)) { |
1408 gfx::Point page_switcher_point(point); | 1416 gfx::Point page_switcher_point(point); |
1409 views::View::ConvertPointToTarget(this, page_switcher_view_, | 1417 views::View::ConvertPointToTarget(this, page_switcher_view_, |
1410 &page_switcher_point); | 1418 &page_switcher_point); |
1411 int page = page_switcher_view_->GetPageForPoint(page_switcher_point); | 1419 int page = page_switcher_view_->GetPageForPoint(page_switcher_point); |
1412 if (pagination_model_.is_valid_page(page)) | 1420 if (pagination_model_.is_valid_page(page)) |
1413 drop_attempt_ = DROP_FOR_NONE; | 1421 drop_attempt_ = DROP_FOR_NONE; |
1414 } else { | 1422 } else { |
1415 DCHECK(drag_view_); | 1423 DCHECK(drag_view_); |
1416 // Try to find the nearest target for folder dropping or re-ordering. | 1424 // Try to find the nearest target for folder dropping or re-ordering. |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1637 } | 1645 } |
1638 } | 1646 } |
1639 } | 1647 } |
1640 } | 1648 } |
1641 | 1649 |
1642 void AppsGridView::MaybeStartPageFlipTimer(const gfx::Point& drag_point) { | 1650 void AppsGridView::MaybeStartPageFlipTimer(const gfx::Point& drag_point) { |
1643 if (!IsPointWithinDragBuffer(drag_point)) | 1651 if (!IsPointWithinDragBuffer(drag_point)) |
1644 StopPageFlipTimer(); | 1652 StopPageFlipTimer(); |
1645 int new_page_flip_target = -1; | 1653 int new_page_flip_target = -1; |
1646 | 1654 |
1647 if (page_switcher_view_->bounds().Contains(drag_point)) { | 1655 if (page_switcher_view_ && |
| 1656 page_switcher_view_->bounds().Contains(drag_point)) { |
1648 gfx::Point page_switcher_point(drag_point); | 1657 gfx::Point page_switcher_point(drag_point); |
1649 views::View::ConvertPointToTarget(this, page_switcher_view_, | 1658 views::View::ConvertPointToTarget(this, page_switcher_view_, |
1650 &page_switcher_point); | 1659 &page_switcher_point); |
1651 new_page_flip_target = | 1660 new_page_flip_target = |
1652 page_switcher_view_->GetPageForPoint(page_switcher_point); | 1661 page_switcher_view_->GetPageForPoint(page_switcher_point); |
1653 } | 1662 } |
1654 | 1663 |
1655 // TODO(xiyuan): Fix this for RTL. | 1664 // TODO(xiyuan): Fix this for RTL. |
1656 if (new_page_flip_target == -1 && drag_point.x() < kPageFlipZoneSize) | 1665 if (new_page_flip_target == -1 && drag_point.x() < kPageFlipZoneSize) |
1657 new_page_flip_target = pagination_model_.selected_page() - 1; | 1666 new_page_flip_target = pagination_model_.selected_page() - 1; |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2218 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, | 2227 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, |
2219 bool is_target_folder) { | 2228 bool is_target_folder) { |
2220 AppListItemView* target_view = | 2229 AppListItemView* target_view = |
2221 static_cast<AppListItemView*>( | 2230 static_cast<AppListItemView*>( |
2222 GetViewAtSlotOnCurrentPage(target_index.slot)); | 2231 GetViewAtSlotOnCurrentPage(target_index.slot)); |
2223 if (target_view) | 2232 if (target_view) |
2224 target_view->SetAsAttemptedFolderTarget(is_target_folder); | 2233 target_view->SetAsAttemptedFolderTarget(is_target_folder); |
2225 } | 2234 } |
2226 | 2235 |
2227 } // namespace app_list | 2236 } // namespace app_list |
OLD | NEW |