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

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: Reformat json schema Created 3 years, 4 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
469 parentId: dropInfo.parentId, 469 var movePromises = this.dragInfo_.dragData.elements.map((item) => {
470 index: dropInfo.index == -1 ? undefined : dropInfo.index 470 return new Promise((resolve) => {
471 chrome.bookmarks.move(item.id, {
472 parentId: dropInfo.parentId,
473 index: dropInfo.index == -1 ? undefined : dropInfo.index
474 }, resolve);
471 }); 475 });
472 }); 476 });
477
478 if (shouldHighlight) {
479 bookmarks.ApiListener.trackUpdatedItems();
480 Promise.all(movePromises)
481 .then(() => bookmarks.ApiListener.highlightUpdatedItems());
482 }
473 } 483 }
474 484
475 this.clearDragData_(); 485 this.clearDragData_();
476 }, 486 },
477 487
478 //////////////////////////////////////////////////////////////////////////// 488 ////////////////////////////////////////////////////////////////////////////
479 // DragEvent handlers: 489 // DragEvent handlers:
480 490
481 /** 491 /**
482 * This should only fire when a mousemove goes from the content area to the 492 * This should only fire when a mousemove goes from the content area to the
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 524
515 /** 525 /**
516 * @private 526 * @private
517 * @param {!Event} e 527 * @param {!Event} e
518 */ 528 */
519 onDrop_: function(e) { 529 onDrop_: function(e) {
520 if (this.dropDestination_) { 530 if (this.dropDestination_) {
521 e.preventDefault(); 531 e.preventDefault();
522 532
523 var dropInfo = this.calculateDropInfo_(this.dropDestination_); 533 var dropInfo = this.calculateDropInfo_(this.dropDestination_);
524 if (dropInfo.index != -1) 534 var index = dropInfo.index != -1 ? dropInfo.index : undefined;
525 chrome.bookmarkManagerPrivate.drop(dropInfo.parentId, dropInfo.index); 535 var shouldHighlight = this.shouldHighlight_(this.dropDestination_);
526 else 536
527 chrome.bookmarkManagerPrivate.drop(dropInfo.parentId); 537 if (shouldHighlight)
538 bookmarks.ApiListener.trackUpdatedItems();
539
540 chrome.bookmarkManagerPrivate.drop(
541 dropInfo.parentId, index,
542 shouldHighlight ? bookmarks.ApiListener.highlightUpdatedItems :
543 undefined);
528 } 544 }
529 545
530 this.clearDragData_(); 546 this.clearDragData_();
531 }, 547 },
532 548
533 /** 549 /**
534 * @private 550 * @private
535 * @param {Event} e 551 * @param {Event} e
536 */ 552 */
537 onDragEnter_: function(e) { 553 onDragEnter_: function(e) {
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 state.nodes[state.selectedFolder].children.length == 0; 871 state.nodes[state.selectedFolder].children.length == 0;
856 } 872 }
857 873
858 // We can only drop on a folder. 874 // We can only drop on a folder.
859 if (getBookmarkNode(overElement).url) 875 if (getBookmarkNode(overElement).url)
860 return false; 876 return false;
861 877
862 return !this.dragInfo_.isDraggingChildBookmark(overElement.itemId); 878 return !this.dragInfo_.isDraggingChildBookmark(overElement.itemId);
863 }, 879 },
864 880
881 /**
882 * @param {DropDestination} dropDestination
883 * @private
884 */
885 shouldHighlight_: function(dropDestination) {
886 return isBookmarkItem(dropDestination.element) ||
887 isBookmarkList(dropDestination.element);
888 },
889
865 /** @param {bookmarks.TimerProxy} timerProxy */ 890 /** @param {bookmarks.TimerProxy} timerProxy */
866 setTimerProxyForTesting: function(timerProxy) { 891 setTimerProxyForTesting: function(timerProxy) {
867 this.timerProxy_ = timerProxy; 892 this.timerProxy_ = timerProxy;
868 this.dropIndicator_.timerProxy = timerProxy; 893 this.dropIndicator_.timerProxy = timerProxy;
869 }, 894 },
870 895
871 /** @return {BookmarksDndChipElement} */ 896 /** @return {BookmarksDndChipElement} */
872 get dndChip() { 897 get dndChip() {
873 if (!this.chip_) { 898 if (!this.chip_) {
874 this.chip_ = 899 this.chip_ =
875 /** @type {BookmarksDndChipElement} */ ( 900 /** @type {BookmarksDndChipElement} */ (
876 document.createElement('bookmarks-dnd-chip')); 901 document.createElement('bookmarks-dnd-chip'));
877 document.body.appendChild(this.chip_); 902 document.body.appendChild(this.chip_);
878 } 903 }
879 904
880 return this.chip_; 905 return this.chip_;
881 }, 906 },
882 }; 907 };
883 908
884 return { 909 return {
885 DNDManager: DNDManager, 910 DNDManager: DNDManager,
886 DragInfo: DragInfo, 911 DragInfo: DragInfo,
887 DropIndicator: DropIndicator, 912 DropIndicator: DropIndicator,
888 }; 913 };
889 }); 914 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/dialog_focus_manager.js ('k') | chrome/browser/resources/md_bookmarks/edit_dialog.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698