Replace WTF::move with WTFMove
[WebKit-https.git] / Source / WebCore / editing / ReplaceNodeWithSpanCommand.cpp
index 662415b..a4c6858 100644 (file)
@@ -48,25 +48,20 @@ ReplaceNodeWithSpanCommand::ReplaceNodeWithSpanCommand(PassRefPtr<HTMLElement> e
     ASSERT(m_elementToReplace);
 }
 
-static void swapInNodePreservingAttributesAndChildren(HTMLElement* newNode, HTMLElement* nodeToReplace)
+static void swapInNodePreservingAttributesAndChildren(HTMLElement& newNode, HTMLElement& nodeToReplace)
 {
-    ASSERT(nodeToReplace->inDocument());
-    ExceptionCode ec = 0;
-    ContainerNode* parentNode = nodeToReplace->parentNode();
-    parentNode->insertBefore(newNode, nodeToReplace, ec);
-    ASSERT(!ec);
+    ASSERT(nodeToReplace.inDocument());
+    RefPtr<ContainerNode> parentNode = nodeToReplace.parentNode();
 
-    RefPtr<Node> nextChild;
-    for (Node* child = nodeToReplace->firstChild(); child; child = nextChild.get()) {
-        nextChild = child->nextSibling();
-        newNode->appendChild(child, ec);
-        ASSERT(!ec);
-    }
+    // FIXME: Fix this to send the proper MutationRecords when MutationObservers are present.
+    newNode.cloneDataFromElement(nodeToReplace);
+    NodeVector children;
+    getChildNodes(nodeToReplace, children);
+    for (auto& child : children)
+        newNode.appendChild(WTFMove(child), ASSERT_NO_EXCEPTION);
 
-    newNode->attributes()->setAttributes(*nodeToReplace->attributes());
-
-    parentNode->removeChild(nodeToReplace, ec);
-    ASSERT(!ec);
+    parentNode->insertBefore(newNode, &nodeToReplace, ASSERT_NO_EXCEPTION);
+    parentNode->removeChild(nodeToReplace, ASSERT_NO_EXCEPTION);
 }
 
 void ReplaceNodeWithSpanCommand::doApply()
@@ -75,14 +70,22 @@ void ReplaceNodeWithSpanCommand::doApply()
         return;
     if (!m_spanElement)
         m_spanElement = createHTMLElement(m_elementToReplace->document(), spanTag);
-    swapInNodePreservingAttributesAndChildren(m_spanElement.get(), m_elementToReplace.get());
+    swapInNodePreservingAttributesAndChildren(*m_spanElement, *m_elementToReplace);
 }
 
 void ReplaceNodeWithSpanCommand::doUnapply()
 {
     if (!m_spanElement->inDocument())
         return;
-    swapInNodePreservingAttributesAndChildren(m_elementToReplace.get(), m_spanElement.get());
+    swapInNodePreservingAttributesAndChildren(*m_elementToReplace, *m_spanElement);
+}
+
+#ifndef NDEBUG
+void ReplaceNodeWithSpanCommand::getNodesInCommand(HashSet<Node*>& nodes)
+{
+    addNodeAndDescendants(m_elementToReplace.get(), nodes);
+    addNodeAndDescendants(m_spanElement.get(), nodes);
 }
+#endif
 
 } // namespace WebCore