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