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