Use PassRefPtr less in editing code
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 May 2017 17:41:46 +0000 (17:41 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 May 2017 17:41:46 +0000 (17:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=171534

Reviewed by Geoffrey Garen.

Use PassRefPtr less in editing code.

* editing/AppendNodeCommand.cpp:
(WebCore::AppendNodeCommand::AppendNodeCommand):
(WebCore::AppendNodeCommand::getNodesInCommand):
* editing/AppendNodeCommand.h:
(WebCore::AppendNodeCommand::create):
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::surroundNodeRangeWithElement):
(WebCore::ApplyStyleCommand::positionToComputeInlineStyleChange):
* editing/BreakBlockquoteCommand.cpp:
(WebCore::BreakBlockquoteCommand::doApply):
* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::insertNodeBefore):
(WebCore::CompositeEditCommand::insertNodeAfter):
(WebCore::CompositeEditCommand::insertNodeAt):
(WebCore::CompositeEditCommand::appendNode):
(WebCore::CompositeEditCommand::moveRemainingSiblingsToNewParent):
(WebCore::CompositeEditCommand::mergeIdenticalElements):
(WebCore::CompositeEditCommand::insertNodeAtTabSpanPosition):
(WebCore::CompositeEditCommand::appendBlockPlaceholder):
(WebCore::CompositeEditCommand::insertBlockPlaceholder):
(WebCore::CompositeEditCommand::addBlockPlaceholderIfNeeded):
(WebCore::CompositeEditCommand::insertNewDefaultParagraphElementAt):
(WebCore::CompositeEditCommand::cloneParagraphUnderNewElement):
(WebCore::CompositeEditCommand::moveParagraphs):
* editing/CompositeEditCommand.h:
* editing/CreateLinkCommand.cpp:
(WebCore::CreateLinkCommand::doApply):
* editing/DeleteSelectionCommand.cpp:
(WebCore::DeleteSelectionCommand::makeStylingElementsDirectChildrenOfEditableRootToPreventStyleLoss):
(WebCore::DeleteSelectionCommand::mergeParagraphs):
* editing/FormatBlockCommand.cpp:
(WebCore::FormatBlockCommand::formatRange):
* editing/IndentOutdentCommand.cpp:
(WebCore::IndentOutdentCommand::tryIndentingAsListItem):
(WebCore::IndentOutdentCommand::indentIntoBlockquote):
(WebCore::IndentOutdentCommand::outdentParagraph):
* editing/InsertLineBreakCommand.cpp:
(WebCore::InsertLineBreakCommand::doApply):
* editing/InsertLineBreakCommand.h:
* editing/InsertListCommand.cpp:
(WebCore::InsertListCommand::fixOrphanedListChild):
(WebCore::InsertListCommand::doApplyForSingleParagraph):
(WebCore::InsertListCommand::unlistifyParagraph):
(WebCore::InsertListCommand::listifyParagraph):
* editing/InsertListCommand.h:
* editing/InsertNodeBeforeCommand.cpp:
(WebCore::InsertNodeBeforeCommand::InsertNodeBeforeCommand):
(WebCore::InsertNodeBeforeCommand::doApply):
(WebCore::InsertNodeBeforeCommand::doUnapply):
(WebCore::InsertNodeBeforeCommand::getNodesInCommand):
* editing/InsertNodeBeforeCommand.h:
(WebCore::InsertNodeBeforeCommand::create):
* editing/InsertParagraphSeparatorCommand.cpp:
(WebCore::InsertParagraphSeparatorCommand::cloneHierarchyUnderNewBlock):
(WebCore::InsertParagraphSeparatorCommand::doApply):
* editing/InsertParagraphSeparatorCommand.h:
* editing/InsertTextCommand.cpp:
(WebCore::InsertTextCommand::positionInsideTextNode):
(WebCore::InsertTextCommand::insertTab):
* editing/ModifySelectionListLevel.cpp:
(WebCore::ModifySelectionListLevelCommand::insertSiblingNodeRangeBefore):
(WebCore::ModifySelectionListLevelCommand::insertSiblingNodeRangeAfter):
(WebCore::ModifySelectionListLevelCommand::appendSiblingNodeRange):
(WebCore::IncreaseSelectionListLevelCommand::doApply):
* editing/RemoveNodePreservingChildrenCommand.cpp:
(WebCore::RemoveNodePreservingChildrenCommand::doApply):
* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::moveNodeOutOfAncestor):
(WebCore::ReplaceSelectionCommand::mergeEndIfNeeded):
(WebCore::ReplaceSelectionCommand::doApply):
(WebCore::ReplaceSelectionCommand::addSpacesForSmartReplace):
(WebCore::ReplaceSelectionCommand::insertAsListItems):
* editing/SimplifyMarkupCommand.cpp:
(WebCore::SimplifyMarkupCommand::pruneSubsequentAncestorsToRemove):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@216074 268f45cc-cd09-0410-ab3c-d52691b4dbfc

24 files changed:
Source/WebCore/ChangeLog
Source/WebCore/editing/AppendNodeCommand.cpp
Source/WebCore/editing/AppendNodeCommand.h
Source/WebCore/editing/ApplyStyleCommand.cpp
Source/WebCore/editing/BreakBlockquoteCommand.cpp
Source/WebCore/editing/CompositeEditCommand.cpp
Source/WebCore/editing/CompositeEditCommand.h
Source/WebCore/editing/CreateLinkCommand.cpp
Source/WebCore/editing/DeleteSelectionCommand.cpp
Source/WebCore/editing/FormatBlockCommand.cpp
Source/WebCore/editing/IndentOutdentCommand.cpp
Source/WebCore/editing/InsertLineBreakCommand.cpp
Source/WebCore/editing/InsertLineBreakCommand.h
Source/WebCore/editing/InsertListCommand.cpp
Source/WebCore/editing/InsertListCommand.h
Source/WebCore/editing/InsertNodeBeforeCommand.cpp
Source/WebCore/editing/InsertNodeBeforeCommand.h
Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp
Source/WebCore/editing/InsertParagraphSeparatorCommand.h
Source/WebCore/editing/InsertTextCommand.cpp
Source/WebCore/editing/ModifySelectionListLevel.cpp
Source/WebCore/editing/RemoveNodePreservingChildrenCommand.cpp
Source/WebCore/editing/ReplaceSelectionCommand.cpp
Source/WebCore/editing/SimplifyMarkupCommand.cpp

index 8815ba7..ee62d1b 100644 (file)
@@ -1,3 +1,87 @@
+2017-05-02  Chris Dumez  <cdumez@apple.com>
+
+        Use PassRefPtr less in editing code
+        https://bugs.webkit.org/show_bug.cgi?id=171534
+
+        Reviewed by Geoffrey Garen.
+
+        Use PassRefPtr less in editing code.
+
+        * editing/AppendNodeCommand.cpp:
+        (WebCore::AppendNodeCommand::AppendNodeCommand):
+        (WebCore::AppendNodeCommand::getNodesInCommand):
+        * editing/AppendNodeCommand.h:
+        (WebCore::AppendNodeCommand::create):
+        * editing/ApplyStyleCommand.cpp:
+        (WebCore::ApplyStyleCommand::surroundNodeRangeWithElement):
+        (WebCore::ApplyStyleCommand::positionToComputeInlineStyleChange):
+        * editing/BreakBlockquoteCommand.cpp:
+        (WebCore::BreakBlockquoteCommand::doApply):
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::insertNodeBefore):
+        (WebCore::CompositeEditCommand::insertNodeAfter):
+        (WebCore::CompositeEditCommand::insertNodeAt):
+        (WebCore::CompositeEditCommand::appendNode):
+        (WebCore::CompositeEditCommand::moveRemainingSiblingsToNewParent):
+        (WebCore::CompositeEditCommand::mergeIdenticalElements):
+        (WebCore::CompositeEditCommand::insertNodeAtTabSpanPosition):
+        (WebCore::CompositeEditCommand::appendBlockPlaceholder):
+        (WebCore::CompositeEditCommand::insertBlockPlaceholder):
+        (WebCore::CompositeEditCommand::addBlockPlaceholderIfNeeded):
+        (WebCore::CompositeEditCommand::insertNewDefaultParagraphElementAt):
+        (WebCore::CompositeEditCommand::cloneParagraphUnderNewElement):
+        (WebCore::CompositeEditCommand::moveParagraphs):
+        * editing/CompositeEditCommand.h:
+        * editing/CreateLinkCommand.cpp:
+        (WebCore::CreateLinkCommand::doApply):
+        * editing/DeleteSelectionCommand.cpp:
+        (WebCore::DeleteSelectionCommand::makeStylingElementsDirectChildrenOfEditableRootToPreventStyleLoss):
+        (WebCore::DeleteSelectionCommand::mergeParagraphs):
+        * editing/FormatBlockCommand.cpp:
+        (WebCore::FormatBlockCommand::formatRange):
+        * editing/IndentOutdentCommand.cpp:
+        (WebCore::IndentOutdentCommand::tryIndentingAsListItem):
+        (WebCore::IndentOutdentCommand::indentIntoBlockquote):
+        (WebCore::IndentOutdentCommand::outdentParagraph):
+        * editing/InsertLineBreakCommand.cpp:
+        (WebCore::InsertLineBreakCommand::doApply):
+        * editing/InsertLineBreakCommand.h:
+        * editing/InsertListCommand.cpp:
+        (WebCore::InsertListCommand::fixOrphanedListChild):
+        (WebCore::InsertListCommand::doApplyForSingleParagraph):
+        (WebCore::InsertListCommand::unlistifyParagraph):
+        (WebCore::InsertListCommand::listifyParagraph):
+        * editing/InsertListCommand.h:
+        * editing/InsertNodeBeforeCommand.cpp:
+        (WebCore::InsertNodeBeforeCommand::InsertNodeBeforeCommand):
+        (WebCore::InsertNodeBeforeCommand::doApply):
+        (WebCore::InsertNodeBeforeCommand::doUnapply):
+        (WebCore::InsertNodeBeforeCommand::getNodesInCommand):
+        * editing/InsertNodeBeforeCommand.h:
+        (WebCore::InsertNodeBeforeCommand::create):
+        * editing/InsertParagraphSeparatorCommand.cpp:
+        (WebCore::InsertParagraphSeparatorCommand::cloneHierarchyUnderNewBlock):
+        (WebCore::InsertParagraphSeparatorCommand::doApply):
+        * editing/InsertParagraphSeparatorCommand.h:
+        * editing/InsertTextCommand.cpp:
+        (WebCore::InsertTextCommand::positionInsideTextNode):
+        (WebCore::InsertTextCommand::insertTab):
+        * editing/ModifySelectionListLevel.cpp:
+        (WebCore::ModifySelectionListLevelCommand::insertSiblingNodeRangeBefore):
+        (WebCore::ModifySelectionListLevelCommand::insertSiblingNodeRangeAfter):
+        (WebCore::ModifySelectionListLevelCommand::appendSiblingNodeRange):
+        (WebCore::IncreaseSelectionListLevelCommand::doApply):
+        * editing/RemoveNodePreservingChildrenCommand.cpp:
+        (WebCore::RemoveNodePreservingChildrenCommand::doApply):
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::moveNodeOutOfAncestor):
+        (WebCore::ReplaceSelectionCommand::mergeEndIfNeeded):
+        (WebCore::ReplaceSelectionCommand::doApply):
+        (WebCore::ReplaceSelectionCommand::addSpacesForSmartReplace):
+        (WebCore::ReplaceSelectionCommand::insertAsListItems):
+        * editing/SimplifyMarkupCommand.cpp:
+        (WebCore::SimplifyMarkupCommand::pruneSubsequentAncestorsToRemove):
+
 2017-05-02  Ben Kelly <ben@wanderview.com>
 
         Set Response.blob() type correctly when body is a ReadableStream.
index 0d70469..2d598fc 100644 (file)
 
 namespace WebCore {
 
-AppendNodeCommand::AppendNodeCommand(PassRefPtr<ContainerNode> parent, Ref<Node>&& node, EditAction editingAction)
+AppendNodeCommand::AppendNodeCommand(Ref<ContainerNode>&& parent, Ref<Node>&& node, EditAction editingAction)
     : SimpleEditCommand(parent->document(), editingAction)
-    , m_parent(parent)
+    , m_parent(WTFMove(parent))
     , m_node(WTFMove(node))
 {
-    ASSERT(m_parent);
     ASSERT(!m_node->parentNode());
-
     ASSERT(m_parent->hasEditableStyle() || !m_parent->renderer());
 }
 
@@ -64,7 +62,7 @@ void AppendNodeCommand::doUnapply()
 #ifndef NDEBUG
 void AppendNodeCommand::getNodesInCommand(HashSet<Node*>& nodes)
 {
-    addNodeAndDescendants(m_parent.get(), nodes);
+    addNodeAndDescendants(m_parent.ptr(), nodes);
     addNodeAndDescendants(m_node.ptr(), nodes);
 }
 #endif
index 5d58be7..3cd9144 100644 (file)
@@ -31,13 +31,13 @@ namespace WebCore {
 
 class AppendNodeCommand : public SimpleEditCommand {
 public:
-    static Ref<AppendNodeCommand> create(PassRefPtr<ContainerNode> parent, Ref<Node>&& node, EditAction editingAction)
+    static Ref<AppendNodeCommand> create(Ref<ContainerNode>&& parent, Ref<Node>&& node, EditAction editingAction)
     {
-        return adoptRef(*new AppendNodeCommand(parent, WTFMove(node), editingAction));
+        return adoptRef(*new AppendNodeCommand(WTFMove(parent), WTFMove(node), editingAction));
     }
 
 private:
-    AppendNodeCommand(PassRefPtr<ContainerNode> parent, Ref<Node>&&, EditAction);
+    AppendNodeCommand(Ref<ContainerNode>&& parent, Ref<Node>&&, EditAction);
 
     void doApply() override;
     void doUnapply() override;
@@ -46,7 +46,7 @@ private:
     void getNodesInCommand(HashSet<Node*>&) override;
 #endif
 
-    RefPtr<ContainerNode> m_parent;
+    Ref<ContainerNode> m_parent;
     Ref<Node> m_node;
 };
 
index ab71b1a..f7a7421 100644 (file)
@@ -1341,14 +1341,14 @@ void ApplyStyleCommand::surroundNodeRangeWithElement(Node& startNode, Node& endN
     Ref<Node> protectedStartNode = startNode;
     Ref<Element> element = WTFMove(elementToInsert);
 
-    insertNodeBefore(element.ptr(), &startNode);
+    insertNodeBefore(element.copyRef(), startNode);
 
     RefPtr<Node> node = &startNode;
     while (node) {
         RefPtr<Node> next = node->nextSibling();
         if (isEditableNode(*node)) {
             removeNode(node);
-            appendNode(node, element.ptr());
+            appendNode(*node, element.copyRef());
         }
         if (node == &endNode)
             break;
@@ -1412,7 +1412,7 @@ Position ApplyStyleCommand::positionToComputeInlineStyleChange(Node& startNode,
     // It's okay to obtain the style at the startNode because we've removed all relevant styles from the current run.
     if (!is<Element>(startNode)) {
         dummyElement = createStyleSpanElement(document());
-        insertNodeAt(dummyElement, positionBeforeNode(&startNode));
+        insertNodeAt(*dummyElement, positionBeforeNode(&startNode));
         return firstPositionInOrBeforeNode(dummyElement.get());
     }
 
index acf6dce..982cc99 100644 (file)
@@ -77,14 +77,14 @@ void BreakBlockquoteCommand::doApply()
     // If the position is at the beginning of the top quoted content, we don't need to break the quote.
     // Instead, insert the break before the blockquote, unless the position is as the end of the the quoted content.
     if (isFirstVisiblePositionInNode(visiblePos, topBlockquote) && !isLastVisPosInNode) {
-        insertNodeBefore(breakNode.copyRef(), topBlockquote);
+        insertNodeBefore(breakNode.copyRef(), *topBlockquote);
         setEndingSelection(VisibleSelection(positionBeforeNode(breakNode.ptr()), DOWNSTREAM, endingSelection().isDirectional()));
         rebalanceWhitespace();   
         return;
     }
     
     // Insert a break after the top blockquote.
-    insertNodeAfter(breakNode.copyRef(), topBlockquote);
+    insertNodeAfter(breakNode.copyRef(), *topBlockquote);
 
     // If we're inserting the break at the end of the quoted content, we don't need to break the quote.
     if (isLastVisPosInNode) {
@@ -131,16 +131,16 @@ void BreakBlockquoteCommand::doApply()
         ancestors.append(node);
     
     // Insert a clone of the top blockquote after the break.
-    RefPtr<Element> clonedBlockquote = downcast<Element>(*topBlockquote).cloneElementWithoutChildren(document());
-    insertNodeAfter(clonedBlockquote.get(), breakNode.copyRef());
+    auto clonedBlockquote = downcast<Element>(*topBlockquote).cloneElementWithoutChildren(document());
+    insertNodeAfter(clonedBlockquote.copyRef(), breakNode);
     
     // Clone startNode's ancestors into the cloned blockquote.
     // On exiting this loop, clonedAncestor is the lowest ancestor
     // that was cloned (i.e. the clone of either ancestors.last()
     // or clonedBlockquote if ancestors is empty).
-    RefPtr<Element> clonedAncestor = clonedBlockquote;
+    RefPtr<Element> clonedAncestor = clonedBlockquote.copyRef();
     for (size_t i = ancestors.size(); i != 0; --i) {
-        RefPtr<Element> clonedChild = ancestors[i - 1]->cloneElementWithoutChildren(document());
+        auto clonedChild = ancestors[i - 1]->cloneElementWithoutChildren(document());
         // Preserve list item numbering in cloned lists.
         if (clonedChild->isElementNode() && clonedChild->hasTagName(olTag)) {
             Node* listChildNode = i > 1 ? ancestors[i - 2].get() : startNode;
@@ -149,11 +149,11 @@ void BreakBlockquoteCommand::doApply()
             while (listChildNode && !listChildNode->hasTagName(liTag))
                 listChildNode = listChildNode->nextSibling();
             if (listChildNode && is<RenderListItem>(listChildNode->renderer()))
-                setNodeAttribute(clonedChild, startAttr, AtomicString::number(downcast<RenderListItem>(*listChildNode->renderer()).value()));
+                setNodeAttribute(clonedChild.ptr(), startAttr, AtomicString::number(downcast<RenderListItem>(*listChildNode->renderer()).value()));
         }
             
-        appendNode(clonedChild.get(), clonedAncestor.get());
-        clonedAncestor = clonedChild;
+        appendNode(clonedChild.copyRef(), clonedAncestor.releaseNonNull());
+        clonedAncestor = WTFMove(clonedChild);
     }
 
     moveRemainingSiblingsToNewParent(startNode, 0, clonedAncestor);
@@ -177,7 +177,7 @@ void BreakBlockquoteCommand::doApply()
     }
     
     // Make sure the cloned block quote renders.
-    addBlockPlaceholderIfNeeded(clonedBlockquote.get());
+    addBlockPlaceholderIfNeeded(clonedBlockquote.ptr());
     
     // Put the selection right before the break.
     setEndingSelection(VisibleSelection(positionBeforeNode(breakNode.ptr()), DOWNSTREAM, endingSelection().isDirectional()));
index e7deb86..ac6a3ec 100644 (file)
@@ -526,29 +526,27 @@ bool CompositeEditCommand::isRemovableBlock(const Node* node)
     return false;
 }
 
-void CompositeEditCommand::insertNodeBefore(PassRefPtr<Node> insertChild, PassRefPtr<Node> refChild, ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable)
+void CompositeEditCommand::insertNodeBefore(Ref<Node>&& insertChild, Node& refChild, ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable)
 {
-    applyCommandToComposite(InsertNodeBeforeCommand::create(insertChild, refChild, shouldAssumeContentIsAlwaysEditable, editingAction()));
+    applyCommandToComposite(InsertNodeBeforeCommand::create(WTFMove(insertChild), refChild, shouldAssumeContentIsAlwaysEditable, editingAction()));
 }
 
-void CompositeEditCommand::insertNodeAfter(PassRefPtr<Node> insertChild, PassRefPtr<Node> refChild)
+void CompositeEditCommand::insertNodeAfter(Ref<Node>&& insertChild, Node& refChild)
 {
-    ASSERT(insertChild);
-    ASSERT(refChild);
-    ContainerNode* parent = refChild->parentNode();
+    ContainerNode* parent = refChild.parentNode();
     if (!parent)
         return;
 
     ASSERT(!parent->isShadowRoot());
-    if (parent->lastChild() == refChild)
-        appendNode(insertChild, parent);
+    if (parent->lastChild() == &refChild)
+        appendNode(WTFMove(insertChild), *parent);
     else {
-        ASSERT(refChild->nextSibling());
-        insertNodeBefore(insertChild, refChild->nextSibling());
+        ASSERT(refChild.nextSibling());
+        insertNodeBefore(WTFMove(insertChild), *refChild.nextSibling());
     }
 }
 
-void CompositeEditCommand::insertNodeAt(PassRefPtr<Node> insertChild, const Position& editingPosition)
+void CompositeEditCommand::insertNodeAt(Ref<Node>&& insertChild, const Position& editingPosition)
 {
     ASSERT(isEditablePosition(editingPosition));
     // For editing positions like [table, 0], insert before the table,
@@ -562,27 +560,26 @@ void CompositeEditCommand::insertNodeAt(PassRefPtr<Node> insertChild, const Posi
         for (int i = 0; child && i < offset; i++)
             child = child->nextSibling();
         if (child)
-            insertNodeBefore(insertChild, child);
+            insertNodeBefore(WTFMove(insertChild), *child);
         else
-            appendNode(insertChild, downcast<ContainerNode>(refChild));
+            appendNode(WTFMove(insertChild), downcast<ContainerNode>(*refChild));
     } else if (caretMinOffset(*refChild) >= offset)
-        insertNodeBefore(insertChild, refChild);
+        insertNodeBefore(WTFMove(insertChild), *refChild);
     else if (is<Text>(*refChild) && caretMaxOffset(*refChild) > offset) {
         splitTextNode(downcast<Text>(refChild), offset);
 
         // Mutation events (bug 22634) from the text node insertion may have removed the refChild
         if (!refChild->isConnected())
             return;
-        insertNodeBefore(insertChild, refChild);
+        insertNodeBefore(WTFMove(insertChild), *refChild);
     } else
-        insertNodeAfter(insertChild, refChild);
+        insertNodeAfter(WTFMove(insertChild), *refChild);
 }
 
-void CompositeEditCommand::appendNode(PassRefPtr<Node> node, PassRefPtr<ContainerNode> parent)
+void CompositeEditCommand::appendNode(Ref<Node>&& node, Ref<ContainerNode>&& parent)
 {
-    ASSERT(canHaveChildrenForEditing(*parent));
-    ASSERT(node);
-    applyCommandToComposite(AppendNodeCommand::create(parent, *node, editingAction()));
+    ASSERT(canHaveChildrenForEditing(parent));
+    applyCommandToComposite(AppendNodeCommand::create(WTFMove(parent), WTFMove(node), editingAction()));
 }
 
 void CompositeEditCommand::removeChildrenInRange(PassRefPtr<Node> node, unsigned from, unsigned to)
@@ -625,7 +622,7 @@ void CompositeEditCommand::moveRemainingSiblingsToNewParent(Node* node, Node* pa
 
     for (auto& nodeToRemove : nodesToRemove) {
         removeNode(nodeToRemove.ptr());
-        appendNode(nodeToRemove.ptr(), newParent);
+        appendNode(WTFMove(nodeToRemove), *newParent);
     }
 }
 
@@ -675,7 +672,7 @@ void CompositeEditCommand::mergeIdenticalElements(PassRefPtr<Element> prpFirst,
     ASSERT(!first->isDescendantOf(second.get()) && second != first);
     if (first->nextSibling() != second) {
         removeNode(second);
-        insertNodeAfter(second, first);
+        insertNodeAfter(*second, *first);
     }
     applyCommandToComposite(MergeIdenticalElementsCommand::create(first, second));
 }
@@ -817,10 +814,10 @@ Position CompositeEditCommand::positionOutsideTabSpan(const Position& position)
     return positionInParentBeforeNode(tabSpan);
 }
 
-void CompositeEditCommand::insertNodeAtTabSpanPosition(PassRefPtr<Node> node, const Position& pos)
+void CompositeEditCommand::insertNodeAtTabSpanPosition(Ref<Node>&& node, const Position& pos)
 {
     // insert node before, after, or at split of tab span
-    insertNodeAt(node, positionOutsideTabSpan(pos));
+    insertNodeAt(WTFMove(node), positionOutsideTabSpan(pos));
 }
 
 static EditAction deleteSelectionEditingActionForEditingAction(EditAction editingAction)
@@ -1095,19 +1092,16 @@ void CompositeEditCommand::deleteInsignificantTextDownstream(const Position& pos
     deleteInsignificantText(pos, end);
 }
 
-RefPtr<Node> CompositeEditCommand::appendBlockPlaceholder(PassRefPtr<Element> container)
+Ref<Element> CompositeEditCommand::appendBlockPlaceholder(Ref<Element>&& container)
 {
-    if (!container)
-        return nullptr;
-
     document().updateLayoutIgnorePendingStylesheets();
     
     // Should assert isBlockFlow || isInlineFlow when deletion improves. See 4244964.
     ASSERT(container->renderer());
 
     auto placeholder = createBlockPlaceholderElement(document());
-    appendNode(placeholder.ptr(), container);
-    return WTFMove(placeholder);
+    appendNode(placeholder.copyRef(), WTFMove(container));
+    return placeholder;
 }
 
 RefPtr<Node> CompositeEditCommand::insertBlockPlaceholder(const Position& pos)
@@ -1119,7 +1113,7 @@ RefPtr<Node> CompositeEditCommand::insertBlockPlaceholder(const Position& pos)
     ASSERT(pos.deprecatedNode()->renderer());
 
     auto placeholder = createBlockPlaceholderElement(document());
-    insertNodeAt(placeholder.ptr(), pos);
+    insertNodeAt(placeholder.copyRef(), pos);
     return WTFMove(placeholder);
 }
 
@@ -1137,7 +1131,7 @@ RefPtr<Node> CompositeEditCommand::addBlockPlaceholderIfNeeded(Element* containe
     // Append the placeholder to make sure it follows any unrendered blocks.
     auto& blockFlow = downcast<RenderBlockFlow>(*renderer);
     if (!blockFlow.height() || (blockFlow.isListItem() && !blockFlow.firstChild()))
-        return appendBlockPlaceholder(container);
+        return appendBlockPlaceholder(*container);
 
     return nullptr;
 }
@@ -1160,7 +1154,7 @@ Ref<HTMLElement> CompositeEditCommand::insertNewDefaultParagraphElementAt(const
 {
     auto paragraphElement = createDefaultParagraphElement(document());
     paragraphElement->appendChild(HTMLBRElement::create(document()));
-    insertNodeAt(paragraphElement.ptr(), position);
+    insertNodeAt(paragraphElement.copyRef(), position);
     return paragraphElement;
 }
 
@@ -1256,7 +1250,7 @@ void CompositeEditCommand::cloneParagraphUnderNewElement(const Position& start,
         lastNode = blockElement;
     } else {
         lastNode = outerNode->cloneNode(isRenderedTable(outerNode.get()));
-        appendNode(lastNode, blockElement);
+        appendNode(*lastNode, *blockElement);
     }
 
     if (start.deprecatedNode() != outerNode && lastNode->isElementNode() && start.anchorNode()->isDescendantOf(outerNode.get())) {
@@ -1271,7 +1265,7 @@ void CompositeEditCommand::cloneParagraphUnderNewElement(const Position& start,
         for (size_t i = ancestors.size(); i != 0; --i) {
             Node* item = ancestors[i - 1].get();
             auto child = item->cloneNode(isRenderedTable(item));
-            appendNode(child.ptr(), downcast<Element>(lastNode.get()));
+            appendNode(child.copyRef(), downcast<Element>(*lastNode));
             lastNode = WTFMove(child);
         }
     }
@@ -1298,7 +1292,7 @@ void CompositeEditCommand::cloneParagraphUnderNewElement(const Position& start,
             }
 
             auto clonedNode = node->cloneNode(true);
-            insertNodeAfter(clonedNode.ptr(), lastNode);
+            insertNodeAfter(clonedNode.copyRef(), *lastNode);
             lastNode = WTFMove(clonedNode);
             if (node == end.deprecatedNode() || end.deprecatedNode()->isDescendantOf(*node))
                 break;
@@ -1591,16 +1585,16 @@ bool CompositeEditCommand::breakOutOfEmptyListItem()
         // If emptyListItem is followed by other list item or nested list, then insert newBlock before the list node.
         // Because we have splitted the element, emptyListItem is the first element in the list node.
         // i.e. insert newBlock before ul or ol whose first element is emptyListItem
-        insertNodeBefore(newBlock, listNode);
+        insertNodeBefore(*newBlock, *listNode);
         removeNode(emptyListItem);
     } else {
         // When emptyListItem does not follow any list item or nested list, insert newBlock after the enclosing list node.
         // Remove the enclosing node if emptyListItem is the only child; otherwise just remove emptyListItem.
-        insertNodeAfter(newBlock, listNode);
+        insertNodeAfter(*newBlock, *listNode);
         removeNode(isListItem(previousListNode.get()) || isListHTMLElement(previousListNode.get()) ? emptyListItem : listNode);
     }
 
-    appendBlockPlaceholder(newBlock);
+    appendBlockPlaceholder(*newBlock);
     setEndingSelection(VisibleSelection(firstPositionInNode(newBlock.get()), DOWNSTREAM, endingSelection().isDirectional()));
 
     style->prepareToApplyAt(endingSelection().start());
@@ -1630,15 +1624,16 @@ bool CompositeEditCommand::breakOutOfEmptyMailBlockquotedParagraph()
     if (enclosingNodeOfType(previous.deepEquivalent(), &isMailBlockquote))
         return false;
     
-    RefPtr<Node> br = HTMLBRElement::create(document());
+    auto br = HTMLBRElement::create(document());
+    auto* brPtr = br.ptr();
     // We want to replace this quoted paragraph with an unquoted one, so insert a br
     // to hold the caret before the highest blockquote.
-    insertNodeBefore(br, highestBlockquote);
-    VisiblePosition atBR(positionBeforeNode(br.get()));
+    insertNodeBefore(WTFMove(br), *highestBlockquote);
+    VisiblePosition atBR(positionBeforeNode(brPtr));
     // If the br we inserted collapsed, for example foo<br><blockquote>...</blockquote>, insert
     // a second one.
     if (!isStartOfParagraph(atBR))
-        insertNodeBefore(HTMLBRElement::create(document()), br);
+        insertNodeBefore(HTMLBRElement::create(document()), *brPtr);
     setEndingSelection(VisibleSelection(atBR, endingSelection().isDirectional()));
     
     // If this is an empty paragraph there must be a line break here.
index 37af01e..ca49744 100644 (file)
@@ -133,7 +133,7 @@ protected:
     //
     // sugary-sweet convenience functions to help create and apply edit commands in composite commands
     //
-    void appendNode(PassRefPtr<Node>, PassRefPtr<ContainerNode> parent);
+    void appendNode(Ref<Node>&&, Ref<ContainerNode>&& parent);
     void applyCommandToComposite(Ref<EditCommand>&&);
     void applyCommandToComposite(Ref<CompositeEditCommand>&&, const VisibleSelection&);
     void applyStyle(const EditingStyle*, EditAction = EditActionChangeAttributes);
@@ -145,10 +145,10 @@ protected:
     virtual void deleteTextFromNode(PassRefPtr<Text>, unsigned offset, unsigned count);
     void inputText(const String&, bool selectInsertedText = false);
     bool isRemovableBlock(const Node*);
-    void insertNodeAfter(PassRefPtr<Node>, PassRefPtr<Node> refChild);
-    void insertNodeAt(PassRefPtr<Node>, const Position&);
-    void insertNodeAtTabSpanPosition(PassRefPtr<Node>, const Position&);
-    void insertNodeBefore(PassRefPtr<Node>, PassRefPtr<Node> refChild, ShouldAssumeContentIsAlwaysEditable = DoNotAssumeContentIsAlwaysEditable);
+    void insertNodeAfter(Ref<Node>&&, Node& refChild);
+    void insertNodeAt(Ref<Node>&&, const Position&);
+    void insertNodeAtTabSpanPosition(Ref<Node>&&, const Position&);
+    void insertNodeBefore(Ref<Node>&&, Node& refChild, ShouldAssumeContentIsAlwaysEditable = DoNotAssumeContentIsAlwaysEditable);
     void insertParagraphSeparator(bool useDefaultParagraphElement = false, bool pasteBlockqutoeIntoUnquotedArea = false);
     void insertLineBreak();
     void insertTextIntoNode(PassRefPtr<Text>, unsigned offset, const String& text);
@@ -183,7 +183,7 @@ protected:
     void deleteInsignificantText(const Position& start, const Position& end);
     void deleteInsignificantTextDownstream(const Position&);
 
-    RefPtr<Node> appendBlockPlaceholder(PassRefPtr<Element>);
+    Ref<Element> appendBlockPlaceholder(Ref<Element>&&);
     RefPtr<Node> insertBlockPlaceholder(const Position&);
     RefPtr<Node> addBlockPlaceholderIfNeeded(Element*);
     void removePlaceholderAt(const Position&);
index 45397ca..4213471 100644 (file)
@@ -49,9 +49,8 @@ void CreateLinkCommand::doApply()
     if (endingSelection().isRange())
         applyStyledElement(WTFMove(anchorElement));
     else {
-        insertNodeAt(anchorElement.ptr(), endingSelection().start());
-        auto textNode = Text::create(document(), m_url);
-        appendNode(WTFMove(textNode), anchorElement.ptr());
+        insertNodeAt(anchorElement.copyRef(), endingSelection().start());
+        appendNode(Text::create(document(), m_url), anchorElement.copyRef());
         setEndingSelection(VisibleSelection(positionInParentBeforeNode(anchorElement.ptr()), positionInParentAfterNode(anchorElement.ptr()), DOWNSTREAM, endingSelection().isDirectional()));
     }
 }
index 5b74cf8..7a75e69 100644 (file)
@@ -466,7 +466,7 @@ void DeleteSelectionCommand::makeStylingElementsDirectChildrenOfEditableRootToPr
             RefPtr<ContainerNode> rootEditableElement = node->rootEditableElement();
             if (rootEditableElement) {
                 removeNode(node);
-                appendNode(node, rootEditableElement);
+                appendNode(*node, *rootEditableElement);
             }
         }
         node = nextNode;
@@ -657,7 +657,7 @@ void DeleteSelectionCommand::mergeParagraphs()
     
     // We need to merge into m_upstreamStart's block, but it's been emptied out and collapsed by deletion.
     if (!mergeDestination.deepEquivalent().deprecatedNode() || !mergeDestination.deepEquivalent().deprecatedNode()->isDescendantOf(enclosingBlock(m_upstreamStart.containerNode())) || m_startsAtEmptyLine) {
-        insertNodeAt(HTMLBRElement::create(document()).ptr(), m_upstreamStart);
+        insertNodeAt(HTMLBRElement::create(document()), m_upstreamStart);
         mergeDestination = VisiblePosition(m_upstreamStart);
     }
     
index 3c77079..1974a3e 100644 (file)
@@ -86,7 +86,7 @@ void FormatBlockCommand::formatRange(const Position& start, const Position& end,
         // Create a new blockquote and insert it as a child of the root editable element. We accomplish
         // this by splitting all parents of the current paragraph up to that point.
         blockNode = createBlockElement();
-        insertNodeBefore(blockNode, nodeAfterInsertionPosition);
+        insertNodeBefore(*blockNode, *nodeAfterInsertionPosition);
     }
 
     Position lastParagraphInBlockNode = blockNode->lastChild() ? positionAfterNode(blockNode->lastChild()) : Position();
index da4fd51..f4d4cb3 100644 (file)
@@ -78,7 +78,7 @@ bool IndentOutdentCommand::tryIndentingAsListItem(const Position& start, const P
         newList = HTMLUListElement::create(document());
     else
         newList = HTMLOListElement::create(document());
-    insertNodeBefore(newList, selectedListItem);
+    insertNodeBefore(*newList, *selectedListItem);
 
     moveParagraphWithClones(start, end, newList.get(), selectedListItem.get());
 
@@ -113,9 +113,9 @@ void IndentOutdentCommand::indentIntoBlockquote(const Position& start, const Pos
         // this by splitting all parents of the current paragraph up to that point.
         targetBlockquote = createBlockElement();
         if (outerBlock == nodeToSplitTo)
-            insertNodeAt(targetBlockquote, start);
+            insertNodeAt(*targetBlockquote, start);
         else
-            insertNodeBefore(targetBlockquote, outerBlock);
+            insertNodeBefore(*targetBlockquote, *outerBlock);
         startOfContents = positionInParentAfterNode(targetBlockquote.get());
     }
 
@@ -186,8 +186,9 @@ void IndentOutdentCommand::outdentParagraph()
         splitElement(enclosingNode, highestInlineNode ? highestInlineNode : visibleStartOfParagraph.deepEquivalent().deprecatedNode());
     }
     auto placeholder = HTMLBRElement::create(document());
-    insertNodeBefore(placeholder.copyRef(), splitBlockquoteNode);
-    moveParagraph(startOfParagraph(visibleStartOfParagraph), endOfParagraph(visibleEndOfParagraph), positionBeforeNode(placeholder.ptr()), true);
+    auto* placeholderPtr = placeholder.ptr();
+    insertNodeBefore(WTFMove(placeholder), *splitBlockquoteNode);
+    moveParagraph(startOfParagraph(visibleStartOfParagraph), endOfParagraph(visibleEndOfParagraph), positionBeforeNode(placeholderPtr), true);
 }
 
 // FIXME: We should merge this function with ApplyBlockElementCommand::formatSelection
index 59176d9..add2cdf 100644 (file)
@@ -53,30 +53,6 @@ bool InsertLineBreakCommand::preservesTypingStyle() const
     return true;
 }
 
-void InsertLineBreakCommand::insertNodeAfterPosition(Node* node, const Position& position)
-{
-    // Insert the BR after the caret position. In the case the
-    // position is a block, do an append. We don't want to insert
-    // the BR *after* the block.
-    auto* element = deprecatedEnclosingBlockFlowElement(position.deprecatedNode());
-    if (element == position.deprecatedNode())
-        appendNode(node, element);
-    else
-        insertNodeAfter(node, position.deprecatedNode());
-}
-
-void InsertLineBreakCommand::insertNodeBeforePosition(Node* node, const Position& position)
-{
-    // Insert the BR after the caret position. In the case the
-    // position is a block, do an append. We don't want to insert
-    // the BR *before* the block.
-    auto* element = deprecatedEnclosingBlockFlowElement(position.deprecatedNode());
-    if (element == position.deprecatedNode())
-        appendNode(node, element);
-    else
-        insertNodeBefore(node, position.deprecatedNode());
-}
-
 // Whether we should insert a break element or a '\n'.
 bool InsertLineBreakCommand::shouldUseBreakElement(const Position& position)
 {
@@ -116,31 +92,31 @@ void InsertLineBreakCommand::doApply()
     if (isEndOfParagraph(caret) && !lineBreakExistsAtVisiblePosition(caret)) {
         bool needExtraLineBreak = !is<HTMLHRElement>(*position.deprecatedNode()) && !is<HTMLTableElement>(*position.deprecatedNode());
         
-        insertNodeAt(nodeToInsert.get(), position);
+        insertNodeAt(*nodeToInsert, position);
         
         if (needExtraLineBreak)
-            insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert);
+            insertNodeBefore(nodeToInsert->cloneNode(false), *nodeToInsert);
         
         VisiblePosition endingPosition(positionBeforeNode(nodeToInsert.get()));
         setEndingSelection(VisibleSelection(endingPosition, endingSelection().isDirectional()));
     } else if (position.deprecatedEditingOffset() <= caretMinOffset(*position.deprecatedNode())) {
-        insertNodeAt(nodeToInsert.get(), position);
+        insertNodeAt(*nodeToInsert, position);
         
         // Insert an extra br or '\n' if the just inserted one collapsed.
         if (!isStartOfParagraph(positionBeforeNode(nodeToInsert.get())))
-            insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert.get());
+            insertNodeBefore(nodeToInsert->cloneNode(false), *nodeToInsert);
         
         setEndingSelection(VisibleSelection(positionInParentAfterNode(nodeToInsert.get()), DOWNSTREAM, endingSelection().isDirectional()));
     // If we're inserting after all of the rendered text in a text node, or into a non-text node,
     // a simple insertion is sufficient.
     } else if (position.deprecatedEditingOffset() >= caretMaxOffset(*position.deprecatedNode()) || !is<Text>(*position.deprecatedNode())) {
-        insertNodeAt(nodeToInsert.get(), position);
+        insertNodeAt(*nodeToInsert, position);
         setEndingSelection(VisibleSelection(positionInParentAfterNode(nodeToInsert.get()), DOWNSTREAM, endingSelection().isDirectional()));
     } else if (is<Text>(*position.deprecatedNode())) {
         // Split a text node
         Text& textNode = downcast<Text>(*position.deprecatedNode());
         splitTextNode(&textNode, position.deprecatedEditingOffset());
-        insertNodeBefore(nodeToInsert, &textNode);
+        insertNodeBefore(*nodeToInsert, textNode);
         Position endingPosition = firstPositionInNode(&textNode);
         
         // Handle whitespace that occurs after the split
@@ -154,9 +130,10 @@ void InsertLineBreakCommand::doApply()
             if (textNode.isConnected())
                 insertTextIntoNode(&textNode, 0, nonBreakingSpaceString());
             else {
-                RefPtr<Text> nbspNode = document().createTextNode(nonBreakingSpaceString());
-                insertNodeAt(nbspNode.get(), positionBeforeTextNode);
-                endingPosition = firstPositionInNode(nbspNode.get());
+                auto nbspNode = document().createTextNode(nonBreakingSpaceString());
+                auto* nbspNodePtr = nbspNode.ptr();
+                insertNodeAt(WTFMove(nbspNode), positionBeforeTextNode);
+                endingPosition = firstPositionInNode(nbspNodePtr);
             }
         }
         
index 2b3d1bf..85f91c4 100644 (file)
@@ -43,8 +43,6 @@ private:
 
     bool preservesTypingStyle() const override;
 
-    void insertNodeAfterPosition(Node*, const Position&);
-    void insertNodeBeforePosition(Node*, const Position&);
     bool shouldUseBreakElement(const Position&);
 };
 
index 9e6cdb0..3ab9665 100644 (file)
@@ -54,11 +54,11 @@ RefPtr<HTMLElement> InsertListCommand::insertList(Document& document, Type type)
     return insertCommand->m_listElement;
 }
 
-HTMLElement* InsertListCommand::fixOrphanedListChild(Node* node)
+HTMLElement* InsertListCommand::fixOrphanedListChild(Node& node)
 {
     auto listElement = HTMLUListElement::create(document());
     insertNodeBefore(listElement.copyRef(), node);
-    removeNode(node);
+    removeNode(&node);
     appendNode(node, listElement.copyRef());
     m_listElement = listElement.copyRef();
     return listElement.ptr();
@@ -209,7 +209,7 @@ void InsertListCommand::doApplyForSingleParagraph(bool forceCreateList, const HT
         // Remove the list chlild.
         RefPtr<HTMLElement> listNode = enclosingList(listChildNode);
         if (!listNode) {
-            listNode = fixOrphanedListChild(listChildNode);
+            listNode = fixOrphanedListChild(*listChildNode);
             listNode = mergeWithNeighboringLists(listNode);
         }
         if (!listNode->hasTagName(listTag)) {
@@ -227,7 +227,7 @@ void InsertListCommand::doApplyForSingleParagraph(bool forceCreateList, const HT
             bool rangeEndIsInList = visiblePositionAfterNode(*listNode) == currentSelection->endPosition();
 
             RefPtr<HTMLElement> newList = createHTMLElement(document(), listTag);
-            insertNodeBefore(newList, listNode);
+            insertNodeBefore(*newList, *listNode);
 
             auto* firstChildInList = enclosingListChild(VisiblePosition(firstPositionInNode(listNode.get())).deepEquivalent().deprecatedNode(), listNode.get());
             Node* outerBlock = firstChildInList && isBlockFlowElement(*firstChildInList) ? firstChildInList : listNode.get();
@@ -283,13 +283,13 @@ void InsertListCommand::unlistifyParagraph(const VisiblePosition& originalStart,
     }
     // When removing a list, we must always create a placeholder to act as a point of insertion
     // for the list content being removed.
-    RefPtr<Element> placeholder = HTMLBRElement::create(document());
-    RefPtr<Element> nodeToInsert = placeholder;
+    auto placeholder = HTMLBRElement::create(document());
+    RefPtr<Element> nodeToInsert = placeholder.copyRef();
     // If the content of the list item will be moved into another list, put it in a list item
     // so that we don't create an orphaned list child.
     if (enclosingList(listNode)) {
         nodeToInsert = HTMLLIElement::create(document());
-        appendNode(placeholdernodeToInsert);
+        appendNode(placeholder.copyRef(), *nodeToInsert);
     }
 
     if (nextListChild && previousListChild) {
@@ -301,7 +301,7 @@ void InsertListCommand::unlistifyParagraph(const VisiblePosition& originalStart,
         // listChildNode below in moveParagraphs, previousListChild will be removed along with it if it is 
         // unrendered. But we ought to remove nextListChild too, if it is unrendered.
         splitElement(listNode, splitTreeToNode(nextListChild, listNode));
-        insertNodeBefore(nodeToInsertlistNode);
+        insertNodeBefore(nodeToInsert.releaseNonNull(), *listNode);
     } else if (nextListChild || listChildNode->parentNode() != listNode) {
         // Just because listChildNode has no previousListChild doesn't mean there isn't any content
         // in listNode that comes before listChildNode, as listChildNode could have ancestors
@@ -309,11 +309,11 @@ void InsertListCommand::unlistifyParagraph(const VisiblePosition& originalStart,
         // where we're about to move listChildNode to.
         if (listChildNode->parentNode() != listNode)
             splitElement(listNode, splitTreeToNode(listChildNode, listNode).get());
-        insertNodeBefore(nodeToInsertlistNode);
+        insertNodeBefore(nodeToInsert.releaseNonNull(), *listNode);
     } else
-        insertNodeAfter(nodeToInsertlistNode);
+        insertNodeAfter(nodeToInsert.releaseNonNull(), *listNode);
 
-    VisiblePosition insertionPoint = VisiblePosition(positionBeforeNode(placeholder.get()));
+    VisiblePosition insertionPoint = VisiblePosition(positionBeforeNode(placeholder.ptr()));
     moveParagraphs(start, end, insertionPoint, true);
 }
 
@@ -354,13 +354,13 @@ RefPtr<HTMLElement> InsertListCommand::listifyParagraph(const VisiblePosition& o
     Element* nextList = adjacentEnclosingList(start.deepEquivalent(), end.next(CannotCrossEditingBoundary), listTag);
     RefPtr<HTMLElement> listElement;
     if (previousList)
-        appendNode(WTFMove(listItemElement), previousList);
+        appendNode(WTFMove(listItemElement), *previousList);
     else if (nextList)
         insertNodeAt(WTFMove(listItemElement), positionBeforeNode(nextList));
     else {
         // Create the list.
         listElement = createHTMLElement(document(), listTag);
-        appendNode(WTFMove(listItemElement), listElement);
+        appendNode(WTFMove(listItemElement), *listElement);
 
         if (start == end && isBlock(start.deepEquivalent().deprecatedNode())) {
             // Inserting the list into an empty paragraph that isn't held open 
@@ -382,7 +382,7 @@ RefPtr<HTMLElement> InsertListCommand::listifyParagraph(const VisiblePosition& o
         if (listChild && listChild->hasTagName(liTag))
             insertionPos = positionInParentBeforeNode(listChild);
 
-        insertNodeAt(listElement, insertionPos);
+        insertNodeAt(*listElement, insertionPos);
 
         // We inserted the list at the start of the content we're about to move
         // Update the start of content, so we don't try to move the list into itself.  bug 19066
index 16c3370..d6bab1f 100644 (file)
@@ -51,7 +51,7 @@ private:
     void doApply() final;
     EditAction editingAction() const final;
 
-    HTMLElement* fixOrphanedListChild(Node*);
+    HTMLElement* fixOrphanedListChild(Node&);
     bool selectionHasListOfType(const VisibleSelection& selection, const QualifiedName&);
     RefPtr<HTMLElement> mergeWithNeighboringLists(PassRefPtr<HTMLElement>);
     void doApplyForSingleParagraph(bool forceCreateList, const HTMLQualifiedName&, Range* currentSelection);
index aca9da3..f0435e7 100644 (file)
 
 namespace WebCore {
 
-InsertNodeBeforeCommand::InsertNodeBeforeCommand(RefPtr<Node>&& insertChild, RefPtr<Node>&& refChild, ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable, EditAction editingAction)
-    : SimpleEditCommand(refChild->document(), editingAction)
-    , m_insertChild(insertChild)
+InsertNodeBeforeCommand::InsertNodeBeforeCommand(Ref<Node>&& insertChild, Node& refChild, ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable, EditAction editingAction)
+    : SimpleEditCommand(refChild.document(), editingAction)
+    , m_insertChild(WTFMove(insertChild))
     , m_refChild(refChild)
     , m_shouldAssumeContentIsAlwaysEditable(shouldAssumeContentIsAlwaysEditable)
 {
-    ASSERT(m_insertChild);
     ASSERT(!m_insertChild->parentNode());
-    ASSERT(m_refChild);
     ASSERT(m_refChild->parentNode());
 
     ASSERT(m_refChild->parentNode()->hasEditableStyle() || !m_refChild->parentNode()->renderer());
@@ -54,12 +52,12 @@ void InsertNodeBeforeCommand::doApply()
         return;
     ASSERT(isEditableNode(*parent));
 
-    parent->insertBefore(*m_insertChild, m_refChild.get());
+    parent->insertBefore(m_insertChild, m_refChild.ptr());
 }
 
 void InsertNodeBeforeCommand::doUnapply()
 {
-    if (!isEditableNode(*m_insertChild))
+    if (!isEditableNode(m_insertChild))
         return;
 
     m_insertChild->remove();
@@ -68,8 +66,8 @@ void InsertNodeBeforeCommand::doUnapply()
 #ifndef NDEBUG
 void InsertNodeBeforeCommand::getNodesInCommand(HashSet<Node*>& nodes)
 {
-    addNodeAndDescendants(m_insertChild.get(), nodes);
-    addNodeAndDescendants(m_refChild.get(), nodes);
+    addNodeAndDescendants(m_insertChild.ptr(), nodes);
+    addNodeAndDescendants(m_refChild.ptr(), nodes);
 }
 #endif
 
index 48eab3d..c420596 100644 (file)
@@ -31,14 +31,14 @@ namespace WebCore {
 
 class InsertNodeBeforeCommand : public SimpleEditCommand {
 public:
-    static Ref<InsertNodeBeforeCommand> create(RefPtr<Node>&& childToInsert, RefPtr<Node>&& childToInsertBefore,
+    static Ref<InsertNodeBeforeCommand> create(Ref<Node>&& childToInsert, Node& childToInsertBefore,
         ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable, EditAction editingAction = EditActionInsert)
     {
-        return adoptRef(*new InsertNodeBeforeCommand(WTFMove(childToInsert), WTFMove(childToInsertBefore), shouldAssumeContentIsAlwaysEditable, editingAction));
+        return adoptRef(*new InsertNodeBeforeCommand(WTFMove(childToInsert), childToInsertBefore, shouldAssumeContentIsAlwaysEditable, editingAction));
     }
 
 protected:
-    InsertNodeBeforeCommand(RefPtr<Node>&& childToInsert, RefPtr<Node>&& childToInsertBefore, ShouldAssumeContentIsAlwaysEditable, EditAction);
+    InsertNodeBeforeCommand(Ref<Node>&& childToInsert, Node& childToInsertBefore, ShouldAssumeContentIsAlwaysEditable, EditAction);
 
 private:
     void doApply() override;
@@ -48,8 +48,8 @@ private:
     void getNodesInCommand(HashSet<Node*>&) override;
 #endif
 
-    RefPtr<Node> m_insertChild;
-    RefPtr<Node> m_refChild;
+    Ref<Node> m_insertChild;
+    Ref<Node> m_refChild;
     ShouldAssumeContentIsAlwaysEditable m_shouldAssumeContentIsAlwaysEditable;
 };
 
index 518c988..20ad6a8 100644 (file)
@@ -131,19 +131,19 @@ void InsertParagraphSeparatorCommand::getAncestorsInsideBlock(const Node* insert
     }
 }
 
-RefPtr<Element> InsertParagraphSeparatorCommand::cloneHierarchyUnderNewBlock(const Vector<RefPtr<Element>>& ancestors, PassRefPtr<Element> blockToInsert)
+Ref<Element> InsertParagraphSeparatorCommand::cloneHierarchyUnderNewBlock(const Vector<RefPtr<Element>>& ancestors, Ref<Element>&& blockToInsert)
 {
     // Make clones of ancestors in between the start node and the start block.
-    RefPtr<Element> parent = blockToInsert;
+    RefPtr<Element> parent = WTFMove(blockToInsert);
     for (size_t i = ancestors.size(); i != 0; --i) {
         auto child = ancestors[i - 1]->cloneElementWithoutChildren(document());
         // It should always be okay to remove id from the cloned elements, since the originals are not deleted.
         child->removeAttribute(idAttr);
-        appendNode(child.ptr(), parent);
+        appendNode(child.copyRef(), parent.releaseNonNull());
         parent = WTFMove(child);
     }
     
-    return parent;
+    return parent.releaseNonNull();
 }
 
 void InsertParagraphSeparatorCommand::doApply()
@@ -217,11 +217,11 @@ void InsertParagraphSeparatorCommand::doApply()
             if (isFirstInBlock && !lineBreakExistsAtVisiblePosition(visiblePos)) {
                 // The block is empty.  Create an empty block to
                 // represent the paragraph that we're leaving.
-                RefPtr<Element> extraBlock = createDefaultParagraphElement(document());
-                appendNode(extraBlockstartBlock);
-                appendBlockPlaceholder(extraBlock);
+                auto extraBlock = createDefaultParagraphElement(document());
+                appendNode(extraBlock.copyRef(), *startBlock);
+                appendBlockPlaceholder(WTFMove(extraBlock));
             }
-            appendNode(blockToInsert, startBlock);
+            appendNode(*blockToInsert, *startBlock);
         } else {
             // We can get here if we pasted a copied portion of a blockquote with a newline at the end and are trying to paste it
             // into an unquoted area. We then don't want the newline within the blockquote or else it will also be quoted.
@@ -235,18 +235,19 @@ void InsertParagraphSeparatorCommand::doApply()
             Element* siblingNode = startBlock.get();
             if (blockToInsert->hasTagName(divTag))
                 siblingNode = highestVisuallyEquivalentDivBelowRoot(startBlock.get());
-            insertNodeAfter(blockToInsert, siblingNode);
+            insertNodeAfter(*blockToInsert, *siblingNode);
         }
 
         // Recreate the same structure in the new paragraph.
         
         Vector<RefPtr<Element>> ancestors;
         getAncestorsInsideBlock(positionOutsideTabSpan(insertionPosition).deprecatedNode(), startBlock.get(), ancestors);      
-        RefPtr<Element> parent = cloneHierarchyUnderNewBlock(ancestors, blockToInsert);
+        auto parent = cloneHierarchyUnderNewBlock(ancestors, *blockToInsert);
+        auto* parentPtr = parent.ptr();
         
-        appendBlockPlaceholder(parent);
+        appendBlockPlaceholder(WTFMove(parent));
 
-        setEndingSelection(VisibleSelection(firstPositionInNode(parent.get()), DOWNSTREAM, endingSelection().isDirectional()));
+        setEndingSelection(VisibleSelection(firstPositionInNode(parentPtr), DOWNSTREAM, endingSelection().isDirectional()));
         return;
     }
     
@@ -275,14 +276,14 @@ void InsertParagraphSeparatorCommand::doApply()
         // find ending selection position easily before inserting the paragraph
         insertionPosition = insertionPosition.downstream();
         
-        insertNodeBefore(blockToInsert, refNode);
+        insertNodeBefore(*blockToInsert, *refNode);
 
         // Recreate the same structure in the new paragraph.
 
         Vector<RefPtr<Element>> ancestors;
         getAncestorsInsideBlock(positionAvoidingSpecialElementBoundary(positionOutsideTabSpan(insertionPosition)).deprecatedNode(), startBlock.get(), ancestors);
         
-        appendBlockPlaceholder(cloneHierarchyUnderNewBlock(ancestors, blockToInsert));
+        appendBlockPlaceholder(cloneHierarchyUnderNewBlock(ancestors, *blockToInsert));
         
         // In this case, we need to set the new ending selection.
         setEndingSelection(VisibleSelection(insertionPosition, DOWNSTREAM, endingSelection().isDirectional()));
@@ -297,9 +298,10 @@ void InsertParagraphSeparatorCommand::doApply()
     // it if visiblePos is at the start of a paragraph so that the 
     // content will move down a line.
     if (isStartOfParagraph(visiblePos)) {
-        RefPtr<Element> br = HTMLBRElement::create(document());
-        insertNodeAt(br.get(), insertionPosition);
-        insertionPosition = positionInParentAfterNode(br.get());
+        auto br = HTMLBRElement::create(document());
+        auto* brPtr = br.ptr();
+        insertNodeAt(WTFMove(br), insertionPosition);
+        insertionPosition = positionInParentAfterNode(brPtr);
         // If the insertion point is a break element, there is nothing else
         // we need to do.
         if (visiblePos.deepEquivalent().anchorNode()->renderer()->isBR()) {
@@ -358,9 +360,9 @@ void InsertParagraphSeparatorCommand::doApply()
 
     // Put the added block in the tree.
     if (nestNewBlock)
-        appendNode(blockToInsert.get(), startBlock);
+        appendNode(*blockToInsert, *startBlock);
     else
-        insertNodeAfter(blockToInsert.get(), startBlock);
+        insertNodeAfter(*blockToInsert, *startBlock);
 
     document().updateLayoutIgnorePendingStylesheets();
 
@@ -368,7 +370,7 @@ void InsertParagraphSeparatorCommand::doApply()
     // created.  All of the nodes, starting at visiblePos, are about to be added to the new paragraph 
     // element.  If the first node to be inserted won't be one that will hold an empty line open, add a br.
     if (isEndOfParagraph(visiblePos) && !lineBreakExistsAtVisiblePosition(visiblePos))
-        appendNode(HTMLBRElement::create(document()), blockToInsert.get());
+        appendNode(HTMLBRElement::create(document()), *blockToInsert);
 
     // Move the start node and the siblings of the start node.
     if (VisiblePosition(insertionPosition) != VisiblePosition(positionBeforeNode(blockToInsert.get()))) {
index 5efdd53..0285ae7 100644 (file)
@@ -46,7 +46,7 @@ private:
     void calculateStyleBeforeInsertion(const Position&);
     void applyStyleAfterInsertion(Node* originalEnclosingBlock);
     void getAncestorsInsideBlock(const Node* insertionNode, Element* outerBlock, Vector<RefPtr<Element>>& ancestors);
-    RefPtr<Element> cloneHierarchyUnderNewBlock(const Vector<RefPtr<Element>>& ancestors, PassRefPtr<Element> blockToInsert);
+    Ref<Element> cloneHierarchyUnderNewBlock(const Vector<RefPtr<Element>>& ancestors, Ref<Element>&& blockToInsert);
 
     bool shouldUseDefaultParagraphElement(Node*) const;
 
index 61c82c0..ad0d25e 100644 (file)
@@ -58,17 +58,19 @@ Position InsertTextCommand::positionInsideTextNode(const Position& p)
 {
     Position pos = p;
     if (isTabSpanTextNode(pos.anchorNode())) {
-        RefPtr<Node> textNode = document().createEditingTextNode(emptyString());
-        insertNodeAtTabSpanPosition(textNode.get(), pos);
-        return firstPositionInNode(textNode.get());
+        auto textNode = document().createEditingTextNode(emptyString());
+        auto* textNodePtr = textNode.ptr();
+        insertNodeAtTabSpanPosition(WTFMove(textNode), pos);
+        return firstPositionInNode(textNodePtr);
     }
 
     // Prepare for text input by looking at the specified position.
     // It may be necessary to insert a text node to receive characters.
     if (!pos.containerNode()->isTextNode()) {
-        RefPtr<Node> textNode = document().createEditingTextNode(emptyString());
-        insertNodeAt(textNode.get(), pos);
-        return firstPositionInNode(textNode.get());
+        auto textNode = document().createEditingTextNode(emptyString());
+        auto* textNodePtr = textNode.ptr();
+        insertNodeAt(WTFMove(textNode), pos);
+        return firstPositionInNode(textNodePtr);
     }
 
     return pos;
@@ -250,27 +252,28 @@ Position InsertTextCommand::insertTab(const Position& pos)
     
     // create new tab span
     auto spanNode = createTabSpanElement(document());
+    auto* spanNodePtr = spanNode.ptr();
     
     // place it
     if (!is<Text>(*node))
-        insertNodeAt(spanNode.ptr(), insertPos);
+        insertNodeAt(WTFMove(spanNode), insertPos);
     else {
-        RefPtr<Text> textNode = downcast<Text>(node);
+        Ref<Text> textNode = downcast<Text>(*node);
         if (offset >= textNode->length())
-            insertNodeAfter(spanNode.copyRef(), WTFMove(textNode));
+            insertNodeAfter(WTFMove(spanNode), textNode);
         else {
             // split node to make room for the span
             // NOTE: splitTextNode uses textNode for the
             // second node in the split, so we need to
             // insert the span before it.
             if (offset > 0)
-                splitTextNode(textNode, offset);
-            insertNodeBefore(spanNode.copyRef(), WTFMove(textNode));
+                splitTextNode(textNode.ptr(), offset);
+            insertNodeBefore(WTFMove(spanNode), textNode);
         }
     }
 
     // return the position following the new tab
-    return lastPositionInNode(spanNode.ptr());
+    return lastPositionInNode(spanNodePtr);
 }
 
 }
index 52d21af..2392945 100644 (file)
@@ -95,7 +95,7 @@ void ModifySelectionListLevelCommand::insertSiblingNodeRangeBefore(Node* startNo
     while (1) {
         Node* next = node->nextSibling();
         removeNode(node);
-        insertNodeBefore(node, refNode);
+        insertNodeBefore(*node, *refNode);
 
         if (node == endNode)
             break;
@@ -110,7 +110,7 @@ void ModifySelectionListLevelCommand::insertSiblingNodeRangeAfter(Node* startNod
     while (1) {
         Node* next = node->nextSibling();
         removeNode(node);
-        insertNodeAfter(node, refNode);
+        insertNodeAfter(*node, *refNode);
 
         if (node == endNode)
             break;
@@ -126,7 +126,7 @@ void ModifySelectionListLevelCommand::appendSiblingNodeRange(Node* startNode, No
     while (1) {
         Node* next = node->nextSibling();
         removeNode(node);
-        appendNode(node, newParent);
+        appendNode(*node, *newParent);
 
         if (node == endNode)
             break;
@@ -197,7 +197,7 @@ void IncreaseSelectionListLevelCommand::doApply()
                 newParent = HTMLUListElement::create(document());
                 break;
         }
-        insertNodeBefore(newParent, startListChild);
+        insertNodeBefore(*newParent, *startListChild);
         appendSiblingNodeRange(startListChild, endListChild, newParent.get());
         m_listElement = WTFMove(newParent);
     }
index 16f0f63..b616443 100644 (file)
@@ -41,15 +41,15 @@ RemoveNodePreservingChildrenCommand::RemoveNodePreservingChildrenCommand(PassRef
 
 void RemoveNodePreservingChildrenCommand::doApply()
 {
-    Vector<RefPtr<Node>> children;
+    Vector<Ref<Node>> children;
     for (Node* child = m_node->firstChild(); child; child = child->nextSibling())
-        children.append(child);
+        children.append(*child);
 
     size_t size = children.size();
     for (size_t i = 0; i < size; ++i) {
         auto child = WTFMove(children[i]);
-        removeNode(child, m_shouldAssumeContentIsAlwaysEditable);
-        insertNodeBefore(WTFMove(child), m_node, m_shouldAssumeContentIsAlwaysEditable);
+        removeNode(child.ptr(), m_shouldAssumeContentIsAlwaysEditable);
+        insertNodeBefore(WTFMove(child), *m_node, m_shouldAssumeContentIsAlwaysEditable);
     }
     removeNode(m_node, m_shouldAssumeContentIsAlwaysEditable);
 }
index b8aba83..941527b 100644 (file)
@@ -670,13 +670,13 @@ void ReplaceSelectionCommand::moveNodeOutOfAncestor(PassRefPtr<Node> prpNode, Pa
     if (positionAtEndOfNode == lastPositionInParagraph) {
         removeNode(node);
         if (ancestor->nextSibling())
-            insertNodeBefore(nodeancestor->nextSibling());
+            insertNodeBefore(node.releaseNonNull(), *ancestor->nextSibling());
         else
-            appendNode(nodeancestor->parentNode());
+            appendNode(node.releaseNonNull(), *ancestor->parentNode());
     } else {
         RefPtr<Node> nodeToSplitTo = splitTreeToNode(node.get(), ancestor.get(), true);
         removeNode(node);
-        insertNodeBefore(nodenodeToSplitTo);
+        insertNodeBefore(node.releaseNonNull(), *nodeToSplitTo);
     }
     if (!ancestor->firstChild()) {
         insertedNodes.willRemoveNode(ancestor.get());
@@ -851,9 +851,10 @@ void ReplaceSelectionCommand::mergeEndIfNeeded()
     // Merging forward could result in deleting the destination anchor node.
     // To avoid this, we add a placeholder node before the start of the paragraph.
     if (endOfParagraph(startOfParagraphToMove) == destination) {
-        RefPtr<Node> placeholder = HTMLBRElement::create(document());
-        insertNodeBefore(placeholder, startOfParagraphToMove.deepEquivalent().deprecatedNode());
-        destination = VisiblePosition(positionBeforeNode(placeholder.get()));
+        auto placeholder = HTMLBRElement::create(document());
+        auto* placeholderPtr = placeholder.ptr();
+        insertNodeBefore(WTFMove(placeholder), *startOfParagraphToMove.deepEquivalent().deprecatedNode());
+        destination = VisiblePosition(positionBeforeNode(placeholderPtr));
     }
 
     moveParagraph(startOfParagraphToMove, endOfParagraph(startOfParagraphToMove), destination);
@@ -1116,7 +1117,7 @@ void ReplaceSelectionCommand::doApply()
         && blockStart && blockStart->renderer()->isListItem())
         refNode = insertAsListItems(downcast<HTMLElement>(refNode.get()), blockStart, insertionPos, insertedNodes);
     else {
-        insertNodeAt(refNode, insertionPos);
+        insertNodeAt(*refNode, insertionPos);
         insertedNodes.respondToNodeInsertion(refNode.get());
     }
 
@@ -1129,7 +1130,7 @@ void ReplaceSelectionCommand::doApply()
     while (node) {
         RefPtr<Node> next = node->nextSibling();
         fragment.removeNode(node.get());
-        insertNodeAfter(node, refNode.get());
+        insertNodeAfter(*node, *refNode);
         insertedNodes.respondToNodeInsertion(node.get());
 
         // Mutation events (bug 22634) may have already removed the inserted content
@@ -1191,7 +1192,7 @@ void ReplaceSelectionCommand::doApply()
         // We insert a placeholder before the newly inserted content to avoid being merged into the inline.
         Node* destinationNode = destination.deepEquivalent().deprecatedNode();
         if (m_shouldMergeEnd && destinationNode != enclosingInline(destinationNode) && enclosingInline(destinationNode)->nextSibling())
-            insertNodeBefore(HTMLBRElement::create(document()), refNode.get());
+            insertNodeBefore(HTMLBRElement::create(document()), *refNode);
         
         // Merging the the first paragraph of inserted content with the content that came
         // before the selection that was pasted into would also move content after 
@@ -1227,7 +1228,7 @@ void ReplaceSelectionCommand::doApply()
                 Node* enclosingNode = enclosingBlock(endOfInsertedContent.deepEquivalent().deprecatedNode());
                 if (isListItem(enclosingNode)) {
                     auto newListItem = HTMLLIElement::create(document());
-                    insertNodeAfter(newListItem.copyRef(), enclosingNode);
+                    insertNodeAfter(newListItem.copyRef(), *enclosingNode);
                     setEndingSelection(VisiblePosition(firstPositionInNode(newListItem.ptr())));
                 } else {
                     // Use a default paragraph element (a plain div) for the empty paragraph, using the last paragraph
@@ -1336,9 +1337,9 @@ void ReplaceSelectionCommand::addSpacesForSmartReplace()
             if (m_endOfInsertedContent.containerNode() == endNode)
                 m_endOfInsertedContent.moveToOffset(m_endOfInsertedContent.offsetInContainerNode() + 1);
         } else {
-            RefPtr<Node> node = document().createEditingTextNode(collapseWhiteSpace ? nonBreakingSpaceString() : " ");
-            insertNodeAfter(nodeendNode);
-            updateNodesInserted(node.get());
+            auto node = document().createEditingTextNode(collapseWhiteSpace ? nonBreakingSpaceString() : " ");
+            insertNodeAfter(node.copyRef(), *endNode);
+            updateNodesInserted(node.ptr());
         }
     }
 
@@ -1360,11 +1361,12 @@ void ReplaceSelectionCommand::addSpacesForSmartReplace()
             if (m_endOfInsertedContent.containerNode() == startNode && m_endOfInsertedContent.offsetInContainerNode())
                 m_endOfInsertedContent.moveToOffset(m_endOfInsertedContent.offsetInContainerNode() + 1);
         } else {
-            RefPtr<Node> node = document().createEditingTextNode(collapseWhiteSpace ? nonBreakingSpaceString() : " ");
+            auto node = document().createEditingTextNode(collapseWhiteSpace ? nonBreakingSpaceString() : " ");
+            auto* nodePtr = node.ptr();
             // Don't updateNodesInserted. Doing so would set m_endOfInsertedContent to be the node containing the leading space,
             // but m_endOfInsertedContent is supposed to mark the end of pasted content.
-            insertNodeBefore(node, startNode);
-            m_startOfInsertedContent = firstPositionInNode(node.get());
+            insertNodeBefore(WTFMove(node), *startNode);
+            m_startOfInsertedContent = firstPositionInNode(nodePtr);
         }
     }
 }
@@ -1486,10 +1488,10 @@ Node* ReplaceSelectionCommand::insertAsListItems(PassRefPtr<HTMLElement> prpList
     while (RefPtr<Node> listItem = listElement->firstChild()) {
         listElement->removeChild(*listItem);
         if (isStart || isMiddle) {
-            insertNodeBefore(listItem, lastNode);
+            insertNodeBefore(*listItem, *lastNode);
             insertedNodes.respondToNodeInsertion(listItem.get());
         } else if (isEnd) {
-            insertNodeAfter(listItem, lastNode);
+            insertNodeAfter(*listItem, *lastNode);
             insertedNodes.respondToNodeInsertion(listItem.get());
             lastNode = listItem.get();
         } else
index 31570a5..33e8d83 100644 (file)
@@ -120,7 +120,7 @@ int SimplifyMarkupCommand::pruneSubsequentAncestorsToRemove(Vector<RefPtr<Node>>
         return 0;
 
     removeNode(nodesToRemove[startNodeIndex], AssumeContentIsAlwaysEditable);
-    insertNodeBefore(nodesToRemove[startNodeIndex], highestAncestorToRemove, AssumeContentIsAlwaysEditable);
+    insertNodeBefore(*nodesToRemove[startNodeIndex], *highestAncestorToRemove, AssumeContentIsAlwaysEditable);
     removeNode(highestAncestorToRemove, AssumeContentIsAlwaysEditable);
 
     return pastLastNodeToRemove - startNodeIndex - 1;