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 gfx::Size grid_size = GetTileGridSize();
1187 // Page size including padding pixels. A tile.x + page_width means the same
1188 // tile slot in the next page; similarly for tile.y + page_height.
1189 const int page_width = grid_size.width() + kPagePadding;
1190 const int page_height = grid_size.height() + kPagePadding;
1192 // If there is a transition, calculates offset for current and target page.
1193 const int current_page = pagination_model_.selected_page();
1194 const PaginationModel::Transition& transition =
1195 pagination_model_.transition();
1196 const bool is_valid = pagination_model_.is_valid_page(transition.target_page);
1198 // Transition to previous page means negative offset.
1199 const int dir = transition.target_page > current_page ? -1 : 1;
1201 const int total_views =
1202 view_model_.view_size() + pulsing_blocks_model_.view_size();
1204 for (int i = 0; i < total_views; ++i) {
1205 if (i < view_model_.view_size() && view_model_.view_at(i) == drag_view_)
1208 Index view_index = GetIndexFromModelIndex(slot_index);
1210 // Leaves a blank space in the grid for the current reorder placeholder.
1211 if (reorder_placeholder_ == view_index) {
1213 view_index = GetIndexFromModelIndex(slot_index);
1216 // Decide the x or y offset for current item.
1220 if (pagination_controller_->scroll_axis() ==
1221 PaginationController::SCROLL_AXIS_HORIZONTAL) {
1222 if (view_index.page < current_page)
1223 x_offset = -page_width;
1224 else if (view_index.page > current_page)
1225 x_offset = page_width;
1228 if (view_index.page == current_page ||
1229 view_index.page == transition.target_page) {
1230 x_offset += transition.progress * page_width * dir;
1234 if (view_index.page < current_page)
1235 y_offset = -page_height;
1236 else if (view_index.page > current_page)
1237 y_offset = page_height;
1240 if (view_index.page == current_page ||
1241 view_index.page == transition.target_page) {
1242 y_offset += transition.progress * page_height * dir;
1247 const int row = view_index.slot / cols_;
1248 const int col = view_index.slot % cols_;
1249 gfx::Rect tile_slot = GetExpectedTileBounds(row, col);
1250 tile_slot.Offset(x_offset, y_offset);
1251 if (i < view_model_.view_size()) {
1252 view_model_.set_ideal_bounds(i, tile_slot);
1254 pulsing_blocks_model_.set_ideal_bounds(i - view_model_.view_size(),
1262 void AppsGridView::AnimateToIdealBounds() {
1263 const gfx::Rect visible_bounds(GetVisibleBounds());
1265 CalculateIdealBounds();
1266 for (int i = 0; i < view_model_.view_size(); ++i) {
1267 views::View* view = view_model_.view_at(i);
1268 if (view == drag_view_)
1271 const gfx::Rect& target = view_model_.ideal_bounds(i);
1272 if (bounds_animator_.GetTargetBounds(view) == target)
1275 const gfx::Rect& current = view->bounds();
1276 const bool current_visible = visible_bounds.Intersects(current);
1277 const bool target_visible = visible_bounds.Intersects(target);
1278 const bool visible = current_visible || target_visible;
1280 const int y_diff = target.y() - current.y();
1281 if (visible && y_diff && y_diff % GetTotalTileSize().height() == 0) {
1282 AnimationBetweenRows(view,
1287 } else if (visible || bounds_animator_.IsAnimating(view)) {
1288 bounds_animator_.AnimateViewTo(view, target);
1289 bounds_animator_.SetAnimationDelegate(
1291 scoped_ptr<gfx::AnimationDelegate>(
1292 new ItemMoveAnimationDelegate(view)));
1294 view->SetBoundsRect(target);
1299 void AppsGridView::AnimationBetweenRows(views::View* view,
1300 bool animate_current,
1301 const gfx::Rect& current,
1302 bool animate_target,
1303 const gfx::Rect& target) {
1304 // Determine page of |current| and |target|. -1 means in the left invisible
1305 // page, 0 is the center visible page and 1 means in the right invisible page.
1306 const int current_page = current.x() < 0 ? -1 :
1307 current.x() >= width() ? 1 : 0;
1308 const int target_page = target.x() < 0 ? -1 :
1309 target.x() >= width() ? 1 : 0;
1311 const int dir = current_page < target_page ||
1312 (current_page == target_page && current.y() < target.y()) ? 1 : -1;
1314 scoped_ptr<ui::Layer> layer;
1315 if (animate_current) {
1316 layer = view->RecreateLayer();
1317 layer->SuppressPaint();
1319 view->SetFillsBoundsOpaquely(false);
1320 view->layer()->SetOpacity(0.f);
1323 gfx::Size total_tile_size = GetTotalTileSize();
1324 gfx::Rect current_out(current);
1325 current_out.Offset(dir * total_tile_size.width(), 0);
1327 gfx::Rect target_in(target);
1329 target_in.Offset(-dir * total_tile_size.width(), 0);
1330 view->SetBoundsRect(target_in);
1331 bounds_animator_.AnimateViewTo(view, target);
1333 bounds_animator_.SetAnimationDelegate(
1335 scoped_ptr<gfx::AnimationDelegate>(
1336 new RowMoveAnimationDelegate(view, layer.release(), current_out)));
1339 void AppsGridView::ExtractDragLocation(const ui::LocatedEvent& event,
1340 gfx::Point* drag_point) {
1341 #if defined(USE_AURA) && !defined(OS_WIN)
1342 // Use root location of |event| instead of location in |drag_view_|'s
1343 // coordinates because |drag_view_| has a scale transform and location
1344 // could have integer round error and causes jitter.
1345 *drag_point = event.root_location();
1347 // GetWidget() could be NULL for tests.
1349 aura::Window::ConvertPointToTarget(
1350 GetWidget()->GetNativeWindow()->GetRootWindow(),
1351 GetWidget()->GetNativeWindow(),
1355 views::View::ConvertPointFromWidget(this, drag_point);
1357 // For non-aura, root location is not clearly defined but |drag_view_| does
1358 // not have the scale transform. So no round error would be introduced and
1359 // it's okay to use View::ConvertPointToTarget.
1360 *drag_point = event.location();
1361 views::View::ConvertPointToTarget(drag_view_, this, drag_point);
1365 void AppsGridView::CalculateDropTarget() {
1368 gfx::Point point = drag_view_->icon()->bounds().CenterPoint();
1369 views::View::ConvertPointToTarget(drag_view_, this, &point);
1370 if (!IsPointWithinDragBuffer(point)) {
1371 // Reset the reorder target to the original position if the cursor is
1372 // outside the drag buffer.
1373 if (IsDraggingForReparentInRootLevelGridView()) {
1374 drop_attempt_ = DROP_FOR_NONE;
1378 reorder_drop_target_ = drag_view_init_index_;
1379 drop_attempt_ = DROP_FOR_REORDER;
1383 if (EnableFolderDragDropUI() &&
1384 CalculateFolderDropTarget(point, &folder_drop_target_)) {
1385 drop_attempt_ = DROP_FOR_FOLDER;
1389 drop_attempt_ = DROP_FOR_REORDER;
1390 CalculateReorderDropTarget(point, &reorder_drop_target_);
1393 bool AppsGridView::CalculateFolderDropTarget(const gfx::Point& point,
1394 Index* drop_target) const {
1395 Index nearest_tile_index(GetNearestTileIndexForPoint(point));
1396 int distance_to_tile_center =
1397 (point - GetExpectedTileBounds(nearest_tile_index.slot).CenterPoint())
1399 if (nearest_tile_index != reorder_placeholder_ &&
1400 distance_to_tile_center < kFolderDroppingCircleRadius &&
1401 !IsFolderItem(drag_view_->item()) &&
1402 CanDropIntoTarget(nearest_tile_index)) {
1403 *drop_target = nearest_tile_index;
1404 DCHECK(IsValidIndex(*drop_target));
1411 void AppsGridView::CalculateReorderDropTarget(const gfx::Point& point,
1412 Index* drop_target) const {
1413 gfx::Rect bounds = GetContentsBounds();
1414 Index grid_index = GetNearestTileIndexForPoint(point);
1415 gfx::Point reorder_placeholder_center =
1416 GetExpectedTileBounds(reorder_placeholder_.slot).CenterPoint();
1418 int x_offset_direction = 0;
1419 if (grid_index == reorder_placeholder_) {
1420 x_offset_direction = reorder_placeholder_center.x() < point.x() ? -1 : 1;
1422 x_offset_direction = reorder_placeholder_ < grid_index ? -1 : 1;
1425 gfx::Size total_tile_size = GetTotalTileSize();
1426 int row = grid_index.slot / cols_;
1428 // Offset the target column based on the direction of the target. This will
1429 // result in earlier targets getting their reorder zone shifted backwards
1430 // and later targets getting their reorder zones shifted forwards.
1432 // This makes eordering feel like the user is slotting items into the spaces
1434 int x_offset = x_offset_direction *
1435 (total_tile_size.width() - kFolderDroppingCircleRadius) / 2;
1436 int col = (point.x() - bounds.x() + x_offset) / total_tile_size.width();
1437 col = ClampToRange(col, 0, cols_ - 1);
1439 std::min(Index(pagination_model_.selected_page(), row * cols_ + col),
1440 GetLastViewIndex());
1441 DCHECK(IsValidIndex(*drop_target));
1444 void AppsGridView::OnReorderTimer() {
1445 if (drop_attempt_ == DROP_FOR_REORDER) {
1446 reorder_placeholder_ = reorder_drop_target_;
1447 AnimateToIdealBounds();
1451 void AppsGridView::OnFolderItemReparentTimer() {
1452 DCHECK(folder_delegate_);
1453 if (drag_out_of_folder_container_ && drag_view_) {
1454 folder_delegate_->ReparentItem(drag_view_, last_drag_point_);
1456 // Set the flag in the folder's grid view.
1457 dragging_for_reparent_item_ = true;
1459 // Do not observe any data change since it is going to be hidden.
1460 item_list_->RemoveObserver(this);
1465 void AppsGridView::OnFolderDroppingTimer() {
1466 if (drop_attempt_ == DROP_FOR_FOLDER)
1467 SetAsFolderDroppingTarget(folder_drop_target_, true);
1470 void AppsGridView::UpdateDragStateInsideFolder(Pointer pointer,
1471 const gfx::Point& drag_point) {
1472 if (IsUnderOEMFolder())
1475 if (IsDraggingForReparentInHiddenGridView()) {
1476 // Dispatch drag event to root level grid view for re-parenting folder
1477 // folder item purpose.
1478 DispatchDragEventForReparent(pointer, drag_point);
1482 // Regular drag and drop in a folder's grid view.
1483 folder_delegate_->UpdateFolderViewBackground(true);
1485 // Calculate if the drag_view_ is dragged out of the folder's container
1487 gfx::Rect bounds_to_folder_view = ConvertRectToParent(drag_view_->bounds());
1488 gfx::Point pt = bounds_to_folder_view.CenterPoint();
1489 bool is_item_dragged_out_of_folder =
1490 folder_delegate_->IsPointOutsideOfFolderBoundary(pt);
1491 if (is_item_dragged_out_of_folder) {
1492 if (!drag_out_of_folder_container_) {
1493 folder_item_reparent_timer_.Start(
1495 base::TimeDelta::FromMilliseconds(kFolderItemReparentDelay),
1497 &AppsGridView::OnFolderItemReparentTimer);
1498 drag_out_of_folder_container_ = true;
1501 folder_item_reparent_timer_.Stop();
1502 drag_out_of_folder_container_ = false;
1506 bool AppsGridView::IsDraggingForReparentInRootLevelGridView() const {
1507 return (!folder_delegate_ && dragging_for_reparent_item_);
1510 bool AppsGridView::IsDraggingForReparentInHiddenGridView() const {
1511 return (folder_delegate_ && dragging_for_reparent_item_);
1514 gfx::Rect AppsGridView::GetTargetIconRectInFolder(
1515 AppListItemView* drag_item_view,
1516 AppListItemView* folder_item_view) {
1517 gfx::Rect view_ideal_bounds = view_model_.ideal_bounds(
1518 view_model_.GetIndexOfView(folder_item_view));
1519 gfx::Rect icon_ideal_bounds =
1520 folder_item_view->GetIconBoundsForTargetViewBounds(view_ideal_bounds);
1521 AppListFolderItem* folder_item =
1522 static_cast<AppListFolderItem*>(folder_item_view->item());
1523 return folder_item->GetTargetIconRectInFolderForItem(
1524 drag_item_view->item(), icon_ideal_bounds);
1527 bool AppsGridView::IsUnderOEMFolder() {
1528 if (!folder_delegate_)
1531 return folder_delegate_->IsOEMFolder();
1534 void AppsGridView::DispatchDragEventForReparent(Pointer pointer,
1535 const gfx::Point& drag_point) {
1536 folder_delegate_->DispatchDragEventForReparent(pointer, drag_point);
1539 void AppsGridView::EndDragFromReparentItemInRootLevel(
1540 bool events_forwarded_to_drag_drop_host,
1542 // EndDrag was called before if |drag_view_| is NULL.
1546 DCHECK(IsDraggingForReparentInRootLevelGridView());
1547 bool cancel_reparent = cancel_drag || drop_attempt_ == DROP_FOR_NONE;
1548 if (!events_forwarded_to_drag_drop_host && !cancel_reparent) {
1549 CalculateDropTarget();
1550 if (drop_attempt_ == DROP_FOR_REORDER &&
1551 IsValidIndex(reorder_drop_target_)) {
1552 ReparentItemForReorder(drag_view_, reorder_drop_target_);
1553 } else if (drop_attempt_ == DROP_FOR_FOLDER &&
1554 IsValidIndex(folder_drop_target_)) {
1555 ReparentItemToAnotherFolder(drag_view_, folder_drop_target_);
1559 SetViewHidden(drag_view_, false /* show */, true /* no animate */);
1562 // The drag can be ended after the synchronous drag is created but before it
1564 CleanUpSynchronousDrag();
1566 SetAsFolderDroppingTarget(folder_drop_target_, false);
1567 if (cancel_reparent) {
1568 CancelFolderItemReparent(drag_view_);
1570 // By setting |drag_view_| to NULL here, we prevent ClearDragState() from
1571 // cleaning up the newly created AppListItemView, effectively claiming
1572 // ownership of the newly created drag view.
1573 drag_view_->OnDragEnded();
1577 AnimateToIdealBounds();
1579 StopPageFlipTimer();
1582 void AppsGridView::EndDragForReparentInHiddenFolderGridView() {
1583 if (drag_and_drop_host_) {
1584 // If we had a drag and drop proxy icon, we delete it and make the real
1585 // item visible again.
1586 drag_and_drop_host_->DestroyDragIconProxy();
1589 // The drag can be ended after the synchronous drag is created but before it
1591 CleanUpSynchronousDrag();
1593 SetAsFolderDroppingTarget(folder_drop_target_, false);
1597 void AppsGridView::OnFolderItemRemoved() {
1598 DCHECK(folder_delegate_);
1602 void AppsGridView::StartDragAndDropHostDrag(const gfx::Point& grid_location) {
1603 // When a drag and drop host is given, the item can be dragged out of the app
1604 // list window. In that case a proxy widget needs to be used.
1605 // Note: This code has very likely to be changed for Windows (non metro mode)
1606 // when a |drag_and_drop_host_| gets implemented.
1607 if (!drag_view_ || !drag_and_drop_host_)
1610 gfx::Point screen_location = grid_location;
1611 views::View::ConvertPointToScreen(this, &screen_location);
1613 // Determine the mouse offset to the center of the icon so that the drag and
1614 // drop host follows this layer.
1615 gfx::Vector2d delta = drag_view_offset_ -
1616 drag_view_->GetLocalBounds().CenterPoint();
1617 delta.set_y(delta.y() + drag_view_->title()->size().height() / 2);
1619 // We have to hide the original item since the drag and drop host will do
1620 // the OS dependent code to "lift off the dragged item".
1621 DCHECK(!IsDraggingForReparentInRootLevelGridView());
1622 drag_and_drop_host_->CreateDragIconProxy(screen_location,
1623 drag_view_->item()->icon(),
1626 kDragAndDropProxyScale);
1627 SetViewHidden(drag_view_,
1629 true /* no animation */);
1632 void AppsGridView::DispatchDragEventToDragAndDropHost(
1633 const gfx::Point& location_in_screen_coordinates) {
1634 if (!drag_view_ || !drag_and_drop_host_)
1637 if (GetLocalBounds().Contains(last_drag_point_)) {
1638 // The event was issued inside the app menu and we should get all events.
1639 if (forward_events_to_drag_and_drop_host_) {
1640 // The DnD host was previously called and needs to be informed that the
1641 // session returns to the owner.
1642 forward_events_to_drag_and_drop_host_ = false;
1643 drag_and_drop_host_->EndDrag(true);
1646 if (IsFolderItem(drag_view_->item()))
1649 // The event happened outside our app menu and we might need to dispatch.
1650 if (forward_events_to_drag_and_drop_host_) {
1651 // Dispatch since we have already started.
1652 if (!drag_and_drop_host_->Drag(location_in_screen_coordinates)) {
1653 // The host is not active any longer and we cancel the operation.
1654 forward_events_to_drag_and_drop_host_ = false;
1655 drag_and_drop_host_->EndDrag(true);
1658 if (drag_and_drop_host_->StartDrag(drag_view_->item()->id(),
1659 location_in_screen_coordinates)) {
1660 // From now on we forward the drag events.
1661 forward_events_to_drag_and_drop_host_ = true;
1662 // Any flip operations are stopped.
1663 StopPageFlipTimer();
1669 void AppsGridView::MaybeStartPageFlipTimer(const gfx::Point& drag_point) {
1670 if (!IsPointWithinDragBuffer(drag_point))
1671 StopPageFlipTimer();
1672 int new_page_flip_target = -1;
1674 // Drag zones are at the edges of the scroll axis.
1675 if (pagination_controller_->scroll_axis() ==
1676 PaginationController::SCROLL_AXIS_VERTICAL) {
1677 if (drag_point.y() < kPageFlipZoneSize)
1678 new_page_flip_target = pagination_model_.selected_page() - 1;
1679 else if (drag_point.y() > height() - kPageFlipZoneSize)
1680 new_page_flip_target = pagination_model_.selected_page() + 1;
1682 if (page_switcher_view_->bounds().Contains(drag_point)) {
1683 gfx::Point page_switcher_point(drag_point);
1684 views::View::ConvertPointToTarget(
1685 this, page_switcher_view_, &page_switcher_point);
1686 new_page_flip_target =
1687 page_switcher_view_->GetPageForPoint(page_switcher_point);
1690 // TODO(xiyuan): Fix this for RTL.
1691 if (new_page_flip_target == -1 && drag_point.x() < kPageFlipZoneSize)
1692 new_page_flip_target = pagination_model_.selected_page() - 1;
1694 if (new_page_flip_target == -1 &&
1695 drag_point.x() > width() - kPageFlipZoneSize) {
1696 new_page_flip_target = pagination_model_.selected_page() + 1;
1700 if (new_page_flip_target == page_flip_target_)
1703 StopPageFlipTimer();
1704 if (pagination_model_.is_valid_page(new_page_flip_target)) {
1705 page_flip_target_ = new_page_flip_target;
1707 if (page_flip_target_ != pagination_model_.selected_page()) {
1708 page_flip_timer_.Start(FROM_HERE,
1709 base::TimeDelta::FromMilliseconds(page_flip_delay_in_ms_),
1710 this, &AppsGridView::OnPageFlipTimer);
1715 void AppsGridView::OnPageFlipTimer() {
1716 DCHECK(pagination_model_.is_valid_page(page_flip_target_));
1717 pagination_model_.SelectPage(page_flip_target_, true);
1720 void AppsGridView::MoveItemInModel(views::View* item_view,
1721 const Index& target) {
1722 int current_model_index = view_model_.GetIndexOfView(item_view);
1723 DCHECK_GE(current_model_index, 0);
1725 int target_model_index = GetModelIndexFromIndex(target);
1726 if (target_model_index == current_model_index)
1729 item_list_->RemoveObserver(this);
1730 item_list_->MoveItem(current_model_index, target_model_index);
1731 view_model_.Move(current_model_index, target_model_index);
1732 item_list_->AddObserver(this);
1734 if (pagination_model_.selected_page() != target.page)
1735 pagination_model_.SelectPage(target.page, false);
1738 void AppsGridView::MoveItemToFolder(views::View* item_view,
1739 const Index& target) {
1740 const std::string& source_item_id =
1741 static_cast<AppListItemView*>(item_view)->item()->id();
1742 AppListItemView* target_view =
1743 static_cast<AppListItemView*>(GetViewAtSlotOnCurrentPage(target.slot));
1744 const std::string& target_view_item_id = target_view->item()->id();
1746 // Make change to data model.
1747 item_list_->RemoveObserver(this);
1748 std::string folder_item_id =
1749 model_->MergeItems(target_view_item_id, source_item_id);
1750 item_list_->AddObserver(this);
1751 if (folder_item_id.empty()) {
1752 LOG(ERROR) << "Unable to merge into item id: " << target_view_item_id;
1755 if (folder_item_id != target_view_item_id) {
1756 // New folder was created, change the view model to replace the old target
1757 // view with the new folder item view.
1758 size_t folder_item_index;
1759 if (item_list_->FindItemIndex(folder_item_id, &folder_item_index)) {
1760 int target_view_index = view_model_.GetIndexOfView(target_view);
1761 gfx::Rect target_view_bounds = target_view->bounds();
1762 DeleteItemViewAtIndex(target_view_index);
1763 views::View* target_folder_view =
1764 CreateViewForItemAtIndex(folder_item_index);
1765 target_folder_view->SetBoundsRect(target_view_bounds);
1766 view_model_.Add(target_folder_view, target_view_index);
1767 AddChildView(target_folder_view);
1769 LOG(ERROR) << "Folder no longer in item_list: " << folder_item_id;
1773 // Fade out the drag_view_ and delete it when animation ends.
1774 int drag_view_index = view_model_.GetIndexOfView(drag_view_);
1775 view_model_.Remove(drag_view_index);
1776 bounds_animator_.AnimateViewTo(drag_view_, drag_view_->bounds());
1777 bounds_animator_.SetAnimationDelegate(
1779 scoped_ptr<gfx::AnimationDelegate>(
1780 new ItemRemoveAnimationDelegate(drag_view_)));
1784 void AppsGridView::ReparentItemForReorder(views::View* item_view,
1785 const Index& target) {
1786 item_list_->RemoveObserver(this);
1787 model_->RemoveObserver(this);
1789 AppListItem* reparent_item = static_cast<AppListItemView*>(item_view)->item();
1790 DCHECK(reparent_item->IsInFolder());
1791 const std::string source_folder_id = reparent_item->folder_id();
1792 AppListFolderItem* source_folder =
1793 static_cast<AppListFolderItem*>(item_list_->FindItem(source_folder_id));
1795 int target_model_index = GetModelIndexFromIndex(target);
1797 // Remove the source folder view if there is only 1 item in it, since the
1798 // source folder will be deleted after its only child item removed from it.
1799 if (source_folder->ChildItemCount() == 1u) {
1800 const int deleted_folder_index =
1801 view_model_.GetIndexOfView(activated_folder_item_view());
1802 DeleteItemViewAtIndex(deleted_folder_index);
1804 // Adjust |target_model_index| if it is beyond the deleted folder index.
1805 if (target_model_index > deleted_folder_index)
1806 --target_model_index;
1809 // Move the item from its parent folder to top level item list.
1810 // Must move to target_model_index, the location we expect the target item
1811 // to be, not the item location we want to insert before.
1812 int current_model_index = view_model_.GetIndexOfView(item_view);
1813 syncer::StringOrdinal target_position;
1814 if (target_model_index < static_cast<int>(item_list_->item_count()))
1815 target_position = item_list_->item_at(target_model_index)->position();
1816 model_->MoveItemToFolderAt(reparent_item, "", target_position);
1817 view_model_.Move(current_model_index, target_model_index);
1819 RemoveLastItemFromReparentItemFolderIfNecessary(source_folder_id);
1821 item_list_->AddObserver(this);
1822 model_->AddObserver(this);
1826 void AppsGridView::ReparentItemToAnotherFolder(views::View* item_view,
1827 const Index& target) {
1828 DCHECK(IsDraggingForReparentInRootLevelGridView());
1830 AppListItemView* target_view =
1831 static_cast<AppListItemView*>(GetViewAtSlotOnCurrentPage(target.slot));
1835 // Make change to data model.
1836 item_list_->RemoveObserver(this);
1838 AppListItem* reparent_item = static_cast<AppListItemView*>(item_view)->item();
1839 DCHECK(reparent_item->IsInFolder());
1840 const std::string source_folder_id = reparent_item->folder_id();
1841 AppListFolderItem* source_folder =
1842 static_cast<AppListFolderItem*>(item_list_->FindItem(source_folder_id));
1844 // Remove the source folder view if there is only 1 item in it, since the
1845 // source folder will be deleted after its only child item merged into the
1847 if (source_folder->ChildItemCount() == 1u)
1848 DeleteItemViewAtIndex(
1849 view_model_.GetIndexOfView(activated_folder_item_view()));
1851 AppListItem* target_item = target_view->item();
1853 // Move item to the target folder.
1854 std::string target_id_after_merge =
1855 model_->MergeItems(target_item->id(), reparent_item->id());
1856 if (target_id_after_merge.empty()) {
1857 LOG(ERROR) << "Unable to reparent to item id: " << target_item->id();
1858 item_list_->AddObserver(this);
1862 if (target_id_after_merge != target_item->id()) {
1863 // New folder was created, change the view model to replace the old target
1864 // view with the new folder item view.
1865 const std::string& new_folder_id = reparent_item->folder_id();
1866 size_t new_folder_index;
1867 if (item_list_->FindItemIndex(new_folder_id, &new_folder_index)) {
1868 int target_view_index = view_model_.GetIndexOfView(target_view);
1869 DeleteItemViewAtIndex(target_view_index);
1870 views::View* new_folder_view =
1871 CreateViewForItemAtIndex(new_folder_index);
1872 view_model_.Add(new_folder_view, target_view_index);
1873 AddChildView(new_folder_view);
1875 LOG(ERROR) << "Folder no longer in item_list: " << new_folder_id;
1879 RemoveLastItemFromReparentItemFolderIfNecessary(source_folder_id);
1881 item_list_->AddObserver(this);
1883 // Fade out the drag_view_ and delete it when animation ends.
1884 int drag_view_index = view_model_.GetIndexOfView(drag_view_);
1885 view_model_.Remove(drag_view_index);
1886 bounds_animator_.AnimateViewTo(drag_view_, drag_view_->bounds());
1887 bounds_animator_.SetAnimationDelegate(
1889 scoped_ptr<gfx::AnimationDelegate>(
1890 new ItemRemoveAnimationDelegate(drag_view_)));
1894 // After moving the re-parenting item out of the folder, if there is only 1 item
1895 // left, remove the last item out of the folder, delete the folder and insert it
1896 // to the data model at the same position. Make the same change to view_model_
1898 void AppsGridView::RemoveLastItemFromReparentItemFolderIfNecessary(
1899 const std::string& source_folder_id) {
1900 AppListFolderItem* source_folder =
1901 static_cast<AppListFolderItem*>(item_list_->FindItem(source_folder_id));
1902 if (!source_folder || source_folder->ChildItemCount() != 1u)
1905 // Delete view associated with the folder item to be removed.
1906 DeleteItemViewAtIndex(
1907 view_model_.GetIndexOfView(activated_folder_item_view()));
1909 // Now make the data change to remove the folder item in model.
1910 AppListItem* last_item = source_folder->item_list()->item_at(0);
1911 model_->MoveItemToFolderAt(last_item, "", source_folder->position());
1913 // Create a new item view for the last item in folder.
1914 size_t last_item_index;
1915 if (!item_list_->FindItemIndex(last_item->id(), &last_item_index) ||
1916 last_item_index > static_cast<size_t>(view_model_.view_size())) {
1920 views::View* last_item_view = CreateViewForItemAtIndex(last_item_index);
1921 view_model_.Add(last_item_view, last_item_index);
1922 AddChildView(last_item_view);
1925 void AppsGridView::CancelFolderItemReparent(AppListItemView* drag_item_view) {
1926 // The icon of the dragged item must target to its final ideal bounds after
1927 // the animation completes.
1928 CalculateIdealBounds();
1930 gfx::Rect target_icon_rect =
1931 GetTargetIconRectInFolder(drag_item_view, activated_folder_item_view_);
1933 gfx::Rect drag_view_icon_to_grid =
1934 drag_item_view->ConvertRectToParent(drag_item_view->GetIconBounds());
1935 drag_view_icon_to_grid.ClampToCenteredSize(
1936 gfx::Size(kGridIconDimension, kGridIconDimension));
1937 TopIconAnimationView* icon_view = new TopIconAnimationView(
1938 drag_item_view->item()->icon(),
1940 false); /* animate like closing folder */
1941 AddChildView(icon_view);
1942 icon_view->SetBoundsRect(drag_view_icon_to_grid);
1943 icon_view->TransformView();
1946 void AppsGridView::CancelContextMenusOnCurrentPage() {
1947 int start = pagination_model_.selected_page() * tiles_per_page();
1948 int end = std::min(view_model_.view_size(), start + tiles_per_page());
1949 for (int i = start; i < end; ++i) {
1950 AppListItemView* view =
1951 static_cast<AppListItemView*>(view_model_.view_at(i));
1952 view->CancelContextMenu();
1956 void AppsGridView::DeleteItemViewAtIndex(int index) {
1957 views::View* item_view = view_model_.view_at(index);
1958 view_model_.Remove(index);
1959 if (item_view == drag_view_)
1964 bool AppsGridView::IsPointWithinDragBuffer(const gfx::Point& point) const {
1965 gfx::Rect rect(GetLocalBounds());
1966 rect.Inset(-kDragBufferPx, -kDragBufferPx, -kDragBufferPx, -kDragBufferPx);
1967 return rect.Contains(point);
1970 void AppsGridView::ButtonPressed(views::Button* sender,
1971 const ui::Event& event) {
1975 if (strcmp(sender->GetClassName(), AppListItemView::kViewClassName))
1979 // Always set the previous activated_folder_item_view_ to be visible. This
1980 // prevents a case where the item would remain hidden due the
1981 // |activated_folder_item_view_| changing during the animation. We only
1982 // need to track |activated_folder_item_view_| in the root level grid view.
1983 if (!folder_delegate_) {
1984 if (activated_folder_item_view_)
1985 activated_folder_item_view_->SetVisible(true);
1986 AppListItemView* pressed_item_view =
1987 static_cast<AppListItemView*>(sender);
1988 if (IsFolderItem(pressed_item_view->item()))
1989 activated_folder_item_view_ = pressed_item_view;
1991 activated_folder_item_view_ = NULL;
1993 delegate_->ActivateApp(static_cast<AppListItemView*>(sender)->item(),
1998 void AppsGridView::OnListItemAdded(size_t index, AppListItem* item) {
2001 views::View* view = CreateViewForItemAtIndex(index);
2002 view_model_.Add(view, index);
2006 UpdatePulsingBlockViews();
2011 void AppsGridView::OnListItemRemoved(size_t index, AppListItem* item) {
2014 DeleteItemViewAtIndex(index);
2017 UpdatePulsingBlockViews();
2022 void AppsGridView::OnListItemMoved(size_t from_index,
2024 AppListItem* item) {
2026 view_model_.Move(from_index, to_index);
2029 AnimateToIdealBounds();
2032 void AppsGridView::TotalPagesChanged() {
2035 void AppsGridView::SelectedPageChanged(int old_selected, int new_selected) {
2037 CalculateDropTarget();
2039 MaybeStartPageFlipTimer(last_drag_point_);
2041 ClearSelectedView(selected_view_);
2046 void AppsGridView::TransitionStarted() {
2047 CancelContextMenusOnCurrentPage();
2050 void AppsGridView::TransitionChanged() {
2051 // Update layout for valid page transition only since over-scroll no longer
2052 // animates app icons.
2053 const PaginationModel::Transition& transition =
2054 pagination_model_.transition();
2055 if (pagination_model_.is_valid_page(transition.target_page))
2059 void AppsGridView::OnAppListModelStatusChanged() {
2060 UpdatePulsingBlockViews();
2065 void AppsGridView::SetViewHidden(views::View* view, bool hide, bool immediate) {
2066 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator());
2067 animator.SetPreemptionStrategy(
2068 immediate ? ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET :
2069 ui::LayerAnimator::BLEND_WITH_CURRENT_ANIMATION);
2070 view->layer()->SetOpacity(hide ? 0 : 1);
2073 void AppsGridView::OnImplicitAnimationsCompleted() {
2074 if (layer()->opacity() == 0.0f)
2078 bool AppsGridView::EnableFolderDragDropUI() {
2079 // Enable drag and drop folder UI only if it is at the app list root level
2080 // and the switch is on.
2081 return model_->folders_enabled() && !folder_delegate_;
2084 bool AppsGridView::CanDropIntoTarget(const Index& drop_target) const {
2085 views::View* target_view = GetViewAtIndex(drop_target);
2089 AppListItem* target_item =
2090 static_cast<AppListItemView*>(target_view)->item();
2091 // Items can be dropped into non-folders (which have no children) or folders
2092 // that have fewer than the max allowed items.
2093 // OEM folder does not allow to drag/drop other items in it.
2094 return target_item->ChildItemCount() < kMaxFolderItems &&
2095 !IsOEMFolderItem(target_item);
2098 AppsGridView::Index AppsGridView::GetNearestTileIndexForPoint(
2099 const gfx::Point& point) const {
2100 gfx::Rect bounds = GetContentsBounds();
2101 gfx::Size total_tile_size = GetTotalTileSize();
2102 int col = ClampToRange(
2103 (point.x() - bounds.x()) / total_tile_size.width(), 0, cols_ - 1);
2104 int row = ClampToRange((point.y() - bounds.y()) / total_tile_size.height(),
2106 rows_per_page_ - 1);
2107 return Index(pagination_model_.selected_page(), row * cols_ + col);
2110 gfx::Size AppsGridView::GetTileGridSize() const {
2111 gfx::Rect bounds = GetExpectedTileBounds(0, 0);
2112 bounds.Union(GetExpectedTileBounds(rows_per_page_ - 1, cols_ - 1));
2113 if (switches::IsExperimentalAppListEnabled())
2114 bounds.Inset(-kExperimentalTileLeftRightPadding,
2115 -kExperimentalTileTopBottomPadding);
2116 return bounds.size();
2119 gfx::Rect AppsGridView::GetExpectedTileBounds(int slot) const {
2120 return GetExpectedTileBounds(slot / cols_, slot % cols_);
2123 gfx::Rect AppsGridView::GetExpectedTileBounds(int row, int col) const {
2124 gfx::Rect bounds(GetContentsBounds());
2125 gfx::Size total_tile_size = GetTotalTileSize();
2126 gfx::Rect tile_bounds(gfx::Point(bounds.x() + col * total_tile_size.width(),
2127 bounds.y() + row * total_tile_size.height()),
2129 tile_bounds.ClampToCenteredSize(GetTileViewSize());
2133 views::View* AppsGridView::GetViewAtSlotOnCurrentPage(int slot) {
2137 // Calculate the original bound of the tile at |index|.
2138 int row = slot / cols_;
2139 int col = slot % cols_;
2140 gfx::Rect tile_rect = GetExpectedTileBounds(row, col);
2142 for (int i = 0; i < view_model_.view_size(); ++i) {
2143 views::View* view = view_model_.view_at(i);
2144 if (view->bounds() == tile_rect && view != drag_view_)
2150 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index,
2151 bool is_target_folder) {
2152 AppListItemView* target_view =
2153 static_cast<AppListItemView*>(
2154 GetViewAtSlotOnCurrentPage(target_index.slot));
2156 target_view->SetAsAttemptedFolderTarget(is_target_folder);
2159 } // namespace app_list