Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/app_list/views/apps_grid_view.h" | 5 #include "ui/app_list/views/apps_grid_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 int GetDistanceBetweenRects(gfx::Rect rect_1, | 175 int GetDistanceBetweenRects(gfx::Rect rect_1, |
| 176 gfx::Rect rect_2) { | 176 gfx::Rect rect_2) { |
| 177 return (rect_1.CenterPoint() - rect_2.CenterPoint()).Length(); | 177 return (rect_1.CenterPoint() - rect_2.CenterPoint()).Length(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 // Returns true if the |item| is an folder item. | 180 // Returns true if the |item| is an folder item. |
| 181 bool IsFolderItem(AppListItem* item) { | 181 bool IsFolderItem(AppListItem* item) { |
| 182 return (item->GetItemType() == AppListFolderItem::kItemType); | 182 return (item->GetItemType() == AppListFolderItem::kItemType); |
| 183 } | 183 } |
| 184 | 184 |
| 185 // Merges |source_item| into the folder containing the target item specified | |
| 186 // by |target_item_id|. Both |source_item| and target item belongs to | |
| 187 // |item_list|. | |
| 188 // Returns the index of the target folder. | |
| 189 size_t MergeItems(AppListItemList* item_list, | |
| 190 const std::string& target_item_id, | |
| 191 AppListItem* source_item) { | |
| 192 scoped_ptr<AppListItem> source_item_ptr = | |
| 193 item_list->RemoveItem(source_item->id()); | |
| 194 DCHECK_EQ(source_item, source_item_ptr.get()); | |
| 195 size_t target_index; | |
| 196 bool found_target_item = item_list->FindItemIndex(target_item_id, | |
| 197 &target_index); | |
| 198 DCHECK(found_target_item); | |
| 199 AppListItem* target_item = item_list->item_at(target_index); | |
| 200 if (IsFolderItem(target_item)) { | |
| 201 AppListFolderItem* target_folder = | |
| 202 static_cast<AppListFolderItem*>(target_item); | |
| 203 target_folder->item_list()->AddItem(source_item_ptr.release()); | |
| 204 } else { | |
| 205 scoped_ptr<AppListItem> target_item_ptr = | |
| 206 item_list->RemoveItemAt(target_index); | |
| 207 DCHECK_EQ(target_item, target_item_ptr.get()); | |
| 208 AppListFolderItem* new_folder = | |
| 209 new AppListFolderItem(base::GenerateGUID()); | |
| 210 new_folder->item_list()->AddItem(target_item_ptr.release()); | |
| 211 new_folder->item_list()->AddItem(source_item_ptr.release()); | |
| 212 item_list->InsertItemAt(new_folder, target_index); | |
| 213 } | |
| 214 | |
| 215 return target_index; | |
| 216 } | |
| 217 | |
| 218 } // namespace | 185 } // namespace |
| 219 | 186 |
| 220 #if defined(OS_WIN) | 187 #if defined(OS_WIN) |
| 221 // Interprets drag events sent from Windows via the drag/drop API and forwards | 188 // Interprets drag events sent from Windows via the drag/drop API and forwards |
| 222 // them to AppsGridView. | 189 // them to AppsGridView. |
| 223 // On Windows, in order to have the OS perform the drag properly we need to | 190 // On Windows, in order to have the OS perform the drag properly we need to |
| 224 // provide it with a shortcut file which may or may not exist at the time the | 191 // provide it with a shortcut file which may or may not exist at the time the |
| 225 // drag is started. Therefore while waiting for that shortcut to be located we | 192 // drag is started. Therefore while waiting for that shortcut to be located we |
| 226 // just do a regular "internal" drag and transition into the synchronous drag | 193 // just do a regular "internal" drag and transition into the synchronous drag |
| 227 // when the shortcut is found/created. Hence a synchronous drag is an optional | 194 // when the shortcut is found/created. Hence a synchronous drag is an optional |
| (...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1360 item_list_->MoveItem(current_model_index, target_model_index); | 1327 item_list_->MoveItem(current_model_index, target_model_index); |
| 1361 view_model_.Move(current_model_index, target_model_index); | 1328 view_model_.Move(current_model_index, target_model_index); |
| 1362 item_list_->AddObserver(this); | 1329 item_list_->AddObserver(this); |
| 1363 | 1330 |
| 1364 if (pagination_model_->selected_page() != target.page) | 1331 if (pagination_model_->selected_page() != target.page) |
| 1365 pagination_model_->SelectPage(target.page, false); | 1332 pagination_model_->SelectPage(target.page, false); |
| 1366 } | 1333 } |
| 1367 | 1334 |
| 1368 void AppsGridView::MoveItemToFolder(views::View* item_view, | 1335 void AppsGridView::MoveItemToFolder(views::View* item_view, |
| 1369 const Index& target) { | 1336 const Index& target) { |
| 1370 AppListItem* source_item = | 1337 std::string source_id = |
|
xiyuan
2014/01/28 05:58:29
nit: const std::string&
stevenjb
2014/01/28 18:28:08
Done.
| |
| 1371 static_cast<AppListItemView*>(item_view)->item(); | 1338 static_cast<AppListItemView*>(item_view)->item()->id(); |
| 1372 AppListItemView* target_view = | 1339 AppListItemView* target_view = |
| 1373 static_cast<AppListItemView*>(GetViewAtSlotOnCurrentPage(target.slot)); | 1340 static_cast<AppListItemView*>(GetViewAtSlotOnCurrentPage(target.slot)); |
| 1374 AppListItem* target_item = target_view->item(); | 1341 std::string target_id = target_view->item()->id(); |
|
xiyuan
2014/01/28 05:58:29
nit: const std::string&
stevenjb
2014/01/28 18:28:08
Done.
| |
| 1375 bool target_is_folder = IsFolderItem(target_item); | |
| 1376 | 1342 |
| 1377 // Make change to data model. | 1343 // Make change to data model. |
| 1378 item_list_->RemoveObserver(this); | 1344 item_list_->RemoveObserver(this); |
| 1379 int folder_index = MergeItems(item_list_, target_item->id(), source_item); | 1345 std::string folder_id = model_->MergeItems(target_id, source_id); |
| 1380 item_list_->AddObserver(this); | 1346 item_list_->AddObserver(this); |
| 1381 | 1347 |
| 1382 if (!target_is_folder) { | 1348 if (folder_id != target_id) { |
| 1383 // Change view_model_ to replace the old target view with new folder | 1349 // New folder was created, change the view model to replace the old target |
| 1384 // item view. | 1350 // view with the new folder item view. |
| 1385 int target_index = view_model_.GetIndexOfView(target_view); | 1351 size_t folder_index; |
| 1386 view_model_.Remove(target_index); | 1352 if (item_list_->FindItemIndex(folder_id, &folder_index)) { |
| 1387 delete target_view; | 1353 int target_index = view_model_.GetIndexOfView(target_view); |
| 1388 | 1354 view_model_.Remove(target_index); |
| 1389 views::View* target_folder_view = CreateViewForItemAtIndex(folder_index); | 1355 delete target_view; |
| 1390 view_model_.Add(target_folder_view, target_index); | 1356 views::View* target_folder_view = CreateViewForItemAtIndex(folder_index); |
| 1391 AddChildView(target_folder_view); | 1357 view_model_.Add(target_folder_view, target_index); |
| 1358 AddChildView(target_folder_view); | |
| 1359 } else { | |
| 1360 LOG(ERROR) << "Folder no longer in item_list: " << folder_id; | |
| 1361 } | |
| 1392 } | 1362 } |
| 1393 | 1363 |
| 1394 // Fade out the drag_view_ and delete it when animation ends. | 1364 // Fade out the drag_view_ and delete it when animation ends. |
| 1395 int drag_view_index = view_model_.GetIndexOfView(drag_view_); | 1365 int drag_view_index = view_model_.GetIndexOfView(drag_view_); |
| 1396 view_model_.Remove(drag_view_index); | 1366 view_model_.Remove(drag_view_index); |
| 1397 bounds_animator_.AnimateViewTo(drag_view_, drag_view_->bounds()); | 1367 bounds_animator_.AnimateViewTo(drag_view_, drag_view_->bounds()); |
| 1398 bounds_animator_.SetAnimationDelegate( | 1368 bounds_animator_.SetAnimationDelegate( |
| 1399 drag_view_, new ItemRemoveAnimationDelegate(drag_view_), true); | 1369 drag_view_, new ItemRemoveAnimationDelegate(drag_view_), true); |
| 1400 | 1370 |
| 1401 UpdatePaging(); | 1371 UpdatePaging(); |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1693 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, | 1663 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, |
| 1694 bool is_target_folder) { | 1664 bool is_target_folder) { |
| 1695 AppListItemView* target_view = | 1665 AppListItemView* target_view = |
| 1696 static_cast<AppListItemView*>( | 1666 static_cast<AppListItemView*>( |
| 1697 GetViewAtSlotOnCurrentPage(target_index.slot)); | 1667 GetViewAtSlotOnCurrentPage(target_index.slot)); |
| 1698 if (target_view) | 1668 if (target_view) |
| 1699 target_view->SetAsAttemptedFolderTarget(is_target_folder); | 1669 target_view->SetAsAttemptedFolderTarget(is_target_folder); |
| 1700 } | 1670 } |
| 1701 | 1671 |
| 1702 } // namespace app_list | 1672 } // namespace app_list |
| OLD | NEW |