Bug 967494 - "Preference Composition/Spelling/Language is ignored, and changing spellcheck language in one composition window affects all open and new compositions" r=mkmelin
authorJan Horak <jhorak@redhat.com>
Thu, 07 May 2015 13:18:00 +0300
changeset 22590 0631809c3173f19ee57ba2d5cb5c9c893f22fdcc
parent 22589 95616afdd7190fc7ded31f25836970d2901f5268
child 22591 38116ed2287cc5fbc3b913d6347953119321fed6
push id1420
push usermbanner@mozilla.com
push dateMon, 29 Jun 2015 20:47:24 +0000
treeherdercomm-beta@b3db00bb24e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs967494
Bug 967494 - "Preference Composition/Spelling/Language is ignored, and changing spellcheck language in one composition window affects all open and new compositions" r=mkmelin
mail/components/compose/content/MsgComposeCommands.js
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -179,16 +179,19 @@ var gComposeRecyclingListener = {
     //Reset recipients and attachments
     awResetAllRows();
     RemoveAllAttachments();
 
     // We need to clear the identity popup menu in case the user will change them.
     // It will be rebuilt later in ComposeStartup
     ClearIdentityListPopup(document.getElementById("msgIdentityPopup"));
 
+    // Do not listen to changes to spell check dictionary.
+    document.removeEventListener("spellcheck-changed", updateDocumentLanguage);
+
     // Stop gSpellChecker so personal dictionary is saved.
     // We need to do this before disabling the editor.
     enableInlineSpellCheck(false);
     // clear any suggestions in the context menu
     gSpellChecker.clearSuggestionsFromMenu();
     gSpellChecker.clearDictionaryListFromMenu();
 
     SetContentAndBodyAsUnmodified();
@@ -3114,16 +3117,21 @@ function ChangeLanguage(event)
   // We need to change the dictionary language and if we are using inline spell check,
   // recheck the message
 
   var spellChecker = gSpellChecker.mInlineSpellChecker.spellChecker;
   if (spellChecker.GetCurrentDictionary() != event.target.value)
   {
     spellChecker.SetCurrentDictionary(event.target.value);
 
+    // Update the document language as well (needed to synchronise
+    // the subject).
+    document.getElementById("msgcomposeWindow")
+            .setAttribute("lang", event.target.value);
+
     // now check the document over again with the new dictionary
     if (gSpellChecker.enabled)
       gSpellChecker.mInlineSpellChecker.spellCheckRange(null);
   }
   event.stopPropagation();
 }
 
 function ToggleReturnReceipt(target)
@@ -4664,16 +4672,27 @@ const gAttachmentNotifier =
   },
 
   timer: Components.classes["@mozilla.org/timer;1"]
                    .createInstance(Components.interfaces.nsITimer)
 };
 
 function InitEditor()
 {
+  // Set eEditorMailMask flag to avoid using content prefs for spell checker,
+  // otherwise dictionary setting in preferences is ignored and dictionary is
+  // inconsistent in subject and message body.
+  let editorElem = document.getElementById('content-frame');
+  let contentEditor = editorElem.getEditor(editorElem.contentWindow);
+  let msgSubject = document.getElementById('msgSubject');
+  contentEditor.flags = contentEditor.flags |
+    Components.interfaces.nsIPlaintextEditor.eEditorMailMask;
+  msgSubject.editor.flags = msgSubject.editor.flags |
+    Components.interfaces.nsIPlaintextEditor.eEditorMailMask;
+
   var editor = GetCurrentEditor();
 
   editor.QueryInterface(nsIEditorStyleSheets);
   // We use addOverrideStyleSheet rather than addStyleSheet so that we get
   // a synchronous load, rather than having a late-finishing async load
   // mark our editor as modified when the user hasn't typed anything yet,
   // but that means the sheet must not @import slow things, especially
   // not over the network.
@@ -4690,16 +4709,31 @@ function InitEditor()
           .setAttribute('disabled', !gSpellChecker.canSpellCheck);
   // If canSpellCheck = false, then hidden = false, i.e. show it so that we can
   // still add dictionaries. Else, hide that.
   document.getElementById('spellCheckAddDictionariesMain')
           .setAttribute('hidden', gSpellChecker.canSpellCheck);
   // Then, we enable related UI entries.
   enableInlineSpellCheck(getPref("mail.spellcheck.inline"));
   gAttachmentNotifier.init(editor.document);
+
+  // Set document language to preferred dictionary.
+  document.getElementById("msgcomposeWindow").setAttribute("lang",
+    Services.prefs.getCharPref("spellchecker.dictionary"));
+  // Listen for spellchecker changes, set document language to
+  // dictionary picked by the user via the right-click menu in the editor.
+  document.addEventListener("spellcheck-changed", updateDocumentLanguage);
+}
+
+// This is used as event listener to spellcheck-changed event to update
+// document language.
+function updateDocumentLanguage(e)
+{
+  document.getElementById("msgcomposeWindow")
+          .setAttribute("lang", e.detail.dictionary);
 }
 
 // This function modifies gSpellChecker and updates the UI accordingly. It's
 // called either at startup (see InitEditor above), or when the user clicks on
 // one of the two menu items that allow them to toggle the spellcheck feature
 // (either context menu or Options menu).
 function enableInlineSpellCheck(aEnableInlineSpellCheck)
 {