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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 this.dropIndicator_.finish(); | 279 this.dropIndicator_.finish(); |
| 280 }, | 280 }, |
| 281 | 281 |
| 282 /** | 282 /** |
| 283 * @private | 283 * @private |
| 284 * @param {!Event} e | 284 * @param {!Event} e |
| 285 */ | 285 */ |
| 286 onDrop_: function(e) { | 286 onDrop_: function(e) { |
| 287 if (this.dropDestination_) { | 287 if (this.dropDestination_) { |
| 288 e.preventDefault(); | 288 e.preventDefault(); |
| 289 | |
| 290 var dropInfo = this.calculateDropInfo_(this.dropDestination_); | |
| 291 if (dropInfo.index != -1) | |
| 292 chrome.bookmarkManagerPrivate.drop(dropInfo.parentId, dropInfo.index); | |
| 293 else | |
| 294 chrome.bookmarkManagerPrivate.drop(dropInfo.parentId); | |
| 289 } | 295 } |
| 290 this.dropDestination_ = null; | 296 this.dropDestination_ = null; |
| 291 this.dropIndicator_.finish(); | 297 this.dropIndicator_.finish(); |
| 292 }, | 298 }, |
| 293 | 299 |
| 300 /** | |
| 301 * @param {DropDestination} dropDestination | |
| 302 * @return {?{parentId: string, index: number}} | |
|
tsergeant
2017/03/29 00:32:48
Nit: This shouldn't be nullable, there's no early
calamity
2017/03/29 03:35:37
Done.
| |
| 303 */ | |
| 304 calculateDropInfo_: function(dropDestination) { | |
| 305 var node = getBookmarkNode(dropDestination.element); | |
| 306 var position = dropDestination.position; | |
| 307 var parentId = position == DropPosition.ON || !node.parentId ? | |
| 308 node.id : | |
| 309 node.parentId; | |
| 310 var index = -1; | |
| 311 | |
| 312 if (position != DropPosition.ON) { | |
| 313 var state = bookmarks.Store.getInstance().data; | |
| 314 var listItems = bookmarks.util.getDisplayedList(state); | |
|
tsergeant
2017/03/29 00:32:48
I think that since you can't drop onto search resu
calamity
2017/03/29 03:35:37
Changed, added a comment.
tsergeant
2017/03/29 04:28:01
I actually meant that you can replace the whole if
calamity
2017/03/30 01:57:54
Ah yeah, I made this a bit more clear.
| |
| 315 // TODO(calamity): Handle dropping to an empty bookmark list. | |
| 316 if (isBookmarkItem(dropDestination.element)) { | |
| 317 index = listItems.indexOf(node.id); | |
| 318 } else { | |
| 319 index = state.nodes[node.parentId].children.indexOf(node.id); | |
| 320 } | |
| 321 | |
| 322 if (position == DropPosition.BELOW) | |
| 323 index++; | |
| 324 } | |
| 325 | |
| 326 return { | |
| 327 index: index, | |
| 328 parentId: parentId, | |
| 329 }; | |
| 330 }, | |
| 331 | |
| 294 /** @private */ | 332 /** @private */ |
| 295 clearDragData_: function() { | 333 clearDragData_: function() { |
| 296 this.dragInfo_.clearDragData(); | 334 this.dragInfo_.clearDragData(); |
| 297 this.dropDestination_ = null; | 335 this.dropDestination_ = null; |
| 298 this.dropIndicator_.finish(); | 336 this.dropIndicator_.finish(); |
| 299 }, | 337 }, |
| 300 | 338 |
| 301 /** | 339 /** |
| 302 * @private | 340 * @private |
| 303 * @param {Event} e | 341 * @param {Event} e |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 return !this.dragInfo_.isDraggingChildBookmark(overElement.itemId) | 551 return !this.dragInfo_.isDraggingChildBookmark(overElement.itemId) |
| 514 }, | 552 }, |
| 515 }; | 553 }; |
| 516 | 554 |
| 517 return { | 555 return { |
| 518 DNDManager: DNDManager, | 556 DNDManager: DNDManager, |
| 519 DragInfo: DragInfo, | 557 DragInfo: DragInfo, |
| 520 DropIndicator: DropIndicator, | 558 DropIndicator: DropIndicator, |
| 521 }; | 559 }; |
| 522 }); | 560 }); |
| OLD | NEW |