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

Side by Side Diff: chrome/browser/resources/md_bookmarks/dnd_manager.js

Issue 2912893002: MD Bookmarks: Support policies for disabling bookmark editing (Closed)
Patch Set: canEdit -> globalCanEdit Created 3 years, 6 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 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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 clear: false, 419 clear: false,
420 range: false, 420 range: false,
421 toggle: false, 421 toggle: false,
422 })); 422 }));
423 } 423 }
424 draggedNodes = [dragId]; 424 draggedNodes = [dragId];
425 } 425 }
426 426
427 e.preventDefault(); 427 e.preventDefault();
428 428
429 // If any node can't be dragged, early return (after preventDefault).
430 var anyUnmodifiable = draggedNodes.some(function(itemId) {
431 return !bookmarks.util.canEditNode(state, itemId);
432 });
433 if (anyUnmodifiable)
434 return;
435
429 // If we are dragging a single link, we can do the *Link* effect. 436 // If we are dragging a single link, we can do the *Link* effect.
430 // Otherwise, we only allow copy and move. 437 // Otherwise, we only allow copy and move.
431 if (e.dataTransfer) { 438 if (e.dataTransfer) {
432 e.dataTransfer.effectAllowed = 439 e.dataTransfer.effectAllowed =
433 draggedNodes.length == 1 && state.nodes[draggedNodes[0]].url ? 440 draggedNodes.length == 1 && state.nodes[draggedNodes[0]].url ?
434 'copyLink' : 441 'copyLink' :
435 'copyMove'; 442 'copyMove';
436 } 443 }
437 444
438 // TODO(calamity): account for touch. 445 // TODO(calamity): account for touch.
(...skipping 29 matching lines...) Expand all
468 e.preventDefault(); 475 e.preventDefault();
469 476
470 if (!this.dragInfo_.isDragValid()) 477 if (!this.dragInfo_.isDragValid())
471 return; 478 return;
472 479
473 var overElement = getBookmarkElement(e.path); 480 var overElement = getBookmarkElement(e.path);
474 this.autoExpander_.update(e, overElement); 481 this.autoExpander_.update(e, overElement);
475 if (!overElement) 482 if (!overElement)
476 return; 483 return;
477 484
478
479 // Now we know that we can drop. Determine if we will drop above, on or 485 // Now we know that we can drop. Determine if we will drop above, on or
480 // below based on mouse position etc. 486 // below based on mouse position etc.
481 this.dropDestination_ = 487 this.dropDestination_ =
482 this.calculateDropDestination_(e.clientY, overElement); 488 this.calculateDropDestination_(e.clientY, overElement);
483 if (!this.dropDestination_) { 489 if (!this.dropDestination_) {
484 this.dropIndicator_.finish(); 490 this.dropIndicator_.finish();
485 return; 491 return;
486 } 492 }
487 493
488 if (e.dataTransfer) { 494 if (e.dataTransfer) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 546
541 // Drags aren't allowed onto the search result list. 547 // Drags aren't allowed onto the search result list.
542 if ((isBookmarkList(overElement) || isBookmarkItem(overElement)) && 548 if ((isBookmarkList(overElement) || isBookmarkItem(overElement)) &&
543 bookmarks.util.isShowingSearch(state)) { 549 bookmarks.util.isShowingSearch(state)) {
544 return DropPosition.NONE; 550 return DropPosition.NONE;
545 } 551 }
546 552
547 if (isBookmarkList(overElement)) 553 if (isBookmarkList(overElement))
548 itemId = state.selectedFolder; 554 itemId = state.selectedFolder;
549 555
556 if (!bookmarks.util.canReorderChildren(state, itemId))
557 return DropPosition.NONE;
558
550 // Drags of a bookmark onto itself or of a folder into its children aren't 559 // Drags of a bookmark onto itself or of a folder into its children aren't
551 // allowed. 560 // allowed.
552 if (dragInfo.isDraggingBookmark(itemId) || 561 if (dragInfo.isDraggingBookmark(itemId) ||
553 dragInfo.isDraggingFolderToDescendant(itemId, state.nodes)) { 562 dragInfo.isDraggingFolderToDescendant(itemId, state.nodes)) {
554 return DropPosition.NONE; 563 return DropPosition.NONE;
555 } 564 }
556 565
557 var validDropPositions = this.calculateDropAboveBelow_(overElement); 566 var validDropPositions = this.calculateDropAboveBelow_(overElement);
558 if (this.canDropOn_(overElement)) 567 if (this.canDropOn_(overElement))
559 validDropPositions |= DropPosition.ON; 568 validDropPositions |= DropPosition.ON;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 this.dropIndicator_.setTimeout = this.setTimeout_; 645 this.dropIndicator_.setTimeout = this.setTimeout_;
637 } 646 }
638 }; 647 };
639 648
640 return { 649 return {
641 DNDManager: DNDManager, 650 DNDManager: DNDManager,
642 DragInfo: DragInfo, 651 DragInfo: DragInfo,
643 DropIndicator: DropIndicator, 652 DropIndicator: DropIndicator,
644 }; 653 };
645 }); 654 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/command_manager.js ('k') | chrome/browser/resources/md_bookmarks/folder_node.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698