Chromium Code Reviews| Index: chrome/browser/resources/md_bookmarks/dnd_manager.js |
| diff --git a/chrome/browser/resources/md_bookmarks/dnd_manager.js b/chrome/browser/resources/md_bookmarks/dnd_manager.js |
| index 2f590a60674bf938cdadff5c05098f2f46900077..ffe274d5c8e297d380d8d9981b54b541d4f9ebd3 100644 |
| --- a/chrome/browser/resources/md_bookmarks/dnd_manager.js |
| +++ b/chrome/browser/resources/md_bookmarks/dnd_manager.js |
| @@ -113,6 +113,61 @@ cr.define('bookmarks', function() { |
| }, |
| }; |
| + |
| + /** |
| + * Manages auto expanding of sidebar folders on hover while dragging. |
| + * @constructor |
| + */ |
| + function AutoExpander() { |
| + /** @const {number} */ |
| + this.EXPAND_FOLDER_DELAY = 400; |
| + |
| + /** @private {number} */ |
| + this.lastTimestamp_ = 0; |
| + |
| + /** @private {BookmarkElement|null} */ |
| + this.lastElement_ = null; |
| + |
| + /** @private {number} */ |
| + this.testTimestamp_ = 0; |
| + } |
| + |
| + AutoExpander.prototype = { |
| + /** |
| + * @param {Event} e |
| + * @param {BookmarkElement} overElement |
|
tsergeant
2017/04/05 07:49:36
Nit: Annotate as ?, since it is nullable
calamity
2017/04/10 03:38:12
Done.
|
| + */ |
| + update: function(e, overElement) { |
| + var eventTimestamp = this.testTimestamp_ || e.timeStamp; |
| + var itemId = overElement.itemId; |
|
tsergeant
2017/04/05 07:49:36
overelement can be null (which is important, I gue
calamity
2017/04/10 03:38:12
Done.
|
| + var store = bookmarks.Store.getInstance(); |
| + |
| + // If hovering over the same folder as last update, open the folder after |
| + // the delay has passed. |
| + if (overElement && overElement == this.lastElement_) { |
| + if (eventTimestamp - this.lastTimestamp_ < this.EXPAND_FOLDER_DELAY) |
| + return; |
| + |
| + var action = bookmarks.actions.changeFolderOpen(itemId, true); |
| + store.handleAction(action); |
| + } else if ( |
| + isBookmarkFolderNode(overElement) && |
| + bookmarks.util.hasChildFolders(itemId, store.data.nodes) && |
| + store.data.closedFolders.has(itemId)) { |
| + // Since this is a closed folder node that has children, set the auto |
| + // expander to this element. |
| + this.lastTimestamp_ = eventTimestamp; |
| + this.lastElement_ = overElement; |
| + return; |
| + } |
| + |
| + // If the folder has been expanded or we have moved to a different |
| + // element, reset the auto expander. |
| + this.lastTimestamp_ = 0; |
| + this.lastElement_ = null; |
| + }, |
| + }; |
| + |
| /** |
| * Encapsulates the behavior of the drag and drop indicator which puts a line |
| * between items or highlights folders which are valid drop targets. |
| @@ -230,6 +285,7 @@ cr.define('bookmarks', function() { |
| init: function() { |
| this.dragInfo_ = new DragInfo(); |
| this.dropIndicator_ = new DropIndicator(); |
| + this.autoExpander_ = new AutoExpander(); |
| this.documentListeners_ = { |
| 'dragstart': this.onDragStart_.bind(this), |
| @@ -383,10 +439,10 @@ cr.define('bookmarks', function() { |
| return; |
| var overElement = getBookmarkElement(e.path); |
| + this.autoExpander_.update(e, overElement); |
| if (!overElement) |
| return; |
| - // TODO(calamity): open folders on hover. |
| // Now we know that we can drop. Determine if we will drop above, on or |
| // below based on mouse position etc. |