Places:Drag & Drop: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
Line 10: Line 10:
== Controller Drop Handling Helper ==
== Controller Drop Handling Helper ==


The <code>PlacesControllerDragHelper</code> provides an <code>onDrop</code> method that performs view-agnostic drop handling. This method performs the following actions:
The <code>PlacesControllerDragHelper</code> is an helper object providing methods and informations to views.


# Determine what mime types of objects are being dragged (from the dragged transferable), and compares this list of types supported as droppable by the target view (<code>peerDropTypes, childDropTypes</code>).
Every drag & drop event in our views saves the current DataTransfer object (https://developer.mozilla.org/En/DragDrop/DataTransfer) to <code>PlacesControllerDragHelper.currentDataTransfer</code>. Helper methods will use this cached value to check for drop validity and perform it.
# For each dropped item, unwrap the data, generate insertion or copy transactions, and execute the transactions on the transaction manager.
 
It provides an <code>onDrop</code> method that performs view-agnostic drop handling.
For each dropped item this method performs the following actions:
# Determine what mime types of objects are being dragged (from the <code>PlacesControllerDragHelper.currentDataTransfer</code> cached object), and compares this list of types supported as droppable with the list of flavors supported by Places' Views (<code>PlacesControllerDragHelper.GENERIC_VIEW_DROP_TYPES</code>).
# In case this is a tab drag&drop converts data to an acceptable flavor.
# Unwrap the data, generate insertion or copy transactions, aggregates the transaction and executes them through the transaction manager.

Revision as of 14:30, 9 March 2009

Tree Drop Handling

The Places Tree View (tree.xml) implements nsINavHistoryResultViewObserver, which provides a method onDrop which is called by the view when a drop occurs. When this happens, the following steps occur:

  1. Check whether or not the drop is valid by calling the canDrop method, returning silently if it is not.
  2. Determine how many new items will be inserted into open folders in the tree view after the drop completes.
  3. If the drag and drop operation occured within the same view, adjust the insertion index to account for the fact that items may have been removed before it.
  4. Call the controller's onDrop helper.

Controller Drop Handling Helper

The PlacesControllerDragHelper is an helper object providing methods and informations to views.

Every drag & drop event in our views saves the current DataTransfer object (https://developer.mozilla.org/En/DragDrop/DataTransfer) to PlacesControllerDragHelper.currentDataTransfer. Helper methods will use this cached value to check for drop validity and perform it.

It provides an onDrop method that performs view-agnostic drop handling. For each dropped item this method performs the following actions:

  1. Determine what mime types of objects are being dragged (from the PlacesControllerDragHelper.currentDataTransfer cached object), and compares this list of types supported as droppable with the list of flavors supported by Places' Views (PlacesControllerDragHelper.GENERIC_VIEW_DROP_TYPES).
  2. In case this is a tab drag&drop converts data to an acceptable flavor.
  3. Unwrap the data, generate insertion or copy transactions, aggregates the transaction and executes them through the transaction manager.