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

Side by Side Diff: chrome/browser/resources/md_bookmarks/dnd_manager.js

Issue 2977523002: MD Bookmarks: Scroll and select items that are added to the main list (Closed)
Patch Set: Add debouncer, rebase past DND change Created 3 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 5
6 /** @typedef {?{elements: !Array<BookmarkNode>, sameProfile: boolean}} */ 6 /** @typedef {?{elements: !Array<BookmarkNode>, sameProfile: boolean}} */
7 var NormalizedDragData; 7 var NormalizedDragData;
8 8
9 cr.define('bookmarks', function() { 9 cr.define('bookmarks', function() {
10 /** 10 /**
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 * @private 457 * @private
458 */ 458 */
459 onMouseUp_: function() { 459 onMouseUp_: function() {
460 if (!this.internalDragElement_) 460 if (!this.internalDragElement_)
461 return; 461 return;
462 462
463 if (this.dropDestination_) { 463 if (this.dropDestination_) {
464 // Complete the drag by moving all dragged items to the drop 464 // Complete the drag by moving all dragged items to the drop
465 // destination. 465 // destination.
466 var dropInfo = this.calculateDropInfo_(this.dropDestination_); 466 var dropInfo = this.calculateDropInfo_(this.dropDestination_);
467 this.dragInfo_.dragData.elements.forEach((item) => { 467 var shouldHighlight = this.shouldHighlight_(this.dropDestination_);
468 chrome.bookmarks.move(item.id, { 468 var dragElements = this.dragInfo_.dragData.elements;
469 parentId: dropInfo.parentId, 469 var completedMoves = 0;
470 index: dropInfo.index == -1 ? undefined : dropInfo.index 470
471 }); 471 if (shouldHighlight)
472 bookmarks.ApiListener.trackUpdatedItems();
473
474 dragElements.forEach((item) => {
475 chrome.bookmarks.move(
476 item.id, {
477 parentId: dropInfo.parentId,
478 index: dropInfo.index == -1 ? undefined : dropInfo.index
479 },
480 function() {
481 completedMoves += 1;
482 if (shouldHighlight && completedMoves == dragElements.length)
483 bookmarks.ApiListener.highlightUpdatedItems();
calamity 2017/07/26 05:36:06 optional: Consider using an array of PromiseResolv
tsergeant 2017/07/26 06:34:07 Done, it works out a little bit nicer.
484 });
472 }); 485 });
473 } 486 }
474 487
475 this.clearDragData_(); 488 this.clearDragData_();
476 }, 489 },
477 490
478 //////////////////////////////////////////////////////////////////////////// 491 ////////////////////////////////////////////////////////////////////////////
479 // DragEvent handlers: 492 // DragEvent handlers:
480 493
481 /** 494 /**
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 527
515 /** 528 /**
516 * @private 529 * @private
517 * @param {!Event} e 530 * @param {!Event} e
518 */ 531 */
519 onDrop_: function(e) { 532 onDrop_: function(e) {
520 if (this.dropDestination_) { 533 if (this.dropDestination_) {
521 e.preventDefault(); 534 e.preventDefault();
522 535
523 var dropInfo = this.calculateDropInfo_(this.dropDestination_); 536 var dropInfo = this.calculateDropInfo_(this.dropDestination_);
524 if (dropInfo.index != -1) 537 var index = dropInfo.index != -1 ? dropInfo.index : undefined;
525 chrome.bookmarkManagerPrivate.drop(dropInfo.parentId, dropInfo.index); 538 var shouldHighlight = this.shouldHighlight_(this.dropDestination_);
526 else 539
527 chrome.bookmarkManagerPrivate.drop(dropInfo.parentId); 540 if (shouldHighlight)
541 bookmarks.ApiListener.trackUpdatedItems();
542
543 chrome.bookmarkManagerPrivate.drop(
544 dropInfo.parentId, index,
545 shouldHighlight ? bookmarks.ApiListener.highlightUpdatedItems :
546 undefined);
528 } 547 }
529 548
530 this.clearDragData_(); 549 this.clearDragData_();
531 }, 550 },
532 551
533 /** 552 /**
534 * @private 553 * @private
535 * @param {Event} e 554 * @param {Event} e
536 */ 555 */
537 onDragEnter_: function(e) { 556 onDragEnter_: function(e) {
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 state.nodes[state.selectedFolder].children.length == 0; 874 state.nodes[state.selectedFolder].children.length == 0;
856 } 875 }
857 876
858 // We can only drop on a folder. 877 // We can only drop on a folder.
859 if (getBookmarkNode(overElement).url) 878 if (getBookmarkNode(overElement).url)
860 return false; 879 return false;
861 880
862 return !this.dragInfo_.isDraggingChildBookmark(overElement.itemId); 881 return !this.dragInfo_.isDraggingChildBookmark(overElement.itemId);
863 }, 882 },
864 883
884 /**
885 * @param {DropDestination} dropDestination
886 * @private
887 */
888 shouldHighlight_: function(dropDestination) {
889 return isBookmarkItem(dropDestination.element) ||
890 isBookmarkList(dropDestination.element);
891 },
892
865 /** @param {bookmarks.TimerProxy} timerProxy */ 893 /** @param {bookmarks.TimerProxy} timerProxy */
866 setTimerProxyForTesting: function(timerProxy) { 894 setTimerProxyForTesting: function(timerProxy) {
867 this.timerProxy_ = timerProxy; 895 this.timerProxy_ = timerProxy;
868 this.dropIndicator_.timerProxy = timerProxy; 896 this.dropIndicator_.timerProxy = timerProxy;
869 }, 897 },
870 898
871 /** @return {BookmarksDndChipElement} */ 899 /** @return {BookmarksDndChipElement} */
872 get dndChip() { 900 get dndChip() {
873 if (!this.chip_) { 901 if (!this.chip_) {
874 this.chip_ = 902 this.chip_ =
875 /** @type {BookmarksDndChipElement} */ ( 903 /** @type {BookmarksDndChipElement} */ (
876 document.createElement('bookmarks-dnd-chip')); 904 document.createElement('bookmarks-dnd-chip'));
877 document.body.appendChild(this.chip_); 905 document.body.appendChild(this.chip_);
878 } 906 }
879 907
880 return this.chip_; 908 return this.chip_;
881 }, 909 },
882 }; 910 };
883 911
884 return { 912 return {
885 DNDManager: DNDManager, 913 DNDManager: DNDManager,
886 DragInfo: DragInfo, 914 DragInfo: DragInfo,
887 DropIndicator: DropIndicator, 915 DropIndicator: DropIndicator,
888 }; 916 };
889 }); 917 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698