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
3 // found in the LICENSE file.
5 #include "ui/app_list/views/apps_grid_view.h"
11 #include "base/guid.h"
12 #include "ui/app_list/app_list_constants.h"
13 #include "ui/app_list/app_list_folder_item.h"
14 #include "ui/app_list/app_list_item.h"
15 #include "ui/app_list/app_list_switches.h"
16 #include "ui/app_list/pagination_controller.h"
17 #include "ui/app_list/views/app_list_drag_and_drop_host.h"
18 #include "ui/app_list/views/app_list_folder_view.h"
19 #include "ui/app_list/views/app_list_item_view.h"
20 #include "ui/app_list/views/apps_grid_view_delegate.h"
21 #include "ui/app_list/views/page_switcher.h"
22 #include "ui/app_list/views/pulsing_block_view.h"
23 #include "ui/app_list/views/top_icon_animation_view.h"
24 #include "ui/compositor/scoped_layer_animation_settings.h"
25 #include "ui/events/event.h"
26 #include "ui/gfx/animation/animation.h"
27 #include "ui/gfx/geometry/vector2d.h"
28 #include "ui/gfx/geometry/vector2d_conversions.h"
29 #include "ui/views/border.h"
30 #include "ui/views/view_model_utils.h"
31 #include "ui/views/widget/widget.h"
34 #include "ui/aura/window.h"
35 #include "ui/aura/window_event_dispatcher.h"
37 #include "ui/views/win/hwnd_util.h"
38 #endif // defined(OS_WIN)
39 #endif // defined(USE_AURA)
42 #include "base/command_line.h"
43 #include "base/files/file_path.h"
44 #include "base/win/shortcut.h"
45 #include "ui/base/dragdrop/drag_utils.h"
46 #include "ui/base/dragdrop/drop_target_win.h"
47 #include "ui/base/dragdrop/os_exchange_data.h"
48 #include "ui/base/dragdrop/os_exchange_data_provider_win.h"
49 #include "ui/gfx/win/dpi.h"
56 // Distance a drag needs to be from the app grid to be considered 'outside', at
57 // which point we rearrange the apps to their pre-drag configuration, as a drop
58 // then would be canceled. We have a buffer to make it easier to drag apps to
60 const int kDragBufferPx = 20;
62 // Padding space in pixels for fixed layout.
63 const int kLeftRightPadding = 23;
64 const int kTopPadding = 1;
66 // Padding space in pixels between pages.
67 const int kPagePadding = 40;
69 // Preferred tile size when showing in fixed layout.
70 const int kPreferredTileWidth = 88;
71 const int kPreferredTileHeight = 98;
73 const int kExperimentalPreferredTileWidth = 90;
74 const int kExperimentalPrefferedTileHeight = 90;
76 // Padding on each side of a tile.
77 const int kExperimentalTileLeftRightPadding = 15;
78 const int kExperimentalTileTopBottomPadding = 11;
80 // Width in pixels of the area on the sides that triggers a page flip.
81 const int kPageFlipZoneSize = 40;
83 // Delay in milliseconds to do the page flip.
84 const int kPageFlipDelayInMs = 1000;
86 // How many pages on either side of the selected one we prerender.
87 const int kPrerenderPages = 1;
89 // The drag and drop proxy should get scaled by this factor.
90 const float kDragAndDropProxyScale = 1.5f;
92 // Delays in milliseconds to show folder dropping preview circle.
93 const int kFolderDroppingDelay = 150;
95 // Delays in milliseconds to show re-order preview.
96 const int kReorderDelay = 120;
98 // Delays in milliseconds to show folder item reparent UI.
99 const int kFolderItemReparentDelay = 50;
101 // Radius of the circle, in which if entered, show folder dropping preview
103 const int kFolderDroppingCircleRadius = 39;
105 // Returns the size of a tile view excluding its padding.
106 gfx::Size GetTileViewSize() {
107 return switches::IsExperimentalAppListEnabled()
108 ? gfx::Size(kExperimentalPreferredTileWidth,
109 kExperimentalPrefferedTileHeight)
110 : gfx::Size(kPreferredTileWidth, kPreferredTileHeight);
113 // Returns the size of a tile view inccluding its padding.
114 gfx::Size GetTotalTileSize() {
115 gfx::Size size = GetTileViewSize();
116 if (switches::IsExperimentalAppListEnabled())
117 size.Enlarge(2 * kExperimentalTileLeftRightPadding,
118 2 * kExperimentalTileTopBottomPadding);
122 // RowMoveAnimationDelegate is used when moving an item into a different row.
123 // Before running the animation, the item's layer is re-created and kept in
124 // the original position, then the item is moved to just before its target
125 // position and opacity set to 0. When the animation runs, this delegate moves
126 // the layer and fades it out while fading in the item at the same time.
127 class RowMoveAnimationDelegate : public gfx::AnimationDelegate {
129 RowMoveAnimationDelegate(views::View* view,
131 const gfx::Rect& layer_target)
134 layer_start_(layer ? layer->bounds() : gfx::Rect()),
135 layer_target_(layer_target) {
137 virtual ~RowMoveAnimationDelegate() {}
139 // gfx::AnimationDelegate overrides:
140 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE {
141 view_->layer()->SetOpacity(animation->GetCurrentValue());
142 view_->layer()->ScheduleDraw();
145 layer_->SetOpacity(1 - animation->GetCurrentValue());
146 layer_->SetBounds(animation->CurrentValueBetween(layer_start_,
148 layer_->ScheduleDraw();
151 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE {
152 view_->layer()->SetOpacity(1.0f);
153 view_->SchedulePaint();
155 virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE {
156 view_->layer()->SetOpacity(1.0f);
157 view_->SchedulePaint();
161 // The view that needs to be wrapped. Owned by views hierarchy.
164 scoped_ptr<ui::Layer> layer_;
165 const gfx::Rect layer_start_;
166 const gfx::Rect layer_target_;
168 DISALLOW_COPY_AND_ASSIGN(RowMoveAnimationDelegate);
171 // ItemRemoveAnimationDelegate is used to show animation for removing an item.
172 // This happens when user drags an item into a folder. The dragged item will
173 // be removed from the original list after it is dropped into the folder.
174 class ItemRemoveAnimationDelegate : public gfx::AnimationDelegate {
176 explicit ItemRemoveAnimationDelegate(views::View* view)
180 virtual ~ItemRemoveAnimationDelegate() {
183 // gfx::AnimationDelegate overrides:
184 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE {
185 view_->layer()->SetOpacity(1 - animation->GetCurrentValue());
186 view_->layer()->ScheduleDraw();
190 scoped_ptr<views::View> view_;
192 DISALLOW_COPY_AND_ASSIGN(ItemRemoveAnimationDelegate);
195 // ItemMoveAnimationDelegate observes when an item finishes animating when it is
196 // not moving between rows. This is to ensure an item is repainted for the
197 // "zoom out" case when releasing an item being dragged.
198 class ItemMoveAnimationDelegate : public gfx::AnimationDelegate {
200 ItemMoveAnimationDelegate(views::View* view) : view_(view) {}
202 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE {
203 view_->SchedulePaint();
205 virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE {
206 view_->SchedulePaint();
212 DISALLOW_COPY_AND_ASSIGN(ItemMoveAnimationDelegate);
215 // Returns true if the |item| is an folder item.
216 bool IsFolderItem(AppListItem* item) {
217 return (item->GetItemType() == AppListFolderItem::kItemType);
220 bool IsOEMFolderItem(AppListItem* item) {
221 return IsFolderItem(item) &&
222 (static_cast<AppListFolderItem*>(item))->folder_type() ==
223 AppListFolderItem::FOLDER_TYPE_OEM;
226 int ClampToRange(int value, int min, int max) {
227 return std::min(std::max(value, min), max);
233 // Interprets drag events sent from Windows via the drag/drop API and forwards
234 // them to AppsGridView.
235 // On Windows, in order to have the OS perform the drag properly we need to
236 // provide it with a shortcut file which may or may not exist at the time the
237 // drag is started. Therefore while waiting for that shortcut to be located we
238 // just do a regular "internal" drag and transition into the synchronous drag
239 // when the shortcut is found/created. Hence a synchronous drag is an optional
240 // phase of a regular drag and non-Windows platforms drags are equivalent to a
241 // Windows drag that never enters the synchronous drag phase.
242 class SynchronousDrag : public ui::DragSourceWin {
244 SynchronousDrag(AppsGridView* grid_view,
245 AppListItemView* drag_view,
246 const gfx::Point& drag_view_offset)
247 : grid_view_(grid_view),
248 drag_view_(drag_view),
249 drag_view_offset_(drag_view_offset),
250 has_shortcut_path_(false),
254 void set_shortcut_path(const base::FilePath& shortcut_path) {
255 has_shortcut_path_ = true;
256 shortcut_path_ = shortcut_path;
259 bool running() { return running_; }
262 return has_shortcut_path_ && !running_;
268 // Prevent the synchronous dragger being destroyed while the drag is
270 scoped_refptr<SynchronousDrag> this_ref = this;
273 ui::OSExchangeData data;
274 SetupExchangeData(&data);
276 // Hide the dragged view because the OS is going to create its own.
277 drag_view_->SetVisible(false);
279 // Blocks until the drag is finished. Calls into the ui::DragSourceWin
282 DoDragDrop(ui::OSExchangeDataProviderWin::GetIDataObject(data),
283 this, DROPEFFECT_MOVE | DROPEFFECT_LINK, &effects);
285 // If |drag_view_| is NULL the drag was ended by some reentrant code.
287 // Make the drag view visible again.
288 drag_view_->SetVisible(true);
289 drag_view_->OnSyncDragEnd();
291 grid_view_->EndDrag(canceled_ || !IsCursorWithinGridView());
295 void EndDragExternally() {
298 drag_view_->SetVisible(true);
303 // Overridden from ui::DragSourceWin.
304 virtual void OnDragSourceCancel() OVERRIDE {
308 virtual void OnDragSourceDrop() OVERRIDE {
311 virtual void OnDragSourceMove() OVERRIDE {
312 grid_view_->UpdateDrag(AppsGridView::MOUSE, GetCursorInGridViewCoords());
315 void SetupExchangeData(ui::OSExchangeData* data) {
316 data->SetFilename(shortcut_path_);
317 gfx::ImageSkia image(drag_view_->GetDragImage());
318 gfx::Size image_size(image.size());
319 drag_utils::SetDragImageOnDataObject(
321 drag_view_offset_ - drag_view_->GetDragImageOffset(),
325 HWND GetGridViewHWND() {
326 return views::HWNDForView(grid_view_);
329 bool IsCursorWithinGridView() {
332 return GetGridViewHWND() == WindowFromPoint(p);
335 gfx::Point GetCursorInGridViewCoords() {
338 ScreenToClient(GetGridViewHWND(), &p);
339 gfx::Point grid_view_pt(p.x, p.y);
340 grid_view_pt = gfx::win::ScreenToDIPPoint(grid_view_pt);
341 views::View::ConvertPointFromWidget(grid_view_, &grid_view_pt);
345 AppsGridView* grid_view_;
346 AppListItemView* drag_view_;
347 gfx::Point drag_view_offset_;
348 bool has_shortcut_path_;
349 base::FilePath shortcut_path_;
353 DISALLOW_COPY_AND_ASSIGN(SynchronousDrag);
355 #endif // defined(OS_WIN)
357 AppsGridView::AppsGridView(AppsGridViewDelegate* delegate)
361 folder_delegate_(NULL),
362 page_switcher_view_(NULL),
365 selected_view_(NULL),
367 drag_start_page_(-1),
369 use_synchronous_drag_(true),
372 drop_attempt_(DROP_FOR_NONE),
373 drag_and_drop_host_(NULL),
374 forward_events_to_drag_and_drop_host_(false),
375 page_flip_target_(-1),
376 page_flip_delay_in_ms_(kPageFlipDelayInMs),
377 bounds_animator_(this),
378 activated_folder_item_view_(NULL),
379 dragging_for_reparent_item_(false) {
380 SetPaintToLayer(true);
381 // Clip any icons that are outside the grid view's bounds. These icons would
382 // otherwise be visible to the user when the grid view is off screen.
383 layer()->SetMasksToBounds(true);
384 SetFillsBoundsOpaquely(false);
386 pagination_model_.SetTransitionDurations(kPageTransitionDurationInMs,
387 kOverscrollPageTransitionDurationMs);
389 pagination_model_.AddObserver(this);
390 // The experimental app list transitions vertically.
391 PaginationController::ScrollAxis scroll_axis =
392 app_list::switches::IsExperimentalAppListEnabled()
393 ? PaginationController::SCROLL_AXIS_VERTICAL
394 : PaginationController::SCROLL_AXIS_HORIZONTAL;
395 pagination_controller_.reset(
396 new PaginationController(&pagination_model_, scroll_axis));
397 if (!switches::IsExperimentalAppListEnabled()) {
398 page_switcher_view_ = new PageSwitcher(&pagination_model_);
399 AddChildView(page_switcher_view_);
403 AppsGridView::~AppsGridView() {
404 // Coming here |drag_view_| should already be canceled since otherwise the
405 // drag would disappear after the app list got animated away and closed,
406 // which would look odd.
412 model_->RemoveObserver(this);
413 pagination_model_.RemoveObserver(this);
416 item_list_->RemoveObserver(this);
418 // Make sure |page_switcher_view_| is deleted before |pagination_model_|.
420 RemoveAllChildViews(true);
423 void AppsGridView::SetLayout(int cols, int rows_per_page) {
425 rows_per_page_ = rows_per_page;
427 SetBorder(views::Border::CreateEmptyBorder(
428 switches::IsExperimentalAppListEnabled() ? 0 : kTopPadding,
434 void AppsGridView::ResetForShowApps() {
435 activated_folder_item_view_ = NULL;
437 layer()->SetOpacity(1.0f);
439 // Set all views to visible in case they weren't made visible again by an
440 // incomplete animation.
441 for (int i = 0; i < view_model_.view_size(); ++i) {
442 view_model_.view_at(i)->SetVisible(true);
444 CHECK_EQ(item_list_->item_count(),
445 static_cast<size_t>(view_model_.view_size()));
448 void AppsGridView::SetModel(AppListModel* model) {
450 model_->RemoveObserver(this);
454 model_->AddObserver(this);
459 void AppsGridView::SetItemList(AppListItemList* item_list) {
461 item_list_->RemoveObserver(this);
462 item_list_ = item_list;
464 item_list_->AddObserver(this);
468 void AppsGridView::SetSelectedView(views::View* view) {
469 if (IsSelectedView(view) || IsDraggedView(view))
472 Index index = GetIndexOfView(view);
473 if (IsValidIndex(index))
474 SetSelectedItemByIndex(index);
477 void AppsGridView::ClearSelectedView(views::View* view) {
478 if (view && IsSelectedView(view)) {
479 selected_view_->SchedulePaint();
480 selected_view_ = NULL;
484 void AppsGridView::ClearAnySelectedView() {
485 if (selected_view_) {
486 selected_view_->SchedulePaint();
487 selected_view_ = NULL;
491 bool AppsGridView::IsSelectedView(const views::View* view) const {
492 return selected_view_ == view;
495 void AppsGridView::EnsureViewVisible(const views::View* view) {
496 if (pagination_model_.has_transition())
499 Index index = GetIndexOfView(view);
500 if (IsValidIndex(index))
501 pagination_model_.SelectPage(index.page, false);
504 void AppsGridView::InitiateDrag(AppListItemView* view,
506 const ui::LocatedEvent& event) {
508 if (drag_view_ || pulsing_blocks_model_.view_size())
512 drag_view_init_index_ = GetIndexOfView(drag_view_);
513 drag_view_offset_ = event.location();
514 drag_start_page_ = pagination_model_.selected_page();
515 reorder_placeholder_ = drag_view_init_index_;
516 ExtractDragLocation(event, &drag_start_grid_view_);
517 drag_view_start_ = gfx::Point(drag_view_->x(), drag_view_->y());
520 void AppsGridView::StartSettingUpSynchronousDrag() {
522 if (!delegate_ || !use_synchronous_drag_)
525 // Folders and downloading items can't be integrated with the OS.
526 if (IsFolderItem(drag_view_->item()) || drag_view_->item()->is_installing())
529 // Favor the drag and drop host over native win32 drag. For the Win8/ash
530 // launcher we want to have ashes drag and drop over win32's.
531 if (drag_and_drop_host_)
534 // Never create a second synchronous drag if the drag started in a folder.
535 if (IsDraggingForReparentInRootLevelGridView())
538 synchronous_drag_ = new SynchronousDrag(this, drag_view_, drag_view_offset_);
539 delegate_->GetShortcutPathForApp(drag_view_->item()->id(),
540 base::Bind(&AppsGridView::OnGotShortcutPath,
541 base::Unretained(this),
546 bool AppsGridView::RunSynchronousDrag() {
548 if (!synchronous_drag_)
551 if (synchronous_drag_->CanRun()) {
552 if (IsDraggingForReparentInHiddenGridView())
553 folder_delegate_->SetRootLevelDragViewVisible(false);
554 synchronous_drag_->Run();
555 synchronous_drag_ = NULL;
557 } else if (!synchronous_drag_->running()) {
558 // The OS drag is not ready yet. If the root grid has a drag view because
559 // a reparent has started, ensure it is visible.
560 if (IsDraggingForReparentInHiddenGridView())
561 folder_delegate_->SetRootLevelDragViewVisible(true);
567 void AppsGridView::CleanUpSynchronousDrag() {
569 if (synchronous_drag_)
570 synchronous_drag_->EndDragExternally();
572 synchronous_drag_ = NULL;
577 void AppsGridView::OnGotShortcutPath(
578 scoped_refptr<SynchronousDrag> synchronous_drag,
579 const base::FilePath& path) {
580 // Drag may have ended before we get the shortcut path or a new drag may have
582 if (synchronous_drag_ != synchronous_drag)
584 // Setting the shortcut path here means the next time we hit UpdateDrag()
585 // we'll enter the synchronous drag.
586 // NOTE we don't Run() the drag here because that causes animations not to
587 // update for some reason.
588 synchronous_drag_->set_shortcut_path(path);
589 DCHECK(synchronous_drag_->CanRun());
593 bool AppsGridView::UpdateDragFromItem(Pointer pointer,
594 const ui::LocatedEvent& event) {
596 return false; // Drag canceled.
598 gfx::Point drag_point_in_grid_view;
599 ExtractDragLocation(event, &drag_point_in_grid_view);
600 UpdateDrag(pointer, drag_point_in_grid_view);
604 // If a drag and drop host is provided, see if the drag operation needs to be
606 gfx::Point location_in_screen = drag_point_in_grid_view;
607 views::View::ConvertPointToScreen(this, &location_in_screen);
608 DispatchDragEventToDragAndDropHost(location_in_screen);
609 if (drag_and_drop_host_)
610 drag_and_drop_host_->UpdateDragIconProxy(location_in_screen);
614 void AppsGridView::UpdateDrag(Pointer pointer, const gfx::Point& point) {
615 if (folder_delegate_)
616 UpdateDragStateInsideFolder(pointer, point);
619 return; // Drag canceled.
621 if (RunSynchronousDrag())
624 gfx::Vector2d drag_vector(point - drag_start_grid_view_);
625 if (!dragging() && ExceededDragThreshold(drag_vector)) {
626 drag_pointer_ = pointer;
627 // Move the view to the front so that it appears on top of other views.
628 ReorderChildView(drag_view_, -1);
629 bounds_animator_.StopAnimatingView(drag_view_);
630 // Stopping the animation may have invalidated our drag view due to the
631 // view hierarchy changing.
635 StartSettingUpSynchronousDrag();
636 if (!dragging_for_reparent_item_)
637 StartDragAndDropHostDrag(point);
640 if (drag_pointer_ != pointer)
643 drag_view_->SetPosition(drag_view_start_ + drag_vector);
645 last_drag_point_ = point;
646 const Index last_reorder_drop_target = reorder_drop_target_;
647 const Index last_folder_drop_target = folder_drop_target_;
648 DropAttempt last_drop_attempt = drop_attempt_;
649 CalculateDropTarget();
651 MaybeStartPageFlipTimer(last_drag_point_);
653 if (page_switcher_view_) {
654 gfx::Point page_switcher_point(last_drag_point_);
655 views::View::ConvertPointToTarget(
656 this, page_switcher_view_, &page_switcher_point);
657 page_switcher_view_->UpdateUIForDragPoint(page_switcher_point);
660 if (last_folder_drop_target != folder_drop_target_ ||
661 last_reorder_drop_target != reorder_drop_target_ ||
662 last_drop_attempt != drop_attempt_) {
663 if (drop_attempt_ == DROP_FOR_REORDER) {
664 folder_dropping_timer_.Stop();
665 reorder_timer_.Start(FROM_HERE,
666 base::TimeDelta::FromMilliseconds(kReorderDelay),
667 this, &AppsGridView::OnReorderTimer);
668 } else if (drop_attempt_ == DROP_FOR_FOLDER) {
669 reorder_timer_.Stop();
670 folder_dropping_timer_.Start(FROM_HERE,
671 base::TimeDelta::FromMilliseconds(kFolderDroppingDelay),
672 this, &AppsGridView::OnFolderDroppingTimer);
675 // Reset the previous drop target.
676 SetAsFolderDroppingTarget(last_folder_drop_target, false);
680 void AppsGridView::EndDrag(bool cancel) {
681 // EndDrag was called before if |drag_view_| is NULL.
685 // Coming here a drag and drop was in progress.
686 bool landed_in_drag_and_drop_host = forward_events_to_drag_and_drop_host_;
687 if (forward_events_to_drag_and_drop_host_) {
688 DCHECK(!IsDraggingForReparentInRootLevelGridView());
689 forward_events_to_drag_and_drop_host_ = false;
690 drag_and_drop_host_->EndDrag(cancel);
691 if (IsDraggingForReparentInHiddenGridView()) {
692 folder_delegate_->DispatchEndDragEventForReparent(
693 true /* events_forwarded_to_drag_drop_host */,
694 cancel /* cancel_drag */);
697 if (IsDraggingForReparentInHiddenGridView()) {
698 // Forward the EndDrag event to the root level grid view.
699 folder_delegate_->DispatchEndDragEventForReparent(
700 false /* events_forwarded_to_drag_drop_host */,
701 cancel /* cancel_drag */);
702 EndDragForReparentInHiddenFolderGridView();
706 if (IsDraggingForReparentInRootLevelGridView()) {
707 // An EndDrag can be received during a reparent via a model change. This
708 // is always a cancel and needs to be forwarded to the folder.
710 delegate_->CancelDragInActiveFolder();
714 if (!cancel && dragging()) {
715 // Regular drag ending path, ie, not for reparenting.
716 CalculateDropTarget();
717 if (EnableFolderDragDropUI() && drop_attempt_ == DROP_FOR_FOLDER &&
718 IsValidIndex(folder_drop_target_)) {
719 MoveItemToFolder(drag_view_, folder_drop_target_);
720 } else if (IsValidIndex(reorder_drop_target_)) {
721 MoveItemInModel(drag_view_, reorder_drop_target_);
726 if (drag_and_drop_host_) {
727 // If we had a drag and drop proxy icon, we delete it and make the real
728 // item visible again.
729 drag_and_drop_host_->DestroyDragIconProxy();
730 if (landed_in_drag_and_drop_host) {
731 // Move the item directly to the target location, avoiding the "zip back"
732 // animation if the user was pinning it to the shelf.
733 int i = reorder_drop_target_.slot;
734 gfx::Rect bounds = view_model_.ideal_bounds(i);
735 drag_view_->SetBoundsRect(bounds);
737 // Fade in slowly if it landed in the shelf.
738 SetViewHidden(drag_view_,
740 !landed_in_drag_and_drop_host /* animate */);
743 // The drag can be ended after the synchronous drag is created but before it
745 CleanUpSynchronousDrag();
747 SetAsFolderDroppingTarget(folder_drop_target_, false);
749 AnimateToIdealBounds();
753 // If user releases mouse inside a folder's grid view, burst the folder
754 // container ink bubble.
755 if (folder_delegate_ && !IsDraggingForReparentInHiddenGridView())
756 folder_delegate_->UpdateFolderViewBackground(false);
759 void AppsGridView::StopPageFlipTimer() {
760 page_flip_timer_.Stop();
761 page_flip_target_ = -1;
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));
769 void AppsGridView::SetTopItemViewsVisible(bool visible) {
770 int top_item_count = std::min(static_cast<int>(kNumFolderTopItems),
771 view_model_.view_size());
772 for (int i = 0; i < top_item_count; ++i)
773 GetItemViewAt(i)->icon()->SetVisible(visible);
776 void AppsGridView::ScheduleShowHideAnimation(bool show) {
777 // Stop any previous animation.
778 layer()->GetAnimator()->StopAnimating();
780 // Set initial state.
782 layer()->SetOpacity(show ? 0.0f : 1.0f);
784 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator());
785 animation.AddObserver(this);
786 animation.SetTweenType(
787 show ? kFolderFadeInTweenType : kFolderFadeOutTweenType);
788 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
789 show ? kFolderTransitionInDurationMs : kFolderTransitionOutDurationMs));
791 layer()->SetOpacity(show ? 1.0f : 0.0f);
794 void AppsGridView::InitiateDragFromReparentItemInRootLevelGridView(
795 AppListItemView* original_drag_view,
796 const gfx::Rect& drag_view_rect,
797 const gfx::Point& drag_point) {
798 DCHECK(original_drag_view && !drag_view_);
799 DCHECK(!dragging_for_reparent_item_);
801 // Since the item is new, its placeholder is conceptually at the back of the
803 reorder_placeholder_ = GetLastViewIndex();
805 // Create a new AppListItemView to duplicate the original_drag_view in the
806 // folder's grid view.
807 AppListItemView* view = new AppListItemView(this, original_drag_view->item());
810 drag_view_->SetPaintToLayer(true);
811 // Note: For testing purpose, SetFillsBoundsOpaquely can be set to true to
812 // show the gray background.
813 drag_view_->SetFillsBoundsOpaquely(false);
814 drag_view_->SetBoundsRect(drag_view_rect);
815 drag_view_->SetDragUIState(); // Hide the title of the drag_view_.
817 // Hide the drag_view_ for drag icon proxy.
818 SetViewHidden(drag_view_,
820 true /* no animate */);
822 // Add drag_view_ to the end of the view_model_.
823 view_model_.Add(drag_view_, view_model_.view_size());
825 drag_start_page_ = pagination_model_.selected_page();
826 drag_start_grid_view_ = drag_point;
828 drag_view_start_ = gfx::Point(drag_view_->x(), drag_view_->y());
830 // Set the flag in root level grid view.
831 dragging_for_reparent_item_ = true;
834 void AppsGridView::UpdateDragFromReparentItem(Pointer pointer,
835 const gfx::Point& drag_point) {
836 // 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()
838 // for |drag_view_| being NULL (in the folder grid) is sufficient.
840 DCHECK(IsDraggingForReparentInRootLevelGridView());
842 UpdateDrag(pointer, drag_point);
845 bool AppsGridView::IsDraggedView(const views::View* view) const {
846 return drag_view_ == view;
849 void AppsGridView::ClearDragState() {
850 drop_attempt_ = DROP_FOR_NONE;
851 drag_pointer_ = NONE;
852 reorder_drop_target_ = Index();
853 folder_drop_target_ = Index();
854 reorder_placeholder_ = Index();
855 drag_start_grid_view_ = gfx::Point();
856 drag_start_page_ = -1;
857 drag_view_offset_ = gfx::Point();
860 drag_view_->OnDragEnded();
861 if (IsDraggingForReparentInRootLevelGridView()) {
862 const int drag_view_index = view_model_.GetIndexOfView(drag_view_);
863 CHECK_EQ(view_model_.view_size() - 1, drag_view_index);
864 DeleteItemViewAtIndex(drag_view_index);
868 dragging_for_reparent_item_ = false;
871 void AppsGridView::SetDragViewVisible(bool visible) {
873 SetViewHidden(drag_view_, !visible, true);
876 void AppsGridView::SetDragAndDropHostOfCurrentAppList(
877 ApplicationDragAndDropHost* drag_and_drop_host) {
878 drag_and_drop_host_ = drag_and_drop_host;
881 void AppsGridView::Prerender() {
883 int selected_page = std::max(0, pagination_model_.selected_page());
884 int start = std::max(0, (selected_page - kPrerenderPages) * tiles_per_page());
885 int end = std::min(view_model_.view_size(),
886 (selected_page + 1 + kPrerenderPages) * tiles_per_page());
887 for (int i = start; i < end; i++) {
888 AppListItemView* v = static_cast<AppListItemView*>(view_model_.view_at(i));
893 bool AppsGridView::IsAnimatingView(views::View* view) {
894 return bounds_animator_.IsAnimating(view);
897 gfx::Size AppsGridView::GetPreferredSize() const {
898 const gfx::Insets insets(GetInsets());
899 int page_switcher_height = 0;
900 if (page_switcher_view_)
901 page_switcher_height = page_switcher_view_->GetPreferredSize().height();
902 gfx::Size size = GetTileGridSize();
903 size.Enlarge(insets.width(), insets.height() + page_switcher_height);
907 bool AppsGridView::GetDropFormats(
909 std::set<OSExchangeData::CustomFormat>* custom_formats) {
910 // TODO(koz): Only accept a specific drag type for app shortcuts.
911 *formats = OSExchangeData::FILE_NAME;
915 bool AppsGridView::CanDrop(const OSExchangeData& data) {
919 int AppsGridView::OnDragUpdated(const ui::DropTargetEvent& event) {
920 return ui::DragDropTypes::DRAG_MOVE;
923 void AppsGridView::Layout() {
924 if (bounds_animator_.IsAnimating())
925 bounds_animator_.Cancel();
927 CalculateIdealBounds();
928 for (int i = 0; i < view_model_.view_size(); ++i) {
929 views::View* view = view_model_.view_at(i);
930 if (view != drag_view_)
931 view->SetBoundsRect(view_model_.ideal_bounds(i));
933 views::ViewModelUtils::SetViewBoundsToIdealBounds(pulsing_blocks_model_);
935 if (page_switcher_view_) {
936 const int page_switcher_height =
937 page_switcher_view_->GetPreferredSize().height();
938 gfx::Rect rect(GetContentsBounds());
939 rect.set_y(rect.bottom() - page_switcher_height);
940 rect.set_height(page_switcher_height);
941 page_switcher_view_->SetBoundsRect(rect);
945 bool AppsGridView::OnKeyPressed(const ui::KeyEvent& event) {
946 bool handled = false;
948 handled = selected_view_->OnKeyPressed(event);
951 const int forward_dir = base::i18n::IsRTL() ? -1 : 1;
952 switch (event.key_code()) {
954 MoveSelected(0, -forward_dir, 0);
957 MoveSelected(0, forward_dir, 0);
960 MoveSelected(0, 0, -1);
963 MoveSelected(0, 0, 1);
965 case ui::VKEY_PRIOR: {
966 MoveSelected(-1, 0, 0);
969 case ui::VKEY_NEXT: {
970 MoveSelected(1, 0, 0);
981 bool AppsGridView::OnKeyReleased(const ui::KeyEvent& event) {
982 bool handled = false;
984 handled = selected_view_->OnKeyReleased(event);
989 bool AppsGridView::OnMouseWheel(const ui::MouseWheelEvent& event) {
990 return pagination_controller_->OnScroll(
991 gfx::Vector2d(event.x_offset(), event.y_offset()));
994 void AppsGridView::ViewHierarchyChanged(
995 const ViewHierarchyChangedDetails& details) {
996 if (!details.is_add && details.parent == this) {
997 // The view being delete should not have reference in |view_model_|.
998 CHECK_EQ(-1, view_model_.GetIndexOfView(details.child));
1000 if (selected_view_ == details.child)
1001 selected_view_ = NULL;
1002 if (activated_folder_item_view_ == details.child)
1003 activated_folder_item_view_ = NULL;
1005 if (drag_view_ == details.child)
1008 bounds_animator_.StopAnimatingView(details.child);
1012 void AppsGridView::OnGestureEvent(ui::GestureEvent* event) {
1013 if (pagination_controller_->OnGestureEvent(*event, GetContentsBounds()))
1014 event->SetHandled();
1017 void AppsGridView::OnScrollEvent(ui::ScrollEvent* event) {
1018 if (event->type() == ui::ET_SCROLL_FLING_CANCEL)
1021 gfx::Vector2dF offset(event->x_offset(), event->y_offset());
1022 if (pagination_controller_->OnScroll(gfx::ToFlooredVector2d(offset))) {
1023 event->SetHandled();
1024 event->StopPropagation();
1028 void AppsGridView::Update() {
1029 DCHECK(!selected_view_ && !drag_view_);
1030 view_model_.Clear();
1031 if (!item_list_ || !item_list_->item_count())
1033 for (size_t i = 0; i < item_list_->item_count(); ++i) {
1034 views::View* view = CreateViewForItemAtIndex(i);
1035 view_model_.Add(view, i);
1039 UpdatePulsingBlockViews();
1044 void AppsGridView::UpdatePaging() {
1045 int total_page = view_model_.view_size() && tiles_per_page()
1046 ? (view_model_.view_size() - 1) / tiles_per_page() + 1
1049 pagination_model_.SetTotalPages(total_page);
1052 void AppsGridView::UpdatePulsingBlockViews() {
1053 const int existing_items = item_list_ ? item_list_->item_count() : 0;
1054 const int available_slots =
1055 tiles_per_page() - existing_items % tiles_per_page();
1056 const int desired = model_->status() == AppListModel::STATUS_SYNCING ?
1057 available_slots : 0;
1059 if (pulsing_blocks_model_.view_size() == desired)
1062 while (pulsing_blocks_model_.view_size() > desired) {
1063 views::View* view = pulsing_blocks_model_.view_at(0);
1064 pulsing_blocks_model_.Remove(0);
1068 while (pulsing_blocks_model_.view_size() < desired) {
1069 views::View* view = new PulsingBlockView(GetTotalTileSize(), true);
1070 pulsing_blocks_model_.Add(view, 0);
1075 views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) {
1076 // The drag_view_ might be pending for deletion, therefore view_model_
1077 // may have one more item than item_list_.
1078 DCHECK_LE(index, item_list_->item_count());
1079 AppListItemView* view = new AppListItemView(this,
1080 item_list_->item_at(index));
1081 view->SetPaintToLayer(true);
1082 view->SetFillsBoundsOpaquely(false);
1086 AppsGridView::Index AppsGridView::GetIndexFromModelIndex(
1087 int model_index) const {
1088 return Index(model_index / tiles_per_page(), model_index % tiles_per_page());
1091 int AppsGridView::GetModelIndexFromIndex(const Index& index) const {
1092 return index.page * tiles_per_page() + index.slot;
1095 void AppsGridView::SetSelectedItemByIndex(const Index& index) {
1096 if (GetIndexOfView(selected_view_) == index)
1099 views::View* new_selection = GetViewAtIndex(index);
1101 return; // Keep current selection.
1104 selected_view_->SchedulePaint();
1106 EnsureViewVisible(new_selection);
1107 selected_view_ = new_selection;
1108 selected_view_->SchedulePaint();
1109 selected_view_->NotifyAccessibilityEvent(
1110 ui::AX_EVENT_FOCUS, true);
1113 bool AppsGridView::IsValidIndex(const Index& index) const {
1114 return index.page >= 0 && index.page < pagination_model_.total_pages() &&
1115 index.slot >= 0 && index.slot < tiles_per_page() &&
1116 GetModelIndexFromIndex(index) < view_model_.view_size();
1119 AppsGridView::Index AppsGridView::GetIndexOfView(
1120 const views::View* view) const {
1121 const int model_index = view_model_.GetIndexOfView(view);
1122 if (model_index == -1)
1125 return GetIndexFromModelIndex(model_index);
1128 views::View* AppsGridView::GetViewAtIndex(const Index& index) const {
1129 if (!IsValidIndex(index))
1132 const int model_index = GetModelIndexFromIndex(index);
1133 return view_model_.view_at(model_index);
1136 AppsGridView::Index AppsGridView::GetLastViewIndex() const {
1137 DCHECK_LT(0, view_model_.view_size());
1138 int view_index = view_model_.view_size() - 1;
1139 return Index(view_index / tiles_per_page(), view_index % tiles_per_page());
1142 void AppsGridView::MoveSelected(int page_delta,
1145 if (!selected_view_)
1146 return SetSelectedItemByIndex(Index(pagination_model_.selected_page(), 0));
1148 const Index& selected = GetIndexOfView(selected_view_);
1149 int target_slot = selected.slot + slot_x_delta + slot_y_delta * cols_;
1151 if (selected.slot % cols_ == 0 && slot_x_delta == -1) {
1152 if (selected.page > 0) {
1154 target_slot = selected.slot + cols_ - 1;
1156 target_slot = selected.slot;
1160 if (selected.slot % cols_ == cols_ - 1 && slot_x_delta == 1) {
1161 if (selected.page < pagination_model_.total_pages() - 1) {
1163 target_slot = selected.slot - cols_ + 1;
1165 target_slot = selected.slot;
1169 // Clamp the target slot to the last item if we are moving to the last page
1170 // but our target slot is past the end of the item list.
1172 selected.page + page_delta == pagination_model_.total_pages() - 1) {
1173 int last_item_slot = (view_model_.view_size() - 1) % tiles_per_page();
1174 if (last_item_slot < target_slot) {
1175 target_slot = last_item_slot;
1179 int target_page = std::min(pagination_model_.total_pages() - 1,
1180 std::max(selected.page + page_delta, 0));
1181 SetSelectedItemByIndex(Index(target_page, target_slot));
1184 void AppsGridView::CalculateIdealBounds() {
1185 // TODO(calamity): This fixes http://crbug.com/422604 on ChromeOS but it's
1186 // unclear why. This should be investigated to fix the issue on Linux Ash.
1187 if (GetContentsBounds().IsEmpty())
1190 gfx::Size grid_size = GetTileGridSize();
1192 // Page size including padding pixels. A tile.x + page_width means the same
1193 // tile slot in the next page; similarly for tile.y + page_height.
1194 const int page_width = grid_size.width() + kPagePadding;
1195 const int page_height = grid_size.height() + kPagePadding;
1197 // If there is a transition, calculates offset for current and target page.
1198 const int current_page = pagination_model_.selected_page();
1199 const PaginationModel::Transition& transition =
1200 pagination_model_.transition();
1201 const bool is_valid = pagination_model_.is_valid_page(transition.target_page);
1203 // Transition to previous page means negative offset.
1204 const int dir = transition.target_page > current_page ? -1 : 1;
1206 const int total_views =
1207 view_model_.view_size() + pulsing_blocks_model_.view_size();
1209 for (int i = 0; i < total_views; ++i) {
1210 if (i < view_model_.view_size() && view_model_.view_at(i) == drag_view_)
1213 Index view_index = GetIndexFromModelIndex(slot_index);
1215 // Leaves a blank space in the grid for the current reorder placeholder.
1216 if (reorder_placeholder_ == view_index) {
1218 view_index = GetIndexFromModelIndex(slot_index);
1221 // Decide the x or y offset for current item.
1225 if (pagination_controller_->scroll_axis() ==
1226 PaginationController::SCROLL_AXIS_HORIZONTAL) {
1227 if (view_index.page < current_page)
1228 x_offset = -page_width;
1229 else if (view_index.page > current_page)
1230 x_offset = page_width;
1233 if (view_index.page == current_page ||
1234 view_index.page == transition.target_page) {
1235 x_offset += transition.progress * page_width * dir;
1239 if (view_index.page < current_page)
1240 y_offset = -page_height;
1241 else if (view_index.page > current_page)
1242 y_offset = page_height;
1245 if (view_index.page == current_page ||
1246 view_index.page == transition.target_page) {
1247 y_offset += transition.progress * page_height * dir;
1252 const int row = view_index.slot / cols_;
1253 const int col = view_index.slot % cols_;
1254 gfx::Rect tile_slot = GetExpectedTileBounds(row, col);
1255 tile_slot.Offset(x_offset, y_offset);
1256 if (i < view_model_.view_size()) {
1257 view_model_.set_ideal_bounds(i, tile_slot);
1259 pulsing_blocks_model_.set_ideal_bounds(i - view_model_.view_size(),
1267 void AppsGridView::AnimateToIdealBounds() {
1268 const gfx::Rect visible_bounds(GetVisibleBounds());
1270 CalculateIdealBounds();
1271 for (int i = 0; i < view_model_.view_size(); ++i) {
1272 views::View* view = view_model_.view_at(i);
1273 if (view == drag_view_)
1276 const gfx::Rect& target = view_model_.ideal_bounds(i);
1277 if (bounds_animator_.GetTargetBounds(view) == target)
1280 const gfx::Rect& current = view->bounds();
1281 const bool current_visible = visible_bounds.Intersects(current);
1282 const bool target_visible = visible_bounds.Intersects(target);
1283 const bool visible = current_visible || target_visible;
1285 const int y_diff = target.y() - current.y();
1286 if (visible && y_diff && y_diff % GetTotalTileSize().height() == 0) {
1287 AnimationBetweenRows(view,
1292 } else if (visible || bounds_animator_.IsAnimating(view)) {
1293 bounds_animator_.AnimateViewTo(view, target);
1294 bounds_animator_.SetAnimationDelegate(
1296 scoped_ptr<gfx::AnimationDelegate>(
1297 new ItemMoveAnimationDelegate(view)));
1299 view->SetBoundsRect(target);
1304 void AppsGridView::AnimationBetweenRows(views::View* view,
1305 bool animate_current,
1306 const gfx::Rect& current,
1307 bool animate_target,
1308 const gfx::Rect& target) {
1309 // Determine page of |current| and |target|. -1 means in the left invisible
1310 // page, 0 is the center visible page and 1 means in the right invisible page.
1311 const int current_page = current.x() < 0 ? -1 :
1312 current.x() >= width() ? 1 : 0;
1313 const int target_page = target.x() < 0 ? -1 :
1314 target.x() >= width() ? 1 : 0;
1316 const int dir = current_page < target_page ||
1317 (current_page == target_page && current.y() < target.y()) ? 1 : -1;
1319 scoped_ptr<ui::Layer> layer;
1320 if (animate_current) {
1321 layer = view->RecreateLayer();
1322 layer->SuppressPaint();
1324 view->SetFillsBoundsOpaquely(false);
1325 view->layer()->SetOpacity(0.f);
1328 gfx::Size total_tile_size = GetTotalTileSize();
1329 gfx::Rect current_out(current);
1330 current_out.Offset(dir * total_tile_size.width(), 0);
1332 gfx::Rect target_in(target);
1334 target_in.Offset(-dir * total_tile_size.width(), 0);
1335 view->SetBoundsRect(target_in);
1336 bounds_animator_.AnimateViewTo(view, target);
1338 bounds_animator_.SetAnimationDelegate(
1340 scoped_ptr<gfx::AnimationDelegate>(
1341 new RowMoveAnimationDelegate(view, layer.release(), current_out)));
1344 void AppsGridView::ExtractDragLocation(const ui::LocatedEvent& event,
1345 gfx::Point* drag_point) {
1346 #if defined(USE_AURA) && !defined(OS_WIN)
1347 // Use root location of |event| instead of location in |drag_view_|'s
1348 // coordinates because |drag_view_| has a scale transform and location
1349 // could have integer round error and causes jitter.
1350 *drag_point = event.root_location();
1352 // GetWidget() could be NULL for tests.
1354 aura::Window::ConvertPointToTarget(
1355 GetWidget()->GetNativeWindow()->GetRootWindow(),
1356 GetWidget()->GetNativeWindow(),
1360 views::View::ConvertPointFromWidget(this, drag_point);
1362 // For non-aura, root location is not clearly defined but |drag_view_| does
1363 // not have the scale transform. So no round error would be introduced and
1364 // it's okay to use View::ConvertPointToTarget.
1365 *drag_point = event.location();
1366 views::View::ConvertPointToTarget(drag_view_, this, drag_point);
1370 void AppsGridView::CalculateDropTarget() {
1373 gfx::Point point = drag_view_->icon()->bounds().CenterPoint();
1374 views::View::ConvertPointToTarget(drag_view_, this, &point);
1375 if (!IsPointWithinDragBuffer(point)) {
1376 // Reset the reorder target to the original position if the cursor is
1377 // outside the drag buffer.
1378 if (IsDraggingForReparentInRootLevelGridView()) {
1379 drop_attempt_ = DROP_FOR_NONE;
1383 reorder_drop_target_ = drag_view_init_index_;
1384 drop_attempt_ = DROP_FOR_REORDER;
1388 if (EnableFolderDragDropUI() &&
1389 CalculateFolderDropTarget(point, &folder_drop_target_)) {
1390 drop_attempt_ = DROP_FOR_FOLDER;
1394 drop_attempt_ = DROP_FOR_REORDER;
1395 CalculateReorderDropTarget(point, &reorder_drop_target_);
1398 bool AppsGridView::CalculateFolderDropTarget(const gfx::Point& point,
1399 Index* drop_target) const {
1400 Index nearest_tile_index(GetNearestTileIndexForPoint(point));
1401 int distance_to_tile_center =
1402 (point - GetExpectedTileBounds(nearest_tile_index.slot).CenterPoint())
1404 if (nearest_tile_index != reorder_placeholder_ &&
1405 distance_to_tile_center < kFolderDroppingCircleRadius &&
1406 !IsFolderItem(drag_view_->item()) &&
1407 CanDropIntoTarget(nearest_tile_index)) {
1408 *drop_target = nearest_tile_index;
1409 DCHECK(IsValidIndex(*drop_target));
1416 void AppsGridView::CalculateReorderDropTarget(const gfx::Point& point,
1417 Index* drop_target) const {
1418 gfx::Rect bounds = GetContentsBounds();
1419 Index grid_index = GetNearestTileIndexForPoint(point);
1420 gfx::Point reorder_placeholder_center =
1421 GetExpectedTileBounds(reorder_placeholder_.slot).CenterPoint();
1423 int x_offset_direction = 0;
1424 if (grid_index == reorder_placeholder_) {
1425 x_offset_direction = reorder_placeholder_center.x() < point.x() ? -1 : 1;
1427 x_offset_direction = reorder_placeholder_ < grid_index ? -1 : 1;
1430 gfx::Size total_tile_size = GetTotalTileSize();
1431 int row = grid_index.slot / cols_;
1433 // Offset the target column based on the direction of the target. This will
1434 // result in earlier targets getting their reorder zone shifted backwards
1435 // and later targets getting their reorder zones shifted forwards.
1437 // This makes eordering feel like the user is slotting items into the spaces
1439 int x_offset = x_offset_direction *
1440 (total_tile_size.width() - kFolderDroppingCircleRadius) / 2;
1441 int col = (point.x() - bounds.x() + x_offset) / total_tile_size.width();
1442 col = ClampToRange(col, 0, cols_ - 1);
1444 std::min(Index(pagination_model_.selected_page(), row * cols_ + col),
1445 GetLastViewIndex());
1446 DCHECK(IsValidIndex(*drop_target));
1449 void AppsGridView::OnReorderTimer() {
1450 if (drop_attempt_ == DROP_FOR_REORDER) {
1451 reorder_placeholder_ = reorder_drop_target_;
1452 AnimateToIdealBounds();
1456 void AppsGridView::OnFolderItemReparentTimer() {
1457 DCHECK(folder_delegate_);
1458 if (drag_out_of_folder_container_ && drag_view_) {
1459 folder_delegate_->ReparentItem(drag_view_, last_drag_point_);
1461 // Set the flag in the folder's grid view.
1462 dragging_for_reparent_item_ = true;
1464 // Do not observe any data change since it is going to be hidden.
1465 item_list_->RemoveObserver(this);
1470 void AppsGridView::OnFolderDroppingTimer() {
1471 if (drop_attempt_ == DROP_FOR_FOLDER)
1472 SetAsFolderDroppingTarget(folder_drop_target_, true);
1475 void AppsGridView::UpdateDragStateInsideFolder(Pointer pointer,
1476 const gfx::Point& drag_point) {
1477 if (IsUnderOEMFolder())
1480 if (IsDraggingForReparentInHiddenGridView()) {
1481 // Dispatch drag event to root level grid view for re-parenting folder
1482 // folder item purpose.
1483 DispatchDragEventForReparent(pointer, drag_point);
1487 // Regular drag and drop in a folder's grid view.
1488 folder_delegate_->UpdateFolderViewBackground(true);
1490 // Calculate if the drag_view_ is dragged out of the folder's container
1492 gfx::Rect bounds_to_folder_view = ConvertRectToParent(drag_view_->bounds());
1493 gfx::Point pt = bounds_to_folder_view.CenterPoint();
1494 bool is_item_dragged_out_of_folder =
1495 folder_delegate_->IsPointOutsideOfFolderBoundary(pt);
1496 if (is_item_dragged_out_of_folder) {
1497 if (!drag_out_of_folder_container_) {
1498 folder_item_reparent_timer_.Start(
1500 base::TimeDelta::FromMilliseconds(kFolderItemReparentDelay),
1502 &AppsGridView::OnFolderItemReparentTimer);
1503 drag_out_of_folder_container_ = true;
1506 folder_item_reparent_timer_.Stop();
1507 drag_out_of_folder_container_ = false;
1511 bool AppsGridView::IsDraggingForReparentInRootLevelGridView() const {
1512 return (!folder_delegate_ && dragging_for_reparent_item_);
1515 bool AppsGridView::IsDraggingForReparentInHiddenGridView() const {
1516 return (folder_delegate_ && dragging_for_reparent_item_);
1519 gfx::Rect AppsGridView::GetTargetIconRectInFolder(
1520 AppListItemView* drag_item_view,
1521 AppListItemView* folder_item_view) {
1522 gfx::Rect view_ideal_bounds = view_model_.ideal_bounds(
1523 view_model_.GetIndexOfView(folder_item_view));
1524 gfx::Rect icon_ideal_bounds =
1525 folder_item_view->GetIconBoundsForTargetViewBounds(view_ideal_bounds);
1526 AppListFolderItem* folder_item =
1527 static_cast<AppListFolderItem*>(folder_item_view->item());
1528 return folder_item->GetTargetIconRectInFolderForItem(
1529 drag_item_view->item(), icon_ideal_bounds);
1532 bool AppsGridView::IsUnderOEMFolder() {
1533 if (!folder_delegate_)
1536 return folder_delegate_->IsOEMFolder();
1539 void AppsGridView::DispatchDragEventForReparent(Pointer pointer,
1540 const gfx::Point& drag_point) {
1541 folder_delegate_->DispatchDragEventForReparent(pointer, drag_point);
1544 void AppsGridView::EndDragFromReparentItemInRootLevel(
1545 bool events_forwarded_to_drag_drop_host,
1547 // EndDrag was called before if |drag_view_| is NULL.
1551 DCHECK(IsDraggingForReparentInRootLevelGridView());
1552 bool cancel_reparent = cancel_drag || drop_attempt_ == DROP_FOR_NONE;
1553 if (!events_forwarded_to_drag_drop_host && !cancel_reparent) {
1554 CalculateDropTarget();
1555 if (drop_attempt_ == DROP_FOR_REORDER &&
1556 IsValidIndex(reorder_drop_target_)) {
1557 ReparentItemForReorder(drag_view_, reorder_drop_target_);
1558 } else if (drop_attempt_ == DROP_FOR_FOLDER &&
1559 IsValidIndex(folder_drop_target_)) {
1560 ReparentItemToAnotherFolder(drag_view_, folder_drop_target_);
1564 SetViewHidden(drag_view_, false /* show */, true /* no animate */);
1567 // The drag can be ended after the synchronous drag is created but before it
1569 CleanUpSynchronousDrag();
1571 SetAsFolderDroppingTarget(folder_drop_target_, false);
1572 if (cancel_reparent) {
1573 CancelFolderItemReparent(drag_view_);
1575 // By setting |drag_view_| to NULL here, we prevent ClearDragState() from
1576 // cleaning up the newly created AppListItemView, effectively claiming
1577 // ownership of the newly created drag view.
1578 drag_view_->OnDragEnded();
1582 AnimateToIdealBounds();
1584 StopPageFlipTimer();
1587 void AppsGridView::EndDragForReparentInHiddenFolderGridView() {
1588 if (drag_and_drop_host_) {
1589 // If we had a drag and drop proxy icon, we delete it and make the real
1590 // item visible again.
1591 drag_and_drop_host_->DestroyDragIconProxy();
1594 // The drag can be ended after the synchronous drag is created but before it
1596 CleanUpSynchronousDrag();
1598 SetAsFolderDroppingTarget(folder_drop_target_, false);
1602 void AppsGridView::OnFolderItemRemoved() {
1603 DCHECK(folder_delegate_);
1607 void AppsGridView::StartDragAndDropHostDrag(const gfx::Point& grid_location) {
1608 // When a drag and drop host is given, the item can be dragged out of the app
1609 // list window. In that case a proxy widget needs to be used.
1610 // Note: This code has very likely to be changed for Windows (non metro mode)
1611 // when a |drag_and_drop_host_| gets implemented.
1612 if (!drag_view_ || !drag_and_drop_host_)
1615 gfx::Point screen_location = grid_location;
1616 views::View::ConvertPointToScreen(this, &screen_location);
1618 // Determine the mouse offset to the center of the icon so that the drag and
1619 // drop host follows this layer.
1620 gfx::Vector2d delta = drag_view_offset_ -
1621 drag_view_->GetLocalBounds().CenterPoint();
1622 delta.set_y(delta.y() + drag_view_->title()->size().height() / 2);
1624 // We have to hide the original item since the drag and drop host will do
1625 // the OS dependent code to "lift off the dragged item".
1626 DCHECK(!IsDraggingForReparentInRootLevelGridView());
1627 drag_and_drop_host_->CreateDragIconProxy(screen_location,
1628 drag_view_->item()->icon(),
1631 kDragAndDropProxyScale);
1632 SetViewHidden(drag_view_,
1634 true /* no animation */);
1637 void AppsGridView::DispatchDragEventToDragAndDropHost(
1638 const gfx::Point& location_in_screen_coordinates) {
1639 if (!drag_view_ || !drag_and_drop_host_)
1642 if (GetLocalBounds().Contains(last_drag_point_)) {
1643 // The event was issued inside the app menu and we should get all events.
1644 if (forward_events_to_drag_and_drop_host_) {
1645 // The DnD host was previously called and needs to be informed that the
1646 // session returns to the owner.
1647 forward_events_to_drag_and_drop_host_ = false;
1648 drag_and_drop_host_->EndDrag(true);
1651 if (IsFolderItem(drag_view_->item()))
1654 // The event happened outside our app menu and we might need to dispatch.
1655 if (forward_events_to_drag_and_drop_host_) {
1656 // Dispatch since we have already started.
1657 if (!drag_and_drop_host_->Drag(location_in_screen_coordinates)) {
1658 // The host is not active any longer and we cancel the operation.
1659 forward_events_to_drag_and_drop_host_ = false;
1660 drag_and_drop_host_->EndDrag(true);
1663 if (drag_and_drop_host_->StartDrag(drag_view_->item()->id(),
1664 location_in_screen_coordinates)) {
1665 // From now on we forward the drag events.
1666 forward_events_to_drag_and_drop_host_ = true;
1667 // Any flip operations are stopped.
1668 StopPageFlipTimer();
1674 void AppsGridView::MaybeStartPageFlipTimer(const gfx::Point& drag_point) {
1675 if (!IsPointWithinDragBuffer(drag_point))
1676 StopPageFlipTimer();
1677 int new_page_flip_target = -1;
1679 // Drag zones are at the edges of the scroll axis.
1680 if (pagination_controller_->scroll_axis() ==
1681 PaginationController::SCROLL_AXIS_VERTICAL) {
1682 if (drag_point.y() < kPageFlipZoneSize)
1683 new_page_flip_target = pagination_model_.selected_page() - 1;
1684 else if (drag_point.y() > height() - kPageFlipZoneSize)
1685 new_page_flip_target = pagination_model_.selected_page() + 1;
1687 if (page_switcher_view_->bounds().Contains(drag_point)) {
1688 gfx::Point page_switcher_point(drag_point);
1689 views::View::ConvertPointToTarget(
1690 this, page_switcher_view_, &page_switcher_point);
1691 new_page_flip_target =
1692 page_switcher_view_->GetPageForPoint(page_switcher_point);
1695 // TODO(xiyuan): Fix this for RTL.
1696 if (new_page_flip_target == -1 && drag_point.x() < kPageFlipZoneSize)
1697 new_page_flip_target = pagination_model_.selected_page() - 1;
1699 if (new_page_flip_target == -1 &&
1700 drag_point.x() > width() - kPageFlipZoneSize) {
1701 new_page_flip_target = pagination_model_.selected_page() + 1;
1705 if (new_page_flip_target == page_flip_target_)
1708 StopPageFlipTimer();
1709 if (pagination_model_.is_valid_page(new_page_flip_target)) {
1710 page_flip_target_ = new_page_flip_target;
1712 if (page_flip_target_ != pagination_model_.selected_page()) {
1713 page_flip_timer_.Start(FROM_HERE,
1714 base::TimeDelta::FromMilliseconds(page_flip_delay_in_ms_),
1715 this, &AppsGridView::OnPageFlipTimer);
1720 void AppsGridView::OnPageFlipTimer() {
1721 DCHECK(pagination_model_.is_valid_page(page_flip_target_));
1722 pagination_model_.SelectPage(page_flip_target_, true);
1725 void AppsGridView::MoveItemInModel(views::View* item_view,
1726 const Index& target) {
1727 int current_model_index = view_model_.GetIndexOfView(item_view);
1728 DCHECK_GE(current_model_index, 0);
1730 int target_model_index = GetModelIndexFromIndex(target);
1731 if (target_model_index == current_model_index)
1734 item_list_->RemoveObserver(this);
1735 item_list_->MoveItem(current_model_index, target_model_index);
1736 view_model_.Move(current_model_index, target_model_index);
1737 item_list_->AddObserver(this);
1739 if (pagination_model_.selected_page() != target.page)
1740 pagination_model_.SelectPage(target.page, false);
1743 void AppsGridView::MoveItemToFolder(views::View* item_view,
1744 const Index& target) {
1745 const std::string& source_item_id =
1746 static_cast<AppListItemView*>(item_view)->item()->id();
1747 AppListItemView* target_view =
1748 static_cast<AppListItemView*>(GetViewAtSlotOnCurrentPage(target.slot));
1749 const std::string& target_view_item_id = target_view->item()->id();
1751 // Make change to data model.
1752 item_list_->RemoveObserver(this);
1753 std::string folder_item_id =
1754 model_->MergeItems(target_view_item_id, source_item_id);
1755 item_list_->AddObserver(this);
1756 if (folder_item_id.empty()) {
1757 LOG(ERROR) << "Unable to merge into item id: " << target_view_item_id;
1760 if (folder_item_id != target_view_item_id) {
1761 // New folder was created, change the view model to replace the old target
1762 // view with the new folder item view.
1763 size_t folder_item_index;
1764 if (item_list_->FindItemIndex(folder_item_id, &folder_item_index)) {
1765 int target_view_index = view_model_.GetIndexOfView(target_view);
1766 gfx::Rect target_view_bounds = target_view->bounds();
1767 DeleteItemViewAtIndex(target_view_index);
1768 views::View* target_folder_view =
1769 CreateViewForItemAtIndex(folder_item_index);
1770 target_folder_view->SetBoundsRect(target_view_bounds);
1771 view_model_.Add(target_folder_view, target_view_index);
1772 AddChildView(target_folder_view);
1774 LOG(ERROR) << "Folder no longer in item_list: " << folder_item_id;
1778 // Fade out the drag_view_ and delete it when animation ends.
1779 int drag_view_index = view_model_.GetIndexOfView(drag_view_);
1780 view_model_.Remove(drag_view_index);
1781 bounds_animator_.AnimateViewTo(drag_view_, drag_view_->bounds());
1782 bounds_animator_.SetAnimationDelegate(
1784 scoped_ptr<gfx::AnimationDelegate>(
1785 new ItemRemoveAnimationDelegate(drag_view_)));
1789 void AppsGridView::ReparentItemForReorder(views::View* item_view,
1790 const Index& target) {
1791 item_list_->RemoveObserver(this);
1792 model_->RemoveObserver(this);
1794 AppListItem* reparent_item = static_cast<AppListItemView*>(item_view)->item();
1795 DCHECK(reparent_item->IsInFolder());
1796 const std::string source_folder_id = reparent_item->folder_id();
1797 AppListFolderItem* source_folder =
1798 static_cast<AppListFolderItem*>(item_list_->FindItem(source_folder_id));
1800 int target_model_index = GetModelIndexFromIndex(target);
1802 // Remove the source folder view if there is only 1 item in it, since the
1803 // source folder will be deleted after its only child item removed from it.
1804 if (source_folder->ChildItemCount() == 1u) {
1805 const int deleted_folder_index =
1806 view_model_.GetIndexOfView(activated_folder_item_view());
1807 DeleteItemViewAtIndex(deleted_folder_index);
1809 // Adjust |target_model_index| if it is beyond the deleted folder index.
1810 if (target_model_index > deleted_folder_index)
1811 --target_model_index;
1814 // Move the item from its parent folder to top level item list.
1815 // Must move to target_model_index, the location we expect the target item
1816 // to be, not the item location we want to insert before.
1817 int current_model_index = view_model_.GetIndexOfView(item_view);
1818 syncer::StringOrdinal target_position;
1819 if (target_model_index < static_cast<int>(item_list_->item_count()))
1820 target_position = item_list_->item_at(target_model_index)->position();
1821 model_->MoveItemToFolderAt(reparent_item, "", target_position);
1822 view_model_.Move(current_model_index, target_model_index);
1824 RemoveLastItemFromReparentItemFolderIfNecessary(source_folder_id);
1826 item_list_->AddObserver(this);
1827 model_->AddObserver(this);
1831 void AppsGridView::ReparentItemToAnotherFolder(views::View* item_view,
1832 const Index& target) {
1833 DCHECK(IsDraggingForReparentInRootLevelGridView());
1835 AppListItemView* target_view =
1836 static_cast<AppListItemView*>(GetViewAtSlotOnCurrentPage(target.slot));
1840 // Make change to data model.
1841 item_list_->RemoveObserver(this);
1843 AppListItem* reparent_item = static_cast<AppListItemView*>(item_view)->item();
1844 DCHECK(reparent_item->IsInFolder());
1845 const std::string source_folder_id = reparent_item->folder_id();
1846 AppListFolderItem* source_folder =
1847 static_cast<AppListFolderItem*>(item_list_->FindItem(source_folder_id));
1849 // Remove the source folder view if there is only 1 item in it, since the
1850 // source folder will be deleted after its only child item merged into the
1852 if (source_folder->ChildItemCount() == 1u)
1853 DeleteItemViewAtIndex(
1854 view_model_.GetIndexOfView(activated_folder_item_view()));
1856 AppListItem* target_item = target_view->item();
1858 // Move item to the target folder.
1859 std::string target_id_after_merge =
1860 model_->MergeItems(target_item->id(), reparent_item->id());
1861 if (target_id_after_merge.empty()) {
1862 LOG(ERROR) << "Unable to reparent to item id: " << target_item->id();
1863 item_list_->AddObserver(this);
1867 if (target_id_after_merge != target_item->id()) {
1868 // New folder was created, change the view model to replace the old target
1869 // view with the new folder item view.
1870 const std::string& new_folder_id = reparent_item->folder_id();
1871 size_t new_folder_index;
1872 if (item_list_->FindItemIndex(new_folder_id, &new_folder_index)) {
1873 int target_view_index = view_model_.GetIndexOfView(target_view);
1874 DeleteItemViewAtIndex(target_view_index);
1875 views::View* new_folder_view =
1876 CreateViewForItemAtIndex(new_folder_index);
1877 view_model_.Add(new_folder_view, target_view_index);
1878 AddChildView(new_folder_view);
1880 LOG(ERROR) << "Folder no longer in item_list: " << new_folder_id;
1884 RemoveLastItemFromReparentItemFolderIfNecessary(source_folder_id);
1886 item_list_->AddObserver(this);
1888 // Fade out the drag_view_ and delete it when animation ends.
1889 int drag_view_index = view_model_.GetIndexOfView(drag_view_);
1890 view_model_.Remove(drag_view_index);
1891 bounds_animator_.AnimateViewTo(drag_view_, drag_view_->bounds());
1892 bounds_animator_.SetAnimationDelegate(
1894 scoped_ptr<gfx::AnimationDelegate>(
1895 new ItemRemoveAnimationDelegate(drag_view_)));
1899 // After moving the re-parenting item out of the folder, if there is only 1 item
1900 // left, remove the last item out of the folder, delete the folder and insert it
1901 // to the data model at the same position. Make the same change to view_model_
1903 void AppsGridView::RemoveLastItemFromReparentItemFolderIfNecessary(
1904 const std::string& source_folder_id) {
1905 AppListFolderItem* source_folder =
1906 static_cast<AppListFolderItem*>(item_list_->FindItem(source_folder_id));
1907 if (!source_folder || source_folder->ChildItemCount() != 1u)
1910 // Delete view associated with the folder item to be removed.
1911 DeleteItemViewAtIndex(
1912 view_model_.GetIndexOfView(activated_folder_item_view()));
1914 // Now make the data change to remove the folder item in model.
1915 AppListItem* last_item = source_folder->item_list()->item_at(0);
1916 model_->MoveItemToFolderAt(last_item, "", source_folder->position());
1918 // Create a new item view for the last item in folder.
1919 size_t last_item_index;
1920 if (!item_list_->FindItemIndex(last_item->id(), &last_item_index) ||
1921 last_item_index > static_cast<size_t>(view_model_.view_size())) {
1925 views::View* last_item_view = CreateViewForItemAtIndex(last_item_index);
1926 view_model_.Add(last_item_view, last_item_index);
1927 AddChildView(last_item_view);
1930 void AppsGridView::CancelFolderItemReparent(AppListItemView* drag_item_view) {
1931 // The icon of the dragged item must target to its final ideal bounds after
1932 // the animation completes.
1933 CalculateIdealBounds();
1935 gfx::Rect target_icon_rect =
1936 GetTargetIconRectInFolder(drag_item_view, activated_folder_item_view_);
1938 gfx::Rect drag_view_icon_to_grid =
1939 drag_item_view->ConvertRectToParent(drag_item_view->GetIconBounds());
1940 drag_view_icon_to_grid.ClampToCenteredSize(
1941 gfx::Size(kGridIconDimension, kGridIconDimension));
1942 TopIconAnimationView* icon_view = new TopIconAnimationView(
1943 drag_item_view->item()->icon(),
1945 false); /* animate like closing folder */
1946 AddChildView(icon_view);
1947 icon_view->SetBoundsRect(drag_view_icon_to_grid);
1948 icon_view->TransformView();
1951 void AppsGridView::CancelContextMenusOnCurrentPage() {
1952 int start = pagination_model_.selected_page() * tiles_per_page();
1953 int end = std::min(view_model_.view_size(), start + tiles_per_page());
1954 for (int i = start; i < end; ++i) {
1955 AppListItemView* view =
1956 static_cast<AppListItemView*>(view_model_.view_at(i));
1957 view->CancelContextMenu();
1961 void AppsGridView::DeleteItemViewAtIndex(int index) {
1962 views::View* item_view = view_model_.view_at(index);
1963 view_model_.Remove(index);
1964 if (item_view == drag_view_)
1969 bool AppsGridView::IsPointWithinDragBuffer(const gfx::Point& point) const {
1970 gfx::Rect rect(GetLocalBounds());
1971 rect.Inset(-kDragBufferPx, -kDragBufferPx, -kDragBufferPx, -kDragBufferPx);
1972 return rect.Contains(point);
1975 void AppsGridView::ButtonPressed(views::Button* sender,
1976 const ui::Event& event) {
1980 if (strcmp(sender->GetClassName(), AppListItemView::kViewClassName))
1984 // Always set the previous activated_folder_item_view_ to be visible. This
1985 // prevents a case where the item would remain hidden due the
1986 // |activated_folder_item_view_| changing during the animation. We only
1987 // need to track |activated_folder_item_view_| in the root level grid view.
1988 if (!folder_delegate_) {
1989 if (activated_folder_item_view_)
1990 activated_folder_item_view_->SetVisible(true);
1991 AppListItemView* pressed_item_view =
1992 static_cast<AppListItemView*>(sender);
1993 if (IsFolderItem(pressed_item_view->item()))
1994 activated_folder_item_view_ = pressed_item_view;
1996 activated_folder_item_view_ = NULL;
1998 delegate_->ActivateApp(static_cast<AppListItemView*>(sender)->item(),
2003 void AppsGridView::OnListItemAdded(size_t index, AppListItem* item) {
2006 views::View* view = CreateViewForItemAtIndex(index);
2007 view_model_.Add(view, index);
2011 UpdatePulsingBlockViews();
2016 void AppsGridView::OnListItemRemoved(size_t index, AppListItem* item) {
2019 DeleteItemViewAtIndex(index);
2022 UpdatePulsingBlockViews();
2027 void AppsGridView::OnListItemMoved(size_t from_index,
2029 AppListItem* item) {
2031 view_model_.Move(from_index, to_index);
2034 AnimateToIdealBounds();
2037 void AppsGridView::TotalPagesChanged() {
2040 void AppsGridView::SelectedPageChanged(int old_selected, int new_selected) {
2042 CalculateDropTarget();
2044 MaybeStartPageFlipTimer(last_drag_point_);
2046 ClearSelectedView(selected_view_);
2051 void AppsGridView::TransitionStarted() {
2052 CancelContextMenusOnCurrentPage();
2055 void AppsGridView::TransitionChanged() {
2056 // Update layout for valid page transition only since over-scroll no longer
2057 // animates app icons.
2058 const PaginationModel::Transition& transition =
2059 pagination_model_.transition();
2060 if (pagination_model_.is_valid_page(transition.target_page))
2064 void AppsGridView::OnAppListModelStatusChanged() {
2065 UpdatePulsingBlockViews();
2070 void AppsGridView::SetViewHidden(views::View* view, bool hide, bool immediate) {
2071 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator());
2072 animator.SetPreemptionStrategy(
2073 immediate ? ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET :
2074 ui::LayerAnimator::BLEND_WITH_CURRENT_ANIMATION);
2075 view->layer()->SetOpacity(hide ? 0 : 1);
2078 void AppsGridView::OnImplicitAnimationsCompleted() {
2079 if (layer()->opacity() == 0.0f)
2083 bool AppsGridView::EnableFolderDragDropUI() {
2084 // Enable drag and drop folder UI only if it is at the app list root level
2085 // and the switch is on.
2086 return model_->folders_enabled() && !folder_delegate_;
2089 bool AppsGridView::CanDropIntoTarget(const Index& drop_target) const {
2090 views::View* target_view = GetViewAtSlotOnCurrentPage(drop_target.slot);
2095 AppListItem* target_item =
2096 static_cast<AppListItemView*>(target_view)->item();
2097 // Items can be dropped into non-folders (which have no children) or folders
2098 // that have fewer than the max allowed items.
2099 // OEM folder does not allow to drag/drop other items in it.
2100 return target_item->ChildItemCount() < kMaxFolderItems &&
2101 !IsOEMFolderItem(target_item);
2104 AppsGridView::Index AppsGridView::GetNearestTileIndexForPoint(
2105 const gfx::Point& point) const {
2106 gfx::Rect bounds = GetContentsBounds();
2107 gfx::Size total_tile_size = GetTotalTileSize();
2108 int col = ClampToRange(
2109 (point.x() - bounds.x()) / total_tile_size.width(), 0, cols_ - 1);
2110 int row = ClampToRange((point.y() - bounds.y()) / total_tile_size.height(),
2112 rows_per_page_ - 1);
2113 return Index(pagination_model_.selected_page(), row * cols_ + col);
2116 gfx::Size AppsGridView::GetTileGridSize() const {
2117 gfx::Rect bounds = GetExpectedTileBounds(0, 0);
2118 bounds.Union(GetExpectedTileBounds(rows_per_page_ - 1, cols_ - 1));
2119 if (switches::IsExperimentalAppListEnabled())
2120 bounds.Inset(-kExperimentalTileLeftRightPadding,
2121 -kExperimentalTileTopBottomPadding);
2122 return bounds.size();
2125 gfx::Rect AppsGridView::GetExpectedTileBounds(int slot) const {
2126 return GetExpectedTileBounds(slot / cols_, slot % cols_);
2129 gfx::Rect AppsGridView::GetExpectedTileBounds(int row, int col) const {
2130 gfx::Rect bounds(GetContentsBounds());
2131 gfx::Size total_tile_size = GetTotalTileSize();
2132 gfx::Rect tile_bounds(gfx::Point(bounds.x() + col * total_tile_size.width(),
2133 bounds.y() + row * total_tile_size.height()),
2135 tile_bounds.ClampToCenteredSize(GetTileViewSize());
2139 views::View* AppsGridView::GetViewAtSlotOnCurrentPage(int slot) const {
2143 // Calculate the original bound of the tile at |index|.
2144 int row = slot / cols_;
2145 int col = slot % cols_;
2146 gfx::Rect tile_rect = GetExpectedTileBounds(row, col);
2148 for (int i = 0; i < view_model_.view_size(); ++i) {
2149 views::View* view = view_model_.view_at(i);
2150 if (view->bounds() == tile_rect && view != drag_view_)
2156 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index,
2157 bool is_target_folder) {
2158 AppListItemView* target_view =
2159 static_cast<AppListItemView*>(
2160 GetViewAtSlotOnCurrentPage(target_index.slot));
2162 target_view->SetAsAttemptedFolderTarget(is_target_folder);
2165 } // namespace app_list