Bug 1465347 - Remove the ability to sort results by annotation as it is no longer used. r=mak

MozReview-Commit-ID: bl588eAmkD

Differential Revision: https://phabricator.services.mozilla.com/D1662
This commit is contained in:
Mark Banner 2018-06-15 07:39:32 +00:00
Родитель d61184c99d
Коммит a801c17c04
13 изменённых файлов: 36 добавлений и 693 удалений

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

@ -1156,13 +1156,11 @@ var ViewMenu = {
}
// This maps the possible values of columnId (i.e., anonid's of treecols in
// placeContent) to the default sortingMode and sortingAnnotation values for
// each column.
// placeContent) to the default sortingMode for each column.
// key: Sort key in the name of one of the
// nsINavHistoryQueryOptions.SORT_BY_* constants
// dir: Default sort direction to use if none has been specified
// anno: The annotation to sort by, if key is "ANNOTATION"
var colLookupTable = {
const colLookupTable = {
title: { key: "TITLE", dir: "ascending" },
tags: { key: "TAGS", dir: "ascending" },
url: { key: "URI", dir: "ascending" },
@ -1182,7 +1180,6 @@ var ViewMenu = {
aDirection = (aDirection || colLookupTable[columnId].dir).toUpperCase();
var sortConst = "SORT_BY_" + colLookupTable[columnId].key + "_" + aDirection;
result.sortingAnnotation = colLookupTable[columnId].anno || "";
result.sortingMode = Ci.nsINavHistoryQueryOptions[sortConst];
}
};

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

@ -1646,7 +1646,6 @@ PlacesTreeView.prototype = {
let oldSort = this._result.sortingMode;
let newSort;
let newSortingAnnotation = "";
const NHQO = Ci.nsINavHistoryQueryOptions;
switch (this._getColumnType(aColumn)) {
case this.COLUMN_TYPE_TITLE:
@ -1721,7 +1720,6 @@ PlacesTreeView.prototype = {
default:
throw Cr.NS_ERROR_INVALID_ARG;
}
this._result.sortingAnnotation = newSortingAnnotation;
this._result.sortingMode = newSort;
},

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

@ -19,16 +19,14 @@
*/
// Two properties of nsINavHistoryResult control the sort of the tree:
// sortingMode and sortingAnnotation. sortingMode's value is one of the
// nsINavHistoryQueryOptions.SORT_BY_* constants. sortingAnnotation is the
// annotation used to sort for SORT_BY_ANNOTATION_* mode.
// sortingMode. sortingMode's value is one of the
// nsINavHistoryQueryOptions.SORT_BY_* constants.
//
// This lookup table maps the possible values of anonid's of the treecols to
// objects that represent the treecols' correct state after the user sorts the
// previously unsorted tree by selecting a column from the Views > Sort menu.
// sortingMode is constructed from the key and dir properties (i.e.,
// SORT_BY_<key>_<dir>) and sortingAnnotation is checked against anno. anno
// may be undefined if key is not "ANNOTATION".
// SORT_BY_<key>_<dir>).
const SORT_LOOKUP_TABLE = {
title: { key: "TITLE", dir: "ASCENDING" },
tags: { key: "TAGS", dir: "ASCENDING" },
@ -37,9 +35,6 @@ const SORT_LOOKUP_TABLE = {
visitCount: { key: "VISITCOUNT", dir: "DESCENDING" },
dateAdded: { key: "DATEADDED", dir: "DESCENDING" },
lastModified: { key: "LASTMODIFIED", dir: "DESCENDING" },
description: { key: "ANNOTATION",
dir: "ASCENDING",
anno: "bookmarkProperties/description" }
};
// This is the column that's sorted if one is not specified and the tree is
@ -55,17 +50,14 @@ var prevSortDir = null;
var prevSortKey = null;
/**
* Ensures that the sort of aTree is aSortingMode and aSortingAnno.
* Ensures that the sort of aTree is aSortingMode
*
* @param aTree
* the tree to check
* @param aSortingMode
* one of the Ci.nsINavHistoryQueryOptions.SORT_BY_* constants
* @param aSortingAnno
* checked only if sorting mode is one of the
* Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_* constants
*/
function checkSort(aTree, aSortingMode, aSortingAnno) {
function checkSort(aTree, aSortingMode) {
// The placeContent tree's sort is determined by the nsINavHistoryResult it
// stores. Get it and check that the sort is what the caller expects.
let res = aTree.result;
@ -75,14 +67,6 @@ function checkSort(aTree, aSortingMode, aSortingAnno) {
// Check sortingMode.
is(res.sortingMode, aSortingMode,
"column should now have sortingMode " + aSortingMode);
// Check sortingAnnotation, but only if sortingMode is ANNOTATION.
if ([Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING].
includes(aSortingMode)) {
is(res.sortingAnnotation, aSortingAnno,
"column should now have sorting annotation " + aSortingAnno);
}
}
/**
@ -190,11 +174,10 @@ function testSortByColAndDir(aOrganizerWin, aPlaceContentTree, aUnsortFirst) {
"SORT_BY_" + SORT_LOOKUP_TABLE[colId].key + "_" +
(aUnsortFirst ? SORT_LOOKUP_TABLE[colId].dir : prevSortDir);
let expectedSortMode = Ci.nsINavHistoryQueryOptions[sortStr];
let expectedAnno = SORT_LOOKUP_TABLE[colId].anno || "";
// Test sorting by only a column.
setSort(aOrganizerWin, aPlaceContentTree, aUnsortFirst, false, col);
checkSort(aPlaceContentTree, expectedSortMode, expectedAnno);
checkSort(aPlaceContentTree, expectedSortMode);
// Test sorting by both a column and a direction.
["ascending", "descending"].forEach(function(dir) {
@ -202,7 +185,7 @@ function testSortByColAndDir(aOrganizerWin, aPlaceContentTree, aUnsortFirst) {
"SORT_BY_" + SORT_LOOKUP_TABLE[colId].key + "_" + dir.toUpperCase();
expectedSortMode = Ci.nsINavHistoryQueryOptions[sortStr];
setSort(aOrganizerWin, aPlaceContentTree, aUnsortFirst, false, col, dir);
checkSort(aPlaceContentTree, expectedSortMode, expectedAnno);
checkSort(aPlaceContentTree, expectedSortMode);
});
}
}

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

@ -574,12 +574,6 @@ interface nsINavHistoryResult : nsISupports
*/
attribute unsigned short sortingMode;
/**
* The annotation to use in SORT_BY_ANNOTATION_* sorting modes, set this
* before setting the sortingMode attribute.
*/
attribute AUTF8String sortingAnnotation;
/**
* Whether or not notifications on result changes are suppressed.
* Initially set to false.
@ -1004,8 +998,6 @@ interface nsINavHistoryQueryOptions : nsISupports
const unsigned short SORT_BY_LASTMODIFIED_DESCENDING = 14;
const unsigned short SORT_BY_TAGS_ASCENDING = 17;
const unsigned short SORT_BY_TAGS_DESCENDING = 18;
const unsigned short SORT_BY_ANNOTATION_ASCENDING = 19;
const unsigned short SORT_BY_ANNOTATION_DESCENDING = 20;
const unsigned short SORT_BY_FRECENCY_ASCENDING = 21;
const unsigned short SORT_BY_FRECENCY_DESCENDING = 22;
@ -1084,11 +1076,6 @@ interface nsINavHistoryQueryOptions : nsISupports
*/
attribute unsigned short sortingMode;
/**
* The annotation to use in SORT_BY_ANNOTATION_* sorting modes.
*/
attribute AUTF8String sortingAnnotation;
/**
* Sets the result type. One of RESULT_TYPE_* which includes how URIs are
* represented.

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

@ -1889,8 +1889,6 @@ PlacesSQLQueryBuilder::OrderBy()
break;
case nsINavHistoryQueryOptions::SORT_BY_TAGS_ASCENDING:
case nsINavHistoryQueryOptions::SORT_BY_TAGS_DESCENDING:
case nsINavHistoryQueryOptions::SORT_BY_ANNOTATION_ASCENDING:
case nsINavHistoryQueryOptions::SORT_BY_ANNOTATION_DESCENDING:
break; // Sort later in nsNavHistoryQueryResultNode::FillChildren()
case nsINavHistoryQueryOptions::SORT_BY_FRECENCY_ASCENDING:
OrderByColumnIndexAsc(nsNavHistory::kGetInfoIndex_Frecency);

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

@ -87,7 +87,6 @@ static void SetOptionsKeyUint32(const nsCString& aValue,
#define QUERYKEY_URI "uri"
#define QUERYKEY_GROUP "group"
#define QUERYKEY_SORT "sort"
#define QUERYKEY_SORTING_ANNOTATION "sortingAnnotation"
#define QUERYKEY_RESULT_TYPE "type"
#define QUERYKEY_EXCLUDE_ITEMS "excludeItems"
#define QUERYKEY_EXCLUDE_QUERIES "excludeQueries"
@ -307,19 +306,6 @@ nsNavHistory::QueryToQueryString(nsINavHistoryQuery *aQuery,
AppendAmpersandIfNonempty(queryString);
queryString += NS_LITERAL_CSTRING(QUERYKEY_SORT "=");
AppendInt16(queryString, options->SortingMode());
if (options->SortingMode() == nsINavHistoryQueryOptions::SORT_BY_ANNOTATION_DESCENDING ||
options->SortingMode() == nsINavHistoryQueryOptions::SORT_BY_ANNOTATION_ASCENDING) {
// sortingAnnotation
nsAutoCString sortingAnnotation;
if (NS_SUCCEEDED(options->GetSortingAnnotation(sortingAnnotation))) {
nsCString escaped;
if (!NS_Escape(sortingAnnotation, escaped, url_XAlphas))
return NS_ERROR_OUT_OF_MEMORY;
AppendAmpersandIfNonempty(queryString);
queryString += NS_LITERAL_CSTRING(QUERYKEY_SORTING_ANNOTATION "=");
queryString.Append(escaped);
}
}
}
// result type
@ -514,12 +500,6 @@ nsNavHistory::TokensToQuery(const nsTArray<QueryKeyValuePair>& aTokens,
} else if (kvp.key.EqualsLiteral(QUERYKEY_SORT)) {
SetOptionsKeyUint16(kvp.value, aOptions,
&nsINavHistoryQueryOptions::SetSortingMode);
// sorting annotation
} else if (kvp.key.EqualsLiteral(QUERYKEY_SORTING_ANNOTATION)) {
nsCString sortingAnnotation = kvp.value;
NS_UnescapeURL(sortingAnnotation);
rv = aOptions->SetSortingAnnotation(sortingAnnotation);
NS_ENSURE_SUCCESS(rv, rv);
// result type
} else if (kvp.key.EqualsLiteral(QUERYKEY_RESULT_TYPE)) {
SetOptionsKeyUint16(kvp.value, aOptions,
@ -1076,7 +1056,6 @@ nsNavHistoryQueryOptions::nsNavHistoryQueryOptions()
nsNavHistoryQueryOptions::nsNavHistoryQueryOptions(const nsNavHistoryQueryOptions& other)
: mSort(other.mSort)
, mSortingAnnotation(other.mSortingAnnotation)
, mResultType(other.mResultType)
, mExcludeItems(other.mExcludeItems)
, mExcludeQueries(other.mExcludeQueries)
@ -1105,19 +1084,6 @@ nsNavHistoryQueryOptions::SetSortingMode(uint16_t aMode)
return NS_OK;
}
// sortingAnnotation
NS_IMETHODIMP
nsNavHistoryQueryOptions::GetSortingAnnotation(nsACString& _result) {
_result.Assign(mSortingAnnotation);
return NS_OK;
}
NS_IMETHODIMP
nsNavHistoryQueryOptions::SetSortingAnnotation(const nsACString& aSortingAnnotation) {
mSortingAnnotation.Assign(aSortingAnnotation);
return NS_OK;
}
// resultType
NS_IMETHODIMP
nsNavHistoryQueryOptions::GetResultType(uint16_t* aType)

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

@ -139,7 +139,6 @@ private:
// * Add to the deserialization code (see nsNavHistory::QueryStringToQueries)
// * Add to the nsNavHistory.cpp::GetSimpleBookmarksQueryFolder function if applicable
uint16_t mSort;
nsCString mSortingAnnotation;
uint16_t mResultType;
bool mExcludeItems;
bool mExcludeQueries;

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

@ -908,15 +908,6 @@ nsresult nsNavHistoryContainerResultNode::Refresh() {
return NS_OK;
}
void
nsNavHistoryContainerResultNode::GetSortingAnnotation(nsACString& aAnnotation)
{
if (mParent)
mParent->GetSortingAnnotation(aAnnotation);
else if (mResult)
aAnnotation.Assign(mResult->mSortingAnnotation);
}
/**
* @return the sorting comparator function for the give sort type, or null if
* there is no comparator.
@ -944,10 +935,6 @@ nsNavHistoryContainerResultNode::GetSortingComparator(uint16_t aSortType)
return &SortComparison_VisitCountLess;
case nsINavHistoryQueryOptions::SORT_BY_VISITCOUNT_DESCENDING:
return &SortComparison_VisitCountGreater;
case nsINavHistoryQueryOptions::SORT_BY_ANNOTATION_ASCENDING:
return &SortComparison_AnnotationLess;
case nsINavHistoryQueryOptions::SORT_BY_ANNOTATION_DESCENDING:
return &SortComparison_AnnotationGreater;
case nsINavHistoryQueryOptions::SORT_BY_DATEADDED_ASCENDING:
return &SortComparison_DateAddedLess;
case nsINavHistoryQueryOptions::SORT_BY_DATEADDED_DESCENDING:
@ -979,15 +966,12 @@ nsNavHistoryContainerResultNode::GetSortingComparator(uint16_t aSortType)
* have to completely rebuild the visible list after this.
*/
void
nsNavHistoryContainerResultNode::RecursiveSort(
const char* aData, SortComparator aComparator)
nsNavHistoryContainerResultNode::RecursiveSort(SortComparator aComparator)
{
void* data = const_cast<void*>(static_cast<const void*>(aData));
mChildren.Sort(aComparator, data);
mChildren.Sort(aComparator, nullptr);
for (int32_t i = 0; i < mChildren.Count(); ++i) {
if (mChildren[i]->IsContainer())
mChildren[i]->GetAsContainer()->RecursiveSort(aData, aComparator);
mChildren[i]->GetAsContainer()->RecursiveSort(aComparator);
}
}
@ -999,7 +983,7 @@ nsNavHistoryContainerResultNode::RecursiveSort(
uint32_t
nsNavHistoryContainerResultNode::FindInsertionPoint(
nsNavHistoryResultNode* aNode, SortComparator aComparator,
const char* aData, bool* aItemExists)
bool* aItemExists)
{
if (aItemExists)
(*aItemExists) = false;
@ -1007,18 +991,16 @@ nsNavHistoryContainerResultNode::FindInsertionPoint(
if (mChildren.Count() == 0)
return 0;
void* data = const_cast<void*>(static_cast<const void*>(aData));
// The common case is the beginning or the end because this is used to insert
// new items that are added to history, which is usually sorted by date.
int32_t res;
res = aComparator(aNode, mChildren[0], data);
res = aComparator(aNode, mChildren[0], nullptr);
if (res <= 0) {
if (aItemExists && res == 0)
(*aItemExists) = true;
return 0;
}
res = aComparator(aNode, mChildren[mChildren.Count() - 1], data);
res = aComparator(aNode, mChildren[mChildren.Count() - 1], nullptr);
if (res >= 0) {
if (aItemExists && res == 0)
(*aItemExists) = true;
@ -1031,7 +1013,7 @@ nsNavHistoryContainerResultNode::FindInsertionPoint(
if (beginRange == endRange)
return endRange;
uint32_t center = beginRange + (endRange - beginRange) / 2;
int32_t res = aComparator(aNode, mChildren[center], data);
int32_t res = aComparator(aNode, mChildren[center], nullptr);
if (res <= 0) {
endRange = center; // left side
if (aItemExists && res == 0)
@ -1053,23 +1035,21 @@ nsNavHistoryContainerResultNode::FindInsertionPoint(
*/
bool
nsNavHistoryContainerResultNode::DoesChildNeedResorting(uint32_t aIndex,
SortComparator aComparator, const char* aData)
SortComparator aComparator)
{
NS_ASSERTION(aIndex < uint32_t(mChildren.Count()),
"Input index out of range");
if (mChildren.Count() == 1)
return false;
void* data = const_cast<void*>(static_cast<const void*>(aData));
if (aIndex > 0) {
// compare to previous item
if (aComparator(mChildren[aIndex - 1], mChildren[aIndex], data) > 0)
if (aComparator(mChildren[aIndex - 1], mChildren[aIndex], nullptr) > 0)
return true;
}
if (aIndex < uint32_t(mChildren.Count()) - 1) {
// compare to next item
if (aComparator(mChildren[aIndex], mChildren[aIndex + 1], data) > 0)
if (aComparator(mChildren[aIndex], mChildren[aIndex + 1], nullptr) > 0)
return true;
}
return false;
@ -1229,146 +1209,6 @@ int32_t nsNavHistoryContainerResultNode::SortComparison_URIGreater(
return -SortComparison_URILess(a, b, closure);
}
int32_t nsNavHistoryContainerResultNode::SortComparison_AnnotationLess(
nsNavHistoryResultNode* a, nsNavHistoryResultNode* b, void* closure)
{
nsAutoCString annoName(static_cast<char*>(closure));
NS_ENSURE_TRUE(!annoName.IsEmpty(), 0);
bool a_itemAnno = false;
bool b_itemAnno = false;
// Not used for item annos
nsCOMPtr<nsIURI> a_uri, b_uri;
if (a->mItemId != -1) {
a_itemAnno = true;
} else {
nsAutoCString spec;
if (NS_SUCCEEDED(a->GetUri(spec))){
MOZ_ALWAYS_SUCCEEDS(NS_NewURI(getter_AddRefs(a_uri), spec));
}
NS_ENSURE_TRUE(a_uri, 0);
}
if (b->mItemId != -1) {
b_itemAnno = true;
} else {
nsAutoCString spec;
if (NS_SUCCEEDED(b->GetUri(spec))) {
MOZ_ALWAYS_SUCCEEDS(NS_NewURI(getter_AddRefs(b_uri), spec));
}
NS_ENSURE_TRUE(b_uri, 0);
}
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
NS_ENSURE_TRUE(annosvc, 0);
bool a_hasAnno, b_hasAnno;
if (a_itemAnno) {
NS_ENSURE_SUCCESS(annosvc->ItemHasAnnotation(a->mItemId, annoName,
&a_hasAnno), 0);
} else {
NS_ENSURE_SUCCESS(annosvc->PageHasAnnotation(a_uri, annoName,
&a_hasAnno), 0);
}
if (b_itemAnno) {
NS_ENSURE_SUCCESS(annosvc->ItemHasAnnotation(b->mItemId, annoName,
&b_hasAnno), 0);
} else {
NS_ENSURE_SUCCESS(annosvc->PageHasAnnotation(b_uri, annoName,
&b_hasAnno), 0);
}
int32_t value = 0;
if (a_hasAnno || b_hasAnno) {
uint16_t annoType;
if (a_hasAnno) {
if (a_itemAnno) {
NS_ENSURE_SUCCESS(annosvc->GetItemAnnotationType(a->mItemId,
annoName,
&annoType), 0);
} else {
NS_ENSURE_SUCCESS(annosvc->GetPageAnnotationType(a_uri, annoName,
&annoType), 0);
}
}
if (b_hasAnno) {
uint16_t b_type;
if (b_itemAnno) {
NS_ENSURE_SUCCESS(annosvc->GetItemAnnotationType(b->mItemId,
annoName,
&b_type), 0);
} else {
NS_ENSURE_SUCCESS(annosvc->GetPageAnnotationType(b_uri, annoName,
&b_type), 0);
}
// We better make the API not support this state, really
// XXXmano: this is actually wrong for double<->int and int64_t<->int32_t
if (a_hasAnno && b_type != annoType)
return 0;
annoType = b_type;
}
#define GET_ANNOTATIONS_VALUES(METHOD_ITEM, METHOD_PAGE, A_VAL, B_VAL) \
if (a_hasAnno) { \
if (a_itemAnno) { \
NS_ENSURE_SUCCESS(annosvc->METHOD_ITEM(a->mItemId, annoName, \
A_VAL), 0); \
} else { \
NS_ENSURE_SUCCESS(annosvc->METHOD_PAGE(a_uri, annoName, \
A_VAL), 0); \
} \
} \
if (b_hasAnno) { \
if (b_itemAnno) { \
NS_ENSURE_SUCCESS(annosvc->METHOD_ITEM(b->mItemId, annoName, \
B_VAL), 0); \
} else { \
NS_ENSURE_SUCCESS(annosvc->METHOD_PAGE(b_uri, annoName, \
B_VAL), 0); \
} \
}
if (annoType == nsIAnnotationService::TYPE_STRING) {
nsAutoString a_val, b_val;
GET_ANNOTATIONS_VALUES(GetItemAnnotationString,
GetPageAnnotationString, a_val, b_val);
value = SortComparison_StringLess(a_val, b_val);
}
else if (annoType == nsIAnnotationService::TYPE_INT32) {
int32_t a_val = 0, b_val = 0;
GET_ANNOTATIONS_VALUES(GetItemAnnotationInt32,
GetPageAnnotationInt32, &a_val, &b_val);
value = (a_val < b_val) ? -1 : (a_val > b_val) ? 1 : 0;
}
else if (annoType == nsIAnnotationService::TYPE_INT64) {
int64_t a_val = 0, b_val = 0;
GET_ANNOTATIONS_VALUES(GetItemAnnotationInt64,
GetPageAnnotationInt64, &a_val, &b_val);
value = (a_val < b_val) ? -1 : (a_val > b_val) ? 1 : 0;
}
else if (annoType == nsIAnnotationService::TYPE_DOUBLE) {
double a_val = 0, b_val = 0;
GET_ANNOTATIONS_VALUES(GetItemAnnotationDouble,
GetPageAnnotationDouble, &a_val, &b_val);
value = (a_val < b_val) ? -1 : (a_val > b_val) ? 1 : 0;
}
}
// Note we also fall back to the title-sorting route one of the items didn't
// have the annotation set or if both had it set but in a different storage
// type
if (value == 0)
return SortComparison_TitleLess(a, b, nullptr);
return value;
}
int32_t nsNavHistoryContainerResultNode::SortComparison_AnnotationGreater(
nsNavHistoryResultNode* a, nsNavHistoryResultNode* b, void* closure)
{
return -SortComparison_AnnotationLess(a, b, closure);
}
/**
* Fall back on dates for conflict resolution
*/
@ -1558,11 +1398,8 @@ nsNavHistoryContainerResultNode::InsertSortedChild(
container->FillStats();
}
nsAutoCString sortingAnnotation;
GetSortingAnnotation(sortingAnnotation);
bool itemExists;
uint32_t position = FindInsertionPoint(aNode, comparator,
sortingAnnotation.get(),
&itemExists);
if (aIgnoreDuplicates && itemExists)
return NS_OK;
@ -1589,16 +1426,13 @@ nsNavHistoryContainerResultNode::EnsureItemPosition(uint32_t aIndex) {
if (!comparator)
return false;
nsAutoCString sortAnno;
GetSortingAnnotation(sortAnno);
if (!DoesChildNeedResorting(aIndex, comparator, sortAnno.get()))
if (!DoesChildNeedResorting(aIndex, comparator))
return false;
RefPtr<nsNavHistoryResultNode> node(mChildren[aIndex]);
mChildren.RemoveObjectAt(aIndex);
uint32_t newIndex = FindInsertionPoint(
node, comparator,sortAnno.get(), nullptr);
uint32_t newIndex = FindInsertionPoint(node, comparator, nullptr);
mChildren.InsertObjectAt(node.get(), newIndex);
if (AreChildrenVisible()) {
@ -2164,8 +1998,6 @@ nsNavHistoryQueryResultNode::FillChildren()
// then have proper visit counts and dates.
SortComparator comparator = GetSortingComparator(GetSortType());
if (comparator) {
nsAutoCString sortingAnnotation;
GetSortingAnnotation(sortingAnnotation);
// Usually containers queries results comes already sorted from the
// database, but some locales could have special rules to sort by title.
// RecursiveSort won't apply these rules to containers in containers
@ -2180,10 +2012,12 @@ nsNavHistoryQueryResultNode::FillChildren()
if (IsContainersQuery() &&
sortType == mOptions->SortingMode() &&
(sortType == nsINavHistoryQueryOptions::SORT_BY_TITLE_ASCENDING ||
sortType == nsINavHistoryQueryOptions::SORT_BY_TITLE_DESCENDING))
nsNavHistoryContainerResultNode::RecursiveSort(sortingAnnotation.get(), comparator);
else
RecursiveSort(sortingAnnotation.get(), comparator);
sortType == nsINavHistoryQueryOptions::SORT_BY_TITLE_DESCENDING)) {
nsNavHistoryContainerResultNode::RecursiveSort(comparator);
}
else {
RecursiveSort(comparator);
}
}
}
@ -2352,28 +2186,14 @@ nsNavHistoryQueryResultNode::GetSortType()
void
nsNavHistoryQueryResultNode::GetSortingAnnotation(nsACString& aAnnotation) {
if (mParent) {
// use our sorting, we are not the root
mOptions->GetSortingAnnotation(aAnnotation);
}
else if (mResult) {
aAnnotation.Assign(mResult->mSortingAnnotation);
}
}
void
nsNavHistoryQueryResultNode::RecursiveSort(
const char* aData, SortComparator aComparator)
nsNavHistoryQueryResultNode::RecursiveSort(SortComparator aComparator)
{
void* data = const_cast<void*>(static_cast<const void*>(aData));
if (!IsContainersQuery())
mChildren.Sort(aComparator, data);
mChildren.Sort(aComparator, nullptr);
for (int32_t i = 0; i < mChildren.Count(); ++i) {
if (mChildren[i]->IsContainer())
mChildren[i]->GetAsContainer()->RecursiveSort(aData, aComparator);
mChildren[i]->GetAsContainer()->RecursiveSort(aComparator);
}
}
@ -3295,9 +3115,7 @@ nsNavHistoryFolderResultNode::OnChildrenFilled()
// then have proper visit counts and dates.
SortComparator comparator = GetSortingComparator(GetSortType());
if (comparator) {
nsAutoCString sortingAnnotation;
GetSortingAnnotation(sortingAnnotation);
RecursiveSort(sortingAnnotation.get(), comparator);
RecursiveSort(comparator);
}
}
@ -4140,7 +3958,6 @@ nsNavHistoryResult::nsNavHistoryResult(nsNavHistoryContainerResultNode* aRoot,
, mSuppressNotifications(false)
{
mSortingMode = aOptions->SortingMode();
MOZ_ALWAYS_SUCCEEDS(aOptions->GetSortingAnnotation(mSortingAnnotation));
mRootNode->mResult = this;
MOZ_ASSERT(mRootNode->mIndentLevel == -1,
@ -4344,7 +4161,7 @@ nsNavHistoryResult::SetSortingMode(uint16_t aSortingMode)
if (comparator) {
nsNavHistory* history = nsNavHistory::GetHistoryService();
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
mRootNode->RecursiveSort(mSortingAnnotation.get(), comparator);
mRootNode->RecursiveSort(comparator);
}
NOTIFY_RESULT_OBSERVERS(this, SortingChanged(aSortingMode));
@ -4353,20 +4170,6 @@ nsNavHistoryResult::SetSortingMode(uint16_t aSortingMode)
}
NS_IMETHODIMP
nsNavHistoryResult::GetSortingAnnotation(nsACString& _result) {
_result.Assign(mSortingAnnotation);
return NS_OK;
}
NS_IMETHODIMP
nsNavHistoryResult::SetSortingAnnotation(const nsACString& aSortingAnnotation) {
mSortingAnnotation.Assign(aSortingAnnotation);
return NS_OK;
}
NS_IMETHODIMP
nsNavHistoryResult::AddObserver(nsINavHistoryResultObserver* aObserver,
bool aOwnsWeak)

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

@ -144,9 +144,6 @@ public:
// This var states the fact we need to apply sortingMode in such a situation.
bool mNeedsToApplySortingMode;
// The sorting annotation to be used for in SORT_BY_ANNOTATION_* modes
nsCString mSortingAnnotation;
// node observers
bool mIsHistoryObserver;
bool mIsBookmarkFolderObserver;
@ -488,15 +485,12 @@ public:
// Sorting methods.
typedef nsCOMArray<nsNavHistoryResultNode>::nsCOMArrayComparatorFunc SortComparator;
virtual uint16_t GetSortType();
virtual void GetSortingAnnotation(nsACString& aSortingAnnotation);
static SortComparator GetSortingComparator(uint16_t aSortType);
virtual void RecursiveSort(const char* aData,
SortComparator aComparator);
virtual void RecursiveSort(SortComparator aComparator);
uint32_t FindInsertionPoint(nsNavHistoryResultNode* aNode, SortComparator aComparator,
const char* aData, bool* aItemExists);
bool DoesChildNeedResorting(uint32_t aIndex, SortComparator aComparator,
const char* aData);
bool* aItemExists);
bool DoesChildNeedResorting(uint32_t aIndex, SortComparator aComparator);
static int32_t SortComparison_StringLess(const nsAString& a, const nsAString& b);
@ -527,12 +521,6 @@ public:
static int32_t SortComparison_VisitCountGreater(nsNavHistoryResultNode* a,
nsNavHistoryResultNode* b,
void* closure);
static int32_t SortComparison_AnnotationLess(nsNavHistoryResultNode* a,
nsNavHistoryResultNode* b,
void* closure);
static int32_t SortComparison_AnnotationGreater(nsNavHistoryResultNode* a,
nsNavHistoryResultNode* b,
void* closure);
static int32_t SortComparison_DateAddedLess(nsNavHistoryResultNode* a,
nsNavHistoryResultNode* b,
void* closure);
@ -664,9 +652,7 @@ public:
nsresult Refresh() override;
virtual uint16_t GetSortType() override;
virtual void GetSortingAnnotation(nsACString& aSortingAnnotation) override;
virtual void RecursiveSort(const char* aData,
SortComparator aComparator) override;
virtual void RecursiveSort(SortComparator aComparator) override;
nsresult NotifyIfTagsChanged(nsIURI* aURI);

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

@ -339,11 +339,6 @@ const queryOptionSwitches = [
desc: "nsINavHistoryQueryOptions.sortingMode",
matches(aOptions1, aOptions2) {
if (aOptions1.sortingMode === aOptions2.sortingMode) {
switch (aOptions1.sortingMode) {
case aOptions1.SORT_BY_ANNOTATION_ASCENDING:
case aOptions1.SORT_BY_ANNOTATION_DESCENDING:
return aOptions1.sortingAnnotation === aOptions2.sortingAnnotation;
}
return true;
}
return false;
@ -352,10 +347,6 @@ const queryOptionSwitches = [
function(aQuery, aQueryOptions) {
aQueryOptions.sortingMode = aQueryOptions.SORT_BY_DATE_ASCENDING;
},
function(aQuery, aQueryOptions) {
aQueryOptions.sortingMode = aQueryOptions.SORT_BY_ANNOTATION_ASCENDING;
aQueryOptions.sortingAnnotation = "bookmarks/toolbarFolder";
}
]
},
// resultType

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

@ -720,344 +720,6 @@ tests.push({
}
});
// SORT_BY_ANNOTATION_* (int32)
tests.push({
_sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
async setup() {
info("Sorting test 10: SORT BY ANNOTATION (int32)");
var timeInMicroseconds = Date.now() * 1000;
this._unsortedData = [
{ isVisit: true,
isDetails: true,
lastVisit: timeInMicroseconds,
uri: "http://example.com/b1",
title: "y1",
isPageAnnotation: true,
annoName: "sorting",
annoVal: 2,
annoFlags: 0,
annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
isInQuery: true },
{ isVisit: true,
isDetails: true,
lastVisit: timeInMicroseconds,
uri: "http://example.com/a",
title: "z",
isPageAnnotation: true,
annoName: "sorting",
annoVal: 1,
annoFlags: 0,
annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
isInQuery: true },
{ isVisit: true,
isDetails: true,
lastVisit: timeInMicroseconds,
uri: "http://example.com/c",
title: "x",
isPageAnnotation: true,
annoName: "sorting",
annoVal: 3,
annoFlags: 0,
annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
isInQuery: true },
// if annotations are equal, should fall back to title
{ isVisit: true,
isDetails: true,
lastVisit: timeInMicroseconds,
uri: "http://example.com/b2",
title: "y2",
isPageAnnotation: true,
annoName: "sorting",
annoVal: 2,
annoFlags: 0,
annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
isInQuery: true },
];
this._sortedData = [
this._unsortedData[1],
this._unsortedData[0],
this._unsortedData[3],
this._unsortedData[2],
];
// This function in head_queries.js creates our database with the above data
await task_populateDB(this._unsortedData);
},
check() {
// Query
var query = PlacesUtils.history.getNewQuery();
// query options
var options = PlacesUtils.history.getNewQueryOptions();
options.sortingAnnotation = "sorting";
options.sortingMode = this._sortingMode;
// Results - this gets the result set and opens it for reading and modification.
var result = PlacesUtils.history.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
compareArrayToResult(this._sortedData, root);
root.containerOpen = false;
},
check_reverse() {
this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
this._sortedData.reverse();
this.check();
}
});
// SORT_BY_ANNOTATION_* (int64)
tests.push({
_sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
async setup() {
info("Sorting test 11: SORT BY ANNOTATION (int64)");
var timeInMicroseconds = Date.now() * 1000;
this._unsortedData = [
{ isVisit: true,
isDetails: true,
uri: "http://moz.com/",
lastVisit: timeInMicroseconds,
title: "I",
isPageAnnotation: true,
annoName: "sorting",
annoVal: 0xffffffff1,
annoFlags: 0,
annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
isInQuery: true },
{ isVisit: true,
isDetails: true,
uri: "http://is.com/",
lastVisit: timeInMicroseconds,
title: "love",
isPageAnnotation: true,
annoName: "sorting",
annoVal: 0xffffffff0,
annoFlags: 0,
annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
isInQuery: true },
{ isVisit: true,
isDetails: true,
uri: "http://best.com/",
lastVisit: timeInMicroseconds,
title: "moz",
isPageAnnotation: true,
annoName: "sorting",
annoVal: 0xffffffff2,
annoFlags: 0,
annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
isInQuery: true },
];
this._sortedData = [
this._unsortedData[1],
this._unsortedData[0],
this._unsortedData[2],
];
// This function in head_queries.js creates our database with the above data
await task_populateDB(this._unsortedData);
},
check() {
// Query
var query = PlacesUtils.history.getNewQuery();
// query options
var options = PlacesUtils.history.getNewQueryOptions();
options.sortingAnnotation = "sorting";
options.sortingMode = this._sortingMode;
// Results - this gets the result set and opens it for reading and modification.
var result = PlacesUtils.history.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
compareArrayToResult(this._sortedData, root);
root.containerOpen = false;
},
check_reverse() {
this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
this._sortedData.reverse();
this.check();
}
});
// SORT_BY_ANNOTATION_* (string)
tests.push({
_sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
async setup() {
info("Sorting test 12: SORT BY ANNOTATION (string)");
var timeInMicroseconds = Date.now() * 1000;
this._unsortedData = [
{ isVisit: true,
isDetails: true,
uri: "http://moz.com/",
lastVisit: timeInMicroseconds,
title: "I",
isPageAnnotation: true,
annoName: "sorting",
annoVal: "a",
annoFlags: 0,
annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
isInQuery: true },
{ isVisit: true,
isDetails: true,
uri: "http://is.com/",
lastVisit: timeInMicroseconds,
title: "love",
isPageAnnotation: true,
annoName: "sorting",
annoVal: "",
annoFlags: 0,
annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
isInQuery: true },
{ isVisit: true,
isDetails: true,
uri: "http://best.com/",
lastVisit: timeInMicroseconds,
title: "moz",
isPageAnnotation: true,
annoName: "sorting",
annoVal: "z",
annoFlags: 0,
annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
isInQuery: true },
];
this._sortedData = [
this._unsortedData[1],
this._unsortedData[0],
this._unsortedData[2],
];
// This function in head_queries.js creates our database with the above data
await task_populateDB(this._unsortedData);
},
check() {
// Query
var query = PlacesUtils.history.getNewQuery();
// query options
var options = PlacesUtils.history.getNewQueryOptions();
options.sortingAnnotation = "sorting";
options.sortingMode = this._sortingMode;
// Results - this gets the result set and opens it for reading and modification.
var result = PlacesUtils.history.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
compareArrayToResult(this._sortedData, root);
root.containerOpen = false;
},
check_reverse() {
this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
this._sortedData.reverse();
this.check();
}
});
// SORT_BY_ANNOTATION_* (double)
tests.push({
_sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
async setup() {
info("Sorting test 13: SORT BY ANNOTATION (double)");
var timeInMicroseconds = Date.now() * 1000;
this._unsortedData = [
{ isVisit: true,
isDetails: true,
uri: "http://moz.com/",
lastVisit: timeInMicroseconds,
title: "I",
isPageAnnotation: true,
annoName: "sorting",
annoVal: 1.2,
annoFlags: 0,
annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
isInQuery: true },
{ isVisit: true,
isDetails: true,
uri: "http://is.com/",
lastVisit: timeInMicroseconds,
title: "love",
isPageAnnotation: true,
annoName: "sorting",
annoVal: 1.1,
annoFlags: 0,
annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
isInQuery: true },
{ isVisit: true,
isDetails: true,
uri: "http://best.com/",
lastVisit: timeInMicroseconds,
title: "moz",
isPageAnnotation: true,
annoName: "sorting",
annoVal: 1.3,
annoFlags: 0,
annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
isInQuery: true },
];
this._sortedData = [
this._unsortedData[1],
this._unsortedData[0],
this._unsortedData[2],
];
// This function in head_queries.js creates our database with the above data
await task_populateDB(this._unsortedData);
},
check() {
// Query
var query = PlacesUtils.history.getNewQuery();
// query options
var options = PlacesUtils.history.getNewQueryOptions();
options.sortingAnnotation = "sorting";
options.sortingMode = this._sortingMode;
// Results - this gets the result set and opens it for reading and modification.
var result = PlacesUtils.history.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
compareArrayToResult(this._sortedData, root);
root.containerOpen = false;
},
check_reverse() {
this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
this._sortedData.reverse();
this.check();
}
});
// SORT_BY_FRECENCY_*
tests.push({

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

@ -13,15 +13,4 @@ function run_test() {
query.setParents([PlacesUtils.bookmarks.rootGuid], 1);
Assert.equal(PlacesUtils.history.queryToQueryString(query, options),
`place:parent=${PlacesUtils.bookmarks.rootGuid}`);
// Bug 378828
options.sortingAnnotation = "test anno";
options.sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
var placeURI =
`place:parent=${PlacesUtils.bookmarks.rootGuid}&sort=${Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING}&sortingAnnotation=test%20anno`;
Assert.equal(PlacesUtils.history.queryToQueryString(query, options), placeURI);
options = {};
PlacesUtils.history.queryStringToQuery(placeURI, {}, options);
Assert.equal(options.value.sortingAnnotation, "test anno");
Assert.equal(options.value.sortingMode, Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING);
}

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

@ -96,26 +96,10 @@ add_task(async function test() {
// XXXtodo: test history sortings (visit count, visit date)
// XXXtodo: test different item types once folderId and bookmarkId are merged.
// XXXtodo: test sortingAnnotation functionality with non-bookmark nodes
info("Sort by annotation desc");
let ids = await PlacesUtils.promiseManyItemIds([guid1, guid3]);
PlacesUtils.annotations.setItemAnnotation(ids.get(guid1), "testAnno", "a", 0, 0);
PlacesUtils.annotations.setItemAnnotation(ids.get(guid3), "testAnno", "b", 0, 0);
result.sortingAnnotation = "testAnno";
result.sortingMode = NHQO.SORT_BY_ANNOTATION_DESCENDING;
// guid1 precedes guid2 per title-descending fallback
checkOrder(guid3, guid1, guid2);
// XXXtodo: test dateAdded sort
// XXXtodo: test lastModified sort
// test live update
info("Annotation liveupdate");
PlacesUtils.annotations.setItemAnnotation(ids.get(guid1), "testAnno", "c", 0, 0);
checkOrder(guid1, guid3, guid2);
// Add a visit, then check frecency ordering.
// When the bookmarks service gets onVisit, it asynchronously fetches all