2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nscore.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIContent.h"
|
2014-06-19 19:01:40 -07:00
|
|
|
#include "mozilla/dom/NodeInfo.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIBoxObject.h"
|
|
|
|
#include "nsITreeBoxObject.h"
|
|
|
|
#include "nsITreeSelection.h"
|
|
|
|
#include "nsITreeColumns.h"
|
|
|
|
#include "nsITreeView.h"
|
|
|
|
#include "nsTreeUtils.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsQuickSort.h"
|
|
|
|
#include "nsTreeRows.h"
|
|
|
|
#include "nsTemplateRule.h"
|
|
|
|
#include "nsTemplateMatch.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsXULContentUtils.h"
|
|
|
|
#include "nsXULTemplateBuilder.h"
|
2010-06-16 10:09:51 -07:00
|
|
|
#include "nsIXULSortService.h"
|
2009-03-20 01:15:35 -07:00
|
|
|
#include "nsTArray.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsUnicharUtils.h"
|
2014-02-27 15:04:46 -08:00
|
|
|
#include "nsNameSpaceManager.h"
|
2011-10-03 12:11:31 -07:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2010-06-16 10:09:51 -07:00
|
|
|
#include "nsWhitespaceTokenizer.h"
|
2010-07-31 11:22:29 -07:00
|
|
|
#include "nsTreeContentView.h"
|
2014-08-19 07:31:00 -07:00
|
|
|
#include "nsIXULStore.h"
|
2014-09-17 06:46:24 -07:00
|
|
|
#include "mozilla/BinarySearch.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// For security check
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A XUL template builder that serves as an tree view, allowing
|
|
|
|
* (pretty much) arbitrary RDF to be presented in an tree.
|
|
|
|
*/
|
|
|
|
class nsXULTreeBuilder : public nsXULTemplateBuilder,
|
|
|
|
public nsIXULTreeBuilder,
|
|
|
|
public nsINativeTreeView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2011-07-01 07:02:04 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsXULTreeBuilder, nsXULTemplateBuilder)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIXULTreeBuilder
|
|
|
|
NS_DECL_NSIXULTREEBUILDER
|
|
|
|
|
|
|
|
// nsITreeView
|
|
|
|
NS_DECL_NSITREEVIEW
|
|
|
|
// nsINativeTreeView: Untrusted code can use us
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD EnsureNative() override { return NS_OK; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-26 04:45:23 -07:00
|
|
|
// nsIMutationObserver
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
protected:
|
2010-06-10 11:11:40 -07:00
|
|
|
friend nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_NewXULTreeBuilder(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
|
|
|
|
2014-09-17 06:46:24 -07:00
|
|
|
friend struct ResultComparator;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXULTreeBuilder();
|
2014-07-08 14:23:16 -07:00
|
|
|
~nsXULTreeBuilder();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Uninitialize the template builder
|
|
|
|
*/
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual void Uninit(bool aIsFinal) override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get sort variables from the active <treecol>
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
EnsureSortVariables();
|
|
|
|
|
|
|
|
virtual nsresult
|
2015-03-21 09:28:04 -07:00
|
|
|
RebuildAll() override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a row, use the row's match to figure out the appropriate
|
|
|
|
* <treerow> in the rule's <action>.
|
|
|
|
*/
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
GetTemplateActionRowFor(int32_t aRow, nsIContent** aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a row and a column ID, use the row's match to figure out
|
|
|
|
* the appropriate <treecell> in the rule's <action>.
|
|
|
|
*/
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
GetTemplateActionCellFor(int32_t aRow, nsITreeColumn* aCol, nsIContent** aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the resource corresponding to a row in the tree.
|
|
|
|
*/
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
GetResourceFor(int32_t aRow, nsIRDFResource** aResource);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a container row, inserting the container's children into
|
|
|
|
* the view.
|
|
|
|
*/
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
OpenContainer(int32_t aIndex, nsIXULTemplateResult* aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for OpenContainer, recursively open subtrees, remembering
|
|
|
|
* persisted ``open'' state
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
OpenSubtreeOf(nsTreeRows::Subtree* aSubtree,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aIndex,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIXULTemplateResult *aResult,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t* aDelta);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
OpenSubtreeForQuerySet(nsTreeRows::Subtree* aSubtree,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aIndex,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIXULTemplateResult *aResult,
|
|
|
|
nsTemplateQuerySet* aQuerySet,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t* aDelta,
|
|
|
|
nsTArray<int32_t>& open);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Close a container row, removing the container's childrem from
|
|
|
|
* the view.
|
|
|
|
*/
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
CloseContainer(int32_t aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the matches for the rows in a subtree
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
RemoveMatchesFor(nsTreeRows::Subtree& subtree);
|
|
|
|
|
|
|
|
/**
|
2014-08-19 07:31:00 -07:00
|
|
|
* Helper method that determines if the specified container is open.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2014-08-19 07:31:00 -07:00
|
|
|
bool
|
|
|
|
IsContainerOpen(nsIXULTemplateResult* aResource);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A sorting callback for NS_QuickSort().
|
|
|
|
*/
|
2008-10-10 08:04:34 -07:00
|
|
|
static int
|
2007-03-22 10:30:00 -07:00
|
|
|
Compare(const void* aLeft, const void* aRight, void* aClosure);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The real sort routine
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2007-03-22 10:30:00 -07:00
|
|
|
CompareResults(nsIXULTemplateResult* aLeft, nsIXULTemplateResult* aRight);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sort the specified subtree, and recursively sort any subtrees
|
|
|
|
* beneath it.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
SortSubtree(nsTreeRows::Subtree* aSubtree);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
HasGeneratedContent(nsIRDFResource* aResource,
|
|
|
|
nsIAtom* aTag,
|
2015-03-21 09:28:04 -07:00
|
|
|
bool* aGenerated) override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// GetInsertionLocations, ReplaceMatch and SynchronizeResult are inherited
|
|
|
|
// from nsXULTemplateBuilder
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if the result can be inserted into the template as a new
|
|
|
|
* row.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
GetInsertionLocations(nsIXULTemplateResult* aResult,
|
2015-03-21 09:28:04 -07:00
|
|
|
nsCOMArray<nsIContent>** aLocations) override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implement result replacement
|
|
|
|
*/
|
|
|
|
virtual nsresult
|
|
|
|
ReplaceMatch(nsIXULTemplateResult* aOldResult,
|
|
|
|
nsTemplateMatch* aNewMatch,
|
|
|
|
nsTemplateRule* aNewMatchRule,
|
2015-03-21 09:28:04 -07:00
|
|
|
void* aContext) override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implement match synchronization
|
|
|
|
*/
|
|
|
|
virtual nsresult
|
2015-03-21 09:28:04 -07:00
|
|
|
SynchronizeResult(nsIXULTemplateResult* aResult) override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The tree's box object, used to communicate with the front-end.
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsITreeBoxObject> mBoxObject;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The tree's selection object.
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsITreeSelection> mSelection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The datasource that's used to persist open folder information
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIRDFDataSource> mPersistStateStore;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The rows in the view
|
|
|
|
*/
|
|
|
|
nsTreeRows mRows;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The currently active sort variable
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIAtom> mSortVariable;
|
|
|
|
|
|
|
|
enum Direction {
|
|
|
|
eDirection_Descending = -1,
|
|
|
|
eDirection_Natural = 0,
|
|
|
|
eDirection_Ascending = +1
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The currently active sort order
|
|
|
|
*/
|
|
|
|
Direction mSortDirection;
|
|
|
|
|
2010-06-16 10:09:51 -07:00
|
|
|
/*
|
|
|
|
* Sort hints (compare case, etc)
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mSortHints;
|
2010-06-16 10:09:51 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* The builder observers.
|
|
|
|
*/
|
2012-12-10 02:27:14 -08:00
|
|
|
nsCOMArray<nsIXULTreeBuilderObserver> mObservers;
|
2014-08-19 07:31:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XUL store for holding open container state
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIXULStore> mLocalStore;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2010-06-10 11:11:40 -07:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_NewXULTreeBuilder(nsISupports* aOuter, REFNSIID aIID, void** aResult)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aResult = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_PRECONDITION(aOuter == nullptr, "no aggregation");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aOuter)
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsXULTreeBuilder* result = new nsXULTreeBuilder();
|
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(result); // stabilize
|
|
|
|
|
|
|
|
rv = result->InitGlobals();
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = result->QueryInterface(aIID, aResult);
|
|
|
|
|
|
|
|
NS_RELEASE(result);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsXULTreeBuilder, nsXULTemplateBuilder)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsXULTreeBuilder, nsXULTemplateBuilder)
|
|
|
|
|
2014-04-25 09:49:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(nsXULTreeBuilder, nsXULTemplateBuilder,
|
|
|
|
mBoxObject,
|
|
|
|
mSelection,
|
|
|
|
mPersistStateStore,
|
2014-08-19 07:31:00 -07:00
|
|
|
mLocalStore,
|
2014-04-25 09:49:00 -07:00
|
|
|
mObservers)
|
2011-07-01 07:02:04 -07:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsXULTreeBuilder)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIXULTreeBuilder)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITreeView)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(XULTreeBuilder)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsXULTemplateBuilder)
|
|
|
|
|
|
|
|
|
|
|
|
nsXULTreeBuilder::nsXULTreeBuilder()
|
2010-06-16 10:09:51 -07:00
|
|
|
: mSortDirection(eDirection_Natural), mSortHints(0)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-08 14:23:16 -07:00
|
|
|
nsXULTreeBuilder::~nsXULTreeBuilder()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULTreeBuilder::Uninit(bool aIsFinal)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = mRows.Count();
|
2007-03-22 10:30:00 -07:00
|
|
|
mRows.Clear();
|
|
|
|
|
|
|
|
if (mBoxObject) {
|
|
|
|
mBoxObject->BeginUpdateBatch();
|
|
|
|
mBoxObject->RowCountChanged(0, -count);
|
2009-05-22 02:04:02 -07:00
|
|
|
if (mBoxObject) {
|
|
|
|
mBoxObject->EndUpdateBatch();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXULTemplateBuilder::Uninit(aIsFinal);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsIXULTreeBuilder methods
|
|
|
|
//
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::GetResourceAtIndex(int32_t aRowIndex, nsIRDFResource** aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aRowIndex < 0 || aRowIndex >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
return GetResourceFor(aRowIndex, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::GetIndexOfResource(nsIRDFResource* aResource, int32_t* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResource);
|
|
|
|
nsTreeRows::iterator iter = mRows.FindByResource(aResource);
|
|
|
|
if (iter == mRows.Last())
|
|
|
|
*aResult = -1;
|
|
|
|
else
|
|
|
|
*aResult = iter.GetRowIndex();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeBuilder::AddObserver(nsIXULTreeBuilderObserver* aObserver)
|
|
|
|
{
|
2012-12-10 02:27:14 -08:00
|
|
|
return mObservers.AppendObject(aObserver) ? NS_OK : NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeBuilder::RemoveObserver(nsIXULTreeBuilderObserver* aObserver)
|
|
|
|
{
|
2012-12-10 02:27:14 -08:00
|
|
|
return mObservers.RemoveObject(aObserver) ? NS_OK : NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeBuilder::Sort(nsIDOMElement* aElement)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> header = do_QueryInterface(aElement);
|
|
|
|
if (! header)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (header->AttrValueIs(kNameSpaceID_None, nsGkAtoms::sortLocked,
|
|
|
|
nsGkAtoms::_true, eCaseMatters))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsAutoString sort;
|
|
|
|
header->GetAttr(kNameSpaceID_None, nsGkAtoms::sort, sort);
|
|
|
|
|
|
|
|
if (sort.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Grab the new sort variable
|
|
|
|
mSortVariable = do_GetAtom(sort);
|
|
|
|
|
2010-06-16 10:09:51 -07:00
|
|
|
nsAutoString hints;
|
|
|
|
header->GetAttr(kNameSpaceID_None, nsGkAtoms::sorthints, hints);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasNaturalState = true;
|
2010-06-16 10:09:51 -07:00
|
|
|
nsWhitespaceTokenizer tokenizer(hints);
|
|
|
|
while (tokenizer.hasMoreTokens()) {
|
|
|
|
const nsDependentSubstring& token(tokenizer.nextToken());
|
|
|
|
if (token.EqualsLiteral("comparecase"))
|
|
|
|
mSortHints |= nsIXULSortService::SORT_COMPARECASE;
|
|
|
|
else if (token.EqualsLiteral("integer"))
|
|
|
|
mSortHints |= nsIXULSortService::SORT_INTEGER;
|
|
|
|
else if (token.EqualsLiteral("twostate"))
|
2011-10-17 07:59:28 -07:00
|
|
|
hasNaturalState = false;
|
2010-06-16 10:09:51 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Cycle the sort direction
|
|
|
|
nsAutoString dir;
|
|
|
|
header->GetAttr(kNameSpaceID_None, nsGkAtoms::sortDirection, dir);
|
|
|
|
|
|
|
|
if (dir.EqualsLiteral("ascending")) {
|
|
|
|
dir.AssignLiteral("descending");
|
|
|
|
mSortDirection = eDirection_Descending;
|
|
|
|
}
|
2010-06-16 10:09:51 -07:00
|
|
|
else if (hasNaturalState && dir.EqualsLiteral("descending")) {
|
2007-03-22 10:30:00 -07:00
|
|
|
dir.AssignLiteral("natural");
|
|
|
|
mSortDirection = eDirection_Natural;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dir.AssignLiteral("ascending");
|
|
|
|
mSortDirection = eDirection_Ascending;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort it.
|
|
|
|
SortSubtree(mRows.GetRoot());
|
|
|
|
mRows.InvalidateCachedRow();
|
|
|
|
if (mBoxObject)
|
|
|
|
mBoxObject->Invalidate();
|
|
|
|
|
|
|
|
nsTreeUtils::UpdateSortIndicators(header, dir);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsITreeView methods
|
|
|
|
//
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::GetRowCount(int32_t* aRowCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aRowCount = mRows.Count();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeBuilder::GetSelection(nsITreeSelection** aSelection)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aSelection = mSelection.get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeBuilder::SetSelection(nsITreeSelection* aSelection)
|
|
|
|
{
|
2010-07-31 11:22:29 -07:00
|
|
|
NS_ENSURE_TRUE(!aSelection ||
|
|
|
|
nsTreeContentView::CanTrustTreeSelection(aSelection),
|
|
|
|
NS_ERROR_DOM_SECURITY_ERR);
|
2007-03-22 10:30:00 -07:00
|
|
|
mSelection = aSelection;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-01-06 16:54:42 -08:00
|
|
|
nsXULTreeBuilder::GetRowProperties(int32_t aIndex, nsAString& aProps)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aIndex >= 0 && aIndex < mRows.Count(), "bad row");
|
|
|
|
if (aIndex < 0 || aIndex >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> row;
|
|
|
|
GetTemplateActionRowFor(aIndex, getter_AddRefs(row));
|
|
|
|
if (row) {
|
|
|
|
nsAutoString raw;
|
|
|
|
row->GetAttr(kNameSpaceID_None, nsGkAtoms::properties, raw);
|
|
|
|
|
|
|
|
if (!raw.IsEmpty()) {
|
2013-01-06 16:54:42 -08:00
|
|
|
SubstituteText(mRows[aIndex]->mMatch->mResult, raw, aProps);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-01-06 16:54:42 -08:00
|
|
|
nsXULTreeBuilder::GetCellProperties(int32_t aRow, nsITreeColumn* aCol,
|
|
|
|
nsAString& aProps)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCol);
|
|
|
|
NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad row");
|
|
|
|
if (aRow < 0 || aRow >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> cell;
|
|
|
|
GetTemplateActionCellFor(aRow, aCol, getter_AddRefs(cell));
|
|
|
|
if (cell) {
|
|
|
|
nsAutoString raw;
|
|
|
|
cell->GetAttr(kNameSpaceID_None, nsGkAtoms::properties, raw);
|
|
|
|
|
|
|
|
if (!raw.IsEmpty()) {
|
2013-01-06 16:54:42 -08:00
|
|
|
SubstituteText(mRows[aRow]->mMatch->mResult, raw, aProps);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-01-06 16:54:42 -08:00
|
|
|
nsXULTreeBuilder::GetColumnProperties(nsITreeColumn* aCol, nsAString& aProps)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCol);
|
|
|
|
// XXX sortactive fu
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::IsContainer(int32_t aIndex, bool* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aIndex >= 0 && aIndex < mRows.Count(), "bad row");
|
|
|
|
if (aIndex < 0 || aIndex >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
nsTreeRows::iterator iter = mRows[aIndex];
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isContainer;
|
2010-10-18 12:56:56 -07:00
|
|
|
iter->mMatch->mResult->GetIsContainer(&isContainer);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-10-18 12:56:56 -07:00
|
|
|
iter->mContainerType = isContainer
|
|
|
|
? nsTreeRows::eContainerType_Container
|
|
|
|
: nsTreeRows::eContainerType_Noncontainer;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
*aResult = (iter->mContainerType == nsTreeRows::eContainerType_Container);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::IsContainerOpen(int32_t aIndex, bool* aOpen)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aIndex >= 0 && aIndex < mRows.Count(), "bad row");
|
|
|
|
if (aIndex < 0 || aIndex >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
nsTreeRows::iterator iter = mRows[aIndex];
|
|
|
|
|
|
|
|
if (iter->mContainerState == nsTreeRows::eContainerState_Unknown) {
|
2014-08-19 07:31:00 -07:00
|
|
|
bool isOpen = IsContainerOpen(iter->mMatch->mResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
iter->mContainerState = isOpen
|
|
|
|
? nsTreeRows::eContainerState_Open
|
|
|
|
: nsTreeRows::eContainerState_Closed;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aOpen = (iter->mContainerState == nsTreeRows::eContainerState_Open);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::IsContainerEmpty(int32_t aIndex, bool* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aIndex >= 0 && aIndex < mRows.Count(), "bad row");
|
|
|
|
if (aIndex < 0 || aIndex >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
nsTreeRows::iterator iter = mRows[aIndex];
|
|
|
|
NS_ASSERTION(iter->mContainerType == nsTreeRows::eContainerType_Container,
|
|
|
|
"asking for empty state on non-container");
|
|
|
|
|
|
|
|
// if recursion is disabled, pretend that the container is empty. This
|
|
|
|
// ensures that folders are still displayed as such, yet won't display
|
|
|
|
// their children
|
|
|
|
if ((mFlags & eDontRecurse) && (iter->mMatch->mResult != mRootResult)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
*aResult = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iter->mContainerFill == nsTreeRows::eContainerFill_Unknown) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isEmpty;
|
2007-03-22 10:30:00 -07:00
|
|
|
iter->mMatch->mResult->GetIsEmpty(&isEmpty);
|
|
|
|
|
|
|
|
iter->mContainerFill = isEmpty
|
|
|
|
? nsTreeRows::eContainerFill_Empty
|
|
|
|
: nsTreeRows::eContainerFill_Nonempty;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = (iter->mContainerFill == nsTreeRows::eContainerFill_Empty);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::IsSeparator(int32_t aIndex, bool* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aIndex >= 0 && aIndex < mRows.Count(), "bad row");
|
|
|
|
if (aIndex < 0 || aIndex >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
nsAutoString type;
|
|
|
|
nsTreeRows::Row& row = *(mRows[aIndex]);
|
|
|
|
row.mMatch->mResult->GetType(type);
|
|
|
|
|
|
|
|
*aResult = type.EqualsLiteral("separator");
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::GetParentIndex(int32_t aRowIndex, int32_t* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aRowIndex >= 0 && aRowIndex < mRows.Count(), "bad row");
|
|
|
|
if (aRowIndex < 0 || aRowIndex >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
// Construct a path to the row
|
|
|
|
nsTreeRows::iterator iter = mRows[aRowIndex];
|
|
|
|
|
|
|
|
// The parent of the row will be at the top of the path
|
|
|
|
nsTreeRows::Subtree* parent = iter.GetParent();
|
|
|
|
|
|
|
|
// Now walk through our previous siblings, subtracting off each
|
|
|
|
// one's subtree size
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = iter.GetChildIndex();
|
2007-03-22 10:30:00 -07:00
|
|
|
while (--index >= 0)
|
|
|
|
aRowIndex -= mRows.GetSubtreeSizeFor(parent, index) + 1;
|
|
|
|
|
|
|
|
// Now the parent's index will be the first row's index, less one.
|
|
|
|
*aResult = aRowIndex - 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::HasNextSibling(int32_t aRowIndex, int32_t aAfterIndex, bool* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aRowIndex >= 0 && aRowIndex < mRows.Count(), "bad row");
|
|
|
|
if (aRowIndex < 0 || aRowIndex >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
// Construct a path to the row
|
|
|
|
nsTreeRows::iterator iter = mRows[aRowIndex];
|
|
|
|
|
|
|
|
// The parent of the row will be at the top of the path
|
|
|
|
nsTreeRows::Subtree* parent = iter.GetParent();
|
|
|
|
|
|
|
|
// We have a next sibling if the child is not the last in the
|
|
|
|
// subtree.
|
|
|
|
*aResult = iter.GetChildIndex() != parent->Count() - 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::GetLevel(int32_t aRowIndex, int32_t* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aRowIndex >= 0 && aRowIndex < mRows.Count(), "bad row");
|
|
|
|
if (aRowIndex < 0 || aRowIndex >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
// Construct a path to the row; the ``level'' is the path length
|
|
|
|
// less one.
|
|
|
|
nsTreeRows::iterator iter = mRows[aRowIndex];
|
|
|
|
*aResult = iter.GetDepth() - 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::GetImageSrc(int32_t aRow, nsITreeColumn* aCol, nsAString& aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCol);
|
|
|
|
NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad index");
|
|
|
|
if (aRow < 0 || aRow >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
// Find the <cell> that corresponds to the column we want.
|
|
|
|
nsCOMPtr<nsIContent> cell;
|
|
|
|
GetTemplateActionCellFor(aRow, aCol, getter_AddRefs(cell));
|
|
|
|
if (cell) {
|
|
|
|
nsAutoString raw;
|
|
|
|
cell->GetAttr(kNameSpaceID_None, nsGkAtoms::src, raw);
|
|
|
|
|
|
|
|
SubstituteText(mRows[aRow]->mMatch->mResult, raw, aResult);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aResult.Truncate();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::GetProgressMode(int32_t aRow, nsITreeColumn* aCol, int32_t* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCol);
|
|
|
|
NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad index");
|
|
|
|
if (aRow < 0 || aRow >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
*aResult = nsITreeView::PROGRESS_NONE;
|
|
|
|
|
|
|
|
// Find the <cell> that corresponds to the column we want.
|
|
|
|
nsCOMPtr<nsIContent> cell;
|
|
|
|
GetTemplateActionCellFor(aRow, aCol, getter_AddRefs(cell));
|
|
|
|
if (cell) {
|
|
|
|
nsAutoString raw;
|
|
|
|
cell->GetAttr(kNameSpaceID_None, nsGkAtoms::mode, raw);
|
|
|
|
|
|
|
|
nsAutoString mode;
|
|
|
|
SubstituteText(mRows[aRow]->mMatch->mResult, raw, mode);
|
|
|
|
|
|
|
|
if (mode.EqualsLiteral("normal"))
|
|
|
|
*aResult = nsITreeView::PROGRESS_NORMAL;
|
|
|
|
else if (mode.EqualsLiteral("undetermined"))
|
|
|
|
*aResult = nsITreeView::PROGRESS_UNDETERMINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::GetCellValue(int32_t aRow, nsITreeColumn* aCol, nsAString& aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCol);
|
|
|
|
NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad index");
|
|
|
|
if (aRow < 0 || aRow >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
// Find the <cell> that corresponds to the column we want.
|
|
|
|
nsCOMPtr<nsIContent> cell;
|
|
|
|
GetTemplateActionCellFor(aRow, aCol, getter_AddRefs(cell));
|
|
|
|
if (cell) {
|
|
|
|
nsAutoString raw;
|
|
|
|
cell->GetAttr(kNameSpaceID_None, nsGkAtoms::value, raw);
|
|
|
|
|
|
|
|
SubstituteText(mRows[aRow]->mMatch->mResult, raw, aResult);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aResult.Truncate();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::GetCellText(int32_t aRow, nsITreeColumn* aCol, nsAString& aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCol);
|
|
|
|
NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad index");
|
|
|
|
if (aRow < 0 || aRow >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
// Find the <cell> that corresponds to the column we want.
|
|
|
|
nsCOMPtr<nsIContent> cell;
|
|
|
|
GetTemplateActionCellFor(aRow, aCol, getter_AddRefs(cell));
|
|
|
|
if (cell) {
|
|
|
|
nsAutoString raw;
|
|
|
|
cell->GetAttr(kNameSpaceID_None, nsGkAtoms::label, raw);
|
|
|
|
|
|
|
|
SubstituteText(mRows[aRow]->mMatch->mResult, raw, aResult);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aResult.Truncate();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeBuilder::SetTree(nsITreeBoxObject* aTree)
|
|
|
|
{
|
|
|
|
mBoxObject = aTree;
|
|
|
|
|
|
|
|
// If this is teardown time, then we're done.
|
|
|
|
if (!mBoxObject) {
|
2011-10-17 07:59:28 -07:00
|
|
|
Uninit(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-02-18 14:52:19 -08:00
|
|
|
NS_ENSURE_TRUE(mRoot, NS_ERROR_NOT_INITIALIZED);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-19 07:31:00 -07:00
|
|
|
// Only use the XUL store if the root's principal is trusted.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isTrusted = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = IsSystemPrincipal(mRoot->NodePrincipal(), &isTrusted);
|
|
|
|
if (NS_SUCCEEDED(rv) && isTrusted) {
|
2014-08-19 07:31:00 -07:00
|
|
|
mLocalStore = do_GetService("@mozilla.org/xul/xulstore;1");
|
|
|
|
if(NS_WARN_IF(!mLocalStore)){
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Rebuild();
|
|
|
|
|
|
|
|
EnsureSortVariables();
|
|
|
|
if (mSortVariable)
|
|
|
|
SortSubtree(mRows.GetRoot());
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::ToggleOpenState(int32_t aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aIndex < 0 || aIndex >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
nsIXULTemplateResult* result = mRows[aIndex]->mMatch->mResult;
|
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (mFlags & eDontRecurse)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (result && result != mRootResult) {
|
|
|
|
// don't open containers if child processing isn't allowed
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mayProcessChildren;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = result->GetMayProcessChildren(&mayProcessChildren);
|
|
|
|
if (NS_FAILED(rv) || !mayProcessChildren)
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-12-10 02:27:14 -08:00
|
|
|
uint32_t count = mObservers.Count();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
nsCOMPtr<nsIXULTreeBuilderObserver> observer = mObservers.SafeObjectAt(i);
|
|
|
|
if (observer)
|
|
|
|
observer->OnToggleOpenState(aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-08-19 07:31:00 -07:00
|
|
|
if (mLocalStore && mRoot) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isOpen;
|
2007-03-22 10:30:00 -07:00
|
|
|
IsContainerOpen(aIndex, &isOpen);
|
|
|
|
|
2014-08-22 13:11:27 -07:00
|
|
|
nsIDocument* doc = mRoot->GetComposedDoc();
|
2014-08-19 07:31:00 -07:00
|
|
|
if (!doc) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2014-08-19 07:31:00 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-19 07:31:00 -07:00
|
|
|
nsIURI* docURI = doc->GetDocumentURI();
|
|
|
|
nsTreeRows::Row& row = *(mRows[aIndex]);
|
|
|
|
nsAutoString nodeid;
|
|
|
|
nsresult rv = row.mMatch->mResult->GetId(nodeid);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-19 07:31:00 -07:00
|
|
|
nsAutoCString utf8uri;
|
|
|
|
rv = docURI->GetSpec(utf8uri);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
NS_ConvertUTF8toUTF16 uri(utf8uri);
|
2014-08-20 09:10:05 -07:00
|
|
|
|
2014-08-19 07:31:00 -07:00
|
|
|
if (isOpen) {
|
|
|
|
mLocalStore->RemoveValue(uri, nodeid, NS_LITERAL_STRING("open"));
|
2007-03-22 10:30:00 -07:00
|
|
|
CloseContainer(aIndex);
|
2014-08-19 07:31:00 -07:00
|
|
|
} else {
|
|
|
|
mLocalStore->SetValue(uri, nodeid, NS_LITERAL_STRING("open"),
|
|
|
|
NS_LITERAL_STRING("true"));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
OpenContainer(aIndex, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeBuilder::CycleHeader(nsITreeColumn* aCol)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCol);
|
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
aCol->GetElement(getter_AddRefs(element));
|
|
|
|
|
2012-12-10 02:27:14 -08:00
|
|
|
nsAutoString id;
|
|
|
|
aCol->GetId(id);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-10 02:27:14 -08:00
|
|
|
uint32_t count = mObservers.Count();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
nsCOMPtr<nsIXULTreeBuilderObserver> observer = mObservers.SafeObjectAt(i);
|
|
|
|
if (observer)
|
|
|
|
observer->OnCycleHeader(id.get(), element);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return Sort(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeBuilder::SelectionChanged()
|
|
|
|
{
|
2012-12-10 02:27:14 -08:00
|
|
|
uint32_t count = mObservers.Count();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
nsCOMPtr<nsIXULTreeBuilderObserver> observer = mObservers.SafeObjectAt(i);
|
|
|
|
if (observer)
|
|
|
|
observer->OnSelectionChanged();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::CycleCell(int32_t aRow, nsITreeColumn* aCol)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCol);
|
2012-12-10 02:27:14 -08:00
|
|
|
|
|
|
|
nsAutoString id;
|
|
|
|
aCol->GetId(id);
|
|
|
|
|
|
|
|
uint32_t count = mObservers.Count();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
nsCOMPtr<nsIXULTreeBuilderObserver> observer = mObservers.SafeObjectAt(i);
|
|
|
|
if (observer)
|
|
|
|
observer->OnCycleCell(aRow, id.get());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::IsEditable(int32_t aRow, nsITreeColumn* aCol, bool* _retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*_retval = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aCol);
|
|
|
|
NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad index");
|
|
|
|
if (aRow < 0 || aRow >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
// Find the <cell> that corresponds to the column we want.
|
|
|
|
nsCOMPtr<nsIContent> cell;
|
|
|
|
GetTemplateActionCellFor(aRow, aCol, getter_AddRefs(cell));
|
|
|
|
if (cell) {
|
|
|
|
nsAutoString raw;
|
|
|
|
cell->GetAttr(kNameSpaceID_None, nsGkAtoms::editable, raw);
|
|
|
|
|
|
|
|
nsAutoString editable;
|
|
|
|
SubstituteText(mRows[aRow]->mMatch->mResult, raw, editable);
|
|
|
|
|
|
|
|
if (editable.EqualsLiteral("false"))
|
2011-10-17 07:59:28 -07:00
|
|
|
*_retval = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::IsSelectable(int32_t aRow, nsITreeColumn* aCol, bool* _retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad index");
|
|
|
|
if (aRow < 0 || aRow >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*_retval = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Find the <cell> that corresponds to the column we want.
|
|
|
|
nsCOMPtr<nsIContent> cell;
|
|
|
|
GetTemplateActionCellFor(aRow, aCol, getter_AddRefs(cell));
|
|
|
|
if (cell) {
|
|
|
|
nsAutoString raw;
|
|
|
|
cell->GetAttr(kNameSpaceID_None, nsGkAtoms::selectable, raw);
|
|
|
|
|
|
|
|
nsAutoString selectable;
|
|
|
|
SubstituteText(mRows[aRow]->mMatch->mResult, raw, selectable);
|
|
|
|
|
|
|
|
if (selectable.EqualsLiteral("false"))
|
2011-10-17 07:59:28 -07:00
|
|
|
*_retval = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::SetCellValue(int32_t aRow, nsITreeColumn* aCol, const nsAString& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCol);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::SetCellText(int32_t aRow, nsITreeColumn* aCol, const nsAString& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCol);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXULTreeBuilder::PerformAction(const char16_t* aAction)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-10 02:27:14 -08:00
|
|
|
uint32_t count = mObservers.Count();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
nsCOMPtr<nsIXULTreeBuilderObserver> observer = mObservers.SafeObjectAt(i);
|
|
|
|
if (observer)
|
|
|
|
observer->OnPerformAction(aAction);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXULTreeBuilder::PerformActionOnRow(const char16_t* aAction, int32_t aRow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-10 02:27:14 -08:00
|
|
|
uint32_t count = mObservers.Count();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
nsCOMPtr<nsIXULTreeBuilderObserver> observer = mObservers.SafeObjectAt(i);
|
|
|
|
if (observer)
|
|
|
|
observer->OnPerformActionOnRow(aAction, aRow);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXULTreeBuilder::PerformActionOnCell(const char16_t* aAction, int32_t aRow, nsITreeColumn* aCol)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCol);
|
2012-12-10 02:27:14 -08:00
|
|
|
nsAutoString id;
|
|
|
|
aCol->GetId(id);
|
|
|
|
|
|
|
|
uint32_t count = mObservers.Count();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
nsCOMPtr<nsIXULTreeBuilderObserver> observer = mObservers.SafeObjectAt(i);
|
|
|
|
if (observer)
|
|
|
|
observer->OnPerformActionOnCell(aAction, aRow, id.get());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULTreeBuilder::NodeWillBeDestroyed(const nsINode* aNode)
|
|
|
|
{
|
2010-07-21 08:33:32 -07:00
|
|
|
nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this);
|
2012-12-10 02:27:14 -08:00
|
|
|
mObservers.Clear();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsXULTemplateBuilder::NodeWillBeDestroyed(aNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeBuilder::HasGeneratedContent(nsIRDFResource* aResource,
|
|
|
|
nsIAtom* aTag,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aGenerated)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*aGenerated = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aResource);
|
|
|
|
|
|
|
|
if (!mRootResult)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFResource> rootresource;
|
|
|
|
nsresult rv = mRootResult->GetResource(getter_AddRefs(rootresource));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (aResource == rootresource ||
|
|
|
|
mRows.FindByResource(aResource) != mRows.Last())
|
2011-10-17 07:59:28 -07:00
|
|
|
*aGenerated = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXULTreeBuilder::GetInsertionLocations(nsIXULTemplateResult* aResult,
|
|
|
|
nsCOMArray<nsIContent>** aLocations)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aLocations = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Get the reference point and check if it is an open container. Rows
|
|
|
|
// should not be generated otherwise.
|
|
|
|
|
|
|
|
nsAutoString ref;
|
|
|
|
nsresult rv = aResult->GetBindingFor(mRefVariable, ref);
|
|
|
|
if (NS_FAILED(rv) || ref.IsEmpty())
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFResource> container;
|
|
|
|
rv = gRDFService->GetUnicodeResource(ref, getter_AddRefs(container));
|
|
|
|
if (NS_FAILED(rv))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Can always insert into the root resource
|
|
|
|
if (container == mRows.GetRootResource())
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsTreeRows::iterator iter = mRows.FindByResource(container);
|
|
|
|
if (iter == mRows.Last())
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return (iter->mContainerState == nsTreeRows::eContainerState_Open);
|
|
|
|
}
|
|
|
|
|
2014-09-17 06:46:24 -07:00
|
|
|
struct ResultComparator
|
|
|
|
{
|
|
|
|
nsXULTreeBuilder* const mTreebuilder;
|
|
|
|
nsIXULTemplateResult* const mResult;
|
|
|
|
ResultComparator(nsXULTreeBuilder* aTreebuilder, nsIXULTemplateResult* aResult)
|
|
|
|
: mTreebuilder(aTreebuilder), mResult(aResult) {}
|
|
|
|
int operator()(const nsTreeRows::Row& aSubtree) const {
|
|
|
|
return mTreebuilder->CompareResults(mResult, aSubtree.mMatch->mResult);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsXULTreeBuilder::ReplaceMatch(nsIXULTemplateResult* aOldResult,
|
|
|
|
nsTemplateMatch* aNewMatch,
|
|
|
|
nsTemplateRule* aNewMatchRule,
|
|
|
|
void *aLocation)
|
|
|
|
{
|
|
|
|
if (! mBoxObject)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (aOldResult) {
|
|
|
|
// Grovel through the rows looking for oldresult.
|
|
|
|
nsTreeRows::iterator iter = mRows.Find(aOldResult);
|
|
|
|
|
|
|
|
NS_ASSERTION(iter != mRows.Last(), "couldn't find row");
|
|
|
|
if (iter == mRows.Last())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Remove the rows from the view
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t row = iter.GetRowIndex();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If the row contains children, remove the matches from the
|
|
|
|
// children so that they can be regenerated again if the element
|
|
|
|
// gets added back.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t delta = mRows.GetSubtreeSizeFor(iter);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (delta)
|
|
|
|
RemoveMatchesFor(*(iter->mSubtree));
|
|
|
|
|
|
|
|
if (mRows.RemoveRowAt(iter) == 0 && iter.GetRowIndex() >= 0) {
|
|
|
|
|
|
|
|
// In this case iter now points to its parent
|
|
|
|
// Invalidate the row's cached fill state
|
|
|
|
iter->mContainerFill = nsTreeRows::eContainerFill_Unknown;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITreeColumns> cols;
|
|
|
|
mBoxObject->GetColumns(getter_AddRefs(cols));
|
|
|
|
if (cols) {
|
|
|
|
nsCOMPtr<nsITreeColumn> primaryCol;
|
|
|
|
cols->GetPrimaryColumn(getter_AddRefs(primaryCol));
|
|
|
|
if (primaryCol)
|
|
|
|
mBoxObject->InvalidateCell(iter.GetRowIndex(), primaryCol);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notify the box object
|
|
|
|
mBoxObject->RowCountChanged(row, -delta - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aNewMatch && aNewMatch->mResult) {
|
|
|
|
// Insertion.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t row = -1;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsTreeRows::Subtree* parent = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIXULTemplateResult* result = aNewMatch->mResult;
|
|
|
|
|
|
|
|
nsAutoString ref;
|
|
|
|
nsresult rv = result->GetBindingFor(mRefVariable, ref);
|
|
|
|
if (NS_FAILED(rv) || ref.IsEmpty())
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFResource> container;
|
|
|
|
rv = gRDFService->GetUnicodeResource(ref, getter_AddRefs(container));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (container != mRows.GetRootResource()) {
|
|
|
|
nsTreeRows::iterator iter = mRows.FindByResource(container);
|
|
|
|
row = iter.GetRowIndex();
|
|
|
|
|
|
|
|
NS_ASSERTION(iter != mRows.Last(), "couldn't find container row");
|
|
|
|
if (iter == mRows.Last())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Use the persist store to remember if the container
|
|
|
|
// is open or closed.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool open = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
IsContainerOpen(row, &open);
|
|
|
|
|
|
|
|
// If it's open, make sure that we've got a subtree structure ready.
|
|
|
|
if (open)
|
|
|
|
parent = mRows.EnsureSubtreeFor(iter);
|
|
|
|
|
|
|
|
// We know something has just been inserted into the
|
|
|
|
// container, so whether its open or closed, make sure
|
|
|
|
// that we've got our tree row's state correct.
|
|
|
|
if ((iter->mContainerType != nsTreeRows::eContainerType_Container) ||
|
|
|
|
(iter->mContainerFill != nsTreeRows::eContainerFill_Nonempty)) {
|
|
|
|
iter->mContainerType = nsTreeRows::eContainerType_Container;
|
|
|
|
iter->mContainerFill = nsTreeRows::eContainerFill_Nonempty;
|
|
|
|
mBoxObject->InvalidateRow(iter.GetRowIndex());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
parent = mRows.GetRoot();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent) {
|
|
|
|
// If we get here, then we're inserting into an open
|
|
|
|
// container. By default, place the new element at the
|
|
|
|
// end of the container
|
2014-09-17 06:46:24 -07:00
|
|
|
size_t index = parent->Count();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mSortVariable) {
|
2014-09-17 06:46:24 -07:00
|
|
|
// Figure out where to put the new element through
|
|
|
|
// binary search.
|
|
|
|
mozilla::BinarySearchIf(*parent, 0, parent->Count(),
|
|
|
|
ResultComparator(this, result), &index);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsTreeRows::iterator iter =
|
|
|
|
mRows.InsertRowAt(aNewMatch, parent, index);
|
|
|
|
|
|
|
|
mBoxObject->RowCountChanged(iter.GetRowIndex(), +1);
|
|
|
|
|
|
|
|
// See if this newly added row is open; in which case,
|
|
|
|
// recursively add its children to the tree, too.
|
|
|
|
|
|
|
|
if (mFlags & eDontRecurse)
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-02-22 04:04:47 -08:00
|
|
|
if (result != mRootResult) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// don't open containers if child processing isn't allowed
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mayProcessChildren;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = result->GetMayProcessChildren(&mayProcessChildren);
|
|
|
|
if (NS_FAILED(rv) || ! mayProcessChildren) return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-08-19 07:31:00 -07:00
|
|
|
if (IsContainerOpen(result)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
OpenContainer(iter.GetRowIndex(), result);
|
2014-08-19 07:31:00 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULTreeBuilder::SynchronizeResult(nsIXULTemplateResult* aResult)
|
|
|
|
{
|
|
|
|
if (mBoxObject) {
|
|
|
|
// XXX we could be more conservative and just invalidate the cells
|
|
|
|
// that got whacked...
|
|
|
|
|
|
|
|
nsTreeRows::iterator iter = mRows.Find(aResult);
|
|
|
|
|
|
|
|
NS_ASSERTION(iter != mRows.Last(), "couldn't find row");
|
|
|
|
if (iter == mRows.Last())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t row = iter.GetRowIndex();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (row >= 0)
|
|
|
|
mBoxObject->InvalidateRow(row);
|
|
|
|
|
2015-06-03 15:25:57 -07:00
|
|
|
MOZ_LOG(gXULTemplateLog, LogLevel::Debug,
|
2007-03-22 10:30:00 -07:00
|
|
|
("xultemplate[%p] => row %d", this, row));
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULTreeBuilder::EnsureSortVariables()
|
|
|
|
{
|
|
|
|
// Grovel through <treecols> kids to find the <treecol>
|
|
|
|
// with the sort attributes.
|
|
|
|
nsCOMPtr<nsIContent> treecols;
|
|
|
|
|
|
|
|
nsXULContentUtils::FindChildByTag(mRoot, kNameSpaceID_XUL,
|
|
|
|
nsGkAtoms::treecols,
|
|
|
|
getter_AddRefs(treecols));
|
|
|
|
|
|
|
|
if (!treecols)
|
|
|
|
return NS_OK;
|
2011-09-27 00:54:58 -07:00
|
|
|
|
|
|
|
for (nsIContent* child = treecols->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (child->NodeInfo()->Equals(nsGkAtoms::treecol,
|
|
|
|
kNameSpaceID_XUL)) {
|
|
|
|
if (child->AttrValueIs(kNameSpaceID_None, nsGkAtoms::sortActive,
|
|
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
|
|
|
nsAutoString sort;
|
|
|
|
child->GetAttr(kNameSpaceID_None, nsGkAtoms::sort, sort);
|
|
|
|
if (! sort.IsEmpty()) {
|
|
|
|
mSortVariable = do_GetAtom(sort);
|
|
|
|
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2012-07-30 07:20:58 -07:00
|
|
|
{&nsGkAtoms::ascending, &nsGkAtoms::descending, nullptr};
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (child->FindAttrValueIn(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::sortDirection,
|
|
|
|
strings, eCaseMatters)) {
|
|
|
|
case 0: mSortDirection = eDirection_Ascending; break;
|
|
|
|
case 1: mSortDirection = eDirection_Descending; break;
|
|
|
|
default: mSortDirection = eDirection_Natural; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULTreeBuilder::RebuildAll()
|
|
|
|
{
|
2008-02-18 14:52:19 -08:00
|
|
|
NS_ENSURE_TRUE(mRoot, NS_ERROR_NOT_INITIALIZED);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-22 13:11:27 -07:00
|
|
|
nsCOMPtr<nsIDocument> doc = mRoot->GetComposedDoc();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Bail out early if we are being torn down.
|
|
|
|
if (!doc)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (! mQueryProcessor)
|
|
|
|
return NS_OK;
|
|
|
|
|
2009-05-22 02:04:02 -07:00
|
|
|
if (mBoxObject) {
|
|
|
|
mBoxObject->BeginUpdateBatch();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mQueriesCompiled) {
|
2011-10-17 07:59:28 -07:00
|
|
|
Uninit(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (mBoxObject) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = mRows.Count();
|
2007-03-22 10:30:00 -07:00
|
|
|
mRows.Clear();
|
|
|
|
mBoxObject->RowCountChanged(0, -count);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = CompileQueries();
|
2009-05-22 02:04:02 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && mQuerySets.Length() > 0) {
|
|
|
|
// Seed the rule network with assignments for the tree row variable
|
|
|
|
nsAutoString ref;
|
|
|
|
mRoot->GetAttr(kNameSpaceID_None, nsGkAtoms::ref, ref);
|
|
|
|
if (!ref.IsEmpty()) {
|
|
|
|
rv = mQueryProcessor->TranslateRef(mDataSource, ref,
|
|
|
|
getter_AddRefs(mRootResult));
|
|
|
|
if (NS_SUCCEEDED(rv) && mRootResult) {
|
|
|
|
OpenContainer(-1, mRootResult);
|
2009-05-21 12:35:49 -07:00
|
|
|
|
2009-05-22 02:04:02 -07:00
|
|
|
nsCOMPtr<nsIRDFResource> rootResource;
|
|
|
|
GetResultResource(mRootResult, getter_AddRefs(rootResource));
|
2009-05-21 12:35:49 -07:00
|
|
|
|
2009-05-22 02:04:02 -07:00
|
|
|
mRows.SetRootResource(rootResource);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mBoxObject) {
|
|
|
|
mBoxObject->EndUpdateBatch();
|
|
|
|
}
|
|
|
|
|
2009-05-22 02:04:02 -07:00
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::GetTemplateActionRowFor(int32_t aRow, nsIContent** aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Get the template in the DOM from which we're supposed to
|
|
|
|
// generate text
|
|
|
|
nsTreeRows::Row& row = *(mRows[aRow]);
|
|
|
|
|
|
|
|
// The match stores the indices of the rule and query to use. Use these
|
|
|
|
// to look up the right nsTemplateRule and use that rule's action to get
|
|
|
|
// the treerow in the template.
|
2012-08-22 08:56:38 -07:00
|
|
|
int16_t ruleindex = row.mMatch->RuleIndex();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (ruleindex >= 0) {
|
|
|
|
nsTemplateQuerySet* qs = mQuerySets[row.mMatch->QuerySetPriority()];
|
|
|
|
nsTemplateRule* rule = qs->GetRuleAt(ruleindex);
|
|
|
|
if (rule) {
|
|
|
|
nsCOMPtr<nsIContent> children;
|
2008-12-19 05:43:24 -08:00
|
|
|
nsXULContentUtils::FindChildByTag(rule->GetAction(), kNameSpaceID_XUL,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGkAtoms::treechildren,
|
|
|
|
getter_AddRefs(children));
|
|
|
|
if (children) {
|
|
|
|
nsCOMPtr<nsIContent> item;
|
|
|
|
nsXULContentUtils::FindChildByTag(children, kNameSpaceID_XUL,
|
|
|
|
nsGkAtoms::treeitem,
|
|
|
|
getter_AddRefs(item));
|
|
|
|
if (item)
|
|
|
|
return nsXULContentUtils::FindChildByTag(item,
|
|
|
|
kNameSpaceID_XUL,
|
|
|
|
nsGkAtoms::treerow,
|
|
|
|
aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
*aResult = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::GetTemplateActionCellFor(int32_t aRow,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsITreeColumn* aCol,
|
|
|
|
nsIContent** aResult)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aResult = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!aCol) return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> row;
|
|
|
|
GetTemplateActionRowFor(aRow, getter_AddRefs(row));
|
|
|
|
if (row) {
|
|
|
|
nsCOMPtr<nsIAtom> colAtom;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t colIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
aCol->GetAtom(getter_AddRefs(colAtom));
|
|
|
|
aCol->GetIndex(&colIndex);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t j = 0;
|
2011-09-27 00:54:58 -07:00
|
|
|
for (nsIContent* child = row->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (child->NodeInfo()->Equals(nsGkAtoms::treecell,
|
|
|
|
kNameSpaceID_XUL)) {
|
|
|
|
if (colAtom &&
|
|
|
|
child->AttrValueIs(kNameSpaceID_None, nsGkAtoms::ref,
|
|
|
|
colAtom, eCaseMatters)) {
|
|
|
|
*aResult = child;
|
|
|
|
break;
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
else if (j == (uint32_t)colIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
*aResult = child;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::GetResourceFor(int32_t aRow, nsIRDFResource** aResource)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsTreeRows::Row& row = *(mRows[aRow]);
|
|
|
|
return GetResultResource(row.mMatch->mResult, aResource);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::OpenContainer(int32_t aIndex, nsIXULTemplateResult* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// A row index of -1 in this case means ``open tree body''
|
|
|
|
NS_ASSERTION(aIndex >= -1 && aIndex < mRows.Count(), "bad row");
|
|
|
|
if (aIndex < -1 || aIndex >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
nsTreeRows::Subtree* container;
|
|
|
|
|
|
|
|
if (aIndex >= 0) {
|
|
|
|
nsTreeRows::iterator iter = mRows[aIndex];
|
|
|
|
container = mRows.EnsureSubtreeFor(iter.GetParent(),
|
|
|
|
iter.GetChildIndex());
|
|
|
|
|
|
|
|
iter->mContainerState = nsTreeRows::eContainerState_Open;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
container = mRows.GetRoot();
|
|
|
|
|
|
|
|
if (! container)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count;
|
2007-03-22 10:30:00 -07:00
|
|
|
OpenSubtreeOf(container, aIndex, aResult, &count);
|
|
|
|
|
|
|
|
// Notify the box object
|
|
|
|
if (mBoxObject) {
|
|
|
|
if (aIndex >= 0)
|
|
|
|
mBoxObject->InvalidateRow(aIndex);
|
|
|
|
|
|
|
|
if (count)
|
|
|
|
mBoxObject->RowCountChanged(aIndex + 1, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULTreeBuilder::OpenSubtreeOf(nsTreeRows::Subtree* aSubtree,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aIndex,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIXULTemplateResult *aResult,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t* aDelta)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
nsAutoTArray<int32_t, 8> open;
|
|
|
|
int32_t count = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t rulecount = mQuerySets.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t r = 0; r < rulecount; r++) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTemplateQuerySet* queryset = mQuerySets[r];
|
|
|
|
OpenSubtreeForQuerySet(aSubtree, aIndex, aResult, queryset, &count, open);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now recursively deal with any open sub-containers that just got
|
|
|
|
// inserted. We need to do this back-to-front to avoid skewing offsets.
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = open.Length() - 1; i >= 0; --i) {
|
|
|
|
int32_t index = open[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsTreeRows::Subtree* child =
|
|
|
|
mRows.EnsureSubtreeFor(aSubtree, index);
|
|
|
|
|
|
|
|
nsIXULTemplateResult* result = (*aSubtree)[index].mMatch->mResult;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t delta;
|
2007-03-22 10:30:00 -07:00
|
|
|
OpenSubtreeOf(child, aIndex + index, result, &delta);
|
|
|
|
count += delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort the container.
|
|
|
|
if (mSortVariable) {
|
|
|
|
NS_QuickSort(mRows.GetRowsFor(aSubtree),
|
|
|
|
aSubtree->Count(),
|
|
|
|
sizeof(nsTreeRows::Row),
|
|
|
|
Compare,
|
|
|
|
this);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aDelta = count;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULTreeBuilder::OpenSubtreeForQuerySet(nsTreeRows::Subtree* aSubtree,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aIndex,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIXULTemplateResult* aResult,
|
|
|
|
nsTemplateQuerySet* aQuerySet,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t* aDelta,
|
|
|
|
nsTArray<int32_t>& open)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = *aDelta;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> results;
|
2007-06-15 08:03:44 -07:00
|
|
|
nsresult rv = mQueryProcessor->GenerateResults(mDataSource, aResult,
|
2007-03-22 10:30:00 -07:00
|
|
|
aQuerySet->mCompiledQuery,
|
|
|
|
getter_AddRefs(results));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasMoreResults;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = results->HasMoreElements(&hasMoreResults);
|
|
|
|
|
|
|
|
for (; NS_SUCCEEDED(rv) && hasMoreResults;
|
|
|
|
rv = results->HasMoreElements(&hasMoreResults)) {
|
|
|
|
nsCOMPtr<nsISupports> nr;
|
|
|
|
rv = results->GetNext(getter_AddRefs(nr));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIXULTemplateResult> nextresult = do_QueryInterface(nr);
|
|
|
|
if (!nextresult)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFResource> resultid;
|
|
|
|
rv = GetResultResource(nextresult, getter_AddRefs(resultid));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (! resultid)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// check if there is already an existing match. If so, a previous
|
|
|
|
// query already generated content so the match is just added to the
|
|
|
|
// end of the set of matches.
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool generateContent = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsTemplateMatch* prevmatch = nullptr;
|
|
|
|
nsTemplateMatch* existingmatch = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mMatchMap.Get(resultid, &existingmatch)){
|
|
|
|
// check if there is an existing match that matched a rule
|
|
|
|
while (existingmatch) {
|
|
|
|
if (existingmatch->IsActive())
|
2011-10-17 07:59:28 -07:00
|
|
|
generateContent = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
prevmatch = existingmatch;
|
|
|
|
existingmatch = existingmatch->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTemplateMatch *newmatch =
|
2013-03-04 20:49:49 -08:00
|
|
|
nsTemplateMatch::Create(aQuerySet->Priority(), nextresult, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!newmatch)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
if (generateContent) {
|
|
|
|
// Don't allow cyclic graphs to get our knickers in a knot.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool cyclic = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aIndex >= 0) {
|
|
|
|
for (nsTreeRows::iterator iter = mRows[aIndex]; iter.GetDepth() > 0; iter.Pop()) {
|
|
|
|
nsCOMPtr<nsIRDFResource> parentid;
|
|
|
|
rv = GetResultResource(iter->mMatch->mResult, getter_AddRefs(parentid));
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-03-04 20:49:49 -08:00
|
|
|
nsTemplateMatch::Destroy(newmatch, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resultid == parentid) {
|
2011-10-17 07:59:28 -07:00
|
|
|
cyclic = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cyclic) {
|
|
|
|
NS_WARNING("tree cannot handle cyclic graphs");
|
2013-03-04 20:49:49 -08:00
|
|
|
nsTemplateMatch::Destroy(newmatch, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int16_t ruleindex;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsTemplateRule* matchedrule = nullptr;
|
|
|
|
rv = DetermineMatchedRule(nullptr, nextresult, aQuerySet,
|
2007-03-22 10:30:00 -07:00
|
|
|
&matchedrule, &ruleindex);
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-03-04 20:49:49 -08:00
|
|
|
nsTemplateMatch::Destroy(newmatch, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (matchedrule) {
|
|
|
|
rv = newmatch->RuleMatched(aQuerySet, matchedrule, ruleindex,
|
|
|
|
nextresult);
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-03-04 20:49:49 -08:00
|
|
|
nsTemplateMatch::Destroy(newmatch, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remember that this match applied to this row
|
|
|
|
mRows.InsertRowAt(newmatch, aSubtree, count);
|
|
|
|
|
|
|
|
// If this is open, then remember it so we can recursively add
|
|
|
|
// *its* rows to the tree.
|
2014-08-19 07:31:00 -07:00
|
|
|
if (IsContainerOpen(nextresult)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
if (open.AppendElement(count) == nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
++count;
|
|
|
|
}
|
2010-02-01 10:09:47 -08:00
|
|
|
|
|
|
|
if (mFlags & eLoggingEnabled)
|
2011-10-17 07:59:28 -07:00
|
|
|
OutputMatchToLog(resultid, newmatch, true);
|
2010-02-01 10:09:47 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (prevmatch) {
|
|
|
|
prevmatch->mNext = newmatch;
|
|
|
|
}
|
2012-05-18 10:30:49 -07:00
|
|
|
else {
|
|
|
|
mMatchMap.Put(resultid, newmatch);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aDelta = count;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::CloseContainer(int32_t aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aIndex >= 0 && aIndex < mRows.Count(), "bad row");
|
|
|
|
if (aIndex < 0 || aIndex >= mRows.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
nsTreeRows::iterator iter = mRows[aIndex];
|
|
|
|
|
2010-05-23 15:26:34 -07:00
|
|
|
if (iter->mSubtree)
|
|
|
|
RemoveMatchesFor(*iter->mSubtree);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = mRows.GetSubtreeSizeFor(iter);
|
2007-03-22 10:30:00 -07:00
|
|
|
mRows.RemoveSubtreeFor(iter);
|
|
|
|
|
|
|
|
iter->mContainerState = nsTreeRows::eContainerState_Closed;
|
|
|
|
|
|
|
|
if (mBoxObject) {
|
|
|
|
mBoxObject->InvalidateRow(aIndex);
|
|
|
|
|
|
|
|
if (count)
|
|
|
|
mBoxObject->RowCountChanged(aIndex + 1, -count);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULTreeBuilder::RemoveMatchesFor(nsTreeRows::Subtree& subtree)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = subtree.Count() - 1; i >= 0; --i) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTreeRows::Row& row = subtree[i];
|
|
|
|
|
|
|
|
nsTemplateMatch* match = row.mMatch;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFResource> id;
|
|
|
|
nsresult rv = GetResultResource(match->mResult, getter_AddRefs(id));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsTemplateMatch* existingmatch;
|
|
|
|
if (mMatchMap.Get(id, &existingmatch)) {
|
|
|
|
while (existingmatch) {
|
|
|
|
nsTemplateMatch* nextmatch = existingmatch->mNext;
|
2013-03-04 20:49:49 -08:00
|
|
|
nsTemplateMatch::Destroy(existingmatch, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
existingmatch = nextmatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
mMatchMap.Remove(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((row.mContainerState == nsTreeRows::eContainerState_Open) && row.mSubtree)
|
|
|
|
RemoveMatchesFor(*(row.mSubtree));
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-19 07:31:00 -07:00
|
|
|
bool
|
|
|
|
nsXULTreeBuilder::IsContainerOpen(nsIXULTemplateResult *aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-08-19 07:31:00 -07:00
|
|
|
// items are never open if recursion is disabled
|
|
|
|
if ((mFlags & eDontRecurse) && aResult != mRootResult) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mLocalStore) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-22 13:11:27 -07:00
|
|
|
nsIDocument* doc = mRoot->GetComposedDoc();
|
2014-08-19 07:31:00 -07:00
|
|
|
if (!doc) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIURI* docURI = doc->GetDocumentURI();
|
|
|
|
|
|
|
|
nsAutoString nodeid;
|
|
|
|
nsresult rv = aResult->GetId(nodeid);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString utf8uri;
|
|
|
|
rv = docURI->GetSpec(utf8uri);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
NS_ConvertUTF8toUTF16 uri(utf8uri);
|
|
|
|
|
|
|
|
nsAutoString val;
|
|
|
|
mLocalStore->GetValue(uri, nodeid, NS_LITERAL_STRING("open"), val);
|
|
|
|
return val.EqualsLiteral("true");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nsXULTreeBuilder::Compare(const void* aLeft, const void* aRight, void* aClosure)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsXULTreeBuilder* self = static_cast<nsXULTreeBuilder*>(aClosure);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
nsTreeRows::Row* left = static_cast<nsTreeRows::Row*>
|
|
|
|
(const_cast<void*>(aLeft));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
nsTreeRows::Row* right = static_cast<nsTreeRows::Row*>
|
|
|
|
(const_cast<void*>(aRight));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return self->CompareResults(left->mMatch->mResult, right->mMatch->mResult);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXULTreeBuilder::CompareResults(nsIXULTemplateResult* aLeft, nsIXULTemplateResult* aRight)
|
|
|
|
{
|
2007-06-15 08:03:44 -07:00
|
|
|
// this is an extra check done for RDF queries such that results appear in
|
|
|
|
// the order they appear in their containing Seq
|
|
|
|
if (mSortDirection == eDirection_Natural && mDB) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// If the sort order is ``natural'', then see if the container
|
|
|
|
// is an RDF sequence. If so, we'll try to use the ordinal
|
|
|
|
// properties to determine order.
|
|
|
|
//
|
|
|
|
// XXX the problem with this is, it doesn't always get the
|
|
|
|
// *real* container; e.g.,
|
|
|
|
//
|
|
|
|
// <treerow uri="?uri" />
|
|
|
|
//
|
|
|
|
// <triple subject="?uri"
|
|
|
|
// predicate="http://home.netscape.com/NC-rdf#subheadings"
|
|
|
|
// object="?subheadings" />
|
|
|
|
//
|
|
|
|
// <member container="?subheadings" child="?subheading" />
|
|
|
|
//
|
|
|
|
// In this case mRefVariable is bound to ?uri, not
|
|
|
|
// ?subheadings. (The ``container'' in the template sense !=
|
|
|
|
// container in the RDF sense.)
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> ref;
|
|
|
|
nsresult rv = aLeft->GetBindingObjectFor(mRefVariable, getter_AddRefs(ref));
|
|
|
|
if (NS_FAILED(rv))
|
2012-08-09 01:36:41 -07:00
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFResource> container = do_QueryInterface(ref);
|
|
|
|
if (container) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isSequence = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
gRDFContainerUtils->IsSeq(mDB, container, &isSequence);
|
|
|
|
if (isSequence) {
|
|
|
|
// Determine the indices of the left and right elements
|
|
|
|
// in the container.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t lindex = 0, rindex = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFResource> leftitem;
|
|
|
|
aLeft->GetResource(getter_AddRefs(leftitem));
|
|
|
|
if (leftitem) {
|
|
|
|
gRDFContainerUtils->IndexOf(mDB, container, leftitem, &lindex);
|
|
|
|
if (lindex < 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFResource> rightitem;
|
|
|
|
aRight->GetResource(getter_AddRefs(rightitem));
|
|
|
|
if (rightitem) {
|
|
|
|
gRDFContainerUtils->IndexOf(mDB, container, rightitem, &rindex);
|
|
|
|
if (rindex < 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lindex - rindex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t sortorder;
|
2012-04-03 14:12:31 -07:00
|
|
|
if (!mQueryProcessor)
|
|
|
|
return 0;
|
|
|
|
|
2010-06-16 10:09:51 -07:00
|
|
|
mQueryProcessor->CompareResults(aLeft, aRight, mSortVariable, mSortHints, &sortorder);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (sortorder)
|
|
|
|
sortorder = sortorder * mSortDirection;
|
|
|
|
return sortorder;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULTreeBuilder::SortSubtree(nsTreeRows::Subtree* aSubtree)
|
|
|
|
{
|
|
|
|
NS_QuickSort(mRows.GetRowsFor(aSubtree),
|
|
|
|
aSubtree->Count(),
|
|
|
|
sizeof(nsTreeRows::Row),
|
|
|
|
Compare,
|
|
|
|
this);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = aSubtree->Count() - 1; i >= 0; --i) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTreeRows::Subtree* child = (*aSubtree)[i].mSubtree;
|
|
|
|
if (child)
|
|
|
|
SortSubtree(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* boolean canDrop (in long index, in long orientation); */
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::CanDrop(int32_t index, int32_t orientation,
|
2011-09-28 23:19:26 -07:00
|
|
|
nsIDOMDataTransfer* dataTransfer, bool *_retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*_retval = false;
|
2012-12-10 02:27:14 -08:00
|
|
|
uint32_t count = mObservers.Count();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
nsCOMPtr<nsIXULTreeBuilderObserver> observer = mObservers.SafeObjectAt(i);
|
|
|
|
if (observer) {
|
|
|
|
observer->CanDrop(index, orientation, dataTransfer, _retval);
|
|
|
|
if (*_retval)
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULTreeBuilder::Drop(int32_t row, int32_t orient, nsIDOMDataTransfer* dataTransfer)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-10 02:27:14 -08:00
|
|
|
uint32_t count = mObservers.Count();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
nsCOMPtr<nsIXULTreeBuilderObserver> observer = mObservers.SafeObjectAt(i);
|
|
|
|
if (observer) {
|
|
|
|
bool canDrop = false;
|
|
|
|
observer->CanDrop(row, orient, dataTransfer, &canDrop);
|
|
|
|
if (canDrop)
|
|
|
|
observer->OnDrop(row, orient, dataTransfer);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULTreeBuilder::IsSorted(bool *_retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*_retval = (mSortVariable != nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|