| OLD | NEW |
| 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 cr.define('bookmarks', function() { | 5 cr.define('bookmarks', function() { |
| 6 /** | 6 /** |
| 7 * @param {BookmarkElement} element | 7 * @param {BookmarkElement} element |
| 8 * @return {boolean} | 8 * @return {boolean} |
| 9 */ | 9 */ |
| 10 function isBookmarkItem(element) { | 10 function isBookmarkItem(element) { |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 * Used to instantly clearDragData in tests. | 288 * Used to instantly clearDragData in tests. |
| 289 * @private {bookmarks.TimerProxy} | 289 * @private {bookmarks.TimerProxy} |
| 290 */ | 290 */ |
| 291 this.timerProxy_ = new bookmarks.TimerProxy(); | 291 this.timerProxy_ = new bookmarks.TimerProxy(); |
| 292 | 292 |
| 293 /** | 293 /** |
| 294 * The bookmark drag and drop indicator chip. | 294 * The bookmark drag and drop indicator chip. |
| 295 * @private {BookmarksDndChipElement} | 295 * @private {BookmarksDndChipElement} |
| 296 */ | 296 */ |
| 297 this.chip_ = null; | 297 this.chip_ = null; |
| 298 |
| 299 /** |
| 300 * The element that initiated a drag. |
| 301 * @private {BookmarkElement} |
| 302 */ |
| 303 this.dragElement_ = null; |
| 298 } | 304 } |
| 299 | 305 |
| 300 DNDManager.prototype = { | 306 DNDManager.prototype = { |
| 301 init: function() { | 307 init: function() { |
| 302 this.dragInfo_ = new DragInfo(); | 308 this.dragInfo_ = new DragInfo(); |
| 303 this.dropIndicator_ = new DropIndicator(); | 309 this.dropIndicator_ = new DropIndicator(); |
| 304 this.autoExpander_ = new AutoExpander(); | 310 this.autoExpander_ = new AutoExpander(); |
| 305 | 311 |
| 306 this.documentListeners_ = { | 312 this.documentListeners_ = { |
| 307 'dragstart': this.onDragStart_.bind(this), | 313 'dragstart': this.onDragStart_.bind(this), |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 393 |
| 388 return { | 394 return { |
| 389 index: index, | 395 index: index, |
| 390 parentId: parentId, | 396 parentId: parentId, |
| 391 }; | 397 }; |
| 392 }, | 398 }, |
| 393 | 399 |
| 394 /** @private */ | 400 /** @private */ |
| 395 clearDragData_: function() { | 401 clearDragData_: function() { |
| 396 this.dndChip.hide(); | 402 this.dndChip.hide(); |
| 403 this.dragElement_ = null; |
| 397 | 404 |
| 398 // Defer the clearing of the data so that the bookmark manager API's drop | 405 // Defer the clearing of the data so that the bookmark manager API's drop |
| 399 // event doesn't clear the drop data before the web drop event has a | 406 // event doesn't clear the drop data before the web drop event has a |
| 400 // chance to execute (on Mac). | 407 // chance to execute (on Mac). |
| 401 this.timerProxy_.setTimeout(function() { | 408 this.timerProxy_.setTimeout(function() { |
| 402 this.dragInfo_.clearDragData(); | 409 this.dragInfo_.clearDragData(); |
| 403 this.dropDestination_ = null; | 410 this.dropDestination_ = null; |
| 404 this.dropIndicator_.finish(); | 411 this.dropIndicator_.finish(); |
| 405 }.bind(this), 0); | 412 }.bind(this), 0); |
| 406 }, | 413 }, |
| 407 | 414 |
| 408 /** | 415 /** |
| 409 * @private | 416 * @private |
| 410 * @param {Event} e | 417 * @param {Event} e |
| 411 */ | 418 */ |
| 412 onDragStart_: function(e) { | 419 onDragStart_: function(e) { |
| 413 var dragElement = getBookmarkElement(e.path); | 420 var dragElement = getBookmarkElement(e.path); |
| 414 if (!dragElement) | 421 if (!dragElement) |
| 415 return; | 422 return; |
| 416 | 423 |
| 417 var store = bookmarks.Store.getInstance(); | 424 var store = bookmarks.Store.getInstance(); |
| 418 var dragId = dragElement.itemId; | 425 var dragId = dragElement.itemId; |
| 426 this.dragElement_ = dragElement; |
| 419 | 427 |
| 420 // Determine the selected bookmarks. | 428 // Determine the selected bookmarks. |
| 421 var state = store.data; | 429 var state = store.data; |
| 422 var draggedNodes = Array.from(state.selection.items); | 430 var draggedNodes = Array.from(state.selection.items); |
| 423 | 431 |
| 424 // Change selection to the dragged node if the node is not part of the | 432 // Change selection to the dragged node if the node is not part of the |
| 425 // existing selection. | 433 // existing selection. |
| 426 if (isBookmarkFolderNode(dragElement) || | 434 if (isBookmarkFolderNode(dragElement) || |
| 427 draggedNodes.indexOf(dragId) == -1) { | 435 draggedNodes.indexOf(dragId) == -1) { |
| 428 store.dispatch(bookmarks.actions.deselectItems()); | 436 store.dispatch(bookmarks.actions.deselectItems()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 if (e.path[0].tagName == 'INPUT') | 490 if (e.path[0].tagName == 'INPUT') |
| 483 return; | 491 return; |
| 484 | 492 |
| 485 // The default operation is to allow dropping links etc to do | 493 // The default operation is to allow dropping links etc to do |
| 486 // navigation. We never want to do that for the bookmark manager. | 494 // navigation. We never want to do that for the bookmark manager. |
| 487 e.preventDefault(); | 495 e.preventDefault(); |
| 488 | 496 |
| 489 if (!this.dragInfo_.isDragValid()) | 497 if (!this.dragInfo_.isDragValid()) |
| 490 return; | 498 return; |
| 491 | 499 |
| 500 var state = bookmarks.Store.getInstance().data; |
| 501 var items = this.dragInfo_.dragData.elements.map(function(x) { |
| 502 return bookmarks.util.normalizeNode(x); |
| 503 }); |
| 492 this.dndChip.showForItems( | 504 this.dndChip.showForItems( |
| 493 e.clientX, e.clientY, | 505 e.clientX, e.clientY, items, |
| 494 this.dragInfo_.dragData.elements.map(function(x) { | 506 this.dragElement_ ? state.nodes[this.dragElement_.itemId] : items[0]); |
| 495 return bookmarks.util.normalizeNode(x); | |
| 496 })); | |
| 497 | 507 |
| 498 var overElement = getBookmarkElement(e.path); | 508 var overElement = getBookmarkElement(e.path); |
| 499 this.autoExpander_.update(e, overElement); | 509 this.autoExpander_.update(e, overElement); |
| 500 if (!overElement) | 510 if (!overElement) |
| 501 return; | 511 return; |
| 502 | 512 |
| 503 // Now we know that we can drop. Determine if we will drop above, on or | 513 // Now we know that we can drop. Determine if we will drop above, on or |
| 504 // below based on mouse position etc. | 514 // below based on mouse position etc. |
| 505 this.dropDestination_ = | 515 this.dropDestination_ = |
| 506 this.calculateDropDestination_(e.clientY, overElement); | 516 this.calculateDropDestination_(e.clientY, overElement); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 return this.chip_; | 684 return this.chip_; |
| 675 }, | 685 }, |
| 676 }; | 686 }; |
| 677 | 687 |
| 678 return { | 688 return { |
| 679 DNDManager: DNDManager, | 689 DNDManager: DNDManager, |
| 680 DragInfo: DragInfo, | 690 DragInfo: DragInfo, |
| 681 DropIndicator: DropIndicator, | 691 DropIndicator: DropIndicator, |
| 682 }; | 692 }; |
| 683 }); | 693 }); |
| OLD | NEW |