Bug 418712 - nsIAutoCompleteInput should fire an event when a search begins. r=gavin, a1.9=beltzner

This commit is contained in:
dolske@mozilla.com 2008-02-21 15:17:33 -08:00
parent 2130a28164
commit 7c4d95852e
14 changed files with 107 additions and 1 deletions

View File

@ -40,7 +40,7 @@
interface nsIAutoCompletePopup;
[scriptable, uuid(8a5918dc-89ba-4bd0-934c-90e9c21568b8)]
[scriptable, uuid(f5eddd39-f8e0-43b7-bc3d-03623f595e52)]
interface nsIAutoCompleteInput : nsISupports
{
/*
@ -144,6 +144,11 @@ interface nsIAutoCompleteInput : nsISupports
*/
void selectTextRange(in long startIndex, in long endIndex);
/*
* Notification that the search has started
*/
void onSearchBegin();
/*
* Notification that the search concluded successfully
*/

View File

@ -978,6 +978,9 @@ nsAutoCompleteController::StartSearch()
mSearchesOngoing = count;
mFirstSearchResult = PR_TRUE;
// notify the input that the search is beginning
mInput->OnSearchBegin();
PRUint32 searchesFailed = 0;
for (PRUint32 i = 0; i < count; ++i) {
nsCOMPtr<nsIAutoCompleteSearch> search;

View File

@ -76,6 +76,7 @@ AutoCompleteInput.prototype = {
return this.searches[aIndex];
},
onSearchBegin: function() {},
onSearchComplete: function() {},
popupOpen: false,
@ -274,8 +275,17 @@ function run_test() {
// Make an AutoCompleteInput that uses our searches
// and confirms results on search complete
var input = new AutoCompleteInput([emptySearch.name, regularSearch.name]);
var numSearchesStarted = 0;
input.onSearchBegin = function() {
numSearchesStarted++;
do_check_eq(numSearchesStarted, 1);
};
input.onSearchComplete = function() {
do_check_eq(numSearchesStarted, 1);
do_check_eq(controller.searchStatus,
Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);
do_check_eq(controller.matchCount, 2);

View File

@ -75,6 +75,7 @@ AutoCompleteInput.prototype = {
return this.searches[aIndex];
},
onSearchBegin: function() {},
onSearchComplete: function() {},
popupOpen: false,
@ -266,8 +267,17 @@ function run_test() {
// Make an AutoCompleteInput that uses our search
// and confirms results on search complete
var input = new AutoCompleteInput([emptySearch.name]);
var numSearchesStarted = 0;
input.onSearchBegin = function() {
numSearchesStarted++;
do_check_eq(numSearchesStarted, 1);
};
input.onSearchComplete = function() {
do_check_eq(numSearchesStarted, 1);
do_check_eq(controller.searchStatus,
Ci.nsIAutoCompleteController.STATUS_COMPLETE_NO_MATCH);
do_check_eq(controller.matchCount, 0);

View File

@ -69,6 +69,7 @@ AutoCompleteInput.prototype = {
return this.searches[aIndex];
},
onSearchBegin: function() {},
onSearchComplete: function() {},
popupOpen: false,
@ -271,8 +272,17 @@ function run_test() {
// Make an AutoCompleteInput that uses our searches
// and confirms results on search complete
var input = new AutoCompleteInput([search1.name, search2.name]);
var numSearchesStarted = 0;
input.onSearchBegin = function() {
numSearchesStarted++;
do_check_eq(numSearchesStarted, 1);
};
input.onSearchComplete = function() {
do_check_eq(numSearchesStarted, 1);
do_check_eq(controller.searchStatus,
Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);
do_check_eq(controller.matchCount, expected1.length + expected2.length);

View File

@ -195,6 +195,7 @@ AutoCompleteInput.prototype = {
return this.searches[aIndex];
},
onSearchBegin: function() {},
onSearchComplete: function() {},
popupOpen: false,
@ -236,7 +237,14 @@ function run_test() {
// Search is asynchronous, so don't let the test finish immediately
do_test_pending();
var numSearchesStarted = 0;
input.onSearchBegin = function() {
numSearchesStarted++;
do_check_eq(numSearchesStarted, 1);
};
input.onSearchComplete = function() {
do_check_eq(numSearchesStarted, 1);
do_check_eq(controller.searchStatus,
Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);

View File

@ -62,6 +62,7 @@ AutoCompleteInput.prototype = {
return this.searches[aIndex];
},
onSearchBegin: function() {},
onSearchComplete: function() {},
popupOpen: false,
@ -112,7 +113,14 @@ function ensure_tag_results(uris, searchTerm)
// Search is asynchronous, so don't let the test finish immediately
do_test_pending();
var numSearchesStarted = 0;
input.onSearchBegin = function() {
numSearchesStarted++;
do_check_eq(numSearchesStarted, 1);
};
input.onSearchComplete = function() {
do_check_eq(numSearchesStarted, 1);
do_check_eq(controller.searchStatus,
Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);
do_check_eq(controller.matchCount, uris.length);

View File

@ -91,6 +91,7 @@ AutoCompleteInput.prototype = {
return this.searches[aIndex];
},
onSearchBegin: function() {},
onSearchComplete: function() {},
popupOpen: false,
@ -132,7 +133,14 @@ function run_test() {
// Search is asynchronous, so don't let the test finish immediately
do_test_pending();
var numSearchesStarted = 0;
input.onSearchBegin = function() {
numSearchesStarted++;
do_check_eq(numSearchesStarted, 1);
};
input.onSearchComplete = function() {
do_check_eq(numSearchesStarted, 1);
do_check_eq(controller.searchStatus,
Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);

View File

@ -102,6 +102,7 @@ AutoCompleteInput.prototype = {
return this.searches[aIndex];
},
onSearchBegin: function() {},
onSearchComplete: function() {},
popupOpen: false,
@ -143,7 +144,14 @@ function run_test() {
// Search is asynchronous, so don't let the test finish immediately
do_test_pending();
var numSearchesStarted = 0;
input.onSearchBegin = function() {
numSearchesStarted++;
do_check_eq(numSearchesStarted, 1);
};
input.onSearchComplete = function() {
do_check_eq(numSearchesStarted, 1);
do_check_eq(controller.searchStatus,
Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);

View File

@ -69,6 +69,7 @@ AutoCompleteInput.prototype = {
return this.searches[aIndex];
},
onSearchBegin: function() {},
onSearchComplete: function() {},
popupOpen: false,
@ -111,7 +112,14 @@ function ensure_results(uris, searchTerm)
// Search is asynchronous, so don't let the test finish immediately
do_test_pending();
var numSearchesStarted = 0;
input.onSearchBegin = function() {
numSearchesStarted++;
do_check_eq(numSearchesStarted, 1);
};
input.onSearchComplete = function() {
do_check_eq(numSearchesStarted, 1);
do_check_eq(controller.searchStatus,
Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);
do_check_eq(controller.matchCount, uris.length);

View File

@ -62,6 +62,7 @@ AutoCompleteInput.prototype = {
return this.searches[aIndex];
},
onSearchBegin: function() {},
onSearchComplete: function() {},
popupOpen: false,
@ -112,7 +113,14 @@ function ensure_tag_results(uris, searchTerm)
// Search is asynchronous, so don't let the test finish immediately
do_test_pending();
var numSearchesStarted = 0;
input.onSearchBegin = function() {
numSearchesStarted++;
do_check_eq(numSearchesStarted, 1);
};
input.onSearchComplete = function() {
do_check_eq(numSearchesStarted, 1);
do_check_eq(controller.searchStatus,
Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);
do_check_eq(controller.matchCount, uris.length);

View File

@ -71,6 +71,7 @@ AutoCompleteInput.prototype = {
return this.searches[aIndex];
},
onSearchBegin: function() {},
onSearchComplete: function() {},
popupOpen: false,
@ -110,7 +111,14 @@ function ensure_results(aSearch, aExpected)
controller.input = input;
var numSearchesStarted = 0;
input.onSearchBegin = function() {
numSearchesStarted++;
do_check_eq(numSearchesStarted, 1);
};
input.onSearchComplete = function() {
do_check_eq(numSearchesStarted, 1);
// If we expect results, make sure we got matches
do_check_eq(controller.searchStatus, aExpected.length ?
Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH :

View File

@ -436,6 +436,12 @@ nsFormFillController::SelectTextRange(PRInt32 aStartIndex, PRInt32 aEndIndex)
return NS_OK;
}
NS_IMETHODIMP
nsFormFillController::OnSearchBegin()
{
return NS_OK;
}
NS_IMETHODIMP
nsFormFillController::OnSearchComplete()
{

View File

@ -200,6 +200,12 @@
]]></body>
</method>
<method name="onSearchBegin">
<body><![CDATA[
this.fireEvent("searchbegin");
]]></body>
</method>
<method name="onSearchComplete">
<body><![CDATA[
if (this.mController.matchCount == 0)