Chromium Code Reviews| 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 /** | 5 /** |
| 6 * Enumeration of valid drop locations relative to an element. These are | 6 * Enumeration of valid drop locations relative to an element. These are |
| 7 * bit masks to allow combining multiple locations in a single value. | 7 * bit masks to allow combining multiple locations in a single value. |
| 8 * @enum {number} | 8 * @enum {number} |
| 9 * @const | 9 * @const |
| 10 */ | 10 */ |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 /** @private */ | 276 /** @private */ |
| 277 onDragLeave_: function() { | 277 onDragLeave_: function() { |
| 278 this.dropIndicator_.finish(); | 278 this.dropIndicator_.finish(); |
| 279 }, | 279 }, |
| 280 | 280 |
| 281 /** | 281 /** |
| 282 * @private | 282 * @private |
| 283 * @param {!Event} e | 283 * @param {!Event} e |
| 284 */ | 284 */ |
| 285 onDrop_: function(e) { | 285 onDrop_: function(e) { |
| 286 if (this.dropDestination_) | 286 if (this.dropDestination_) { |
| 287 e.preventDefault(); | 287 e.preventDefault(); |
| 288 | 288 |
| 289 var dropInfo = this.calculateDropInfo_(this.dropDestination_); | |
| 290 if (dropInfo.index != -1) | |
| 291 chrome.bookmarkManagerPrivate.drop(dropInfo.parentId, dropInfo.index); | |
| 292 else | |
| 293 chrome.bookmarkManagerPrivate.drop(dropInfo.parentId); | |
| 294 } | |
| 295 | |
| 289 this.dropDestination_ = null; | 296 this.dropDestination_ = null; |
| 290 this.dropIndicator_.finish(); | 297 this.dropIndicator_.finish(); |
| 291 }, | 298 }, |
| 292 | 299 |
| 300 /** | |
| 301 * @param {DropDestination} dropDestination | |
| 302 * @return {{parentId: string, index: number}} | |
| 303 */ | |
| 304 calculateDropInfo_: function(dropDestination) { | |
| 305 var node = getBookmarkNode(dropDestination.element); | |
| 306 var position = dropDestination.position; | |
| 307 var index = -1; | |
| 308 var parentId = node.id; | |
| 309 | |
| 310 if (position != DropPosition.ON) { | |
| 311 var state = bookmarks.Store.getInstance().data; | |
| 312 | |
| 313 // Drops between items in the normal list and the sidebar use the drop | |
| 314 // destination node's parent. | |
| 315 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.
| |
| 316 index = state.nodes[parentId].children.indexOf(node.id); | |
| 317 | |
| 318 // TODO(calamity): Handle dropping to an empty bookmark list. | |
| 319 if (position == DropPosition.BELOW) | |
| 320 index++; | |
| 321 } | |
| 322 | |
| 323 return { | |
| 324 index: index, | |
| 325 parentId: parentId, | |
| 326 }; | |
| 327 }, | |
| 328 | |
| 293 /** @private */ | 329 /** @private */ |
| 294 clearDragData_: function() { | 330 clearDragData_: function() { |
| 295 this.dragInfo_.clearDragData(); | 331 this.dragInfo_.clearDragData(); |
| 296 this.dropDestination_ = null; | 332 this.dropDestination_ = null; |
| 297 this.dropIndicator_.finish(); | 333 this.dropIndicator_.finish(); |
| 298 }, | 334 }, |
| 299 | 335 |
| 300 /** | 336 /** |
| 301 * @private | 337 * @private |
| 302 * @param {Event} e | 338 * @param {Event} e |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 return !this.dragInfo_.isDraggingChildBookmark(overElement.itemId) | 546 return !this.dragInfo_.isDraggingChildBookmark(overElement.itemId) |
| 511 }, | 547 }, |
| 512 }; | 548 }; |
| 513 | 549 |
| 514 return { | 550 return { |
| 515 DNDManager: DNDManager, | 551 DNDManager: DNDManager, |
| 516 DragInfo: DragInfo, | 552 DragInfo: DragInfo, |
| 517 DropIndicator: DropIndicator, | 553 DropIndicator: DropIndicator, |
| 518 }; | 554 }; |
| 519 }); | 555 }); |
| OLD | NEW |