B2G/gecko/browser/components/places/content/controller.js
/**
   * Determines whether or not the data currently being dragged can be dropped
   * on a places view.
   * @param ip
   *        The insertion point where the items should be dropped.
   */
Determines whether or not the data currently being dragged can be dropped
on a places view.
@param ip
The insertion point where the items should be dropped.
Determines whether or not the data currently being dragged can be dropped on a places view . @param ip The insertion point where the items should be dropped .
function PCDH_canDrop(ip, dt) {
    let dropCount = dt.mozItemCount;
    for (let i = 0; i < dropCount; i++) {
      let flavor = this.getFirstValidFlavor(dt.mozTypesAt(i));
      if (!flavor)
        return false;
      if (flavor == TAB_DROP_TYPE)
        continue;
      let data = dt.mozGetDataAt(flavor, i);
      let dragged;
      try {
        dragged = PlacesUtils.unwrapNodes(data, flavor)[0];
      }
      catch (e) {
        return false;
      }
      if (ip.isTag && ip.orientation == Ci.nsITreeView.DROP_ON &&
          dragged.type != PlacesUtils.TYPE_X_MOZ_URL &&
          (dragged.type != PlacesUtils.TYPE_X_MOZ_PLACE ||
           (dragged.uri && dragged.uri.startsWith("place:")) ))
        return false;
      if (dragged.type == PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER ||
          (dragged.uri && dragged.uri.startsWith("place:")) ) {
        let parentId = ip.itemId;
        while (parentId != PlacesUtils.placesRootId) {
          if (dragged.concreteId == parentId || dragged.id == parentId)
            return false;
          parentId = PlacesUtils.bookmarks.getFolderIdForItem(parentId);
        }
      }
    }
    return true;
  }
function PCDH_canDrop ( ip , dt ) { let dropCount = dt . mozItemCount ; for ( let i = 0 ; i < dropCount ; i ++ ) { let flavor = this . getFirstValidFlavor ( dt . mozTypesAt ( i ) ) ; if ( ! flavor ) return false ; if ( flavor == TAB_DROP_TYPE ) continue ; let data = dt . mozGetDataAt ( flavor , i ) ; let dragged ; try { dragged = PlacesUtils . unwrapNodes ( data , flavor ) [ 0 ] ; } catch ( e ) { return false ; } if ( ip . isTag && ip . orientation == Ci . nsITreeView . DROP_ON && dragged . type != PlacesUtils . TYPE_X_MOZ_URL && ( dragged . type != PlacesUtils . TYPE_X_MOZ_PLACE || ( dragged . uri && dragged . uri . startsWith ( "place:" ) ) ) ) return false ; if ( dragged . type == PlacesUtils . TYPE_X_MOZ_PLACE_CONTAINER || ( dragged . uri && dragged . uri . startsWith ( "place:" ) ) ) { let parentId = ip . itemId ; while ( parentId != PlacesUtils . placesRootId ) { if ( dragged . concreteId == parentId || dragged . id == parentId ) return false ; parentId = PlacesUtils . bookmarks . getFolderIdForItem ( parentId ) ; } } } return true ; }
Determines whether or not the data currently being dragged can be dropped
 on a places view.
Determines whether or not the data currently being dragged can be dropped on a places view .
// Check every dragged item. // Urls can be dropped on any insertionpoint. // XXXmano: remember that this method is called for each dragover event! // Thus we shouldn't use unwrapNodes here at all if possible. // I think it would be OK to accept bogus data here (e.g. text which was // somehow wrapped as TAB_DROP_TYPE, this is not in our control, and // will just case the actual drop to be a no-op), and only rule out valid // expected cases, which are either unsupported flavors, or items which // cannot be dropped in the current insertionpoint. The last case will // likely force us to use unwrapNodes for the private data types of // places. // Only bookmarks and urls can be dropped into tag containers. // The following loop disallows the dropping of a folder on itself or // on any of its descendants.