1 // Copyright (c) 2015 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.
7 * @param {!Element} element
8 * @param {!Array.<string>} transferTypes
9 * @param {string} messageText
10 * @param {function(!DataTransfer)} handleDrop
12 WebInspector
.DropTarget = function(element
, transferTypes
, messageText
, handleDrop
)
14 element
.addEventListener("dragenter", this._onDragEnter
.bind(this), true);
15 element
.addEventListener("dragover", this._onDragOver
.bind(this), true);
16 this._element
= element
;
17 this._transferTypes
= transferTypes
;
18 this._messageText
= messageText
;
19 this._handleDrop
= handleDrop
;
23 WebInspector
.DropTarget
.Types
= {
25 URIList
: "text/uri-list"
28 WebInspector
.DropTarget
.prototype = {
30 * @param {boolean} enabled
32 setEnabled: function(enabled
)
34 this._enabled
= enabled
;
38 * @param {!Event} event
40 _onDragEnter: function(event
)
42 if (this._enabled
&& this._hasMatchingType(event
))
47 * @param {!Event} event
50 _hasMatchingType: function(event
)
52 for (var type
of this._transferTypes
) {
53 if (event
.dataTransfer
.types
.indexOf(type
) !== -1)
60 * @param {!Event} event
62 _onDragOver: function(event
)
64 if (!this._enabled
|| !this._hasMatchingType(event
))
66 event
.dataTransfer
.dropEffect
= "copy";
68 if (this._dragMaskElement
)
70 this._dragMaskElement
= this._element
.createChild("div", "");
71 var shadowRoot
= WebInspector
.createShadowRootWithCoreStyles(this._dragMaskElement
);
72 shadowRoot
.appendChild(WebInspector
.Widget
.createStyleElement("ui/dropTarget.css"));
73 shadowRoot
.createChild("div", "drop-target-message").textContent
= this._messageText
;
74 this._dragMaskElement
.addEventListener("drop", this._onDrop
.bind(this), true);
75 this._dragMaskElement
.addEventListener("dragleave", this._onDragLeave
.bind(this), true);
79 * @param {!Event} event
81 _onDrop: function(event
)
86 this._handleDrop(event
.dataTransfer
);
90 * @param {!Event} event
92 _onDragLeave: function(event
)
98 _removeMask: function()
100 this._dragMaskElement
.remove();
101 delete this._dragMaskElement
;