Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: ui/app_list/views/apps_grid_view.cc

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

Powered by Google App Engine
This is Rietveld 408576698