Remove unnecessary null check in FrameSelection::nodeWillBeRemoved()
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Nov 2014 00:02:57 +0000 (00:02 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Nov 2014 00:02:57 +0000 (00:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=138578

Reviewed by Andreas Kling.

Remove unnecessary null check in FrameSelection::nodeWillBeRemoved()
and turn the argument into a reference to make it clear it cannot be
null.

No new tests, no behavior change.

* dom/ContainerNode.cpp:
(WebCore::ContainerNode::willRemoveChild):
* dom/Document.cpp:
(WebCore::Document::nodeChildrenWillBeRemoved):
(WebCore::Document::nodeWillBeRemoved):
* dom/Document.h:
* dom/NodeIterator.cpp:
(WebCore::NodeIterator::nodeWillBeRemoved):
(WebCore::NodeIterator::updateForNodeRemoval):
* dom/NodeIterator.h:
* dom/Range.cpp:
(WebCore::Range::insertNode):
(WebCore::boundaryNodeWillBeRemoved):
(WebCore::Range::nodeWillBeRemoved):
* dom/Range.h:
* dom/RangeBoundaryPoint.h:
(WebCore::RangeBoundaryPoint::setToBeforeChild):
* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::updatePositionForNodeRemovalPreservingChildren):
* editing/CompositeEditCommand.h:
* editing/DeleteSelectionCommand.cpp:
(WebCore::DeleteSelectionCommand::removeNode):
(WebCore::DeleteSelectionCommand::handleGeneralDelete):
(WebCore::DeleteSelectionCommand::removeRedundantBlocks):
* editing/FrameSelection.cpp:
(WebCore::removingNodeRemovesPosition):
(WebCore::DragCaretController::nodeWillBeRemoved):
(WebCore::FrameSelection::nodeWillBeRemoved):
(WebCore::FrameSelection::respondToNodeModification):
* editing/FrameSelection.h:
* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::mergeTextNodesAroundPosition):
* editing/htmlediting.cpp:
(WebCore::updatePositionForNodeRemoval):
* editing/htmlediting.h:
* page/EventHandler.cpp:
(WebCore::EventHandler::nodeWillBeRemoved):
* page/EventHandler.h:

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

19 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/ContainerNode.cpp
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/NodeIterator.cpp
Source/WebCore/dom/NodeIterator.h
Source/WebCore/dom/Range.cpp
Source/WebCore/dom/Range.h
Source/WebCore/dom/RangeBoundaryPoint.h
Source/WebCore/editing/CompositeEditCommand.cpp
Source/WebCore/editing/CompositeEditCommand.h
Source/WebCore/editing/DeleteSelectionCommand.cpp
Source/WebCore/editing/FrameSelection.cpp
Source/WebCore/editing/FrameSelection.h
Source/WebCore/editing/ReplaceSelectionCommand.cpp
Source/WebCore/editing/htmlediting.cpp
Source/WebCore/editing/htmlediting.h
Source/WebCore/page/EventHandler.cpp
Source/WebCore/page/EventHandler.h

index 000588e419339ecb1429b07150df75ed4bbfa762..aaf4c98a7d7abdd3c9d11d333fa0cfa7235fb88c 100644 (file)
@@ -1,3 +1,55 @@
+2014-11-10  Chris Dumez  <cdumez@apple.com>
+
+        Remove unnecessary null check in FrameSelection::nodeWillBeRemoved()
+        https://bugs.webkit.org/show_bug.cgi?id=138578
+
+        Reviewed by Andreas Kling.
+
+        Remove unnecessary null check in FrameSelection::nodeWillBeRemoved()
+        and turn the argument into a reference to make it clear it cannot be
+        null.
+
+        No new tests, no behavior change.
+
+        * dom/ContainerNode.cpp:
+        (WebCore::ContainerNode::willRemoveChild):
+        * dom/Document.cpp:
+        (WebCore::Document::nodeChildrenWillBeRemoved):
+        (WebCore::Document::nodeWillBeRemoved):
+        * dom/Document.h:
+        * dom/NodeIterator.cpp:
+        (WebCore::NodeIterator::nodeWillBeRemoved):
+        (WebCore::NodeIterator::updateForNodeRemoval):
+        * dom/NodeIterator.h:
+        * dom/Range.cpp:
+        (WebCore::Range::insertNode):
+        (WebCore::boundaryNodeWillBeRemoved):
+        (WebCore::Range::nodeWillBeRemoved):
+        * dom/Range.h:
+        * dom/RangeBoundaryPoint.h:
+        (WebCore::RangeBoundaryPoint::setToBeforeChild):
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::updatePositionForNodeRemovalPreservingChildren):
+        * editing/CompositeEditCommand.h:
+        * editing/DeleteSelectionCommand.cpp:
+        (WebCore::DeleteSelectionCommand::removeNode):
+        (WebCore::DeleteSelectionCommand::handleGeneralDelete):
+        (WebCore::DeleteSelectionCommand::removeRedundantBlocks):
+        * editing/FrameSelection.cpp:
+        (WebCore::removingNodeRemovesPosition):
+        (WebCore::DragCaretController::nodeWillBeRemoved):
+        (WebCore::FrameSelection::nodeWillBeRemoved):
+        (WebCore::FrameSelection::respondToNodeModification):
+        * editing/FrameSelection.h:
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::mergeTextNodesAroundPosition):
+        * editing/htmlediting.cpp:
+        (WebCore::updatePositionForNodeRemoval):
+        * editing/htmlediting.h:
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::nodeWillBeRemoved):
+        * page/EventHandler.h:
+
 2014-11-10  Benjamin Poulain  <bpoulain@apple.com>
 
         Fix the build when CSS Selectors Level 4 is disabled
index f2c57ae558080f35c3316fde8401e6ef910353ad..4d4bec49b513affa25d0f398f8606315dfa5fbff 100644 (file)
@@ -476,7 +476,7 @@ void ContainerNode::willRemoveChild(Node& child)
     if (child.parentNode() != this)
         return;
 
-    child.document().nodeWillBeRemoved(&child); // e.g. mutation event listener can create a new range.
+    child.document().nodeWillBeRemoved(child); // e.g. mutation event listener can create a new range.
     if (is<ContainerNode>(child))
         disconnectSubframesIfNeeded(downcast<ContainerNode>(child), RootAndDescendants);
 }
index 282215c8fc061f44721681da526cf6a8547fe7fd..f2194b7d8ee13030b11f7b78563f70bfb9a32832 100644 (file)
@@ -3661,19 +3661,19 @@ void Document::nodeChildrenWillBeRemoved(ContainerNode& container)
 
     for (auto it = m_nodeIterators.begin(), end = m_nodeIterators.end(); it != end; ++it) {
         for (Node* n = container.firstChild(); n; n = n->nextSibling())
-            (*it)->nodeWillBeRemoved(n);
+            (*it)->nodeWillBeRemoved(*n);
     }
 
     if (Frame* frame = this->frame()) {
         for (Node* n = container.firstChild(); n; n = n->nextSibling()) {
-            frame->eventHandler().nodeWillBeRemoved(n);
-            frame->selection().nodeWillBeRemoved(n);
-            frame->page()->dragCaretController().nodeWillBeRemoved(n);
+            frame->eventHandler().nodeWillBeRemoved(*n);
+            frame->selection().nodeWillBeRemoved(*n);
+            frame->page()->dragCaretController().nodeWillBeRemoved(*n);
         }
     }
 }
 
-void Document::nodeWillBeRemoved(Node* n)
+void Document::nodeWillBeRemoved(Node& n)
 {
     HashSet<NodeIterator*>::const_iterator nodeIteratorsEnd = m_nodeIterators.end();
     for (HashSet<NodeIterator*>::const_iterator it = m_nodeIterators.begin(); it != nodeIteratorsEnd; ++it)
index 719d6ccc65eeb3ba80b875a5cf1495d058c542c8..bc36139c259f937a4afc6a4cd04b5bd9e61e056f 100644 (file)
@@ -796,7 +796,7 @@ public:
     // nodeChildrenWillBeRemoved is used when removing all node children at once.
     void nodeChildrenWillBeRemoved(ContainerNode&);
     // nodeWillBeRemoved is only safe when removing one node at a time.
-    void nodeWillBeRemoved(Node*);
+    void nodeWillBeRemoved(Node&);
     bool canReplaceChild(Node* newChild, Node* oldChild);
 
     void textInserted(Node*, unsigned offset, unsigned length);
index c51b14a3d7658670ae0cdd5cd5d561be55f6db8c..8b6a1484247e3800e6583b7f13b510c01f5d035d 100644 (file)
@@ -154,43 +154,42 @@ void NodeIterator::detach()
     m_referenceNode.node.clear();
 }
 
-void NodeIterator::nodeWillBeRemoved(Node* removedNode)
+void NodeIterator::nodeWillBeRemoved(Node& removedNode)
 {
     updateForNodeRemoval(removedNode, m_candidateNode);
     updateForNodeRemoval(removedNode, m_referenceNode);
 }
 
-void NodeIterator::updateForNodeRemoval(Node* removedNode, NodePointer& referenceNode) const
+void NodeIterator::updateForNodeRemoval(Node& removedNode, NodePointer& referenceNode) const
 {
     ASSERT(!m_detached);
-    ASSERT(removedNode);
-    ASSERT(&root()->document() == &removedNode->document());
+    ASSERT(&root()->document() == &removedNode.document());
 
     // Iterator is not affected if the removed node is the reference node and is the root.
     // or if removed node is not the reference node, or the ancestor of the reference node.
-    if (!removedNode->isDescendantOf(root()))
+    if (!removedNode.isDescendantOf(root()))
         return;
-    bool willRemoveReferenceNode = removedNode == referenceNode.node;
-    bool willRemoveReferenceNodeAncestor = referenceNode.node && referenceNode.node->isDescendantOf(removedNode);
+    bool willRemoveReferenceNode = &removedNode == referenceNode.node;
+    bool willRemoveReferenceNodeAncestor = referenceNode.node && referenceNode.node->isDescendantOf(&removedNode);
     if (!willRemoveReferenceNode && !willRemoveReferenceNodeAncestor)
         return;
 
     if (referenceNode.isPointerBeforeNode) {
-        Node* node = NodeTraversal::next(removedNode, root());
+        Node* node = NodeTraversal::next(&removedNode, root());
         if (node) {
             // Move out from under the node being removed if the new reference
             // node is a descendant of the node being removed.
-            while (node && node->isDescendantOf(removedNode))
+            while (node && node->isDescendantOf(&removedNode))
                 node = NodeTraversal::next(node, root());
             if (node)
                 referenceNode.node = node;
         } else {
-            node = NodeTraversal::previous(removedNode);
+            node = NodeTraversal::previous(&removedNode);
             if (node) {
                 // Move out from under the node being removed if the reference node is
                 // a descendant of the node being removed.
                 if (willRemoveReferenceNodeAncestor) {
-                    while (node && node->isDescendantOf(removedNode))
+                    while (node && node->isDescendantOf(&removedNode))
                         node = NodeTraversal::previous(node);
                 }
                 if (node) {
@@ -203,23 +202,23 @@ void NodeIterator::updateForNodeRemoval(Node* removedNode, NodePointer& referenc
             }
         }
     } else {
-        Node* node = NodeTraversal::previous(removedNode);
+        Node* node = NodeTraversal::previous(&removedNode);
         if (node) {
             // Move out from under the node being removed if the reference node is
             // a descendant of the node being removed.
             if (willRemoveReferenceNodeAncestor) {
-                while (node && node->isDescendantOf(removedNode))
+                while (node && node->isDescendantOf(&removedNode))
                     node = NodeTraversal::previous(node);
             }
             if (node)
                 referenceNode.node = node;
         } else {
             // FIXME: This branch doesn't appear to have any LayoutTests.
-            node = NodeTraversal::next(removedNode, root());
+            node = NodeTraversal::next(&removedNode, root());
             // Move out from under the node being removed if the reference node is
             // a descendant of the node being removed.
             if (willRemoveReferenceNodeAncestor) {
-                while (node && node->isDescendantOf(removedNode))
+                while (node && node->isDescendantOf(&removedNode))
                     node = NodeTraversal::previous(node);
             }
             if (node)
index 48925ad2013210173c830b450fa075cb7b7d0f3c..710be45af48a503e43be93a71e7534550d9253ed 100644 (file)
@@ -51,7 +51,7 @@ namespace WebCore {
         bool pointerBeforeReferenceNode() const { return m_referenceNode.isPointerBeforeNode; }
 
         // This function is called before any node is removed from the document tree.
-        void nodeWillBeRemoved(Node*);
+        void nodeWillBeRemoved(Node&);
 
         // Do not call these functions. They are just scaffolding to support the Objective-C bindings.
         // They operate in the main thread normal world, and they swallow JS exceptions.
@@ -71,7 +71,7 @@ namespace WebCore {
             bool moveToPrevious(Node* root);
         };
 
-        void updateForNodeRemoval(Node* nodeToBeRemoved, NodePointer&) const;
+        void updateForNodeRemoval(Node& nodeToBeRemoved, NodePointer&) const;
 
         NodePointer m_referenceNode;
         NodePointer m_candidateNode;
index d70ad91a0b20e4fce9bc8346b1566cf9864d6783..95523e652869d9ea3eb7c94a48b57eb8a1e04320 100644 (file)
@@ -1050,7 +1050,7 @@ void Range::insertNode(PassRefPtr<Node> prpNewNode, ExceptionCode& ec)
             return;
 
         if (collapsed && newText->parentNode() == container && &container->document() == &ownerDocument())
-            m_end.setToBeforeChild(newText.get());
+            m_end.setToBeforeChild(*newText);
     } else {
         container = m_start.container();
         RefPtr<Node> firstInsertedChild = newNodeType == Node::DOCUMENT_FRAGMENT_NODE ? newNode->firstChild() : newNode;
@@ -1062,7 +1062,7 @@ void Range::insertNode(PassRefPtr<Node> prpNewNode, ExceptionCode& ec)
 
         if (collapsed && numNewChildren && &container->document() == &ownerDocument()) {
             if (firstInsertedChild->parentNode() == container)
-                m_start.setToBeforeChild(firstInsertedChild.get());
+                m_start.setToBeforeChild(*firstInsertedChild);
             if (lastInsertedChild->parentNode() == container)
                 m_end.set(container, lastInsertedChild->computeNodeIndex() + 1, lastInsertedChild.get());
         }
@@ -2060,27 +2060,26 @@ void Range::nodeChildrenWillBeRemoved(ContainerNode& container)
     boundaryNodeChildrenWillBeRemoved(m_end, container);
 }
 
-static inline void boundaryNodeWillBeRemoved(RangeBoundaryPoint& boundary, Node* nodeToBeRemoved)
+static inline void boundaryNodeWillBeRemoved(RangeBoundaryPoint& boundary, Node& nodeToBeRemoved)
 {
-    if (boundary.childBefore() == nodeToBeRemoved) {
+    if (boundary.childBefore() == &nodeToBeRemoved) {
         boundary.childBeforeWillBeRemoved();
         return;
     }
 
     for (Node* n = boundary.container(); n; n = n->parentNode()) {
-        if (n == nodeToBeRemoved) {
+        if (n == &nodeToBeRemoved) {
             boundary.setToBeforeChild(nodeToBeRemoved);
             return;
         }
     }
 }
 
-void Range::nodeWillBeRemoved(Node* node)
+void Range::nodeWillBeRemoved(Node& node)
 {
-    ASSERT(node);
-    ASSERT(&node->document() == &ownerDocument());
-    ASSERT(node != &ownerDocument());
-    ASSERT(node->parentNode());
+    ASSERT(&node.document() == &ownerDocument());
+    ASSERT(&node != &ownerDocument());
+    ASSERT(node.parentNode());
     boundaryNodeWillBeRemoved(m_start, node);
     boundaryNodeWillBeRemoved(m_end, node);
 }
index 1fe175c253f2794f1c511e34413f4dca727865f6..f58ea299cdcdd0c151e761ac41868b922a9c8369 100644 (file)
@@ -139,7 +139,7 @@ public:
 
     void nodeChildrenChanged(ContainerNode&);
     void nodeChildrenWillBeRemoved(ContainerNode&);
-    void nodeWillBeRemoved(Node*);
+    void nodeWillBeRemoved(Node&);
 
     void textInserted(Node*, unsigned offset, unsigned length);
     void textRemoved(Node*, unsigned offset, unsigned length);
index 784fa453b48dc32927795bdb7141519fb573f4e2..b04dc08b55bf021ccddfb26aee5d384b1126ae03 100644 (file)
@@ -48,7 +48,7 @@ public:
     void set(PassRefPtr<Node> container, int offset, Node* childBefore);
     void setOffset(int offset);
 
-    void setToBeforeChild(Node*);
+    void setToBeforeChild(Node&);
     void setToStartOfNode(PassRefPtr<Node>);
     void setToEndOfNode(PassRefPtr<Node>);
 
@@ -136,12 +136,11 @@ inline void RangeBoundaryPoint::setOffset(int offset)
     m_offsetInContainer = offset;
 }
 
-inline void RangeBoundaryPoint::setToBeforeChild(Node* child)
+inline void RangeBoundaryPoint::setToBeforeChild(Node& child)
 {
-    ASSERT(child);
-    ASSERT(child->parentNode());
-    m_childBeforeBoundary = child->previousSibling();
-    m_containerNode = child->parentNode();
+    ASSERT(child.parentNode());
+    m_childBeforeBoundary = child.previousSibling();
+    m_containerNode = child.parentNode();
     m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0;
 }
 
index 17b5f626b7cbe1f454c79191b5cfaba7c1daa655..416a001c02d38dcab8facf25479177e3b879c057 100644 (file)
@@ -423,7 +423,7 @@ void CompositeEditCommand::moveRemainingSiblingsToNewParent(Node* node, Node* pa
     }
 }
 
-void CompositeEditCommand::updatePositionForNodeRemovalPreservingChildren(Position& position, Node* node)
+void CompositeEditCommand::updatePositionForNodeRemovalPreservingChildren(Position& position, Node& node)
 {
     int offset = (position.anchorType() == Position::PositionIsOffsetInAnchor) ? position.offsetInContainerNode() : 0;
     updatePositionForNodeRemoval(position, node);
index 43ef5a6fa80336dba2c3b33ff9f34d8402db4185..5ff886280e2929f8f110759fe03c44df5eef5fd7 100644 (file)
@@ -128,7 +128,7 @@ protected:
     void removeNodePreservingChildren(PassRefPtr<Node>, ShouldAssumeContentIsAlwaysEditable = DoNotAssumeContentIsAlwaysEditable);
     void removeNodeAndPruneAncestors(PassRefPtr<Node>);
     void moveRemainingSiblingsToNewParent(Node*, Node* pastLastNodeToMove, PassRefPtr<Element> prpNewParent);
-    void updatePositionForNodeRemovalPreservingChildren(Position&, Node*);
+    void updatePositionForNodeRemovalPreservingChildren(Position&, Node&);
     void prune(PassRefPtr<Node>);
     void replaceTextInNode(PassRefPtr<Text>, unsigned offset, unsigned count, const String& replacementText);
     Position replaceSelectedTextInNode(const String&);
index 9da3cbcef763cc741adf507ed89a7b2673dd5c2f..5bbc312ca543d760c747147cdc9d7519e4b64ec3 100644 (file)
@@ -402,9 +402,9 @@ void DeleteSelectionCommand::removeNode(PassRefPtr<Node> node, ShouldAssumeConte
         m_needPlaceholder = true;
     
     // FIXME: Update the endpoints of the range being deleted.
-    updatePositionForNodeRemoval(m_endingPosition, node.get());
-    updatePositionForNodeRemoval(m_leadingWhitespace, node.get());
-    updatePositionForNodeRemoval(m_trailingWhitespace, node.get());
+    updatePositionForNodeRemoval(m_endingPosition, *node);
+    updatePositionForNodeRemoval(m_leadingWhitespace, *node);
+    updatePositionForNodeRemoval(m_trailingWhitespace, *node);
     
     CompositeEditCommand::removeNode(node, shouldAssumeContentIsAlwaysEditable);
 }
@@ -526,7 +526,7 @@ void DeleteSelectionCommand::handleGeneralDelete()
                 RefPtr<Node> nextNode = NodeTraversal::nextSkippingChildren(node.get());
                 // if we just removed a node from the end container, update end position so the
                 // check above will work
-                updatePositionForNodeRemoval(m_downstreamEnd, node.get());
+                updatePositionForNodeRemoval(m_downstreamEnd, *node);
                 removeNode(node.get());
                 node = nextNode.get();
             } else {
@@ -784,7 +784,7 @@ void DeleteSelectionCommand::removeRedundantBlocks()
     while (node != rootNode) {
         if (isRemovableBlock(node)) {
             if (node == m_endingPosition.anchorNode())
-                updatePositionForNodeRemovalPreservingChildren(m_endingPosition, node);
+                updatePositionForNodeRemovalPreservingChildren(m_endingPosition, *node);
             
             CompositeEditCommand::removeNodePreservingChildren(node);
             node = m_endingPosition.anchorNode();
index df4b843146ae4af0e165b84871bac6bd85045176..8df98db8d664ecadddb1b9e7d389535b24cfadad 100644 (file)
@@ -390,19 +390,18 @@ void FrameSelection::updateDataDetectorsForSelection()
 #endif
 }
 
-static bool removingNodeRemovesPosition(Node* node, const Position& position)
+static bool removingNodeRemovesPosition(Node& node, const Position& position)
 {
     if (!position.anchorNode())
         return false;
 
-    if (position.anchorNode() == node)
+    if (position.anchorNode() == &node)
         return true;
 
-    if (!is<Element>(*node))
+    if (!is<Element>(node))
         return false;
 
-    Element* element = downcast<Element>(node);
-    return element->containsIncludingShadowDOM(position.anchorNode());
+    return downcast<Element>(node).containsIncludingShadowDOM(position.anchorNode());
 }
 
 static void clearRenderViewSelection(Node& node)
@@ -413,30 +412,30 @@ static void clearRenderViewSelection(Node& node)
         view->clearSelection();
 }
 
-void DragCaretController::nodeWillBeRemoved(Node* node)
+void DragCaretController::nodeWillBeRemoved(Node& node)
 {
-    if (!hasCaret() || (node && !node->inDocument()))
+    if (!hasCaret() || !node.inDocument())
         return;
 
     if (!removingNodeRemovesPosition(node, m_position.deepEquivalent()))
         return;
 
-    clearRenderViewSelection(*node);
+    clearRenderViewSelection(node);
     clear();
 }
 
-void FrameSelection::nodeWillBeRemoved(Node* node)
+void FrameSelection::nodeWillBeRemoved(Node& node)
 {
     // There can't be a selection inside a fragment, so if a fragment's node is being removed,
     // the selection in the document that created the fragment needs no adjustment.
-    if (isNone() || (node && !node->inDocument()))
+    if (isNone() || !node.inDocument())
         return;
 
     respondToNodeModification(node, removingNodeRemovesPosition(node, m_selection.base()), removingNodeRemovesPosition(node, m_selection.extent()),
         removingNodeRemovesPosition(node, m_selection.start()), removingNodeRemovesPosition(node, m_selection.end()));
 }
 
-void FrameSelection::respondToNodeModification(Node* node, bool baseRemoved, bool extentRemoved, bool startRemoved, bool endRemoved)
+void FrameSelection::respondToNodeModification(Node& node, bool baseRemoved, bool extentRemoved, bool startRemoved, bool endRemoved)
 {
     bool clearRenderTreeSelection = false;
     bool clearDOMTreeSelection = false;
@@ -469,7 +468,7 @@ void FrameSelection::respondToNodeModification(Node* node, bool baseRemoved, boo
             m_selection.setWithoutValidation(m_selection.end(), m_selection.start());
     } else if (RefPtr<Range> range = m_selection.firstRange()) {
         ExceptionCode ec = 0;
-        Range::CompareResults compareResult = range->compareNode(node, ec);
+        Range::CompareResults compareResult = range->compareNode(&node, ec);
         if (!ec && (compareResult == Range::NODE_BEFORE_AND_AFTER || compareResult == Range::NODE_INSIDE)) {
             // If we did nothing here, when this node's renderer was destroyed, the rect that it 
             // occupied would be invalidated, but, selection gaps that change as a result of 
@@ -480,10 +479,10 @@ void FrameSelection::respondToNodeModification(Node* node, bool baseRemoved, boo
     }
 
     if (clearRenderTreeSelection) {
-        clearRenderViewSelection(*node);
+        clearRenderViewSelection(node);
 
         // Trigger a selection update so the selection will be set again.
-        if (auto* renderView = node->document().renderView()) {
+        if (auto* renderView = node.document().renderView()) {
             m_pendingSelectionUpdate = true;
             renderView->setNeedsLayout();
         }
index a9dc92c3e17232150ba1149ecea44338af758e17..f988c6cd21a5fd6cf2f9945186a0b9533372621b 100644 (file)
@@ -103,7 +103,7 @@ public:
     void setCaretPosition(const VisiblePosition&);
     WEBCORE_EXPORT void clear() { setCaretPosition(VisiblePosition()); }
 
-    void nodeWillBeRemoved(Node*);
+    void nodeWillBeRemoved(Node&);
 
 private:
     VisiblePosition m_position;
@@ -187,7 +187,7 @@ public:
 
     void debugRenderer(RenderObject*, bool selected) const;
 
-    void nodeWillBeRemoved(Node*);
+    void nodeWillBeRemoved(Node&);
     void textWasReplaced(CharacterData*, unsigned offset, unsigned oldLength, unsigned newLength);
 
     void setCaretVisible(bool caretIsVisible) { setCaretVisibility(caretIsVisible ? Visible : Hidden); }
@@ -276,7 +276,7 @@ private:
 
     bool setSelectionWithoutUpdatingAppearance(const VisibleSelection&, SetSelectionOptions, CursorAlignOnScroll, TextGranularity);
 
-    void respondToNodeModification(Node*, bool baseRemoved, bool extentRemoved, bool startRemoved, bool endRemoved);
+    void respondToNodeModification(Node&, bool baseRemoved, bool extentRemoved, bool startRemoved, bool endRemoved);
     TextDirection directionOfEnclosingBlock();
     TextDirection directionOfSelection();
 
index 458363b047f7b607aa58886a0ca941d45843dbcb..95a4c464545f04a4eafe69275428dd14ec6f7b21 100644 (file)
@@ -1391,7 +1391,7 @@ void ReplaceSelectionCommand::mergeTextNodesAroundPosition(Position& position, P
         return;
 
     if (is<Text>(text->previousSibling())) {
-        RefPtr<Text> previous = downcast<Text>(text->previousSibling());
+        Ref<Text> previous(downcast<Text>(*text->previousSibling()));
         insertTextIntoNode(text, 0, previous->data());
 
         if (positionIsOffsetInAnchor)
@@ -1402,27 +1402,27 @@ void ReplaceSelectionCommand::mergeTextNodesAroundPosition(Position& position, P
         if (positionOnlyToBeUpdatedIsOffsetInAnchor) {
             if (positionOnlyToBeUpdated.containerNode() == text)
                 positionOnlyToBeUpdated.moveToOffset(previous->length() + positionOnlyToBeUpdated.offsetInContainerNode());
-            else if (positionOnlyToBeUpdated.containerNode() == previous)
+            else if (positionOnlyToBeUpdated.containerNode() == previous.ptr())
                 positionOnlyToBeUpdated.moveToPosition(text, positionOnlyToBeUpdated.offsetInContainerNode());
         } else
             updatePositionForNodeRemoval(positionOnlyToBeUpdated, previous.get());
 
-        removeNode(previous);
+        removeNode(previous.ptr());
     }
     if (is<Text>(text->nextSibling())) {
-        RefPtr<Text> next = downcast<Text>(text->nextSibling());
+        Ref<Text> next(downcast<Text>(*text->nextSibling()));
         unsigned originalLength = text->length();
         insertTextIntoNode(text, originalLength, next->data());
 
         if (!positionIsOffsetInAnchor)
             updatePositionForNodeRemoval(position, next.get());
 
-        if (positionOnlyToBeUpdatedIsOffsetInAnchor && positionOnlyToBeUpdated.containerNode() == next)
+        if (positionOnlyToBeUpdatedIsOffsetInAnchor && positionOnlyToBeUpdated.containerNode() == next.ptr())
             positionOnlyToBeUpdated.moveToPosition(text, originalLength + positionOnlyToBeUpdated.offsetInContainerNode());
         else
             updatePositionForNodeRemoval(positionOnlyToBeUpdated, next.get());
 
-        removeNode(next);
+        removeNode(next.ptr());
     }
 }
 
index 6fb4acb7ac09660561f9d38ec1d5abbea7c36862..09735a4dc80010f5f1c53ac7c7aeedb8fb99749a 100644 (file)
@@ -984,32 +984,32 @@ unsigned numEnclosingMailBlockquotes(const Position& p)
     return num;
 }
 
-void updatePositionForNodeRemoval(Position& position, Node* node)
+void updatePositionForNodeRemoval(Position& position, Node& node)
 {
     if (position.isNull())
         return;
     switch (position.anchorType()) {
     case Position::PositionIsBeforeChildren:
-        if (node->containsIncludingShadowDOM(position.containerNode()))
-            position = positionInParentBeforeNode(node);
+        if (node.containsIncludingShadowDOM(position.containerNode()))
+            position = positionInParentBeforeNode(&node);
         break;
     case Position::PositionIsAfterChildren:
-        if (node->containsIncludingShadowDOM(position.containerNode()))
-            position = positionInParentBeforeNode(node);
+        if (node.containsIncludingShadowDOM(position.containerNode()))
+            position = positionInParentBeforeNode(&node);
         break;
     case Position::PositionIsOffsetInAnchor:
-        if (position.containerNode() == node->parentNode() && static_cast<unsigned>(position.offsetInContainerNode()) > node->computeNodeIndex())
+        if (position.containerNode() == node.parentNode() && static_cast<unsigned>(position.offsetInContainerNode()) > node.computeNodeIndex())
             position.moveToOffset(position.offsetInContainerNode() - 1);
-        else if (node->containsIncludingShadowDOM(position.containerNode()))
-            position = positionInParentBeforeNode(node);
+        else if (node.containsIncludingShadowDOM(position.containerNode()))
+            position = positionInParentBeforeNode(&node);
         break;
     case Position::PositionIsAfterAnchor:
-        if (node->containsIncludingShadowDOM(position.anchorNode()))
-            position = positionInParentAfterNode(node);
+        if (node.containsIncludingShadowDOM(position.anchorNode()))
+            position = positionInParentAfterNode(&node);
         break;
     case Position::PositionIsBeforeAnchor:
-        if (node->containsIncludingShadowDOM(position.anchorNode()))
-            position = positionInParentBeforeNode(node);
+        if (node.containsIncludingShadowDOM(position.anchorNode()))
+            position = positionInParentBeforeNode(&node);
         break;
     }
 }
index 54f973867226ff83d6dbf2963bfb64acb45ba3ab..d249cf9aafa3922998a6cc5a93f8137cf386a8ae 100644 (file)
@@ -170,7 +170,7 @@ bool isAtUnsplittableElement(const Position&);
 // miscellaneous functions on Position
 
 unsigned numEnclosingMailBlockquotes(const Position&);
-void updatePositionForNodeRemoval(Position&, Node*);
+void updatePositionForNodeRemoval(Position&, Node&);
 
 // -------------------------------------------------------------------------
 // VisiblePosition
index 92fe65ca25a12d3c55edcbb62d53dbb84db15be7..d09dd603593f0dc3423d08147bf5c96d9c894397 100644 (file)
@@ -503,10 +503,10 @@ void EventHandler::clear()
     m_didLongPressInvokeContextMenu = false;
 }
 
-void EventHandler::nodeWillBeRemoved(Node* nodeToBeRemoved)
+void EventHandler::nodeWillBeRemoved(Node& nodeToBeRemoved)
 {
-    if (nodeToBeRemoved->contains(m_clickNode.get()))
-        m_clickNode = 0;
+    if (nodeToBeRemoved.contains(m_clickNode.get()))
+        m_clickNode = nullptr;
 }
 
 static void setSelectionIfNeeded(FrameSelection& selection, const VisibleSelection& newSelection)
index 9cd857ac690fc2f59e22998a39d26ca923a911b3..59dfe0a24eade3cfeee7169531b0301e83b52877 100644 (file)
@@ -125,7 +125,7 @@ public:
     ~EventHandler();
 
     void clear();
-    void nodeWillBeRemoved(Node*);
+    void nodeWillBeRemoved(Node&);
 
 #if ENABLE(DRAG_SUPPORT)
     void updateSelectionForMouseDrag();