зеркало из https://github.com/mozilla/gecko-dev.git
Bug 412148 - Drop support for unused view features. r=dietrich, a=schrep.
This commit is contained in:
Родитель
57a0f0371e
Коммит
c8c42ead15
|
@ -564,8 +564,9 @@ var BookmarksMenuDropHandler = {
|
|||
getSupportedFlavours: function BMDH_getSupportedFlavours() {
|
||||
var flavorSet = new FlavourSet();
|
||||
var view = document.getElementById("bookmarksMenuPopup");
|
||||
for (var i = 0; i < view.peerDropTypes.length; ++i)
|
||||
flavorSet.appendFlavour(view.peerDropTypes[i]);
|
||||
var types = PlacesUtils.GENERIC_VIEW_DROP_TYPES
|
||||
for (var i = 0; i < types.length; ++i)
|
||||
flavorSet.appendFlavour(types[i]);
|
||||
return flavorSet;
|
||||
},
|
||||
|
||||
|
@ -596,7 +597,7 @@ var BookmarksMenuDropHandler = {
|
|||
var view = document.getElementById("bookmarksMenuPopup");
|
||||
// Put the item at the end of bookmark menu
|
||||
var ip = new InsertionPoint(PlacesUtils.bookmarksMenuFolderId, -1);
|
||||
PlacesControllerDragHelper.onDrop(null, view, ip);
|
||||
PlacesControllerDragHelper.onDrop(view, ip);
|
||||
view._rebuild();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -37,8 +37,6 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const NHRVO = Ci.nsINavHistoryResultViewObserver;
|
||||
|
||||
// XXXmano: we should move most/all of these constants to PlacesUtils
|
||||
const ORGANIZER_ROOT_BOOKMARKS = "place:folder=2&excludeItems=1&queryType=1";
|
||||
const ORGANIZER_SUBSCRIPTIONS_QUERY = "place:annotation=livemark%2FfeedURI";
|
||||
|
@ -121,16 +119,11 @@ PlacesController.prototype = {
|
|||
return this._view.selectedURINode;
|
||||
case "placesCmd_new:folder":
|
||||
case "placesCmd_new:livemark":
|
||||
return this._canInsert() &&
|
||||
this._view.peerDropTypes
|
||||
.indexOf(PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER) != -1;
|
||||
return this._canInsert();
|
||||
case "placesCmd_new:bookmark":
|
||||
return this._canInsert() &&
|
||||
this._view.peerDropTypes.indexOf(PlacesUtils.TYPE_X_MOZ_URL) != -1;
|
||||
return this._canInsert();
|
||||
case "placesCmd_new:separator":
|
||||
return this._canInsert() &&
|
||||
this._view.peerDropTypes
|
||||
.indexOf(PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR) != -1 &&
|
||||
!asQuery(this._view.getResult().root).queryOptions.excludeItems &&
|
||||
this._view.getResult().sortingMode ==
|
||||
Ci.nsINavHistoryQueryOptions.SORT_BY_NONE;
|
||||
|
@ -777,7 +770,7 @@ PlacesController.prototype = {
|
|||
throw Cr.NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
this._view.saveSelection(this._view.SAVE_SELECTION_INSERT);
|
||||
|
||||
|
||||
var performed = false;
|
||||
if (aType == "bookmark")
|
||||
performed = PlacesUtils.showAddBookmarkUI(null, null, null, ip);
|
||||
|
@ -1407,7 +1400,7 @@ PlacesMenuDNDObserver.prototype = {
|
|||
if (!dropPoint)
|
||||
return;
|
||||
|
||||
PlacesControllerDragHelper.onDrop(null, this._view, dropPoint.ip);
|
||||
PlacesControllerDragHelper.onDrop(dropPoint.ip);
|
||||
},
|
||||
|
||||
onDragExit: function TBV_DO_onDragExit(event, session) {
|
||||
|
@ -1425,8 +1418,9 @@ PlacesMenuDNDObserver.prototype = {
|
|||
|
||||
getSupportedFlavours: function TBV_DO_getSupportedFlavours() {
|
||||
var flavorSet = new FlavourSet();
|
||||
for (var i = 0; i < this._view.peerDropTypes.length; ++i)
|
||||
flavorSet.appendFlavour(this._view.peerDropTypes[i]);
|
||||
var types = PlacesUtils.GENERIC_VIEW_DROP_TYPES;
|
||||
for (var i = 0; i < types; ++i)
|
||||
flavorSet.appendFlavour(types[i]);
|
||||
return flavorSet;
|
||||
},
|
||||
|
||||
|
@ -1496,24 +1490,21 @@ var PlacesControllerDragHelper = {
|
|||
* Determines whether or not the data currently being dragged can be dropped
|
||||
* on the specified view.
|
||||
* @param view
|
||||
* An object implementing the AVI
|
||||
* A places view object (nsINavHistoryResultViewer)
|
||||
* @param orientation
|
||||
* The orientation of the drop
|
||||
* @returns true if the data being dragged is of a type supported by the view
|
||||
* it is being dragged over, false otherwise.
|
||||
*/
|
||||
canDrop: function PCDH_canDrop(view, orientation) {
|
||||
var root = view.getResult().root;
|
||||
var root = view.result.root;
|
||||
if (PlacesUtils.nodeIsReadOnly(root) ||
|
||||
!PlacesUtils.nodeIsFolder(root))
|
||||
return false;
|
||||
|
||||
var session = this.getSession();
|
||||
if (session) {
|
||||
if (orientation != NHRVO.DROP_ON)
|
||||
var types = view.peerDropTypes;
|
||||
else
|
||||
types = view.childDropTypes;
|
||||
var types = PlacesUtils.GENERIC_VIEW_DROP_TYPES;
|
||||
for (var i = 0; i < types.length; ++i) {
|
||||
if (session.isDataFlavorSupported(types[i]))
|
||||
return true;
|
||||
|
@ -1527,21 +1518,13 @@ var PlacesControllerDragHelper = {
|
|||
* supported by a view.
|
||||
* @param session
|
||||
* The active drag session
|
||||
* @param view
|
||||
* An object implementing the AVI that supplies a list of
|
||||
* supported droppable content types
|
||||
* @param orientation
|
||||
* The orientation of the drop
|
||||
* @returns An object implementing nsITransferable that can receive data
|
||||
* dropped onto a view.
|
||||
*/
|
||||
_initTransferable: function PCDH__initTransferable(session, view, orientation) {
|
||||
_initTransferable: function PCDH__initTransferable(session) {
|
||||
var xferable = Cc["@mozilla.org/widget/transferable;1"].
|
||||
createInstance(Ci.nsITransferable);
|
||||
if (orientation != NHRVO.DROP_ON)
|
||||
var types = view.peerDropTypes;
|
||||
else
|
||||
types = view.childDropTypes;
|
||||
var types = PlacesUtils.GENERIC_VIEW_DROP_TYPES;
|
||||
for (var i = 0; i < types.length; ++i) {
|
||||
if (session.isDataFlavorSupported(types[i]))
|
||||
xferable.addDataFlavor(types[i]);
|
||||
|
@ -1551,19 +1534,14 @@ var PlacesControllerDragHelper = {
|
|||
|
||||
/**
|
||||
* Handles the drop of one or more items onto a view.
|
||||
* @param sourceView
|
||||
* The AVI-implementing object that started the drop.
|
||||
* @param targetView
|
||||
* The AVI-implementing object that received the drop.
|
||||
* @param insertionPoint
|
||||
* The insertion point where the items should be dropped
|
||||
*/
|
||||
onDrop: function PCDH_onDrop(sourceView, targetView, insertionPoint) {
|
||||
onDrop: function PCDH_onDrop(insertionPoint) {
|
||||
var session = this.getSession();
|
||||
var copy = session.dragAction & Ci.nsIDragService.DRAGDROP_ACTION_COPY;
|
||||
var transactions = [];
|
||||
var xferable = this._initTransferable(session, targetView,
|
||||
insertionPoint.orientation);
|
||||
var xferable = this._initTransferable(session);
|
||||
var dropCount = session.numDropItems;
|
||||
|
||||
var movedCount = 0;
|
||||
|
|
|
@ -258,6 +258,17 @@
|
|||
throw("Container view not found");
|
||||
},
|
||||
|
||||
get result() {
|
||||
return this._self._result;
|
||||
},
|
||||
|
||||
set result(val) {
|
||||
this._built = false;
|
||||
this._self._containerNodesMap = [];
|
||||
this._self._resultNode = val.root;
|
||||
return this._self._result = val;
|
||||
},
|
||||
|
||||
itemInserted: function PMV_itemInserted(aParentNode, aNode, aIndex) {
|
||||
var popup = this._getPopupForContainer(aParentNode);
|
||||
if (!popup._built)
|
||||
|
@ -422,22 +433,16 @@
|
|||
return this.getAttribute("place");
|
||||
]]></getter>
|
||||
<setter><![CDATA[
|
||||
// Map for containerNodes<->domNodes. There's only one map per
|
||||
// result/viewer, the field is initialized once for the root menu,
|
||||
// for sub menus it is set to the root's map (see insertNewItem)
|
||||
this._containerNodesMap = [];
|
||||
|
||||
this.setAttribute("place", val);
|
||||
var queries = { }, options = { };
|
||||
PlacesUtils.history.queryStringToQueries(val, queries, { }, options);
|
||||
if (!queries.value.length)
|
||||
queries.value = [PlacesUtils.history.getNewQuery()];
|
||||
this._result =
|
||||
var result =
|
||||
PlacesUtils.history.executeQueries(queries.value,
|
||||
queries.value.length,
|
||||
options.value);
|
||||
this._result.viewer = this._viewer;
|
||||
this._resultNode = this._result.root;
|
||||
result.viewer = this._viewer;
|
||||
return val;
|
||||
]]></setter>
|
||||
</property>
|
||||
|
@ -530,12 +535,6 @@
|
|||
]]></getter>
|
||||
</property>
|
||||
|
||||
<!-- nsIPlacesView -->
|
||||
<field name="peerDropTypes">PlacesUtils.GENERIC_VIEW_DROP_TYPES</field>
|
||||
|
||||
<!-- nsIPlacesView -->
|
||||
<field name="childDropTypes">PlacesUtils.GENERIC_VIEW_DROP_TYPES</field>
|
||||
|
||||
<!-- nsIPlacesView -->
|
||||
<method name="selectAll">
|
||||
<body><![CDATA[
|
||||
|
|
|
@ -314,11 +314,10 @@
|
|||
if (!queries.value.length)
|
||||
queries.value = [history.getNewQuery()];
|
||||
try {
|
||||
this._result =
|
||||
var result =
|
||||
history.executeQueries(queries.value, queries.value.length,
|
||||
options.value);
|
||||
this._result.viewer = this._viewer;
|
||||
this._result.root.containerOpen = true;
|
||||
result.viewer = this._viewer;
|
||||
}
|
||||
catch(ex) {
|
||||
// Invalid query, or had no results.
|
||||
|
@ -413,12 +412,6 @@
|
|||
]]></getter>
|
||||
</property>
|
||||
|
||||
<!-- nsIPlacesView -->
|
||||
<field name="peerDropTypes">PlacesUtils.GENERIC_VIEW_DROP_TYPES</field>
|
||||
|
||||
<!-- nsIPlacesView -->
|
||||
<field name="childDropTypes">PlacesUtils.GENERIC_VIEW_DROP_TYPES</field>
|
||||
|
||||
<!-- nsIPlacesView -->
|
||||
<method name="selectAll">
|
||||
<body><![CDATA[
|
||||
|
@ -445,6 +438,17 @@
|
|||
throw("Container view not found");
|
||||
},
|
||||
|
||||
get result() {
|
||||
return this._self._result;
|
||||
},
|
||||
|
||||
set result(val) {
|
||||
this._self._result = val;
|
||||
if (val)
|
||||
val.root.containerOpen = true;
|
||||
return val;
|
||||
},
|
||||
|
||||
itemInserted: function TV_V_itemInserted(aParentNode, aNode, aIndex) {
|
||||
// don't insert new items into the toolbar
|
||||
// if the parent is not the root
|
||||
|
@ -757,16 +761,16 @@
|
|||
if (event.clientX < xulNode.boxObject.x + (xulNode.boxObject.width * 0.25)) {
|
||||
// Drop to the left of this folder.
|
||||
dropPoint.ip =
|
||||
new InsertionPoint(PlacesUtils.getConcreteItemId(result.root),
|
||||
i, -1);
|
||||
new InsertionPoint(PlacesUtils.getConcreteItemId(result.root),
|
||||
i, -1);
|
||||
dropPoint.beforeIndex = i;
|
||||
return dropPoint;
|
||||
}
|
||||
else if (event.clientX < xulNode.boxObject.x + (xulNode.boxObject.width * 0.75)) {
|
||||
// Drop inside this folder.
|
||||
dropPoint.ip =
|
||||
new InsertionPoint(PlacesUtils.getConcreteItemId(xulNode.node),
|
||||
-1, 1);
|
||||
new InsertionPoint(PlacesUtils.getConcreteItemId(xulNode.node),
|
||||
-1, 1);
|
||||
dropPoint.beforeIndex = i;
|
||||
dropPoint.folderNode = xulNode;
|
||||
return dropPoint;
|
||||
|
@ -876,7 +880,7 @@
|
|||
var dropPoint = this._getDropPoint(event);
|
||||
if (dropPoint == null)
|
||||
return;
|
||||
PlacesControllerDragHelper.onDrop(null, this._self, dropPoint.ip);
|
||||
PlacesControllerDragHelper.onDrop(dropPoint.ip);
|
||||
},
|
||||
|
||||
onDragExit: function TBV_DO_onDragExit(event, session) {
|
||||
|
@ -894,8 +898,9 @@
|
|||
|
||||
getSupportedFlavours: function TBV_DO_getSupportedFlavours() {
|
||||
var flavorSet = new FlavourSet();
|
||||
for (var i = 0; i < this._self.peerDropTypes.length; ++i)
|
||||
flavorSet.appendFlavour(this._self.peerDropTypes[i]);
|
||||
var types = PlacesUtils.GENERIC_VIEW_DROP_TYPES;
|
||||
for (var i = 0; i < types.length; ++i)
|
||||
flavorSet.appendFlavour(types[i]);
|
||||
return flavorSet;
|
||||
}
|
||||
})]]></field>
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<binding id="places-tree" extends="chrome://global/content/bindings/tree.xml#tree">
|
||||
<implementation implements="nsINavHistoryResultViewObserver">
|
||||
<implementation>
|
||||
<constructor><![CDATA[
|
||||
// Force an initial build.
|
||||
if (this.place)
|
||||
|
@ -71,17 +71,7 @@
|
|||
return this.treeBoxObject.view;
|
||||
]]></getter>
|
||||
<setter><![CDATA[
|
||||
// Make sure the last result doesn't hold a reference to us anymore
|
||||
var resultview = this.getResultView();
|
||||
if (resultview)
|
||||
resultview.removeViewObserver(this._viewObserver);
|
||||
|
||||
this.treeBoxObject.view = val;
|
||||
if (val) {
|
||||
val.QueryInterface(Ci.nsINavHistoryResultViewer)
|
||||
.addViewObserver(this._viewObserver, false);
|
||||
}
|
||||
return val;
|
||||
return this.treeBoxObject.view = val;
|
||||
]]></setter>
|
||||
</property>
|
||||
|
||||
|
@ -477,7 +467,7 @@
|
|||
return this._cachedInsertionPoint = null;
|
||||
}
|
||||
|
||||
var orientation = NHRVO.DROP_AFTER;
|
||||
var orientation = Ci.nsITreeView.DROP_AFTER;
|
||||
// If there is no selection, insert at the end of the container.
|
||||
if (!this.hasSelection) {
|
||||
var index = this.view.rowCount - 1;
|
||||
|
@ -517,7 +507,7 @@
|
|||
if (this.hasSingleSelection && resultView.isContainer(max.value) &&
|
||||
(resultView.isContainerOpen(max.value) ||
|
||||
itemId == PlacesUtils.bookmarksMenuFolderId))
|
||||
orientation = NHRVO.DROP_ON;
|
||||
orientation = Ci.nsITreeView.DROP_ON;
|
||||
|
||||
this._cachedInsertionPoint =
|
||||
this._getInsertionPoint(max.value, orientation);
|
||||
|
@ -546,7 +536,7 @@
|
|||
// the view is populated from (i.e. the result's itemId).
|
||||
if (index != -1) {
|
||||
var lastSelected = resultview.nodeForTreeIndex(index);
|
||||
if (resultview.isContainer(index) && orientation == NHRVO.DROP_ON) {
|
||||
if (resultview.isContainer(index) && orientation == Ci.nsITreeView.DROP_ON) {
|
||||
// If the last selected item is an open container, append _into_
|
||||
// it, rather than insert adjacent to it.
|
||||
container = lastSelected;
|
||||
|
@ -554,11 +544,11 @@
|
|||
}
|
||||
else if (!this._disallowInsertion(lastSelected) &&
|
||||
lastSelected.containerOpen &&
|
||||
orientation == NHRVO.DROP_AFTER) {
|
||||
orientation == Ci.nsITreeView.DROP_AFTER) {
|
||||
// If the last selected item is an open container and the user is
|
||||
// trying to drag into it as a first item, really insert into it.
|
||||
container = lastSelected;
|
||||
orientation = NHRVO.DROP_BEFORE;
|
||||
orientation = Ci.nsITreeView.DROP_BEFORE;
|
||||
index = 0;
|
||||
}
|
||||
else {
|
||||
|
@ -573,7 +563,7 @@
|
|||
return null;
|
||||
|
||||
var lsi = PlacesUtils.getIndexOfNode(lastSelected);
|
||||
index = orientation == NHRVO.DROP_BEFORE ? lsi : lsi + 1;
|
||||
index = orientation == Ci.nsITreeView.DROP_BEFORE ? lsi : lsi + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -585,12 +575,6 @@
|
|||
]]></body>
|
||||
</method>
|
||||
|
||||
<!-- nsIPlacesView -->
|
||||
<field name="peerDropTypes">PlacesUtils.GENERIC_VIEW_DROP_TYPES</field>
|
||||
|
||||
<!-- nsIPlacesView -->
|
||||
<field name="childDropTypes">PlacesUtils.GENERIC_VIEW_DROP_TYPES</field>
|
||||
|
||||
<!-- nsIPlacesView -->
|
||||
<method name="selectAll">
|
||||
<body><![CDATA[
|
||||
|
@ -721,7 +705,7 @@
|
|||
<parameter name="event"/>
|
||||
<parameter name="session"/>
|
||||
<body><![CDATA[
|
||||
return this._viewObserver.canDrop(-1, -1);
|
||||
return this.view.canDrop(-1, -1);
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
|
@ -741,97 +725,22 @@
|
|||
Cc["@mozilla.org/widget/dragservice;1"].
|
||||
getService(Ci.nsIDragService);
|
||||
var dragSession = dragService.getCurrentSession();
|
||||
dragSession.canDrop = this._viewObserver.canDrop(-1, 1);
|
||||
dragSession.canDrop = this.canDrop(-1, 1);
|
||||
}
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
|
||||
<!-- nsDragAndDrop -->
|
||||
<method name="getSupportedFlavours">
|
||||
<body><![CDATA[
|
||||
var flavorSet = new FlavourSet();
|
||||
for (var i = 0; i < this.peerDropTypes.length; ++i)
|
||||
flavorSet.appendFlavour(this.peerDropTypes[i]);
|
||||
var types = PlacesUtils.GENERIC_VIEW_DROP_TYPES;
|
||||
for (var i = 0; i < types.length; ++i)
|
||||
flavorSet.appendFlavour(types[i]);
|
||||
return flavorSet;
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<field name="_viewObserver"><![CDATA[({
|
||||
_self: this,
|
||||
|
||||
canDrop: function VO_canDrop(index, orientation) {
|
||||
var result = this._self.getResult();
|
||||
var resultview = this._self.getResultView();
|
||||
var node = index != -1 ? resultview.nodeForTreeIndex(index) : result.root;
|
||||
|
||||
if (orientation == NHRVO.DROP_ON) {
|
||||
// The user cannot drop an item into itself or a read-only container
|
||||
var droppingOnSelf =
|
||||
this._getSourceView() == this._self &&
|
||||
this._self.view.selection.isSelected(index);
|
||||
if (droppingOnSelf || PlacesUtils.nodeIsReadOnly(node))
|
||||
return false;
|
||||
}
|
||||
else if (node.parent && PlacesUtils.nodeIsReadOnly(node.parent))
|
||||
return false;
|
||||
|
||||
return PlacesControllerDragHelper.canDrop(this._self, orientation);
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns the view where the drag was initiated.
|
||||
*/
|
||||
_getSourceView: function VO__getSourceView() {
|
||||
var session = this._getCurrentSession();
|
||||
var sourceView = session.sourceNode;
|
||||
while (sourceView && sourceView.localName != "tree")
|
||||
sourceView = sourceView.parentNode;
|
||||
return sourceView;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns the current drag session.
|
||||
*/
|
||||
_getCurrentSession: function VO__getCurrentSession() {
|
||||
var dragService =
|
||||
Cc["@mozilla.org/widget/dragservice;1"].
|
||||
getService(Ci.nsIDragService);
|
||||
return dragService.getCurrentSession();
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles a drop operation on this view
|
||||
* @param index
|
||||
* The index at which content was dropped
|
||||
* @param orientation
|
||||
* The orientation relative to the drop index where content
|
||||
* should be inserted.
|
||||
*/
|
||||
onDrop: function VO_onDrop(index, orientation) {
|
||||
LOG("VO: onDrop: " + index + ", orientation: " + orientation);
|
||||
if (!this.canDrop(index, orientation))
|
||||
return;
|
||||
|
||||
var sourceView = this._getSourceView();
|
||||
|
||||
// We are responsible for translating the |index| and |orientation|
|
||||
// parameters into a container id and index within the container,
|
||||
// since this information is specific to the tree view.
|
||||
var ip = this._self._getInsertionPoint(index, orientation);
|
||||
if (!ip)
|
||||
throw Cr.NS_ERROR_NOT_AVAILABLE;
|
||||
PlacesControllerDragHelper.onDrop(sourceView, this._self, ip);
|
||||
},
|
||||
|
||||
onToggleOpenState: function VO_onToggleOpenState(index) { },
|
||||
onSelectionChanged: function VO_onSelectionChanged() { },
|
||||
onCycleHeader: function VO_onCycleHeader(column) { },
|
||||
onCycleCell: function VO_onCycleCell(row, column) { },
|
||||
onPerformAction: function VO_onPerformAction(action) { },
|
||||
onPerformActionOnRow: function VO_onPerformActionOnRow(action, row) { },
|
||||
onPerformActionOnCell: function VO_onPerformActionOnCell(action, row, column) { }
|
||||
})]]></field>
|
||||
|
||||
<field name="_nextSelection">[]</field>
|
||||
<field name="SAVE_SELECTION_RELOAD">0</field>
|
||||
<field name="SAVE_SELECTION_INSERT">1</field>
|
||||
|
|
|
@ -898,31 +898,6 @@ PlacesTreeView.prototype = {
|
|||
return val;
|
||||
},
|
||||
|
||||
addViewObserver: function PTV_addViewObserver(aObserver, aWeak) {
|
||||
if (aWeak)
|
||||
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
if (this._observers.indexOf(aObserver) == -1)
|
||||
this._observers.push(aObserver);
|
||||
},
|
||||
|
||||
removeViewObserver: function PTV_removeViewObserver(aObserver) {
|
||||
var index = this._observers.indexOf(aObserver);
|
||||
if (index != -1)
|
||||
this._observers.splice(index, 1);
|
||||
},
|
||||
|
||||
_enumerateObservers: function PTV__enumerateObservers(aFunctionName, aArgs) {
|
||||
for (var i=0; i < this._observers.length; i++) {
|
||||
// Don't bail out if one of the observer threw
|
||||
try {
|
||||
var obs = this._observers[i];
|
||||
obs[aFunctionName].apply(obs, aArgs);
|
||||
}
|
||||
catch (ex) { Components.utils.reportError(ex); }
|
||||
}
|
||||
},
|
||||
|
||||
// nsINavHistoryResultTreeViewer
|
||||
get collapseDuplicates() {
|
||||
return this._collapseDuplicates;
|
||||
|
@ -939,10 +914,6 @@ PlacesTreeView.prototype = {
|
|||
return val;
|
||||
},
|
||||
|
||||
get flatItemCount() {
|
||||
return this._visibleElements.length;
|
||||
},
|
||||
|
||||
nodeForTreeIndex: function PTV_nodeForTreeIndex(aIndex) {
|
||||
if (aIndex > this._visibleElements.length)
|
||||
throw Cr.NS_ERROR_INVALID_ARG;
|
||||
|
@ -1095,15 +1066,87 @@ PlacesTreeView.prototype = {
|
|||
},
|
||||
|
||||
canDrop: function PTV_canDrop(aRow, aOrientation) {
|
||||
for (var i=0; i < this._observers.length; i++) {
|
||||
if (this._observers[i].canDrop(aRow, aOrientation))
|
||||
return true;
|
||||
if (!this._result)
|
||||
throw Cr.NS_ERROR_UNEXPECTED;
|
||||
|
||||
var node = aRow != -1 ? this.nodeForTreeIndex(aRow) : this._result.root;
|
||||
|
||||
if (aOrientation == Ci.nsITreeView.DROP_ON) {
|
||||
// The user cannot drop an item into itself or a read-only container
|
||||
var dragService = Cc["@mozilla.org/widget/dragservice;1"].
|
||||
getService(Ci.nsIDragService);
|
||||
var dragSession = dragService.getCurrentSession();
|
||||
var elt = dragSession.sourceNode.parentNode;
|
||||
if (elt.localName == "tree" && elt.view == this &&
|
||||
this.selection.isSelected(aRow))
|
||||
return false;
|
||||
if (node.parent && PlacesUtils.nodeIsReadOnly(node.parent))
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
return PlacesControllerDragHelper.canDrop(this, aOrientation);
|
||||
},
|
||||
|
||||
// XXXmano: these two are copied over from tree.xml, to fix this we need to
|
||||
// either add a helper to PlacesUtils or keep it here and add insertionPoint
|
||||
// to the view interface.
|
||||
_disallowInsertion: function PTV__disallowInsertion(aContainer) {
|
||||
// Disallow insertion of items under readonly folders
|
||||
return (!PlacesUtils.nodeIsFolder(aContainer) ||
|
||||
PlacesUtils.nodeIsReadOnly(aContainer));
|
||||
},
|
||||
|
||||
_getInsertionPoint: function PTV__getInsertionPoint(index, orientation) {
|
||||
var container = this._result.root;
|
||||
// When there's no selection, assume the container is the container
|
||||
// the view is populated from (i.e. the result's itemId).
|
||||
if (index != -1) {
|
||||
var lastSelected = this.nodeForTreeIndex(index);
|
||||
if (this.isContainer(index) && orientation == Ci.nsITreeView.DROP_ON) {
|
||||
// If the last selected item is an open container, append _into_
|
||||
// it, rather than insert adjacent to it.
|
||||
container = lastSelected;
|
||||
index = -1;
|
||||
}
|
||||
else if (!this._disallowInsertion(lastSelected) &&
|
||||
lastSelected.containerOpen &&
|
||||
orientation == Ci.nsITreeView.DROP_AFTER) {
|
||||
// If the last selected item is an open container and the user is
|
||||
// trying to drag into it as a first item, really insert into it.
|
||||
container = lastSelected;
|
||||
orientation = Ci.nsITreeView.DROP_BEFORE;
|
||||
index = 0;
|
||||
}
|
||||
else {
|
||||
// Use the last-selected node's container unless the root node
|
||||
// is selected, in which case we use the root node itself as the
|
||||
// insertion point.
|
||||
container = lastSelected.parent || container;
|
||||
|
||||
// avoid the potentially expensive call to getIndexOfNode()
|
||||
// if we know this container doesn't allow insertion
|
||||
if (this._disallowInsertion(container))
|
||||
return null;
|
||||
|
||||
var lsi = PlacesUtils.getIndexOfNode(lastSelected);
|
||||
index = orientation == Ci.nsITreeView.DROP_BEFORE ? lsi : lsi + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (this._disallowInsertion(container))
|
||||
return null;
|
||||
|
||||
return new InsertionPoint(PlacesUtils.getConcreteItemId(container),
|
||||
index, orientation);
|
||||
},
|
||||
|
||||
drop: function PTV_drop(aRow, aOrientation) {
|
||||
this._enumerateObservers("onDrop", [aRow, aOrientation]);
|
||||
// We are responsible for translating the |index| and |orientation|
|
||||
// parameters into a container id and index within the container,
|
||||
// since this information is specific to the tree view.
|
||||
var ip = this._getInsertionPoint(aRow, aOrientation);
|
||||
if (!ip)
|
||||
throw Cr.NS_ERROR_NOT_AVAILABLE;
|
||||
PlacesControllerDragHelper.onDrop(ip);
|
||||
},
|
||||
|
||||
getParentIndex: function PTV_getParentIndex(aRow) {
|
||||
|
@ -1248,8 +1291,6 @@ PlacesTreeView.prototype = {
|
|||
throw Cr.NS_ERROR_UNEXPECTED;
|
||||
this._ensureValidRow(aRow);
|
||||
|
||||
this._enumerateObservers("onToggleOpenState", [aRow]);
|
||||
|
||||
var node = this._visibleElements[aRow];
|
||||
if (!PlacesUtils.nodeIsContainer(node))
|
||||
return; // not a container, nothing to do
|
||||
|
@ -1272,8 +1313,6 @@ PlacesTreeView.prototype = {
|
|||
if (!this._result)
|
||||
throw Cr.NS_ERROR_UNEXPECTED;
|
||||
|
||||
this._enumerateObservers("onCycleHeader", [aColumn]);
|
||||
|
||||
// Sometimes you want a tri-state sorting, and sometimes you don't. This
|
||||
// rule allows tri-state sorting when the root node is a folder. This will
|
||||
// catch the most common cases. When you are looking at folders, you want
|
||||
|
@ -1395,30 +1434,14 @@ PlacesTreeView.prototype = {
|
|||
this._result.sortingMode = newSort;
|
||||
},
|
||||
|
||||
selectionChanged: function PTV_selectionChnaged() {
|
||||
this._enumerateObservers("onSelectionChanged");
|
||||
},
|
||||
|
||||
cycleCell: function PTV_cycleCell(aRow, aColumn) {
|
||||
this._enumerateObservers("onCycleCell", [aRow, aColumn]);
|
||||
},
|
||||
|
||||
selectionChanged: function() { },
|
||||
cycleCell: function PTV_cycleCell(aRow, aColumn) { },
|
||||
isEditable: function(aRow, aColumn) { return false; },
|
||||
isSelectable: function(aRow, aColumn) { return false; },
|
||||
setCellText: function(aRow, aColumn) { },
|
||||
|
||||
performAction: function PTV_performAction(aAction) {
|
||||
this._enumerateObservers("onPerformAction", [aAction]);
|
||||
},
|
||||
|
||||
performActionOnRow: function PTV_perfromActionOnRow(aAction, aRow) {
|
||||
this._enumerateObservers("onPerformActionOnRow", [aAction, aRow]);
|
||||
},
|
||||
|
||||
performActionOnCell:
|
||||
function PTV_performActionOnCell(aAction, aRow, aColumn) {
|
||||
this._enumerateObservers("onPerformActionOnRow", [aAction, aRow, aColumn]);
|
||||
}
|
||||
performAction: function(aAction) { },
|
||||
performActionOnRow: function(aAction, aRow) { },
|
||||
performActionOnCell: function(aAction, aRow, aColumn) { }
|
||||
};
|
||||
|
||||
function PlacesTreeView(aShowRoot, aFlatList) {
|
||||
|
@ -1431,7 +1454,6 @@ function PlacesTreeView(aShowRoot, aFlatList) {
|
|||
this._showSessions = false;
|
||||
this._selection = null;
|
||||
this._visibleElements = [];
|
||||
this._observers = [];
|
||||
this._showRoot = aShowRoot;
|
||||
this._flatList = aFlatList;
|
||||
}
|
||||
|
|
|
@ -417,73 +417,6 @@ interface nsINavHistoryQueryResultNode : nsINavHistoryContainerResultNode
|
|||
readonly attribute long long folderItemId;
|
||||
};
|
||||
|
||||
/**
|
||||
* Allows clients of the HistoryResult to define domain specific handling
|
||||
* of specific nsITreeView methods that the HistoryResult does not implement.
|
||||
*
|
||||
* @see nsINavHistoryResult for where this fits in
|
||||
*/
|
||||
[scriptable, uuid(b34d5ca4-ce8e-49a6-9201-a59ae2128d2c)]
|
||||
interface nsINavHistoryResultViewObserver : nsISupports
|
||||
{
|
||||
const long DROP_BEFORE = -1;
|
||||
const long DROP_ON = 0;
|
||||
const long DROP_AFTER = 1;
|
||||
/**
|
||||
* Methods used by the drag feedback code to determine if a drag is allowable at
|
||||
* the current location. To get the behavior where drops are only allowed on
|
||||
* items, such as the mailNews folder pane, always return false whe
|
||||
* the orientation is not DROP_ON. Implementors should not change the content of
|
||||
* the observer list!
|
||||
*/
|
||||
boolean canDrop(in long index, in long orientation);
|
||||
|
||||
/**
|
||||
* Called when the user drops something on this view. The |orientation| param
|
||||
* specifies before/on/after the given |row|.
|
||||
*/
|
||||
void onDrop(in long row, in long orientation);
|
||||
|
||||
/**
|
||||
* Called when an item is opened or closed.
|
||||
*/
|
||||
void onToggleOpenState (in long index);
|
||||
|
||||
/**
|
||||
* Called when a header is clicked.
|
||||
*/
|
||||
void onCycleHeader(in nsITreeColumn column);
|
||||
|
||||
/**
|
||||
* Called when a cell in a non-selectable cycling column (e.g.
|
||||
* unread/flag/etc.) is clicked.
|
||||
*/
|
||||
void onCycleCell(in long row, in nsITreeColumn column);
|
||||
|
||||
/**
|
||||
* Called when selection in the tree changes
|
||||
*/
|
||||
void onSelectionChanged();
|
||||
|
||||
/**
|
||||
* A command API that can be used to invoke commands on the selection.
|
||||
* The tree will automatically invoke this method when certain keys
|
||||
* are pressed. For example, when the DEL key is pressed, performAction
|
||||
* will be called with the "delete" string.
|
||||
*/
|
||||
void onPerformAction(in wstring action);
|
||||
|
||||
/**
|
||||
* A command API that can be used to invoke commands on a specific row.
|
||||
*/
|
||||
void onPerformActionOnRow(in wstring action, in long row);
|
||||
|
||||
/**
|
||||
* A command API that can be used to invoke commands on a specific cell.
|
||||
*/
|
||||
void onPerformActionOnCell(in wstring action, in long row, in nsITreeColumn column);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Allows clients to observe what is happening to a result as it updates itself
|
||||
|
@ -492,7 +425,7 @@ interface nsINavHistoryResultViewObserver : nsISupports
|
|||
*
|
||||
* @see nsINavHistoryResult for where this fits in
|
||||
*/
|
||||
[scriptable, uuid(76cad155-21d5-427e-9740-01386cc8b923)]
|
||||
[scriptable, uuid(e60f4429-3787-45c8-a8c0-18ef52621bbf)]
|
||||
interface nsINavHistoryResultViewer : nsISupports
|
||||
{
|
||||
/**
|
||||
|
@ -592,21 +525,6 @@ interface nsINavHistoryResultViewer : nsISupports
|
|||
* is being deallocated. This should not be set by other code.
|
||||
*/
|
||||
attribute nsINavHistoryResult result;
|
||||
|
||||
/**
|
||||
* Adds the specified view observer to the view. In ownsWeak is false, then
|
||||
* the result will hold a strong reference to the observer. If ownsWeak is
|
||||
* true, then the observer must implement nsISupportsWeakReference, and the
|
||||
* result will hold a weak reference to the observer.
|
||||
*/
|
||||
void addViewObserver(in nsINavHistoryResultViewObserver observer,
|
||||
in boolean ownsWeak);
|
||||
|
||||
/**
|
||||
* Removes the specified view observer from this view. This observer must
|
||||
* have been previously registered using addViewObserver.
|
||||
*/
|
||||
void removeViewObserver(in nsINavHistoryResultViewObserver observer);
|
||||
};
|
||||
|
||||
|
||||
|
@ -619,7 +537,7 @@ interface nsINavHistoryResultViewer : nsISupports
|
|||
* object, attach it to a result, never attach it to a tree, and forget about
|
||||
* it, it will leak!
|
||||
*/
|
||||
[scriptable, uuid(ecd6ad22-8eb0-4824-8a57-5edad9a08ae6)]
|
||||
[scriptable, uuid(e0ce87df-8b77-407b-a52b-7510eab14fb5)]
|
||||
interface nsINavHistoryResultTreeViewer : nsINavHistoryResultViewer
|
||||
{
|
||||
/**
|
||||
|
@ -637,14 +555,6 @@ interface nsINavHistoryResultTreeViewer : nsINavHistoryResultViewer
|
|||
*/
|
||||
attribute boolean collapseDuplicates;
|
||||
|
||||
/**
|
||||
* This tells you how many items are in the flattened list of results, i.e.
|
||||
* how many rows are in this tree right now. The tree adaptor will also
|
||||
* QI to nsITreeView, and this will be the same as nsITreeView.rowCount.
|
||||
* This is only valid when a tree is attached, the result will be 0 otherwise.
|
||||
*/
|
||||
readonly attribute unsigned long flatItemCount;
|
||||
|
||||
/**
|
||||
* This allows you to get at the real node for a given row index. This is
|
||||
* only valid when a tree is attached.
|
||||
|
@ -677,21 +587,13 @@ interface nsINavHistoryResultTreeViewer : nsINavHistoryResultViewer
|
|||
* represents the model where the data is stored. External components
|
||||
* provide the view and controller which define how the data looks and how
|
||||
* interaction happens.
|
||||
* +-- nsINavHistoryResultViewObserver
|
||||
* |
|
||||
* [RESULT]----->[viewer]----->[controller]
|
||||
* |
|
||||
* +-- nsINavHistoryResultViewer
|
||||
*
|
||||
* The result indicates to the view when something changes through the
|
||||
* nsINavHistoryResultViewer interface. Viewers register themselves through
|
||||
* the nsINavHistoryResult.RegisterViewer. The viewer interface would then tell
|
||||
* the actual view object what to do. A nsINavHistoryResultTreeViewer is
|
||||
* provided which provides pre-packaged interaction with a nsITreeBoxObject.
|
||||
* Other views will need to provide their own viewer interfaces.
|
||||
*
|
||||
* The viewer provides notifications to the controller when view events occur
|
||||
* through the nsINavHistoryResultViewObserver interface.
|
||||
* nsINavHistoryResultViewer interface. The viewer is set through
|
||||
* the nsINavHistoryResult.viewer property.
|
||||
*/
|
||||
|
||||
[scriptable, uuid(d1562f6f-8d5a-4042-8524-72f747a51b18)]
|
||||
|
|
Загрузка…
Ссылка в новой задаче