Commit c9098ae3 authored by Kevin Strohbehn's avatar Kevin Strohbehn Committed by Commit Bot

Fixes stale icon during reparent drag out of a folder

Bug: 868117
Change-Id: I15aae661ae200ec858e6886be718eaa55ff3266a
Reviewed-on: https://chromium-review.googlesource.com/1152231
Commit-Queue: Kevin Strohbehn <ginko@google.com>
Reviewed-by: default avatarYury Khmel <khmel@chromium.org>
Reviewed-by: default avatarWeidong Guo <weidongg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579655}
parent 209b438b
...@@ -70,4 +70,8 @@ void AppListFolderItem::OnFolderImageUpdated() { ...@@ -70,4 +70,8 @@ void AppListFolderItem::OnFolderImageUpdated() {
SetIcon(folder_image_.icon()); SetIcon(folder_image_.icon());
} }
void AppListFolderItem::NotifyOfDraggedItem(AppListItem* dragged_item) {
folder_image_.UpdateDraggedItem(dragged_item);
}
} // namespace app_list } // namespace app_list
...@@ -73,6 +73,10 @@ class APP_LIST_MODEL_EXPORT AppListFolderItem : public AppListItem, ...@@ -73,6 +73,10 @@ class APP_LIST_MODEL_EXPORT AppListFolderItem : public AppListItem,
// FolderImageObserver overrides: // FolderImageObserver overrides:
void OnFolderImageUpdated() override; void OnFolderImageUpdated() override;
// Informs the folder item of an item being dragged, that it may notify its
// image.
void NotifyOfDraggedItem(AppListItem* dragged_item);
private: private:
// The type of folder; may affect behavior of folder views. // The type of folder; may affect behavior of folder views.
const FolderType folder_type_; const FolderType folder_type_;
......
...@@ -163,15 +163,26 @@ void FolderImage::UpdateIcon() { ...@@ -163,15 +163,26 @@ void FolderImage::UpdateIcon() {
item->RemoveObserver(this); item->RemoveObserver(this);
top_items_.clear(); top_items_.clear();
for (size_t i = 0; i < std::min(kNumFolderTopItems, item_list_->item_count()); for (size_t i = 0;
i < item_list_->item_count() && top_items_.size() < kNumFolderTopItems;
++i) { ++i) {
AppListItem* item = item_list_->item_at(i); AppListItem* item = item_list_->item_at(i);
// If this item is currently being dragged, pretend it has already left our
// folder
if (item == dragged_item_)
continue;
item->AddObserver(this); item->AddObserver(this);
top_items_.push_back(item); top_items_.push_back(item);
} }
RedrawIconAndNotify(); RedrawIconAndNotify();
} }
void FolderImage::UpdateDraggedItem(const AppListItem* dragged_item) {
DCHECK(dragged_item_ != dragged_item);
dragged_item_ = dragged_item;
UpdateIcon();
}
// static // static
std::vector<gfx::Rect> FolderImage::GetTopIconsBounds( std::vector<gfx::Rect> FolderImage::GetTopIconsBounds(
const gfx::Rect& folder_icon_bounds, const gfx::Rect& folder_icon_bounds,
......
...@@ -52,6 +52,10 @@ class APP_LIST_MODEL_EXPORT FolderImage : public AppListItemListObserver, ...@@ -52,6 +52,10 @@ class APP_LIST_MODEL_EXPORT FolderImage : public AppListItemListObserver,
// and notifies observers that the icon has changed. // and notifies observers that the icon has changed.
void UpdateIcon(); void UpdateIcon();
// Given an AppListItem currently being dragged, updates |dragged_item_| then
// executes an ordinary run of UpdateIcon()
void UpdateDraggedItem(const AppListItem* dragged_item);
const gfx::ImageSkia& icon() const { return icon_; } const gfx::ImageSkia& icon() const { return icon_; }
// Calculates the top item icons' bounds inside |folder_icon_bounds|. // Calculates the top item icons' bounds inside |folder_icon_bounds|.
...@@ -96,6 +100,9 @@ class APP_LIST_MODEL_EXPORT FolderImage : public AppListItemListObserver, ...@@ -96,6 +100,9 @@ class APP_LIST_MODEL_EXPORT FolderImage : public AppListItemListObserver,
// List of top-level app list items (to display small in the icon). // List of top-level app list items (to display small in the icon).
AppListItemList* item_list_; AppListItemList* item_list_;
// Item being dragged, if any.
const AppListItem* dragged_item_ = nullptr;
// Top items for generating folder icon. // Top items for generating folder icon.
std::vector<AppListItem*> top_items_; std::vector<AppListItem*> top_items_;
......
...@@ -728,6 +728,9 @@ void AppListFolderView::ReparentItem( ...@@ -728,6 +728,9 @@ void AppListFolderView::ReparentItem(
gfx::Point to_root_level_grid = drag_point_in_folder_grid; gfx::Point to_root_level_grid = drag_point_in_folder_grid;
ConvertPointToTarget(items_grid_view_, container_view_->apps_grid_view(), ConvertPointToTarget(items_grid_view_, container_view_->apps_grid_view(),
&to_root_level_grid); &to_root_level_grid);
// Ensures the icon updates to reflect that the icon has been removed during
// the drag
folder_item_->NotifyOfDraggedItem(original_drag_view->item());
StartSetupDragInRootLevelAppsGridView(original_drag_view, to_root_level_grid, StartSetupDragInRootLevelAppsGridView(original_drag_view, to_root_level_grid,
has_native_drag); has_native_drag);
container_view_->ReparentFolderItemTransit(folder_item_); container_view_->ReparentFolderItemTransit(folder_item_);
......
...@@ -1629,6 +1629,10 @@ void AppsGridView::EndDragFromReparentItemInRootLevel( ...@@ -1629,6 +1629,10 @@ void AppsGridView::EndDragFromReparentItemInRootLevel(
if (!drag_view_) if (!drag_view_)
return; return;
DCHECK(activated_folder_item_view_);
static_cast<AppListFolderItem*>(activated_folder_item_view_->item())
->NotifyOfDraggedItem(nullptr);
DCHECK(IsDraggingForReparentInRootLevelGridView()); DCHECK(IsDraggingForReparentInRootLevelGridView());
bool cancel_reparent = cancel_drag || drop_attempt_ == DROP_FOR_NONE; bool cancel_reparent = cancel_drag || drop_attempt_ == DROP_FOR_NONE;
if (!events_forwarded_to_drag_drop_host && !cancel_reparent) { if (!events_forwarded_to_drag_drop_host && !cancel_reparent) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment