Bug 1249884 - Check for forward before inserting forward container. r=mkmelin a=rkent THUNDERBIRD450b3_2016032415_RELBRANCH
authorJorg K
Mon, 22 Feb 2016 08:26:27 +0100
branchTHUNDERBIRD450b3_2016032415_RELBRANCH
changeset 26842 8599de737858aec437fe3039383062d6cd843a05
parent 26841 e9cec34f984d9c5dfad6bdec1625ee03a2457468
child 26843 fa72ab9a8befca68a2f240e58fbc83bfb73e4bd2
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, rkent
bugs1249884
Bug 1249884 - Check for forward before inserting forward container. r=mkmelin a=rkent
mailnews/compose/src/nsMsgCompose.cpp
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -772,77 +772,85 @@ nsMsgCompose::ConvertAndLoadComposeWindo
                                         NS_LITERAL_STRING("moz-signature"));
         m_editor->EndOfDocument();
         sigOnTopInserted = true;
       }
 
       if (!aBuf.IsEmpty())
       {
         nsresult rv;
-
-        // Create a <div> of the required class.
         nsCOMPtr<nsIDOMElement> divElem;
-        rv = htmlEditor->CreateElementWithDefaults(NS_LITERAL_STRING("div"),
-                                                   getter_AddRefs(divElem));
-        NS_ENSURE_SUCCESS(rv, rv);
-
-        nsAutoString attributeName;
-        nsAutoString attributeValue;
-        attributeName.AssignLiteral("class");
-        attributeValue.AssignLiteral("moz-forward-container");
-        divElem->SetAttribute(attributeName, attributeValue);
-
-        // We can't insert an empty <div>, so fill it with something.
-        nsCOMPtr<nsIDOMElement> brElem;
-        nsCOMPtr<nsIDOMNode> resultNode;
-        rv = htmlEditor->CreateElementWithDefaults(NS_LITERAL_STRING("br"),
-                                                   getter_AddRefs(brElem));
-        NS_ENSURE_SUCCESS(rv, rv);
-        rv = divElem->AppendChild(brElem, getter_AddRefs(resultNode));
-        NS_ENSURE_SUCCESS(rv, rv);
-
-        // Insert the non-empty <div> into the DOM.
-        rv = htmlEditor->InsertElementAtSelection(divElem, false);
-        NS_ENSURE_SUCCESS(rv, rv);
-
-        // Position into the div, so out content goes there.
-        nsCOMPtr<nsISelection> selection;
-        m_editor->GetSelection(getter_AddRefs(selection));
-        rv = selection->Collapse(divElem, 0);
-        NS_ENSURE_SUCCESS(rv, rv);
+        nsCOMPtr<nsIDOMNode> extraBr;
+
+        if (isForwarded) {
+          // Special treatment for forwarded messages: Part 1.
+          // Create a <div> of the required class.
+          rv = htmlEditor->CreateElementWithDefaults(NS_LITERAL_STRING("div"),
+                                                     getter_AddRefs(divElem));
+          NS_ENSURE_SUCCESS(rv, rv);
+
+          nsAutoString attributeName;
+          nsAutoString attributeValue;
+          attributeName.AssignLiteral("class");
+          attributeValue.AssignLiteral("moz-forward-container");
+          divElem->SetAttribute(attributeName, attributeValue);
+
+          // We can't insert an empty <div>, so fill it with something.
+          nsCOMPtr<nsIDOMElement> brElem;
+          rv = htmlEditor->CreateElementWithDefaults(NS_LITERAL_STRING("br"),
+                                                     getter_AddRefs(brElem));
+          NS_ENSURE_SUCCESS(rv, rv);
+          rv = divElem->AppendChild(brElem, getter_AddRefs(extraBr));
+          NS_ENSURE_SUCCESS(rv, rv);
+
+          // Insert the non-empty <div> into the DOM.
+          rv = htmlEditor->InsertElementAtSelection(divElem, false);
+          NS_ENSURE_SUCCESS(rv, rv);
+
+          // Position into the div, so out content goes there.
+          nsCOMPtr<nsISelection> selection;
+          m_editor->GetSelection(getter_AddRefs(selection));
+          rv = selection->Collapse(divElem, 0);
+          NS_ENSURE_SUCCESS(rv, rv);
+        }
 
         if (mailEditor) {
           rv = mailEditor->InsertTextWithQuotations(aBuf);
         } else {
           // Will we ever get here?
           rv = textEditor->InsertText(aBuf);
         }
         NS_ENSURE_SUCCESS(rv, rv);
 
-        if (sigOnTopInserted) {
-          // Sadly the M-C editor inserts a <br> between the <div> for the signature
-          // and this <div>, so remove the <br> we don't want.
-          nsCOMPtr<nsIDOMNode> brBeforeDiv;
-          nsAutoString tagLocalName;
-          rv = divElem->GetPreviousSibling(getter_AddRefs(brBeforeDiv));
-          if (NS_SUCCEEDED(rv) && brBeforeDiv) {
-            brBeforeDiv->GetLocalName(tagLocalName);
-            if (tagLocalName.EqualsLiteral("br")) {
-              rv = m_editor->DeleteNode(brBeforeDiv);
-              NS_ENSURE_SUCCESS(rv, rv);
+        if (isForwarded) {
+          // Special treatment for forwarded messages: Part 2.
+          if (sigOnTopInserted) {
+            // Sadly the M-C editor inserts a <br> between the <div> for the signature
+            // and this <div>, so remove the <br> we don't want.
+            nsCOMPtr<nsIDOMNode> brBeforeDiv;
+            nsAutoString tagLocalName;
+            rv = divElem->GetPreviousSibling(getter_AddRefs(brBeforeDiv));
+            if (NS_SUCCEEDED(rv) && brBeforeDiv) {
+              brBeforeDiv->GetLocalName(tagLocalName);
+              if (tagLocalName.EqualsLiteral("br")) {
+                rv = m_editor->DeleteNode(brBeforeDiv);
+                NS_ENSURE_SUCCESS(rv, rv);
+              }
             }
           }
+
+          // Clean up the <br> we inserted.
+          rv = m_editor->DeleteNode(extraBr);
+          NS_ENSURE_SUCCESS(rv, rv);
         }
 
-        // Clean up the <br> we inserted.
-        rv = m_editor->DeleteNode(resultNode);
-        NS_ENSURE_SUCCESS(rv, rv);
-
         // Use our own function instead of nsEditor::EndOfDocument() because
         // we don't want to position at the end of the div we've just created.
+        // It's OK to use, even if we're not forwarding and didn't create a
+        // <div>.
         rv = MoveToEndOfDocument();
         NS_ENSURE_SUCCESS(rv, rv);
       }
 
       if ((!isForwarded || !sigOnTop) && !aSignature.IsEmpty()) {
         textEditor->InsertLineBreak();
         InsertDivWrappedTextAtSelection(aSignature,
                                         NS_LITERAL_STRING("moz-signature"));