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 |
11 #include "base/guid.h" | 11 #include "base/guid.h" |
12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
13 #include "ui/app_list/app_list_constants.h" | 13 #include "ui/app_list/app_list_constants.h" |
14 #include "ui/app_list/app_list_folder_item.h" | 14 #include "ui/app_list/app_list_folder_item.h" |
15 #include "ui/app_list/app_list_item.h" | 15 #include "ui/app_list/app_list_item.h" |
16 #include "ui/app_list/app_list_switches.h" | 16 #include "ui/app_list/app_list_switches.h" |
17 #include "ui/app_list/pagination_model.h" | |
18 #include "ui/app_list/views/app_list_drag_and_drop_host.h" | 17 #include "ui/app_list/views/app_list_drag_and_drop_host.h" |
19 #include "ui/app_list/views/app_list_folder_view.h" | 18 #include "ui/app_list/views/app_list_folder_view.h" |
20 #include "ui/app_list/views/app_list_item_view.h" | 19 #include "ui/app_list/views/app_list_item_view.h" |
21 #include "ui/app_list/views/apps_grid_view_delegate.h" | 20 #include "ui/app_list/views/apps_grid_view_delegate.h" |
22 #include "ui/app_list/views/page_switcher.h" | 21 #include "ui/app_list/views/page_switcher.h" |
23 #include "ui/app_list/views/pulsing_block_view.h" | 22 #include "ui/app_list/views/pulsing_block_view.h" |
24 #include "ui/app_list/views/top_icon_animation_view.h" | 23 #include "ui/app_list/views/top_icon_animation_view.h" |
25 #include "ui/compositor/scoped_layer_animation_settings.h" | 24 #include "ui/compositor/scoped_layer_animation_settings.h" |
26 #include "ui/events/event.h" | 25 #include "ui/events/event.h" |
27 #include "ui/gfx/animation/animation.h" | 26 #include "ui/gfx/animation/animation.h" |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 gfx::Point drag_view_offset_; | 327 gfx::Point drag_view_offset_; |
329 bool has_shortcut_path_; | 328 bool has_shortcut_path_; |
330 base::FilePath shortcut_path_; | 329 base::FilePath shortcut_path_; |
331 bool running_; | 330 bool running_; |
332 bool canceled_; | 331 bool canceled_; |
333 | 332 |
334 DISALLOW_COPY_AND_ASSIGN(SynchronousDrag); | 333 DISALLOW_COPY_AND_ASSIGN(SynchronousDrag); |
335 }; | 334 }; |
336 #endif // defined(OS_WIN) | 335 #endif // defined(OS_WIN) |
337 | 336 |
338 AppsGridView::AppsGridView(AppsGridViewDelegate* delegate, | 337 AppsGridView::AppsGridView(AppsGridViewDelegate* delegate) |
339 PaginationModel* pagination_model) | |
340 : model_(NULL), | 338 : model_(NULL), |
341 item_list_(NULL), | 339 item_list_(NULL), |
342 delegate_(delegate), | 340 delegate_(delegate), |
343 folder_delegate_(NULL), | 341 folder_delegate_(NULL), |
344 pagination_model_(pagination_model), | 342 page_switcher_view_(new PageSwitcher(&pagination_model_)), |
345 page_switcher_view_(new PageSwitcher(pagination_model)), | |
346 cols_(0), | 343 cols_(0), |
347 rows_per_page_(0), | 344 rows_per_page_(0), |
348 selected_view_(NULL), | 345 selected_view_(NULL), |
349 drag_view_(NULL), | 346 drag_view_(NULL), |
350 drag_start_page_(-1), | 347 drag_start_page_(-1), |
351 #if defined(OS_WIN) | 348 #if defined(OS_WIN) |
352 use_synchronous_drag_(true), | 349 use_synchronous_drag_(true), |
353 #endif | 350 #endif |
354 drag_pointer_(NONE), | 351 drag_pointer_(NONE), |
355 drop_attempt_(DROP_FOR_NONE), | 352 drop_attempt_(DROP_FOR_NONE), |
356 drag_and_drop_host_(NULL), | 353 drag_and_drop_host_(NULL), |
357 forward_events_to_drag_and_drop_host_(false), | 354 forward_events_to_drag_and_drop_host_(false), |
358 page_flip_target_(-1), | 355 page_flip_target_(-1), |
359 page_flip_delay_in_ms_(kPageFlipDelayInMs), | 356 page_flip_delay_in_ms_(kPageFlipDelayInMs), |
360 bounds_animator_(this), | 357 bounds_animator_(this), |
361 activated_folder_item_view_(NULL), | 358 activated_folder_item_view_(NULL), |
362 dragging_for_reparent_item_(false) { | 359 dragging_for_reparent_item_(false) { |
363 SetPaintToLayer(true); | 360 SetPaintToLayer(true); |
364 // Clip any icons that are outside the grid view's bounds. These icons would | 361 // Clip any icons that are outside the grid view's bounds. These icons would |
365 // otherwise be visible to the user when the grid view is off screen. | 362 // otherwise be visible to the user when the grid view is off screen. |
366 layer()->SetMasksToBounds(true); | 363 layer()->SetMasksToBounds(true); |
367 SetFillsBoundsOpaquely(false); | 364 SetFillsBoundsOpaquely(false); |
368 | 365 |
369 pagination_model_->AddObserver(this); | 366 pagination_model_.SetTransitionDurations(kPageTransitionDurationInMs, |
| 367 kOverscrollPageTransitionDurationMs); |
| 368 |
| 369 pagination_model_.AddObserver(this); |
370 AddChildView(page_switcher_view_); | 370 AddChildView(page_switcher_view_); |
371 } | 371 } |
372 | 372 |
373 AppsGridView::~AppsGridView() { | 373 AppsGridView::~AppsGridView() { |
374 // Coming here |drag_view_| should already be canceled since otherwise the | 374 // Coming here |drag_view_| should already be canceled since otherwise the |
375 // drag would disappear after the app list got animated away and closed, | 375 // drag would disappear after the app list got animated away and closed, |
376 // which would look odd. | 376 // which would look odd. |
377 DCHECK(!drag_view_); | 377 DCHECK(!drag_view_); |
378 if (drag_view_) | 378 if (drag_view_) |
379 EndDrag(true); | 379 EndDrag(true); |
380 | 380 |
381 if (model_) | 381 if (model_) |
382 model_->RemoveObserver(this); | 382 model_->RemoveObserver(this); |
383 pagination_model_->RemoveObserver(this); | 383 pagination_model_.RemoveObserver(this); |
384 | 384 |
385 if (item_list_) | 385 if (item_list_) |
386 item_list_->RemoveObserver(this); | 386 item_list_->RemoveObserver(this); |
| 387 |
| 388 // Since |pagination_model_| will be destroyed before the views, |
| 389 // |page_switcher_view_| must stop observing. (We cannot simply call |
| 390 // RemoveAllChildViews, since that will trigger a ViewHierarchyChanged which |
| 391 // should not be called during destruction.) |
| 392 page_switcher_view_->ReleasePaginationModel(); |
387 } | 393 } |
388 | 394 |
389 void AppsGridView::SetLayout(int icon_size, int cols, int rows_per_page) { | 395 void AppsGridView::SetLayout(int icon_size, int cols, int rows_per_page) { |
390 icon_size_.SetSize(icon_size, icon_size); | 396 icon_size_.SetSize(icon_size, icon_size); |
391 cols_ = cols; | 397 cols_ = cols; |
392 rows_per_page_ = rows_per_page; | 398 rows_per_page_ = rows_per_page; |
393 | 399 |
394 SetBorder(views::Border::CreateEmptyBorder( | 400 SetBorder(views::Border::CreateEmptyBorder( |
395 kTopPadding, kLeftRightPadding, 0, kLeftRightPadding)); | 401 kTopPadding, kLeftRightPadding, 0, kLeftRightPadding)); |
396 } | 402 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 selected_view_->SchedulePaint(); | 456 selected_view_->SchedulePaint(); |
451 selected_view_ = NULL; | 457 selected_view_ = NULL; |
452 } | 458 } |
453 } | 459 } |
454 | 460 |
455 bool AppsGridView::IsSelectedView(const views::View* view) const { | 461 bool AppsGridView::IsSelectedView(const views::View* view) const { |
456 return selected_view_ == view; | 462 return selected_view_ == view; |
457 } | 463 } |
458 | 464 |
459 void AppsGridView::EnsureViewVisible(const views::View* view) { | 465 void AppsGridView::EnsureViewVisible(const views::View* view) { |
460 if (pagination_model_->has_transition()) | 466 if (pagination_model_.has_transition()) |
461 return; | 467 return; |
462 | 468 |
463 Index index = GetIndexOfView(view); | 469 Index index = GetIndexOfView(view); |
464 if (IsValidIndex(index)) | 470 if (IsValidIndex(index)) |
465 pagination_model_->SelectPage(index.page, false); | 471 pagination_model_.SelectPage(index.page, false); |
466 } | 472 } |
467 | 473 |
468 void AppsGridView::InitiateDrag(AppListItemView* view, | 474 void AppsGridView::InitiateDrag(AppListItemView* view, |
469 Pointer pointer, | 475 Pointer pointer, |
470 const ui::LocatedEvent& event) { | 476 const ui::LocatedEvent& event) { |
471 DCHECK(view); | 477 DCHECK(view); |
472 if (drag_view_ || pulsing_blocks_model_.view_size()) | 478 if (drag_view_ || pulsing_blocks_model_.view_size()) |
473 return; | 479 return; |
474 | 480 |
475 drag_view_ = view; | 481 drag_view_ = view; |
476 drag_view_init_index_ = GetIndexOfView(drag_view_); | 482 drag_view_init_index_ = GetIndexOfView(drag_view_); |
477 drag_view_offset_ = event.location(); | 483 drag_view_offset_ = event.location(); |
478 drag_start_page_ = pagination_model_->selected_page(); | 484 drag_start_page_ = pagination_model_.selected_page(); |
479 ExtractDragLocation(event, &drag_start_grid_view_); | 485 ExtractDragLocation(event, &drag_start_grid_view_); |
480 drag_view_start_ = gfx::Point(drag_view_->x(), drag_view_->y()); | 486 drag_view_start_ = gfx::Point(drag_view_->x(), drag_view_->y()); |
481 } | 487 } |
482 | 488 |
483 void AppsGridView::StartSettingUpSynchronousDrag() { | 489 void AppsGridView::StartSettingUpSynchronousDrag() { |
484 #if defined(OS_WIN) | 490 #if defined(OS_WIN) |
485 if (!delegate_ || !use_synchronous_drag_) | 491 if (!delegate_ || !use_synchronous_drag_) |
486 return; | 492 return; |
487 | 493 |
488 // Folders can't be integrated with the OS. | 494 // Folders can't be integrated with the OS. |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 drag_view_->SetDragUIState(); // Hide the title of the drag_view_. | 784 drag_view_->SetDragUIState(); // Hide the title of the drag_view_. |
779 | 785 |
780 // Hide the drag_view_ for drag icon proxy. | 786 // Hide the drag_view_ for drag icon proxy. |
781 SetViewHidden(drag_view_, | 787 SetViewHidden(drag_view_, |
782 true /* hide */, | 788 true /* hide */, |
783 true /* no animate */); | 789 true /* no animate */); |
784 | 790 |
785 // Add drag_view_ to the end of the view_model_. | 791 // Add drag_view_ to the end of the view_model_. |
786 view_model_.Add(drag_view_, view_model_.view_size()); | 792 view_model_.Add(drag_view_, view_model_.view_size()); |
787 | 793 |
788 drag_start_page_ = pagination_model_->selected_page(); | 794 drag_start_page_ = pagination_model_.selected_page(); |
789 drag_start_grid_view_ = drag_point; | 795 drag_start_grid_view_ = drag_point; |
790 | 796 |
791 drag_view_start_ = gfx::Point(drag_view_->x(), drag_view_->y()); | 797 drag_view_start_ = gfx::Point(drag_view_->x(), drag_view_->y()); |
792 | 798 |
793 // Set the flag in root level grid view. | 799 // Set the flag in root level grid view. |
794 dragging_for_reparent_item_ = true; | 800 dragging_for_reparent_item_ = true; |
795 } | 801 } |
796 | 802 |
797 void AppsGridView::UpdateDragFromReparentItem(Pointer pointer, | 803 void AppsGridView::UpdateDragFromReparentItem(Pointer pointer, |
798 const gfx::Point& drag_point) { | 804 const gfx::Point& drag_point) { |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 UpdatePulsingBlockViews(); | 981 UpdatePulsingBlockViews(); |
976 Layout(); | 982 Layout(); |
977 SchedulePaint(); | 983 SchedulePaint(); |
978 } | 984 } |
979 | 985 |
980 void AppsGridView::UpdatePaging() { | 986 void AppsGridView::UpdatePaging() { |
981 int total_page = view_model_.view_size() && tiles_per_page() | 987 int total_page = view_model_.view_size() && tiles_per_page() |
982 ? (view_model_.view_size() - 1) / tiles_per_page() + 1 | 988 ? (view_model_.view_size() - 1) / tiles_per_page() + 1 |
983 : 0; | 989 : 0; |
984 | 990 |
985 pagination_model_->SetTotalPages(total_page); | 991 pagination_model_.SetTotalPages(total_page); |
986 } | 992 } |
987 | 993 |
988 void AppsGridView::UpdatePulsingBlockViews() { | 994 void AppsGridView::UpdatePulsingBlockViews() { |
989 const int existing_items = item_list_ ? item_list_->item_count() : 0; | 995 const int existing_items = item_list_ ? item_list_->item_count() : 0; |
990 const int available_slots = | 996 const int available_slots = |
991 tiles_per_page() - existing_items % tiles_per_page(); | 997 tiles_per_page() - existing_items % tiles_per_page(); |
992 const int desired = model_->status() == AppListModel::STATUS_SYNCING ? | 998 const int desired = model_->status() == AppListModel::STATUS_SYNCING ? |
993 available_slots : 0; | 999 available_slots : 0; |
994 | 1000 |
995 if (pulsing_blocks_model_.view_size() == desired) | 1001 if (pulsing_blocks_model_.view_size() == desired) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 selected_view_->SchedulePaint(); | 1050 selected_view_->SchedulePaint(); |
1045 | 1051 |
1046 EnsureViewVisible(new_selection); | 1052 EnsureViewVisible(new_selection); |
1047 selected_view_ = new_selection; | 1053 selected_view_ = new_selection; |
1048 selected_view_->SchedulePaint(); | 1054 selected_view_->SchedulePaint(); |
1049 selected_view_->NotifyAccessibilityEvent( | 1055 selected_view_->NotifyAccessibilityEvent( |
1050 ui::AX_EVENT_FOCUS, true); | 1056 ui::AX_EVENT_FOCUS, true); |
1051 } | 1057 } |
1052 | 1058 |
1053 bool AppsGridView::IsValidIndex(const Index& index) const { | 1059 bool AppsGridView::IsValidIndex(const Index& index) const { |
1054 return index.page >= 0 && index.page < pagination_model_->total_pages() && | 1060 return index.page >= 0 && index.page < pagination_model_.total_pages() && |
1055 index.slot >= 0 && index.slot < tiles_per_page() && | 1061 index.slot >= 0 && index.slot < tiles_per_page() && |
1056 GetModelIndexFromIndex(index) < view_model_.view_size(); | 1062 GetModelIndexFromIndex(index) < view_model_.view_size(); |
1057 } | 1063 } |
1058 | 1064 |
1059 AppsGridView::Index AppsGridView::GetIndexOfView( | 1065 AppsGridView::Index AppsGridView::GetIndexOfView( |
1060 const views::View* view) const { | 1066 const views::View* view) const { |
1061 const int model_index = view_model_.GetIndexOfView(view); | 1067 const int model_index = view_model_.GetIndexOfView(view); |
1062 if (model_index == -1) | 1068 if (model_index == -1) |
1063 return Index(); | 1069 return Index(); |
1064 | 1070 |
1065 return GetIndexFromModelIndex(model_index); | 1071 return GetIndexFromModelIndex(model_index); |
1066 } | 1072 } |
1067 | 1073 |
1068 views::View* AppsGridView::GetViewAtIndex(const Index& index) const { | 1074 views::View* AppsGridView::GetViewAtIndex(const Index& index) const { |
1069 if (!IsValidIndex(index)) | 1075 if (!IsValidIndex(index)) |
1070 return NULL; | 1076 return NULL; |
1071 | 1077 |
1072 const int model_index = GetModelIndexFromIndex(index); | 1078 const int model_index = GetModelIndexFromIndex(index); |
1073 return view_model_.view_at(model_index); | 1079 return view_model_.view_at(model_index); |
1074 } | 1080 } |
1075 | 1081 |
1076 void AppsGridView::MoveSelected(int page_delta, | 1082 void AppsGridView::MoveSelected(int page_delta, |
1077 int slot_x_delta, | 1083 int slot_x_delta, |
1078 int slot_y_delta) { | 1084 int slot_y_delta) { |
1079 if (!selected_view_) | 1085 if (!selected_view_) |
1080 return SetSelectedItemByIndex(Index(pagination_model_->selected_page(), 0)); | 1086 return SetSelectedItemByIndex(Index(pagination_model_.selected_page(), 0)); |
1081 | 1087 |
1082 const Index& selected = GetIndexOfView(selected_view_); | 1088 const Index& selected = GetIndexOfView(selected_view_); |
1083 int target_slot = selected.slot + slot_x_delta + slot_y_delta * cols_; | 1089 int target_slot = selected.slot + slot_x_delta + slot_y_delta * cols_; |
1084 | 1090 |
1085 if (selected.slot % cols_ == 0 && slot_x_delta == -1) { | 1091 if (selected.slot % cols_ == 0 && slot_x_delta == -1) { |
1086 if (selected.page > 0) { | 1092 if (selected.page > 0) { |
1087 page_delta = -1; | 1093 page_delta = -1; |
1088 target_slot = selected.slot + cols_ - 1; | 1094 target_slot = selected.slot + cols_ - 1; |
1089 } else { | 1095 } else { |
1090 target_slot = selected.slot; | 1096 target_slot = selected.slot; |
1091 } | 1097 } |
1092 } | 1098 } |
1093 | 1099 |
1094 if (selected.slot % cols_ == cols_ - 1 && slot_x_delta == 1) { | 1100 if (selected.slot % cols_ == cols_ - 1 && slot_x_delta == 1) { |
1095 if (selected.page < pagination_model_->total_pages() - 1) { | 1101 if (selected.page < pagination_model_.total_pages() - 1) { |
1096 page_delta = 1; | 1102 page_delta = 1; |
1097 target_slot = selected.slot - cols_ + 1; | 1103 target_slot = selected.slot - cols_ + 1; |
1098 } else { | 1104 } else { |
1099 target_slot = selected.slot; | 1105 target_slot = selected.slot; |
1100 } | 1106 } |
1101 } | 1107 } |
1102 | 1108 |
1103 // Clamp the target slot to the last item if we are moving to the last page | 1109 // Clamp the target slot to the last item if we are moving to the last page |
1104 // but our target slot is past the end of the item list. | 1110 // but our target slot is past the end of the item list. |
1105 if (page_delta && | 1111 if (page_delta && |
1106 selected.page + page_delta == pagination_model_->total_pages() - 1) { | 1112 selected.page + page_delta == pagination_model_.total_pages() - 1) { |
1107 int last_item_slot = (view_model_.view_size() - 1) % tiles_per_page(); | 1113 int last_item_slot = (view_model_.view_size() - 1) % tiles_per_page(); |
1108 if (last_item_slot < target_slot) { | 1114 if (last_item_slot < target_slot) { |
1109 target_slot = last_item_slot; | 1115 target_slot = last_item_slot; |
1110 } | 1116 } |
1111 } | 1117 } |
1112 | 1118 |
1113 int target_page = std::min(pagination_model_->total_pages() - 1, | 1119 int target_page = std::min(pagination_model_.total_pages() - 1, |
1114 std::max(selected.page + page_delta, 0)); | 1120 std::max(selected.page + page_delta, 0)); |
1115 SetSelectedItemByIndex(Index(target_page, target_slot)); | 1121 SetSelectedItemByIndex(Index(target_page, target_slot)); |
1116 } | 1122 } |
1117 | 1123 |
1118 void AppsGridView::CalculateIdealBounds() { | 1124 void AppsGridView::CalculateIdealBounds() { |
1119 gfx::Rect rect(GetContentsBounds()); | 1125 gfx::Rect rect(GetContentsBounds()); |
1120 if (rect.IsEmpty()) | 1126 if (rect.IsEmpty()) |
1121 return; | 1127 return; |
1122 | 1128 |
1123 gfx::Size tile_size(kPreferredTileWidth, kPreferredTileHeight); | 1129 gfx::Size tile_size(kPreferredTileWidth, kPreferredTileHeight); |
1124 | 1130 |
1125 gfx::Rect grid_rect(gfx::Size(tile_size.width() * cols_, | 1131 gfx::Rect grid_rect(gfx::Size(tile_size.width() * cols_, |
1126 tile_size.height() * rows_per_page_)); | 1132 tile_size.height() * rows_per_page_)); |
1127 grid_rect.Intersect(rect); | 1133 grid_rect.Intersect(rect); |
1128 | 1134 |
1129 // Page width including padding pixels. A tile.x + page_width means the same | 1135 // Page width including padding pixels. A tile.x + page_width means the same |
1130 // tile slot in the next page. | 1136 // tile slot in the next page. |
1131 const int page_width = grid_rect.width() + kPagePadding; | 1137 const int page_width = grid_rect.width() + kPagePadding; |
1132 | 1138 |
1133 // If there is a transition, calculates offset for current and target page. | 1139 // If there is a transition, calculates offset for current and target page. |
1134 const int current_page = pagination_model_->selected_page(); | 1140 const int current_page = pagination_model_.selected_page(); |
1135 const PaginationModel::Transition& transition = | 1141 const PaginationModel::Transition& transition = |
1136 pagination_model_->transition(); | 1142 pagination_model_.transition(); |
1137 const bool is_valid = | 1143 const bool is_valid = pagination_model_.is_valid_page(transition.target_page); |
1138 pagination_model_->is_valid_page(transition.target_page); | |
1139 | 1144 |
1140 // Transition to right means negative offset. | 1145 // Transition to right means negative offset. |
1141 const int dir = transition.target_page > current_page ? -1 : 1; | 1146 const int dir = transition.target_page > current_page ? -1 : 1; |
1142 const int transition_offset = is_valid ? | 1147 const int transition_offset = is_valid ? |
1143 transition.progress * page_width * dir : 0; | 1148 transition.progress * page_width * dir : 0; |
1144 | 1149 |
1145 const int total_views = | 1150 const int total_views = |
1146 view_model_.view_size() + pulsing_blocks_model_.view_size(); | 1151 view_model_.view_size() + pulsing_blocks_model_.view_size(); |
1147 int slot_index = 0; | 1152 int slot_index = 0; |
1148 for (int i = 0; i < total_views; ++i) { | 1153 for (int i = 0; i < total_views; ++i) { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1299 #endif | 1304 #endif |
1300 } | 1305 } |
1301 | 1306 |
1302 void AppsGridView::CalculateDropTarget(const gfx::Point& drag_point, | 1307 void AppsGridView::CalculateDropTarget(const gfx::Point& drag_point, |
1303 bool use_page_button_hovering) { | 1308 bool use_page_button_hovering) { |
1304 if (EnableFolderDragDropUI()) { | 1309 if (EnableFolderDragDropUI()) { |
1305 CalculateDropTargetWithFolderEnabled(drag_point, use_page_button_hovering); | 1310 CalculateDropTargetWithFolderEnabled(drag_point, use_page_button_hovering); |
1306 return; | 1311 return; |
1307 } | 1312 } |
1308 | 1313 |
1309 int current_page = pagination_model_->selected_page(); | 1314 int current_page = pagination_model_.selected_page(); |
1310 gfx::Point point(drag_point); | 1315 gfx::Point point(drag_point); |
1311 if (!IsPointWithinDragBuffer(drag_point)) { | 1316 if (!IsPointWithinDragBuffer(drag_point)) { |
1312 point = drag_start_grid_view_; | 1317 point = drag_start_grid_view_; |
1313 current_page = drag_start_page_; | 1318 current_page = drag_start_page_; |
1314 } | 1319 } |
1315 | 1320 |
1316 if (use_page_button_hovering && | 1321 if (use_page_button_hovering && |
1317 page_switcher_view_->bounds().Contains(point)) { | 1322 page_switcher_view_->bounds().Contains(point)) { |
1318 gfx::Point page_switcher_point(point); | 1323 gfx::Point page_switcher_point(point); |
1319 views::View::ConvertPointToTarget(this, page_switcher_view_, | 1324 views::View::ConvertPointToTarget(this, page_switcher_view_, |
1320 &page_switcher_point); | 1325 &page_switcher_point); |
1321 int page = page_switcher_view_->GetPageForPoint(page_switcher_point); | 1326 int page = page_switcher_view_->GetPageForPoint(page_switcher_point); |
1322 if (pagination_model_->is_valid_page(page)) { | 1327 if (pagination_model_.is_valid_page(page)) { |
1323 drop_target_.page = page; | 1328 drop_target_.page = page; |
1324 drop_target_.slot = tiles_per_page() - 1; | 1329 drop_target_.slot = tiles_per_page() - 1; |
1325 } | 1330 } |
1326 } else { | 1331 } else { |
1327 gfx::Rect bounds(GetContentsBounds()); | 1332 gfx::Rect bounds(GetContentsBounds()); |
1328 const int drop_row = (point.y() - bounds.y()) / kPreferredTileHeight; | 1333 const int drop_row = (point.y() - bounds.y()) / kPreferredTileHeight; |
1329 const int drop_col = std::min(cols_ - 1, | 1334 const int drop_col = std::min(cols_ - 1, |
1330 (point.x() - bounds.x()) / kPreferredTileWidth); | 1335 (point.x() - bounds.x()) / kPreferredTileWidth); |
1331 | 1336 |
1332 drop_target_.page = current_page; | 1337 drop_target_.page = current_page; |
1333 drop_target_.slot = std::max(0, std::min( | 1338 drop_target_.slot = std::max(0, std::min( |
1334 tiles_per_page() - 1, | 1339 tiles_per_page() - 1, |
1335 drop_row * cols_ + drop_col)); | 1340 drop_row * cols_ + drop_col)); |
1336 } | 1341 } |
1337 | 1342 |
1338 // Limits to the last possible slot on last page. | 1343 // Limits to the last possible slot on last page. |
1339 if (drop_target_.page == pagination_model_->total_pages() - 1) { | 1344 if (drop_target_.page == pagination_model_.total_pages() - 1) { |
1340 drop_target_.slot = std::min( | 1345 drop_target_.slot = std::min( |
1341 (view_model_.view_size() - 1) % tiles_per_page(), | 1346 (view_model_.view_size() - 1) % tiles_per_page(), |
1342 drop_target_.slot); | 1347 drop_target_.slot); |
1343 } | 1348 } |
1344 } | 1349 } |
1345 | 1350 |
1346 | 1351 |
1347 void AppsGridView::CalculateDropTargetWithFolderEnabled( | 1352 void AppsGridView::CalculateDropTargetWithFolderEnabled( |
1348 const gfx::Point& drag_point, | 1353 const gfx::Point& drag_point, |
1349 bool use_page_button_hovering) { | 1354 bool use_page_button_hovering) { |
1350 gfx::Point point(drag_point); | 1355 gfx::Point point(drag_point); |
1351 if (!IsPointWithinDragBuffer(drag_point)) { | 1356 if (!IsPointWithinDragBuffer(drag_point)) { |
1352 point = drag_start_grid_view_; | 1357 point = drag_start_grid_view_; |
1353 } | 1358 } |
1354 | 1359 |
1355 if (use_page_button_hovering && | 1360 if (use_page_button_hovering && |
1356 page_switcher_view_->bounds().Contains(point)) { | 1361 page_switcher_view_->bounds().Contains(point)) { |
1357 gfx::Point page_switcher_point(point); | 1362 gfx::Point page_switcher_point(point); |
1358 views::View::ConvertPointToTarget(this, page_switcher_view_, | 1363 views::View::ConvertPointToTarget(this, page_switcher_view_, |
1359 &page_switcher_point); | 1364 &page_switcher_point); |
1360 int page = page_switcher_view_->GetPageForPoint(page_switcher_point); | 1365 int page = page_switcher_view_->GetPageForPoint(page_switcher_point); |
1361 if (pagination_model_->is_valid_page(page)) | 1366 if (pagination_model_.is_valid_page(page)) |
1362 drop_attempt_ = DROP_FOR_NONE; | 1367 drop_attempt_ = DROP_FOR_NONE; |
1363 } else { | 1368 } else { |
1364 DCHECK(drag_view_); | 1369 DCHECK(drag_view_); |
1365 // Try to find the nearest target for folder dropping or re-ordering. | 1370 // Try to find the nearest target for folder dropping or re-ordering. |
1366 drop_target_ = GetNearestTileForDragView(); | 1371 drop_target_ = GetNearestTileForDragView(); |
1367 } | 1372 } |
1368 } | 1373 } |
1369 | 1374 |
1370 void AppsGridView::OnReorderTimer() { | 1375 void AppsGridView::OnReorderTimer() { |
1371 if (drop_attempt_ == DROP_FOR_REORDER) | 1376 if (drop_attempt_ == DROP_FOR_REORDER) |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 if (page_switcher_view_->bounds().Contains(drag_point)) { | 1601 if (page_switcher_view_->bounds().Contains(drag_point)) { |
1597 gfx::Point page_switcher_point(drag_point); | 1602 gfx::Point page_switcher_point(drag_point); |
1598 views::View::ConvertPointToTarget(this, page_switcher_view_, | 1603 views::View::ConvertPointToTarget(this, page_switcher_view_, |
1599 &page_switcher_point); | 1604 &page_switcher_point); |
1600 new_page_flip_target = | 1605 new_page_flip_target = |
1601 page_switcher_view_->GetPageForPoint(page_switcher_point); | 1606 page_switcher_view_->GetPageForPoint(page_switcher_point); |
1602 } | 1607 } |
1603 | 1608 |
1604 // TODO(xiyuan): Fix this for RTL. | 1609 // TODO(xiyuan): Fix this for RTL. |
1605 if (new_page_flip_target == -1 && drag_point.x() < kPageFlipZoneSize) | 1610 if (new_page_flip_target == -1 && drag_point.x() < kPageFlipZoneSize) |
1606 new_page_flip_target = pagination_model_->selected_page() - 1; | 1611 new_page_flip_target = pagination_model_.selected_page() - 1; |
1607 | 1612 |
1608 if (new_page_flip_target == -1 && | 1613 if (new_page_flip_target == -1 && |
1609 drag_point.x() > width() - kPageFlipZoneSize) { | 1614 drag_point.x() > width() - kPageFlipZoneSize) { |
1610 new_page_flip_target = pagination_model_->selected_page() + 1; | 1615 new_page_flip_target = pagination_model_.selected_page() + 1; |
1611 } | 1616 } |
1612 | 1617 |
1613 if (new_page_flip_target == page_flip_target_) | 1618 if (new_page_flip_target == page_flip_target_) |
1614 return; | 1619 return; |
1615 | 1620 |
1616 StopPageFlipTimer(); | 1621 StopPageFlipTimer(); |
1617 if (pagination_model_->is_valid_page(new_page_flip_target)) { | 1622 if (pagination_model_.is_valid_page(new_page_flip_target)) { |
1618 page_flip_target_ = new_page_flip_target; | 1623 page_flip_target_ = new_page_flip_target; |
1619 | 1624 |
1620 if (page_flip_target_ != pagination_model_->selected_page()) { | 1625 if (page_flip_target_ != pagination_model_.selected_page()) { |
1621 page_flip_timer_.Start(FROM_HERE, | 1626 page_flip_timer_.Start(FROM_HERE, |
1622 base::TimeDelta::FromMilliseconds(page_flip_delay_in_ms_), | 1627 base::TimeDelta::FromMilliseconds(page_flip_delay_in_ms_), |
1623 this, &AppsGridView::OnPageFlipTimer); | 1628 this, &AppsGridView::OnPageFlipTimer); |
1624 } | 1629 } |
1625 } | 1630 } |
1626 } | 1631 } |
1627 | 1632 |
1628 void AppsGridView::OnPageFlipTimer() { | 1633 void AppsGridView::OnPageFlipTimer() { |
1629 DCHECK(pagination_model_->is_valid_page(page_flip_target_)); | 1634 DCHECK(pagination_model_.is_valid_page(page_flip_target_)); |
1630 pagination_model_->SelectPage(page_flip_target_, true); | 1635 pagination_model_.SelectPage(page_flip_target_, true); |
1631 } | 1636 } |
1632 | 1637 |
1633 void AppsGridView::MoveItemInModel(views::View* item_view, | 1638 void AppsGridView::MoveItemInModel(views::View* item_view, |
1634 const Index& target) { | 1639 const Index& target) { |
1635 int current_model_index = view_model_.GetIndexOfView(item_view); | 1640 int current_model_index = view_model_.GetIndexOfView(item_view); |
1636 DCHECK_GE(current_model_index, 0); | 1641 DCHECK_GE(current_model_index, 0); |
1637 | 1642 |
1638 int target_model_index = GetModelIndexFromIndex(target); | 1643 int target_model_index = GetModelIndexFromIndex(target); |
1639 if (target_model_index == current_model_index) | 1644 if (target_model_index == current_model_index) |
1640 return; | 1645 return; |
1641 | 1646 |
1642 item_list_->RemoveObserver(this); | 1647 item_list_->RemoveObserver(this); |
1643 item_list_->MoveItem(current_model_index, target_model_index); | 1648 item_list_->MoveItem(current_model_index, target_model_index); |
1644 view_model_.Move(current_model_index, target_model_index); | 1649 view_model_.Move(current_model_index, target_model_index); |
1645 item_list_->AddObserver(this); | 1650 item_list_->AddObserver(this); |
1646 | 1651 |
1647 if (pagination_model_->selected_page() != target.page) | 1652 if (pagination_model_.selected_page() != target.page) |
1648 pagination_model_->SelectPage(target.page, false); | 1653 pagination_model_.SelectPage(target.page, false); |
1649 } | 1654 } |
1650 | 1655 |
1651 void AppsGridView::MoveItemToFolder(views::View* item_view, | 1656 void AppsGridView::MoveItemToFolder(views::View* item_view, |
1652 const Index& target) { | 1657 const Index& target) { |
1653 const std::string& source_item_id = | 1658 const std::string& source_item_id = |
1654 static_cast<AppListItemView*>(item_view)->item()->id(); | 1659 static_cast<AppListItemView*>(item_view)->item()->id(); |
1655 AppListItemView* target_view = | 1660 AppListItemView* target_view = |
1656 static_cast<AppListItemView*>(GetViewAtSlotOnCurrentPage(target.slot)); | 1661 static_cast<AppListItemView*>(GetViewAtSlotOnCurrentPage(target.slot)); |
1657 const std::string& target_view_item_id = target_view->item()->id(); | 1662 const std::string& target_view_item_id = target_view->item()->id(); |
1658 | 1663 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1846 TopIconAnimationView* icon_view = new TopIconAnimationView( | 1851 TopIconAnimationView* icon_view = new TopIconAnimationView( |
1847 drag_item_view->item()->icon(), | 1852 drag_item_view->item()->icon(), |
1848 target_icon_rect, | 1853 target_icon_rect, |
1849 false); /* animate like closing folder */ | 1854 false); /* animate like closing folder */ |
1850 AddChildView(icon_view); | 1855 AddChildView(icon_view); |
1851 icon_view->SetBoundsRect(drag_view_icon_to_grid); | 1856 icon_view->SetBoundsRect(drag_view_icon_to_grid); |
1852 icon_view->TransformView(); | 1857 icon_view->TransformView(); |
1853 } | 1858 } |
1854 | 1859 |
1855 void AppsGridView::CancelContextMenusOnCurrentPage() { | 1860 void AppsGridView::CancelContextMenusOnCurrentPage() { |
1856 int start = pagination_model_->selected_page() * tiles_per_page(); | 1861 int start = pagination_model_.selected_page() * tiles_per_page(); |
1857 int end = std::min(view_model_.view_size(), start + tiles_per_page()); | 1862 int end = std::min(view_model_.view_size(), start + tiles_per_page()); |
1858 for (int i = start; i < end; ++i) { | 1863 for (int i = start; i < end; ++i) { |
1859 AppListItemView* view = | 1864 AppListItemView* view = |
1860 static_cast<AppListItemView*>(view_model_.view_at(i)); | 1865 static_cast<AppListItemView*>(view_model_.view_at(i)); |
1861 view->CancelContextMenu(); | 1866 view->CancelContextMenu(); |
1862 } | 1867 } |
1863 } | 1868 } |
1864 | 1869 |
1865 void AppsGridView::DeleteItemViewAtIndex(int index) { | 1870 void AppsGridView::DeleteItemViewAtIndex(int index) { |
1866 views::View* item_view = view_model_.view_at(index); | 1871 views::View* item_view = view_model_.view_at(index); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1953 } | 1958 } |
1954 | 1959 |
1955 void AppsGridView::TransitionStarted() { | 1960 void AppsGridView::TransitionStarted() { |
1956 CancelContextMenusOnCurrentPage(); | 1961 CancelContextMenusOnCurrentPage(); |
1957 } | 1962 } |
1958 | 1963 |
1959 void AppsGridView::TransitionChanged() { | 1964 void AppsGridView::TransitionChanged() { |
1960 // Update layout for valid page transition only since over-scroll no longer | 1965 // Update layout for valid page transition only since over-scroll no longer |
1961 // animates app icons. | 1966 // animates app icons. |
1962 const PaginationModel::Transition& transition = | 1967 const PaginationModel::Transition& transition = |
1963 pagination_model_->transition(); | 1968 pagination_model_.transition(); |
1964 if (pagination_model_->is_valid_page(transition.target_page)) | 1969 if (pagination_model_.is_valid_page(transition.target_page)) |
1965 Layout(); | 1970 Layout(); |
1966 } | 1971 } |
1967 | 1972 |
1968 void AppsGridView::OnAppListModelStatusChanged() { | 1973 void AppsGridView::OnAppListModelStatusChanged() { |
1969 UpdatePulsingBlockViews(); | 1974 UpdatePulsingBlockViews(); |
1970 Layout(); | 1975 Layout(); |
1971 SchedulePaint(); | 1976 SchedulePaint(); |
1972 } | 1977 } |
1973 | 1978 |
1974 void AppsGridView::SetViewHidden(views::View* view, bool hide, bool immediate) { | 1979 void AppsGridView::SetViewHidden(views::View* view, bool hide, bool immediate) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2115 return gfx::Rect(); | 2120 return gfx::Rect(); |
2116 | 2121 |
2117 // Calculate which tile |point| is enclosed in. | 2122 // Calculate which tile |point| is enclosed in. |
2118 int x = point.x(); | 2123 int x = point.x(); |
2119 int y = point.y(); | 2124 int y = point.y(); |
2120 int col = (x - bounds.x()) / kPreferredTileWidth; | 2125 int col = (x - bounds.x()) / kPreferredTileWidth; |
2121 int row = (y - bounds.y()) / kPreferredTileHeight; | 2126 int row = (y - bounds.y()) / kPreferredTileHeight; |
2122 gfx::Rect tile_rect = GetTileBounds(row, col); | 2127 gfx::Rect tile_rect = GetTileBounds(row, col); |
2123 | 2128 |
2124 // Check if |point| is outside a valid item's tile. | 2129 // Check if |point| is outside a valid item's tile. |
2125 Index index(pagination_model_->selected_page(), row * cols_ + col); | 2130 Index index(pagination_model_.selected_page(), row * cols_ + col); |
2126 *tile_index = index; | 2131 *tile_index = index; |
2127 return tile_rect; | 2132 return tile_rect; |
2128 } | 2133 } |
2129 | 2134 |
2130 gfx::Rect AppsGridView::GetTileBounds(int row, int col) const { | 2135 gfx::Rect AppsGridView::GetTileBounds(int row, int col) const { |
2131 gfx::Rect bounds(GetContentsBounds()); | 2136 gfx::Rect bounds(GetContentsBounds()); |
2132 gfx::Size tile_size(kPreferredTileWidth, kPreferredTileHeight); | 2137 gfx::Size tile_size(kPreferredTileWidth, kPreferredTileHeight); |
2133 gfx::Rect grid_rect(gfx::Size(tile_size.width() * cols_, | 2138 gfx::Rect grid_rect(gfx::Size(tile_size.width() * cols_, |
2134 tile_size.height() * rows_per_page_)); | 2139 tile_size.height() * rows_per_page_)); |
2135 grid_rect.Intersect(bounds); | 2140 grid_rect.Intersect(bounds); |
2136 gfx::Rect tile_rect( | 2141 gfx::Rect tile_rect( |
2137 gfx::Point(grid_rect.x() + col * tile_size.width(), | 2142 gfx::Point(grid_rect.x() + col * tile_size.width(), |
2138 grid_rect.y() + row * tile_size.height()), | 2143 grid_rect.y() + row * tile_size.height()), |
2139 tile_size); | 2144 tile_size); |
2140 return tile_rect; | 2145 return tile_rect; |
2141 } | 2146 } |
2142 | 2147 |
2143 bool AppsGridView::IsLastPossibleDropTarget(const Index& index) const { | 2148 bool AppsGridView::IsLastPossibleDropTarget(const Index& index) const { |
2144 int last_possible_slot = view_model_.view_size() % tiles_per_page(); | 2149 int last_possible_slot = view_model_.view_size() % tiles_per_page(); |
2145 return (index.page == pagination_model_->total_pages() - 1 && | 2150 return (index.page == pagination_model_.total_pages() - 1 && |
2146 index.slot == last_possible_slot + 1); | 2151 index.slot == last_possible_slot + 1); |
2147 } | 2152 } |
2148 | 2153 |
2149 views::View* AppsGridView::GetViewAtSlotOnCurrentPage(int slot) { | 2154 views::View* AppsGridView::GetViewAtSlotOnCurrentPage(int slot) { |
2150 if (slot < 0) | 2155 if (slot < 0) |
2151 return NULL; | 2156 return NULL; |
2152 | 2157 |
2153 // Calculate the original bound of the tile at |index|. | 2158 // Calculate the original bound of the tile at |index|. |
2154 int row = slot / cols_; | 2159 int row = slot / cols_; |
2155 int col = slot % cols_; | 2160 int col = slot % cols_; |
(...skipping 10 matching lines...) Expand all Loading... |
2166 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, | 2171 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, |
2167 bool is_target_folder) { | 2172 bool is_target_folder) { |
2168 AppListItemView* target_view = | 2173 AppListItemView* target_view = |
2169 static_cast<AppListItemView*>( | 2174 static_cast<AppListItemView*>( |
2170 GetViewAtSlotOnCurrentPage(target_index.slot)); | 2175 GetViewAtSlotOnCurrentPage(target_index.slot)); |
2171 if (target_view) | 2176 if (target_view) |
2172 target_view->SetAsAttemptedFolderTarget(is_target_folder); | 2177 target_view->SetAsAttemptedFolderTarget(is_target_folder); |
2173 } | 2178 } |
2174 | 2179 |
2175 } // namespace app_list | 2180 } // namespace app_list |
OLD | NEW |