| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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('dnd', function() { | 5 cr.define('dnd', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** @const */ var BookmarkList = bmm.BookmarkList; | 8 /** @const */ var BookmarkList = bmm.BookmarkList; |
| 9 /** @const */ var ListItem = cr.ui.ListItem; | 9 /** @const */ var ListItem = cr.ui.ListItem; |
| 10 /** @const */ var TreeItem = cr.ui.TreeItem; | 10 /** @const */ var TreeItem = cr.ui.TreeItem; |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 338 |
| 339 if (draggedNodes.length) { | 339 if (draggedNodes.length) { |
| 340 // If we are dragging a single link, we can do the *Link* effect. | 340 // If we are dragging a single link, we can do the *Link* effect. |
| 341 // Otherwise, we only allow copy and move. | 341 // Otherwise, we only allow copy and move. |
| 342 e.dataTransfer.effectAllowed = draggedNodes.length == 1 && | 342 e.dataTransfer.effectAllowed = draggedNodes.length == 1 && |
| 343 !bmm.isFolder(draggedNodes[0]) ? 'copyMoveLink' : 'copyMove'; | 343 !bmm.isFolder(draggedNodes[0]) ? 'copyMoveLink' : 'copyMove'; |
| 344 | 344 |
| 345 chrome.bookmarkManagerPrivate.startDrag(draggedNodes.map(function(node) { | 345 chrome.bookmarkManagerPrivate.startDrag(draggedNodes.map(function(node) { |
| 346 return node.id; | 346 return node.id; |
| 347 }), isFromTouch); | 347 }), isFromTouch); |
| 348 chrome.metricsPrivate.recordUserAction('BookmarkManager_StartDrag'); | 348 var dragTarget = getBookmarkElement(e.target); |
| 349 if (dragTarget instanceof ListItem || |
| 350 dragTarget instanceof BookmarkList) { |
| 351 chrome.metricsPrivate.recordUserAction( |
| 352 'BookmarkManager_StartDragFromList'); |
| 353 } else if (dragTarget instanceof TreeItem) { |
| 354 chrome.metricsPrivate.recordUserAction( |
| 355 'BookmarkManager_StartDragFromTree'); |
| 356 } |
| 357 |
| 358 chrome.metricsPrivate.recordSmallCount( |
| 359 'BookmarkManager.NumDragged', draggedNodes.length); |
| 349 } | 360 } |
| 350 } | 361 } |
| 351 | 362 |
| 352 function handleDragEnter(e) { | 363 function handleDragEnter(e) { |
| 353 e.preventDefault(); | 364 e.preventDefault(); |
| 354 } | 365 } |
| 355 | 366 |
| 356 /** | 367 /** |
| 357 * Calback for the dragover event. | 368 * Calback for the dragover event. |
| 358 * @param {Event} e The dragover event. | 369 * @param {Event} e The dragover event. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 function handleDrop(e) { | 489 function handleDrop(e) { |
| 479 var dropInfo = calculateDropInfo(e.target, dropDestination); | 490 var dropInfo = calculateDropInfo(e.target, dropDestination); |
| 480 if (dropInfo) { | 491 if (dropInfo) { |
| 481 selectItemsAfterUserAction(dropInfo.selectTarget, | 492 selectItemsAfterUserAction(dropInfo.selectTarget, |
| 482 dropInfo.selectedTreeId); | 493 dropInfo.selectedTreeId); |
| 483 if (dropInfo.index != -1) | 494 if (dropInfo.index != -1) |
| 484 chrome.bookmarkManagerPrivate.drop(dropInfo.parentId, dropInfo.index); | 495 chrome.bookmarkManagerPrivate.drop(dropInfo.parentId, dropInfo.index); |
| 485 else | 496 else |
| 486 chrome.bookmarkManagerPrivate.drop(dropInfo.parentId); | 497 chrome.bookmarkManagerPrivate.drop(dropInfo.parentId); |
| 487 | 498 |
| 488 chrome.metricsPrivate.recordUserAction('BookmarkManager_Drop'); | 499 e.preventDefault(); |
| 489 | 500 |
| 490 e.preventDefault(); | 501 var dragTarget = getBookmarkElement(e.target); |
| 502 var action; |
| 503 if (dragTarget instanceof ListItem || |
| 504 dragTarget instanceof BookmarkList) { |
| 505 action = 'BookmarkManager_DropToList'; |
| 506 if (dropDestination.position == DropPosition.ON) |
| 507 action = 'BookmarkManager_DropToListItem'; |
| 508 } else if (dragTarget instanceof TreeItem) { |
| 509 action = 'BookmarkManager_DropToTree'; |
| 510 if (dropDestination.position == DropPosition.ON) |
| 511 action = 'BookmarkManager_DropToTreeItem'; |
| 512 } |
| 513 if (action) |
| 514 chrome.metricsPrivate.recordUserAction(action); |
| 491 } | 515 } |
| 492 dropDestination = null; | 516 dropDestination = null; |
| 493 dropIndicator.finish(); | 517 dropIndicator.finish(); |
| 494 } | 518 } |
| 495 | 519 |
| 496 function setCurrentTouchTarget(e) { | 520 function setCurrentTouchTarget(e) { |
| 497 // Only set a new target for a single touch point. | 521 // Only set a new target for a single touch point. |
| 498 if (e.touches.length == 1) | 522 if (e.touches.length == 1) |
| 499 currentTouchTarget = getBookmarkElement(e.target); | 523 currentTouchTarget = getBookmarkElement(e.target); |
| 500 } | 524 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 528 document.addEventListener('touchend', clearCurrentTouchTarget); | 552 document.addEventListener('touchend', clearCurrentTouchTarget); |
| 529 document.addEventListener('touchstart', setCurrentTouchTarget); | 553 document.addEventListener('touchstart', setCurrentTouchTarget); |
| 530 | 554 |
| 531 chrome.bookmarkManagerPrivate.onDragEnter.addListener( | 555 chrome.bookmarkManagerPrivate.onDragEnter.addListener( |
| 532 dragInfo.handleChromeDragEnter); | 556 dragInfo.handleChromeDragEnter); |
| 533 chrome.bookmarkManagerPrivate.onDragLeave.addListener(deferredClearData); | 557 chrome.bookmarkManagerPrivate.onDragLeave.addListener(deferredClearData); |
| 534 chrome.bookmarkManagerPrivate.onDrop.addListener(deferredClearData); | 558 chrome.bookmarkManagerPrivate.onDrop.addListener(deferredClearData); |
| 535 } | 559 } |
| 536 return {init: init}; | 560 return {init: init}; |
| 537 }); | 561 }); |
| OLD | NEW |