| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** | 5 /** |
| 6 * @fileoverview Trash | 6 * @fileoverview Trash |
| 7 * This is the class for the trash can that appears when dragging an app. | 7 * This is the class for the trash can that appears when dragging an app. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 cr.define('ntp', function() { | 10 cr.define('ntp', function() { |
| 11 'use strict'; | 11 'use strict'; |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * @constructor | 14 * @constructor |
| 15 * @extends {HTMLDivElement} |
| 16 * @implements {cr.ui.DragWrapperDelegate} |
| 15 */ | 17 */ |
| 16 function Trash(trash) { | 18 function Trash(trash) { |
| 17 trash.__proto__ = Trash.prototype; | 19 trash.__proto__ = Trash.prototype; |
| 18 trash.initialize(); | 20 trash.initialize(); |
| 19 return trash; | 21 return trash; |
| 20 } | 22 } |
| 21 | 23 |
| 22 Trash.prototype = { | 24 Trash.prototype = { |
| 23 __proto__: HTMLDivElement.prototype, | 25 __proto__: HTMLDivElement.prototype, |
| 24 | 26 |
| 25 initialize: function(element) { | 27 initialize: function(element) { |
| 26 this.dragWrapper_ = new cr.ui.DragWrapper(this, this); | 28 this.dragWrapper_ = new cr.ui.DragWrapper(this, this); |
| 27 }, | 29 }, |
| 28 | 30 |
| 29 /** | 31 /** |
| 30 * Determines whether we are interested in the drag data for |e|. | 32 * Determines whether we are interested in the drag data for |e|. |
| 31 * @param {Event} e The event from drag enter. | 33 * @param {Event} e The event from drag enter. |
| 32 * @return {boolean} True if we are interested in the drag data for |e|. | 34 * @return {boolean} True if we are interested in the drag data for |e|. |
| 33 */ | 35 */ |
| 34 shouldAcceptDrag: function(e) { | 36 shouldAcceptDrag: function(e) { |
| 35 var tile = ntp.getCurrentlyDraggingTile(); | 37 var tile = ntp.getCurrentlyDraggingTile(); |
| 36 if (!tile) | 38 if (!tile) |
| 37 return false; | 39 return false; |
| 38 | 40 |
| 39 return tile.firstChild.canBeRemoved(); | 41 return tile.firstChild.canBeRemoved(); |
| 40 }, | 42 }, |
| 41 | 43 |
| 42 /** | 44 /** @override */ |
| 43 * Drag over handler. | |
| 44 * @param {Event} e The drag event. | |
| 45 */ | |
| 46 doDragOver: function(e) { | 45 doDragOver: function(e) { |
| 47 ntp.getCurrentlyDraggingTile().dragClone.classList.add( | 46 ntp.getCurrentlyDraggingTile().dragClone.classList.add( |
| 48 'hovering-on-trash'); | 47 'hovering-on-trash'); |
| 49 ntp.setCurrentDropEffect(e.dataTransfer, 'move'); | 48 ntp.setCurrentDropEffect(e.dataTransfer, 'move'); |
| 50 e.preventDefault(); | 49 e.preventDefault(); |
| 51 }, | 50 }, |
| 52 | 51 |
| 53 /** | 52 /** @override */ |
| 54 * Drag enter handler. | |
| 55 * @param {Event} e The drag event. | |
| 56 */ | |
| 57 doDragEnter: function(e) { | 53 doDragEnter: function(e) { |
| 58 this.doDragOver(e); | 54 this.doDragOver(e); |
| 59 }, | 55 }, |
| 60 | 56 |
| 61 /** | 57 /** @override */ |
| 62 * Drop handler. | |
| 63 * @param {Event} e The drag event. | |
| 64 */ | |
| 65 doDrop: function(e) { | 58 doDrop: function(e) { |
| 66 e.preventDefault(); | 59 e.preventDefault(); |
| 67 | 60 |
| 68 var tile = ntp.getCurrentlyDraggingTile(); | 61 var tile = ntp.getCurrentlyDraggingTile(); |
| 69 tile.firstChild.removeFromChrome(); | 62 tile.firstChild.removeFromChrome(); |
| 70 tile.landedOnTrash = true; | 63 tile.landedOnTrash = true; |
| 71 }, | 64 }, |
| 72 | 65 |
| 73 /** | 66 /** @override */ |
| 74 * Drag leave handler. | |
| 75 * @param {Event} e The drag event. | |
| 76 */ | |
| 77 doDragLeave: function(e) { | 67 doDragLeave: function(e) { |
| 78 ntp.getCurrentlyDraggingTile().dragClone.classList.remove( | 68 ntp.getCurrentlyDraggingTile().dragClone.classList.remove( |
| 79 'hovering-on-trash'); | 69 'hovering-on-trash'); |
| 80 }, | 70 }, |
| 81 }; | 71 }; |
| 82 | 72 |
| 83 return { | 73 return { |
| 84 Trash: Trash, | 74 Trash: Trash, |
| 85 }; | 75 }; |
| 86 }); | 76 }); |
| OLD | NEW |