Back out 59409e2655ca (from bug 720081) due to bug 760803
authorGavin Sharp <gavin@gavinsharp.com>
Sat, 02 Jun 2012 13:35:39 -0700
changeset 95628 9274e6b53af4f784cce57f56363db88632c9caad
parent 95627 f4a7c1a1f5145687df608ba161591118274385b8
child 95629 82d895d433e91ec4f1b054f38f5cdd66b6d2209d
push id22820
push usergsharp@mozilla.com
push dateSat, 02 Jun 2012 20:36:03 +0000
treeherdermozilla-central@9274e6b53af4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs720081, 760803
milestone15.0a1
backs out59409e2655caee811668152de99e1c614ac8b8bb
first release with
nightly linux32
9274e6b53af4 / 15.0a1 / 20120602134306 / files
nightly linux64
9274e6b53af4 / 15.0a1 / 20120602134306 / files
nightly mac
9274e6b53af4 / 15.0a1 / 20120602134306 / files
nightly win32
9274e6b53af4 / 15.0a1 / 20120602134306 / files
nightly win64
9274e6b53af4 / 15.0a1 / 20120602134306 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Back out 59409e2655ca (from bug 720081) due to bug 760803
toolkit/components/autocomplete/nsAutoCompleteController.cpp
toolkit/components/autocomplete/nsAutoCompleteController.h
--- a/toolkit/components/autocomplete/nsAutoCompleteController.cpp
+++ b/toolkit/components/autocomplete/nsAutoCompleteController.cpp
@@ -486,17 +486,20 @@ nsAutoCompleteController::HandleKeyNavig
       }
       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 value;
-        if (NS_SUCCEEDED(GetFinalDefaultCompleteValue(value))) {
+        nsAutoString inputValue;
+        input->GetTextValue(inputValue);
+        if (NS_SUCCEEDED(GetDefaultCompleteValue(-1, false, value)) &&
+            value.Equals(inputValue, nsCaseInsensitiveStringComparator())) {
           input->SetTextValue(value);
           input->SelectTextRange(value.Length(), value.Length());
         }
       }
       // Close the pop-up even if nothing was selected
       ClearSearchTimer();
       ClosePopup();
     }
@@ -1176,17 +1179,20 @@ nsAutoCompleteController::EnterMatch(boo
       GetResultValueAt(selectedIndex, true, value);
     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;
-      if (NS_SUCCEEDED(GetFinalDefaultCompleteValue(defaultIndexValue)))
+      nsAutoString inputValue;
+      input->GetTextValue(inputValue);
+      if (NS_SUCCEEDED(GetDefaultCompleteValue(-1, false, defaultIndexValue)) &&
+          defaultIndexValue.Equals(inputValue, nsCaseInsensitiveStringComparator()))
         value = defaultIndexValue;
     }
 
     if (forceComplete && value.IsEmpty()) {
       // Since nothing was selected, and forceComplete is specified, that means
       // we have to find the first default match and enter it instead
       PRUint32 count = mResults.Count();
       for (PRUint32 i = 0; i < count; ++i) {
@@ -1433,71 +1439,57 @@ nsAutoCompleteController::CompleteDefaul
     CompleteValue(resultValue);
 
   mDefaultIndexCompleted = true;
 
   return NS_OK;
 }
 
 nsresult
-nsAutoCompleteController::GetDefaultCompleteResult(PRInt32 aResultIndex,
-                                                   nsIAutoCompleteResult** _result,
-                                                   PRInt32* _defaultIndex)
+nsAutoCompleteController::GetDefaultCompleteValue(PRInt32 aResultIndex,
+                                                  bool aPreserveCasing,
+                                                  nsAString &_retval)
 {
-  *_defaultIndex = -1;
-  PRInt32 resultIndex = aResultIndex;
-
-  // If a result index was not provided, find the first defaultIndex result.
-  for (PRInt32 i = 0; resultIndex < 0 && i < mResults.Count(); ++i) {
-    nsIAutoCompleteResult *result = mResults[i];
-    if (result &&
-        NS_SUCCEEDED(result->GetDefaultIndex(_defaultIndex)) &&
-        *_defaultIndex >= 0) {
-      resultIndex = i;
+  PRInt32 defaultIndex = -1;
+  PRInt32 index = aResultIndex;
+  if (index < 0) {
+    PRUint32 count = mResults.Count();
+    for (PRUint32 i = 0; i < count; ++i) {
+      nsIAutoCompleteResult *result = mResults[i];
+      if (result && NS_SUCCEEDED(result->GetDefaultIndex(&defaultIndex)) &&
+          defaultIndex >= 0) {
+        index = i;
+        break;
+      }
     }
   }
-  NS_ENSURE_TRUE(resultIndex >= 0, NS_ERROR_FAILURE);
+  NS_ENSURE_TRUE(index >= 0, NS_ERROR_FAILURE);
 
-  *_result = mResults.SafeObjectAt(resultIndex);
-  NS_ENSURE_TRUE(*_result, NS_ERROR_FAILURE);
+  nsIAutoCompleteResult *result = mResults.SafeObjectAt(index);
+  NS_ENSURE_TRUE(result != nsnull, NS_ERROR_FAILURE);
 
-  if (*_defaultIndex < 0) {
+  if (defaultIndex < 0) {
     // The search must explicitly provide a default index in order
     // for us to be able to complete.
-    (*_result)->GetDefaultIndex(_defaultIndex);
+    result->GetDefaultIndex(&defaultIndex);
   }
-
-  if (*_defaultIndex < 0) {
+  if (defaultIndex < 0) {
     // We were given a result index, but that result doesn't want to
     // be autocompleted.
     return NS_ERROR_FAILURE;
   }
 
   // If the result wrongly notifies a RESULT_SUCCESS with no matches, or
   // provides a defaultIndex greater than its matchCount, avoid trying to
   // complete to an empty value.
   PRUint32 matchCount = 0;
-  (*_result)->GetMatchCount(&matchCount);
+  result->GetMatchCount(&matchCount);
   // Here defaultIndex is surely non-negative, so can be cast to unsigned.
-  if ((PRUint32)(*_defaultIndex) >= matchCount) {
+  if ((PRUint32)defaultIndex >= matchCount)
     return NS_ERROR_FAILURE;
-  }
-
-  return NS_OK;
-}
-
-nsresult
-nsAutoCompleteController::GetDefaultCompleteValue(PRInt32 aResultIndex,
-                                                  bool aPreserveCasing,
-                                                  nsAString &_retval)
-{
-  nsIAutoCompleteResult *result;
-  PRInt32 defaultIndex = -1;
-  nsresult rv = GetDefaultCompleteResult(aResultIndex, &result, &defaultIndex);
-  if (NS_FAILED(rv)) return rv;
 
   nsAutoString resultValue;
   result->GetValueAt(defaultIndex, resultValue);
   if (aPreserveCasing &&
       StringBeginsWith(resultValue, mSearchString,
                        nsCaseInsensitiveStringComparator())) {
     // We try to preserve user casing, otherwise we would end up changing
     // the case of what he typed, if we have a result with a different casing.
@@ -1516,47 +1508,16 @@ nsAutoCompleteController::GetDefaultComp
   }
   else
     _retval = resultValue;
 
   return NS_OK;
 }
 
 nsresult
-nsAutoCompleteController::GetFinalDefaultCompleteValue(nsAString &_retval)
-{
-  nsIAutoCompleteResult *result;
-  PRInt32 defaultIndex = -1;
-  nsresult rv = GetDefaultCompleteResult(-1, &result, &defaultIndex);
-  if (NS_FAILED(rv)) return rv;
-
-  // 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;
-  if (NS_SUCCEEDED(result->GetTypeAheadResult(&isTypeAheadResult)) &&
-      isTypeAheadResult &&
-      NS_SUCCEEDED(result->GetCommentAt(defaultIndex, _retval)) &&
-      !_retval.IsEmpty()) {
-    return NS_OK;
-  }
-
-  result->GetValueAt(defaultIndex, _retval);
-  nsAutoString inputValue;
-  mInput->GetTextValue(inputValue);
-  if (!_retval.Equals(inputValue, nsCaseInsensitiveStringComparator())) {
-    return NS_ERROR_FAILURE;
-  }
-
-  return NS_OK;
-}
-
-nsresult
 nsAutoCompleteController::CompleteValue(nsString &aValue)
 /* mInput contains mSearchString, which we want to autocomplete to aValue.  If
  * selectDifference is true, select the remaining portion of aValue not
  * contained in mSearchString. */
 {
   const PRInt32 mSearchStringLength = mSearchString.Length();
   PRInt32 endSelect = aValue.Length();  // By default, select all of aValue.
 
--- a/toolkit/components/autocomplete/nsAutoCompleteController.h
+++ b/toolkit/components/autocomplete/nsAutoCompleteController.h
@@ -61,60 +61,18 @@ protected:
   nsresult GetResultValueAt(PRInt32 aIndex, bool aValueOnly,
                             nsAString & _retval);
   nsresult GetResultLabelAt(PRInt32 aIndex, bool aValueOnly,
                             nsAString & _retval);
 private:
   nsresult GetResultValueLabelAt(PRInt32 aIndex, bool aValueOnly,
                                  bool aGetValue, nsAString & _retval);
 protected:
-
-  /**
-   * Gets and validates the defaultComplete result and the relative
-   * defaultIndex value.
-   *
-   * @param aResultIndex
-   *        Index of the defaultComplete result to be used.  Pass -1 to search
-   *        for the first result providing a valid defaultIndex.
-   * @param _result
-   *        The found result.
-   * @param _defaultIndex
-   *        The defaultIndex relative to _result.
-   */
-  nsresult GetDefaultCompleteResult(PRInt32 aResultIndex,
-                                    nsIAutoCompleteResult** _result,
-                                    PRInt32* _defaultIndex);
-
-  /**
-   * Gets the defaultComplete value to be suggested to the user.
-   *
-   * @param aResultIndex
-   *        Index of the defaultComplete result to be used.
-   * @param aPreserveCasing
-   *        Whether user casing should be preserved.
-   * @param _retval
-   *        The value to be completed.
-   */
   nsresult GetDefaultCompleteValue(PRInt32 aResultIndex, bool aPreserveCasing,
                                    nsAString &_retval);
-
-  /**
-   * Gets the defaultComplete value to be used when the user navigates or
-   * confirms the current match.
-   * The value is returned only if it case-insensitively matches the current
-   * input text, otherwise the method returns NS_ERROR_FAILURE.
-   * This happens because we don't want to override user casing in case of a
-   * navigation key (unless the text is the same), or to replace text if the
-   * user backspaces just before Enter.
-   *
-   * @param _retval
-   *        The value to be completed.
-   */
-  nsresult GetFinalDefaultCompleteValue(nsAString &_retval);
-
   nsresult ClearResults();
   
   nsresult RowIndexToSearch(PRInt32 aRowIndex,
                             PRInt32 *aSearchIndex, PRInt32 *aItemIndex);
 
   // members //////////////////////////////////////////
   
   nsCOMPtr<nsIAutoCompleteInput> mInput;