Improve places command updating performance, part 1. Bug 394695, r=dietrich, a=mconnor.

This commit is contained in:
mozilla.mano%sent.com 2007-09-19 08:13:20 +00:00
Родитель bf7145bfee
Коммит 069dad92d3
5 изменённых файлов: 110 добавлений и 51 удалений

Просмотреть файл

@ -84,9 +84,9 @@ function PlacesController(aView) {
this._view = aView;
}
PlacesController.prototype = {
PlacesController.prototype = {
/**
* The places view.
* The places view.
*/
_view: null,
@ -350,7 +350,7 @@ PlacesController.prototype = {
}
return false;
},
/**
* Looks at the data on the clipboard to see if it is paste-able.
* Paste-able data is:
@ -362,34 +362,24 @@ PlacesController.prototype = {
_isClipboardDataPasteable: function PC__isClipboardDataPasteable() {
// if the clipboard contains TYPE_X_MOZ_PLACE_* data, it is definitely
// pasteable, with no need to unwrap all the nodes.
var placeTypes = [PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER,
PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR,
PlacesUtils.TYPE_X_MOZ_PLACE];
var flavors = Cc["@mozilla.org/supports-array;1"].
createInstance(Ci.nsISupportsArray);
for (var i = 0; i < placeTypes.length; ++i) {
var cstring = Cc["@mozilla.org/supports-cstring;1"].
createInstance(Ci.nsISupportsCString);
cstring.data = placeTypes[i];
flavors.AppendElement(cstring);
}
var clipboard = Cc["@mozilla.org/widget/clipboard;1"].
getService(Ci.nsIClipboard);
var hasPlacesData = clipboard.hasDataMatchingFlavors(flavors,
Ci.nsIClipboard.kGlobalClipboard);
var flavors = PlacesUtils.placesFlavors;
var clipboard = PlacesUtils.clipboard;
var hasPlacesData =
clipboard.hasDataMatchingFlavors(flavors,
Ci.nsIClipboard.kGlobalClipboard);
if (hasPlacesData)
return this._view.insertionPoint != null;
// if the clipboard doesn't have TYPE_X_MOZ_PLACE_* data, we also allow
// pasting of valid "text/unicode" and "text/x-moz-url" data
var xferable = Cc["@mozilla.org/widget/transferable;1"].
createInstance(Ci.nsITransferable);
createInstance(Ci.nsITransferable);
xferable.addDataFlavor(PlacesUtils.TYPE_X_MOZ_URL);
xferable.addDataFlavor(PlacesUtils.TYPE_UNICODE);
clipboard.getData(xferable, Ci.nsIClipboard.kGlobalClipboard);
try {
// getAnyTransferData will throw if no data is available.
var data = { }, type = { };
@ -1379,17 +1369,32 @@ var PlacesControllerDragHelper = {
};
function goUpdatePlacesCommands() {
goUpdateCommand("placesCmd_open");
goUpdateCommand("placesCmd_open:window");
goUpdateCommand("placesCmd_open:tab");
goUpdateCommand("placesCmd_new:folder");
goUpdateCommand("placesCmd_new:bookmark");
goUpdateCommand("placesCmd_new:livemark");
goUpdateCommand("placesCmd_new:separator");
goUpdateCommand("placesCmd_show:info");
goUpdateCommand("placesCmd_moveBookmarks");
goUpdateCommand("placesCmd_setAsBookmarksToolbarFolder");
goUpdateCommand("placesCmd_reload");
goUpdateCommand("placesCmd_reloadMicrosummary");
goUpdateCommand("placesCmd_sortBy:name");
var placesController;
try {
// Or any other command...
placesController = top.document.commandDispatcher
.getControllerForCommand("placesCmd_open");
}
catch(ex) { return; }
function updatePlacesCommand(aCommand) {
var enabled = false;
if (placesController)
enabled = placesController.isCommandEnabled(aCommand);
goSetCommandEnabled(aCommand, enabled);
}
updatePlacesCommand("placesCmd_open");
updatePlacesCommand("placesCmd_open:window");
updatePlacesCommand("placesCmd_open:tab");
updatePlacesCommand("placesCmd_new:folder");
updatePlacesCommand("placesCmd_new:bookmark");
updatePlacesCommand("placesCmd_new:livemark");
updatePlacesCommand("placesCmd_new:separator");
updatePlacesCommand("placesCmd_show:info");
updatePlacesCommand("placesCmd_moveBookmarks");
updatePlacesCommand("placesCmd_setAsBookmarksToolbarFolder");
updatePlacesCommand("placesCmd_reload");
updatePlacesCommand("placesCmd_reloadMicrosummary");
updatePlacesCommand("placesCmd_sortBy:name");
}

Просмотреть файл

@ -628,6 +628,9 @@
<!-- nsIPlacesView -->
<property name="insertionPoint">
<getter><![CDATA[
if (this._cachedInsertionPoint !== undefined)
return this._cachedInsertionPoint;
// By default, the insertion point is at the top level, at the end.
var index = -1;
var folderId = 0;
@ -645,7 +648,8 @@
index = PlacesUtils.getIndexOfNode(this.selectedNode)
}
}
return new InsertionPoint(folderId, index);
this._cachedInsertionPoint = new InsertionPoint(folderId, index);
return this._cachedInsertionPoint;
]]></getter>
</property>
@ -835,6 +839,7 @@
onDragStart: function TBV_DO_onDragStart(event, xferData, dragAction) {
this._self._selection = event.target.node;
this._self._cachedInsertionPoint = undefined;
if (event.ctrlKey)
dragAction.action = Ci.nsIDragService.DRAGDROP_ACTION_COPY;
xferData.data = this._self._controller.getTransferData(dragAction.action);
@ -956,6 +961,7 @@
// Set the selection to the node that was activated. If that
// node has a command but no data associated with it, it should
// act on the entire menu.
this._cachedInsertionPoint = undefined;
this._selection = event.target.node || this._resultNode;
}
]]></handler>
@ -965,8 +971,10 @@
var popupNode = document.popupNode;
// |popupNode == this| happens when the area between menuseparators
// is clicked.
if (popupNode == this || popupNode.parentNode == this)
if (popupNode == this || popupNode.parentNode == this) {
this._selection = popupNode.node || this._resultNode;
this._cachedInsertionPoint = undefined;
}
]]></handler>
<handler event="draggesture"><![CDATA[

Просмотреть файл

@ -403,6 +403,9 @@
<!-- nsIPlacesView -->
<property name="insertionPoint">
<getter><![CDATA[
if (this._cachedInsertionPoint !== undefined)
return this._cachedInsertionPoint;
// By default, the insertion point is at the top level, at the end.
var index = -1;
var folderId = this._result.root.itemId;
@ -418,7 +421,8 @@
index = PlacesUtils.getIndexOfNode(this.selectedNode)
}
}
return new InsertionPoint(folderId, index, 1);
this._cachedInsertionPoint = new InsertionPoint(folderId, index, 1);
return this._cachedInsertionPoint;
]]></getter>
</property>
@ -994,6 +998,7 @@
this._selection = event.target.node;
else
this._selection = this.getResult().root;
this._cachedInsertionPoint = undefined;
]]></handler>
<handler event="draggesture"><![CDATA[
if (event.target.localName == "toolbarbutton")

Просмотреть файл

@ -144,6 +144,7 @@
var treeView = new PlacesTreeView(this.showRoot);
result.viewer = treeView;
this.view = treeView;
this._cachedInsertionPoint = undefined;
]]></body>
</method>
@ -432,24 +433,31 @@
return null;
]]></getter>
</property>
<!-- nsIPlacesView -->
<property name="insertionPoint">
<getter><![CDATA[
// invalidated on selection and focus changes
if (this._cachedInsertionPoint !== undefined)
return this._cachedInsertionPoint;
// there is no insertion point for history queries
// so bail out now and save a lot of work when updating commands
var resultNode = this.getResultNode();
if (PlacesUtils.nodeIsQuery(resultNode)) {
var options = asQuery(resultNode).queryOptions;
if (options.queryType == options.QUERY_TYPE_HISTORY)
return null;
if (options.queryType == options.QUERY_TYPE_HISTORY)
return this._cachedInsertionPoint = null;
}
var orientation = NHRVO.DROP_AFTER;
// If there is no selection, insert at the end of the container.
if (!this.hasSelection) {
var index = this.view.rowCount - 1;
return this._getInsertionPoint(index, orientation);
this._cachedInsertionPoint =
this._getInsertionPoint(index, orientation);
return this._cachedInsertionPoint;
}
// This is a two-part process. The first part is determining the drop
@ -484,7 +492,9 @@
.itemId == PlacesUtils.bookmarksRootId))
orientation = NHRVO.DROP_ON;
return this._getInsertionPoint(max.value, orientation);
this._cachedInsertionPoint =
this._getInsertionPoint(max.value, orientation);
return this._cachedInsertionPoint;
]]></getter>
</property>
@ -992,11 +1002,15 @@
</implementation>
<handlers>
<handler event="focus"><![CDATA[
this._cachedInsertionPoint = undefined;
// See select handler. We need the sidebar's places commandset to be
// updated as well
document.commandDispatcher.updateCommands("focus");
]]></handler>
<handler event="select"><![CDATA[
this._cachedInsertionPoint = undefined;
// This additional complexity is here for the sidebars
var win = window;
while (true) {

Просмотреть файл

@ -200,6 +200,15 @@ var PlacesUtils = {
return this._ptm;
},
_clipboard: null,
get clipboard() {
if (!this._clipboard) {
this._clipboard = Cc["@mozilla.org/widget/clipboard;1"].
getService(Ci.nsIClipboard);
}
return this._clipboard;
},
/**
* Makes a URI from a spec.
* @param aSpec
@ -537,7 +546,7 @@ var PlacesUtils = {
type: self.TYPE_X_MOZ_PLACE_CONTAINER };
bNode.containerOpen = wasOpen;
}
}
}
return node;
}
return JSON.toString(gatherDataPlace(convertNode(aNode)));
@ -605,7 +614,7 @@ var PlacesUtils = {
var wasOpen = bNode.containerOpen;
if (!wasOpen)
bNode.containerOpen = true;
var childString = bNode.title + NEWLINE;
var cc = bNode.childCount;
for (var i = 0; i < cc; ++i) {
@ -669,14 +678,14 @@ var PlacesUtils = {
return aExcludeAnnotations.indexOf(aValue.name) == -1;
});
}
return this.ptm.createItem(itemURL, aContainer, aIndex, itemTitle, keyword,
annos);
},
/**
* Gets a transaction for copying (recursively nesting to include children)
* a folder (or container) and its contents from one folder to another.
* a folder (or container) and its contents from one folder to another.
*
* @param aData
* Unwrapped dropped folder data - Obj containing folder and children
@ -696,12 +705,12 @@ var PlacesUtils = {
for (var i = 0; i < cc; ++i) {
var txn = null;
var node = aChildren[i];
// adjusted to make sure that items are given the correct index -
// transactions insert differently if index == -1
if (aIndex > -1)
index = aIndex + i;
if (node.type == self.TYPE_X_MOZ_PLACE_CONTAINER) {
if (node.folder) {
var title = node.folder.title;
@ -823,11 +832,11 @@ var PlacesUtils = {
case this.TYPE_X_MOZ_PLACE:
if (data.id <= 0)
return this._getURIItemCopyTransaction(data, container, index);
if (copy) {
// Copying a child of a live-bookmark by itself should result
// as a new normal bookmark item (bug 376731)
var copyBookmarkAnno =
var copyBookmarkAnno =
this._getBookmarkItemCopyTransaction(data, container, index,
["livemark/bookmarkFeedURI"]);
return copyBookmarkAnno;
@ -1633,6 +1642,24 @@ var PlacesUtils = {
urlsToOpen.push(aNodes[i].uri);
}
this._openTabset(urlsToOpen, aEvent);
},
_placesFlavors: null,
get placesFlavors() {
if (!this._placesFlavors) {
var placeTypes = [PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER,
PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR,
PlacesUtils.TYPE_X_MOZ_PLACE];
this._placesFlavors = Cc["@mozilla.org/supports-array;1"].
createInstance(Ci.nsISupportsArray);
for (var i = 0; i < placeTypes.length; ++i) {
var cstring = Cc["@mozilla.org/supports-cstring;1"].
createInstance(Ci.nsISupportsCString);
cstring.data = placeTypes[i];
this._placesFlavors.AppendElement(cstring);
}
}
return this._placesFlavors;
}
};