Bug 1168624/1168945 - Fix suboptimal code and reset language for recycling; r=neil,mkmelin
authorJorg K <mozilla@jorgk.com>
Thu, 28 May 2015 01:52:00 +0300
changeset 22750 554c22895acc8de3ebdd04b56236e05ad1939ab5
parent 22749 0979b9fca097dd3460b4fd32823002a291ecaab6
child 22751 4fbe8718e655ae6b1f7d203b9ada1c605bf7c05d
push idunknown
push userunknown
push dateunknown
reviewersneil, mkmelin
bugs1168624, 1168945
Bug 1168624/1168945 - Fix suboptimal code and reset language for recycling; r=neil,mkmelin
mail/components/compose/content/MsgComposeCommands.js
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -2057,16 +2057,20 @@ function ComposeStartup(recycled, aParam
 
     document.documentElement.setAttribute("width", defaultWidth);
     document.documentElement.setAttribute("height", defaultHeight);
     // Make sure we're safe at the left/top edge of screen
     document.documentElement.setAttribute("screenX", screen.availLeft);
     document.documentElement.setAttribute("screenY", screen.availTop);
   }
 
+  // Set document language to the preference as early as possible.
+  document.documentElement.setAttribute("lang",
+    Services.prefs.getCharPref("spellchecker.dictionary"));
+
   var identityList = document.getElementById("msgIdentity");
 
   document.addEventListener("keypress", awDocumentKeyPress, true);
 
   if (identityList)
     FillIdentityList(identityList);
 
   if (!params) {
@@ -3121,18 +3125,17 @@ function ChangeLanguage(event)
 
   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);
+    document.documentElement.setAttribute("lang", event.target.value);
 
     // now check the document over again with the new dictionary
     if (gSpellChecker.enabled)
       gSpellChecker.mInlineSpellChecker.spellCheckRange(null);
   }
   event.stopPropagation();
 }
 
@@ -4679,28 +4682,24 @@ const gAttachmentNotifier =
   },
 
   timer: Components.classes["@mozilla.org/timer;1"]
                    .createInstance(Components.interfaces.nsITimer)
 };
 
 function InitEditor()
 {
+  var editor = GetCurrentEditor();
+
   // 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();
+  let eEditorMailMask = Components.interfaces.nsIPlaintextEditor.eEditorMailMask;
+  editor.flags |= eEditorMailMask;
+  GetMsgSubjectElement().editor.flags |= eEditorMailMask;
 
   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.
   editor.addOverrideStyleSheet("chrome://messenger/content/composerOverlay.css");
@@ -4717,30 +4716,26 @@ function InitEditor()
   // 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);
+  document.documentElement.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)
 {