Index: chrome/browser/resources/md_bookmarks/dnd_manager.js |
diff --git a/chrome/browser/resources/md_bookmarks/dnd_manager.js b/chrome/browser/resources/md_bookmarks/dnd_manager.js |
index 5304a097925c4814a01d081614ccf30334d34101..2dfe8b57bfa29ca26b2a3f9eefc509ed599a3a28 100644 |
--- a/chrome/browser/resources/md_bookmarks/dnd_manager.js |
+++ b/chrome/browser/resources/md_bookmarks/dnd_manager.js |
@@ -283,13 +283,49 @@ cr.define('bookmarks', function() { |
* @param {!Event} e |
*/ |
onDrop_: function(e) { |
- if (this.dropDestination_) |
+ if (this.dropDestination_) { |
e.preventDefault(); |
+ var dropInfo = this.calculateDropInfo_(this.dropDestination_); |
+ if (dropInfo.index != -1) |
+ chrome.bookmarkManagerPrivate.drop(dropInfo.parentId, dropInfo.index); |
+ else |
+ chrome.bookmarkManagerPrivate.drop(dropInfo.parentId); |
+ } |
+ |
this.dropDestination_ = null; |
this.dropIndicator_.finish(); |
}, |
+ /** |
+ * @param {DropDestination} dropDestination |
+ * @return {{parentId: string, index: number}} |
+ */ |
+ calculateDropInfo_: function(dropDestination) { |
+ var node = getBookmarkNode(dropDestination.element); |
+ var position = dropDestination.position; |
+ var index = -1; |
+ var parentId = node.id; |
+ |
+ if (position != DropPosition.ON) { |
+ var state = bookmarks.Store.getInstance().data; |
+ |
+ // Drops between items in the normal list and the sidebar use the drop |
+ // destination node's parent. |
+ parentId = node.parentId || ''; |
tsergeant
2017/03/30 04:02:15
Nit: Maybe assert(node.parentId) here, instead of
calamity
2017/04/03 03:02:28
Done.
|
+ index = state.nodes[parentId].children.indexOf(node.id); |
+ |
+ // TODO(calamity): Handle dropping to an empty bookmark list. |
+ if (position == DropPosition.BELOW) |
+ index++; |
+ } |
+ |
+ return { |
+ index: index, |
+ parentId: parentId, |
+ }; |
+ }, |
+ |
/** @private */ |
clearDragData_: function() { |
this.dragInfo_.clearDragData(); |