| 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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 | 458 |
| 459 void AppsGridView::SetItemList(AppListItemList* item_list) { | 459 void AppsGridView::SetItemList(AppListItemList* item_list) { |
| 460 if (item_list_) | 460 if (item_list_) |
| 461 item_list_->RemoveObserver(this); | 461 item_list_->RemoveObserver(this); |
| 462 item_list_ = item_list; | 462 item_list_ = item_list; |
| 463 if (item_list_) | 463 if (item_list_) |
| 464 item_list_->AddObserver(this); | 464 item_list_->AddObserver(this); |
| 465 Update(); | 465 Update(); |
| 466 } | 466 } |
| 467 | 467 |
| 468 void AppsGridView::SetSelectedView(views::View* view) { | 468 void AppsGridView::SetSelectedView(AppListItemView* view) { |
| 469 if (IsSelectedView(view) || IsDraggedView(view)) | 469 if (IsSelectedView(view) || IsDraggedView(view)) |
| 470 return; | 470 return; |
| 471 | 471 |
| 472 Index index = GetIndexOfView(view); | 472 Index index = GetIndexOfView(view); |
| 473 if (IsValidIndex(index)) | 473 if (IsValidIndex(index)) |
| 474 SetSelectedItemByIndex(index); | 474 SetSelectedItemByIndex(index); |
| 475 } | 475 } |
| 476 | 476 |
| 477 void AppsGridView::ClearSelectedView(views::View* view) { | 477 void AppsGridView::ClearSelectedView(AppListItemView* view) { |
| 478 if (view && IsSelectedView(view)) { | 478 if (view && IsSelectedView(view)) { |
| 479 selected_view_->SchedulePaint(); | 479 selected_view_->SchedulePaint(); |
| 480 selected_view_ = NULL; | 480 selected_view_ = NULL; |
| 481 } | 481 } |
| 482 } | 482 } |
| 483 | 483 |
| 484 void AppsGridView::ClearAnySelectedView() { | 484 void AppsGridView::ClearAnySelectedView() { |
| 485 if (selected_view_) { | 485 if (selected_view_) { |
| 486 selected_view_->SchedulePaint(); | 486 selected_view_->SchedulePaint(); |
| 487 selected_view_ = NULL; | 487 selected_view_ = NULL; |
| 488 } | 488 } |
| 489 } | 489 } |
| 490 | 490 |
| 491 bool AppsGridView::IsSelectedView(const views::View* view) const { | 491 bool AppsGridView::IsSelectedView(const AppListItemView* view) const { |
| 492 return selected_view_ == view; | 492 return selected_view_ == view; |
| 493 } | 493 } |
| 494 | 494 |
| 495 void AppsGridView::EnsureViewVisible(const views::View* view) { | 495 void AppsGridView::EnsureViewVisible(const AppListItemView* view) { |
| 496 if (pagination_model_.has_transition()) | 496 if (pagination_model_.has_transition()) |
| 497 return; | 497 return; |
| 498 | 498 |
| 499 Index index = GetIndexOfView(view); | 499 Index index = GetIndexOfView(view); |
| 500 if (IsValidIndex(index)) | 500 if (IsValidIndex(index)) |
| 501 pagination_model_.SelectPage(index.page, false); | 501 pagination_model_.SelectPage(index.page, false); |
| 502 } | 502 } |
| 503 | 503 |
| 504 void AppsGridView::InitiateDrag(AppListItemView* view, | 504 void AppsGridView::InitiateDrag(AppListItemView* view, |
| 505 Pointer pointer, | 505 Pointer pointer, |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 if (folder_delegate_ && !IsDraggingForReparentInHiddenGridView()) | 755 if (folder_delegate_ && !IsDraggingForReparentInHiddenGridView()) |
| 756 folder_delegate_->UpdateFolderViewBackground(false); | 756 folder_delegate_->UpdateFolderViewBackground(false); |
| 757 } | 757 } |
| 758 | 758 |
| 759 void AppsGridView::StopPageFlipTimer() { | 759 void AppsGridView::StopPageFlipTimer() { |
| 760 page_flip_timer_.Stop(); | 760 page_flip_timer_.Stop(); |
| 761 page_flip_target_ = -1; | 761 page_flip_target_ = -1; |
| 762 } | 762 } |
| 763 | 763 |
| 764 AppListItemView* AppsGridView::GetItemViewAt(int index) const { | 764 AppListItemView* AppsGridView::GetItemViewAt(int index) const { |
| 765 DCHECK(index >= 0 && index < view_model_.view_size()); | |
| 766 return static_cast<AppListItemView*>(view_model_.view_at(index)); | 765 return static_cast<AppListItemView*>(view_model_.view_at(index)); |
| 767 } | 766 } |
| 768 | 767 |
| 769 void AppsGridView::SetTopItemViewsVisible(bool visible) { | 768 void AppsGridView::SetTopItemViewsVisible(bool visible) { |
| 770 int top_item_count = std::min(static_cast<int>(kNumFolderTopItems), | 769 int top_item_count = std::min(static_cast<int>(kNumFolderTopItems), |
| 771 view_model_.view_size()); | 770 view_model_.view_size()); |
| 772 for (int i = 0; i < top_item_count; ++i) | 771 for (int i = 0; i < top_item_count; ++i) |
| 773 GetItemViewAt(i)->icon()->SetVisible(visible); | 772 GetItemViewAt(i)->icon()->SetVisible(visible); |
| 774 } | 773 } |
| 775 | 774 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 const gfx::Point& drag_point) { | 834 const gfx::Point& drag_point) { |
| 836 // Note that if a cancel ocurrs while reparenting, the |drag_view_| in both | 835 // Note that if a cancel ocurrs while reparenting, the |drag_view_| in both |
| 837 // root and folder grid views is cleared, so the check in UpdateDragFromItem() | 836 // root and folder grid views is cleared, so the check in UpdateDragFromItem() |
| 838 // for |drag_view_| being NULL (in the folder grid) is sufficient. | 837 // for |drag_view_| being NULL (in the folder grid) is sufficient. |
| 839 DCHECK(drag_view_); | 838 DCHECK(drag_view_); |
| 840 DCHECK(IsDraggingForReparentInRootLevelGridView()); | 839 DCHECK(IsDraggingForReparentInRootLevelGridView()); |
| 841 | 840 |
| 842 UpdateDrag(pointer, drag_point); | 841 UpdateDrag(pointer, drag_point); |
| 843 } | 842 } |
| 844 | 843 |
| 845 bool AppsGridView::IsDraggedView(const views::View* view) const { | 844 bool AppsGridView::IsDraggedView(const AppListItemView* view) const { |
| 846 return drag_view_ == view; | 845 return drag_view_ == view; |
| 847 } | 846 } |
| 848 | 847 |
| 849 void AppsGridView::ClearDragState() { | 848 void AppsGridView::ClearDragState() { |
| 850 drop_attempt_ = DROP_FOR_NONE; | 849 drop_attempt_ = DROP_FOR_NONE; |
| 851 drag_pointer_ = NONE; | 850 drag_pointer_ = NONE; |
| 852 reorder_drop_target_ = Index(); | 851 reorder_drop_target_ = Index(); |
| 853 folder_drop_target_ = Index(); | 852 folder_drop_target_ = Index(); |
| 854 reorder_placeholder_ = Index(); | 853 reorder_placeholder_ = Index(); |
| 855 drag_start_grid_view_ = gfx::Point(); | 854 drag_start_grid_view_ = gfx::Point(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 877 ApplicationDragAndDropHost* drag_and_drop_host) { | 876 ApplicationDragAndDropHost* drag_and_drop_host) { |
| 878 drag_and_drop_host_ = drag_and_drop_host; | 877 drag_and_drop_host_ = drag_and_drop_host; |
| 879 } | 878 } |
| 880 | 879 |
| 881 void AppsGridView::Prerender() { | 880 void AppsGridView::Prerender() { |
| 882 Layout(); | 881 Layout(); |
| 883 int selected_page = std::max(0, pagination_model_.selected_page()); | 882 int selected_page = std::max(0, pagination_model_.selected_page()); |
| 884 int start = std::max(0, (selected_page - kPrerenderPages) * tiles_per_page()); | 883 int start = std::max(0, (selected_page - kPrerenderPages) * tiles_per_page()); |
| 885 int end = std::min(view_model_.view_size(), | 884 int end = std::min(view_model_.view_size(), |
| 886 (selected_page + 1 + kPrerenderPages) * tiles_per_page()); | 885 (selected_page + 1 + kPrerenderPages) * tiles_per_page()); |
| 887 for (int i = start; i < end; i++) { | 886 for (int i = start; i < end; i++) |
| 888 AppListItemView* v = static_cast<AppListItemView*>(view_model_.view_at(i)); | 887 GetItemViewAt(i)->Prerender(); |
| 889 v->Prerender(); | |
| 890 } | |
| 891 } | 888 } |
| 892 | 889 |
| 893 bool AppsGridView::IsAnimatingView(views::View* view) { | 890 bool AppsGridView::IsAnimatingView(AppListItemView* view) { |
| 894 return bounds_animator_.IsAnimating(view); | 891 return bounds_animator_.IsAnimating(view); |
| 895 } | 892 } |
| 896 | 893 |
| 897 gfx::Size AppsGridView::GetPreferredSize() const { | 894 gfx::Size AppsGridView::GetPreferredSize() const { |
| 898 const gfx::Insets insets(GetInsets()); | 895 const gfx::Insets insets(GetInsets()); |
| 899 int page_switcher_height = 0; | 896 int page_switcher_height = 0; |
| 900 if (page_switcher_view_) | 897 if (page_switcher_view_) |
| 901 page_switcher_height = page_switcher_view_->GetPreferredSize().height(); | 898 page_switcher_height = page_switcher_view_->GetPreferredSize().height(); |
| 902 gfx::Size size = GetTileGridSize(); | 899 gfx::Size size = GetTileGridSize(); |
| 903 size.Enlarge(insets.width(), insets.height() + page_switcher_height); | 900 size.Enlarge(insets.width(), insets.height() + page_switcher_height); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 919 int AppsGridView::OnDragUpdated(const ui::DropTargetEvent& event) { | 916 int AppsGridView::OnDragUpdated(const ui::DropTargetEvent& event) { |
| 920 return ui::DragDropTypes::DRAG_MOVE; | 917 return ui::DragDropTypes::DRAG_MOVE; |
| 921 } | 918 } |
| 922 | 919 |
| 923 void AppsGridView::Layout() { | 920 void AppsGridView::Layout() { |
| 924 if (bounds_animator_.IsAnimating()) | 921 if (bounds_animator_.IsAnimating()) |
| 925 bounds_animator_.Cancel(); | 922 bounds_animator_.Cancel(); |
| 926 | 923 |
| 927 CalculateIdealBounds(); | 924 CalculateIdealBounds(); |
| 928 for (int i = 0; i < view_model_.view_size(); ++i) { | 925 for (int i = 0; i < view_model_.view_size(); ++i) { |
| 929 views::View* view = view_model_.view_at(i); | 926 AppListItemView* view = GetItemViewAt(i); |
| 930 if (view != drag_view_) | 927 if (view != drag_view_) |
| 931 view->SetBoundsRect(view_model_.ideal_bounds(i)); | 928 view->SetBoundsRect(view_model_.ideal_bounds(i)); |
| 932 } | 929 } |
| 933 views::ViewModelUtils::SetViewBoundsToIdealBounds(pulsing_blocks_model_); | 930 views::ViewModelUtils::SetViewBoundsToIdealBounds(pulsing_blocks_model_); |
| 934 | 931 |
| 935 if (page_switcher_view_) { | 932 if (page_switcher_view_) { |
| 936 const int page_switcher_height = | 933 const int page_switcher_height = |
| 937 page_switcher_view_->GetPreferredSize().height(); | 934 page_switcher_view_->GetPreferredSize().height(); |
| 938 gfx::Rect rect(GetContentsBounds()); | 935 gfx::Rect rect(GetContentsBounds()); |
| 939 rect.set_y(rect.bottom() - page_switcher_height); | 936 rect.set_y(rect.bottom() - page_switcher_height); |
| 940 rect.set_height(page_switcher_height); | 937 rect.set_height(page_switcher_height); |
| 941 page_switcher_view_->SetBoundsRect(rect); | 938 page_switcher_view_->SetBoundsRect(rect); |
| 942 } | 939 } |
| 943 } | 940 } |
| 944 | 941 |
| 945 bool AppsGridView::OnKeyPressed(const ui::KeyEvent& event) { | 942 bool AppsGridView::OnKeyPressed(const ui::KeyEvent& event) { |
| 946 bool handled = false; | 943 bool handled = false; |
| 947 if (selected_view_) | 944 if (selected_view_) |
| 948 handled = selected_view_->OnKeyPressed(event); | 945 handled = static_cast<views::View*>(selected_view_)->OnKeyPressed(event); |
| 949 | 946 |
| 950 if (!handled) { | 947 if (!handled) { |
| 951 const int forward_dir = base::i18n::IsRTL() ? -1 : 1; | 948 const int forward_dir = base::i18n::IsRTL() ? -1 : 1; |
| 952 switch (event.key_code()) { | 949 switch (event.key_code()) { |
| 953 case ui::VKEY_LEFT: | 950 case ui::VKEY_LEFT: |
| 954 MoveSelected(0, -forward_dir, 0); | 951 MoveSelected(0, -forward_dir, 0); |
| 955 return true; | 952 return true; |
| 956 case ui::VKEY_RIGHT: | 953 case ui::VKEY_RIGHT: |
| 957 MoveSelected(0, forward_dir, 0); | 954 MoveSelected(0, forward_dir, 0); |
| 958 return true; | 955 return true; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 event->StopPropagation(); | 1021 event->StopPropagation(); |
| 1025 } | 1022 } |
| 1026 } | 1023 } |
| 1027 | 1024 |
| 1028 void AppsGridView::Update() { | 1025 void AppsGridView::Update() { |
| 1029 DCHECK(!selected_view_ && !drag_view_); | 1026 DCHECK(!selected_view_ && !drag_view_); |
| 1030 view_model_.Clear(); | 1027 view_model_.Clear(); |
| 1031 if (!item_list_ || !item_list_->item_count()) | 1028 if (!item_list_ || !item_list_->item_count()) |
| 1032 return; | 1029 return; |
| 1033 for (size_t i = 0; i < item_list_->item_count(); ++i) { | 1030 for (size_t i = 0; i < item_list_->item_count(); ++i) { |
| 1034 views::View* view = CreateViewForItemAtIndex(i); | 1031 AppListItemView* view = CreateViewForItemAtIndex(i); |
| 1035 view_model_.Add(view, i); | 1032 view_model_.Add(view, i); |
| 1036 AddChildView(view); | 1033 AddChildView(view); |
| 1037 } | 1034 } |
| 1038 UpdatePaging(); | 1035 UpdatePaging(); |
| 1039 UpdatePulsingBlockViews(); | 1036 UpdatePulsingBlockViews(); |
| 1040 Layout(); | 1037 Layout(); |
| 1041 SchedulePaint(); | 1038 SchedulePaint(); |
| 1042 } | 1039 } |
| 1043 | 1040 |
| 1044 void AppsGridView::UpdatePaging() { | 1041 void AppsGridView::UpdatePaging() { |
| 1045 int total_page = view_model_.view_size() && tiles_per_page() | 1042 int total_page = view_model_.view_size() && tiles_per_page() |
| 1046 ? (view_model_.view_size() - 1) / tiles_per_page() + 1 | 1043 ? (view_model_.view_size() - 1) / tiles_per_page() + 1 |
| 1047 : 0; | 1044 : 0; |
| 1048 | 1045 |
| 1049 pagination_model_.SetTotalPages(total_page); | 1046 pagination_model_.SetTotalPages(total_page); |
| 1050 } | 1047 } |
| 1051 | 1048 |
| 1052 void AppsGridView::UpdatePulsingBlockViews() { | 1049 void AppsGridView::UpdatePulsingBlockViews() { |
| 1053 const int existing_items = item_list_ ? item_list_->item_count() : 0; | 1050 const int existing_items = item_list_ ? item_list_->item_count() : 0; |
| 1054 const int available_slots = | 1051 const int available_slots = |
| 1055 tiles_per_page() - existing_items % tiles_per_page(); | 1052 tiles_per_page() - existing_items % tiles_per_page(); |
| 1056 const int desired = model_->status() == AppListModel::STATUS_SYNCING ? | 1053 const int desired = model_->status() == AppListModel::STATUS_SYNCING ? |
| 1057 available_slots : 0; | 1054 available_slots : 0; |
| 1058 | 1055 |
| 1059 if (pulsing_blocks_model_.view_size() == desired) | 1056 if (pulsing_blocks_model_.view_size() == desired) |
| 1060 return; | 1057 return; |
| 1061 | 1058 |
| 1062 while (pulsing_blocks_model_.view_size() > desired) { | 1059 while (pulsing_blocks_model_.view_size() > desired) { |
| 1063 views::View* view = pulsing_blocks_model_.view_at(0); | 1060 PulsingBlockView* view = GetPulsingBlockViewAt(0); |
| 1064 pulsing_blocks_model_.Remove(0); | 1061 pulsing_blocks_model_.Remove(0); |
| 1065 delete view; | 1062 delete view; |
| 1066 } | 1063 } |
| 1067 | 1064 |
| 1068 while (pulsing_blocks_model_.view_size() < desired) { | 1065 while (pulsing_blocks_model_.view_size() < desired) { |
| 1069 views::View* view = new PulsingBlockView(GetTotalTileSize(), true); | 1066 PulsingBlockView* view = new PulsingBlockView(GetTotalTileSize(), true); |
| 1070 pulsing_blocks_model_.Add(view, 0); | 1067 pulsing_blocks_model_.Add(view, 0); |
| 1071 AddChildView(view); | 1068 AddChildView(view); |
| 1072 } | 1069 } |
| 1073 } | 1070 } |
| 1074 | 1071 |
| 1075 views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) { | 1072 PulsingBlockView* AppsGridView::GetPulsingBlockViewAt(int index) const { |
| 1073 return static_cast<PulsingBlockView*>(pulsing_blocks_model_.view_at(index)); |
| 1074 } |
| 1075 |
| 1076 AppListItemView* AppsGridView::CreateViewForItemAtIndex(size_t index) { |
| 1076 // The drag_view_ might be pending for deletion, therefore view_model_ | 1077 // The drag_view_ might be pending for deletion, therefore view_model_ |
| 1077 // may have one more item than item_list_. | 1078 // may have one more item than item_list_. |
| 1078 DCHECK_LE(index, item_list_->item_count()); | 1079 DCHECK_LE(index, item_list_->item_count()); |
| 1079 AppListItemView* view = new AppListItemView(this, | 1080 AppListItemView* view = new AppListItemView(this, |
| 1080 item_list_->item_at(index)); | 1081 item_list_->item_at(index)); |
| 1081 view->SetPaintToLayer(true); | 1082 view->SetPaintToLayer(true); |
| 1082 view->SetFillsBoundsOpaquely(false); | 1083 view->SetFillsBoundsOpaquely(false); |
| 1083 return view; | 1084 return view; |
| 1084 } | 1085 } |
| 1085 | 1086 |
| 1086 AppsGridView::Index AppsGridView::GetIndexFromModelIndex( | 1087 AppsGridView::Index AppsGridView::GetIndexFromModelIndex( |
| 1087 int model_index) const { | 1088 int model_index) const { |
| 1088 return Index(model_index / tiles_per_page(), model_index % tiles_per_page()); | 1089 return Index(model_index / tiles_per_page(), model_index % tiles_per_page()); |
| 1089 } | 1090 } |
| 1090 | 1091 |
| 1091 int AppsGridView::GetModelIndexFromIndex(const Index& index) const { | 1092 int AppsGridView::GetModelIndexFromIndex(const Index& index) const { |
| 1092 return index.page * tiles_per_page() + index.slot; | 1093 return index.page * tiles_per_page() + index.slot; |
| 1093 } | 1094 } |
| 1094 | 1095 |
| 1095 void AppsGridView::SetSelectedItemByIndex(const Index& index) { | 1096 void AppsGridView::SetSelectedItemByIndex(const Index& index) { |
| 1096 if (GetIndexOfView(selected_view_) == index) | 1097 if (GetIndexOfView(selected_view_) == index) |
| 1097 return; | 1098 return; |
| 1098 | 1099 |
| 1099 views::View* new_selection = GetViewAtIndex(index); | 1100 AppListItemView* new_selection = GetViewAtIndex(index); |
| 1100 if (!new_selection) | 1101 if (!new_selection) |
| 1101 return; // Keep current selection. | 1102 return; // Keep current selection. |
| 1102 | 1103 |
| 1103 if (selected_view_) | 1104 if (selected_view_) |
| 1104 selected_view_->SchedulePaint(); | 1105 selected_view_->SchedulePaint(); |
| 1105 | 1106 |
| 1106 EnsureViewVisible(new_selection); | 1107 EnsureViewVisible(new_selection); |
| 1107 selected_view_ = new_selection; | 1108 selected_view_ = new_selection; |
| 1108 selected_view_->SchedulePaint(); | 1109 selected_view_->SchedulePaint(); |
| 1109 selected_view_->NotifyAccessibilityEvent( | 1110 selected_view_->NotifyAccessibilityEvent( |
| 1110 ui::AX_EVENT_FOCUS, true); | 1111 ui::AX_EVENT_FOCUS, true); |
| 1111 } | 1112 } |
| 1112 | 1113 |
| 1113 bool AppsGridView::IsValidIndex(const Index& index) const { | 1114 bool AppsGridView::IsValidIndex(const Index& index) const { |
| 1114 return index.page >= 0 && index.page < pagination_model_.total_pages() && | 1115 return index.page >= 0 && index.page < pagination_model_.total_pages() && |
| 1115 index.slot >= 0 && index.slot < tiles_per_page() && | 1116 index.slot >= 0 && index.slot < tiles_per_page() && |
| 1116 GetModelIndexFromIndex(index) < view_model_.view_size(); | 1117 GetModelIndexFromIndex(index) < view_model_.view_size(); |
| 1117 } | 1118 } |
| 1118 | 1119 |
| 1119 AppsGridView::Index AppsGridView::GetIndexOfView( | 1120 AppsGridView::Index AppsGridView::GetIndexOfView( |
| 1120 const views::View* view) const { | 1121 const AppListItemView* view) const { |
| 1121 const int model_index = view_model_.GetIndexOfView(view); | 1122 const int model_index = view_model_.GetIndexOfView(view); |
| 1122 if (model_index == -1) | 1123 if (model_index == -1) |
| 1123 return Index(); | 1124 return Index(); |
| 1124 | 1125 |
| 1125 return GetIndexFromModelIndex(model_index); | 1126 return GetIndexFromModelIndex(model_index); |
| 1126 } | 1127 } |
| 1127 | 1128 |
| 1128 views::View* AppsGridView::GetViewAtIndex(const Index& index) const { | 1129 AppListItemView* AppsGridView::GetViewAtIndex(const Index& index) const { |
| 1129 if (!IsValidIndex(index)) | 1130 if (!IsValidIndex(index)) |
| 1130 return NULL; | 1131 return NULL; |
| 1131 | 1132 |
| 1132 const int model_index = GetModelIndexFromIndex(index); | 1133 const int model_index = GetModelIndexFromIndex(index); |
| 1133 return view_model_.view_at(model_index); | 1134 return GetItemViewAt(model_index); |
| 1134 } | 1135 } |
| 1135 | 1136 |
| 1136 AppsGridView::Index AppsGridView::GetLastViewIndex() const { | 1137 AppsGridView::Index AppsGridView::GetLastViewIndex() const { |
| 1137 DCHECK_LT(0, view_model_.view_size()); | 1138 DCHECK_LT(0, view_model_.view_size()); |
| 1138 int view_index = view_model_.view_size() - 1; | 1139 int view_index = view_model_.view_size() - 1; |
| 1139 return Index(view_index / tiles_per_page(), view_index % tiles_per_page()); | 1140 return Index(view_index / tiles_per_page(), view_index % tiles_per_page()); |
| 1140 } | 1141 } |
| 1141 | 1142 |
| 1142 void AppsGridView::MoveSelected(int page_delta, | 1143 void AppsGridView::MoveSelected(int page_delta, |
| 1143 int slot_x_delta, | 1144 int slot_x_delta, |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1257 | 1258 |
| 1258 ++slot_index; | 1259 ++slot_index; |
| 1259 } | 1260 } |
| 1260 } | 1261 } |
| 1261 | 1262 |
| 1262 void AppsGridView::AnimateToIdealBounds() { | 1263 void AppsGridView::AnimateToIdealBounds() { |
| 1263 const gfx::Rect visible_bounds(GetVisibleBounds()); | 1264 const gfx::Rect visible_bounds(GetVisibleBounds()); |
| 1264 | 1265 |
| 1265 CalculateIdealBounds(); | 1266 CalculateIdealBounds(); |
| 1266 for (int i = 0; i < view_model_.view_size(); ++i) { | 1267 for (int i = 0; i < view_model_.view_size(); ++i) { |
| 1267 views::View* view = view_model_.view_at(i); | 1268 AppListItemView* view = GetItemViewAt(i); |
| 1268 if (view == drag_view_) | 1269 if (view == drag_view_) |
| 1269 continue; | 1270 continue; |
| 1270 | 1271 |
| 1271 const gfx::Rect& target = view_model_.ideal_bounds(i); | 1272 const gfx::Rect& target = view_model_.ideal_bounds(i); |
| 1272 if (bounds_animator_.GetTargetBounds(view) == target) | 1273 if (bounds_animator_.GetTargetBounds(view) == target) |
| 1273 continue; | 1274 continue; |
| 1274 | 1275 |
| 1275 const gfx::Rect& current = view->bounds(); | 1276 const gfx::Rect& current = view->bounds(); |
| 1276 const bool current_visible = visible_bounds.Intersects(current); | 1277 const bool current_visible = visible_bounds.Intersects(current); |
| 1277 const bool target_visible = visible_bounds.Intersects(target); | 1278 const bool target_visible = visible_bounds.Intersects(target); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1289 bounds_animator_.SetAnimationDelegate( | 1290 bounds_animator_.SetAnimationDelegate( |
| 1290 view, | 1291 view, |
| 1291 scoped_ptr<gfx::AnimationDelegate>( | 1292 scoped_ptr<gfx::AnimationDelegate>( |
| 1292 new ItemMoveAnimationDelegate(view))); | 1293 new ItemMoveAnimationDelegate(view))); |
| 1293 } else { | 1294 } else { |
| 1294 view->SetBoundsRect(target); | 1295 view->SetBoundsRect(target); |
| 1295 } | 1296 } |
| 1296 } | 1297 } |
| 1297 } | 1298 } |
| 1298 | 1299 |
| 1299 void AppsGridView::AnimationBetweenRows(views::View* view, | 1300 void AppsGridView::AnimationBetweenRows(AppListItemView* view, |
| 1300 bool animate_current, | 1301 bool animate_current, |
| 1301 const gfx::Rect& current, | 1302 const gfx::Rect& current, |
| 1302 bool animate_target, | 1303 bool animate_target, |
| 1303 const gfx::Rect& target) { | 1304 const gfx::Rect& target) { |
| 1304 // Determine page of |current| and |target|. -1 means in the left invisible | 1305 // Determine page of |current| and |target|. -1 means in the left invisible |
| 1305 // page, 0 is the center visible page and 1 means in the right invisible page. | 1306 // page, 0 is the center visible page and 1 means in the right invisible page. |
| 1306 const int current_page = current.x() < 0 ? -1 : | 1307 const int current_page = current.x() < 0 ? -1 : |
| 1307 current.x() >= width() ? 1 : 0; | 1308 current.x() >= width() ? 1 : 0; |
| 1308 const int target_page = target.x() < 0 ? -1 : | 1309 const int target_page = target.x() < 0 ? -1 : |
| 1309 target.x() >= width() ? 1 : 0; | 1310 target.x() >= width() ? 1 : 0; |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1706 this, &AppsGridView::OnPageFlipTimer); | 1707 this, &AppsGridView::OnPageFlipTimer); |
| 1707 } | 1708 } |
| 1708 } | 1709 } |
| 1709 } | 1710 } |
| 1710 | 1711 |
| 1711 void AppsGridView::OnPageFlipTimer() { | 1712 void AppsGridView::OnPageFlipTimer() { |
| 1712 DCHECK(pagination_model_.is_valid_page(page_flip_target_)); | 1713 DCHECK(pagination_model_.is_valid_page(page_flip_target_)); |
| 1713 pagination_model_.SelectPage(page_flip_target_, true); | 1714 pagination_model_.SelectPage(page_flip_target_, true); |
| 1714 } | 1715 } |
| 1715 | 1716 |
| 1716 void AppsGridView::MoveItemInModel(views::View* item_view, | 1717 void AppsGridView::MoveItemInModel(AppListItemView* item_view, |
| 1717 const Index& target) { | 1718 const Index& target) { |
| 1718 int current_model_index = view_model_.GetIndexOfView(item_view); | 1719 int current_model_index = view_model_.GetIndexOfView(item_view); |
| 1719 DCHECK_GE(current_model_index, 0); | 1720 DCHECK_GE(current_model_index, 0); |
| 1720 | 1721 |
| 1721 int target_model_index = GetModelIndexFromIndex(target); | 1722 int target_model_index = GetModelIndexFromIndex(target); |
| 1722 if (target_model_index == current_model_index) | 1723 if (target_model_index == current_model_index) |
| 1723 return; | 1724 return; |
| 1724 | 1725 |
| 1725 item_list_->RemoveObserver(this); | 1726 item_list_->RemoveObserver(this); |
| 1726 item_list_->MoveItem(current_model_index, target_model_index); | 1727 item_list_->MoveItem(current_model_index, target_model_index); |
| 1727 view_model_.Move(current_model_index, target_model_index); | 1728 view_model_.Move(current_model_index, target_model_index); |
| 1728 item_list_->AddObserver(this); | 1729 item_list_->AddObserver(this); |
| 1729 | 1730 |
| 1730 if (pagination_model_.selected_page() != target.page) | 1731 if (pagination_model_.selected_page() != target.page) |
| 1731 pagination_model_.SelectPage(target.page, false); | 1732 pagination_model_.SelectPage(target.page, false); |
| 1732 } | 1733 } |
| 1733 | 1734 |
| 1734 void AppsGridView::MoveItemToFolder(views::View* item_view, | 1735 void AppsGridView::MoveItemToFolder(AppListItemView* item_view, |
| 1735 const Index& target) { | 1736 const Index& target) { |
| 1736 const std::string& source_item_id = | 1737 const std::string& source_item_id = item_view->item()->id(); |
| 1737 static_cast<AppListItemView*>(item_view)->item()->id(); | |
| 1738 AppListItemView* target_view = | 1738 AppListItemView* target_view = |
| 1739 static_cast<AppListItemView*>(GetViewAtSlotOnCurrentPage(target.slot)); | 1739 GetViewDisplayedAtSlotOnCurrentPage(target.slot); |
| 1740 const std::string& target_view_item_id = target_view->item()->id(); | 1740 const std::string& target_view_item_id = target_view->item()->id(); |
| 1741 | 1741 |
| 1742 // Make change to data model. | 1742 // Make change to data model. |
| 1743 item_list_->RemoveObserver(this); | 1743 item_list_->RemoveObserver(this); |
| 1744 std::string folder_item_id = | 1744 std::string folder_item_id = |
| 1745 model_->MergeItems(target_view_item_id, source_item_id); | 1745 model_->MergeItems(target_view_item_id, source_item_id); |
| 1746 item_list_->AddObserver(this); | 1746 item_list_->AddObserver(this); |
| 1747 if (folder_item_id.empty()) { | 1747 if (folder_item_id.empty()) { |
| 1748 LOG(ERROR) << "Unable to merge into item id: " << target_view_item_id; | 1748 LOG(ERROR) << "Unable to merge into item id: " << target_view_item_id; |
| 1749 return; | 1749 return; |
| 1750 } | 1750 } |
| 1751 if (folder_item_id != target_view_item_id) { | 1751 if (folder_item_id != target_view_item_id) { |
| 1752 // New folder was created, change the view model to replace the old target | 1752 // New folder was created, change the view model to replace the old target |
| 1753 // view with the new folder item view. | 1753 // view with the new folder item view. |
| 1754 size_t folder_item_index; | 1754 size_t folder_item_index; |
| 1755 if (item_list_->FindItemIndex(folder_item_id, &folder_item_index)) { | 1755 if (item_list_->FindItemIndex(folder_item_id, &folder_item_index)) { |
| 1756 int target_view_index = view_model_.GetIndexOfView(target_view); | 1756 int target_view_index = view_model_.GetIndexOfView(target_view); |
| 1757 gfx::Rect target_view_bounds = target_view->bounds(); | 1757 gfx::Rect target_view_bounds = target_view->bounds(); |
| 1758 DeleteItemViewAtIndex(target_view_index); | 1758 DeleteItemViewAtIndex(target_view_index); |
| 1759 views::View* target_folder_view = | 1759 AppListItemView* target_folder_view = |
| 1760 CreateViewForItemAtIndex(folder_item_index); | 1760 CreateViewForItemAtIndex(folder_item_index); |
| 1761 target_folder_view->SetBoundsRect(target_view_bounds); | 1761 target_folder_view->SetBoundsRect(target_view_bounds); |
| 1762 view_model_.Add(target_folder_view, target_view_index); | 1762 view_model_.Add(target_folder_view, target_view_index); |
| 1763 AddChildView(target_folder_view); | 1763 AddChildView(target_folder_view); |
| 1764 } else { | 1764 } else { |
| 1765 LOG(ERROR) << "Folder no longer in item_list: " << folder_item_id; | 1765 LOG(ERROR) << "Folder no longer in item_list: " << folder_item_id; |
| 1766 } | 1766 } |
| 1767 } | 1767 } |
| 1768 | 1768 |
| 1769 // Fade out the drag_view_ and delete it when animation ends. | 1769 // Fade out the drag_view_ and delete it when animation ends. |
| 1770 int drag_view_index = view_model_.GetIndexOfView(drag_view_); | 1770 int drag_view_index = view_model_.GetIndexOfView(drag_view_); |
| 1771 view_model_.Remove(drag_view_index); | 1771 view_model_.Remove(drag_view_index); |
| 1772 bounds_animator_.AnimateViewTo(drag_view_, drag_view_->bounds()); | 1772 bounds_animator_.AnimateViewTo(drag_view_, drag_view_->bounds()); |
| 1773 bounds_animator_.SetAnimationDelegate( | 1773 bounds_animator_.SetAnimationDelegate( |
| 1774 drag_view_, | 1774 drag_view_, |
| 1775 scoped_ptr<gfx::AnimationDelegate>( | 1775 scoped_ptr<gfx::AnimationDelegate>( |
| 1776 new ItemRemoveAnimationDelegate(drag_view_))); | 1776 new ItemRemoveAnimationDelegate(drag_view_))); |
| 1777 UpdatePaging(); | 1777 UpdatePaging(); |
| 1778 } | 1778 } |
| 1779 | 1779 |
| 1780 void AppsGridView::ReparentItemForReorder(views::View* item_view, | 1780 void AppsGridView::ReparentItemForReorder(AppListItemView* item_view, |
| 1781 const Index& target) { | 1781 const Index& target) { |
| 1782 item_list_->RemoveObserver(this); | 1782 item_list_->RemoveObserver(this); |
| 1783 model_->RemoveObserver(this); | 1783 model_->RemoveObserver(this); |
| 1784 | 1784 |
| 1785 AppListItem* reparent_item = static_cast<AppListItemView*>(item_view)->item(); | 1785 AppListItem* reparent_item = item_view->item(); |
| 1786 DCHECK(reparent_item->IsInFolder()); | 1786 DCHECK(reparent_item->IsInFolder()); |
| 1787 const std::string source_folder_id = reparent_item->folder_id(); | 1787 const std::string source_folder_id = reparent_item->folder_id(); |
| 1788 AppListFolderItem* source_folder = | 1788 AppListFolderItem* source_folder = |
| 1789 static_cast<AppListFolderItem*>(item_list_->FindItem(source_folder_id)); | 1789 static_cast<AppListFolderItem*>(item_list_->FindItem(source_folder_id)); |
| 1790 | 1790 |
| 1791 int target_model_index = GetModelIndexFromIndex(target); | 1791 int target_model_index = GetModelIndexFromIndex(target); |
| 1792 | 1792 |
| 1793 // Remove the source folder view if there is only 1 item in it, since the | 1793 // Remove the source folder view if there is only 1 item in it, since the |
| 1794 // source folder will be deleted after its only child item removed from it. | 1794 // source folder will be deleted after its only child item removed from it. |
| 1795 if (source_folder->ChildItemCount() == 1u) { | 1795 if (source_folder->ChildItemCount() == 1u) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1812 model_->MoveItemToFolderAt(reparent_item, "", target_position); | 1812 model_->MoveItemToFolderAt(reparent_item, "", target_position); |
| 1813 view_model_.Move(current_model_index, target_model_index); | 1813 view_model_.Move(current_model_index, target_model_index); |
| 1814 | 1814 |
| 1815 RemoveLastItemFromReparentItemFolderIfNecessary(source_folder_id); | 1815 RemoveLastItemFromReparentItemFolderIfNecessary(source_folder_id); |
| 1816 | 1816 |
| 1817 item_list_->AddObserver(this); | 1817 item_list_->AddObserver(this); |
| 1818 model_->AddObserver(this); | 1818 model_->AddObserver(this); |
| 1819 UpdatePaging(); | 1819 UpdatePaging(); |
| 1820 } | 1820 } |
| 1821 | 1821 |
| 1822 void AppsGridView::ReparentItemToAnotherFolder(views::View* item_view, | 1822 void AppsGridView::ReparentItemToAnotherFolder(AppListItemView* item_view, |
| 1823 const Index& target) { | 1823 const Index& target) { |
| 1824 DCHECK(IsDraggingForReparentInRootLevelGridView()); | 1824 DCHECK(IsDraggingForReparentInRootLevelGridView()); |
| 1825 | 1825 |
| 1826 AppListItemView* target_view = | 1826 AppListItemView* target_view = |
| 1827 static_cast<AppListItemView*>(GetViewAtSlotOnCurrentPage(target.slot)); | 1827 GetViewDisplayedAtSlotOnCurrentPage(target.slot); |
| 1828 if (!target_view) | 1828 if (!target_view) |
| 1829 return; | 1829 return; |
| 1830 | 1830 |
| 1831 // Make change to data model. | 1831 // Make change to data model. |
| 1832 item_list_->RemoveObserver(this); | 1832 item_list_->RemoveObserver(this); |
| 1833 | 1833 |
| 1834 AppListItem* reparent_item = static_cast<AppListItemView*>(item_view)->item(); | 1834 AppListItem* reparent_item = item_view->item(); |
| 1835 DCHECK(reparent_item->IsInFolder()); | 1835 DCHECK(reparent_item->IsInFolder()); |
| 1836 const std::string source_folder_id = reparent_item->folder_id(); | 1836 const std::string source_folder_id = reparent_item->folder_id(); |
| 1837 AppListFolderItem* source_folder = | 1837 AppListFolderItem* source_folder = |
| 1838 static_cast<AppListFolderItem*>(item_list_->FindItem(source_folder_id)); | 1838 static_cast<AppListFolderItem*>(item_list_->FindItem(source_folder_id)); |
| 1839 | 1839 |
| 1840 // Remove the source folder view if there is only 1 item in it, since the | 1840 // Remove the source folder view if there is only 1 item in it, since the |
| 1841 // source folder will be deleted after its only child item merged into the | 1841 // source folder will be deleted after its only child item merged into the |
| 1842 // target item. | 1842 // target item. |
| 1843 if (source_folder->ChildItemCount() == 1u) | 1843 if (source_folder->ChildItemCount() == 1u) |
| 1844 DeleteItemViewAtIndex( | 1844 DeleteItemViewAtIndex( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1856 } | 1856 } |
| 1857 | 1857 |
| 1858 if (target_id_after_merge != target_item->id()) { | 1858 if (target_id_after_merge != target_item->id()) { |
| 1859 // New folder was created, change the view model to replace the old target | 1859 // New folder was created, change the view model to replace the old target |
| 1860 // view with the new folder item view. | 1860 // view with the new folder item view. |
| 1861 const std::string& new_folder_id = reparent_item->folder_id(); | 1861 const std::string& new_folder_id = reparent_item->folder_id(); |
| 1862 size_t new_folder_index; | 1862 size_t new_folder_index; |
| 1863 if (item_list_->FindItemIndex(new_folder_id, &new_folder_index)) { | 1863 if (item_list_->FindItemIndex(new_folder_id, &new_folder_index)) { |
| 1864 int target_view_index = view_model_.GetIndexOfView(target_view); | 1864 int target_view_index = view_model_.GetIndexOfView(target_view); |
| 1865 DeleteItemViewAtIndex(target_view_index); | 1865 DeleteItemViewAtIndex(target_view_index); |
| 1866 views::View* new_folder_view = | 1866 AppListItemView* new_folder_view = |
| 1867 CreateViewForItemAtIndex(new_folder_index); | 1867 CreateViewForItemAtIndex(new_folder_index); |
| 1868 view_model_.Add(new_folder_view, target_view_index); | 1868 view_model_.Add(new_folder_view, target_view_index); |
| 1869 AddChildView(new_folder_view); | 1869 AddChildView(new_folder_view); |
| 1870 } else { | 1870 } else { |
| 1871 LOG(ERROR) << "Folder no longer in item_list: " << new_folder_id; | 1871 LOG(ERROR) << "Folder no longer in item_list: " << new_folder_id; |
| 1872 } | 1872 } |
| 1873 } | 1873 } |
| 1874 | 1874 |
| 1875 RemoveLastItemFromReparentItemFolderIfNecessary(source_folder_id); | 1875 RemoveLastItemFromReparentItemFolderIfNecessary(source_folder_id); |
| 1876 | 1876 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1906 AppListItem* last_item = source_folder->item_list()->item_at(0); | 1906 AppListItem* last_item = source_folder->item_list()->item_at(0); |
| 1907 model_->MoveItemToFolderAt(last_item, "", source_folder->position()); | 1907 model_->MoveItemToFolderAt(last_item, "", source_folder->position()); |
| 1908 | 1908 |
| 1909 // Create a new item view for the last item in folder. | 1909 // Create a new item view for the last item in folder. |
| 1910 size_t last_item_index; | 1910 size_t last_item_index; |
| 1911 if (!item_list_->FindItemIndex(last_item->id(), &last_item_index) || | 1911 if (!item_list_->FindItemIndex(last_item->id(), &last_item_index) || |
| 1912 last_item_index > static_cast<size_t>(view_model_.view_size())) { | 1912 last_item_index > static_cast<size_t>(view_model_.view_size())) { |
| 1913 NOTREACHED(); | 1913 NOTREACHED(); |
| 1914 return; | 1914 return; |
| 1915 } | 1915 } |
| 1916 views::View* last_item_view = CreateViewForItemAtIndex(last_item_index); | 1916 AppListItemView* last_item_view = CreateViewForItemAtIndex(last_item_index); |
| 1917 view_model_.Add(last_item_view, last_item_index); | 1917 view_model_.Add(last_item_view, last_item_index); |
| 1918 AddChildView(last_item_view); | 1918 AddChildView(last_item_view); |
| 1919 } | 1919 } |
| 1920 | 1920 |
| 1921 void AppsGridView::CancelFolderItemReparent(AppListItemView* drag_item_view) { | 1921 void AppsGridView::CancelFolderItemReparent(AppListItemView* drag_item_view) { |
| 1922 // The icon of the dragged item must target to its final ideal bounds after | 1922 // The icon of the dragged item must target to its final ideal bounds after |
| 1923 // the animation completes. | 1923 // the animation completes. |
| 1924 CalculateIdealBounds(); | 1924 CalculateIdealBounds(); |
| 1925 | 1925 |
| 1926 gfx::Rect target_icon_rect = | 1926 gfx::Rect target_icon_rect = |
| 1927 GetTargetIconRectInFolder(drag_item_view, activated_folder_item_view_); | 1927 GetTargetIconRectInFolder(drag_item_view, activated_folder_item_view_); |
| 1928 | 1928 |
| 1929 gfx::Rect drag_view_icon_to_grid = | 1929 gfx::Rect drag_view_icon_to_grid = |
| 1930 drag_item_view->ConvertRectToParent(drag_item_view->GetIconBounds()); | 1930 drag_item_view->ConvertRectToParent(drag_item_view->GetIconBounds()); |
| 1931 drag_view_icon_to_grid.ClampToCenteredSize( | 1931 drag_view_icon_to_grid.ClampToCenteredSize( |
| 1932 gfx::Size(kGridIconDimension, kGridIconDimension)); | 1932 gfx::Size(kGridIconDimension, kGridIconDimension)); |
| 1933 TopIconAnimationView* icon_view = new TopIconAnimationView( | 1933 TopIconAnimationView* icon_view = new TopIconAnimationView( |
| 1934 drag_item_view->item()->icon(), | 1934 drag_item_view->item()->icon(), |
| 1935 target_icon_rect, | 1935 target_icon_rect, |
| 1936 false); /* animate like closing folder */ | 1936 false); /* animate like closing folder */ |
| 1937 AddChildView(icon_view); | 1937 AddChildView(icon_view); |
| 1938 icon_view->SetBoundsRect(drag_view_icon_to_grid); | 1938 icon_view->SetBoundsRect(drag_view_icon_to_grid); |
| 1939 icon_view->TransformView(); | 1939 icon_view->TransformView(); |
| 1940 } | 1940 } |
| 1941 | 1941 |
| 1942 void AppsGridView::CancelContextMenusOnCurrentPage() { | 1942 void AppsGridView::CancelContextMenusOnCurrentPage() { |
| 1943 int start = pagination_model_.selected_page() * tiles_per_page(); | 1943 int start = pagination_model_.selected_page() * tiles_per_page(); |
| 1944 int end = std::min(view_model_.view_size(), start + tiles_per_page()); | 1944 int end = std::min(view_model_.view_size(), start + tiles_per_page()); |
| 1945 for (int i = start; i < end; ++i) { | 1945 for (int i = start; i < end; ++i) |
| 1946 AppListItemView* view = | 1946 GetItemViewAt(i)->CancelContextMenu(); |
| 1947 static_cast<AppListItemView*>(view_model_.view_at(i)); | |
| 1948 view->CancelContextMenu(); | |
| 1949 } | |
| 1950 } | 1947 } |
| 1951 | 1948 |
| 1952 void AppsGridView::DeleteItemViewAtIndex(int index) { | 1949 void AppsGridView::DeleteItemViewAtIndex(int index) { |
| 1953 views::View* item_view = view_model_.view_at(index); | 1950 AppListItemView* item_view = GetItemViewAt(index); |
| 1954 view_model_.Remove(index); | 1951 view_model_.Remove(index); |
| 1955 if (item_view == drag_view_) | 1952 if (item_view == drag_view_) |
| 1956 drag_view_ = NULL; | 1953 drag_view_ = NULL; |
| 1957 delete item_view; | 1954 delete item_view; |
| 1958 } | 1955 } |
| 1959 | 1956 |
| 1960 bool AppsGridView::IsPointWithinDragBuffer(const gfx::Point& point) const { | 1957 bool AppsGridView::IsPointWithinDragBuffer(const gfx::Point& point) const { |
| 1961 gfx::Rect rect(GetLocalBounds()); | 1958 gfx::Rect rect(GetLocalBounds()); |
| 1962 rect.Inset(-kDragBufferPx, -kDragBufferPx, -kDragBufferPx, -kDragBufferPx); | 1959 rect.Inset(-kDragBufferPx, -kDragBufferPx, -kDragBufferPx, -kDragBufferPx); |
| 1963 return rect.Contains(point); | 1960 return rect.Contains(point); |
| 1964 } | 1961 } |
| 1965 | 1962 |
| 1966 void AppsGridView::ButtonPressed(views::Button* sender, | 1963 void AppsGridView::ButtonPressed(views::Button* sender, |
| 1967 const ui::Event& event) { | 1964 const ui::Event& event) { |
| 1968 if (dragging()) | 1965 if (dragging()) |
| 1969 return; | 1966 return; |
| 1970 | 1967 |
| 1971 if (strcmp(sender->GetClassName(), AppListItemView::kViewClassName)) | 1968 if (strcmp(sender->GetClassName(), AppListItemView::kViewClassName)) |
| 1972 return; | 1969 return; |
| 1970 AppListItemView* pressed_item_view = static_cast<AppListItemView*>(sender); |
| 1973 | 1971 |
| 1974 if (delegate_) { | 1972 if (delegate_) { |
| 1975 // Always set the previous activated_folder_item_view_ to be visible. This | 1973 // Always set the previous activated_folder_item_view_ to be visible. This |
| 1976 // prevents a case where the item would remain hidden due the | 1974 // prevents a case where the item would remain hidden due the |
| 1977 // |activated_folder_item_view_| changing during the animation. We only | 1975 // |activated_folder_item_view_| changing during the animation. We only |
| 1978 // need to track |activated_folder_item_view_| in the root level grid view. | 1976 // need to track |activated_folder_item_view_| in the root level grid view. |
| 1979 if (!folder_delegate_) { | 1977 if (!folder_delegate_) { |
| 1980 if (activated_folder_item_view_) | 1978 if (activated_folder_item_view_) |
| 1981 activated_folder_item_view_->SetVisible(true); | 1979 activated_folder_item_view_->SetVisible(true); |
| 1982 AppListItemView* pressed_item_view = | |
| 1983 static_cast<AppListItemView*>(sender); | |
| 1984 if (IsFolderItem(pressed_item_view->item())) | 1980 if (IsFolderItem(pressed_item_view->item())) |
| 1985 activated_folder_item_view_ = pressed_item_view; | 1981 activated_folder_item_view_ = pressed_item_view; |
| 1986 else | 1982 else |
| 1987 activated_folder_item_view_ = NULL; | 1983 activated_folder_item_view_ = NULL; |
| 1988 } | 1984 } |
| 1989 delegate_->ActivateApp(static_cast<AppListItemView*>(sender)->item(), | 1985 delegate_->ActivateApp(pressed_item_view->item(), event.flags()); |
| 1990 event.flags()); | |
| 1991 } | 1986 } |
| 1992 } | 1987 } |
| 1993 | 1988 |
| 1994 void AppsGridView::OnListItemAdded(size_t index, AppListItem* item) { | 1989 void AppsGridView::OnListItemAdded(size_t index, AppListItem* item) { |
| 1995 EndDrag(true); | 1990 EndDrag(true); |
| 1996 | 1991 |
| 1997 views::View* view = CreateViewForItemAtIndex(index); | 1992 AppListItemView* view = CreateViewForItemAtIndex(index); |
| 1998 view_model_.Add(view, index); | 1993 view_model_.Add(view, index); |
| 1999 AddChildView(view); | 1994 AddChildView(view); |
| 2000 | 1995 |
| 2001 UpdatePaging(); | 1996 UpdatePaging(); |
| 2002 UpdatePulsingBlockViews(); | 1997 UpdatePulsingBlockViews(); |
| 2003 Layout(); | 1998 Layout(); |
| 2004 SchedulePaint(); | 1999 SchedulePaint(); |
| 2005 } | 2000 } |
| 2006 | 2001 |
| 2007 void AppsGridView::OnListItemRemoved(size_t index, AppListItem* item) { | 2002 void AppsGridView::OnListItemRemoved(size_t index, AppListItem* item) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2051 if (pagination_model_.is_valid_page(transition.target_page)) | 2046 if (pagination_model_.is_valid_page(transition.target_page)) |
| 2052 Layout(); | 2047 Layout(); |
| 2053 } | 2048 } |
| 2054 | 2049 |
| 2055 void AppsGridView::OnAppListModelStatusChanged() { | 2050 void AppsGridView::OnAppListModelStatusChanged() { |
| 2056 UpdatePulsingBlockViews(); | 2051 UpdatePulsingBlockViews(); |
| 2057 Layout(); | 2052 Layout(); |
| 2058 SchedulePaint(); | 2053 SchedulePaint(); |
| 2059 } | 2054 } |
| 2060 | 2055 |
| 2061 void AppsGridView::SetViewHidden(views::View* view, bool hide, bool immediate) { | 2056 void AppsGridView::SetViewHidden(AppListItemView* view, |
| 2057 bool hide, |
| 2058 bool immediate) { |
| 2062 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); | 2059 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); |
| 2063 animator.SetPreemptionStrategy( | 2060 animator.SetPreemptionStrategy( |
| 2064 immediate ? ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET : | 2061 immediate ? ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET : |
| 2065 ui::LayerAnimator::BLEND_WITH_CURRENT_ANIMATION); | 2062 ui::LayerAnimator::BLEND_WITH_CURRENT_ANIMATION); |
| 2066 view->layer()->SetOpacity(hide ? 0 : 1); | 2063 view->layer()->SetOpacity(hide ? 0 : 1); |
| 2067 } | 2064 } |
| 2068 | 2065 |
| 2069 void AppsGridView::OnImplicitAnimationsCompleted() { | 2066 void AppsGridView::OnImplicitAnimationsCompleted() { |
| 2070 if (layer()->opacity() == 0.0f) | 2067 if (layer()->opacity() == 0.0f) |
| 2071 SetVisible(false); | 2068 SetVisible(false); |
| 2072 } | 2069 } |
| 2073 | 2070 |
| 2074 bool AppsGridView::EnableFolderDragDropUI() { | 2071 bool AppsGridView::EnableFolderDragDropUI() { |
| 2075 // Enable drag and drop folder UI only if it is at the app list root level | 2072 // Enable drag and drop folder UI only if it is at the app list root level |
| 2076 // and the switch is on. | 2073 // and the switch is on. |
| 2077 return model_->folders_enabled() && !folder_delegate_; | 2074 return model_->folders_enabled() && !folder_delegate_; |
| 2078 } | 2075 } |
| 2079 | 2076 |
| 2080 bool AppsGridView::CanDropIntoTarget(const Index& drop_target) const { | 2077 bool AppsGridView::CanDropIntoTarget(const Index& drop_target) const { |
| 2081 views::View* target_view = GetViewAtIndex(drop_target); | 2078 AppListItemView* target_view = GetViewAtIndex(drop_target); |
| 2082 if (!target_view) | 2079 if (!target_view) |
| 2083 return false; | 2080 return false; |
| 2084 | 2081 |
| 2085 AppListItem* target_item = | 2082 AppListItem* target_item = target_view->item(); |
| 2086 static_cast<AppListItemView*>(target_view)->item(); | |
| 2087 // Items can be dropped into non-folders (which have no children) or folders | 2083 // Items can be dropped into non-folders (which have no children) or folders |
| 2088 // that have fewer than the max allowed items. | 2084 // that have fewer than the max allowed items. |
| 2089 // OEM folder does not allow to drag/drop other items in it. | 2085 // OEM folder does not allow to drag/drop other items in it. |
| 2090 return target_item->ChildItemCount() < kMaxFolderItems && | 2086 return target_item->ChildItemCount() < kMaxFolderItems && |
| 2091 !IsOEMFolderItem(target_item); | 2087 !IsOEMFolderItem(target_item); |
| 2092 } | 2088 } |
| 2093 | 2089 |
| 2094 AppsGridView::Index AppsGridView::GetNearestTileIndexForPoint( | 2090 AppsGridView::Index AppsGridView::GetNearestTileIndexForPoint( |
| 2095 const gfx::Point& point) const { | 2091 const gfx::Point& point) const { |
| 2096 gfx::Rect bounds = GetContentsBounds(); | 2092 gfx::Rect bounds = GetContentsBounds(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2118 gfx::Rect AppsGridView::GetExpectedTileBounds(int row, int col) const { | 2114 gfx::Rect AppsGridView::GetExpectedTileBounds(int row, int col) const { |
| 2119 gfx::Rect bounds(GetContentsBounds()); | 2115 gfx::Rect bounds(GetContentsBounds()); |
| 2120 gfx::Size total_tile_size = GetTotalTileSize(); | 2116 gfx::Size total_tile_size = GetTotalTileSize(); |
| 2121 gfx::Rect tile_bounds(gfx::Point(bounds.x() + col * total_tile_size.width(), | 2117 gfx::Rect tile_bounds(gfx::Point(bounds.x() + col * total_tile_size.width(), |
| 2122 bounds.y() + row * total_tile_size.height()), | 2118 bounds.y() + row * total_tile_size.height()), |
| 2123 total_tile_size); | 2119 total_tile_size); |
| 2124 tile_bounds.ClampToCenteredSize(GetTileViewSize()); | 2120 tile_bounds.ClampToCenteredSize(GetTileViewSize()); |
| 2125 return tile_bounds; | 2121 return tile_bounds; |
| 2126 } | 2122 } |
| 2127 | 2123 |
| 2128 views::View* AppsGridView::GetViewAtSlotOnCurrentPage(int slot) { | 2124 AppListItemView* AppsGridView::GetViewDisplayedAtSlotOnCurrentPage(int slot) { |
| 2129 if (slot < 0) | 2125 if (slot < 0) |
| 2130 return NULL; | 2126 return NULL; |
| 2131 | 2127 |
| 2132 // Calculate the original bound of the tile at |index|. | 2128 // Calculate the original bound of the tile at |index|. |
| 2133 int row = slot / cols_; | 2129 int row = slot / cols_; |
| 2134 int col = slot % cols_; | 2130 int col = slot % cols_; |
| 2135 gfx::Rect tile_rect = GetExpectedTileBounds(row, col); | 2131 gfx::Rect tile_rect = GetExpectedTileBounds(row, col); |
| 2136 | 2132 |
| 2137 for (int i = 0; i < view_model_.view_size(); ++i) { | 2133 for (int i = 0; i < view_model_.view_size(); ++i) { |
| 2138 views::View* view = view_model_.view_at(i); | 2134 AppListItemView* view = GetItemViewAt(i); |
| 2139 if (view->bounds() == tile_rect && view != drag_view_) | 2135 if (view->bounds() == tile_rect && view != drag_view_) |
| 2140 return view; | 2136 return view; |
| 2141 } | 2137 } |
| 2142 return NULL; | 2138 return NULL; |
| 2143 } | 2139 } |
| 2144 | 2140 |
| 2145 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, | 2141 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, |
| 2146 bool is_target_folder) { | 2142 bool is_target_folder) { |
| 2147 AppListItemView* target_view = | 2143 AppListItemView* target_view = |
| 2148 static_cast<AppListItemView*>( | 2144 GetViewDisplayedAtSlotOnCurrentPage(target_index.slot); |
| 2149 GetViewAtSlotOnCurrentPage(target_index.slot)); | |
| 2150 if (target_view) | 2145 if (target_view) |
| 2151 target_view->SetAsAttemptedFolderTarget(is_target_folder); | 2146 target_view->SetAsAttemptedFolderTarget(is_target_folder); |
| 2152 } | 2147 } |
| 2153 | 2148 |
| 2154 } // namespace app_list | 2149 } // namespace app_list |
| OLD | NEW |