--- a/toolkit/components/autocomplete/nsAutoCompleteController.cpp
+++ b/toolkit/components/autocomplete/nsAutoCompleteController.cpp
@@ -9,18 +9,16 @@
#include "nsAutoPtr.h"
#include "nsNetCID.h"
#include "nsIIOService.h"
#include "nsToolkitCompsCID.h"
#include "nsIServiceManager.h"
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h"
#include "nsIScriptSecurityManager.h"
-#include "nsITreeBoxObject.h"
-#include "nsITreeColumns.h"
#include "nsIObserverService.h"
#include "mozilla/Services.h"
#include "mozilla/ModuleUtils.h"
#include "mozilla/Unused.h"
#include "mozilla/dom/KeyboardEventBinding.h"
static const char *kAutoCompleteSearchCID = "@mozilla.org/autocomplete/search;1?name=";
@@ -30,39 +28,38 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(nsAutoCom
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsAutoCompleteController)
tmp->SetInput(nullptr);
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsAutoCompleteController)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mInput)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSearches)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mResults)
+ NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mResultCache)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsAutoCompleteController)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsAutoCompleteController)
NS_INTERFACE_TABLE_HEAD(nsAutoCompleteController)
NS_INTERFACE_TABLE(nsAutoCompleteController, nsIAutoCompleteController,
- nsIAutoCompleteObserver, nsITimerCallback, nsITreeView,
- nsINamed)
+ nsIAutoCompleteObserver, nsITimerCallback, nsINamed)
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(nsAutoCompleteController)
NS_INTERFACE_MAP_END
nsAutoCompleteController::nsAutoCompleteController() :
mDefaultIndexCompleted(false),
mPopupClosedByCompositionStart(false),
mProhibitAutoFill(false),
mUserClearedAutoFill(false),
mClearingAutoFillSearchesAgain(false),
mCompositionState(eCompositionState_None),
mSearchStatus(nsAutoCompleteController::STATUS_NONE),
- mRowCount(0),
+ mMatchCount(0),
mSearchesOngoing(0),
mSearchesFailed(0),
- mDelayedRowCountDelta(0),
mImmediateSearchesCount(0),
mCompletedSelectionIndex(-1)
{
}
nsAutoCompleteController::~nsAutoCompleteController()
{
SetInput(nullptr);
@@ -88,17 +85,17 @@ nsAutoCompleteController::GetSearchStatu
{
*aSearchStatus = mSearchStatus;
return NS_OK;
}
NS_IMETHODIMP
nsAutoCompleteController::GetMatchCount(uint32_t *aMatchCount)
{
- *aMatchCount = mRowCount;
+ *aMatchCount = mMatchCount;
return NS_OK;
}
NS_IMETHODIMP
nsAutoCompleteController::GetInput(nsIAutoCompleteInput **aInput)
{
*aInput = mInput;
NS_IF_ADDREF(*aInput);
@@ -146,19 +143,16 @@ nsAutoCompleteController::SetInput(nsIAu
}
nsCOMPtr<nsIAutoCompleteInput> input(mInput);
// Reset the current search string.
nsAutoString value;
input->GetTextValue(value);
SetSearchStringInternal(value);
- // Clear out this reference in case the new input's popup has no tree
- mTree = nullptr;
-
// Since the controller can be used as a service it's important to reset this.
mClearingAutoFillSearchesAgain = false;
return NS_OK;
}
NS_IMETHODIMP
nsAutoCompleteController::ResetInternalState()
@@ -172,18 +166,17 @@ nsAutoCompleteController::ResetInternalS
Unused << ClearResults();
SetSearchStringInternal(value);
}
mPlaceholderCompletionString.Truncate();
mDefaultIndexCompleted = false;
mProhibitAutoFill = false;
mSearchStatus = nsIAutoCompleteController::STATUS_NONE;
- mRowCount = 0;
- mDelayedRowCountDelta = 0;
+ mMatchCount = 0;
mCompletedSelectionIndex = -1;
return NS_OK;
}
NS_IMETHODIMP
nsAutoCompleteController::StartSearch(const nsAString &aSearchString)
{
@@ -530,17 +523,17 @@ nsAutoCompleteController::HandleKeyNavig
}
#endif
if (*_retval) {
nsAutoString oldSearchString;
// Open the popup if there has been a previous search, or else kick off a new search
if (!mResults.IsEmpty() &&
NS_SUCCEEDED(mResults[0]->GetSearchString(oldSearchString)) &&
oldSearchString.Equals(mSearchString, nsCaseInsensitiveStringComparator())) {
- if (mRowCount) {
+ if (mMatchCount) {
OpenPopup();
}
} else {
// Stop all searches in case they are async.
StopSearch();
if (!mInput) {
// StopSearch() can call PostSearchCleanup() which might result
@@ -571,17 +564,17 @@ nsAutoCompleteController::HandleKeyNavig
bool isOpen = false;
input->GetPopupOpen(&isOpen);
// If minresultsforpopup > 1 and there's less matches than the minimum
// required, the popup is not open, but the search suggestion is showing
// inline, so we should proceed as if we had the popup.
uint32_t minResultsForPopup;
input->GetMinResultsForPopup(&minResultsForPopup);
- if (isOpen || (mRowCount > 0 && mRowCount < minResultsForPopup)) {
+ if (isOpen || (mMatchCount > 0 && mMatchCount < minResultsForPopup)) {
// For completeSelectedIndex autocomplete fields, if the popup shouldn't
// close when the caret is moved, don't adjust the text value or caret
// position.
if (isOpen) {
bool noRollup;
input->GetNoRollupOnCaretMove(&noRollup);
if (noRollup) {
bool completeSelection;
@@ -653,65 +646,61 @@ nsAutoCompleteController::HandleDelete(b
{
*_retval = false;
if (!mInput)
return NS_OK;
nsCOMPtr<nsIAutoCompleteInput> input(mInput);
bool isOpen = false;
input->GetPopupOpen(&isOpen);
- if (!isOpen || mRowCount == 0) {
+ if (!isOpen || mMatchCount == 0) {
// Nothing left to delete, proceed as normal
bool unused = false;
HandleText(&unused);
return NS_OK;
}
nsCOMPtr<nsIAutoCompletePopup> popup;
input->GetPopup(getter_AddRefs(popup));
- int32_t index, searchIndex, rowIndex;
+ int32_t index, searchIndex, matchIndex;
popup->GetSelectedIndex(&index);
if (index == -1) {
- // No row is selected in the list
+ // No match is selected in the list
bool unused = false;
HandleText(&unused);
return NS_OK;
}
- RowIndexToSearch(index, &searchIndex, &rowIndex);
- NS_ENSURE_TRUE(searchIndex >= 0 && rowIndex >= 0, NS_ERROR_FAILURE);
+ MatchIndexToSearch(index, &searchIndex, &matchIndex);
+ NS_ENSURE_TRUE(searchIndex >= 0 && matchIndex >= 0, NS_ERROR_FAILURE);
nsIAutoCompleteResult *result = mResults.SafeObjectAt(searchIndex);
NS_ENSURE_TRUE(result, NS_ERROR_FAILURE);
nsAutoString search;
input->GetSearchParam(search);
- // Clear the row in our result and in the DB.
- result->RemoveValueAt(rowIndex, true);
- --mRowCount;
+ // Clear the match in our result and in the DB.
+ result->RemoveValueAt(matchIndex, true);
+ --mMatchCount;
// We removed it, so make sure we cancel the event that triggered this call.
*_retval = true;
// Unselect the current item.
popup->SetSelectedIndex(-1);
- // Tell the tree that the row count changed.
- if (mTree)
- mTree->RowCountChanged(mRowCount, -1);
+ // Adjust index, if needed.
+ MOZ_ASSERT(index >= 0); // We verified this above, after MatchIndexToSearch.
+ if (static_cast<uint32_t>(index) >= mMatchCount)
+ index = mMatchCount - 1;
- // Adjust index, if needed.
- MOZ_ASSERT(index >= 0); // We verified this above, after RowIndexToSearch.
- if (static_cast<uint32_t>(index) >= mRowCount)
- index = mRowCount - 1;
-
- if (mRowCount > 0) {
- // There are still rows in the popup, select the current index again.
+ if (mMatchCount > 0) {
+ // There are still matches in the popup, select the current index again.
popup->SetSelectedIndex(index);
// Complete to the new current value.
bool shouldComplete = false;
input->GetCompleteDefaultIndex(&shouldComplete);
if (shouldComplete) {
nsAutoString value;
if (NS_SUCCEEDED(GetResultValueAt(index, false, value))) {
@@ -732,21 +721,21 @@ nsAutoCompleteController::HandleDelete(b
}
}
return NS_OK;
}
nsresult
nsAutoCompleteController::GetResultAt(int32_t aIndex, nsIAutoCompleteResult** aResult,
- int32_t* aRowIndex)
+ int32_t* aMatchIndex)
{
int32_t searchIndex;
- RowIndexToSearch(aIndex, &searchIndex, aRowIndex);
- NS_ENSURE_TRUE(searchIndex >= 0 && *aRowIndex >= 0, NS_ERROR_FAILURE);
+ MatchIndexToSearch(aIndex, &searchIndex, aMatchIndex);
+ NS_ENSURE_TRUE(searchIndex >= 0 && *aMatchIndex >= 0, NS_ERROR_FAILURE);
*aResult = mResults.SafeObjectAt(searchIndex);
NS_ENSURE_TRUE(*aResult, NS_ERROR_FAILURE);
return NS_OK;
}
NS_IMETHODIMP
nsAutoCompleteController::GetValueAt(int32_t aIndex, nsAString & _retval)
@@ -762,111 +751,97 @@ nsAutoCompleteController::GetLabelAt(int
GetResultLabelAt(aIndex, _retval);
return NS_OK;
}
NS_IMETHODIMP
nsAutoCompleteController::GetCommentAt(int32_t aIndex, nsAString & _retval)
{
- int32_t rowIndex;
+ int32_t matchIndex;
nsIAutoCompleteResult* result;
- nsresult rv = GetResultAt(aIndex, &result, &rowIndex);
+ nsresult rv = GetResultAt(aIndex, &result, &matchIndex);
NS_ENSURE_SUCCESS(rv, rv);
- return result->GetCommentAt(rowIndex, _retval);
+ return result->GetCommentAt(matchIndex, _retval);
}
NS_IMETHODIMP
nsAutoCompleteController::GetStyleAt(int32_t aIndex, nsAString & _retval)
{
- int32_t rowIndex;
+ int32_t matchIndex;
nsIAutoCompleteResult* result;
- nsresult rv = GetResultAt(aIndex, &result, &rowIndex);
+ nsresult rv = GetResultAt(aIndex, &result, &matchIndex);
NS_ENSURE_SUCCESS(rv, rv);
- return result->GetStyleAt(rowIndex, _retval);
+ return result->GetStyleAt(matchIndex, _retval);
}
NS_IMETHODIMP
nsAutoCompleteController::GetImageAt(int32_t aIndex, nsAString & _retval)
{
- int32_t rowIndex;
+ int32_t matchIndex;
nsIAutoCompleteResult* result;
- nsresult rv = GetResultAt(aIndex, &result, &rowIndex);
+ nsresult rv = GetResultAt(aIndex, &result, &matchIndex);
NS_ENSURE_SUCCESS(rv, rv);
- return result->GetImageAt(rowIndex, _retval);
+ return result->GetImageAt(matchIndex, _retval);
}
NS_IMETHODIMP
nsAutoCompleteController::GetFinalCompleteValueAt(int32_t aIndex,
nsAString & _retval)
{
- int32_t rowIndex;
+ int32_t matchIndex;
nsIAutoCompleteResult* result;
- nsresult rv = GetResultAt(aIndex, &result, &rowIndex);
+ nsresult rv = GetResultAt(aIndex, &result, &matchIndex);
NS_ENSURE_SUCCESS(rv, rv);
- return result->GetFinalCompleteValueAt(rowIndex, _retval);
+ return result->GetFinalCompleteValueAt(matchIndex, _retval);
}
NS_IMETHODIMP
nsAutoCompleteController::SetSearchString(const nsAString &aSearchString)
{
SetSearchStringInternal(aSearchString);
return NS_OK;
}
NS_IMETHODIMP
nsAutoCompleteController::GetSearchString(nsAString &aSearchString)
{
aSearchString = mSearchString;
return NS_OK;
}
-void
-nsAutoCompleteController::HandleSearchResult(nsIAutoCompleteSearch *aSearch,
- nsIAutoCompleteResult *aResult)
-{
- // Look up the index of the search which is returning.
- for (uint32_t i = 0; i < mSearches.Length(); ++i) {
- if (mSearches[i] == aSearch) {
- ProcessResult(i, aResult);
- }
- }
-}
-
-
////////////////////////////////////////////////////////////////////////
//// nsIAutoCompleteObserver
NS_IMETHODIMP
nsAutoCompleteController::OnSearchResult(nsIAutoCompleteSearch *aSearch, nsIAutoCompleteResult* aResult)
{
MOZ_ASSERT(mSearchesOngoing > 0 && mSearches.Contains(aSearch));
- // Update the tree if necessary.
- if (mTree && mDelayedRowCountDelta != 0) {
- mTree->RowCountChanged(0, mDelayedRowCountDelta);
- mDelayedRowCountDelta = 0;
- }
-
uint16_t result = 0;
if (aResult) {
aResult->GetSearchResult(&result);
}
// If our results are incremental, the search is still ongoing.
if (result != nsIAutoCompleteResult::RESULT_SUCCESS_ONGOING &&
result != nsIAutoCompleteResult::RESULT_NOMATCH_ONGOING) {
--mSearchesOngoing;
}
- HandleSearchResult(aSearch, aResult);
+ // Look up the index of the search which is returning.
+ for (uint32_t i = 0; i < mSearches.Length(); ++i) {
+ if (mSearches[i] == aSearch) {
+ ProcessResult(i, aResult);
+ }
+ }
if (mSearchesOngoing == 0) {
// If this is the last search to return, cleanup.
PostSearchCleanup();
}
return NS_OK;
}
@@ -897,249 +872,25 @@ nsAutoCompleteController::Notify(nsITime
NS_IMETHODIMP
nsAutoCompleteController::GetName(nsACString& aName)
{
aName.AssignLiteral("nsAutoCompleteController");
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
-// nsITreeView
-
-NS_IMETHODIMP
-nsAutoCompleteController::GetRowCount(int32_t *aRowCount)
-{
- *aRowCount = mRowCount;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::GetRowProperties(int32_t index, nsAString& aProps)
-{
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::GetCellProperties(int32_t row, nsITreeColumn* col,
- nsAString& aProps)
-{
- if (row >= 0) {
- GetStyleAt(row, aProps);
- }
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::GetColumnProperties(nsITreeColumn* col, nsAString& aProps)
-{
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::GetImageSrc(int32_t row, nsITreeColumn* col, nsAString& _retval)
-{
- const char16_t* colID;
- col->GetIdConst(&colID);
-
- if (NS_LITERAL_STRING("treecolAutoCompleteValue").Equals(colID))
- return GetImageAt(row, _retval);
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::GetCellValue(int32_t row, nsITreeColumn* col, nsAString& _retval)
-{
- NS_NOTREACHED("all of our cells are text");
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::GetCellText(int32_t row, nsITreeColumn* col, nsAString& _retval)
-{
- const char16_t* colID;
- col->GetIdConst(&colID);
-
- if (NS_LITERAL_STRING("treecolAutoCompleteValue").Equals(colID))
- GetValueAt(row, _retval);
- else if (NS_LITERAL_STRING("treecolAutoCompleteComment").Equals(colID))
- GetCommentAt(row, _retval);
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::IsContainer(int32_t index, bool *_retval)
-{
- *_retval = false;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::IsContainerOpen(int32_t index, bool *_retval)
-{
- NS_NOTREACHED("no container cells");
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::IsContainerEmpty(int32_t index, bool *_retval)
-{
- NS_NOTREACHED("no container cells");
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::GetLevel(int32_t index, int32_t *_retval)
-{
- *_retval = 0;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::GetParentIndex(int32_t rowIndex, int32_t *_retval)
-{
- *_retval = -1;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::HasNextSibling(int32_t rowIndex, int32_t afterIndex, bool *_retval)
-{
- *_retval = false;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::ToggleOpenState(int32_t index)
-{
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::SetTree(nsITreeBoxObject *tree)
-{
- mTree = tree;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::GetSelection(nsITreeSelection * *aSelection)
-{
- *aSelection = mSelection;
- NS_IF_ADDREF(*aSelection);
- return NS_OK;
-}
-
-NS_IMETHODIMP nsAutoCompleteController::SetSelection(nsITreeSelection * aSelection)
-{
- mSelection = aSelection;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::SelectionChanged()
-{
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::SetCellValue(int32_t row, nsITreeColumn* col, const nsAString& value)
-{
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::SetCellText(int32_t row, nsITreeColumn* col, const nsAString& value)
-{
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::CycleHeader(nsITreeColumn* col)
-{
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::CycleCell(int32_t row, nsITreeColumn* col)
-{
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::IsEditable(int32_t row, nsITreeColumn* col, bool *_retval)
-{
- *_retval = false;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::IsSelectable(int32_t row, nsITreeColumn* col, bool *_retval)
-{
- *_retval = false;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::IsSeparator(int32_t index, bool *_retval)
-{
- *_retval = false;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::IsSorted(bool *_retval)
-{
- *_retval = false;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::CanDrop(int32_t index, int32_t orientation,
- nsIDOMDataTransfer* dataTransfer, bool *_retval)
-{
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::Drop(int32_t row, int32_t orientation, nsIDOMDataTransfer* dataTransfer)
-{
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::PerformAction(const char16_t *action)
-{
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::PerformActionOnRow(const char16_t *action, int32_t row)
-{
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAutoCompleteController::PerformActionOnCell(const char16_t* action, int32_t row, nsITreeColumn* col)
-{
- return NS_OK;
-}
-
-////////////////////////////////////////////////////////////////////////
//// nsAutoCompleteController
nsresult
nsAutoCompleteController::OpenPopup()
{
uint32_t minResults;
mInput->GetMinResultsForPopup(&minResults);
- if (mRowCount >= minResults) {
+ if (mMatchCount >= minResults) {
return mInput->SetPopupOpen(true);
}
return NS_OK;
}
nsresult
nsAutoCompleteController::ClosePopup()
@@ -1171,19 +922,16 @@ nsAutoCompleteController::BeforeSearches
mDefaultIndexCompleted = false;
// ClearResults will clear the mResults array, but we should pass the previous
// result to each search to allow reusing it. So we temporarily cache the
// current results until AfterSearches().
if (!mResultCache.AppendObjects(mResults)) {
return NS_ERROR_OUT_OF_MEMORY;
}
- // The rowCountChanged notification is sent later, when the first result
- // from the search arrives, to avoid flickering in the tree contents.
- mDelayedRowCountDelta = 0;
ClearResults(true);
mSearchesOngoing = mSearches.Length();
mSearchesFailed = 0;
// notify the input that the search is beginning
mInput->OnSearchBegin();
return NS_OK;
@@ -1457,26 +1205,17 @@ nsAutoCompleteController::EnterMatch(boo
int32_t selectedIndex;
popup->GetSelectedIndex(&selectedIndex);
if (selectedIndex >= 0) {
nsAutoString inputValue;
input->GetTextValue(inputValue);
if (aIsPopupSelection || !completeSelection) {
// We need to fill-in the value if:
// * completeselectedindex is false
- // * A row in the popup was confirmed
- //
- // TODO: This is not totally correct, cause it will also confirm
- // a result selected with a simple mouseover, that could also have
- // happened accidentally, maybe touching a touchpad.
- // The reason is that autocomplete.xml sets selectedIndex on mousemove
- // making impossible, in the !completeSelection case, to distinguish if
- // the user wanted to confirm autoFill or the popup entry.
- // The solution may be to change autocomplete.xml to set selectedIndex
- // only on popupClick, but that requires changing the selection behavior.
+ // * A match in the popup was confirmed
GetResultValueAt(selectedIndex, true, value);
} else if (mDefaultIndexCompleted &&
inputValue.Equals(mPlaceholderCompletionString,
nsCaseInsensitiveStringComparator())) {
// We also need to fill-in the value if the default index completion was
// confirmed, though we cannot use the selectedIndex cause the selection
// may have been changed by the mouse in the meanwhile.
GetFinalDefaultCompleteValue(value);
@@ -1486,21 +1225,16 @@ nsAutoCompleteController::EnterMatch(boo
// don't fill in the value as it will have already been filled in as
// needed, unless the selected match has a final complete value that
// differs from the user-facing value.
nsAutoString finalValue;
GetResultValueAt(mCompletedSelectionIndex, true, finalValue);
if (!inputValue.Equals(finalValue)) {
value = finalValue;
}
- // Note that if the user opens the popup, mouses over entries without
- // ever selecting one with the keyboard, and then hits enter, none of
- // the above cases will be hit, since mouseover doesn't activate
- // completeselectedindex and thus mCompletedSelectionIndex would be
- // -1.
}
} else if (shouldComplete) {
// We usually try to preserve the casing of what user has typed, but
// if he wants to autocomplete, we will replace the value with the
// actual autocomplete result.
// The user wants explicitely to use that result, so this ensures
// association of the result with the autocompleted text.
nsAutoString defaultIndexValue;
@@ -1660,46 +1394,39 @@ nsAutoCompleteController::ProcessResult(
}
}
// When found the result should have the same index as the search.
MOZ_ASSERT_IF(mResults.IndexOf(aResult) != -1,
mResults.IndexOf(aResult) == aSearchIndex);
MOZ_ASSERT(mResults.Count() >= aSearchIndex + 1,
"aSearchIndex should always be valid for mResults");
- uint32_t oldRowCount = mRowCount;
+ uint32_t oldMatchCount = mMatchCount;
// If the search failed, increase the match count to include the error
// description.
if (searchResult == nsIAutoCompleteResult::RESULT_FAILURE) {
nsAutoString error;
aResult->GetErrorDescription(error);
if (!error.IsEmpty()) {
- ++mRowCount;
- if (mTree) {
- mTree->RowCountChanged(oldRowCount, 1);
- }
+ ++mMatchCount;
}
} else if (searchResult == nsIAutoCompleteResult::RESULT_SUCCESS ||
searchResult == nsIAutoCompleteResult::RESULT_SUCCESS_ONGOING) {
// Increase the match count for all matches in this result.
uint32_t totalMatchCount = 0;
for (uint32_t i = 0; i < mResults.Length(); i++) {
nsIAutoCompleteResult* result = mResults.SafeObjectAt(i);
if (result) {
uint32_t matchCount = 0;
result->GetMatchCount(&matchCount);
totalMatchCount += matchCount;
}
}
- uint32_t delta = totalMatchCount - oldRowCount;
-
- mRowCount += delta;
- if (mTree) {
- mTree->RowCountChanged(oldRowCount, delta);
- }
+ uint32_t delta = totalMatchCount - oldMatchCount;
+ mMatchCount += delta;
}
// Try to autocomplete the default index for this search.
// Do this before invalidating so the binding knows about it.
CompleteDefaultIndex(aSearchIndex);
// Refresh the popup view to display the new search results
nsCOMPtr<nsIAutoCompletePopup> popup;
@@ -1708,17 +1435,17 @@ nsAutoCompleteController::ProcessResult(
popup->Invalidate(nsIAutoCompletePopup::INVALIDATE_REASON_NEW_RESULT);
uint32_t minResults;
input->GetMinResultsForPopup(&minResults);
// Make sure the popup is open, if necessary, since we now have at least one
// search result ready to display. Don't force the popup closed if we might
// get results in the future to avoid unnecessarily canceling searches.
- if (mRowCount || !minResults) {
+ if (mMatchCount || !minResults) {
OpenPopup();
} else if (mSearchesOngoing == 0) {
ClosePopup();
}
return NS_OK;
}
@@ -1726,25 +1453,19 @@ nsresult
nsAutoCompleteController::PostSearchCleanup()
{
NS_ENSURE_STATE(mInput);
nsCOMPtr<nsIAutoCompleteInput> input(mInput);
uint32_t minResults;
input->GetMinResultsForPopup(&minResults);
- // Apply a pending rowCountChanged.
- if (mTree && mDelayedRowCountDelta != 0) {
- mTree->RowCountChanged(0, mDelayedRowCountDelta);
- // mDelayedRowCountDelta will be reset by the next search.
- }
-
- if (mRowCount || minResults == 0) {
+ if (mMatchCount || minResults == 0) {
OpenPopup();
- if (mRowCount)
+ if (mMatchCount)
mSearchStatus = nsIAutoCompleteController::STATUS_COMPLETE_MATCH;
else
mSearchStatus = nsIAutoCompleteController::STATUS_COMPLETE_NO_MATCH;
} else {
mSearchStatus = nsIAutoCompleteController::STATUS_COMPLETE_NO_MATCH;
ClosePopup();
}
@@ -1752,36 +1473,25 @@ nsAutoCompleteController::PostSearchClea
input->OnSearchComplete();
return NS_OK;
}
nsresult
nsAutoCompleteController::ClearResults(bool aIsSearching)
{
- int32_t oldRowCount = mRowCount;
- mRowCount = 0;
+ int32_t oldMatchCount = mMatchCount;
+ mMatchCount = 0;
mResults.Clear();
- if (oldRowCount != 0) {
- if (mTree) {
- if (aIsSearching) {
- // Delay the notification, so the tree provides a smoother transition to
- // the new result. It will be handled as soon as we add the first result.
- mDelayedRowCountDelta = -oldRowCount;
- } else {
- // Notify immediately.
- mTree->RowCountChanged(0, -oldRowCount);
- }
- } else if (mInput) {
+ if (oldMatchCount != 0) {
+ if (mInput) {
nsCOMPtr<nsIAutoCompletePopup> popup;
mInput->GetPopup(getter_AddRefs(popup));
NS_ENSURE_TRUE(popup != nullptr, NS_ERROR_FAILURE);
- // if we had a tree, RowCountChanged() would have cleared the selection
- // when the selected row was removed. But since we don't have a tree,
- // we need to clear the selection manually.
+ // Clear the selection.
popup->SetSelectedIndex(-1);
}
}
return NS_OK;
}
nsresult
nsAutoCompleteController::CompleteDefaultIndex(int32_t aResultIndex)
@@ -2017,92 +1727,92 @@ nsAutoCompleteController::GetResultValue
}
nsresult
nsAutoCompleteController::GetResultValueLabelAt(int32_t aIndex,
bool aGetFinalValue,
bool aGetValue,
nsAString & _retval)
{
- NS_ENSURE_TRUE(aIndex >= 0 && static_cast<uint32_t>(aIndex) < mRowCount, NS_ERROR_ILLEGAL_VALUE);
+ NS_ENSURE_TRUE(aIndex >= 0 && static_cast<uint32_t>(aIndex) < mMatchCount, NS_ERROR_ILLEGAL_VALUE);
- int32_t rowIndex;
+ int32_t matchIndex;
nsIAutoCompleteResult *result;
- nsresult rv = GetResultAt(aIndex, &result, &rowIndex);
+ nsresult rv = GetResultAt(aIndex, &result, &matchIndex);
NS_ENSURE_SUCCESS(rv, rv);
uint16_t searchResult;
result->GetSearchResult(&searchResult);
if (searchResult == nsIAutoCompleteResult::RESULT_FAILURE) {
if (aGetValue)
return NS_ERROR_FAILURE;
result->GetErrorDescription(_retval);
} else if (searchResult == nsIAutoCompleteResult::RESULT_SUCCESS ||
searchResult == nsIAutoCompleteResult::RESULT_SUCCESS_ONGOING) {
if (aGetFinalValue) {
// Some implementations may miss finalCompleteValue, try to be backwards
// compatible.
- if (NS_FAILED(result->GetFinalCompleteValueAt(rowIndex, _retval))) {
- result->GetValueAt(rowIndex, _retval);
+ if (NS_FAILED(result->GetFinalCompleteValueAt(matchIndex, _retval))) {
+ result->GetValueAt(matchIndex, _retval);
}
} else if (aGetValue) {
- result->GetValueAt(rowIndex, _retval);
+ result->GetValueAt(matchIndex, _retval);
} else {
- result->GetLabelAt(rowIndex, _retval);
+ result->GetLabelAt(matchIndex, _retval);
}
}
return NS_OK;
}
/**
- * Given the index of a row in the autocomplete popup, find the
+ * Given the index of a match in the autocomplete popup, find the
* corresponding nsIAutoCompleteSearch index, and sub-index into
* the search's results list.
*/
nsresult
-nsAutoCompleteController::RowIndexToSearch(int32_t aRowIndex, int32_t *aSearchIndex, int32_t *aItemIndex)
+nsAutoCompleteController::MatchIndexToSearch(int32_t aMatchIndex, int32_t *aSearchIndex, int32_t *aItemIndex)
{
*aSearchIndex = -1;
*aItemIndex = -1;
uint32_t index = 0;
// Move index through the results of each registered nsIAutoCompleteSearch
- // until we find the given row
+ // until we find the given match
for (uint32_t i = 0; i < mSearches.Length(); ++i) {
nsIAutoCompleteResult *result = mResults.SafeObjectAt(i);
if (!result)
continue;
- uint32_t rowCount = 0;
+ uint32_t matchCount = 0;
uint16_t searchResult;
result->GetSearchResult(&searchResult);
// Find out how many results were provided by the
// current nsIAutoCompleteSearch.
if (searchResult == nsIAutoCompleteResult::RESULT_SUCCESS ||
searchResult == nsIAutoCompleteResult::RESULT_SUCCESS_ONGOING) {
- result->GetMatchCount(&rowCount);
+ result->GetMatchCount(&matchCount);
}
- // If the given row index is within the results range
+ // If the given match index is within the results range
// of the current nsIAutoCompleteSearch then return the
// search index and sub-index into the results array
- if ((rowCount != 0) && (index + rowCount-1 >= (uint32_t) aRowIndex)) {
+ if ((matchCount != 0) && (index + matchCount-1 >= (uint32_t) aMatchIndex)) {
*aSearchIndex = i;
- *aItemIndex = aRowIndex - index;
+ *aItemIndex = aMatchIndex - index;
return NS_OK;
}
// Advance the popup table index cursor past the
// results of the current search.
- index += rowCount;
+ index += matchCount;
}
return NS_OK;
}
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAutoCompleteController)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAutoCompleteSimpleResult)