Bug 329546 r=ben@mozilla.org, annie.sullivan Separate out view from history

result.


git-svn-id: svn://10.0.0.236/trunk@192823 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
brettw%gmail.com
2006-03-23 00:32:09 +00:00
parent 2ec4e93072
commit 3780cba74a
6 changed files with 1967 additions and 1523 deletions

View File

@@ -88,6 +88,12 @@
#define NS_NAVHISTORYSERVICE_CONTRACTID \
"@mozilla.org/browser/nav-history-service;1"
#define NS_NAVHISTORYRESULTTREEVIEWER_CID \
{ 0x2ea8966f, 0x0671, 0x4c02, { 0x9c, 0x70, 0x94, 0x59, 0x56, 0xd4, 0x54, 0x34 } }
#define NS_NAVHISTORYRESULTTREEVIEWER_CONTRACTID \
"@mozilla.org/browser/nav-history/result-tree-viewer;1"
#define NS_ANNOTATIONSERVICE_CID \
{ 0x5e8d4751, 0x1852, 0x434b, { 0xa9, 0x92, 0x2c, 0x6d, 0x2a, 0x25, 0xfa, 0x46 } }

View File

@@ -82,6 +82,7 @@
#ifdef MOZ_PLACES
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsNavHistory, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsNavHistoryResultTreeViewer)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAnnoProtocolHandler)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAnnotationService, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsNavBookmarks, Init)
@@ -152,6 +153,11 @@ static const nsModuleComponentInfo components[] =
"@mozilla.org/autocomplete/search;1?name=history",
nsNavHistoryConstructor },
{ "History tree view",
NS_NAVHISTORYRESULTTREEVIEWER_CID,
NS_NAVHISTORYRESULTTREEVIEWER_CONTRACTID,
nsNavHistoryResultTreeViewerConstructor },
{ "Page Annotation Service",
NS_ANNOTATIONSERVICE_CID,
NS_ANNOTATIONSERVICE_CONTRACTID,

View File

@@ -28,12 +28,13 @@
]]></getter>
<setter><![CDATA[
// Make sure the last result doesn't hold a reference to us anymore
var result = this.getResult();
if (result)
result.removeObserver(this._viewObserver);
var resultview = this.getResultView();
if (resultview)
resultview.removeViewObserver(this._viewObserver);
this.treeBoxObject.view = val;
this.getResult().addObserver(this._viewObserver, false);
]]></setter>
val.QueryInterface(Ci.nsINavHistoryResultViewer).addViewObserver(
this._viewObserver, false);
]]></setter>
</property>
<method name="getBestOptions">
@@ -92,7 +93,13 @@
options.expandQueries = this.expandQueries;
var result = this.history.executeQueries(queries, queries.length,
options);
this.view = result.QueryInterface(Ci.nsITreeView);
var treeviewer = Cc["@mozilla.org/browser/nav-history/result-tree-viewer;1"].
createInstance(Ci.nsINavHistoryResultViewer);
result.viewer = treeviewer;
treeviewer.QueryInterface(Ci.nsITreeView);
this.view = treeviewer;
]]></body>
</method>
@@ -159,15 +166,15 @@
// Walk the list backwards (opening from the root of the hierarchy)
// opening each folder as we go.
var result = this.getResult();
var resultview = this.getResultView();
var view = this.view;
for (var i = parents.length - 1; i >= 0; --i) {
var index = result.treeIndexForNode(parents[i]);
var index = resultview.treeIndexForNode(parents[i]);
if (view.isContainer(index) && !view.isContainerOpen(index))
view.toggleOpenState(index);
}
// Select the specified node...
index = result.treeIndexForNode(node);
index = resultview.treeIndexForNode(node);
view.selection.select(index);
// ... and ensure it's visible, not scrolled off somewhere.
this.treeBoxObject.ensureRowIsVisible(index);
@@ -178,7 +185,17 @@
<method name="getResult">
<body><![CDATA[
try {
return this.view.QueryInterface(Ci.nsINavHistoryResult);
return this.view.QueryInterface(Ci.nsINavHistoryResultViewer).result;
}
catch (e) {
return null;
}
]]></body>
</method>
<method name="getResultView">
<body><![CDATA[
try {
return this.view.QueryInterface(Ci.nsINavHistoryResultTreeViewer);
}
catch (e) {
}
@@ -229,13 +246,13 @@
var selection = this.view.selection;
var rc = selection.getRangeCount();
var nodes = [];
var result = this.getResult();
var resultview = this.getResultView();
for (var i = 0; i < rc; ++i) {
var min = { }, max = { };
selection.getRangeAt(i, min, max);
for (var j = min.value; j <= max.value; ++j)
nodes.push(result.nodeForTreeIndex(j));
nodes.push(resultview.nodeForTreeIndex(j));
}
return nodes;
]]></body>
@@ -270,7 +287,7 @@
var selection = this.view.selection;
var rc = selection.getRangeCount();
var nodes = [];
var result = this.getResult();
var resultview = this.getResultView();
// This list is kept independently of the range selected (i.e. OUTSIDE
// the for loop) since the row index of a container is unique for the
// entire view, and we could have some really wacky selection and we
@@ -285,7 +302,7 @@
if (this.view.isContainer(j))
containers[j] = true;
if (!(this.view.getParentIndex(j) in containers))
range.push(result.nodeForTreeIndex(j));
range.push(resultview.nodeForTreeIndex(j));
}
nodes.push(range);
}
@@ -324,7 +341,7 @@
var min = { }, max = { };
selection.getRangeAt(0, min, max);
return this.getResult().nodeForTreeIndex(min.value);
return this.getResultView().nodeForTreeIndex(min.value);
]]></getter>
</property>
@@ -340,7 +357,7 @@
selection.getRangeAt(0, min, max);
// only URI nodes should be returned
var node = this.getResult().nodeForTreeIndex(min.value);
var node = this.getResultView().nodeForTreeIndex(min.value);
if (PlacesController.nodeIsURI(node))
return node;
return null;
@@ -364,7 +381,7 @@
// If an item in the static region is selected, insert the new item
// before the first drop index.
var node = this.getResult().nodeForTreeIndex(max.value);
var node = this.getResultView().nodeForTreeIndex(max.value);
var container = asContainer(this.getResult().root);
var cc = container.childCount;
for (var i = 0; i < cc; ++i) {
@@ -384,14 +401,15 @@
<parameter name="orientation"/>
<body><![CDATA[
var result = this.getResult();
var resultview = this.getResultView();
var container = result.root;
NS_ASSERT(container, "null container");
// When there's no selection, assume the container is the container
// the view is populated from (i.e. the result's folderId).
if (index != -1) {
var lastSelected = result.nodeForTreeIndex(index);
if (this.view.isContainer(index) &&
(this.view.isContainerOpen(index) || orientation == NHRVO.DROP_ON)) {
var lastSelected = resultview.nodeForTreeIndex(index);
if (resultview.isContainer(index) &&
(resultview.isContainerOpen(index) || orientation == NHRVO.DROP_ON)) {
// If the last selected item is an open container, append _into_
// it, rather than insert adjacent to it.
container = lastSelected;
@@ -532,11 +550,11 @@
// For all the nodes we've found, highlight the corresponding
// index in the tree.
var result = this.getResult();
var resultview = this.getResult();
var selection = this.view.selection;
selection.clearSelection();
for(idx in nodes) {
var index = result.treeIndexForNode(nodes[idx]);
var index = resultview.treeIndexForNode(nodes[idx]);
selection.rangedSelect(index, index, true);
}
]]></body>
@@ -572,7 +590,7 @@
// "static" top level "special" items cannot be dragged. They are
// at the root level of the view and are at a lower index in the
// root container than user-configurable items.
var treeIndex = this.getResult().treeIndexForNode(nodes[i]);
var treeIndex = this.getResultView().treeIndexForNode(nodes[i]);
if (this.view.getLevel(treeIndex) == 0) {
var index = PlacesController.getIndexOfNode(nodes[i]);
if (index < this.peerDropIndex)
@@ -674,7 +692,7 @@
var node = this._getInsertionNode(insertionPoint, excludeItems);
// This is the insertion index of the pivot.
if (node)
return this.getResult().treeIndexForNode(node);
return this.getResultView().treeIndexForNode(node);
else if (insertionPoint.orientation == NHRVO.DROP_ON)
return Ci.nsINavHistoryResult.INDEX_INVISIBLE;
return -1;
@@ -686,7 +704,8 @@
canDrop: function VO_canDrop(index, orientation) {
var result = this._self.getResult();
var node = index != -1 ? result.nodeForTreeIndex(index) : result.root;
var resultview = this._self.getResultView();
var node = index != -1 ? resultview.nodeForTreeIndex(index) : result.root;
// Cannot drop before fixed items in the list.
if (node.parent == result.root &&
PlacesController.getIndexOfNode(node) < this._self.peerDropIndex &&

View File

@@ -46,6 +46,7 @@ interface nsINavHistoryQueryResultNode;
interface nsINavHistoryFolderResultNode;
interface nsINavHistoryQuery;
interface nsINavHistoryQueryOptions;
interface nsINavHistoryResult;
interface nsITreeColumn;
interface nsIWritablePropertyBag;
@@ -133,6 +134,13 @@ interface nsINavHistoryResultNode : nsISupports
*/
readonly attribute PRUint32 indentLevel;
/**
* Value with undefined meaning for use by the view. Its initial value will
* be -1. The tree view uses this value to indicate the row in the tree that
* this node is at. Other views may use this value however they choose.
*/
attribute PRInt32 viewIndex;
/**
* You can use this to associate temporary information with the result node.
* This property bag is associated with the result node and is not persisted
@@ -374,6 +382,8 @@ interface nsINavHistoryFolderResultNode : nsINavHistoryQueryResultNode
/**
* 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
@@ -438,22 +448,127 @@ interface nsINavHistoryResultViewObserver : nsISupports
/**
* The result of a history/bookmark query.
* Allows clients to observe what is happening to a result as it updates itself
* according to history and bookmark system events. Register this observer on a
* result using registerView
*
* Use the "root" element to access the children of this query.
* @see nsINavHistoryResult for where this fits in
*/
[scriptable, uuid(25b45a94-3323-4c7b-910a-315f2c59bfb4)]
interface nsINavHistoryResult : nsISupports
[scriptable, uuid(11032c23-a9fd-4918-bc8f-004726a748da)]
interface nsINavHistoryResultViewer : nsISupports
{
/**
* Sorts all nodes recursively by the given parameter, one of
* nsINavHistory.SORT_BY_* This will update the corresponding options for
* this result, so that re-using the current options/queries will always give
* you the current view.
* Called when 'item' is inserted into 'parent' at index 'newIndex'. The item
* previously at index (if any) and everything below it will have been
* shifted down by one. The item may be a container or a leaf.
*/
void sortAll(in PRUint32 aSortingMode);
void itemInserted(in nsINavHistoryContainerResultNode parent,
in nsINavHistoryResultNode item,
in PRUint32 newIndex);
/**
* Called whan 'item' is removed from 'parent' at 'oldIndex'. The item may be
* a container or a leaf. This function will be called after the item has
* been removed from its parent list, but before anything else (including
* NULLing out the item's parent) has happened.
*/
void itemRemoved(in nsINavHistoryContainerResultNode parent,
in nsINavHistoryResultNode item,
in PRUint32 oldIndex);
/**
* Called when an item has been changed and should be repainted. This only
* refers to the specific item. If it is a container, getting this message
* does not imply anything happened to the children. You'll get separate
* messages for those. Also, this may be called for container nodes at times
* when the result thinks it's possible that a twisty mey need to bw redrawn.
*/
void itemChanged(in nsINavHistoryResultNode item);
/**
* Called when an item is being replaced with another item at the exact
* same position.
*/
void itemReplaced(in nsINavHistoryContainerResultNode parent,
in nsINavHistoryResultNode oldItem,
in nsINavHistoryResultNode newItem,
in PRUint32 index);
/**
* Called after a container node went from closed to opened.
*/
void containerOpened(in nsINavHistoryContainerResultNode item);
/**
* Called after a container node went from opened to closed. This will be
* called for the topmost container that is closing, and implies that any
* child containers have closed as well.
*/
void containerClosed(in nsINavHistoryContainerResultNode item);
/**
* Called when something significant has happened within the container. The
* contents of the container should be re-built.
*/
void invalidateContainer(in nsINavHistoryContainerResultNode item);
/**
* Called when something significant is changing that requires everything
* to be recomputed. For example, changing sorting or changing collapse
* duplicates can affect every row.
*/
void invalidateAll();
/**
* This is called to indicate to the UI that the sort has changed to the
* given mode. For trees, for example, this would update the column headers
* to reflect the sorting. For many other types of views, this won't be
* applicable.
*
* @param sortingMode One of nsINavHistoryQueryOptions.SORT_BY_* that
* indicates the new sorting mode.
*
* This only is expected to update the sorting UI. invalidateAll() will also
* get called if the sorting changes to update everything.
*/
void sortingChanged(in PRUint32 sortingMode);
/**
* Called by the result when this object is set using
* nsINavHistoryResult.viewer. This will be set to NULL when the result
* 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);
};
/**
* 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(ecd6ad22-8eb0-4824-8a57-5edad9a08ae6)]
interface nsINavHistoryResultTreeViewer : nsINavHistoryResultViewer
{
/**
* Controls whether duplicate adjacent elements are collapsed into a single
* item in the tree. This prevents you from seeing multiple entries for
@@ -463,36 +578,82 @@ interface nsINavHistoryResult : nsISupports
* ever want one entry per site, you should ask for URIs back instead of
* visits so it will be more efficient.
* Default = true
*
* Changing this value is somewhat heavyweight since it will force a tree
* refresh.
*/
attribute boolean collapseDuplicates;
/**
* This allows you to get at the real node for a given row index in the tree.
* 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 PRUint32 flatItemCount;
/**
* 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 PRUint32 aIndex);
/**
* Reverse of nodeForTreeIndex, returns the row index for a given result node.
* 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).
* parent is collapsed). This is only valid when a tree is attached. The
* the result will always be INDEX_INVISIBLE if not.
*/
const PRUint32 INDEX_INVISIBLE = 0xffffffff;
PRUint32 treeIndexForNode(in nsINavHistoryResultNode aNode);
};
/**
* The result of a history/bookmark query.
*
* Use the "root" element to access the children of this query.
*
* The basic design of the system is a model-view-controller. This result object
* 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.
*/
[scriptable, uuid(25b45a94-3323-4c7b-910a-315f2c59bfb4)]
interface nsINavHistoryResult : nsISupports
{
/**
* Sorts all nodes recursively by the given parameter, one of
* nsINavHistoryQueryOptions.SORT_BY_* This will update the corresponding
* options for this result, so that re-using the current options/queries will
* always give you the current view.
*/
void sortAll(in PRUint32 aSortingMode);
/**
* Add a Tree Builder Observer to handle Tree View methods that the
* HistoryResult object does not implement. If 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.
* The viewer for this result (see comment for the class for how these
* objects are related). This may be null, in which case you can still
* manually walk the tree using the root node. When this is non-null, you
* can access the flattened list of items (flatItemCount, nodeForFlatIndex,
* flatIndexForNode).
*/
void addObserver(in nsINavHistoryResultViewObserver observer,
in boolean ownsWeak);
/**
* Remove a tree builder observer.
*/
void removeObserver(in nsINavHistoryResultViewObserver observer);
attribute nsINavHistoryResultViewer viewer;
/**
* This is the root of the results. It will either be a
@@ -504,6 +665,7 @@ interface nsINavHistoryResult : nsISupports
readonly attribute nsINavHistoryQueryResultNode root;
};
/**
* Similar to nsIRDFObserver for history. Note that we don't pass the data
* source since that is always the global history.

File diff suppressed because it is too large Load Diff

View File

@@ -128,7 +128,11 @@ private:
NS_IMETHOD GetTime(PRTime* aTime) \
{ *aTime = mTime; return NS_OK; } \
NS_IMETHOD GetIndentLevel(PRUint32* aIndentLevel) \
{ *aIndentLevel = mIndentLevel; return NS_OK; }
{ *aIndentLevel = mIndentLevel; return NS_OK; } \
NS_IMETHOD GetViewIndex(PRInt32* aViewIndex) \
{ *aViewIndex = mViewIndex; return NS_OK; } \
NS_IMETHOD SetViewIndex(PRInt32 aViewIndex) \
{ mViewIndex = aViewIndex; return NS_OK; }
// This is used by the base classes instead of
// NS_FORWARD_NSINAVHISTORYRESULTNODE(nsNavHistoryResultNode) because they
@@ -273,11 +277,13 @@ public:
// root's children will have a value of 0, and so on.
PRInt32 mIndentLevel;
// The index into the result's mVisibleElements list of this element. This is
// -1 if it is invalid. For items, >= 0 can be used to determine if the node
// is visible in the list or not. For folders, call IsVisible, since they
// can be the root node which is not itself visible, but its children are.
PRInt32 mVisibleIndex;
// Value used by the view for whatever it wants. For the built-in tree view,
// this is the index into the result's mVisibleElements list of this element.
// This is -1 if it is invalid. For items, >= 0 can be used to determine if
// the node is visible in the list or not. For folders, call IsVisible, since
// they can be the root node which is not itself visible, but its children
// are.
PRInt32 mViewIndex;
};
#ifndef MOZILLA_1_8_BRANCH
@@ -379,6 +385,9 @@ public:
NS_IMETHOD ClearContents() \
{ return nsNavHistoryContainerResultNode::ClearContents(); }
#define NS_NAVHISTORYCONTAINERRESULTNODE_IID \
{ 0x6e3bf8d3, 0x22aa, 0x4065, { 0x86, 0xbc, 0x37, 0x46, 0xb5, 0xb3, 0x2c, 0xe8 } }
class nsNavHistoryContainerResultNode : public nsNavHistoryResultNode,
public nsINavHistoryContainerResultNode
{
@@ -388,6 +397,12 @@ public:
const nsACString& aIconURI, PRUint32 aContainerType,
PRBool aReadOnly, const nsACString& aRemoteContainerType);
#ifdef MOZILLA_1_8_BRANCH
NS_DEFINE_STATIC_IID_ACCESSOR(NS_NAVHISTORYCONTAINERRESULTNODE_IID)
#else
NS_DECLARE_STATIC_IID_ACCESSOR(NS_NAVHISTORYCONTAINERRESULTNODE_IID)
#endif
NS_DECL_ISUPPORTS_INHERITED
NS_FORWARD_COMMON_RESULTNODE_TO_BASE
NS_IMETHOD GetType(PRUint32* type)
@@ -404,7 +419,7 @@ public:
// overridded by descendents to populate
virtual nsresult OpenContainer();
nsresult CloseContainer(PRBool aUpdateVisible = PR_TRUE);
nsresult CloseContainer(PRBool aUpdateView = PR_TRUE);
// this points to the result that owns this container. All containers have
// their result pointer set so we can quickly get to the result without having
@@ -631,6 +646,65 @@ public:
{ *type = nsNavHistoryResultNode::RESULT_TYPE_SEPARATOR; return NS_OK; }
};
// nsNavHistoryResultTreeViewer
//
class nsNavHistoryResultTreeViewer : public nsINavHistoryResultTreeViewer,
public nsITreeView
{
public:
nsNavHistoryResultTreeViewer();
virtual ~nsNavHistoryResultTreeViewer() {}
NS_DECL_ISUPPORTS
NS_DECL_NSINAVHISTORYRESULTVIEWER
NS_DECL_NSINAVHISTORYRESULTTREEVIEWER
NS_DECL_NSITREEVIEW
protected:
nsRefPtr<nsNavHistoryResult> mResult;
nsCOMPtr<nsITreeBoxObject> mTree; // will be null when no tree attached
nsCOMPtr<nsITreeSelection> mSelection; // may be null
PRBool mCollapseDuplicates;
// This value indicates whether we should try to compute session boundaries.
// It is cached so we don't have to compute it every time we want to get a
// row style.
PRBool mShowSessions;
void ComputeShowSessions();
// This list is used to map rows to nodes.
typedef nsTArray< nsCOMPtr<nsNavHistoryResultNode> > VisibleList;
VisibleList mVisibleElements;
nsresult BuildVisibleList();
nsresult BuildVisibleSection(nsNavHistoryContainerResultNode* aContainer,
VisibleList* aVisible,
PRUint32 aVisibleStartIndex);
PRUint32 CountVisibleRowsForItem(nsNavHistoryResultNode* aNode);
nsresult RefreshVisibleSection(nsNavHistoryContainerResultNode* aContainer);
PRBool CanCollapseDuplicates(nsNavHistoryResultNode* aTop,
nsNavHistoryResultNode* aNext,
PRUint32* aShowThisOne);
// external observers
nsMaybeWeakPtrArray<nsINavHistoryResultViewObserver> mObservers;
nsresult FinishInit();
// columns
enum ColumnType { Column_Unknown = -1, Column_Title, Column_URI, Column_Date,
Column_VisitCount };
ColumnType GetColumnType(nsITreeColumn* col);
ColumnType SortTypeToColumnType(PRUint32 aSortType,
PRBool* aDescending = nsnull);
nsresult FormatFriendlyTime(PRTime aTime, nsAString& aResult);
};
// nsNavHistoryResult
//
// nsNavHistory creates this object and fills in mChildren (by getting
@@ -640,11 +714,12 @@ public:
// This object implements nsITreeView so you can just set it to a tree
// view and it will work. This object also observes the necessary history
// and bookmark events to keep itself up-to-date.
//
#define NS_NAVHISTORYRESULT_IID \
{ 0x455d1d40, 0x1b9b, 0x40e6, { 0xa6, 0x41, 0x8b, 0xb7, 0xe8, 0x82, 0x23, 0x87 } }
class nsNavHistoryResult : public nsSupportsWeakReference,
public nsINavHistoryResult,
public nsITreeView,
public nsINavBookmarkObserver,
public nsINavHistoryObserver
{
@@ -655,25 +730,30 @@ public:
nsNavHistoryContainerResultNode* aRoot,
nsNavHistoryResult** result);
// the tree viewer can go faster if it can bypass XPCOM
friend class nsNavHistoryResultTreeViewer;
#ifdef MOZILLA_1_8_BRANCH
NS_DEFINE_STATIC_IID_ACCESSOR(NS_NAVHISTORYRESULT_IID)
#else
NS_DECLARE_STATIC_IID_ACCESSOR(NS_NAVHISTORYRESULT_IID)
#endif
nsresult PropertyBagFor(nsISupports* aObject,
nsIWritablePropertyBag** aBag);
NS_DECL_ISUPPORTS
NS_DECL_NSINAVHISTORYRESULT
NS_DECL_NSITREEVIEW
NS_DECL_BOOKMARK_HISTORY_OBSERVER
// called by container nodes to update the tree when things change
nsresult RefreshVisibleSection(nsNavHistoryContainerResultNode* aContainer);
void AddEverythingObserver(nsNavHistoryQueryResultNode* aNode);
void AddBookmarkObserver(nsNavHistoryFolderResultNode* aNode, PRInt64 aFolder);
void RemoveEverythingObserver(nsNavHistoryQueryResultNode* aNode);
void RemoveBookmarkObserver(nsNavHistoryFolderResultNode* aNode, PRInt64 aFolder);
PRBool CanCollapseDuplicates(nsNavHistoryResultNode* aTop,
nsNavHistoryResultNode* aNext,
PRUint32* aShowThisOne);
// returns the view. NOT-ADDREFED. May be NULL if there is no view
nsINavHistoryResultViewer* GetView() const
{ return mView; }
public:
// two-stage init, use NewHistoryResult to construct
@@ -692,30 +772,11 @@ public:
// but may be overridden if the user clicks on one of the columns.
PRUint32 mSortingMode;
PRBool mCollapseDuplicates;
// This value indicates whether we should try to compute session boundaries.
// It is cached so we don't have to compute it every time we want to get a
// row style.
PRBool mShowSessions;
void ComputeShowSessions();
nsCOMPtr<nsINavHistoryResultViewer> mView;
// property bags for all result nodes, see PropertyBagFor
nsInterfaceHashtable<nsISupportsHashKey, nsIWritablePropertyBag> mPropertyBags;
nsCOMPtr<nsITreeBoxObject> mTree; // will be null if no tree bound
nsCOMPtr<nsITreeSelection> mSelection; // may be null
// This list is maintained only when a tree is attached (mTree != null) to
// the result. It is used to map rows to nodes.
typedef nsTArray< nsCOMPtr<nsNavHistoryResultNode> > VisibleList;
VisibleList mVisibleElements;
nsresult BuildVisibleList();
nsresult BuildVisibleSection(nsNavHistoryContainerResultNode* aContainer,
VisibleList* aVisible,
PRUint32 aVisibleStartIndex);
PRUint32 CountVisibleRowsForItem(nsNavHistoryResultNode* aNode);
// node observers
PRBool mIsHistoryObserver;
PRBool mIsBookmarksObserver;
@@ -724,37 +785,10 @@ public:
nsDataHashtable<nsTrimInt64HashKey, FolderObserverList* > mBookmarkObservers;
FolderObserverList* BookmarkObserversForId(PRInt64 aFolderId, PRBool aCreate);
// external observers
nsMaybeWeakPtrArray<nsINavHistoryResultViewObserver> mObservers;
// columns
enum ColumnType { Column_Unknown = -1, Column_Title, Column_URI, Column_Date,
Column_VisitCount };
ColumnType GetColumnType(nsITreeColumn* col);
ColumnType SortTypeToColumnType(PRUint32 aSortType,
PRBool* aDescending = nsnull);
void SetTreeSortingIndicator();
void RecursiveExpandCollapse(nsNavHistoryContainerResultNode* aContainer,
PRBool aExpand);
void InvalidateTree();
nsresult FormatFriendlyTime(PRTime aTime, nsAString& aResult);
// Notify the result that a row has been added at index aIndex relative
// to aParent.
void RowAdded(PRInt32 aVisibleIndex, nsNavHistoryResultNode* aNode);
// Notify the result that the row with visible index aVisibleIndex has been
// removed from the tree.
void RowsRemoved(PRInt32 aVisibleIndex, PRUint32 aCount = 1);
// Notify the result that the contents of the row at visible index
// aVisibleIndex has been modified.
void RowChanged(PRInt32 aVisibleIndex);
void RowReplaced(PRInt32 aVisibleIndex, nsNavHistoryResultNode* aNode);
};
#endif // nsNavHistoryResult_h_