Bug 1265920 - Move unrelated paragraph-handling code from cloudAttachmentLinkManager.js to MsgComposeCommands.js, r=mkmelin
authorrsx11m <rsx11m.pub@gmail.com>
Wed, 20 Apr 2016 16:02:50 -0500
changeset 24839 0e4ea4d22bc199fc7b42f8b8b390a04df7aa7d86
parent 24838 6d308b9180291cdf249d25c8771bfe1ad9dc6b18
child 24840 f3abd6bc5c743fc8523c509572b0988c36ee65fc
push id1657
push userclokep@gmail.com
push dateMon, 06 Jun 2016 19:50:21 +0000
treeherdercomm-beta@9fac989284b5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1265920
Bug 1265920 - Move unrelated paragraph-handling code from cloudAttachmentLinkManager.js to MsgComposeCommands.js, r=mkmelin
mail/components/compose/content/MsgComposeCommands.js
mail/components/compose/content/cloudAttachmentLinkManager.js
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -271,21 +271,152 @@ function toggleAffectedChrome(aHide)
 
 var stateListener = {
   NotifyComposeFieldsReady: function() {
     ComposeFieldsReady();
     updateSendCommands(true);
   },
 
   NotifyComposeBodyReady: function() {
+    // Look all the possible compose types (nsIMsgComposeParams.idl):
+    switch (gComposeType) {
+
+    case Components.interfaces.nsIMsgCompType.New:
+    case Components.interfaces.nsIMsgCompType.ForwardAsAttachment:
+      this.NotifyComposeBodyReadyNew();
+      break;
+
+    case Components.interfaces.nsIMsgCompType.Reply:
+    case Components.interfaces.nsIMsgCompType.ReplyAll:
+    case Components.interfaces.nsIMsgCompType.ReplyToSender:
+    case Components.interfaces.nsIMsgCompType.ReplyToGroup:
+    case Components.interfaces.nsIMsgCompType.ReplyToSenderAndGroup:
+    case Components.interfaces.nsIMsgCompType.ReplyWithTemplate:
+    case Components.interfaces.nsIMsgCompType.ReplyToList:
+      this.NotifyComposeBodyReadyReply();
+      break;
+
+    case Components.interfaces.nsIMsgCompType.ForwardInline:
+      this.NotifyComposeBodyReadyForwardInline();
+      break;
+
+    case Components.interfaces.nsIMsgCompType.Draft:
+    case Components.interfaces.nsIMsgCompType.Template:
+    case Components.interfaces.nsIMsgCompType.MailToUrl:
+    case Components.interfaces.nsIMsgCompType.Redirect:
+      break;
+
+    default:
+      dump("Unexpected nsIMsgCompType in NotifyComposeBodyReady (" +
+           gComposeType + ")\n");
+    }
+
     if (gMsgCompose.composeHTML)
       loadHTMLMsgPrefs();
     AdjustFocus();
   },
 
+  NotifyComposeBodyReadyNew: function() {
+    // Control insertion of line breaks.
+    let useParagraph = Services.prefs.getBoolPref("editor.CR_creates_new_p");
+    if (gMsgCompose.composeHTML && useParagraph) {
+      let editor = GetCurrentEditor();
+      editor.enableUndo(false);
+
+      let pElement = editor.createElementWithDefaults("p");
+      let brElement = editor.createElementWithDefaults("br");
+      pElement.appendChild(brElement);
+      editor.insertElementAtSelection(pElement,true);
+
+      document.getElementById("cmd_paragraphState").setAttribute("state", "p");
+
+      editor.beginningOfDocument();
+      editor.enableUndo(true);
+      editor.resetModificationCount();
+    } else {
+      document.getElementById("cmd_paragraphState").setAttribute("state", "");
+    }
+  },
+
+  NotifyComposeBodyReadyReply: function() {
+    // Control insertion of line breaks.
+    let useParagraph = Services.prefs.getBoolPref("editor.CR_creates_new_p");
+    if (gMsgCompose.composeHTML && useParagraph) {
+
+      let mailDoc = document.getElementById("content-frame").contentDocument;
+      let mailBody = mailDoc.querySelector("body");
+      let editor = GetCurrentEditor();
+      let selection = editor.selection;
+      let range = selection.getRangeAt(0);
+      let start = range.startOffset;
+
+      if (start != range.endOffset) {
+        // The selection is not collapsed, most likely due to the
+        // "select the quote" option. In this case we do nothing.
+        return;
+      }
+
+      if (range.startContainer != mailBody) {
+        dump("Unexpected selection in NotifyComposeBodyReadyReply\n");
+        return;
+      }
+
+      // Delete a <br> if we see one.
+      let currentNode = mailBody.childNodes[start];
+      if (currentNode.nodeName == "BR") {
+        mailBody.removeChild(currentNode);
+      }
+
+      let pElement = editor.createElementWithDefaults("p");
+      let brElement = editor.createElementWithDefaults("br");
+      pElement.appendChild(brElement);
+      editor.insertElementAtSelection(pElement,true);
+
+      // Position into the paragraph.
+      selection.collapse(pElement, 0);
+
+      document.getElementById("cmd_paragraphState").setAttribute("state", "p");
+
+      editor.enableUndo(true);
+      editor.resetModificationCount();
+    } else {
+      document.getElementById("cmd_paragraphState").setAttribute("state", "");
+    }
+  },
+
+  NotifyComposeBodyReadyForwardInline: function() {
+    let mailDoc = document.getElementById("content-frame").contentDocument;
+    let mailBody = mailDoc.querySelector("body");
+    let editor = GetCurrentEditor();
+    let selection = editor.selection;
+
+    editor.enableUndo(false);
+
+    // Control insertion of line breaks.
+    selection.collapse(mailBody, 0);
+    let useParagraph = Services.prefs.getBoolPref("editor.CR_creates_new_p");
+    if (gMsgCompose.composeHTML && useParagraph) {
+      let pElement = editor.createElementWithDefaults("p");
+      let brElement = editor.createElementWithDefaults("br");
+      pElement.appendChild(brElement);
+      editor.insertElementAtSelection(pElement, false);
+      document.getElementById("cmd_paragraphState").setAttribute("state", "p");
+    } else {
+      // insertLineBreak() has been observed to insert two <br> elements
+      // instead of one before a <div>, so we'll do it ourselves here.
+      let brElement = editor.createElementWithDefaults("br");
+      editor.insertElementAtSelection(brElement, false);
+      document.getElementById("cmd_paragraphState").setAttribute("state", "");
+    }
+
+    editor.beginningOfDocument();
+    editor.enableUndo(true);
+    editor.resetModificationCount();
+  },
+
   ComposeProcessDone: function(aResult) {
     ToggleWindowLock(false);
 
     if (aResult== Components.results.NS_OK)
     {
       if (!gAutoSaving)
         SetContentAndBodyAsUnmodified();
 
--- a/mail/components/compose/content/cloudAttachmentLinkManager.js
+++ b/mail/components/compose/content/cloudAttachmentLinkManager.js
@@ -19,151 +19,17 @@ var gCloudAttachmentLinkManager = {
       if (attachment && attachment.sendViaCloud)
         this.cloudAttachments.push(attachment);
     }
 
     gMsgCompose.RegisterStateListener(this);
   },
 
   NotifyComposeFieldsReady: function() {},
-
-  NotifyComposeBodyReady: function() {
-
-    // Look all the possible compose typed (nsIMsgComposeParams.idl):
-    switch (gComposeType) {
-
-    case Components.interfaces.nsIMsgCompType.New:
-      this.NotifyComposeBodyReadyNew();
-      return;
-
-    case Components.interfaces.nsIMsgCompType.Reply:
-    case Components.interfaces.nsIMsgCompType.ReplyAll:
-    case Components.interfaces.nsIMsgCompType.ReplyToSender:
-    case Components.interfaces.nsIMsgCompType.ReplyToGroup:
-    case Components.interfaces.nsIMsgCompType.ReplyToSenderAndGroup:
-    case Components.interfaces.nsIMsgCompType.ReplyWithTemplate:
-    case Components.interfaces.nsIMsgCompType.ReplyToList:
-      this.NotifyComposeBodyReadyReply();
-      return;
-
-    case Components.interfaces.nsIMsgCompType.ForwardInline:
-      this.NotifyComposeBodyReadyForwardInline();
-      return;
-
-    case Components.interfaces.nsIMsgCompType.ForwardAsAttachment:
-    case Components.interfaces.nsIMsgCompType.Draft:
-    case Components.interfaces.nsIMsgCompType.Template:
-    case Components.interfaces.nsIMsgCompType.MailToUrl:
-    case Components.interfaces.nsIMsgCompType.Redirect:
-      return;
-    default:
-      dump("Unexpected nsIMsgCompType in NotifyComposeBodyReady (" +
-           gComposeType + ")\n");
-      return;
-    }
-  },
-
-  NotifyComposeBodyReadyNew: function() {
-    // Control insertion of line breaks.
-    let useParagraph = Services.prefs.getBoolPref("editor.CR_creates_new_p");
-    if (gMsgCompose.composeHTML && useParagraph) {
-      let editor = GetCurrentEditor();
-      editor.enableUndo(false);
-
-      let pElement = editor.createElementWithDefaults("p");
-      let brElement = editor.createElementWithDefaults("br");
-      pElement.appendChild(brElement);
-      editor.insertElementAtSelection(pElement,true);
-
-      document.getElementById("cmd_paragraphState").setAttribute("state", "p");
-
-      editor.beginningOfDocument();
-      editor.enableUndo(true);
-      editor.resetModificationCount();
-    } else {
-      document.getElementById("cmd_paragraphState").setAttribute("state", "");
-    }
-  },
-
-  NotifyComposeBodyReadyReply: function() {
-    // Control insertion of line breaks.
-    let useParagraph = Services.prefs.getBoolPref("editor.CR_creates_new_p");
-    if (gMsgCompose.composeHTML && useParagraph) {
-
-      let mailDoc = document.getElementById("content-frame").contentDocument;
-      let mailBody = mailDoc.querySelector("body");
-      let editor = GetCurrentEditor();
-      let selection = editor.selection;
-      let range = selection.getRangeAt(0);
-      let start = range.startOffset;
-
-      if (start != range.endOffset) {
-        // The selection is not collapsed, most likely due to the
-        // "select the quote" option. In this case we do nothing.
-        return;
-      }
-
-      if (range.startContainer != mailBody) {
-        dump("Unexpected selection in NotifyComposeBodyReadyReply\n");
-        return;
-      }
-
-      // Delete a <br> if we see one.
-      let currentNode = mailBody.childNodes[start];
-      if (currentNode.nodeName == "BR") {
-        mailBody.removeChild(currentNode);
-      }
-
-      let pElement = editor.createElementWithDefaults("p");
-      let brElement = editor.createElementWithDefaults("br");
-      pElement.appendChild(brElement);
-      editor.insertElementAtSelection(pElement,true);
-
-      // Position into the paragraph.
-      selection.collapse(pElement, 0);
-
-      document.getElementById("cmd_paragraphState").setAttribute("state", "p");
-
-      editor.enableUndo(true);
-      editor.resetModificationCount();
-    } else {
-      document.getElementById("cmd_paragraphState").setAttribute("state", "");
-    }
-  },
-
-  NotifyComposeBodyReadyForwardInline: function() {
-    let mailDoc = document.getElementById("content-frame").contentDocument;
-    let mailBody = mailDoc.querySelector("body");
-    let editor = GetCurrentEditor();
-    let selection = editor.selection;
-
-    editor.enableUndo(false);
-
-    // Control insertion of line breaks.
-    selection.collapse(mailBody, 0);
-    let useParagraph = Services.prefs.getBoolPref("editor.CR_creates_new_p");
-    if (gMsgCompose.composeHTML && useParagraph) {
-      let pElement = editor.createElementWithDefaults("p");
-      let brElement = editor.createElementWithDefaults("br");
-      pElement.appendChild(brElement);
-      editor.insertElementAtSelection(pElement, false);
-      document.getElementById("cmd_paragraphState").setAttribute("state", "p");
-    } else {
-      // insertLineBreak() has been observed to insert two <br> elements
-      // instead of one before a <div>, so we'll do it ourselves here.
-      let brElement = editor.createElementWithDefaults("br");
-      editor.insertElementAtSelection(brElement, false);
-      document.getElementById("cmd_paragraphState").setAttribute("state", "");
-    }
-
-    editor.beginningOfDocument();
-    editor.enableUndo(true);
-    editor.resetModificationCount();
-  },
-
+  NotifyComposeBodyReady: function() {},
   ComposeProcessDone: function() {},
   SaveInFolderDone: function() {},
 
   handleEvent: function(event) {
     let mailDoc = document.getElementById("content-frame").contentDocument;
 
     if (event.type == "attachment-uploaded") {
       if (this.cloudAttachments.length == 0)