Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4000)

Unified Diff: chrome/browser/resources/md_bookmarks/dnd_manager.js

Issue 2772003002: [MD Bookmarks] Make drag and drop update data model. (Closed)
Patch Set: address_comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/data/webui/md_bookmarks/dnd_manager_test.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
« no previous file with comments | « no previous file | chrome/test/data/webui/md_bookmarks/dnd_manager_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698