Bug 1407854 - Part 3: Pass the child node at the offset as an extra argument where possible to CreateNode(); r=masayuki
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 11 Oct 2017 23:16:00 -0400
changeset 386019 95c942759fe204fdbe8dd82407ea54fe6755cf18
parent 386018 4f60235521e987e272de2eb0864d179442428d28
child 386020 7222707904762b443015aeb58cb9eda0b5aa21dc
push id32673
push userarchaeopteryx@coole-files.de
push dateFri, 13 Oct 2017 09:13:17 +0000
treeherdermozilla-central@196dadb2fe50 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1407854
milestone58.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 1407854 - Part 3: Pass the child node at the offset as an extra argument where possible to CreateNode(); r=masayuki This patch converts almost all of the call sites over to passing the extra argument explicitly.
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorBase.h
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditRules.h
editor/libeditor/HTMLEditor.cpp
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -3978,17 +3978,17 @@ EditorBase::IsPreformatted(nsIDOMNode* a
  */
 int32_t
 EditorBase::SplitNodeDeep(nsIContent& aNode,
                           nsIContent& aSplitPointParent,
                           int32_t aSplitPointOffset,
                           EmptyContainers aEmptyContainers,
                           nsIContent** aOutLeftNode,
                           nsIContent** aOutRightNode,
-                          nsCOMPtr<nsIDOMNode>* ioChildAtSplitPointOffset)
+                          nsCOMPtr<nsIContent>* ioChildAtSplitPointOffset)
 {
   MOZ_ASSERT(&aSplitPointParent == &aNode ||
              EditorUtils::IsDescendantOf(&aSplitPointParent, &aNode));
   int32_t offset = aSplitPointOffset;
 
   nsCOMPtr<nsIContent> leftNode, rightNode;
   OwningNonNull<nsIContent> nodeToSplit = aSplitPointParent;
   while (true) {
@@ -4033,17 +4033,17 @@ EditorBase::SplitNodeDeep(nsIContent& aN
 
   if (aOutLeftNode) {
     leftNode.forget(aOutLeftNode);
   }
   if (aOutRightNode) {
     rightNode.forget(aOutRightNode);
   }
   if (ioChildAtSplitPointOffset) {
-    *ioChildAtSplitPointOffset = do_QueryInterface(nodeToSplit);
+    *ioChildAtSplitPointOffset = nodeToSplit;
   }
 
   return offset;
 }
 
 /**
  * This joins two like nodes "deeply", joining children as appropriate.
  * Returns the point of the join, or (nullptr, -1) in case of error.
@@ -4224,18 +4224,19 @@ EditorBase::DeleteSelectionAndCreateElem
   nsresult rv = DeleteSelectionAndPrepareToCreateNode();
   NS_ENSURE_SUCCESS(rv, nullptr);
 
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, nullptr);
 
   nsCOMPtr<nsINode> node = selection->GetAnchorNode();
   uint32_t offset = selection->AnchorOffset();
-
-  nsCOMPtr<Element> newElement = CreateNode(&aTag, node, offset);
+  nsIContent* child = selection->GetChildAtAnchorOffset();
+
+  nsCOMPtr<Element> newElement = CreateNode(&aTag, node, offset, child);
 
   // We want the selection to be just after the new node
   rv = selection->Collapse(node, offset + 1);
   NS_ENSURE_SUCCESS(rv, nullptr);
 
   return newElement.forget();
 }
 
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -949,17 +949,17 @@ public:
 
   enum class EmptyContainers { no, yes };
   int32_t SplitNodeDeep(nsIContent& aNode, nsIContent& aSplitPointParent,
                         int32_t aSplitPointOffset,
                         EmptyContainers aEmptyContainers =
                           EmptyContainers::yes,
                         nsIContent** outLeftNode = nullptr,
                         nsIContent** outRightNode = nullptr,
-                        nsCOMPtr<nsIDOMNode>* ioChildAtSplitPointOffset =
+                        nsCOMPtr<nsIContent>* ioChildAtSplitPointOffset =
                           nullptr);
   EditorDOMPoint JoinNodeDeep(nsIContent& aLeftNode,
                               nsIContent& aRightNode);
 
   nsresult GetString(const nsAString& name, nsAString& value);
 
   void BeginUpdateViewBatch();
   virtual nsresult EndUpdateViewBatch();
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -3257,34 +3257,37 @@ HTMLEditRules::WillMakeList(Selection* a
       }
     }
 
     // get selection location
     NS_ENSURE_STATE(aSelection->RangeCount());
     nsCOMPtr<nsINode> container =
       aSelection->GetRangeAt(0)->GetStartContainer();
     int32_t offset = aSelection->GetRangeAt(0)->StartOffset();
+    nsCOMPtr<nsIContent> child =
+      aSelection->GetRangeAt(0)->GetChildAtStartOffset();
     NS_ENSURE_STATE(container);
 
     // make sure we can put a list here
     NS_ENSURE_STATE(mHTMLEditor);
     if (!mHTMLEditor->CanContainTag(*container, listType)) {
       *aCancel = true;
       return NS_OK;
     }
-    rv = SplitAsNeeded(listType, container, offset);
+    rv = SplitAsNeeded(listType, container, offset,
+                       address_of(child));
     NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_STATE(mHTMLEditor);
     nsCOMPtr<Element> theList =
-      mHTMLEditor->CreateNode(listType, container, offset);
+      mHTMLEditor->CreateNode(listType, container, offset, child);
     NS_ENSURE_STATE(theList);
 
     NS_ENSURE_STATE(mHTMLEditor);
     nsCOMPtr<Element> theListItem =
-      mHTMLEditor->CreateNode(itemType, theList, 0);
+      mHTMLEditor->CreateNode(itemType, theList, 0, theList->GetFirstChild());
     NS_ENSURE_STATE(theListItem);
 
     // remember our new block for postprocessing
     mNewBlock = theListItem;
     // put selection in new list item
     *aHandled = true;
     rv = aSelection->Collapse(theListItem, 0);
     // Don't restore the selection
@@ -3304,16 +3307,17 @@ HTMLEditRules::WillMakeList(Selection* a
   nsCOMPtr<nsINode> curParent;
   nsCOMPtr<Element> curList, prevListItem;
 
   for (uint32_t i = 0; i < listCount; i++) {
     // here's where we actually figure out what to do
     nsCOMPtr<Element> newBlock;
     NS_ENSURE_STATE(arrayOfNodes[i]->IsContent());
     OwningNonNull<nsIContent> curNode = *arrayOfNodes[i]->AsContent();
+    nsCOMPtr<nsIContent> curChild(curNode);
     int32_t offset;
     curParent = EditorBase::GetNodeLocation(curNode, &offset);
 
     // make sure we don't assemble content that is in different table cells
     // into the same list.  respect table cell boundaries when listifying.
     if (curList && InDifferentTableElements(curList, curNode)) {
       curList = nullptr;
     }
@@ -3373,17 +3377,19 @@ HTMLEditRules::WillMakeList(Selection* a
           nsCOMPtr<nsIContent> splitNode =
             mHTMLEditor->SplitNode(*curParent->AsContent(), offset, rv);
           NS_ENSURE_TRUE(!rv.Failed(), rv.StealNSResult());
           newBlock = splitNode ? splitNode->AsElement() : nullptr;
           int32_t offset;
           nsCOMPtr<nsINode> parent = EditorBase::GetNodeLocation(curParent,
                                                                  &offset);
           NS_ENSURE_STATE(mHTMLEditor);
-          curList = mHTMLEditor->CreateNode(listType, parent, offset);
+          curList = mHTMLEditor->CreateNode(listType, parent, offset,
+                                            curParent ? curParent->AsContent()
+                                                      : nullptr);
           NS_ENSURE_STATE(curList);
         }
         // move list item to new list
         NS_ENSURE_STATE(mHTMLEditor);
         rv = mHTMLEditor->MoveNode(curNode, curList, -1);
         NS_ENSURE_SUCCESS(rv, rv);
         // convert list item type if needed
         NS_ENSURE_STATE(mHTMLEditor);
@@ -3439,20 +3445,23 @@ HTMLEditRules::WillMakeList(Selection* a
       rv = mHTMLEditor->RemoveContainer(curNode);
       NS_ENSURE_SUCCESS(rv, rv);
       listCount = arrayOfNodes.Length();
       continue;
     }
 
     // need to make a list to put things in if we haven't already,
     if (!curList) {
-      rv = SplitAsNeeded(listType, curParent, offset);
+      nsCOMPtr<nsIContent> curChild(curNode);
+      rv = SplitAsNeeded(listType, curParent, offset,
+                         address_of(curChild));
       NS_ENSURE_SUCCESS(rv, rv);
       NS_ENSURE_STATE(mHTMLEditor);
-      curList = mHTMLEditor->CreateNode(listType, curParent, offset);
+      curList = mHTMLEditor->CreateNode(listType, curParent, offset,
+                                        curChild);
       // remember our new block for postprocessing
       mNewBlock = curList;
       // curList is now the correct thing to put curNode in
       prevListItem = nullptr;
     }
 
     // if curNode isn't a list item, we must wrap it in one
     nsCOMPtr<Element> listItem;
@@ -3604,17 +3613,18 @@ HTMLEditRules::MakeBasicBlock(Selection&
 
   // If nothing visible in list, make an empty block
   if (ListIsEmptyLine(arrayOfNodes)) {
     // Get selection location
     NS_ENSURE_STATE(aSelection.GetRangeAt(0) &&
                     aSelection.GetRangeAt(0)->GetStartContainer());
     OwningNonNull<nsINode> container =
       *aSelection.GetRangeAt(0)->GetStartContainer();
-    nsIContent* child = aSelection.GetRangeAt(0)->GetChildAtStartOffset();
+    nsCOMPtr<nsIContent> child =
+      aSelection.GetRangeAt(0)->GetChildAtStartOffset();
     int32_t offset = aSelection.GetRangeAt(0)->StartOffset();
 
     if (&blockType == nsGkAtoms::normal ||
         &blockType == nsGkAtoms::_empty) {
       // We are removing blocks (going to "body text")
       NS_ENSURE_TRUE(htmlEditor->GetBlock(container), NS_ERROR_NULL_POINTER);
       OwningNonNull<Element> curBlock = *htmlEditor->GetBlock(container);
       if (HTMLEditUtils::IsFormatNode(curBlock)) {
@@ -3646,22 +3656,23 @@ HTMLEditRules::MakeBasicBlock(Selection&
       // We are making a block.  Consume a br, if needed.
       nsCOMPtr<nsIContent> brNode =
         htmlEditor->GetNextHTMLNode(container, offset, child, true);
       if (brNode && brNode->IsHTMLElement(nsGkAtoms::br)) {
         rv = htmlEditor->DeleteNode(brNode);
         NS_ENSURE_SUCCESS(rv, rv);
         // We don't need to act on this node any more
         arrayOfNodes.RemoveElement(brNode);
+        child = nullptr;
       }
       // Make sure we can put a block here
-      rv = SplitAsNeeded(blockType, container, offset);
+      rv = SplitAsNeeded(blockType, container, offset, address_of(child));
       NS_ENSURE_SUCCESS(rv, rv);
       nsCOMPtr<Element> block =
-        htmlEditor->CreateNode(&blockType, container, offset);
+        htmlEditor->CreateNode(&blockType, container, offset, child);
       NS_ENSURE_STATE(block);
       // Remember our new block for postprocessing
       mNewBlock = block;
       // Delete anything that was in the list of nodes
       while (!arrayOfNodes.IsEmpty()) {
         OwningNonNull<nsINode> curNode = arrayOfNodes[0];
         rv = htmlEditor->DeleteNode(curNode);
         NS_ENSURE_SUCCESS(rv, rv);
@@ -3785,23 +3796,26 @@ HTMLEditRules::WillCSSIndent(Selection* 
 
   // if nothing visible in list, make an empty block
   if (ListIsEmptyLine(arrayOfNodes)) {
     // get selection location
     NS_ENSURE_STATE(aSelection->RangeCount());
     nsCOMPtr<nsINode> container = aSelection->GetRangeAt(0)->GetStartContainer();
     int32_t offset = aSelection->GetRangeAt(0)->StartOffset();
     NS_ENSURE_STATE(container);
+    nsCOMPtr<nsIContent> child =
+      aSelection->GetRangeAt(0)->GetChildAtStartOffset();
 
     // make sure we can put a block here
-    rv = SplitAsNeeded(*nsGkAtoms::div, container, offset);
+    rv = SplitAsNeeded(*nsGkAtoms::div, container, offset, address_of(child));
     NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_STATE(mHTMLEditor);
     nsCOMPtr<Element> theBlock = mHTMLEditor->CreateNode(nsGkAtoms::div,
-                                                         container, offset);
+                                                         container, offset,
+                                                         child);
     NS_ENSURE_STATE(theBlock);
     // remember our new block for postprocessing
     mNewBlock = theBlock;
     ChangeIndentation(*theBlock, Change::plus);
     // delete anything that was in the list of nodes
     while (!arrayOfNodes.IsEmpty()) {
       OwningNonNull<nsINode> curNode = arrayOfNodes[0];
       NS_ENSURE_STATE(mHTMLEditor);
@@ -3880,22 +3894,24 @@ HTMLEditRules::WillCSSIndent(Selection* 
       // curNode is still right after it in the same list.
       if (curList) {
         NS_ENSURE_STATE(mHTMLEditor);
         sibling = mHTMLEditor->GetPriorHTMLSibling(curNode);
       }
 
       if (!curList || (sibling && sibling != curList)) {
         // create a new nested list of correct type
+        nsCOMPtr<nsIContent> curChild(curNode);
         rv =
-          SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent, offset);
+          SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent, offset,
+                        address_of(curChild));
         NS_ENSURE_SUCCESS(rv, rv);
         NS_ENSURE_STATE(mHTMLEditor);
         curList = mHTMLEditor->CreateNode(curParent->NodeInfo()->NameAtom(),
-                                          curParent, offset);
+                                          curParent, offset, curChild);
         NS_ENSURE_STATE(curList);
         // curList is now the correct thing to put curNode in
         // remember our new block for postprocessing
         mNewBlock = curList;
       }
       // tuck the node into the end of the active list
       uint32_t listLen = curList->Length();
       NS_ENSURE_STATE(mHTMLEditor);
@@ -3912,21 +3928,23 @@ HTMLEditRules::WillCSSIndent(Selection* 
           // First, check that our element can contain a div.
           if (NS_WARN_IF(!mHTMLEditor)) {
             return NS_ERROR_UNEXPECTED;
           }
           if (!mHTMLEditor->CanContainTag(*curParent, *nsGkAtoms::div)) {
             return NS_OK; // cancelled
           }
 
-          rv = SplitAsNeeded(*nsGkAtoms::div, curParent, offset);
+          nsCOMPtr<nsIContent> curChild(curNode);
+          rv = SplitAsNeeded(*nsGkAtoms::div, curParent, offset,
+                             address_of(curChild));
           NS_ENSURE_SUCCESS(rv, rv);
           NS_ENSURE_STATE(mHTMLEditor);
           curQuote = mHTMLEditor->CreateNode(nsGkAtoms::div, curParent,
-                                             offset);
+                                             offset, curChild);
           NS_ENSURE_STATE(curQuote);
           ChangeIndentation(*curQuote, Change::plus);
           // remember our new block for postprocessing
           mNewBlock = curQuote;
           // curQuote is now the correct thing to put curNode in
         }
 
         // tuck the node into the end of the active blockquote
@@ -3976,23 +3994,27 @@ HTMLEditRules::WillHTMLIndent(Selection*
   // if nothing visible in list, make an empty block
   if (ListIsEmptyLine(arrayOfNodes)) {
     // get selection location
     NS_ENSURE_STATE(aSelection->RangeCount());
     nsCOMPtr<nsINode> container =
       aSelection->GetRangeAt(0)->GetStartContainer();
     int32_t offset = aSelection->GetRangeAt(0)->StartOffset();
     NS_ENSURE_STATE(container);
+    nsCOMPtr<nsIContent> child =
+      aSelection->GetRangeAt(0)->GetChildAtStartOffset();
 
     // make sure we can put a block here
-    rv = SplitAsNeeded(*nsGkAtoms::blockquote, container, offset);
+    rv = SplitAsNeeded(*nsGkAtoms::blockquote, container, offset,
+                       address_of(child));
     NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_STATE(mHTMLEditor);
     nsCOMPtr<Element> theBlock = mHTMLEditor->CreateNode(nsGkAtoms::blockquote,
-                                                         container, offset);
+                                                         container, offset,
+                                                         child);
     NS_ENSURE_STATE(theBlock);
     // remember our new block for postprocessing
     mNewBlock = theBlock;
     // delete anything that was in the list of nodes
     while (!arrayOfNodes.IsEmpty()) {
       OwningNonNull<nsINode> curNode = arrayOfNodes[0];
       NS_ENSURE_STATE(mHTMLEditor);
       rv = mHTMLEditor->DeleteNode(curNode);
@@ -4071,22 +4093,24 @@ HTMLEditRules::WillHTMLIndent(Selection*
       // curNode is still right after it in the same list.
       if (curList) {
         NS_ENSURE_STATE(mHTMLEditor);
         sibling = mHTMLEditor->GetPriorHTMLSibling(curNode);
       }
 
       if (!curList || (sibling && sibling != curList)) {
         // create a new nested list of correct type
+        nsCOMPtr<nsIContent> curChild(curNode);
         rv =
-          SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent, offset);
+          SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent, offset,
+                        address_of(curChild));
         NS_ENSURE_SUCCESS(rv, rv);
         NS_ENSURE_STATE(mHTMLEditor);
         curList = mHTMLEditor->CreateNode(curParent->NodeInfo()->NameAtom(),
-                                          curParent, offset);
+                                          curParent, offset, curChild);
         NS_ENSURE_STATE(curList);
         // curList is now the correct thing to put curNode in
         // remember our new block for postprocessing
         mNewBlock = curList;
       }
       // tuck the node into the end of the active list
       NS_ENSURE_STATE(mHTMLEditor);
       rv = mHTMLEditor->MoveNode(curNode, curList, -1);
@@ -4115,22 +4139,23 @@ HTMLEditRules::WillHTMLIndent(Selection*
         if (curList) {
           sibling = nullptr;
           NS_ENSURE_STATE(mHTMLEditor);
           sibling = mHTMLEditor->GetPriorHTMLSibling(curNode);
         }
 
         if (!curList || (sibling && sibling != curList)) {
           // create a new nested list of correct type
+          nsCOMPtr<nsIContent> curChild(listItem);
           rv = SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent,
-                             offset);
+                             offset, address_of(curChild));
           NS_ENSURE_SUCCESS(rv, rv);
           NS_ENSURE_STATE(mHTMLEditor);
           curList = mHTMLEditor->CreateNode(curParent->NodeInfo()->NameAtom(),
-                                            curParent, offset);
+                                            curParent, offset, curChild);
           NS_ENSURE_STATE(curList);
         }
         NS_ENSURE_STATE(mHTMLEditor);
         rv = mHTMLEditor->MoveNode(listItem, curList, -1);
         NS_ENSURE_SUCCESS(rv, rv);
         // remember we indented this li
         indentedLI = listItem;
       } else {
@@ -4146,21 +4171,23 @@ HTMLEditRules::WillHTMLIndent(Selection*
           // First, check that our element can contain a blockquote.
           if (NS_WARN_IF(!mHTMLEditor)) {
             return NS_ERROR_UNEXPECTED;
           }
           if (!mHTMLEditor->CanContainTag(*curParent, *nsGkAtoms::blockquote)) {
             return NS_OK; // cancelled
           }
 
-          rv = SplitAsNeeded(*nsGkAtoms::blockquote, curParent, offset);
+          nsCOMPtr<nsIContent> curChild(curNode);
+          rv = SplitAsNeeded(*nsGkAtoms::blockquote, curParent, offset,
+                             address_of(curChild));
           NS_ENSURE_SUCCESS(rv, rv);
           NS_ENSURE_STATE(mHTMLEditor);
           curQuote = mHTMLEditor->CreateNode(nsGkAtoms::blockquote, curParent,
-                                             offset);
+                                             offset, curChild);
           NS_ENSURE_STATE(curQuote);
           // remember our new block for postprocessing
           mNewBlock = curQuote;
           // curQuote is now the correct thing to put curNode in
         }
 
         // tuck the node into the end of the active blockquote
         NS_ENSURE_STATE(mHTMLEditor);
@@ -4740,19 +4767,21 @@ HTMLEditRules::WillAlign(Selection& aSel
     }
   }
   if (emptyDiv) {
     nsCOMPtr<nsINode> parent =
       aSelection.GetRangeAt(0) ? aSelection.GetRangeAt(0)->GetStartContainer()
                                : nullptr;
     NS_ENSURE_STATE(parent);
     int32_t offset = aSelection.GetRangeAt(0)->StartOffset();
-    nsIContent* child = aSelection.GetRangeAt(0)->GetChildAtStartOffset();
-
-    rv = SplitAsNeeded(*nsGkAtoms::div, parent, offset);
+    nsCOMPtr<nsIContent> child =
+      aSelection.GetRangeAt(0)->GetChildAtStartOffset();
+
+    rv = SplitAsNeeded(*nsGkAtoms::div, parent, offset,
+                       address_of(child));
     NS_ENSURE_SUCCESS(rv, rv);
     // Consume a trailing br, if any.  This is to keep an alignment from
     // creating extra lines, if possible.
     nsCOMPtr<nsIContent> brContent =
       htmlEditor->GetNextHTMLNode(parent, offset, child);
     if (brContent && TextEditUtils::IsBreak(brContent)) {
       // Making use of html structure... if next node after where we are
       // putting our div is not a block, then the br we found is in same block
@@ -4762,17 +4791,17 @@ HTMLEditRules::WillAlign(Selection& aSel
         sibling = htmlEditor->GetNextHTMLSibling(child);
       }
       if (sibling && !IsBlockNode(*sibling)) {
         rv = htmlEditor->DeleteNode(brContent);
         NS_ENSURE_SUCCESS(rv, rv);
       }
     }
     nsCOMPtr<Element> div = htmlEditor->CreateNode(nsGkAtoms::div, parent,
-                                                   offset);
+                                                   offset, child);
     NS_ENSURE_STATE(div);
     // Remember our new block for postprocessing
     mNewBlock = div;
     // Set up the alignment on the div, using HTML or CSS
     rv = AlignBlock(*div, aAlignType, ContentsOnly::yes);
     NS_ENSURE_SUCCESS(rv, rv);
     *aHandled = true;
     // Put in a moz-br so that it won't get deleted
@@ -4863,19 +4892,22 @@ HTMLEditRules::WillAlign(Selection& aSel
     // node doesn't go in div we used earlier.
     if (!curDiv || transitionList[i]) {
       // First, check that our element can contain a div.
       if (!htmlEditor->CanContainTag(*curParent, *nsGkAtoms::div)) {
         // Cancelled
         return NS_OK;
       }
 
-      rv = SplitAsNeeded(*nsGkAtoms::div, curParent, offset);
+      nsCOMPtr<nsIContent> curChild(curNode->AsContent());
+      rv = SplitAsNeeded(*nsGkAtoms::div, curParent, offset,
+                         address_of(curChild));
       NS_ENSURE_SUCCESS(rv, rv);
-      curDiv = htmlEditor->CreateNode(nsGkAtoms::div, curParent, offset);
+      curDiv = htmlEditor->CreateNode(nsGkAtoms::div, curParent, offset,
+                                      curChild);
       NS_ENSURE_STATE(curDiv);
       // Remember our new block for postprocessing
       mNewBlock = curDiv;
       // Set up the alignment on the div
       rv = AlignBlock(*curDiv, aAlignType, ContentsOnly::yes);
     }
 
     NS_ENSURE_STATE(curNode->IsContent());
@@ -4952,17 +4984,18 @@ HTMLEditRules::AlignBlockContents(nsIDOM
                                               *alignType);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     }
   } else {
     // else we need to put in a div, set the alignment, and toss in all the children
     NS_ENSURE_STATE(mHTMLEditor);
-    RefPtr<Element> divElem = mHTMLEditor->CreateNode(nsGkAtoms::div, node, 0);
+    RefPtr<Element> divElem = mHTMLEditor->CreateNode(nsGkAtoms::div, node, 0,
+                                                      node->GetFirstChild());
     NS_ENSURE_STATE(divElem);
     // set up the alignment on the div
     if (useCSS) {
       NS_ENSURE_STATE(mHTMLEditor);
       nsresult rv =
         mHTMLEditor->SetAttributeOrEquivalent(divElem, nsGkAtoms::align,
                                               *alignType, false);
       if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -6757,17 +6790,18 @@ HTMLEditRules::ReturnInListItem(Selectio
         RefPtr<nsAtom> nodeAtom = aListItem.NodeInfo()->NameAtom();
         if (nodeAtom == nsGkAtoms::dd || nodeAtom == nsGkAtoms::dt) {
           nsCOMPtr<nsINode> list = aListItem.GetParentNode();
           int32_t itemOffset = list ? list->IndexOf(&aListItem) : -1;
 
           nsAtom* listAtom = nodeAtom == nsGkAtoms::dt ? nsGkAtoms::dd
                                                         : nsGkAtoms::dt;
           nsCOMPtr<Element> newListItem =
-            htmlEditor->CreateNode(listAtom, list, itemOffset + 1);
+            htmlEditor->CreateNode(listAtom, list, itemOffset + 1,
+                                   aListItem.GetNextSibling());
           NS_ENSURE_STATE(newListItem);
           rv = htmlEditor->DeleteNode(&aListItem);
           NS_ENSURE_SUCCESS(rv, rv);
           rv = aSelection.Collapse(newListItem, 0);
           NS_ENSURE_SUCCESS(rv, rv);
 
           return NS_OK;
         }
@@ -6851,21 +6885,23 @@ HTMLEditRules::MakeBlockquote(nsTArray<O
     } else {
       prevParent = curNode->GetParentNode();
     }
 
     // If no curBlock, make one
     if (!curBlock) {
       nsCOMPtr<nsINode> curParent = curNode->GetParentNode();
       int32_t offset = curParent ? curParent->IndexOf(curNode) : -1;
-      nsresult rv = SplitAsNeeded(*nsGkAtoms::blockquote, curParent, offset);
+      nsCOMPtr<nsIContent> curChild(curNode->AsContent());
+      nsresult rv = SplitAsNeeded(*nsGkAtoms::blockquote, curParent, offset,
+                                  address_of(curChild));
       NS_ENSURE_SUCCESS(rv, rv);
       NS_ENSURE_STATE(mHTMLEditor);
       curBlock = mHTMLEditor->CreateNode(nsGkAtoms::blockquote, curParent,
-                                         offset);
+                                         offset, curChild);
       NS_ENSURE_STATE(curBlock);
       // remember our new block for postprocessing
       mNewBlock = curBlock;
       // note: doesn't matter if we set mNewBlock multiple times.
     }
 
     NS_ENSURE_STATE(mHTMLEditor);
     nsresult rv = mHTMLEditor->MoveNode(curNode->AsContent(), curBlock, -1);
@@ -7020,38 +7056,44 @@ HTMLEditRules::ApplyBlockStyle(nsTArray<
       // Recursion time
       nsTArray<OwningNonNull<nsINode>> childArray;
       GetChildNodesForOperation(*curNode, childArray);
       if (!childArray.IsEmpty()) {
         nsresult rv = ApplyBlockStyle(childArray, aBlockTag);
         NS_ENSURE_SUCCESS(rv, rv);
       } else {
         // Make sure we can put a block here
-        nsresult rv = SplitAsNeeded(aBlockTag, curParent, offset);
+        nsCOMPtr<nsIContent> curChild(curNode->AsContent());
+        nsresult rv = SplitAsNeeded(aBlockTag, curParent, offset,
+                                    address_of(curChild));
         NS_ENSURE_SUCCESS(rv, rv);
         nsCOMPtr<Element> theBlock =
-          htmlEditor->CreateNode(&aBlockTag, curParent, offset);
+          htmlEditor->CreateNode(&aBlockTag, curParent, offset,
+                                 curChild);
         NS_ENSURE_STATE(theBlock);
         // Remember our new block for postprocessing
         mNewBlock = theBlock;
       }
     } else if (curNode->IsHTMLElement(nsGkAtoms::br)) {
       // If the node is a break, we honor it by putting further nodes in a new
       // parent
       if (curBlock) {
         // Forget any previous block used for previous inline nodes
         curBlock = nullptr;
         nsresult rv = htmlEditor->DeleteNode(curNode);
         NS_ENSURE_SUCCESS(rv, rv);
       } else {
         // The break is the first (or even only) node we encountered.  Create a
         // block for it.
-        nsresult rv = SplitAsNeeded(aBlockTag, curParent, offset);
+        nsCOMPtr<nsIContent> curChild(curNode->AsContent());
+        nsresult rv = SplitAsNeeded(aBlockTag, curParent, offset,
+                                    address_of(curChild));
         NS_ENSURE_SUCCESS(rv, rv);
-        curBlock = htmlEditor->CreateNode(&aBlockTag, curParent, offset);
+        curBlock = htmlEditor->CreateNode(&aBlockTag, curParent, offset,
+                                          curChild);
         NS_ENSURE_STATE(curBlock);
         // Remember our new block for postprocessing
         mNewBlock = curBlock;
         // Note: doesn't matter if we set mNewBlock multiple times.
         rv = htmlEditor->MoveNode(curNode->AsContent(), curBlock, -1);
         NS_ENSURE_SUCCESS(rv, rv);
       }
     } else if (IsInlineNode(curNode)) {
@@ -7064,19 +7106,22 @@ HTMLEditRules::ApplyBlockStyle(nsTArray<
       // If curNode is a non editable, drop it if we are going to <pre>.
       if (&aBlockTag == nsGkAtoms::pre && !htmlEditor->IsEditable(curNode)) {
         // Do nothing to this block
         continue;
       }
 
       // If no curBlock, make one
       if (!curBlock) {
-        nsresult rv = SplitAsNeeded(aBlockTag, curParent, offset);
+        nsCOMPtr<nsIContent> curChild(curNode->AsContent());
+        nsresult rv = SplitAsNeeded(aBlockTag, curParent, offset,
+                                    address_of(curChild));
         NS_ENSURE_SUCCESS(rv, rv);
-        curBlock = htmlEditor->CreateNode(&aBlockTag, curParent, offset);
+        curBlock = htmlEditor->CreateNode(&aBlockTag, curParent, offset,
+                                          curChild);
         NS_ENSURE_STATE(curBlock);
         // Remember our new block for postprocessing
         mNewBlock = curBlock;
         // Note: doesn't matter if we set mNewBlock multiple times.
       }
 
       if (NS_WARN_IF(!curNode->GetParentNode())) {
         // This is possible due to mutation events, let's not assert
@@ -7096,29 +7141,31 @@ HTMLEditRules::ApplyBlockStyle(nsTArray<
 
 /**
  * Given a tag name, split inOutParent up to the point where we can insert the
  * tag.  Adjust inOutParent and inOutOffset to point to new location for tag.
  */
 nsresult
 HTMLEditRules::SplitAsNeeded(nsAtom& aTag,
                              OwningNonNull<nsINode>& aInOutParent,
-                             int32_t& aInOutOffset)
+                             int32_t& inOutOffset,
+                             nsCOMPtr<nsIContent>* inOutChildAtOffset)
 {
   // XXX Is there a better way to do this?
   nsCOMPtr<nsINode> parent = aInOutParent.forget();
-  nsresult rv = SplitAsNeeded(aTag, parent, aInOutOffset);
+  nsresult rv = SplitAsNeeded(aTag, parent, inOutOffset, inOutChildAtOffset);
   aInOutParent = parent.forget();
   return rv;
 }
 
 nsresult
 HTMLEditRules::SplitAsNeeded(nsAtom& aTag,
                              nsCOMPtr<nsINode>& inOutParent,
-                             int32_t& inOutOffset)
+                             int32_t& inOutOffset,
+                             nsCOMPtr<nsIContent>* inOutChildAtOffset)
 {
   NS_ENSURE_TRUE(inOutParent, NS_ERROR_NULL_POINTER);
 
   // Check that we have a place that can legally contain the tag
   nsCOMPtr<nsINode> tagParent, splitNode;
   for (nsCOMPtr<nsINode> parent = inOutParent; parent;
        parent = parent->GetParentNode()) {
     // Sniffing up the parent tree until we find a legal place for the block
@@ -7146,17 +7193,20 @@ HTMLEditRules::SplitAsNeeded(nsAtom& aTa
     // Could not find a place to build tag!
     return NS_ERROR_FAILURE;
   }
   if (splitNode && splitNode->IsContent() && inOutParent->IsContent()) {
     // We found a place for block, but above inOutParent. We need to split.
     NS_ENSURE_STATE(mHTMLEditor);
     int32_t offset = mHTMLEditor->SplitNodeDeep(*splitNode->AsContent(),
                                                 *inOutParent->AsContent(),
-                                                inOutOffset);
+                                                inOutOffset,
+                                                EditorBase::EmptyContainers::yes,
+                                                nullptr, nullptr,
+                                                inOutChildAtOffset);
     NS_ENSURE_STATE(offset != -1);
     inOutParent = tagParent;
     inOutOffset = offset;
   }
   return NS_OK;
 }
 
 /**
@@ -8780,22 +8830,25 @@ HTMLEditRules::WillAbsolutePosition(Sele
   // If nothing visible in list, make an empty block
   if (ListIsEmptyLine(arrayOfNodes)) {
     // Get selection location
     NS_ENSURE_STATE(aSelection.GetRangeAt(0) &&
                     aSelection.GetRangeAt(0)->GetStartContainer());
     OwningNonNull<nsINode> parent =
       *aSelection.GetRangeAt(0)->GetStartContainer();
     int32_t offset = aSelection.GetRangeAt(0)->StartOffset();
+    nsCOMPtr<nsIContent> child =
+      aSelection.GetRangeAt(0)->GetChildAtStartOffset();
 
     // Make sure we can put a block here
-    rv = SplitAsNeeded(*nsGkAtoms::div, parent, offset);
+    rv = SplitAsNeeded(*nsGkAtoms::div, parent, offset,
+                       address_of(child));
     NS_ENSURE_SUCCESS(rv, rv);
     nsCOMPtr<Element> positionedDiv =
-      htmlEditor->CreateNode(nsGkAtoms::div, parent, offset);
+      htmlEditor->CreateNode(nsGkAtoms::div, parent, offset, child);
     NS_ENSURE_STATE(positionedDiv);
     // Remember our new block for postprocessing
     mNewBlock = positionedDiv;
     // Delete anything that was in the list of nodes
     while (!arrayOfNodes.IsEmpty()) {
       OwningNonNull<nsINode> curNode = arrayOfNodes[0];
       rv = htmlEditor->DeleteNode(curNode);
       NS_ENSURE_SUCCESS(rv, rv);
@@ -8848,17 +8901,18 @@ HTMLEditRules::WillAbsolutePosition(Sele
           nsCOMPtr<nsINode> curParentParent = curParent->GetParentNode();
           int32_t parentOffset = curParentParent
             ? curParentParent->IndexOf(curParent) : -1;
           curPositionedDiv = htmlEditor->CreateNode(nsGkAtoms::div, curParentParent,
                                                     parentOffset);
           mNewBlock = curPositionedDiv;
         }
         curList = htmlEditor->CreateNode(curParent->NodeInfo()->NameAtom(),
-                                         curPositionedDiv, -1);
+                                         curPositionedDiv, -1,
+                                         curPositionedDiv->GetLastChild());
         NS_ENSURE_STATE(curList);
         // curList is now the correct thing to put curNode in.  Remember our
         // new block for postprocessing.
       }
       // Tuck the node into the end of the active list
       rv = htmlEditor->MoveNode(curNode, curList, -1);
       NS_ENSURE_SUCCESS(rv, rv);
     } else {
@@ -8888,41 +8942,45 @@ HTMLEditRules::WillAbsolutePosition(Sele
                              offset);
           NS_ENSURE_SUCCESS(rv, rv);
           if (!curPositionedDiv) {
             nsCOMPtr<nsINode> curParentParent = curParent->GetParentNode();
             int32_t parentOffset = curParentParent ?
               curParentParent->IndexOf(curParent) : -1;
             curPositionedDiv = htmlEditor->CreateNode(nsGkAtoms::div,
                                                       curParentParent,
-                                                      parentOffset);
+                                                      parentOffset,
+                                                      curParent->AsContent());
             mNewBlock = curPositionedDiv;
           }
           curList = htmlEditor->CreateNode(curParent->NodeInfo()->NameAtom(),
-                                           curPositionedDiv, -1);
+                                           curPositionedDiv, -1,
+                                           curPositionedDiv->GetLastChild());
           NS_ENSURE_STATE(curList);
         }
         rv = htmlEditor->MoveNode(listItem, curList, -1);
         NS_ENSURE_SUCCESS(rv, rv);
         // Remember we indented this li
         indentedLI = listItem;
       } else {
         // Need to make a div to put things in if we haven't already
 
         if (!curPositionedDiv) {
           if (curNode->IsHTMLElement(nsGkAtoms::div)) {
             curPositionedDiv = curNode->AsElement();
             mNewBlock = curPositionedDiv;
             curList = nullptr;
             continue;
           }
-          rv = SplitAsNeeded(*nsGkAtoms::div, curParent, offset);
+          nsCOMPtr<nsIContent> curChild(curNode);
+          rv = SplitAsNeeded(*nsGkAtoms::div, curParent, offset,
+                             address_of(curChild));
           NS_ENSURE_SUCCESS(rv, rv);
           curPositionedDiv = htmlEditor->CreateNode(nsGkAtoms::div, curParent,
-                                                    offset);
+                                                    offset, curChild);
           NS_ENSURE_STATE(curPositionedDiv);
           // Remember our new block for postprocessing
           mNewBlock = curPositionedDiv;
           // curPositionedDiv is now the correct thing to put curNode in
         }
 
         // Tuck the node into the end of the active blockquote
         rv = htmlEditor->MoveNode(curNode, curPositionedDiv, -1);
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -375,19 +375,21 @@ protected:
   nsIContent* GetHighestInlineParent(nsINode& aNode);
   void MakeTransitionList(nsTArray<OwningNonNull<nsINode>>& aNodeArray,
                           nsTArray<bool>& aTransitionArray);
   nsresult RemoveBlockStyle(nsTArray<OwningNonNull<nsINode>>& aNodeArray);
   nsresult ApplyBlockStyle(nsTArray<OwningNonNull<nsINode>>& aNodeArray,
                            nsAtom& aBlockTag);
   nsresult MakeBlockquote(nsTArray<OwningNonNull<nsINode>>& aNodeArray);
   nsresult SplitAsNeeded(nsAtom& aTag, OwningNonNull<nsINode>& inOutParent,
-                         int32_t& inOutOffset);
+                         int32_t& inOutOffset,
+                         nsCOMPtr<nsIContent>* inOutChildAtOffset = nullptr);
   nsresult SplitAsNeeded(nsAtom& aTag, nsCOMPtr<nsINode>& inOutParent,
-                         int32_t& inOutOffset);
+                         int32_t& inOutOffset,
+                         nsCOMPtr<nsIContent>* inOutChildAtOffset = nullptr);
   nsresult AddTerminatingBR(nsIDOMNode *aBlock);
   EditorDOMPoint JoinNodesSmart(nsIContent& aNodeLeft,
                                 nsIContent& aNodeRight);
   Element* GetTopEnclosingMailCite(nsINode& aNode);
   nsresult PopListItem(nsIContent& aListItem, bool* aOutOfList = nullptr);
   nsresult RemoveListStructure(Element& aList);
   nsresult CacheInlineStyles(nsIDOMNode* aNode);
   nsresult ReapplyCachedStyles();
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -1606,24 +1606,31 @@ HTMLEditor::InsertNodeAtPoint(nsIDOMNode
       // where we were originally asked.
       parent = topChild = origParent;
       break;
     }
     topChild = parent;
     parent = parent->GetParent();
   }
   if (parent != topChild) {
+    nsCOMPtr<nsIContent> child;
+    if (ioChildAtOffset) {
+      child = do_QueryInterface(*ioChildAtOffset);
+    }
     // we need to split some levels above the original selection parent
     int32_t offset = SplitNodeDeep(*topChild, *origParent, *ioOffset,
                                    aNoEmptyNodes ? EmptyContainers::no
                                                  : EmptyContainers::yes,
-                                   nullptr, nullptr, ioChildAtOffset);
+                                   nullptr, nullptr, address_of(child));
     NS_ENSURE_STATE(offset != -1);
     *ioParent = GetAsDOMNode(parent);
     *ioOffset = offset;
+    if (ioChildAtOffset) {
+      *ioChildAtOffset = GetAsDOMNode(child);
+    }
   }
   // Now we can insert the new node
   nsresult rv = InsertNode(*node, *parent, *ioOffset);
   if (isDocumentFragment) {
     *ioChildAtOffset = do_QueryInterface(parent->GetChildAt(*ioOffset));
   }
   return rv;
 }
@@ -1964,39 +1971,44 @@ HTMLEditor::MakeOrChangeList(const nsASt
 
     NS_ENSURE_TRUE(selection->GetRangeAt(0) &&
                    selection->GetRangeAt(0)->GetStartContainer() &&
                    selection->GetRangeAt(0)->GetStartContainer()->IsContent(),
                    NS_ERROR_FAILURE);
     OwningNonNull<nsIContent> node =
       *selection->GetRangeAt(0)->GetStartContainer()->AsContent();
     int32_t offset = selection->GetRangeAt(0)->StartOffset();
+    nsCOMPtr<nsIContent> child =
+      selection->GetRangeAt(0)->GetChildAtStartOffset();
 
     if (isCollapsed) {
       // have to find a place to put the list
       nsCOMPtr<nsIContent> parent = node;
       nsCOMPtr<nsIContent> topChild = node;
 
       RefPtr<nsAtom> listAtom = NS_Atomize(aListType);
       while (!CanContainTag(*parent, *listAtom)) {
         topChild = parent;
         parent = parent->GetParent();
       }
 
       if (parent != node) {
         // we need to split up to the child of parent
-        offset = SplitNodeDeep(*topChild, *node, offset);
+        offset = SplitNodeDeep(*topChild, *node, offset,
+                               EmptyContainers::yes, nullptr, nullptr,
+                               address_of(child));
         NS_ENSURE_STATE(offset != -1);
       }
 
       // make a list
-      nsCOMPtr<Element> newList = CreateNode(listAtom, parent, offset);
+      nsCOMPtr<Element> newList = CreateNode(listAtom, parent, offset, child);
       NS_ENSURE_STATE(newList);
       // make a list item
-      nsCOMPtr<Element> newItem = CreateNode(nsGkAtoms::li, newList, 0);
+      nsCOMPtr<Element> newItem = CreateNode(nsGkAtoms::li, newList, 0,
+                                             newList->GetFirstChild());
       NS_ENSURE_STATE(newItem);
       rv = selection->Collapse(newItem, 0);
       NS_ENSURE_SUCCESS(rv, rv);
     }
   }
 
   return rules->DidDoAction(selection, &ruleInfo, rv);
 }
@@ -2101,37 +2113,41 @@ HTMLEditor::InsertBasicBlock(const nsASt
 
     NS_ENSURE_TRUE(selection->GetRangeAt(0) &&
                    selection->GetRangeAt(0)->GetStartContainer() &&
                    selection->GetRangeAt(0)->GetStartContainer()->IsContent(),
                    NS_ERROR_FAILURE);
     OwningNonNull<nsIContent> node =
       *selection->GetRangeAt(0)->GetStartContainer()->AsContent();
     int32_t offset = selection->GetRangeAt(0)->StartOffset();
+    nsCOMPtr<nsIContent> child =
+      selection->GetRangeAt(0)->GetChildAtStartOffset();
 
     if (isCollapsed) {
       // have to find a place to put the block
       nsCOMPtr<nsIContent> parent = node;
       nsCOMPtr<nsIContent> topChild = node;
 
       RefPtr<nsAtom> blockAtom = NS_Atomize(aBlockType);
       while (!CanContainTag(*parent, *blockAtom)) {
         NS_ENSURE_TRUE(parent->GetParent(), NS_ERROR_FAILURE);
         topChild = parent;
         parent = parent->GetParent();
       }
 
       if (parent != node) {
         // we need to split up to the child of parent
-        offset = SplitNodeDeep(*topChild, *node, offset);
+        offset = SplitNodeDeep(*topChild, *node, offset,
+                               EmptyContainers::yes, nullptr, nullptr,
+                               address_of(child));
         NS_ENSURE_STATE(offset != -1);
       }
 
       // make a block
-      nsCOMPtr<Element> newBlock = CreateNode(blockAtom, parent, offset);
+      nsCOMPtr<Element> newBlock = CreateNode(blockAtom, parent, offset, child);
       NS_ENSURE_STATE(newBlock);
 
       // reposition selection to inside the block
       rv = selection->Collapse(newBlock, 0);
       NS_ENSURE_SUCCESS(rv, rv);
     }
   }
 
@@ -2172,36 +2188,41 @@ HTMLEditor::Indent(const nsAString& aInd
 
     NS_ENSURE_TRUE(selection->GetRangeAt(0) &&
                    selection->GetRangeAt(0)->GetStartContainer() &&
                    selection->GetRangeAt(0)->GetStartContainer()->IsContent(),
                    NS_ERROR_FAILURE);
     OwningNonNull<nsIContent> node =
       *selection->GetRangeAt(0)->GetStartContainer()->AsContent();
     int32_t offset = selection->GetRangeAt(0)->StartOffset();
+    nsCOMPtr<nsIContent> child =
+      selection->GetRangeAt(0)->GetChildAtStartOffset();
 
     if (aIndent.EqualsLiteral("indent")) {
       if (isCollapsed) {
         // have to find a place to put the blockquote
         nsCOMPtr<nsIContent> parent = node;
         nsCOMPtr<nsIContent> topChild = node;
         while (!CanContainTag(*parent, *nsGkAtoms::blockquote)) {
           NS_ENSURE_TRUE(parent->GetParent(), NS_ERROR_FAILURE);
           topChild = parent;
           parent = parent->GetParent();
         }
 
         if (parent != node) {
           // we need to split up to the child of parent
-          offset = SplitNodeDeep(*topChild, *node, offset);
+          offset = SplitNodeDeep(*topChild, *node, offset,
+                                 EmptyContainers::yes, nullptr, nullptr,
+                                 address_of(child));
           NS_ENSURE_STATE(offset != -1);
         }
 
         // make a blockquote
-        nsCOMPtr<Element> newBQ = CreateNode(nsGkAtoms::blockquote, parent, offset);
+        nsCOMPtr<Element> newBQ =
+          CreateNode(nsGkAtoms::blockquote, parent, offset, child);
         NS_ENSURE_STATE(newBQ);
         // put a space in it so layout will draw the list item
         rv = selection->Collapse(newBQ, 0);
         NS_ENSURE_SUCCESS(rv, rv);
         rv = InsertText(NS_LITERAL_STRING(" "));
         NS_ENSURE_SUCCESS(rv, rv);
         // reposition selection to before the space character
         NS_ENSURE_STATE(selection->GetRangeAt(0));
@@ -4574,17 +4595,18 @@ HTMLEditor::CopyLastEditableChildStyles(
     if (HTMLEditUtils::IsInlineStyle(childElement) ||
         childElement->IsHTMLElement(nsGkAtoms::span)) {
       if (newStyles) {
         newStyles = InsertContainerAbove(newStyles,
                                          childElement->NodeInfo()->NameAtom());
         NS_ENSURE_STATE(newStyles);
       } else {
         deepestStyle = newStyles =
-          CreateNode(childElement->NodeInfo()->NameAtom(), newBlock, 0);
+          CreateNode(childElement->NodeInfo()->NameAtom(), newBlock, 0,
+                     newBlock->GetFirstChild());
         NS_ENSURE_STATE(newStyles);
       }
       CloneAttributes(newStyles, childElement);
     }
     childElement = childElement->GetParentElement();
   }
   if (deepestStyle) {
     RefPtr<Element> retVal = CreateBR(deepestStyle, 0);