Bug 517719 - Remove unnecessary nsINavHistoryResultTreeViewer interface. r?mak
MozReview-Commit-ID: E7TyD4o8dSK
--- a/browser/components/places/content/tree.xml
+++ b/browser/components/places/content/tree.xml
@@ -237,25 +237,25 @@
parents.push(parent);
parent = parent.parent;
}
// Walk the list backwards (opening from the root of the hierarchy)
// opening each folder as we go.
for (var i = parents.length - 1; i >= 0; --i) {
let index = view.treeIndexForNode(parents[i]);
- if (index != Ci.nsINavHistoryResultTreeViewer.INDEX_INVISIBLE &&
+ if (index != -1 &&
view.isContainer(index) && !view.isContainerOpen(index))
view.toggleOpenState(index);
}
// Select the specified node...
}
let index = view.treeIndexForNode(node);
- if (index == Ci.nsINavHistoryResultTreeViewer.INDEX_INVISIBLE)
+ if (index == -1)
return;
view.selection.select(index);
// ... and ensure it's visible, not scrolled off somewhere.
this.treeBoxObject.ensureRowIsVisible(index);
]]></body>
</method>
@@ -667,17 +667,17 @@
selection.selectEventsSuppressed = true;
selection.clearSelection();
// Open nodes containing found items
for (let i = 0; i < nodesToOpen.length; i++) {
nodesToOpen[i].containerOpen = true;
}
for (let i = 0; i < nodes.length; i++) {
var index = resultview.treeIndexForNode(nodes[i]);
- if (index == Ci.nsINavHistoryResultTreeViewer.INDEX_INVISIBLE)
+ if (index == -1)
continue;
selection.rangedSelect(index, index, true);
}
selection.selectEventsSuppressed = false;
]]></body>
</method>
<field name="_contextMenuShown">false</field>
--- a/browser/components/places/content/treeView.js
+++ b/browser/components/places/content/treeView.js
@@ -2,17 +2,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
const PTV_interfaces = [Ci.nsITreeView,
Ci.nsINavHistoryResultObserver,
- Ci.nsINavHistoryResultTreeViewer,
Ci.nsISupportsWeakReference];
/**
* This returns the key for any node/details object.
*
* @param nodeOrDetails
* A node, or an object containing the following properties:
* - uri
@@ -1188,30 +1187,46 @@ PlacesTreeView.prototype = {
// If the tree is not set yet, setTree will call finishInit.
if (this._tree && val)
this._finishInit();
return val;
},
- nodeForTreeIndex: function PTV_nodeForTreeIndex(aIndex) {
+ /**
+ * This allows you to get at the real node for a given row index. This is
+ * only valid when a tree is attached.
+ *
+ * @param {Integer} aIndex The index for the node to get.
+ * @return {Ci.nsINavHistoryResultNode} The node.
+ * @throws Cr.NS_ERROR_INVALID_ARG if the index is greater than the number of
+ * rows.
+ */
+ nodeForTreeIndex(aIndex) {
if (aIndex > this._rows.length)
throw Cr.NS_ERROR_INVALID_ARG;
return this._getNodeForRow(aIndex);
},
- treeIndexForNode: function PTV_treeNodeForIndex(aNode) {
+ /**
+ * Reverse of nodeForTreeIndex, returns the row index for a given result node.
+ * The node should be part of the tree.
+ *
+ * @param {Ci.nsINavHistoryResultNode} aNode The node to look for in the tree.
+ * @returns {Integer} The found index, or -1 if the item is not visible or not found.
+ */
+ treeIndexForNode(aNode) {
// The API allows passing invisible nodes.
try {
return this._getRowForNode(aNode, true);
} catch (ex) { }
- return Ci.nsINavHistoryResultTreeViewer.INDEX_INVISIBLE;
+ return -1;
},
// nsITreeView
get rowCount() {
return this._rows.length;
},
get selection() {
return this._selection;
--- a/browser/components/places/tests/chrome/test_bug549192.xul
+++ b/browser/components/places/tests/chrome/test_bug549192.xul
@@ -124,18 +124,17 @@
// Now remove the pages and verify live-update again.
for (let i = 0; i < rc; i++) {
selection.select(0);
let node = tree.selectedNode;
let promiseDeleted = promiseURIDeleted();
tree.controller.remove("Removing page");
await promiseDeleted;
- ok(treeView.treeIndexForNode(node) == Ci.nsINavHistoryResultTreeViewer.INDEX_INVISIBLE,
- node.uri + " removed.");
+ ok(treeView.treeIndexForNode(node) == -1, node.uri + " removed.");
is(treeView.rowCount, rc - i - 1, "Rows count decreased");
}
// Cleanup.
await PlacesTestUtils.clearHistory();
})().then(() => SimpleTest.finish());
}
]]></script>
--- a/toolkit/components/places/nsINavHistoryService.idl
+++ b/toolkit/components/places/nsINavHistoryService.idl
@@ -191,23 +191,23 @@ interface nsINavHistoryResultNode : nsIS
/**
* If the node is an item (bookmark, folder or a separator) this value is the
* row ID of that bookmark in the database. For other nodes, this value is
* set to -1.
*/
readonly attribute long long itemId;
/**
- * If the node is an item (bookmark, folder or a separator) this value is the
+ * If the node is an item (bookmark, folder or a separator) this value is the
* time that the item was created. For other nodes, this value is 0.
*/
readonly attribute PRTime dateAdded;
/**
- * If the node is an item (bookmark, folder or a separator) this value is the
+ * If the node is an item (bookmark, folder or a separator) this value is the
* time that the item was last modified. For other nodes, this value is 0.
*
* @note When an item is added lastModified is set to the same value as
* dateAdded.
*/
readonly attribute PRTime lastModified;
/**
@@ -395,28 +395,28 @@ interface nsINavHistoryResultObserver :
void nodeMoved(in nsINavHistoryResultNode aNode,
in nsINavHistoryContainerResultNode aOldParent,
in unsigned long aOldIndex,
in nsINavHistoryContainerResultNode aNewParent,
in unsigned long aNewIndex);
/**
* Called right after aNode's title has changed.
- *
+ *
* @param aNode
* a result node
* @param aNewTitle
* the new title
*/
void nodeTitleChanged(in nsINavHistoryResultNode aNode,
in AUTF8String aNewTitle);
/**
* Called right after aNode's uri property has changed.
- *
+ *
* @param aNode
* a result node
* @param aNewURI
* the old uri
*/
void nodeURIChanged(in nsINavHistoryResultNode aNode,
in AUTF8String aOldURI);
@@ -452,29 +452,29 @@ interface nsINavHistoryResultObserver :
* a uri result node
*
* @note: The new tags list is accessible through aNode.tags.
*/
void nodeTagsChanged(in nsINavHistoryResultNode aNode);
/**
* Called right after the aNode's keyword property has changed.
- *
+ *
* @param aNode
* a uri result node
* @param aNewKeyword
* the new keyword
*/
void nodeKeywordChanged(in nsINavHistoryResultNode aNode,
in AUTF8String aNewKeyword);
/**
* Called right after an annotation of aNode's has changed (set, altered, or
* unset).
- *
+ *
* @param aNode
* a result node
* @param aAnnoName
* the name of the annotation that changed
*/
void nodeAnnotationChanged(in nsINavHistoryResultNode aNode,
in AUTF8String aAnnoName);
@@ -551,53 +551,16 @@ interface nsINavHistoryResultObserver :
/**
* Called by the result when this observer is added.
*/
attribute nsINavHistoryResult result;
};
/**
- * TODO: Bug 517719.
- *
- * A predefined view adaptor for interfacing results with an nsITree. This
- * object will remove itself from its associated result when the tree has been
- * detached. This prevents circular references. Users should be aware of this,
- * if you want to re-use the same viewer, you will need to keep your own
- * reference to it and re-initialize it when the tree changes. If you use this
- * object, attach it to a result, never attach it to a tree, and forget about
- * it, it will leak!
- */
-[scriptable, uuid(f8b518c0-1faf-11df-8a39-0800200c9a66)]
-interface nsINavHistoryResultTreeViewer : nsINavHistoryResultObserver
-{
- /**
- * This allows you to get at the real node for a given row index. This is
- * only valid when a tree is attached.
- */
- nsINavHistoryResultNode nodeForTreeIndex(in unsigned long aIndex);
-
- /**
- * Reverse of nodeForFlatIndex, returns the row index for a given result node.
- * Returns INDEX_INVISIBLE if the item is not visible (for example, its
- * parent is collapsed). This is only valid when a tree is attached. The
- * the result will always be INDEX_INVISIBLE if not.
- *
- * Note: This sounds sort of obvious, but it got me: aNode must be a node
- * retrieved from the same result that this viewer is for. If you
- * execute another query and get a node from a _different_ result, this
- * function will always return the index of that node in the tree that
- * is attached to that result.
- */
- const unsigned long INDEX_INVISIBLE = 0xffffffff;
- unsigned long treeIndexForNode(in nsINavHistoryResultNode aNode);
-};
-
-
-/**
* The result of a history/bookmark query.
*/
[scriptable, uuid(c2229ce3-2159-4001-859c-7013c52f7619)]
interface nsINavHistoryResult : nsISupports
{
/**
* Sorts all nodes recursively by the given parameter, one of
* nsINavHistoryQueryOptions.SORT_BY_* This will update the corresponding
@@ -1061,35 +1024,35 @@ interface nsINavHistoryQueryOptions : ns
* often give you multiple results for one URI). Individual result nodes will
* have type "Visit"
*
* @note This result type is only supported by QUERY_TYPE_HISTORY.
*/
const unsigned short RESULTS_AS_VISIT = 1;
/**
- * This returns query nodes for each predefined date range where we
+ * This returns query nodes for each predefined date range where we
* had visits. The node contains information how to load its content:
* - visits for the given date range will be loaded.
*
* @note This result type is only supported by QUERY_TYPE_HISTORY.
*/
const unsigned short RESULTS_AS_DATE_QUERY = 3;
/**
- * This returns nsINavHistoryQueryResultNode nodes for each site where we
+ * This returns nsINavHistoryQueryResultNode nodes for each site where we
* have visits. The node contains information how to load its content:
* - last visit for each url in the given host will be loaded.
*
* @note This result type is only supported by QUERY_TYPE_HISTORY.
*/
const unsigned short RESULTS_AS_SITE_QUERY = 4;
/**
- * This returns nsINavHistoryQueryResultNode nodes for each day where we
+ * This returns nsINavHistoryQueryResultNode nodes for each day where we
* have visits. The node contains information how to load its content:
* - list of hosts visited in the given period will be loaded.
*
* @note This result type is only supported by QUERY_TYPE_HISTORY.
*/
const unsigned short RESULTS_AS_DATE_SITE_QUERY = 5;
/**
@@ -1227,17 +1190,17 @@ interface nsINavHistoryService : nsISupp
* This transition type means the user followed a link and got a new toplevel
* window.
*/
const unsigned long TRANSITION_LINK = 1;
/**
* This transition type means that the user typed the page's URL in the
* URL bar or selected it from URL bar autocomplete results, clicked on
- * it from a history query (from the History sidebar, History menu,
+ * it from a history query (from the History sidebar, History menu,
* or history query in the personal toolbar or Places organizer.
*/
const unsigned long TRANSITION_TYPED = 2;
/**
* This transition is set when the user followed a bookmark to get to the
* page.
*/
@@ -1432,18 +1395,18 @@ interface nsINavHistoryService : nsISupp
* @param aCallback
* nsINavHistoryBatchCallback interface to call.
* @param aUserData
* Opaque parameter passed to nsINavBookmarksBatchCallback
*/
void runInBatchMode(in nsINavHistoryBatchCallback aCallback,
in nsISupports aClosure);
- /**
- * True if history is disabled. currently,
+ /**
+ * True if history is disabled. currently,
* history is disabled if the places.history.enabled pref is false.
*/
readonly attribute boolean historyDisabled;
/**
* Clear all TRANSITION_EMBED visits.
*/
void clearEmbedVisits();