Bug 1193293 - Don't pick a new dictionary which checking. r=roc
authorJorg K <mozilla@jorgk.com>
Mon, 21 Sep 2015 21:51:00 +0200
changeset 263646 c6212d71ed933f894be4e6406a51baf35363d5f2
parent 263645 a43a384dbaeae57ae3bd483ffd9592a91ce56731
child 263647 20624d683ef63e0deae95a81b9ba70ac674f4f4f
push id65390
push usercbook@mozilla.com
push dateTue, 22 Sep 2015 07:07:07 +0000
treeherdermozilla-inbound@20624d683ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1193293
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1193293 - Don't pick a new dictionary which checking. r=roc
editor/composer/nsEditorSpellCheck.cpp
editor/libeditor/nsEditor.cpp
editor/nsIEditorSpellCheck.idl
--- a/editor/composer/nsEditorSpellCheck.cpp
+++ b/editor/composer/nsEditorSpellCheck.cpp
@@ -634,37 +634,16 @@ nsEditorSpellCheck::SetCurrentDictionary
   }
   return mSpellChecker->SetCurrentDictionary(aDictionary);
 }
 
 NS_IMETHODIMP
 nsEditorSpellCheck::CheckCurrentDictionary()
 {
   mSpellChecker->CheckCurrentDictionary();
-
-  // Check if our current dictionary is still available.
-  nsAutoString currentDictionary;
-  nsresult rv = GetCurrentDictionary(currentDictionary);
-  if (NS_SUCCEEDED(rv) && !currentDictionary.IsEmpty()) {
-    return NS_OK;
-  }
-
-  // If our preferred current dictionary has gone, pick another one.
-  nsTArray<nsString> dictList;
-  rv = mSpellChecker->GetDictionaryList(&dictList);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (dictList.Length() > 0) {
-    // Use RAII object to prevent content preferences being written during
-    // this call.
-    UpdateDictionaryHolder holder(this);
-    rv = SetCurrentDictionary(dictList[0]);
-    NS_ENSURE_SUCCESS(rv, rv);
-  }
-
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsEditorSpellCheck::UninitSpellChecker()
 {
   NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED);
 
@@ -759,17 +738,17 @@ nsEditorSpellCheck::TryDictionary(nsAuto
       case DICT_COMPARE_CASE_INSENSITIVE:
         equals = aDictName.Equals(dictStr, nsCaseInsensitiveStringComparator());
         break;
       case DICT_COMPARE_DASHMATCH:
         equals = nsStyleUtil::DashMatchCompare(dictStr, aDictName, nsCaseInsensitiveStringComparator());
         break;
     }
     if (equals) {
-      rv = SetCurrentDictionary(dictStr);
+      rv = mSpellChecker->SetCurrentDictionary(dictStr);
 #ifdef DEBUG_DICT
       if (NS_SUCCEEDED(rv))
         printf("***** Set |%s|.\n", NS_ConvertUTF16toUTF8(dictStr).get());
 #endif
       // We always break here. We tried to set the dictionary to an existing
       // dictionary from the list. This must work, if it doesn't, there is
       // no point trying another one.
       break;
@@ -830,27 +809,35 @@ nsEditorSpellCheck::DictionaryFetched(Di
   if (mPreferredLang.IsEmpty()) {
     mPreferredLang.Assign(aFetcher->mRootDocContentLang);
 #ifdef DEBUG_DICT
     printf("***** mPreferredLang (content-language) |%s|\n",
            NS_ConvertUTF16toUTF8(mPreferredLang).get());
 #endif
   }
 
+  // Auxiliary status.
+  nsresult rv2;
+
+  // We obtain a list of available dictionaries.
+  nsTArray<nsString> dictList;
+  rv2 = mSpellChecker->GetDictionaryList(&dictList);
+  NS_ENSURE_SUCCESS(rv2, rv2);
+
   // Priority 1:
   // If we successfully fetched a dictionary from content prefs, do not go
   // further. Use this exact dictionary.
   // Don't use content preferences for editor with eEditorMailMask flag.
   nsAutoString dictName;
   uint32_t flags;
   mEditor->GetFlags(&flags);
   if (!(flags & nsIPlaintextEditor::eEditorMailMask)) {
     dictName.Assign(aFetcher->mDictionary);
     if (!dictName.IsEmpty()) {
-      if (NS_SUCCEEDED(SetCurrentDictionary(dictName))) {
+      if (NS_SUCCEEDED(TryDictionary(dictName, dictList, DICT_NORMAL_COMPARE))) {
 #ifdef DEBUG_DICT
         printf("***** Assigned from content preferences |%s|\n",
                NS_ConvertUTF16toUTF8(dictName).get());
 #endif
 
         // We take an early exit here, so let's not forget to clear the word
         // list.
         DeleteSuggestedWordList();
@@ -866,24 +853,16 @@ nsEditorSpellCheck::DictionaryFetched(Di
   // After checking the content preferences, we use the language of the element
   // or document.
   dictName.Assign(mPreferredLang);
 #ifdef DEBUG_DICT
   printf("***** Assigned from element/doc |%s|\n",
          NS_ConvertUTF16toUTF8(dictName).get());
 #endif
 
-  // Auxiliary status.
-  nsresult rv2;
-
-  // We obtain a list of available dictionaries.
-  nsTArray<nsString> dictList;
-  rv2 = mSpellChecker->GetDictionaryList(&dictList);
-  NS_ENSURE_SUCCESS(rv2, rv2);
-
   // Get the preference value.
   nsAutoString preferredDict;
   preferredDict = Preferences::GetLocalizedString("spellchecker.dictionary");
 
   // The following will be driven by this status. Once we were able to set a
   // dictionary successfully, we're done. So we start with a "failed" status.
   nsresult rv = NS_ERROR_NOT_AVAILABLE;
 
@@ -1001,17 +980,19 @@ nsEditorSpellCheck::DictionaryFetched(Di
           rv = TryDictionary(lang2, dictList, DICT_COMPARE_CASE_INSENSITIVE);
         }
       }
 
       // Priority 7:
       // If it does not work, pick the first one.
       if (NS_FAILED(rv)) {
         if (dictList.Length() > 0) {
-          rv = SetCurrentDictionary(dictList[0]);
+          nsAutoString firstInList;
+          firstInList.Assign(dictList[0]);
+          rv = TryDictionary(firstInList, dictList, DICT_NORMAL_COMPARE);
 #ifdef DEBUG_DICT
           printf("***** Trying first of list |%s|\n",
                  NS_ConvertUTF16toUTF8(dictList[0]).get());
           if (NS_SUCCEEDED(rv))
             printf ("***** Setting worked.\n");
 #endif
         }
       }
--- a/editor/libeditor/nsEditor.cpp
+++ b/editor/libeditor/nsEditor.cpp
@@ -1323,22 +1323,21 @@ NS_IMETHODIMP nsEditor::Observe(nsISuppo
                        SPELLCHECK_DICTIONARY_REMOVE_NOTIFICATION),
                "Unexpected observer topic");
 
   // When mozInlineSpellChecker::CanEnableInlineSpellChecking changes
   SyncRealTimeSpell();
 
   // When nsIEditorSpellCheck::GetCurrentDictionary changes
   if (mInlineSpellChecker) {
-    // if the current dictionary is no longer available, find another one
+    // Do the right thing in the spellchecker, if the dictionary is no longer
+    // available. This will not set a new dictionary.
     nsCOMPtr<nsIEditorSpellCheck> editorSpellCheck;
     mInlineSpellChecker->GetSpellChecker(getter_AddRefs(editorSpellCheck));
     if (editorSpellCheck) {
-      // Note: This might change the current dictionary, which may call
-      // this observer recursively.
       editorSpellCheck->CheckCurrentDictionary();
     }
 
     // update the inline spell checker to reflect the new current dictionary
     mInlineSpellChecker->SpellCheckRange(nullptr); // causes recheck
   }
 
   return NS_OK;
--- a/editor/nsIEditorSpellCheck.idl
+++ b/editor/nsIEditorSpellCheck.idl
@@ -11,17 +11,16 @@ interface nsIEditorSpellCheckCallback;
 
 [scriptable, uuid(dd32ef3b-a7d8-43d1-9617-5f2dddbe29eb)]
 interface nsIEditorSpellCheck : nsISupports
 {
 
   /**
    * Call this on any change in installed dictionaries to ensure that the spell
    * checker is not using a current dictionary which is no longer available.
-   * If the current dictionary is no longer available, then pick another one.
    */
   void checkCurrentDictionary();
 
  /**
    * Returns true if we can enable spellchecking. If there are no available
    * dictionaries, this will return false.
    */
   boolean       canSpellCheck();