Bug 754265 - Add a dedicated API to provide a final complete value different from the matching one, r=Enn sr=gavin
This commit is contained in:
@@ -410,7 +410,7 @@ nsAutoCompleteController::HandleKeyNavigation(uint32_t aKey, bool *_retval)
|
||||
if (selectedIndex >= 0) {
|
||||
// A result is selected, so fill in its value
|
||||
nsAutoString value;
|
||||
if (NS_SUCCEEDED(GetResultValueAt(selectedIndex, true, value))) {
|
||||
if (NS_SUCCEEDED(GetResultValueAt(selectedIndex, false, value))) {
|
||||
input->SetTextValue(value);
|
||||
input->SelectTextRange(value.Length(), value.Length());
|
||||
}
|
||||
@@ -481,7 +481,7 @@ nsAutoCompleteController::HandleKeyNavigation(uint32_t aKey, bool *_retval)
|
||||
if (selectedIndex >= 0) {
|
||||
// The pop-up is open and has a selection, take its value
|
||||
nsAutoString value;
|
||||
if (NS_SUCCEEDED(GetResultValueAt(selectedIndex, true, value))) {
|
||||
if (NS_SUCCEEDED(GetResultValueAt(selectedIndex, false, value))) {
|
||||
input->SetTextValue(value);
|
||||
input->SelectTextRange(value.Length(), value.Length());
|
||||
}
|
||||
@@ -579,7 +579,7 @@ nsAutoCompleteController::HandleDelete(bool *_retval)
|
||||
input->GetCompleteDefaultIndex(&shouldComplete);
|
||||
if (shouldComplete) {
|
||||
nsAutoString value;
|
||||
if (NS_SUCCEEDED(GetResultValueAt(index, true, value))) {
|
||||
if (NS_SUCCEEDED(GetResultValueAt(index, false, value))) {
|
||||
CompleteValue(value);
|
||||
}
|
||||
}
|
||||
@@ -616,7 +616,7 @@ nsAutoCompleteController::GetResultAt(int32_t aIndex, nsIAutoCompleteResult** aR
|
||||
NS_IMETHODIMP
|
||||
nsAutoCompleteController::GetValueAt(int32_t aIndex, nsAString & _retval)
|
||||
{
|
||||
GetResultLabelAt(aIndex, false, _retval);
|
||||
GetResultLabelAt(aIndex, _retval);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -624,7 +624,7 @@ nsAutoCompleteController::GetValueAt(int32_t aIndex, nsAString & _retval)
|
||||
NS_IMETHODIMP
|
||||
nsAutoCompleteController::GetLabelAt(int32_t aIndex, nsAString & _retval)
|
||||
{
|
||||
GetResultLabelAt(aIndex, false, _retval);
|
||||
GetResultLabelAt(aIndex, _retval);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -662,6 +662,18 @@ nsAutoCompleteController::GetImageAt(int32_t aIndex, nsAString & _retval)
|
||||
return result->GetImageAt(rowIndex, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAutoCompleteController::GetFinalCompleteValueAt(int32_t aIndex,
|
||||
nsAString & _retval)
|
||||
{
|
||||
int32_t rowIndex;
|
||||
nsIAutoCompleteResult* result;
|
||||
nsresult rv = GetResultAt(aIndex, &result, &rowIndex);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return result->GetFinalCompleteValueAt(rowIndex, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAutoCompleteController::SetSearchString(const nsAString &aSearchString)
|
||||
{
|
||||
@@ -1181,9 +1193,14 @@ nsAutoCompleteController::EnterMatch(bool aIsPopupSelection)
|
||||
// enter it into the textbox. If completeselectedindex is true, or
|
||||
// EnterMatch was called via other means, for instance pressing Enter,
|
||||
// don't fill in the value as it will have already been filled in as
|
||||
// needed.
|
||||
if (!completeSelection || aIsPopupSelection)
|
||||
GetResultValueAt(selectedIndex, true, value);
|
||||
// needed, unless the final complete value differs.
|
||||
nsAutoString finalValue, inputValue;
|
||||
GetResultValueAt(selectedIndex, true, finalValue);
|
||||
input->GetTextValue(inputValue);
|
||||
if (!completeSelection || aIsPopupSelection ||
|
||||
!finalValue.Equals(inputValue)) {
|
||||
value = finalValue;
|
||||
}
|
||||
}
|
||||
else if (shouldComplete) {
|
||||
// We usually try to preserve the casing of what user has typed, but
|
||||
@@ -1206,7 +1223,7 @@ nsAutoCompleteController::EnterMatch(bool aIsPopupSelection)
|
||||
int32_t defaultIndex;
|
||||
result->GetDefaultIndex(&defaultIndex);
|
||||
if (defaultIndex >= 0) {
|
||||
result->GetValueAt(defaultIndex, value);
|
||||
result->GetFinalCompleteValueAt(defaultIndex, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1549,18 +1566,10 @@ nsAutoCompleteController::GetFinalDefaultCompleteValue(nsAString &_retval)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Hack: For typeAheadResults allow the comment to be used as the final
|
||||
// defaultComplete value if provided, otherwise fall back to the usual
|
||||
// value. This allows to provide a different complete text when the user
|
||||
// confirms the match. Don't rely on this for production code, since it's a
|
||||
// temporary solution that needs a dedicated API (bug 754265).
|
||||
bool isTypeAheadResult = false;
|
||||
nsAutoString commentValue;
|
||||
if (NS_SUCCEEDED(result->GetTypeAheadResult(&isTypeAheadResult)) &&
|
||||
isTypeAheadResult &&
|
||||
NS_SUCCEEDED(result->GetCommentAt(defaultIndex, commentValue)) &&
|
||||
!commentValue.IsEmpty()) {
|
||||
_retval = commentValue;
|
||||
nsAutoString finalCompleteValue;
|
||||
rv = result->GetFinalCompleteValueAt(defaultIndex, finalCompleteValue);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
_retval = finalCompleteValue;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(FindInReadable(inputValue, _retval, nsCaseInsensitiveStringComparator()),
|
||||
@@ -1625,20 +1634,23 @@ nsAutoCompleteController::CompleteValue(nsString &aValue)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAutoCompleteController::GetResultLabelAt(int32_t aIndex, bool aValueOnly, nsAString & _retval)
|
||||
nsAutoCompleteController::GetResultLabelAt(int32_t aIndex, nsAString & _retval)
|
||||
{
|
||||
return GetResultValueLabelAt(aIndex, aValueOnly, false, _retval);
|
||||
return GetResultValueLabelAt(aIndex, false, false, _retval);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAutoCompleteController::GetResultValueAt(int32_t aIndex, bool aValueOnly, nsAString & _retval)
|
||||
nsAutoCompleteController::GetResultValueAt(int32_t aIndex, bool aGetFinalValue,
|
||||
nsAString & _retval)
|
||||
{
|
||||
return GetResultValueLabelAt(aIndex, aValueOnly, true, _retval);
|
||||
return GetResultValueLabelAt(aIndex, aGetFinalValue, true, _retval);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAutoCompleteController::GetResultValueLabelAt(int32_t aIndex, bool aValueOnly,
|
||||
bool aGetValue, nsAString & _retval)
|
||||
nsAutoCompleteController::GetResultValueLabelAt(int32_t aIndex,
|
||||
bool aGetFinalValue,
|
||||
bool aGetValue,
|
||||
nsAString & _retval)
|
||||
{
|
||||
NS_ENSURE_TRUE(aIndex >= 0 && (uint32_t) aIndex < mRowCount, NS_ERROR_ILLEGAL_VALUE);
|
||||
|
||||
@@ -1651,12 +1663,14 @@ nsAutoCompleteController::GetResultValueLabelAt(int32_t aIndex, bool aValueOnly,
|
||||
result->GetSearchResult(&searchResult);
|
||||
|
||||
if (searchResult == nsIAutoCompleteResult::RESULT_FAILURE) {
|
||||
if (aValueOnly)
|
||||
if (aGetValue)
|
||||
return NS_ERROR_FAILURE;
|
||||
result->GetErrorDescription(_retval);
|
||||
} else if (searchResult == nsIAutoCompleteResult::RESULT_SUCCESS ||
|
||||
searchResult == nsIAutoCompleteResult::RESULT_SUCCESS_ONGOING) {
|
||||
if (aGetValue)
|
||||
if (aGetFinalValue)
|
||||
result->GetFinalCompleteValueAt(rowIndex, _retval);
|
||||
else if (aGetValue)
|
||||
result->GetValueAt(rowIndex, _retval);
|
||||
else
|
||||
result->GetLabelAt(rowIndex, _retval);
|
||||
|
||||
Reference in New Issue
Block a user