OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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('ntp4', function() { | 10 cr.define('ntp4', function() { |
(...skipping 15 matching lines...) Expand all Loading... |
26 /** | 26 /** |
27 * Determines whether we are interested in the drag data for |e|. | 27 * Determines whether we are interested in the drag data for |e|. |
28 * @param {Event} e The event from drag enter. | 28 * @param {Event} e The event from drag enter. |
29 * @return {bool} | 29 * @return {bool} |
30 */ | 30 */ |
31 shouldAcceptDrag: function(e) { | 31 shouldAcceptDrag: function(e) { |
32 var tile = ntp4.getCurrentlyDraggingTile(); | 32 var tile = ntp4.getCurrentlyDraggingTile(); |
33 if (!tile) | 33 if (!tile) |
34 return false; | 34 return false; |
35 | 35 |
36 var app = tile.querySelector('.app'); | 36 return tile.firstChild.canBeRemoved(); |
37 if (!app) | |
38 return false; | |
39 | |
40 return app.appData.can_uninstall; | |
41 }, | 37 }, |
42 | 38 |
43 /** | 39 /** |
44 * Drag over handler. | 40 * Drag over handler. |
45 * @param {Event} e The drag event. | 41 * @param {Event} e The drag event. |
46 */ | 42 */ |
47 doDragOver: function(e) { | 43 doDragOver: function(e) { |
48 ntp4.getCurrentlyDraggingTile().dragClone.classList.add( | 44 ntp4.getCurrentlyDraggingTile().dragClone.classList.add( |
49 'hovering-on-trash'); | 45 'hovering-on-trash'); |
50 e.preventDefault(); | 46 e.preventDefault(); |
51 e.dataTransfer.dropEffect = 'move'; | 47 e.dataTransfer.dropEffect = 'move'; |
52 }, | 48 }, |
53 | 49 |
54 /** | 50 /** |
55 * Drag enter handler. | 51 * Drag enter handler. |
56 * @param {Event} e The drag event. | 52 * @param {Event} e The drag event. |
57 */ | 53 */ |
58 doDragEnter: function(e) { | 54 doDragEnter: function(e) { |
59 this.doDragOver(e); | 55 this.doDragOver(e); |
60 }, | 56 }, |
61 | 57 |
62 /** | 58 /** |
63 * Drop handler. | 59 * Drop handler. |
64 * @param {Event} e The drag event. | 60 * @param {Event} e The drag event. |
65 */ | 61 */ |
66 doDrop: function(e) { | 62 doDrop: function(e) { |
67 e.preventDefault(); | 63 e.preventDefault(); |
68 | 64 |
69 var tile = ntp4.getCurrentlyDraggingTile(); | 65 var tile = ntp4.getCurrentlyDraggingTile(); |
70 var app = tile.querySelector('.app'); | 66 tile.firstChild.removeFromChrome(); |
71 if (!app) | 67 tile.landedOnTrash = true; |
72 return; | |
73 | |
74 chrome.send('uninstallApp', [app.appData.id, true]); | |
75 | |
76 var page = tile.tilePage; | |
77 tile.parentNode.removeChild(tile); | |
78 page.cleanupDrag(); | |
79 }, | 68 }, |
80 | 69 |
81 /** | 70 /** |
82 * Drag leave handler. | 71 * Drag leave handler. |
83 * @param {Event} e The drag event. | 72 * @param {Event} e The drag event. |
84 */ | 73 */ |
85 doDragLeave: function(e) { | 74 doDragLeave: function(e) { |
86 ntp4.getCurrentlyDraggingTile().dragClone.classList.remove( | 75 ntp4.getCurrentlyDraggingTile().dragClone.classList.remove( |
87 'hovering-on-trash'); | 76 'hovering-on-trash'); |
88 }, | 77 }, |
89 }; | 78 }; |
90 | 79 |
91 return { | 80 return { |
92 Trash: Trash, | 81 Trash: Trash, |
93 }; | 82 }; |
94 }); | 83 }); |
OLD | NEW |