зеркало из https://github.com/mozilla/pjs.git
bug 315570
r=bryner r=annie.sullivan Add a reusable autocomplete result type that doesn't depend on Mork. Components can easily provide autocomplete results using this interface and implementation.
This commit is contained in:
Родитель
d080d41d53
Коммит
36a99f6872
|
@ -73,6 +73,7 @@ Extra:
|
|||
#include <stdio.h>
|
||||
#include "nsNavHistory.h"
|
||||
|
||||
#include "nsArray.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsCollationCID.h"
|
||||
|
@ -100,7 +101,6 @@ Extra:
|
|||
#include "nsArrayEnumerator.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsEnumeratorUtils.h"
|
||||
#include "nsAutoCompleteStorageResult.h"
|
||||
#include "nsPrintfCString.h"
|
||||
|
||||
#include "mozIStorageService.h"
|
||||
|
@ -130,6 +130,9 @@ Extra:
|
|||
// the value of mLastNow expires every 3 seconds
|
||||
#define HISTORY_EXPIRE_NOW_TIMEOUT (3 * PR_MSEC_PER_SEC)
|
||||
|
||||
#define NS_AUTOCOMPLETESIMPLERESULT_CONTRACTID \
|
||||
"@mozilla.org/autocomplete/simple-result;1"
|
||||
|
||||
NS_IMPL_ISUPPORTS6(nsNavHistory,
|
||||
nsINavHistory,
|
||||
nsIGlobalHistory2,
|
||||
|
@ -1803,6 +1806,65 @@ nsNavHistory::Observe(nsISupports *aSubject, const char *aTopic,
|
|||
|
||||
// nsIAutoCompleteSearch *******************************************************
|
||||
|
||||
|
||||
// AutoCompleteIntermediateResult/Set
|
||||
//
|
||||
// This class holds intermediate autocomplete results so that they can be
|
||||
// sorted. This list is then handed off to a result using FillResult. The
|
||||
// major reason for this is so that we can use nsArray's sorting functions,
|
||||
// not use COM, yet have well-defined lifetimes for the objects. This uses
|
||||
// a void array, but makes sure to delete the objects on desctruction.
|
||||
|
||||
struct AutoCompleteIntermediateResult
|
||||
{
|
||||
nsString url;
|
||||
nsString title;
|
||||
PRUint32 priority;
|
||||
};
|
||||
class AutoCompleteIntermediateResultSet
|
||||
{
|
||||
public:
|
||||
AutoCompleteIntermediateResultSet()
|
||||
{
|
||||
}
|
||||
~AutoCompleteIntermediateResultSet()
|
||||
{
|
||||
for (PRInt32 i = 0; i < mArray.Count(); i ++) {
|
||||
AutoCompleteIntermediateResult* cur = NS_STATIC_CAST(
|
||||
AutoCompleteIntermediateResult*, mArray[i]);
|
||||
delete cur;
|
||||
}
|
||||
}
|
||||
PRBool Add(const nsString& aURL, const nsString& aTitle, PRInt32 aPriority)
|
||||
{
|
||||
AutoCompleteIntermediateResult* cur = new AutoCompleteIntermediateResult;
|
||||
if (! cur)
|
||||
return PR_FALSE;
|
||||
cur->url = aURL;
|
||||
cur->title = aTitle;
|
||||
cur->priority = aPriority;
|
||||
mArray.AppendElement(cur);
|
||||
return PR_TRUE;
|
||||
}
|
||||
void Sort(nsNavHistory* navHistory)
|
||||
{
|
||||
mArray.Sort(nsNavHistory::AutoCompleteSortComparison, navHistory);
|
||||
}
|
||||
nsresult FillResult(nsIAutoCompleteSimpleResult* aResult)
|
||||
{
|
||||
for (PRInt32 i = 0; i < mArray.Count(); i ++)
|
||||
{
|
||||
AutoCompleteIntermediateResult* cur = NS_STATIC_CAST(
|
||||
AutoCompleteIntermediateResult*, mArray[i]);
|
||||
nsresult rv = aResult->AppendMatch(cur->url, cur->title);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
protected:
|
||||
nsVoidArray mArray;
|
||||
};
|
||||
|
||||
// nsNavHistory::StartSearch
|
||||
//
|
||||
|
||||
|
@ -1816,8 +1878,8 @@ nsNavHistory::StartSearch(const nsAString & aSearchString,
|
|||
|
||||
NS_ENSURE_ARG_POINTER(aListener);
|
||||
|
||||
nsCOMPtr<nsIAutoCompleteStorageResult> result =
|
||||
do_CreateInstance("@mozilla.org/autocomplete/storage-result;1", &rv);
|
||||
nsCOMPtr<nsIAutoCompleteSimpleResult> result =
|
||||
do_CreateInstance(NS_AUTOCOMPLETESIMPLERESULT_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
result->SetSearchString(aSearchString);
|
||||
|
||||
|
@ -1847,11 +1909,7 @@ nsNavHistory::StartSearch(const nsAString & aSearchString,
|
|||
if (aSearchString.IsEmpty()) {
|
||||
rv = AutoCompleteTypedSearch(result);
|
||||
} else if (usePrevious) {
|
||||
nsCOMPtr<nsIAutoCompleteStorageResult> prevStorageResult =
|
||||
do_QueryInterface(aPreviousResult, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = AutoCompleteRefineHistorySearch(aSearchString,
|
||||
prevStorageResult, result);
|
||||
rv = AutoCompleteRefineHistorySearch(aSearchString, aPreviousResult, result);
|
||||
} else {
|
||||
rv = AutoCompleteFullHistorySearch(aSearchString, result);
|
||||
}
|
||||
|
@ -1892,7 +1950,7 @@ nsNavHistory::StopSearch()
|
|||
// visit count (primary) and time since last visited (secondary).
|
||||
|
||||
nsresult nsNavHistory::AutoCompleteTypedSearch(
|
||||
nsIAutoCompleteStorageResult* result)
|
||||
nsIAutoCompleteSimpleResult* result)
|
||||
{
|
||||
// note: need to test against hidden = 1 since the column can also be null
|
||||
// (meaning not hidden)
|
||||
|
@ -1908,13 +1966,7 @@ nsresult nsNavHistory::AutoCompleteTypedSearch(
|
|||
dbSelectStatement->GetAsString(0, entryURL);
|
||||
dbSelectStatement->GetAsString(1, entryTitle);
|
||||
|
||||
// note: we never take ownership of this object, we just create it and
|
||||
// hand it to the array, which will addref it for its own use.
|
||||
nsAutoCompleteStorageMatch* entry = new nsAutoCompleteStorageMatch(
|
||||
entryURL, entryTitle, 0);
|
||||
if (! entry)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
rv = result->AppendMatch(entry);
|
||||
rv = result->AppendMatch(entryURL, entryTitle);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
|
@ -1931,7 +1983,7 @@ nsresult nsNavHistory::AutoCompleteTypedSearch(
|
|||
|
||||
nsresult
|
||||
nsNavHistory::AutoCompleteFullHistorySearch(const nsAString& aSearchString,
|
||||
nsIAutoCompleteStorageResult* result)
|
||||
nsIAutoCompleteSimpleResult* result)
|
||||
{
|
||||
// figure out whether any known prefixes are present in the search string
|
||||
// so we know not to ignore them when comparing results later
|
||||
|
@ -1942,7 +1994,8 @@ nsNavHistory::AutoCompleteFullHistorySearch(const nsAString& aSearchString,
|
|||
nsresult rv = mDBFullAutoComplete->BindInt32Parameter(0, mAutoCompleteMaxCount);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMArray<nsIAutoCompleteStorageMatch> resultArray;
|
||||
// load the intermediate result so it can be sorted
|
||||
AutoCompleteIntermediateResultSet resultSet;
|
||||
PRBool hasMore = PR_FALSE;
|
||||
while (NS_SUCCEEDED(mDBFullAutoComplete->ExecuteStep(&hasMore)) && hasMore) {
|
||||
|
||||
|
@ -1962,26 +2015,14 @@ nsNavHistory::AutoCompleteFullHistorySearch(const nsAString& aSearchString,
|
|||
mDBFullAutoComplete->AsInt32(kAutoCompleteIndex_VisitCount),
|
||||
typed);
|
||||
|
||||
// note: we never take ownership of this object, we just create it and
|
||||
// hand it to the array, which will addref it for its own use.
|
||||
nsAutoCompleteStorageMatch* entry = new nsAutoCompleteStorageMatch(
|
||||
entryurl, entrytitle, priority);
|
||||
if (! entry)
|
||||
if (! resultSet.Add(entryurl, entrytitle, priority))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
rv = resultArray.AppendObject(entry);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
}
|
||||
|
||||
// sort and populate the result
|
||||
resultArray.Sort(AutoCompleteSortComparison, this);
|
||||
PRUint32 count = resultArray.Count();
|
||||
for (PRUint32 i = 0; i < count; i ++) {
|
||||
rv = result->AppendMatch(resultArray[i]);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
// sort and populate the final result
|
||||
resultSet.Sort(this);
|
||||
return resultSet.FillResult(result);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1994,8 +2035,8 @@ nsNavHistory::AutoCompleteFullHistorySearch(const nsAString& aSearchString,
|
|||
nsresult
|
||||
nsNavHistory::AutoCompleteRefineHistorySearch(
|
||||
const nsAString& aSearchString,
|
||||
nsIAutoCompleteStorageResult* aPreviousResult,
|
||||
nsIAutoCompleteStorageResult* aNewResult)
|
||||
nsIAutoCompleteResult* aPreviousResult,
|
||||
nsIAutoCompleteSimpleResult* aNewResult)
|
||||
{
|
||||
// figure out whether any known prefixes are present in the search string
|
||||
// so we know not to ignore them when comparing results later
|
||||
|
@ -2006,14 +2047,16 @@ nsNavHistory::AutoCompleteRefineHistorySearch(
|
|||
aPreviousResult->GetMatchCount(&matchCount);
|
||||
|
||||
for (PRUint32 i = 0; i < matchCount; i ++) {
|
||||
nsCOMPtr<nsIAutoCompleteStorageMatch> entry;
|
||||
nsresult rv = aPreviousResult->GetMatchAt(i, getter_AddRefs(entry));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsAutoString cururl;
|
||||
entry->GetValue(cururl);
|
||||
if (AutoCompleteCompare(cururl, aSearchString, exclude))
|
||||
aNewResult->AppendMatch(entry);
|
||||
nsresult rv = aPreviousResult->GetValueAt(i, cururl);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (AutoCompleteCompare(cururl, aSearchString, exclude)) {
|
||||
nsAutoString curcomment;
|
||||
rv = aPreviousResult->GetCommentAt(i, curcomment);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = aNewResult->AppendMatch(cururl, curcomment);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -2130,49 +2173,44 @@ nsNavHistory::AutoCompleteCompare(const nsAString& aHistoryURL,
|
|||
// computation.
|
||||
|
||||
int PR_CALLBACK // static
|
||||
nsNavHistory::AutoCompleteSortComparison(nsIAutoCompleteStorageMatch* match1,
|
||||
nsIAutoCompleteStorageMatch* match2,
|
||||
nsNavHistory::AutoCompleteSortComparison(const void* match1Void,
|
||||
const void* match2Void,
|
||||
void *navHistoryVoid)
|
||||
{
|
||||
// get our class pointer (this is a static function)
|
||||
nsNavHistory* navHistory = NS_STATIC_CAST(nsNavHistory*, navHistoryVoid);
|
||||
|
||||
// get visit counts - we're ignoring all errors and relying on default values
|
||||
PRInt32 item1priority = 0, item2priority = 0;
|
||||
match1->GetPrivatePriority(&item1priority);
|
||||
match2->GetPrivatePriority(&item2priority);
|
||||
const AutoCompleteIntermediateResult* match1 = NS_STATIC_CAST(
|
||||
const AutoCompleteIntermediateResult*, match1Void);
|
||||
const AutoCompleteIntermediateResult* match2 = NS_STATIC_CAST(
|
||||
const AutoCompleteIntermediateResult*, match2Void);
|
||||
|
||||
// In most cases the priorities will be different and we just use them
|
||||
if (item1priority != item2priority)
|
||||
if (match1->priority != match2->priority)
|
||||
{
|
||||
return item2priority - item1priority;
|
||||
return match2->priority - match1->priority;
|
||||
}
|
||||
else
|
||||
{
|
||||
// get URLs
|
||||
nsAutoString url1, url2;
|
||||
match1->GetValue(url1);
|
||||
match2->GetValue(url2);
|
||||
|
||||
// secondary sorting gives priority to site names and paths (ending in a /)
|
||||
PRBool isPath1 = PR_FALSE, isPath2 = PR_FALSE;
|
||||
if (!url1.IsEmpty())
|
||||
isPath1 = (url1.Last() == PRUnichar('/'));
|
||||
if (!url2.IsEmpty())
|
||||
isPath2 = (url2.Last() == PRUnichar('/'));
|
||||
if (!match1->url.IsEmpty())
|
||||
isPath1 = (match1->url.Last() == PRUnichar('/'));
|
||||
if (!match2->url.IsEmpty())
|
||||
isPath2 = (match2->url.Last() == PRUnichar('/'));
|
||||
|
||||
if (isPath1 && !isPath2) return -1; // url1 is a website/path, url2 isn't
|
||||
if (!isPath1 && isPath2) return 1; // url1 isn't a website/path, url2 is
|
||||
if (isPath1 && !isPath2) return -1; // match1->url is a website/path, match2->url isn't
|
||||
if (!isPath1 && isPath2) return 1; // match1->url isn't a website/path, match2->url is
|
||||
|
||||
// find the prefixes so we can sort by the stuff after the prefixes
|
||||
AutoCompleteExclude prefix1, prefix2;
|
||||
navHistory->AutoCompleteGetExcludeInfo(url1, &prefix1);
|
||||
navHistory->AutoCompleteGetExcludeInfo(url2, &prefix2);
|
||||
navHistory->AutoCompleteGetExcludeInfo(match1->url, &prefix1);
|
||||
navHistory->AutoCompleteGetExcludeInfo(match2->url, &prefix2);
|
||||
|
||||
// compare non-prefixed urls
|
||||
PRInt32 ret = Compare(
|
||||
Substring(url1, prefix1.postPrefixOffset, url1.Length()),
|
||||
Substring(url2, prefix2.postPrefixOffset, url2.Length()));
|
||||
Substring(match1->url, prefix1.postPrefixOffset, match1->url.Length()),
|
||||
Substring(match2->url, prefix2.postPrefixOffset, match2->url.Length()));
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
#include "nsIAutoCompleteSearch.h"
|
||||
#include "nsIAutoCompleteResult.h"
|
||||
#include "nsIAutoCompleteResultTypes.h"
|
||||
#include "nsAutoCompleteStorageResult.h"
|
||||
#include "nsIAutoCompleteSimpleResult.h"
|
||||
#include "nsIBrowserHistory.h"
|
||||
#include "nsICollation.h"
|
||||
#include "nsIGlobalHistory.h"
|
||||
|
@ -268,6 +268,7 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
|
||||
// nsNavHistory
|
||||
|
||||
class nsNavHistory : nsSupportsWeakReference,
|
||||
|
@ -276,6 +277,7 @@ class nsNavHistory : nsSupportsWeakReference,
|
|||
public nsIBrowserHistory,
|
||||
public nsIAutoCompleteSearch
|
||||
{
|
||||
friend struct AutoCompleteIntermediateResultSet;
|
||||
public:
|
||||
nsNavHistory();
|
||||
|
||||
|
@ -416,12 +418,12 @@ protected:
|
|||
PRInt32 postPrefixOffset;
|
||||
};
|
||||
|
||||
nsresult AutoCompleteTypedSearch(nsIAutoCompleteStorageResult* result);
|
||||
nsresult AutoCompleteTypedSearch(nsIAutoCompleteSimpleResult* result);
|
||||
nsresult AutoCompleteFullHistorySearch(const nsAString& aSearchString,
|
||||
nsIAutoCompleteStorageResult* result);
|
||||
nsIAutoCompleteSimpleResult* result);
|
||||
nsresult AutoCompleteRefineHistorySearch(const nsAString& aSearchString,
|
||||
nsIAutoCompleteStorageResult* aPreviousResult,
|
||||
nsIAutoCompleteStorageResult* aNewResult);
|
||||
nsIAutoCompleteResult* aPreviousResult,
|
||||
nsIAutoCompleteSimpleResult* aNewResult);
|
||||
void AutoCompleteCutPrefix(nsString* aURL,
|
||||
const AutoCompleteExclude* aExclude);
|
||||
void AutoCompleteGetExcludeInfo(const nsAString& aURL,
|
||||
|
@ -430,8 +432,8 @@ protected:
|
|||
const nsAString& aUserURL,
|
||||
const AutoCompleteExclude& aExclude);
|
||||
PR_STATIC_CALLBACK(int) AutoCompleteSortComparison(
|
||||
nsIAutoCompleteStorageMatch* match1,
|
||||
nsIAutoCompleteStorageMatch* match2,
|
||||
const void* match1Void,
|
||||
const void* match2Void,
|
||||
void *navHistoryVoid);
|
||||
|
||||
nsresult ImportFromMork();
|
||||
|
|
|
@ -52,6 +52,7 @@ XPIDLSRCS = nsIAutoCompleteController.idl \
|
|||
nsIAutoCompleteSearch.idl \
|
||||
nsIAutoCompleteResult.idl \
|
||||
nsIAutoCompleteResultTypes.idl \
|
||||
nsIAutoCompleteSimpleResult.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is autocomplete code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Google Inc.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brett Wilson <brettw@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIAutoCompleteResult.idl"
|
||||
|
||||
/**
|
||||
* This class implements nsIAutoCompleteResult and provides simple methods
|
||||
* for setting the value and result items. It can be used whenever some basic
|
||||
* auto complete results are needed that can be pre-generated and filled into
|
||||
* an array.
|
||||
*/
|
||||
|
||||
[scriptable, uuid(cc79f293-7114-4287-870b-d28aa61aa7df)]
|
||||
interface nsIAutoCompleteSimpleResult : nsIAutoCompleteResult
|
||||
{
|
||||
/**
|
||||
* A writer for the readonly attribute 'searchString' which should contain
|
||||
* the string that the user typed.
|
||||
*/
|
||||
void setSearchString(in AString aSearchString);
|
||||
|
||||
/**
|
||||
* A writer for the readonly attribute 'errorDescription'.
|
||||
*/
|
||||
void setErrorDescription(in AString aErrorDescription);
|
||||
|
||||
/**
|
||||
* A writer for the readonly attribute 'defaultIndex' which should contain
|
||||
* the index of the list that will be selected by default (normally 0).
|
||||
*/
|
||||
void setDefaultIndex(in long aDefaultIndex);
|
||||
|
||||
/**
|
||||
* A writer for the readonly attribute 'searchResult' which should contain
|
||||
* one of the constants nsIAutoCompleteResult.RESULT_* indicating the success
|
||||
* of the search.
|
||||
*/
|
||||
void setSearchResult(in unsigned short aSearchResult);
|
||||
|
||||
/**
|
||||
* Appends a result item consisting of the given value and comment. This is
|
||||
* how you add results.
|
||||
*/
|
||||
void appendMatch(in AString aValue, in AString aComment);
|
||||
};
|
|
@ -62,6 +62,7 @@ REQUIRES = xpcom \
|
|||
|
||||
CPPSRCS = nsAutoCompleteController.cpp \
|
||||
nsAutoCompleteMdbResult.cpp \
|
||||
nsAutoCompleteSimpleResult.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS += \
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
|
||||
#include "nsAutoCompleteController.h"
|
||||
#include "nsAutoCompleteMdbResult.h"
|
||||
#include "nsAutoCompleteSimpleResult.h"
|
||||
|
||||
#include "nsToolkitCompsCID.h"
|
||||
#include "nsIAutoCompleteResultTypes.h"
|
||||
|
@ -1270,6 +1271,7 @@ nsAutoCompleteController::RowIndexToSearch(PRInt32 aRowIndex, PRInt32 *aSearchIn
|
|||
}
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAutoCompleteController)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAutoCompleteSimpleResult)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAutoCompleteMdbResult)
|
||||
|
||||
static const nsModuleComponentInfo components[] =
|
||||
|
@ -1279,6 +1281,11 @@ static const nsModuleComponentInfo components[] =
|
|||
NS_AUTOCOMPLETECONTROLLER_CONTRACTID,
|
||||
nsAutoCompleteControllerConstructor },
|
||||
|
||||
{ "AutoComplete Simple Result",
|
||||
NS_AUTOCOMPLETESIMPLERESULT_CID,
|
||||
NS_AUTOCOMPLETESIMPLERESULT_CONTRACTID,
|
||||
nsAutoCompleteSimpleResultConstructor },
|
||||
|
||||
{ "AutoComplete Mdb Result",
|
||||
NS_AUTOCOMPLETEMDBRESULT_CID,
|
||||
NS_AUTOCOMPLETEMDBRESULT_CONTRACTID,
|
||||
|
|
|
@ -0,0 +1,162 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is autocomplete code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Google Inc.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brett Wilson <brettw@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsAutoCompleteSimpleResult.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsAutoCompleteSimpleResult,
|
||||
nsIAutoCompleteResult,
|
||||
nsIAutoCompleteSimpleResult)
|
||||
|
||||
nsAutoCompleteSimpleResult::nsAutoCompleteSimpleResult() :
|
||||
mDefaultIndex(-1),
|
||||
mSearchResult(RESULT_NOMATCH)
|
||||
{
|
||||
}
|
||||
|
||||
// searchString
|
||||
NS_IMETHODIMP
|
||||
nsAutoCompleteSimpleResult::GetSearchString(nsAString &aSearchString)
|
||||
{
|
||||
aSearchString = mSearchString;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP
|
||||
nsAutoCompleteSimpleResult::SetSearchString(const nsAString &aSearchString)
|
||||
{
|
||||
mSearchString.Assign(aSearchString);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// searchResult
|
||||
NS_IMETHODIMP
|
||||
nsAutoCompleteSimpleResult::GetSearchResult(PRUint16 *aSearchResult)
|
||||
{
|
||||
*aSearchResult = mSearchResult;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP
|
||||
nsAutoCompleteSimpleResult::SetSearchResult(PRUint16 aSearchResult)
|
||||
{
|
||||
mSearchResult = aSearchResult;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// defaultIndex
|
||||
NS_IMETHODIMP
|
||||
nsAutoCompleteSimpleResult::GetDefaultIndex(PRInt32 *aDefaultIndex)
|
||||
{
|
||||
*aDefaultIndex = mDefaultIndex;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP
|
||||
nsAutoCompleteSimpleResult::SetDefaultIndex(PRInt32 aDefaultIndex)
|
||||
{
|
||||
mDefaultIndex = aDefaultIndex;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// errorDescription
|
||||
NS_IMETHODIMP
|
||||
nsAutoCompleteSimpleResult::GetErrorDescription(nsAString & aErrorDescription)
|
||||
{
|
||||
aErrorDescription = mErrorDescription;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP
|
||||
nsAutoCompleteSimpleResult::SetErrorDescription(
|
||||
const nsAString &aErrorDescription)
|
||||
{
|
||||
mErrorDescription.Assign(aErrorDescription);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAutoCompleteSimpleResult::AppendMatch(const nsAString& aValue,
|
||||
const nsAString& aComment)
|
||||
{
|
||||
NS_ASSERTION(mValues.Count() == mComments.Count(), "Arrays out of sync");
|
||||
if (! mValues.AppendString(aValue))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
if (! mComments.AppendString(aComment)) {
|
||||
mValues.RemoveStringAt(mValues.Count() - 1);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAutoCompleteSimpleResult::GetMatchCount(PRUint32 *aMatchCount)
|
||||
{
|
||||
NS_ASSERTION(mValues.Count() == mComments.Count(), "Arrays out of sync");
|
||||
*aMatchCount = mValues.Count();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAutoCompleteSimpleResult::GetValueAt(PRInt32 aIndex, nsAString& _retval)
|
||||
{
|
||||
NS_ENSURE_TRUE(aIndex >= 0 && aIndex < mValues.Count(),
|
||||
NS_ERROR_ILLEGAL_VALUE);
|
||||
NS_ASSERTION(mValues.Count() == mComments.Count(), "Arrays out of sync");
|
||||
mValues.StringAt(aIndex, _retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAutoCompleteSimpleResult::GetCommentAt(PRInt32 aIndex, nsAString& _retval)
|
||||
{
|
||||
NS_ENSURE_TRUE(aIndex >= 0 && aIndex < mComments.Count(),
|
||||
NS_ERROR_ILLEGAL_VALUE);
|
||||
NS_ASSERTION(mValues.Count() == mComments.Count(), "Arrays out of sync");
|
||||
mComments.StringAt(aIndex, _retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAutoCompleteSimpleResult::GetStyleAt(PRInt32 aIndex, nsAString& _retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAutoCompleteSimpleResult::RemoveValueAt(PRInt32 aRowIndex,
|
||||
PRBool aRemoveFromDb)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is autocomplete code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Google Inc.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brett Wilson <brettw@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __nsAutoCompleteSimpleResult__
|
||||
#define __nsAutoCompleteSimpleResult__
|
||||
|
||||
#include "nsIAutoCompleteResult.h"
|
||||
#include "nsIAutoCompleteSimpleResult.h"
|
||||
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsString.h"
|
||||
#include "prtypes.h"
|
||||
|
||||
class nsAutoCompleteSimpleResult : public nsIAutoCompleteSimpleResult
|
||||
{
|
||||
public:
|
||||
nsAutoCompleteSimpleResult();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIAUTOCOMPLETERESULT
|
||||
NS_DECL_NSIAUTOCOMPLETESIMPLERESULT
|
||||
|
||||
protected:
|
||||
~nsAutoCompleteSimpleResult() {};
|
||||
|
||||
// What we really want is an array of structs with value/comment contents.
|
||||
// But then we'd either have to use COM or manage object lifetimes ourselves.
|
||||
// Having two arrays of string simplifies this, but is stupid.
|
||||
nsStringArray mValues;
|
||||
nsStringArray mComments;
|
||||
|
||||
nsString mSearchString;
|
||||
nsString mErrorDescription;
|
||||
PRInt32 mDefaultIndex;
|
||||
PRUint32 mSearchResult;
|
||||
};
|
||||
|
||||
#endif // __nsAutoCompleteSimpleResult__
|
|
@ -44,6 +44,9 @@
|
|||
#define NS_AUTOCOMPLETECONTROLLER_CONTRACTID \
|
||||
"@mozilla.org/autocomplete/controller;1"
|
||||
|
||||
#define NS_AUTOCOMPLETESIMPLERESULT_CONTRACTID \
|
||||
"@mozilla.org/autocomplete/simple-result;1"
|
||||
|
||||
#define NS_AUTOCOMPLETEMDBRESULT_CONTRACTID \
|
||||
"@mozilla.org/autocomplete/mdb-result;1"
|
||||
|
||||
|
@ -78,6 +81,10 @@
|
|||
#define NS_AUTOCOMPLETECONTROLLER_CID \
|
||||
{ 0xf6d5ebbd, 0x34f4, 0x487d, { 0x9d, 0x10, 0x3d, 0x34, 0x12, 0x3e, 0x3e, 0xb9 } }
|
||||
|
||||
// {2ee3039b-2de4-43d9-93b0-649beacff39a}
|
||||
#define NS_AUTOCOMPLETESIMPLERESULT_CID \
|
||||
{ 0x2ee3039b, 0x2de4, 0x43d9, { 0x93, 0xb0, 0x64, 0x9b, 0xea, 0xcf, 0xf3, 0x9a } }
|
||||
|
||||
// {7A6F70B6-2BBD-44b5-9304-501352D44AB5}
|
||||
#define NS_AUTOCOMPLETEMDBRESULT_CID \
|
||||
{ 0x7a6f70b6, 0x2bbd, 0x44b5, { 0x93, 0x4, 0x50, 0x13, 0x52, 0xd4, 0x4a, 0xb5 } }
|
||||
|
|
Загрузка…
Ссылка в новой задаче