+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.
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());
}
#ifndef NDEBUG
void AppendNodeCommand::getNodesInCommand(HashSet<Node*>& nodes)
{
- addNodeAndDescendants(m_parent.get(), nodes);
+ addNodeAndDescendants(m_parent.ptr(), nodes);
addNodeAndDescendants(m_node.ptr(), nodes);
}
#endif
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;
void getNodesInCommand(HashSet<Node*>&) override;
#endif
- RefPtr<ContainerNode> m_parent;
+ Ref<ContainerNode> m_parent;
Ref<Node> m_node;
};
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;
// 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());
}
// 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) {
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;
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);
}
// 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()));
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,
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)
for (auto& nodeToRemove : nodesToRemove) {
removeNode(nodeToRemove.ptr());
- appendNode(nodeToRemove.ptr(), newParent);
+ appendNode(WTFMove(nodeToRemove), *newParent);
}
}
ASSERT(!first->isDescendantOf(second.get()) && second != first);
if (first->nextSibling() != second) {
removeNode(second);
- insertNodeAfter(second, first);
+ insertNodeAfter(*second, *first);
}
applyCommandToComposite(MergeIdenticalElementsCommand::create(first, second));
}
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)
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)
ASSERT(pos.deprecatedNode()->renderer());
auto placeholder = createBlockPlaceholderElement(document());
- insertNodeAt(placeholder.ptr(), pos);
+ insertNodeAt(placeholder.copyRef(), pos);
return WTFMove(placeholder);
}
// 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;
}
{
auto paragraphElement = createDefaultParagraphElement(document());
paragraphElement->appendChild(HTMLBRElement::create(document()));
- insertNodeAt(paragraphElement.ptr(), position);
+ insertNodeAt(paragraphElement.copyRef(), position);
return paragraphElement;
}
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())) {
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);
}
}
}
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;
// 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());
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.
//
// 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);
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);
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&);
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()));
}
}
RefPtr<ContainerNode> rootEditableElement = node->rootEditableElement();
if (rootEditableElement) {
removeNode(node);
- appendNode(node, rootEditableElement);
+ appendNode(*node, *rootEditableElement);
}
}
node = nextNode;
// 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);
}
// 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();
newList = HTMLUListElement::create(document());
else
newList = HTMLOListElement::create(document());
- insertNodeBefore(newList, selectedListItem);
+ insertNodeBefore(*newList, *selectedListItem);
moveParagraphWithClones(start, end, newList.get(), selectedListItem.get());
// 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());
}
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
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)
{
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
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);
}
}
bool preservesTypingStyle() const override;
- void insertNodeAfterPosition(Node*, const Position&);
- void insertNodeBeforePosition(Node*, const Position&);
bool shouldUseBreakElement(const Position&);
};
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();
// Remove the list chlild.
RefPtr<HTMLElement> listNode = enclosingList(listChildNode);
if (!listNode) {
- listNode = fixOrphanedListChild(listChildNode);
+ listNode = fixOrphanedListChild(*listChildNode);
listNode = mergeWithNeighboringLists(listNode);
}
if (!listNode->hasTagName(listTag)) {
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();
}
// 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(placeholder, nodeToInsert);
+ appendNode(placeholder.copyRef(), *nodeToInsert);
}
if (nextListChild && previousListChild) {
// 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(nodeToInsert, listNode);
+ 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
// where we're about to move listChildNode to.
if (listChildNode->parentNode() != listNode)
splitElement(listNode, splitTreeToNode(listChildNode, listNode).get());
- insertNodeBefore(nodeToInsert, listNode);
+ insertNodeBefore(nodeToInsert.releaseNonNull(), *listNode);
} else
- insertNodeAfter(nodeToInsert, listNode);
+ insertNodeAfter(nodeToInsert.releaseNonNull(), *listNode);
- VisiblePosition insertionPoint = VisiblePosition(positionBeforeNode(placeholder.get()));
+ VisiblePosition insertionPoint = VisiblePosition(positionBeforeNode(placeholder.ptr()));
moveParagraphs(start, end, insertionPoint, true);
}
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
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
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);
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());
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();
#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
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;
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;
};
}
}
-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()
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(extraBlock, startBlock);
- 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.
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;
}
// 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()));
// 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()) {
// 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();
// 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()))) {
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;
{
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;
// 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);
}
}
while (1) {
Node* next = node->nextSibling();
removeNode(node);
- insertNodeBefore(node, refNode);
+ insertNodeBefore(*node, *refNode);
if (node == endNode)
break;
while (1) {
Node* next = node->nextSibling();
removeNode(node);
- insertNodeAfter(node, refNode);
+ insertNodeAfter(*node, *refNode);
if (node == endNode)
break;
while (1) {
Node* next = node->nextSibling();
removeNode(node);
- appendNode(node, newParent);
+ appendNode(*node, *newParent);
if (node == endNode)
break;
newParent = HTMLUListElement::create(document());
break;
}
- insertNodeBefore(newParent, startListChild);
+ insertNodeBefore(*newParent, *startListChild);
appendSiblingNodeRange(startListChild, endListChild, newParent.get());
m_listElement = WTFMove(newParent);
}
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);
}
if (positionAtEndOfNode == lastPositionInParagraph) {
removeNode(node);
if (ancestor->nextSibling())
- insertNodeBefore(node, ancestor->nextSibling());
+ insertNodeBefore(node.releaseNonNull(), *ancestor->nextSibling());
else
- appendNode(node, ancestor->parentNode());
+ appendNode(node.releaseNonNull(), *ancestor->parentNode());
} else {
RefPtr<Node> nodeToSplitTo = splitTreeToNode(node.get(), ancestor.get(), true);
removeNode(node);
- insertNodeBefore(node, nodeToSplitTo);
+ insertNodeBefore(node.releaseNonNull(), *nodeToSplitTo);
}
if (!ancestor->firstChild()) {
insertedNodes.willRemoveNode(ancestor.get());
// 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);
&& blockStart && blockStart->renderer()->isListItem())
refNode = insertAsListItems(downcast<HTMLElement>(refNode.get()), blockStart, insertionPos, insertedNodes);
else {
- insertNodeAt(refNode, insertionPos);
+ insertNodeAt(*refNode, insertionPos);
insertedNodes.respondToNodeInsertion(refNode.get());
}
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
// 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
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
if (m_endOfInsertedContent.containerNode() == endNode)
m_endOfInsertedContent.moveToOffset(m_endOfInsertedContent.offsetInContainerNode() + 1);
} else {
- RefPtr<Node> node = document().createEditingTextNode(collapseWhiteSpace ? nonBreakingSpaceString() : " ");
- insertNodeAfter(node, endNode);
- updateNodesInserted(node.get());
+ auto node = document().createEditingTextNode(collapseWhiteSpace ? nonBreakingSpaceString() : " ");
+ insertNodeAfter(node.copyRef(), *endNode);
+ updateNodesInserted(node.ptr());
}
}
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);
}
}
}
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
return 0;
removeNode(nodesToRemove[startNodeIndex], AssumeContentIsAlwaysEditable);
- insertNodeBefore(nodesToRemove[startNodeIndex], highestAncestorToRemove, AssumeContentIsAlwaysEditable);
+ insertNodeBefore(*nodesToRemove[startNodeIndex], *highestAncestorToRemove, AssumeContentIsAlwaysEditable);
removeNode(highestAncestorToRemove, AssumeContentIsAlwaysEditable);
return pastLastNodeToRemove - startNodeIndex - 1;