1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2005, 2006, 2007, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. 5 * 6 * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: https://www.zimbra.com/license 9 * The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 10 * have been added to cover use of software over a computer network and provide for limited attribution 11 * for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B. 12 * 13 * Software distributed under the License is distributed on an "AS IS" basis, 14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. 15 * See the License for the specific language governing rights and limitations under the License. 16 * The Original Code is Zimbra Open Source Web Client. 17 * The Initial Developer of the Original Code is Zimbra, Inc. All rights to the Original Code were 18 * transferred by Zimbra, Inc. to Synacor, Inc. on September 14, 2015. 19 * 20 * All portions of the code are Copyright (C) 2005, 2006, 2007, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * @constructor 26 * @class 27 * A drag source is registered with a control to indicate that the control is 28 * draggable. The drag source is the mechanism by which the DnD framework provides 29 * the binding between the UI components and the application. 30 * <p> 31 * Application developers instantiate {@link DwtDragSource} and register it with the control 32 * which is to be draggable (via {@link DwtControl.setDragSource}). The 33 * application should then register a listener with the {@link DwtDragSource}. This way 34 * when drag events occur the application will be notified and may act on them 35 * accordingly 36 * </p> 37 * 38 * @author Ross Dargahi 39 * 40 * @param {number} supportedOps the supported operations. This is an arithmetic OR'ing of 41 * the operations supported by the drag source. Supported values are: 42 * <ul> 43 * <li>{@link Dwt.DND_DROP_NONE}</li> 44 * <li>{@link Dwt.DND_DROP_COPY}</li> 45 * <li>{@link Dwt.DND_DROP_MOVE}</li> 46 * </ul> 47 * 48 * @see DwtDragEvent 49 * @see DwtControl 50 * @see DwtControl#setDragSource 51 */ 52 DwtDragSource = function(supportedOps) { 53 this.__supportedOps = supportedOps 54 this.__evtMgr = new AjxEventMgr(); 55 }; 56 57 /** @private */ 58 DwtDragSource.__DRAG_LISTENER = "DwtDragSource.__DRAG_LISTENER"; 59 60 /** @private */ 61 DwtDragSource.__dragEvent = new DwtDragEvent(); 62 63 /** 64 * Returns a string representation of this object. 65 * 66 * @return {string} a string representation of this object 67 */ 68 DwtDragSource.prototype.toString = 69 function() { 70 return "DwtDragSource"; 71 }; 72 73 74 /** 75 * Registers a listener for <i>DwtDragEvent</i> events. 76 * 77 * @param {AjxListener} dragSourceListener Listener to be registered 78 * 79 * @see DwtDragEvent 80 * @see AjxListener 81 * @see #removeDragListener 82 */ 83 DwtDragSource.prototype.addDragListener = 84 function(dragSourceListener) { 85 this.__evtMgr.addListener(DwtDragSource.__DRAG_LISTENER, dragSourceListener); 86 }; 87 88 /** 89 * Removes a registered event listener. 90 * 91 * @param {AjxListener} dragSourceListener Listener to be removed 92 * 93 * @see AjxListener 94 * @see #addDragListener 95 */ 96 DwtDragSource.prototype.removeDragListener = 97 function(dragSourceListener) { 98 this.__evtMgr.removeListener(DwtDragSource.__DRAG_LISTENER, dragSourceListener); 99 }; 100 101 // The following methods are called by DwtControl during the drag lifecycle 102 103 /** @private */ 104 DwtDragSource.prototype._beginDrag = 105 function(operation, srcControl) { 106 if (!(this.__supportedOps & operation)) 107 return Dwt.DND_DROP_NONE; 108 109 DwtDragSource.__dragEvent.operation = operation; 110 DwtDragSource.__dragEvent.srcControl = srcControl; 111 DwtDragSource.__dragEvent.action = DwtDragEvent.DRAG_START; 112 DwtDragSource.__dragEvent.srcData = null; 113 DwtDragSource.__dragEvent.doit = true; 114 this.__evtMgr.notifyListeners(DwtDragSource.__DRAG_LISTENER, DwtDragSource.__dragEvent); 115 return DwtDragSource.__dragEvent.operation; 116 }; 117 118 /** @private */ 119 DwtDragSource.prototype._getData = 120 function() { 121 DwtDragSource.__dragEvent.action = DwtDragEvent.SET_DATA; 122 this.__evtMgr.notifyListeners(DwtDragSource.__DRAG_LISTENER, DwtDragSource.__dragEvent); 123 return DwtDragSource.__dragEvent.srcData; 124 }; 125 126 /** @private */ 127 DwtDragSource.prototype._endDrag = 128 function() { 129 DwtDragSource.__dragEvent.action = DwtDragEvent.DRAG_END; 130 DwtDragSource.__dragEvent.doit = false; 131 this.__evtMgr.notifyListeners(DwtDragSource.__DRAG_LISTENER, DwtDragSource.__dragEvent); 132 return DwtDragSource.__dragEvent.doit; 133 }; 134 135 /** @private */ 136 DwtDragSource.prototype._cancelDrag = 137 function() { 138 DwtDragSource.__dragEvent.action = DwtDragEvent.DRAG_CANCEL; 139 DwtDragSource.__dragEvent.doit = false; 140 this.__evtMgr.notifyListeners(DwtDragSource.__DRAG_LISTENER, DwtDragSource.__dragEvent); 141 return DwtDragSource.__dragEvent.doit; 142 }; 143