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

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

Issue 2845243003: [MD Bookmarks] Fix drag and drop on Mac. (Closed)
Patch Set: fix test Created 3 years, 7 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
« no previous file with comments | « no previous file | chrome/test/data/webui/md_bookmarks/dnd_manager_test.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 /** 198 /**
199 * The style that was applied to indicate the drop location. 199 * The style that was applied to indicate the drop location.
200 * @private {?string|null} 200 * @private {?string|null}
201 */ 201 */
202 this.lastIndicatorClassName_ = null; 202 this.lastIndicatorClassName_ = null;
203 203
204 /** 204 /**
205 * Used to instantly remove the indicator style in tests. 205 * Used to instantly remove the indicator style in tests.
206 * @private {function((Function|null|string), number)} 206 * @private {function((Function|null|string), number)}
207 */ 207 */
208 this.setTimeout_ = window.setTimeout.bind(window); 208 this.setTimeout = window.setTimeout.bind(window);
209 } 209 }
210 210
211 DropIndicator.prototype = { 211 DropIndicator.prototype = {
212 /** 212 /**
213 * Applies the drop indicator style on the target element and stores that 213 * Applies the drop indicator style on the target element and stores that
214 * information to easily remove the style in the future. 214 * information to easily remove the style in the future.
215 * @param {HTMLElement} indicatorElement 215 * @param {HTMLElement} indicatorElement
216 * @param {DropPosition} position 216 * @param {DropPosition} position
217 */ 217 */
218 addDropIndicatorStyle: function(indicatorElement, position) { 218 addDropIndicatorStyle: function(indicatorElement, position) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 this.addDropIndicatorStyle(indicatorElement, position); 253 this.addDropIndicatorStyle(indicatorElement, position);
254 }, 254 },
255 255
256 /** 256 /**
257 * Stop displaying the drop indicator. 257 * Stop displaying the drop indicator.
258 */ 258 */
259 finish: function() { 259 finish: function() {
260 // The use of a timeout is in order to reduce flickering as we move 260 // The use of a timeout is in order to reduce flickering as we move
261 // between valid drop targets. 261 // between valid drop targets.
262 window.clearTimeout(this.removeDropIndicatorTimer_); 262 window.clearTimeout(this.removeDropIndicatorTimer_);
263 this.removeDropIndicatorTimer_ = this.setTimeout_(function() { 263 this.removeDropIndicatorTimer_ = this.setTimeout(function() {
264 this.removeDropIndicatorStyle(); 264 this.removeDropIndicatorStyle();
265 }.bind(this), 100); 265 }.bind(this), 100);
266 }, 266 },
267
268 disableTimeoutForTesting: function() {
269 this.setTimeout_ = function(fn, timeout) {
270 fn();
271 };
272 },
273 }; 267 };
274 268
275 /** 269 /**
276 * Manages drag and drop events for the bookmarks-app. 270 * Manages drag and drop events for the bookmarks-app.
277 * @constructor 271 * @constructor
278 */ 272 */
279 function DNDManager() { 273 function DNDManager() {
280 /** @private {bookmarks.DragInfo} */ 274 /** @private {bookmarks.DragInfo} */
281 this.dragInfo_ = null; 275 this.dragInfo_ = null;
282 276
283 /** @private {?DropDestination} */ 277 /** @private {?DropDestination} */
284 this.dropDestination_ = null; 278 this.dropDestination_ = null;
285 279
286 /** @private {bookmarks.DropIndicator} */ 280 /** @private {bookmarks.DropIndicator} */
287 this.dropIndicator_ = null; 281 this.dropIndicator_ = null;
288 282
289 /** @private {Object<string, function(!Event)>} */ 283 /** @private {Object<string, function(!Event)>} */
290 this.documentListeners_ = null; 284 this.documentListeners_ = null;
285
286 /**
287 * Used to instantly clearDragData in tests.
288 * @private {function((Function|null|string), number)}
289 */
290 this.setTimeout = window.setTimeout.bind(window);
291 } 291 }
292 292
293 DNDManager.prototype = { 293 DNDManager.prototype = {
294 init: function() { 294 init: function() {
295 this.dragInfo_ = new DragInfo(); 295 this.dragInfo_ = new DragInfo();
296 this.dropIndicator_ = new DropIndicator(); 296 this.dropIndicator_ = new DropIndicator();
297 this.autoExpander_ = new AutoExpander(); 297 this.autoExpander_ = new AutoExpander();
298 298
299 this.documentListeners_ = { 299 this.documentListeners_ = {
300 'dragstart': this.onDragStart_.bind(this), 300 'dragstart': this.onDragStart_.bind(this),
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 } 377 }
378 378
379 return { 379 return {
380 index: index, 380 index: index,
381 parentId: parentId, 381 parentId: parentId,
382 }; 382 };
383 }, 383 },
384 384
385 /** @private */ 385 /** @private */
386 clearDragData_: function() { 386 clearDragData_: function() {
387 this.dragInfo_.clearDragData(); 387 // Defer the clearing of the data so that the bookmark manager API's drop
388 this.dropDestination_ = null; 388 // event doesn't clear the drop data before the web drop event has a
389 this.dropIndicator_.finish(); 389 // chance to execute (on Mac).
390 this.setTimeout_(function() {
391 this.dragInfo_.clearDragData();
392 this.dropDestination_ = null;
393 this.dropIndicator_.finish();
394 }.bind(this), 0);
390 }, 395 },
391 396
392 /** 397 /**
393 * @private 398 * @private
394 * @param {Event} e 399 * @param {Event} e
395 */ 400 */
396 onDragStart_: function(e) { 401 onDragStart_: function(e) {
397 var dragElement = getBookmarkElement(e.path); 402 var dragElement = getBookmarkElement(e.path);
398 if (!dragElement) 403 if (!dragElement)
399 return; 404 return;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 return state.selectedFolder && 612 return state.selectedFolder &&
608 state.nodes[state.selectedFolder].children.length == 0; 613 state.nodes[state.selectedFolder].children.length == 0;
609 } 614 }
610 615
611 // We can only drop on a folder. 616 // We can only drop on a folder.
612 if (getBookmarkNode(overElement).url) 617 if (getBookmarkNode(overElement).url)
613 return false; 618 return false;
614 619
615 return !this.dragInfo_.isDraggingChildBookmark(overElement.itemId) 620 return !this.dragInfo_.isDraggingChildBookmark(overElement.itemId)
616 }, 621 },
622
623 disableTimeoutsForTesting: function() {
624 this.setTimeout_ = function(fn) {
625 fn();
626 };
627 this.dropIndicator_.setTimeout = this.setTimeout_;
628 }
617 }; 629 };
618 630
619 return { 631 return {
620 DNDManager: DNDManager, 632 DNDManager: DNDManager,
621 DragInfo: DragInfo, 633 DragInfo: DragInfo,
622 DropIndicator: DropIndicator, 634 DropIndicator: DropIndicator,
623 }; 635 };
624 }); 636 });
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/webui/md_bookmarks/dnd_manager_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698