Commit 279fda40 authored by calamity's avatar calamity Committed by Commit bot

[MD Bookmarks] Fix drag and drop on Mac.

This CL fixes an issue where drag and drop wouldn't work on Mac because
the drop data was being cleared by the bookmark manager API's drop
handler before the bookmark manager's handler had handled the drop. This
has been fixed by adding a setTimeout to clearing the data, which was
also in the old bookmark manager, giving the bookmark manager a chance
to deal with the drop.

BUG=716257
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2845243003
Cr-Commit-Position: refs/heads/master@{#468281}
parent e284fdd7
...@@ -205,7 +205,7 @@ cr.define('bookmarks', function() { ...@@ -205,7 +205,7 @@ cr.define('bookmarks', function() {
* Used to instantly remove the indicator style in tests. * Used to instantly remove the indicator style in tests.
* @private {function((Function|null|string), number)} * @private {function((Function|null|string), number)}
*/ */
this.setTimeout_ = window.setTimeout.bind(window); this.setTimeout = window.setTimeout.bind(window);
} }
DropIndicator.prototype = { DropIndicator.prototype = {
...@@ -260,16 +260,10 @@ cr.define('bookmarks', function() { ...@@ -260,16 +260,10 @@ cr.define('bookmarks', function() {
// The use of a timeout is in order to reduce flickering as we move // The use of a timeout is in order to reduce flickering as we move
// between valid drop targets. // between valid drop targets.
window.clearTimeout(this.removeDropIndicatorTimer_); window.clearTimeout(this.removeDropIndicatorTimer_);
this.removeDropIndicatorTimer_ = this.setTimeout_(function() { this.removeDropIndicatorTimer_ = this.setTimeout(function() {
this.removeDropIndicatorStyle(); this.removeDropIndicatorStyle();
}.bind(this), 100); }.bind(this), 100);
}, },
disableTimeoutForTesting: function() {
this.setTimeout_ = function(fn, timeout) {
fn();
};
},
}; };
/** /**
...@@ -288,6 +282,12 @@ cr.define('bookmarks', function() { ...@@ -288,6 +282,12 @@ cr.define('bookmarks', function() {
/** @private {Object<string, function(!Event)>} */ /** @private {Object<string, function(!Event)>} */
this.documentListeners_ = null; this.documentListeners_ = null;
/**
* Used to instantly clearDragData in tests.
* @private {function((Function|null|string), number)}
*/
this.setTimeout = window.setTimeout.bind(window);
} }
DNDManager.prototype = { DNDManager.prototype = {
...@@ -384,9 +384,14 @@ cr.define('bookmarks', function() { ...@@ -384,9 +384,14 @@ cr.define('bookmarks', function() {
/** @private */ /** @private */
clearDragData_: function() { clearDragData_: function() {
this.dragInfo_.clearDragData(); // Defer the clearing of the data so that the bookmark manager API's drop
this.dropDestination_ = null; // event doesn't clear the drop data before the web drop event has a
this.dropIndicator_.finish(); // chance to execute (on Mac).
this.setTimeout_(function() {
this.dragInfo_.clearDragData();
this.dropDestination_ = null;
this.dropIndicator_.finish();
}.bind(this), 0);
}, },
/** /**
...@@ -614,6 +619,13 @@ cr.define('bookmarks', function() { ...@@ -614,6 +619,13 @@ cr.define('bookmarks', function() {
return !this.dragInfo_.isDraggingChildBookmark(overElement.itemId) return !this.dragInfo_.isDraggingChildBookmark(overElement.itemId)
}, },
disableTimeoutsForTesting: function() {
this.setTimeout_ = function(fn) {
fn();
};
this.dropIndicator_.setTimeout = this.setTimeout_;
}
}; };
return { return {
......
...@@ -109,7 +109,7 @@ suite('drag and drop', function() { ...@@ -109,7 +109,7 @@ suite('drag and drop', function() {
list = app.$$('bookmarks-list'); list = app.$$('bookmarks-list');
rootFolderNode = app.$$('bookmarks-folder-node'); rootFolderNode = app.$$('bookmarks-folder-node');
dndManager = app.dndManager_; dndManager = app.dndManager_;
dndManager.dropIndicator_.disableTimeoutForTesting(); dndManager.disableTimeoutsForTesting();
Polymer.dom.flush(); Polymer.dom.flush();
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment