Drop [UsePointersEvenForNonNullableObjectArguments] from Range
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Apr 2016 16:07:18 +0000 (16:07 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Apr 2016 16:07:18 +0000 (16:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=156805

Reviewed by Youenn Fablet.

Source/WebCore:

No new tests, no web-exposed behavior change.

* accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::rangeForNodeContents):
(WebCore::characterOffsetsInOrder):
(WebCore::setRangeStartOrEndWithCharacterOffset):
(WebCore::AXObjectCache::startOrEndCharacterOffsetForRange):
(WebCore::AXObjectCache::previousBoundary):
* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::selectText):
* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::documentBasedSelectedTextRange):
* dom/Node.cpp:
(WebCore::Node::textRects):
* dom/Range.cpp:
(WebCore::Range::Range):
(WebCore::Range::setDocument):
(WebCore::Range::setStart):
(WebCore::Range::setEnd):
(WebCore::Range::isPointInRange):
(WebCore::Range::comparePoint):
(WebCore::Range::compareNode):
(WebCore::Range::compareBoundaryPoints):
(WebCore::Range::compareBoundaryPointsForBindings):
(WebCore::Range::intersectsNode):
(WebCore::Range::processContents):
(WebCore::Range::insertNode):
(WebCore::Range::checkNodeWOffset):
(WebCore::Range::setStartAfter):
(WebCore::Range::setEndBefore):
(WebCore::Range::setEndAfter):
(WebCore::Range::selectNode):
(WebCore::Range::selectNodeContents):
(WebCore::Range::surroundContents):
(WebCore::Range::setStartBefore):
(WebCore::Range::contains):
(WebCore::rangesOverlap):
(WebCore::rangeOfContents):
(WebCore::boundaryNodeChildrenWillBeRemoved):
(WebCore::boundaryTextNodesMerged):
(WebCore::boundaryTextNodesSplit):
(WebCore::Range::expand):
(WebCore::checkForDifferentRootContainer): Deleted.
(WebCore::highestAncestorUnderCommonRoot): Deleted.
(WebCore::childOfCommonRootBeforeOffset): Deleted.
(WebCore::deleteCharacterData): Deleted.
(WebCore::Range::toString): Deleted.
(WebCore::Range::toHTML): Deleted.
(WebCore::Range::text): Deleted.
(WebCore::Range::cloneRange): Deleted.
(WebCore::Range::absoluteTextRects): Deleted.
(WebCore::Range::absoluteTextQuads): Deleted.
(WebCore::boundaryNodeChildrenChanged): Deleted.
(WebCore::boundaryNodeWillBeRemoved): Deleted.
(WebCore::Range::nodeWillBeRemoved): Deleted.
(WebCore::boundaryTextRemoved): Deleted.
(WebCore::Range::getBoundingClientRect): Deleted.
(WebCore::Range::getBorderAndTextQuads): Deleted.
* dom/Range.h:
* dom/Range.idl:
* dom/RangeBoundaryPoint.h:
(WebCore::RangeBoundaryPoint::set):
(WebCore::RangeBoundaryPoint::setToStartOfNode):
(WebCore::RangeBoundaryPoint::setToEndOfNode):
* editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::applyAlternativeTextToRange):
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::fixRangeAndApplyInlineStyle):
* editing/Editor.cpp:
(WebCore::Editor::advanceToNextMisspelling):
(WebCore::Editor::rangeOfString):
(WebCore::isFrameInRange):
(WebCore::Editor::countMatchesForText):
* editing/EditorCommand.cpp:
(WebCore::unionDOMRanges):
(WebCore::executeDeleteToMark):
(WebCore::executeSelectToMark):
* editing/FormatBlockCommand.cpp:
(WebCore::FormatBlockCommand::formatRange):
* editing/FrameSelection.cpp:
(WebCore::FrameSelection::respondToNodeModification):
* editing/InsertListCommand.cpp:
(WebCore::InsertListCommand::doApplyForSingleParagraph):
* editing/TextCheckingHelper.cpp:
(WebCore::TextCheckingParagraph::offsetTo):
* editing/TextIterator.cpp:
(WebCore::CharacterIterator::range):
(WebCore::BackwardsCharacterIterator::range):
(WebCore::TextIterator::rangeFromLocationAndLength):
(WebCore::TextIterator::getLocationAndLengthFromRange):
(WebCore::findPlainText):
* editing/VisiblePosition.cpp:
(WebCore::setStart):
(WebCore::setEnd):
* editing/VisibleSelection.cpp:
(WebCore::makeSearchRange):
* editing/VisibleUnits.cpp:
(WebCore::previousBoundary):
(WebCore::nextBoundary):
* editing/htmlediting.cpp:
(WebCore::visiblePositionForIndexUsingCharacterIterator):
(WebCore::isNodeVisiblyContainedWithin):
* editing/htmlediting.h:
* editing/mac/EditorMac.mm:
(WebCore::Editor::adjustedSelectionRange):
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::contextMenuItemSelected):
* page/DOMSelection.cpp:
(WebCore::DOMSelection::addRange):
* page/DragController.cpp:
(WebCore::selectElement):
* page/EventHandler.cpp:
(WebCore::EventHandler::dispatchMouseEvent):
* page/Page.cpp:
(WebCore::Page::findStringMatchingRanges):
* page/TextIndicator.cpp:
(WebCore::hasNonInlineOrReplacedElements):
* rendering/RenderNamedFlowThread.cpp:
(WebCore::RenderNamedFlowThread::getRanges):

Source/WebKit/mac:

* WebView/WebFrame.mm:
(-[WebFrame _smartDeleteRangeForProposedRange:]):

Source/WebKit2:

* WebProcess/InjectedBundle/API/mac/WKDOMRange.mm:
(-[WKDOMRange setStart:offset:]):
(-[WKDOMRange setEnd:offset:]):
(-[WKDOMRange selectNode:]):
(-[WKDOMRange selectNodeContents:]):
* WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::contentsAsString):

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

42 files changed:
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AXObjectCache.cpp
Source/WebCore/accessibility/AccessibilityObject.cpp
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/accessibility/atk/WebKitAccessibleUtil.cpp
Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm
Source/WebCore/bindings/objc/DOMUIKitExtensions.mm
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Range.cpp
Source/WebCore/dom/Range.h
Source/WebCore/dom/Range.idl
Source/WebCore/dom/RangeBoundaryPoint.h
Source/WebCore/editing/AlternativeTextController.cpp
Source/WebCore/editing/ApplyStyleCommand.cpp
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/EditorCommand.cpp
Source/WebCore/editing/FormatBlockCommand.cpp
Source/WebCore/editing/FrameSelection.cpp
Source/WebCore/editing/FrameSelection.h
Source/WebCore/editing/InsertListCommand.cpp
Source/WebCore/editing/TextCheckingHelper.cpp
Source/WebCore/editing/TextIterator.cpp
Source/WebCore/editing/VisiblePosition.cpp
Source/WebCore/editing/VisibleSelection.cpp
Source/WebCore/editing/VisibleUnits.cpp
Source/WebCore/editing/htmlediting.cpp
Source/WebCore/editing/htmlediting.h
Source/WebCore/editing/mac/EditorMac.mm
Source/WebCore/page/ContextMenuController.cpp
Source/WebCore/page/DOMSelection.cpp
Source/WebCore/page/DragController.cpp
Source/WebCore/page/EventHandler.cpp
Source/WebCore/page/Page.cpp
Source/WebCore/page/TextIndicator.cpp
Source/WebCore/rendering/RenderNamedFlowThread.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebFrame.mm
Source/WebKit/win/WebView.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMRange.mm
Source/WebKit2/WebProcess/WebPage/WebFrame.cpp
Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

index 94d4eb9..5c00bfc 100644 (file)
@@ -1,5 +1,132 @@
 2016-04-21  Chris Dumez  <cdumez@apple.com>
 
+        Drop [UsePointersEvenForNonNullableObjectArguments] from Range
+        https://bugs.webkit.org/show_bug.cgi?id=156805
+
+        Reviewed by Youenn Fablet.
+
+        No new tests, no web-exposed behavior change.
+
+        * accessibility/AXObjectCache.cpp:
+        (WebCore::AXObjectCache::rangeForNodeContents):
+        (WebCore::characterOffsetsInOrder):
+        (WebCore::setRangeStartOrEndWithCharacterOffset):
+        (WebCore::AXObjectCache::startOrEndCharacterOffsetForRange):
+        (WebCore::AXObjectCache::previousBoundary):
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::AccessibilityObject::selectText):
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::AccessibilityRenderObject::documentBasedSelectedTextRange):
+        * dom/Node.cpp:
+        (WebCore::Node::textRects):
+        * dom/Range.cpp:
+        (WebCore::Range::Range):
+        (WebCore::Range::setDocument):
+        (WebCore::Range::setStart):
+        (WebCore::Range::setEnd):
+        (WebCore::Range::isPointInRange):
+        (WebCore::Range::comparePoint):
+        (WebCore::Range::compareNode):
+        (WebCore::Range::compareBoundaryPoints):
+        (WebCore::Range::compareBoundaryPointsForBindings):
+        (WebCore::Range::intersectsNode):
+        (WebCore::Range::processContents):
+        (WebCore::Range::insertNode):
+        (WebCore::Range::checkNodeWOffset):
+        (WebCore::Range::setStartAfter):
+        (WebCore::Range::setEndBefore):
+        (WebCore::Range::setEndAfter):
+        (WebCore::Range::selectNode):
+        (WebCore::Range::selectNodeContents):
+        (WebCore::Range::surroundContents):
+        (WebCore::Range::setStartBefore):
+        (WebCore::Range::contains):
+        (WebCore::rangesOverlap):
+        (WebCore::rangeOfContents):
+        (WebCore::boundaryNodeChildrenWillBeRemoved):
+        (WebCore::boundaryTextNodesMerged):
+        (WebCore::boundaryTextNodesSplit):
+        (WebCore::Range::expand):
+        (WebCore::checkForDifferentRootContainer): Deleted.
+        (WebCore::highestAncestorUnderCommonRoot): Deleted.
+        (WebCore::childOfCommonRootBeforeOffset): Deleted.
+        (WebCore::deleteCharacterData): Deleted.
+        (WebCore::Range::toString): Deleted.
+        (WebCore::Range::toHTML): Deleted.
+        (WebCore::Range::text): Deleted.
+        (WebCore::Range::cloneRange): Deleted.
+        (WebCore::Range::absoluteTextRects): Deleted.
+        (WebCore::Range::absoluteTextQuads): Deleted.
+        (WebCore::boundaryNodeChildrenChanged): Deleted.
+        (WebCore::boundaryNodeWillBeRemoved): Deleted.
+        (WebCore::Range::nodeWillBeRemoved): Deleted.
+        (WebCore::boundaryTextRemoved): Deleted.
+        (WebCore::Range::getBoundingClientRect): Deleted.
+        (WebCore::Range::getBorderAndTextQuads): Deleted.
+        * dom/Range.h:
+        * dom/Range.idl:
+        * dom/RangeBoundaryPoint.h:
+        (WebCore::RangeBoundaryPoint::set):
+        (WebCore::RangeBoundaryPoint::setToStartOfNode):
+        (WebCore::RangeBoundaryPoint::setToEndOfNode):
+        * editing/AlternativeTextController.cpp:
+        (WebCore::AlternativeTextController::applyAlternativeTextToRange):
+        * editing/ApplyStyleCommand.cpp:
+        (WebCore::ApplyStyleCommand::fixRangeAndApplyInlineStyle):
+        * editing/Editor.cpp:
+        (WebCore::Editor::advanceToNextMisspelling):
+        (WebCore::Editor::rangeOfString):
+        (WebCore::isFrameInRange):
+        (WebCore::Editor::countMatchesForText):
+        * editing/EditorCommand.cpp:
+        (WebCore::unionDOMRanges):
+        (WebCore::executeDeleteToMark):
+        (WebCore::executeSelectToMark):
+        * editing/FormatBlockCommand.cpp:
+        (WebCore::FormatBlockCommand::formatRange):
+        * editing/FrameSelection.cpp:
+        (WebCore::FrameSelection::respondToNodeModification):
+        * editing/InsertListCommand.cpp:
+        (WebCore::InsertListCommand::doApplyForSingleParagraph):
+        * editing/TextCheckingHelper.cpp:
+        (WebCore::TextCheckingParagraph::offsetTo):
+        * editing/TextIterator.cpp:
+        (WebCore::CharacterIterator::range):
+        (WebCore::BackwardsCharacterIterator::range):
+        (WebCore::TextIterator::rangeFromLocationAndLength):
+        (WebCore::TextIterator::getLocationAndLengthFromRange):
+        (WebCore::findPlainText):
+        * editing/VisiblePosition.cpp:
+        (WebCore::setStart):
+        (WebCore::setEnd):
+        * editing/VisibleSelection.cpp:
+        (WebCore::makeSearchRange):
+        * editing/VisibleUnits.cpp:
+        (WebCore::previousBoundary):
+        (WebCore::nextBoundary):
+        * editing/htmlediting.cpp:
+        (WebCore::visiblePositionForIndexUsingCharacterIterator):
+        (WebCore::isNodeVisiblyContainedWithin):
+        * editing/htmlediting.h:
+        * editing/mac/EditorMac.mm:
+        (WebCore::Editor::adjustedSelectionRange):
+        * page/ContextMenuController.cpp:
+        (WebCore::ContextMenuController::contextMenuItemSelected):
+        * page/DOMSelection.cpp:
+        (WebCore::DOMSelection::addRange):
+        * page/DragController.cpp:
+        (WebCore::selectElement):
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::dispatchMouseEvent):
+        * page/Page.cpp:
+        (WebCore::Page::findStringMatchingRanges):
+        * page/TextIndicator.cpp:
+        (WebCore::hasNonInlineOrReplacedElements):
+        * rendering/RenderNamedFlowThread.cpp:
+        (WebCore::RenderNamedFlowThread::getRanges):
+
+2016-04-21  Chris Dumez  <cdumez@apple.com>
+
         Drop [UsePointersEvenForNonNullableObjectArguments] from DOMURL
         https://bugs.webkit.org/show_bug.cgi?id=156797
 
index 4dd3476..595a387 100644 (file)
@@ -1606,7 +1606,7 @@ RefPtr<Range> AXObjectCache::rangeForNodeContents(Node* node)
         return nullptr;
     RefPtr<Range> range = Range::create(*document);
     ExceptionCode ec = 0;
-    range->selectNodeContents(node, ec);
+    range->selectNodeContents(*node, ec);
     return ec ? nullptr : range;
 }
     
@@ -1635,7 +1635,8 @@ static bool characterOffsetsInOrder(const CharacterOffset& characterOffset1, con
     
     RefPtr<Range> range1 = AXObjectCache::rangeForNodeContents(node1);
     RefPtr<Range> range2 = AXObjectCache::rangeForNodeContents(node2);
-    return range1->compareBoundaryPoints(Range::START_TO_START, range2.get(), IGNORE_EXCEPTION) <= 0;
+
+    return !range2 || range1->compareBoundaryPoints(Range::START_TO_START, *range2, IGNORE_EXCEPTION) <= 0;
 }
 
 static Node* resetNodeAndOffsetForReplacedNode(Node* replacedNode, int& offset, int characterCount)
@@ -1663,6 +1664,7 @@ static void setRangeStartOrEndWithCharacterOffset(RefPtr<Range> range, const Cha
     
     int offset = characterOffset.startIndex + characterOffset.offset;
     Node* node = characterOffset.node;
+    ASSERT(node);
     
     bool replacedNodeOrBR = isReplacedNodeOrBR(node);
     // For the non text node that has no children, we should create the range with its parent, otherwise the range would be collapsed.
@@ -1673,10 +1675,15 @@ static void setRangeStartOrEndWithCharacterOffset(RefPtr<Range> range, const Cha
     if (replacedNodeOrBR || noChildren)
         node = resetNodeAndOffsetForReplacedNode(node, offset, characterCount);
     
+    if (!node) {
+        ec = TypeError;
+        return;
+    }
+
     if (isStart)
-        range->setStart(node, offset, ec);
+        range->setStart(*node, offset, ec);
     else
-        range->setEnd(node, offset, ec);
+        range->setEnd(*node, offset, ec);
 }
 
 RefPtr<Range> AXObjectCache::rangeForUnorderedCharacterOffsets(const CharacterOffset& characterOffset1, const CharacterOffset& characterOffset2)
@@ -1743,18 +1750,18 @@ CharacterOffset AXObjectCache::startOrEndCharacterOffsetForRange(RefPtr<Range> r
     // If it's end text marker, we want to go to the end of the range, and stay within the range.
     bool stayWithinRange = !isStart;
     
-    RefPtr<Range> copyRange = range;
+    Ref<Range> copyRange = *range;
     // Change the start of the range, so the character offset starts from node beginning.
     int offset = 0;
-    Node* node = &copyRange->startContainer();
-    if (node->offsetInCharacters()) {
+    Node& node = copyRange->startContainer();
+    if (node.offsetInCharacters()) {
         copyRange = Range::create(range->ownerDocument(), &range->startContainer(), range->startOffset(), &range->endContainer(), range->endOffset());
-        CharacterOffset nodeStartOffset = traverseToOffsetInRange(rangeForNodeContents(node), 0);
+        CharacterOffset nodeStartOffset = traverseToOffsetInRange(rangeForNodeContents(&node), 0);
         offset = std::max(copyRange->startOffset() - nodeStartOffset.startIndex, 0);
         copyRange->setStart(node, nodeStartOffset.startIndex);
     }
     
-    return traverseToOffsetInRange(copyRange, offset, isStart ? TraverseOptionDefault : TraverseOptionToNodeEnd, stayWithinRange);
+    return traverseToOffsetInRange(WTFMove(copyRange), offset, isStart ? TraverseOptionDefault : TraverseOptionToNodeEnd, stayWithinRange);
 }
 
 void AXObjectCache::startOrEndTextMarkerDataForRange(TextMarkerData& textMarkerData, RefPtr<Range> range, bool isStart)
@@ -2213,7 +2220,7 @@ CharacterOffset AXObjectCache::previousBoundary(const CharacterOffset& character
     ExceptionCode ec = 0;
     if (requiresContextForWordBoundary(characterBefore(characterOffset))) {
         RefPtr<Range> forwardsScanRange(boundary->document().createRange());
-        forwardsScanRange->setEndAfter(boundary, ec);
+        forwardsScanRange->setEndAfter(*boundary, ec);
         setRangeStartOrEndWithCharacterOffset(forwardsScanRange, characterOffset, true, ec);
         suffixLength = suffixLengthForRange(forwardsScanRange, string);
     }
index a9296dc..5488e19 100644 (file)
@@ -737,7 +737,7 @@ String AccessibilityObject::selectText(AccessibilitySelectTextCriteria* criteria
     
     RefPtr<Range> selectedStringRange = selectionRange();
     // When starting our search again, make this a zero length range so that search forwards will find this selected range if its appropriate.
-    selectedStringRange->setEnd(&selectedStringRange->startContainer(), selectedStringRange->startOffset());
+    selectedStringRange->setEnd(selectedStringRange->startContainer(), selectedStringRange->startOffset());
     
     RefPtr<Range> closestAfterStringRange = nullptr;
     RefPtr<Range> closestBeforeStringRange = nullptr;
index 29f4be5..82c87fb 100644 (file)
@@ -1434,7 +1434,7 @@ PlainTextRange AccessibilityRenderObject::documentBasedSelectedTextRange() const
     
     VisibleSelection visibleSelection = selection();
     RefPtr<Range> currentSelectionRange = visibleSelection.toNormalizedRange();
-    if (!currentSelectionRange || !currentSelectionRange->intersectsNode(node, IGNORE_EXCEPTION))
+    if (!currentSelectionRange || !currentSelectionRange->intersectsNode(*node, IGNORE_EXCEPTION))
         return PlainTextRange();
     
     int start = indexForVisiblePosition(visibleSelection.start());
@@ -1513,8 +1513,9 @@ void AccessibilityRenderObject::setSelectedTextRange(const PlainTextRange& range
         HTMLTextFormControlElement& textControl = downcast<RenderTextControl>(*m_renderer).textFormControlElement();
         textControl.setSelectionRange(range.start, range.start + range.length);
     } else {
-        VisiblePosition start = visiblePositionForIndexUsingCharacterIterator(node(), range.start);
-        VisiblePosition end = visiblePositionForIndexUsingCharacterIterator(node(), range.start + range.length);
+        ASSERT(node());
+        VisiblePosition start = visiblePositionForIndexUsingCharacterIterator(*node(), range.start);
+        VisiblePosition end = visiblePositionForIndexUsingCharacterIterator(*node(), range.start + range.length);
         m_renderer->frame().selection().setSelection(VisibleSelection(start, end), FrameSelection::defaultSetSelectionOptions(UserTriggered));
     }
     
@@ -1876,7 +1877,7 @@ VisiblePosition AccessibilityRenderObject::visiblePositionForIndex(int index) co
     if (!node)
         return VisiblePosition();
 
-    return visiblePositionForIndexUsingCharacterIterator(node, index);
+    return visiblePositionForIndexUsingCharacterIterator(*node, index);
 }
     
 int AccessibilityRenderObject::indexForVisiblePosition(const VisiblePosition& pos) const
index 94a7a23..22d00c4 100644 (file)
@@ -161,7 +161,7 @@ bool selectionBelongsToObject(AccessibilityObject* coreObject, VisibleSelection&
     // node is actually inside the region, at least partially.
     Node* node = coreObject->node();
     Node* lastDescendant = node->lastDescendant();
-    return (range->intersectsNode(node, IGNORE_EXCEPTION)
+    return (range->intersectsNode(*node, IGNORE_EXCEPTION)
         && (&range->endContainer() != node || range->endOffset())
         && (&range->startContainer() != lastDescendant || range->startOffset() != lastOffsetInNode(lastDescendant)));
 }
index e8e0cb2..72f9d97 100644 (file)
@@ -2131,7 +2131,7 @@ static void AXAttributedStringAppendText(NSMutableAttributedString* attrString,
     int startPosition = TextIterator::rangeLength(testRange.get());
     
     ExceptionCode ec;
-    testRange->setEnd(&range->endContainer(), range->endOffset(), ec);
+    testRange->setEnd(range->endContainer(), range->endOffset(), ec);
     ASSERT(&testRange->startContainer() == scope);
     int endPosition = TextIterator::rangeLength(testRange.get());
     return NSMakeRange(startPosition, endPosition - startPosition);
index 86d70fa..eadaa6a 100644 (file)
@@ -113,8 +113,10 @@ using WebCore::VisiblePosition;
     ExceptionCode ignored;
     Position start = frameSelection.selection().start().parentAnchoredEquivalent();
     Position end = frameSelection.selection().end().parentAnchoredEquivalent();
-    range->setStart(start.containerNode(), start.offsetInContainerNode(), ignored);
-    range->setEnd(end.containerNode(), end.offsetInContainerNode(), ignored);
+    if (start.containerNode())
+        range->setStart(*start.containerNode(), start.offsetInContainerNode(), ignored);
+    if (end.containerNode())
+        range->setEnd(*end.containerNode(), end.offsetInContainerNode(), ignored);
 }
 
 - (void)extend:(UInt32)amount inDirection:(WebTextAdjustmentDirection)direction
@@ -129,8 +131,10 @@ using WebCore::VisiblePosition;
     ExceptionCode ignored;
     Position start = frameSelection.selection().start().parentAnchoredEquivalent();
     Position end = frameSelection.selection().end().parentAnchoredEquivalent();
-    range->setStart(start.containerNode(), start.offsetInContainerNode(), ignored);
-    range->setEnd(end.containerNode(), end.offsetInContainerNode(), ignored);
+    if (start.containerNode())
+        range->setStart(*start.containerNode(), start.offsetInContainerNode(), ignored);
+    if (end.containerNode())
+        range->setEnd(*end.containerNode(), end.offsetInContainerNode(), ignored);
 }
 
 - (DOMNode *)firstNode
index f879eee..8360982 100644 (file)
@@ -2314,7 +2314,7 @@ void Node::removedLastRef()
 void Node::textRects(Vector<IntRect>& rects) const
 {
     RefPtr<Range> range = Range::create(document());
-    range->selectNodeContents(const_cast<Node*>(this), IGNORE_EXCEPTION);
+    range->selectNodeContents(const_cast<Node&>(*this), IGNORE_EXCEPTION);
     range->absoluteTextRects(rects);
 }
 
index 7f8b761..3dcf6a8 100644 (file)
@@ -80,6 +80,7 @@ Ref<Range> Range::create(Document& ownerDocument)
     return adoptRef(*new Range(ownerDocument));
 }
 
+// FIXME: startContainer and endContainer should probably be Ref<Node>&&.
 inline Range::Range(Document& ownerDocument, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset)
     : m_ownerDocument(ownerDocument)
     , m_start(&ownerDocument)
@@ -93,8 +94,10 @@ inline Range::Range(Document& ownerDocument, PassRefPtr<Node> startContainer, in
 
     // Simply setting the containers and offsets directly would not do any of the checking
     // that setStart and setEnd do, so we call those functions.
-    setStart(startContainer, startOffset);
-    setEnd(endContainer, endOffset);
+    if (startContainer)
+        setStart(*startContainer, startOffset);
+    if (endContainer)
+        setEnd(*endContainer, endOffset);
 }
 
 Ref<Range> Range::create(Document& ownerDocument, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset)
@@ -129,8 +132,8 @@ void Range::setDocument(Document& document)
     ASSERT(m_ownerDocument.ptr() != &document);
     m_ownerDocument->detachRange(this);
     m_ownerDocument = document;
-    m_start.setToStartOfNode(&document);
-    m_end.setToStartOfNode(&document);
+    m_start.setToStartOfNode(document);
+    m_end.setToStartOfNode(document);
     m_ownerDocument->attachRange(this);
 }
 
@@ -157,13 +160,8 @@ static inline bool checkForDifferentRootContainer(const RangeBoundaryPoint& star
     return startRootContainer != endRootContainer || (Range::compareBoundaryPoints(start, end, ASSERT_NO_EXCEPTION) > 0);
 }
 
-void Range::setStart(PassRefPtr<Node> refNode, int offset, ExceptionCode& ec)
+void Range::setStart(Ref<Node>&& refNode, int offset, ExceptionCode& ec)
 {
-    if (!refNode) {
-        ec = TypeError;
-        return;
-    }
-
     bool didMoveDocument = false;
     if (&refNode->document() != &ownerDocument()) {
         setDocument(refNode->document());
@@ -171,23 +169,18 @@ void Range::setStart(PassRefPtr<Node> refNode, int offset, ExceptionCode& ec)
     }
 
     ec = 0;
-    Node* childNode = checkNodeWOffset(refNode.get(), offset, ec);
+    Node* childNode = checkNodeWOffset(refNode, offset, ec);
     if (ec)
         return;
 
-    m_start.set(refNode, offset, childNode);
+    m_start.set(WTFMove(refNode), offset, childNode);
 
     if (didMoveDocument || checkForDifferentRootContainer(m_start, m_end))
         collapse(true);
 }
 
-void Range::setEnd(PassRefPtr<Node> refNode, int offset, ExceptionCode& ec)
+void Range::setEnd(Ref<Node>&& refNode, int offset, ExceptionCode& ec)
 {
-    if (!refNode) {
-        ec = TypeError;
-        return;
-    }
-
     bool didMoveDocument = false;
     if (&refNode->document() != &ownerDocument()) {
         setDocument(refNode->document());
@@ -195,11 +188,11 @@ void Range::setEnd(PassRefPtr<Node> refNode, int offset, ExceptionCode& ec)
     }
 
     ec = 0;
-    Node* childNode = checkNodeWOffset(refNode.get(), offset, ec);
+    Node* childNode = checkNodeWOffset(refNode, offset, ec);
     if (ec)
         return;
 
-    m_end.set(refNode, offset, childNode);
+    m_end.set(WTFMove(refNode), offset, childNode);
 
     if (didMoveDocument || checkForDifferentRootContainer(m_start, m_end))
         collapse(false);
@@ -208,13 +201,21 @@ void Range::setEnd(PassRefPtr<Node> refNode, int offset, ExceptionCode& ec)
 void Range::setStart(const Position& start, ExceptionCode& ec)
 {
     Position parentAnchored = start.parentAnchoredEquivalent();
-    setStart(parentAnchored.containerNode(), parentAnchored.offsetInContainerNode(), ec);
+    if (!parentAnchored.containerNode()) {
+        ec = TypeError;
+        return;
+    }
+    setStart(*parentAnchored.containerNode(), parentAnchored.offsetInContainerNode(), ec);
 }
 
 void Range::setEnd(const Position& end, ExceptionCode& ec)
 {
     Position parentAnchored = end.parentAnchoredEquivalent();
-    setEnd(parentAnchored.containerNode(), parentAnchored.offsetInContainerNode(), ec);
+    if (!parentAnchored.containerNode()) {
+        ec = TypeError;
+        return;
+    }
+    setEnd(*parentAnchored.containerNode(), parentAnchored.offsetInContainerNode(), ec);
 }
 
 void Range::collapse(bool toStart)
@@ -225,14 +226,9 @@ void Range::collapse(bool toStart)
         m_start = m_end;
 }
 
-bool Range::isPointInRange(Node* refNode, int offset, ExceptionCode& ec)
+bool Range::isPointInRange(Node& refNode, int offset, ExceptionCode& ec)
 {
-    if (!refNode) {
-        ec = TypeError;
-        return false;
-    }
-
-    if (&refNode->document() != &ownerDocument()) {
+    if (&refNode.document() != &ownerDocument()) {
         return false;
     }
 
@@ -241,30 +237,24 @@ bool Range::isPointInRange(Node* refNode, int offset, ExceptionCode& ec)
     if (ec) {
         // DOM4 spec requires us to check whether refNode and start container have the same root first
         // but we do it in the reverse order to avoid O(n) operation here in common case.
-        if (!commonAncestorContainer(refNode, &startContainer()))
+        if (!commonAncestorContainer(&refNode, &startContainer()))
             ec = 0;
         return false;
     }
 
-    bool result = compareBoundaryPoints(refNode, offset, &startContainer(), m_start.offset(), ec) >= 0 && !ec
-        && compareBoundaryPoints(refNode, offset, &endContainer(), m_end.offset(), ec) <= 0 && !ec;
+    bool result = compareBoundaryPoints(&refNode, offset, &startContainer(), m_start.offset(), ec) >= 0 && !ec
+        && compareBoundaryPoints(&refNode, offset, &endContainer(), m_end.offset(), ec) <= 0 && !ec;
     ASSERT(!ec || ec == WRONG_DOCUMENT_ERR);
     ec = 0;
     return result;
 }
 
-short Range::comparePoint(Node* refNode, int offset, ExceptionCode& ec) const
+short Range::comparePoint(Node& refNode, int offset, ExceptionCode& ec) const
 {
     // http://developer.mozilla.org/en/docs/DOM:range.comparePoint
     // This method returns -1, 0 or 1 depending on if the point described by the 
     // refNode node and an offset within the node is before, same as, or after the range respectively.
-
-    if (!refNode) {
-        ec = TypeError;
-        return 0;
-    }
-
-    if (&refNode->document() != &ownerDocument()) {
+    if (&refNode.document() != &ownerDocument()) {
         ec = WRONG_DOCUMENT_ERR;
         return 0;
     }
@@ -274,49 +264,44 @@ short Range::comparePoint(Node* refNode, int offset, ExceptionCode& ec) const
     if (ec) {
         // DOM4 spec requires us to check whether refNode and start container have the same root first
         // but we do it in the reverse order to avoid O(n) operation here in common case.
-        if (!refNode->inDocument() && !commonAncestorContainer(refNode, &startContainer()))
+        if (!refNode.inDocument() && !commonAncestorContainer(&refNode, &startContainer()))
             ec = WRONG_DOCUMENT_ERR;
         return 0;
     }
 
     // compare to start, and point comes before
-    if (compareBoundaryPoints(refNode, offset, &startContainer(), m_start.offset(), ec) < 0)
+    if (compareBoundaryPoints(&refNode, offset, &startContainer(), m_start.offset(), ec) < 0)
         return -1;
 
     if (ec)
         return 0;
 
     // compare to end, and point comes after
-    if (compareBoundaryPoints(refNode, offset, &endContainer(), m_end.offset(), ec) > 0 && !ec)
+    if (compareBoundaryPoints(&refNode, offset, &endContainer(), m_end.offset(), ec) > 0 && !ec)
         return 1;
 
     // point is in the middle of this range, or on the boundary points
     return 0;
 }
 
-Range::CompareResults Range::compareNode(Node* refNode, ExceptionCode& ec) const
+Range::CompareResults Range::compareNode(Node& refNode, ExceptionCode& ec) const
 {
     // http://developer.mozilla.org/en/docs/DOM:range.compareNode
     // This method returns 0, 1, 2, or 3 based on if the node is before, after,
     // before and after(surrounds), or inside the range, respectively
 
-    if (!refNode) {
-        ec = TypeError;
-        return NODE_BEFORE;
-    }
-
-    if (!refNode->inDocument()) {
+    if (!refNode.inDocument()) {
         // Firefox doesn't throw an exception for this case; it returns 0.
         return NODE_BEFORE;
     }
 
-    if (&refNode->document() != &ownerDocument()) {
+    if (&refNode.document() != &ownerDocument()) {
         // Firefox doesn't throw an exception for this case; it returns 0.
         return NODE_BEFORE;
     }
 
-    ContainerNode* parentNode = refNode->parentNode();
-    unsigned nodeIndex = refNode->computeNodeIndex();
+    ContainerNode* parentNode = refNode.parentNode();
+    unsigned nodeIndex = refNode.computeNodeIndex();
     
     if (!parentNode) {
         // if the node is the top document we should return NODE_BEFORE_AND_AFTER
@@ -325,26 +310,22 @@ Range::CompareResults Range::compareNode(Node* refNode, ExceptionCode& ec) const
         return NODE_BEFORE;
     }
 
-    if (comparePoint(parentNode, nodeIndex, ec) < 0) { // starts before
-        if (comparePoint(parentNode, nodeIndex + 1, ec) > 0) // ends after the range
+    // starts before
+    if (comparePoint(*parentNode, nodeIndex, ec) < 0) {
+        if (comparePoint(*parentNode, nodeIndex + 1, ec) > 0) // ends after the range
             return NODE_BEFORE_AND_AFTER;
         return NODE_BEFORE; // ends before or in the range
-    } else { // starts at or after the range start
-        if (comparePoint(parentNode, nodeIndex + 1, ec) > 0) // ends after the range
-            return NODE_AFTER;
-        return NODE_INSIDE; // ends inside the range
     }
+    // starts at or after the range start
+    if (comparePoint(*parentNode, nodeIndex + 1, ec) > 0) // ends after the range
+        return NODE_AFTER;
+    return NODE_INSIDE; // ends inside the range
 }
 
-short Range::compareBoundaryPoints(CompareHow how, const Range* sourceRange, ExceptionCode& ec) const
+short Range::compareBoundaryPoints(CompareHow how, const Range& sourceRange, ExceptionCode& ec) const
 {
-    if (!sourceRange) {
-        ec = TypeError;
-        return 0;
-    }
-
     Node* thisCont = commonAncestorContainer();
-    Node* sourceCont = sourceRange->commonAncestorContainer();
+    Node* sourceCont = sourceRange.commonAncestorContainer();
 
     if (&thisCont->document() != &sourceCont->document()) {
         ec = WRONG_DOCUMENT_ERR;
@@ -364,20 +345,20 @@ short Range::compareBoundaryPoints(CompareHow how, const Range* sourceRange, Exc
 
     switch (how) {
         case START_TO_START:
-            return compareBoundaryPoints(m_start, sourceRange->m_start, ec);
+            return compareBoundaryPoints(m_start, sourceRange.m_start, ec);
         case START_TO_END:
-            return compareBoundaryPoints(m_end, sourceRange->m_start, ec);
+            return compareBoundaryPoints(m_end, sourceRange.m_start, ec);
         case END_TO_END:
-            return compareBoundaryPoints(m_end, sourceRange->m_end, ec);
+            return compareBoundaryPoints(m_end, sourceRange.m_end, ec);
         case END_TO_START:
-            return compareBoundaryPoints(m_start, sourceRange->m_end, ec);
+            return compareBoundaryPoints(m_start, sourceRange.m_end, ec);
     }
 
     ec = SYNTAX_ERR;
     return 0;
 }
 
-short Range::compareBoundaryPointsForBindings(unsigned short compareHow, const Range* sourceRange, ExceptionCode& ec) const
+short Range::compareBoundaryPointsForBindings(unsigned short compareHow, const Range& sourceRange, ExceptionCode& ec) const
 {
     if (compareHow > END_TO_START) {
         ec = NOT_SUPPORTED_ERR;
@@ -495,26 +476,21 @@ void Range::deleteContents(ExceptionCode& ec)
     processContents(Delete, ec);
 }
 
-bool Range::intersectsNode(Node* refNode, ExceptionCode& ec) const
+bool Range::intersectsNode(Node& refNode, ExceptionCode& ec) const
 {
-    if (!refNode) {
-        ec = TypeError;
-        return false;
-    }
-
-    if (!refNode->inDocument() || &refNode->document() != &ownerDocument())
+    if (!refNode.inDocument() || &refNode.document() != &ownerDocument())
         return false;
 
-    ContainerNode* parentNode = refNode->parentNode();
+    ContainerNode* parentNode = refNode.parentNode();
     if (!parentNode)
         return true;
 
-    unsigned nodeIndex = refNode->computeNodeIndex();
+    unsigned nodeIndex = refNode.computeNodeIndex();
 
     // If (parent, offset) is before end and (parent, offset + 1) is after start, return true.
     // Otherwise, return false.
-    short compareFirst = comparePoint(parentNode, nodeIndex, ec);
-    short compareSecond = comparePoint(parentNode, nodeIndex + 1, ec);
+    short compareFirst = comparePoint(*parentNode, nodeIndex, ec);
+    short compareSecond = comparePoint(*parentNode, nodeIndex + 1, ec);
 
     bool isFirstBeforeEnd = m_start == m_end ? compareFirst < 0 : compareFirst <= 0;
     bool isSecondAfterStart = m_start == m_end ? compareSecond > 0 : compareSecond >= 0;
@@ -645,9 +621,9 @@ RefPtr<DocumentFragment> Range::processContents(ActionType action, ExceptionCode
     ec = 0;
     if (action == Extract || action == Delete) {
         if (partialStart && commonRoot->contains(partialStart.get()))
-            setStart(partialStart->parentNode(), partialStart->computeNodeIndex() + 1, ec);
+            setStart(*partialStart->parentNode(), partialStart->computeNodeIndex() + 1, ec);
         else if (partialEnd && commonRoot->contains(partialEnd.get()))
-            setStart(partialEnd->parentNode(), partialEnd->computeNodeIndex(), ec);
+            setStart(*partialEnd->parentNode(), partialEnd->computeNodeIndex(), ec);
         if (ec)
             return nullptr;
         m_end = m_start;
@@ -836,13 +812,8 @@ RefPtr<DocumentFragment> Range::cloneContents(ExceptionCode& ec)
     return processContents(Clone, ec);
 }
 
-void Range::insertNode(RefPtr<Node>&& node, ExceptionCode& ec)
+void Range::insertNode(Ref<Node>&& node, ExceptionCode& ec)
 {
-    if (!node) {
-        ec = TypeError;
-        return;
-    }
-
     bool startIsCharacterData = is<CharacterData>(startContainer());
     if (startIsCharacterData && !startContainer().parentNode()) {
         ec = HIERARCHY_REQUEST_ERR;
@@ -859,7 +830,7 @@ void Range::insertNode(RefPtr<Node>&& node, ExceptionCode& ec)
     Ref<ContainerNode> parent = downcast<ContainerNode>(*parentNode);
 
     ec = 0;
-    if (!parent->ensurePreInsertionValidity(*node, referenceNode.get(), ec))
+    if (!parent->ensurePreInsertionValidity(node, referenceNode.get(), ec))
         return;
 
     EventQueueScope scope;
@@ -869,7 +840,7 @@ void Range::insertNode(RefPtr<Node>&& node, ExceptionCode& ec)
             return;
     }
 
-    if (referenceNode == node)
+    if (referenceNode == node.ptr())
         referenceNode = referenceNode->nextSibling();
 
     node->remove(ec);
@@ -877,17 +848,17 @@ void Range::insertNode(RefPtr<Node>&& node, ExceptionCode& ec)
         return;
 
     unsigned newOffset = referenceNode ? referenceNode->computeNodeIndex() : parent->countChildNodes();
-    if (is<DocumentFragment>(*node))
-        newOffset += downcast<DocumentFragment>(*node).countChildNodes();
+    if (is<DocumentFragment>(node.get()))
+        newOffset += downcast<DocumentFragment>(node.get()).countChildNodes();
     else
         ++newOffset;
 
-    parent->insertBefore(node.releaseNonNull(), referenceNode.get(), ec);
+    parent->insertBefore(WTFMove(node), referenceNode.get(), ec);
     if (ec)
         return;
 
     if (collapsed())
-        setEnd(parent.ptr(), newOffset, ec);
+        setEnd(WTFMove(parent), newOffset, ec);
 }
 
 String Range::toString() const
@@ -950,9 +921,9 @@ void Range::detach()
     // This is now a no-op as per the DOM specification.
 }
 
-Node* Range::checkNodeWOffset(Node* n, int offset, ExceptionCode& ec) const
+Node* Range::checkNodeWOffset(Node& node, int offset, ExceptionCode& ec) const
 {
-    switch (n->nodeType()) {
+    switch (node.nodeType()) {
         case Node::DOCUMENT_TYPE_NODE:
             ec = INVALID_NODE_TYPE_ERR;
             return nullptr;
@@ -960,7 +931,7 @@ Node* Range::checkNodeWOffset(Node* n, int offset, ExceptionCode& ec) const
         case Node::COMMENT_NODE:
         case Node::TEXT_NODE:
         case Node::PROCESSING_INSTRUCTION_NODE:
-            if (static_cast<unsigned>(offset) > downcast<CharacterData>(*n).length())
+            if (static_cast<unsigned>(offset) > downcast<CharacterData>(node).length())
                 ec = INDEX_SIZE_ERR;
             return nullptr;
         case Node::ATTRIBUTE_NODE:
@@ -969,7 +940,7 @@ Node* Range::checkNodeWOffset(Node* n, int offset, ExceptionCode& ec) const
         case Node::ELEMENT_NODE: {
             if (!offset)
                 return nullptr;
-            Node* childBefore = n->traverseToChildAt(offset - 1);
+            Node* childBefore = node.traverseToChildAt(offset - 1);
             if (!childBefore)
                 ec = INDEX_SIZE_ERR;
             return childBefore;
@@ -984,101 +955,71 @@ Ref<Range> Range::cloneRange() const
     return Range::create(ownerDocument(), &startContainer(), m_start.offset(), &endContainer(), m_end.offset());
 }
 
-void Range::setStartAfter(Node* refNode, ExceptionCode& ec)
+void Range::setStartAfter(Node& refNode, ExceptionCode& ec)
 {
-    if (!refNode) {
-        ec = TypeError;
-        return;
-    }
-
-    if (!refNode->parentNode()) {
+    if (!refNode.parentNode()) {
         ec = INVALID_NODE_TYPE_ERR;
         return;
     }
 
-    setStart(refNode->parentNode(), refNode->computeNodeIndex() + 1, ec);
+    setStart(*refNode.parentNode(), refNode.computeNodeIndex() + 1, ec);
 }
 
-void Range::setEndBefore(Node* refNode, ExceptionCode& ec)
+void Range::setEndBefore(Node& refNode, ExceptionCode& ec)
 {
-    if (!refNode) {
-        ec = TypeError;
-        return;
-    }
-
-    if (!refNode->parentNode()) {
+    if (!refNode.parentNode()) {
         ec = INVALID_NODE_TYPE_ERR;
         return;
     }
 
-    setEnd(refNode->parentNode(), refNode->computeNodeIndex(), ec);
+    setEnd(*refNode.parentNode(), refNode.computeNodeIndex(), ec);
 }
 
-void Range::setEndAfter(Node* refNode, ExceptionCode& ec)
+void Range::setEndAfter(Node& refNode, ExceptionCode& ec)
 {
-    if (!refNode) {
-        ec = TypeError;
-        return;
-    }
-
-    if (!refNode->parentNode()) {
+    if (!refNode.parentNode()) {
         ec = INVALID_NODE_TYPE_ERR;
         return;
     }
 
-    setEnd(refNode->parentNode(), refNode->computeNodeIndex() + 1, ec);
+    setEnd(*refNode.parentNode(), refNode.computeNodeIndex() + 1, ec);
 }
 
-void Range::selectNode(Node* refNode, ExceptionCode& ec)
+void Range::selectNode(Node& refNode, ExceptionCode& ec)
 {
-    if (!refNode) {
-        ec = TypeError;
-        return;
-    }
-
-    if (!refNode->parentNode()) {
+    if (!refNode.parentNode()) {
         ec = INVALID_NODE_TYPE_ERR;
         return;
     }
 
-    if (&ownerDocument() != &refNode->document())
-        setDocument(refNode->document());
+    if (&ownerDocument() != &refNode.document())
+        setDocument(refNode.document());
 
-    unsigned index = refNode->computeNodeIndex();
+    unsigned index = refNode.computeNodeIndex();
     ec = 0;
-    setStart(refNode->parentNode(), index, ec);
+    setStart(*refNode.parentNode(), index, ec);
     if (ec)
         return;
-    setEnd(refNode->parentNode(), index + 1, ec);
+    setEnd(*refNode.parentNode(), index + 1, ec);
 }
 
-void Range::selectNodeContents(Node* refNode, ExceptionCode& ec)
+void Range::selectNodeContents(Node& refNode, ExceptionCode& ec)
 {
-    if (!refNode) {
-        ec = TypeError;
-        return;
-    }
-
-    if (refNode->isDocumentTypeNode()) {
+    if (refNode.isDocumentTypeNode()) {
         ec = INVALID_NODE_TYPE_ERR;
         return;
     }
 
-    if (&ownerDocument() != &refNode->document())
-        setDocument(refNode->document());
+    if (&ownerDocument() != &refNode.document())
+        setDocument(refNode.document());
 
     m_start.setToStartOfNode(refNode);
     m_end.setToEndOfNode(refNode);
 }
 
-void Range::surroundContents(PassRefPtr<Node> passNewParent, ExceptionCode& ec)
+void Range::surroundContents(Node& passNewParent, ExceptionCode& ec)
 {
-    RefPtr<Node> newParent = passNewParent;
-
-    if (!newParent) {
-        ec = TypeError;
-        return;
-    }
+    Ref<Node> newParent = passNewParent;
 
     // INVALID_STATE_ERR: Raised if the Range partially selects a non-Text node.
     // https://dom.spec.whatwg.org/#dom-range-surroundcontents (step 1).
@@ -1133,7 +1074,7 @@ void Range::surroundContents(PassRefPtr<Node> passNewParent, ExceptionCode& ec)
 
     ec = 0;
     while (Node* n = newParent->firstChild()) {
-        downcast<ContainerNode>(*newParent).removeChild(*n, ec);
+        downcast<ContainerNode>(newParent.get()).removeChild(*n, ec);
         if (ec)
             return;
     }
@@ -1146,22 +1087,17 @@ void Range::surroundContents(PassRefPtr<Node> passNewParent, ExceptionCode& ec)
     newParent->appendChild(fragment.release(), ec);
     if (ec)
         return;
-    selectNode(newParent.get(), ec);
+    selectNode(newParent, ec);
 }
 
-void Range::setStartBefore(Node* refNode, ExceptionCode& ec)
+void Range::setStartBefore(Node& refNode, ExceptionCode& ec)
 {
-    if (!refNode) {
-        ec = TypeError;
-        return;
-    }
-
-    if (!refNode->parentNode()) {
+    if (!refNode.parentNode()) {
         ec = INVALID_NODE_TYPE_ERR;
         return;
     }
 
-    setStart(refNode->parentNode(), refNode->computeNodeIndex(), ec);
+    setStart(*refNode.parentNode(), refNode.computeNodeIndex(), ec);
 }
 
 Node* Range::firstNode() const
@@ -1539,11 +1475,11 @@ bool Range::contains(const Range& other) const
     if (commonAncestorContainer()->ownerDocument() != other.commonAncestorContainer()->ownerDocument())
         return false;
 
-    short startToStart = compareBoundaryPoints(Range::START_TO_START, &other, ASSERT_NO_EXCEPTION);
+    short startToStart = compareBoundaryPoints(Range::START_TO_START, other, ASSERT_NO_EXCEPTION);
     if (startToStart > 0)
         return false;
 
-    short endToEnd = compareBoundaryPoints(Range::END_TO_END, &other, ASSERT_NO_EXCEPTION);
+    short endToEnd = compareBoundaryPoints(Range::END_TO_END, other, ASSERT_NO_EXCEPTION);
     return endToEnd >= 0;
 }
 
@@ -1575,19 +1511,19 @@ bool rangesOverlap(const Range* a, const Range* b)
     if (a->commonAncestorContainer()->ownerDocument() != b->commonAncestorContainer()->ownerDocument())
         return false;
 
-    short startToStart = a->compareBoundaryPoints(Range::START_TO_START, b, ASSERT_NO_EXCEPTION);
-    short endToEnd = a->compareBoundaryPoints(Range::END_TO_END, b, ASSERT_NO_EXCEPTION);
+    short startToStart = a->compareBoundaryPoints(Range::START_TO_START, *b, ASSERT_NO_EXCEPTION);
+    short endToEnd = a->compareBoundaryPoints(Range::END_TO_END, *b, ASSERT_NO_EXCEPTION);
 
     // First range contains the second range.
     if (startToStart <= 0 && endToEnd >= 0)
         return true;
 
     // End of first range is inside second range.
-    if (a->compareBoundaryPoints(Range::START_TO_END, b, ASSERT_NO_EXCEPTION) >= 0 && endToEnd <= 0)
+    if (a->compareBoundaryPoints(Range::START_TO_END, *b, ASSERT_NO_EXCEPTION) >= 0 && endToEnd <= 0)
         return true;
 
     // Start of first range is inside second range.
-    if (startToStart >= 0 && a->compareBoundaryPoints(Range::END_TO_START, b, ASSERT_NO_EXCEPTION) <= 0)
+    if (startToStart >= 0 && a->compareBoundaryPoints(Range::END_TO_START, *b, ASSERT_NO_EXCEPTION) <= 0)
         return true;
 
     return false;
@@ -1597,7 +1533,7 @@ Ref<Range> rangeOfContents(Node& node)
 {
     Ref<Range> range = Range::create(node.document());
     int exception = 0;
-    range->selectNodeContents(&node, exception);
+    range->selectNodeContents(node, exception);
     return range;
 }
 
@@ -1621,13 +1557,13 @@ static inline void boundaryNodeChildrenWillBeRemoved(RangeBoundaryPoint& boundar
 {
     for (Node* nodeToBeRemoved = container.firstChild(); nodeToBeRemoved; nodeToBeRemoved = nodeToBeRemoved->nextSibling()) {
         if (boundary.childBefore() == nodeToBeRemoved) {
-            boundary.setToStartOfNode(&container);
+            boundary.setToStartOfNode(container);
             return;
         }
 
         for (Node* n = boundary.container(); n; n = n->parentNode()) {
             if (n == nodeToBeRemoved) {
-                boundary.setToStartOfNode(&container);
+                boundary.setToStartOfNode(container);
                 return;
             }
         }
@@ -1707,9 +1643,9 @@ void Range::textRemoved(Node* text, unsigned offset, unsigned length)
 static inline void boundaryTextNodesMerged(RangeBoundaryPoint& boundary, NodeWithIndex& oldNode, unsigned offset)
 {
     if (boundary.container() == oldNode.node())
-        boundary.set(oldNode.node()->previousSibling(), boundary.offset() + offset, 0);
+        boundary.set(*oldNode.node()->previousSibling(), boundary.offset() + offset, 0);
     else if (boundary.container() == oldNode.node()->parentNode() && boundary.offset() == oldNode.index())
-        boundary.set(oldNode.node()->previousSibling(), offset, 0);
+        boundary.set(*oldNode.node()->previousSibling(), offset, 0);
 }
 
 void Range::textNodesMerged(NodeWithIndex& oldNode, unsigned offset)
@@ -1730,7 +1666,7 @@ static inline void boundaryTextNodesSplit(RangeBoundaryPoint& boundary, Text* ol
         unsigned splitOffset = oldNode->length();
         unsigned boundaryOffset = boundary.offset();
         if (boundaryOffset > splitOffset)
-            boundary.set(oldNode->nextSibling(), boundaryOffset - splitOffset, 0);
+            boundary.set(*oldNode->nextSibling(), boundaryOffset - splitOffset, 0);
         return;
     }
     auto* parent = oldNode->parentNode();
@@ -1771,8 +1707,17 @@ void Range::expand(const String& unit, ExceptionCode& ec)
         end = endOfDocument(end);
     } else
         return;
-    setStart(start.deepEquivalent().containerNode(), start.deepEquivalent().computeOffsetInContainerNode(), ec);
-    setEnd(end.deepEquivalent().containerNode(), end.deepEquivalent().computeOffsetInContainerNode(), ec);
+
+    if (!start.deepEquivalent().containerNode()) {
+        ec = TypeError;
+        return;
+    }
+    setStart(*start.deepEquivalent().containerNode(), start.deepEquivalent().computeOffsetInContainerNode(), ec);
+    if (!end.deepEquivalent().containerNode()) {
+        ec = TypeError;
+        return;
+    }
+    setEnd(*end.deepEquivalent().containerNode(), end.deepEquivalent().computeOffsetInContainerNode(), ec);
 }
 
 Ref<ClientRectList> Range::getClientRects() const
index a22ede6..23ac357 100644 (file)
@@ -66,24 +66,24 @@ public:
 
     Node* commonAncestorContainer() const { return commonAncestorContainer(&startContainer(), &endContainer()); }
     WEBCORE_EXPORT static Node* commonAncestorContainer(Node* containerA, Node* containerB);
-    WEBCORE_EXPORT void setStart(PassRefPtr<Node> container, int offset, ExceptionCode& = ASSERT_NO_EXCEPTION);
-    WEBCORE_EXPORT void setEnd(PassRefPtr<Node> container, int offset, ExceptionCode& = ASSERT_NO_EXCEPTION);
+    WEBCORE_EXPORT void setStart(Ref<Node>&& container, int offset, ExceptionCode& = ASSERT_NO_EXCEPTION);
+    WEBCORE_EXPORT void setEnd(Ref<Node>&& container, int offset, ExceptionCode& = ASSERT_NO_EXCEPTION);
     WEBCORE_EXPORT void collapse(bool toStart);
-    WEBCORE_EXPORT bool isPointInRange(Node* refNode, int offset, ExceptionCode&);
-    short comparePoint(Node* refNode, int offset, ExceptionCode&) const;
+    WEBCORE_EXPORT bool isPointInRange(Node& refNode, int offset, ExceptionCode&);
+    short comparePoint(Node& refNode, int offset, ExceptionCode&) const;
     enum CompareResults { NODE_BEFORE, NODE_AFTER, NODE_BEFORE_AND_AFTER, NODE_INSIDE };
-    CompareResults compareNode(Node* refNode, ExceptionCode&) const;
+    CompareResults compareNode(Node& refNode, ExceptionCode&) const;
     enum CompareHow { START_TO_START, START_TO_END, END_TO_END, END_TO_START };
-    WEBCORE_EXPORT short compareBoundaryPoints(CompareHow, const Range* sourceRange, ExceptionCode&) const;
-    short compareBoundaryPointsForBindings(unsigned short compareHow, const Range* sourceRange, ExceptionCode&) const;
+    WEBCORE_EXPORT short compareBoundaryPoints(CompareHow, const Range& sourceRange, ExceptionCode&) const;
+    short compareBoundaryPointsForBindings(unsigned short compareHow, const Range& sourceRange, ExceptionCode&) const;
     static short compareBoundaryPoints(Node* containerA, int offsetA, Node* containerB, int offsetB, ExceptionCode&);
     static short compareBoundaryPoints(const RangeBoundaryPoint& boundaryA, const RangeBoundaryPoint& boundaryB, ExceptionCode&);
     WEBCORE_EXPORT bool boundaryPointsValid() const;
-    bool intersectsNode(Node* refNode, ExceptionCode&) const;
+    bool intersectsNode(Node& refNode, ExceptionCode&) const;
     void deleteContents(ExceptionCode&);
     RefPtr<DocumentFragment> extractContents(ExceptionCode&);
     RefPtr<DocumentFragment> cloneContents(ExceptionCode&);
-    void insertNode(RefPtr<Node>&&, ExceptionCode&);
+    void insertNode(Ref<Node>&&, ExceptionCode&);
     String toString() const;
 
     String toHTML() const;
@@ -94,13 +94,13 @@ public:
     void detach();
     WEBCORE_EXPORT Ref<Range> cloneRange() const;
 
-    WEBCORE_EXPORT void setStartAfter(Node*, ExceptionCode& = ASSERT_NO_EXCEPTION);
-    WEBCORE_EXPORT void setEndBefore(Node*, ExceptionCode& = ASSERT_NO_EXCEPTION);
-    WEBCORE_EXPORT void setEndAfter(Node*, ExceptionCode& = ASSERT_NO_EXCEPTION);
-    WEBCORE_EXPORT void selectNode(Node*, ExceptionCode& = ASSERT_NO_EXCEPTION);
-    WEBCORE_EXPORT void selectNodeContents(Node*, ExceptionCode&);
-    void surroundContents(PassRefPtr<Node>, ExceptionCode&);
-    WEBCORE_EXPORT void setStartBefore(Node*, ExceptionCode&);
+    WEBCORE_EXPORT void setStartAfter(Node&, ExceptionCode& = ASSERT_NO_EXCEPTION);
+    WEBCORE_EXPORT void setEndBefore(Node&, ExceptionCode& = ASSERT_NO_EXCEPTION);
+    WEBCORE_EXPORT void setEndAfter(Node&, ExceptionCode& = ASSERT_NO_EXCEPTION);
+    WEBCORE_EXPORT void selectNode(Node&, ExceptionCode& = ASSERT_NO_EXCEPTION);
+    WEBCORE_EXPORT void selectNodeContents(Node&, ExceptionCode&);
+    void surroundContents(Node&, ExceptionCode&);
+    WEBCORE_EXPORT void setStartBefore(Node&, ExceptionCode&);
 
     const Position startPosition() const { return m_start.toPosition(); }
     const Position endPosition() const { return m_end.toPosition(); }
@@ -159,7 +159,7 @@ private:
 
     void setDocument(Document&);
 
-    Node* checkNodeWOffset(Node*, int offset, ExceptionCode&) const;
+    Node* checkNodeWOffset(Node&, int offset, ExceptionCode&) const;
 
     enum ActionType { Delete, Extract, Clone };
     RefPtr<DocumentFragment> processContents(ActionType, ExceptionCode&);
index f23af8c..a758683 100644 (file)
@@ -22,7 +22,6 @@
 [
     Constructor,
     ConstructorCallWith=Document,
-    UsePointersEvenForNonNullableObjectArguments,
     ImplementationLacksVTable,
     ExportMacro=WEBCORE_EXPORT,
 ] interface Range {
index 28e88c3..bf8f9e4 100644 (file)
@@ -45,13 +45,13 @@ public:
 
     void clear();
 
-    void set(PassRefPtr<Node> container, int offset, Node* childBefore);
+    void set(Ref<Node>&& container, int offset, Node* childBefore);
     void setOffset(int offset);
 
     void setToBeforeChild(Node&);
     void setToAfterChild(Node&);
-    void setToStartOfNode(PassRefPtr<Node>);
-    void setToEndOfNode(PassRefPtr<Node>);
+    void setToStartOfNode(Ref<Node>&&);
+    void setToEndOfNode(Ref<Node>&&);
 
     void childBeforeWillBeRemoved();
     void invalidateOffset() const;
@@ -116,12 +116,11 @@ inline void RangeBoundaryPoint::clear()
     m_childBeforeBoundary = nullptr;
 }
 
-inline void RangeBoundaryPoint::set(PassRefPtr<Node> container, int offset, Node* childBefore)
+inline void RangeBoundaryPoint::set(Ref<Node>&& container, int offset, Node* childBefore)
 {
-    ASSERT(container);
     ASSERT(offset >= 0);
     ASSERT(childBefore == (offset ? container->traverseToChildAt(offset - 1) : 0));
-    m_containerNode = container;
+    m_containerNode = WTFMove(container);
     m_offsetInContainer = offset;
     m_childBeforeBoundary = childBefore;
 }
@@ -151,18 +150,16 @@ inline void RangeBoundaryPoint::setToAfterChild(Node& child)
     m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0;
 }
 
-inline void RangeBoundaryPoint::setToStartOfNode(PassRefPtr<Node> container)
+inline void RangeBoundaryPoint::setToStartOfNode(Ref<Node>&& container)
 {
-    ASSERT(container);
-    m_containerNode = container;
+    m_containerNode = WTFMove(container);
     m_offsetInContainer = 0;
     m_childBeforeBoundary = nullptr;
 }
 
-inline void RangeBoundaryPoint::setToEndOfNode(PassRefPtr<Node> container)
+inline void RangeBoundaryPoint::setToEndOfNode(Ref<Node>&& container)
 {
-    ASSERT(container);
-    m_containerNode = container;
+    m_containerNode = WTFMove(container);
     if (m_containerNode->offsetInCharacters()) {
         m_offsetInContainer = m_containerNode->maxCharacterOffset();
         m_childBeforeBoundary = nullptr;
index eda52ea..7231cfa 100644 (file)
@@ -258,7 +258,9 @@ void AlternativeTextController::applyAlternativeTextToRange(const Range* range,
 
     Position startPositionOfRangeWithAlternative = range->startPosition();
     ExceptionCode ec = 0;
-    correctionStartOffsetInParagraphAsRange->setEnd(startPositionOfRangeWithAlternative.containerNode(), startPositionOfRangeWithAlternative.computeOffsetInContainerNode(), ec);
+    if (!startPositionOfRangeWithAlternative.containerNode())
+        return;
+    correctionStartOffsetInParagraphAsRange->setEnd(*startPositionOfRangeWithAlternative.containerNode(), startPositionOfRangeWithAlternative.computeOffsetInContainerNode(), ec);
     if (ec)
         return;
 
index 7b89e0e..ac46488 100644 (file)
@@ -722,7 +722,7 @@ void ApplyStyleCommand::fixRangeAndApplyInlineStyle(EditingStyle* style, const P
     RefPtr<Range> range = Range::create(startNode->document(), start, end);
     Element* editableRoot = startNode->rootEditableElement();
     if (startNode != editableRoot) {
-        while (editableRoot && startNode->parentNode() != editableRoot && isNodeVisiblyContainedWithin(startNode->parentNode(), range.get()))
+        while (editableRoot && startNode->parentNode() != editableRoot && isNodeVisiblyContainedWithin(*startNode->parentNode(), range.get()))
             startNode = startNode->parentNode();
     }
 
index 64bde72..62d06f9 100644 (file)
@@ -419,7 +419,7 @@ void Editor::setDictationPhrasesAsChildOfElement(const Vector<Vector<String>>& d
     
     ExceptionCode ec;    
     RefPtr<Range> context = document().createRange();
-    context->selectNodeContents(&element, ec);
+    context->selectNodeContents(element, ec);
 
     StringBuilder dictationPhrasesBuilder;
     for (auto& interpretations : dictationPhrases)
@@ -627,7 +627,7 @@ void Editor::setTextAsChildOfElement(const String& text, Element* elem)
             elem->remove(ec);    
             
         RefPtr<Range> context = document().createRange();
-        context->selectNodeContents(elem, ec);
+        context->selectNodeContents(*elem, ec);
         Ref<DocumentFragment> fragment = createFragmentFromText(*context.get(), text);
         elem->appendChild(WTFMove(fragment), ec);
     
@@ -1950,14 +1950,16 @@ void Editor::advanceToNextMisspelling(bool startBeforeSelection)
             return;
         
         Position rangeCompliantPosition = position.parentAnchoredEquivalent();
-        spellingSearchRange->setStart(rangeCompliantPosition.deprecatedNode(), rangeCompliantPosition.deprecatedEditingOffset(), IGNORE_EXCEPTION);
+        if (rangeCompliantPosition.deprecatedNode())
+            spellingSearchRange->setStart(*rangeCompliantPosition.deprecatedNode(), rangeCompliantPosition.deprecatedEditingOffset(), IGNORE_EXCEPTION);
         startedWithSelection = false; // won't need to wrap
     }
     
     // topNode defines the whole range we want to operate on 
     Node* topNode = highestEditableRoot(position);
     // FIXME: lastOffsetForEditing() is wrong here if editingIgnoresContent(highestEditableRoot()) returns true (e.g. a <table>)
-    spellingSearchRange->setEnd(topNode, lastOffsetForEditing(topNode), IGNORE_EXCEPTION);
+    if (topNode)
+        spellingSearchRange->setEnd(*topNode, lastOffsetForEditing(topNode), IGNORE_EXCEPTION);
 
     // If spellingSearchRange starts in the middle of a word, advance to the next word so we start checking
     // at a word boundary. Going back by one char and then forward by a word does the trick.
@@ -2011,7 +2013,7 @@ void Editor::advanceToNextMisspelling(bool startBeforeSelection)
             // Stop looking at start of next misspelled word
             CharacterIterator chars(*grammarSearchRange);
             chars.advance(misspellingOffset);
-            grammarSearchRange->setEnd(&chars.range()->startContainer(), chars.range()->startOffset(), IGNORE_EXCEPTION);
+            grammarSearchRange->setEnd(chars.range()->startContainer(), chars.range()->startOffset(), IGNORE_EXCEPTION);
         }
     
         if (isGrammarCheckingEnabled())
@@ -2022,9 +2024,10 @@ void Editor::advanceToNextMisspelling(bool startBeforeSelection)
     // If we found neither bad grammar nor a misspelled word, wrap and try again (but don't bother if we started at the beginning of the
     // block rather than at a selection).
     if (startedWithSelection && !misspelledWord && !badGrammarPhrase) {
-        spellingSearchRange->setStart(topNode, 0, IGNORE_EXCEPTION);
+        if (topNode)
+            spellingSearchRange->setStart(*topNode, 0, IGNORE_EXCEPTION);
         // going until the end of the very first chunk we tested is far enough
-        spellingSearchRange->setEnd(&searchEndNodeAfterWrap, searchEndOffsetAfterWrap, IGNORE_EXCEPTION);
+        spellingSearchRange->setEnd(searchEndNodeAfterWrap, searchEndOffsetAfterWrap, IGNORE_EXCEPTION);
         
         if (unifiedTextCheckerEnabled()) {
             grammarSearchRange = spellingSearchRange->cloneRange();
@@ -2045,7 +2048,7 @@ void Editor::advanceToNextMisspelling(bool startBeforeSelection)
                 // Stop looking at start of next misspelled word
                 CharacterIterator chars(*grammarSearchRange);
                 chars.advance(misspellingOffset);
-                grammarSearchRange->setEnd(&chars.range()->startContainer(), chars.range()->startOffset(), IGNORE_EXCEPTION);
+                grammarSearchRange->setEnd(chars.range()->startContainer(), chars.range()->startOffset(), IGNORE_EXCEPTION);
             }
 
             if (isGrammarCheckingEnabled())
@@ -3168,9 +3171,9 @@ PassRefPtr<Range> Editor::rangeOfString(const String& target, Range* referenceRa
     RefPtr<Node> shadowTreeRoot = referenceRange ? referenceRange->startContainer().nonBoundaryShadowTreeRootNode() : nullptr;
     if (shadowTreeRoot) {
         if (forward)
-            searchRange->setEnd(shadowTreeRoot.get(), shadowTreeRoot->countChildNodes());
+            searchRange->setEnd(*shadowTreeRoot, shadowTreeRoot->countChildNodes());
         else
-            searchRange->setStart(shadowTreeRoot.get(), 0);
+            searchRange->setStart(*shadowTreeRoot, 0);
     }
 
     RefPtr<Range> resultRange(findPlainText(*searchRange, target, options));
@@ -3186,9 +3189,9 @@ PassRefPtr<Range> Editor::rangeOfString(const String& target, Range* referenceRa
 
         if (shadowTreeRoot) {
             if (forward)
-                searchRange->setEnd(shadowTreeRoot.get(), shadowTreeRoot->countChildNodes());
+                searchRange->setEnd(*shadowTreeRoot, shadowTreeRoot->countChildNodes());
             else
-                searchRange->setStart(shadowTreeRoot.get(), 0);
+                searchRange->setStart(*shadowTreeRoot, 0);
         }
 
         resultRange = findPlainText(*searchRange, target, options);
@@ -3197,10 +3200,12 @@ PassRefPtr<Range> Editor::rangeOfString(const String& target, Range* referenceRa
     // If nothing was found in the shadow tree, search in main content following the shadow tree.
     if (resultRange->collapsed() && shadowTreeRoot) {
         searchRange = rangeOfContents(document());
-        if (forward)
-            searchRange->setStartAfter(shadowTreeRoot->shadowHost());
-        else
-            searchRange->setEndBefore(shadowTreeRoot->shadowHost());
+        if (shadowTreeRoot->shadowHost()) {
+            if (forward)
+                searchRange->setStartAfter(*shadowTreeRoot->shadowHost());
+            else
+                searchRange->setEndBefore(*shadowTreeRoot->shadowHost());
+        }
 
         resultRange = findPlainText(*searchRange, target, options);
     }
@@ -3223,7 +3228,7 @@ static bool isFrameInRange(Frame* frame, Range* range)
     bool inRange = false;
     for (HTMLFrameOwnerElement* ownerElement = frame->ownerElement(); ownerElement; ownerElement = ownerElement->document().ownerElement()) {
         if (&ownerElement->document() == &range->ownerDocument()) {
-            inRange = range->intersectsNode(ownerElement, IGNORE_EXCEPTION);
+            inRange = range->intersectsNode(*ownerElement, IGNORE_EXCEPTION);
             break;
         }
     }
@@ -3255,8 +3260,8 @@ unsigned Editor::countMatchesForText(const String& target, Range* range, FindOpt
             if (!resultRange->startContainer().isInShadowTree())
                 break;
 
-            searchRange->setStartAfter(resultRange->startContainer().shadowHost(), IGNORE_EXCEPTION);
-            searchRange->setEnd(&originalEndContainer, originalEndOffset, IGNORE_EXCEPTION);
+            searchRange->setStartAfter(*resultRange->startContainer().shadowHost(), IGNORE_EXCEPTION);
+            searchRange->setEnd(originalEndContainer, originalEndOffset, IGNORE_EXCEPTION);
             continue;
         }
 
@@ -3275,11 +3280,11 @@ unsigned Editor::countMatchesForText(const String& target, Range* range, FindOpt
         // result range. There is no need to use a VisiblePosition here,
         // since findPlainText will use a TextIterator to go over the visible
         // text nodes. 
-        searchRange->setStart(&resultRange->endContainer(), resultRange->endOffset(), IGNORE_EXCEPTION);
+        searchRange->setStart(resultRange->endContainer(), resultRange->endOffset(), IGNORE_EXCEPTION);
 
         Node* shadowTreeRoot = searchRange->shadowRoot();
         if (searchRange->collapsed() && shadowTreeRoot)
-            searchRange->setEnd(shadowTreeRoot, shadowTreeRoot->countChildNodes(), IGNORE_EXCEPTION);
+            searchRange->setEnd(*shadowTreeRoot, shadowTreeRoot->countChildNodes(), IGNORE_EXCEPTION);
     } while (true);
 
     return matchCount;
index 91ad176..81aa000 100644 (file)
@@ -228,12 +228,11 @@ static unsigned verticalScrollDistance(Frame& frame)
     return static_cast<unsigned>(Scrollbar::pageStep(height));
 }
 
-static RefPtr<Range> unionDOMRanges(Range* a, Range* b)
+static RefPtr<Range> unionDOMRanges(Range& a, Range& b)
 {
-    Range* start = a->compareBoundaryPoints(Range::START_TO_START, b, ASSERT_NO_EXCEPTION) <= 0 ? a : b;
-    Range* end = a->compareBoundaryPoints(Range::END_TO_END, b, ASSERT_NO_EXCEPTION) <= 0 ? b : a;
-
-    return Range::create(a->ownerDocument(), &start->startContainer(), start->startOffset(), &end->endContainer(), end->endOffset());
+    Range& start = a.compareBoundaryPoints(Range::START_TO_START, b, ASSERT_NO_EXCEPTION) <= 0 ? a : b;
+    Range& end = a.compareBoundaryPoints(Range::END_TO_END, b, ASSERT_NO_EXCEPTION) <= 0 ? b : a;
+    return Range::create(a.ownerDocument(), &start.startContainer(), start.startOffset(), &end.endContainer(), end.endOffset());
 }
 
 // Execute command functions
@@ -356,8 +355,8 @@ static bool executeDeleteToMark(Frame& frame, Event*, EditorCommandSource, const
 {
     RefPtr<Range> mark = frame.editor().mark().toNormalizedRange();
     FrameSelection& selection = frame.selection();
-    if (mark) {
-        bool selected = selection.setSelectedRange(unionDOMRanges(mark.get(), frame.editor().selectedRange().get()).get(), DOWNSTREAM, true);
+    if (mark && frame.editor().selectedRange()) {
+        bool selected = selection.setSelectedRange(unionDOMRanges(*mark, *frame.editor().selectedRange()).get(), DOWNSTREAM, true);
         ASSERT(selected);
         if (!selected)
             return false;
@@ -1010,7 +1009,7 @@ static bool executeSelectToMark(Frame& frame, Event*, EditorCommandSource, const
         systemBeep();
         return false;
     }
-    frame.selection().setSelectedRange(unionDOMRanges(mark.get(), selection.get()).get(), DOWNSTREAM, true);
+    frame.selection().setSelectedRange(unionDOMRanges(*mark, *selection).get(), DOWNSTREAM, true);
     return true;
 }
 
index a0256a4..aaa99a8 100644 (file)
@@ -73,7 +73,7 @@ void FormatBlockCommand::formatRange(const Position& start, const Position& end,
     if (!root || !refNode)
         return;
     if (isElementForFormatBlock(refNode->tagQName()) && start == startOfBlock(start)
-        && (end == endOfBlock(end) || isNodeVisiblyContainedWithin(refNode, range.get()))
+        && (end == endOfBlock(end) || isNodeVisiblyContainedWithin(*refNode, range.get()))
         && refNode != root && !root->isDescendantOf(refNode)) {
         // Already in a block element that only contains the current paragraph
         if (refNode->hasTagName(tagName()))
index 5ac3077..8b0b2b5 100644 (file)
@@ -474,7 +474,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 
@@ -2605,7 +2605,7 @@ PassRefPtr<Range> FrameSelection::rangeByExtendingCurrentSelection(int amount) c
     return rangeByAlteringCurrentSelection(AlterationExtend, amount);
 }
 
-void FrameSelection::selectRangeOnElement(unsigned location, unsigned length, Node* node)
+void FrameSelection::selectRangeOnElement(unsigned location, unsigned length, Node& node)
 {
     RefPtr<Range> resultRange = m_frame->document()->createRange();
     ExceptionCode ec = 0;
index 69b5c9f..95ac377 100644 (file)
@@ -230,7 +230,7 @@ public:
     WEBCORE_EXPORT bool selectionAtWordStart() const;
     WEBCORE_EXPORT PassRefPtr<Range> rangeByMovingCurrentSelection(int amount) const;
     WEBCORE_EXPORT PassRefPtr<Range> rangeByExtendingCurrentSelection(int amount) const;
-    WEBCORE_EXPORT void selectRangeOnElement(unsigned location, unsigned length, Node*);
+    WEBCORE_EXPORT void selectRangeOnElement(unsigned location, unsigned length, Node&);
     WEBCORE_EXPORT void clearCurrentSelection();
     void setCaretBlinks(bool caretBlinks = true);
     WEBCORE_EXPORT void setCaretColor(const Color&);
index ef4f621..6ff7c1a 100644 (file)
@@ -220,7 +220,7 @@ void InsertListCommand::doApplyForSingleParagraph(bool forceCreateList, const HT
             return;
 
         // If the entire list is selected, then convert the whole list.
-        if (switchListType && isNodeVisiblyContainedWithin(listNode.get(), currentSelection)) {
+        if (switchListType && isNodeVisiblyContainedWithin(*listNode, currentSelection)) {
             bool rangeStartIsInList = visiblePositionBeforeNode(listNode.get()) == currentSelection->startPosition();
             bool rangeEndIsInList = visiblePositionAfterNode(listNode.get()) == currentSelection->endPosition();
 
@@ -243,9 +243,9 @@ void InsertListCommand::doApplyForSingleParagraph(bool forceCreateList, const HT
             // Restore the start and the end of current selection if they started inside listNode
             // because moveParagraphWithClones could have removed them.
             if (rangeStartIsInList && newList)
-                currentSelection->setStart(newList, 0, IGNORE_EXCEPTION);
+                currentSelection->setStart(*newList, 0, IGNORE_EXCEPTION);
             if (rangeEndIsInList && newList)
-                currentSelection->setEnd(newList, lastOffsetInNode(newList.get()), IGNORE_EXCEPTION);
+                currentSelection->setEnd(*newList, lastOffsetInNode(newList.get()), IGNORE_EXCEPTION);
 
             setEndingSelection(VisiblePosition(firstPositionInNode(newList.get())));
 
index 7536920..b6952e2 100644 (file)
@@ -174,8 +174,13 @@ PassRefPtr<Range> TextCheckingParagraph::subrange(int characterOffset, int chara
 int TextCheckingParagraph::offsetTo(const Position& position, ExceptionCode& ec) const
 {
     ASSERT(m_checkingRange);
+    if (!position.containerNode()) {
+        ec = TypeError;
+        return 0;
+    }
+
     Ref<Range> range = offsetAsRange()->cloneRange();
-    range->setEnd(position.containerNode(), position.computeOffsetInContainerNode(), ec);
+    range->setEnd(*position.containerNode(), position.computeOffsetInContainerNode(), ec);
     if (ec)
         return 0;
     return TextIterator::rangeLength(range.ptr());
index 483a4d4..f2b2fb7 100644 (file)
@@ -1479,8 +1479,8 @@ Ref<Range> CharacterIterator::range() const
             Node& node = range->startContainer();
             ASSERT(&node == &range->endContainer());
             int offset = range->startOffset() + m_runOffset;
-            range->setStart(&node, offset);
-            range->setEnd(&node, offset + 1);
+            range->setStart(node, offset);
+            range->setEnd(node, offset + 1);
         }
     }
     return range;
@@ -1569,8 +1569,8 @@ Ref<Range> BackwardsCharacterIterator::range() const
             Node& node = r->startContainer();
             ASSERT(&node == &r->endContainer());
             int offset = r->endOffset() - m_runOffset;
-            r->setStart(&node, offset - 1);
-            r->setEnd(&node, offset);
+            r->setStart(node, offset - 1);
+            r->setEnd(node, offset);
         }
     }
     return r;
@@ -2479,8 +2479,8 @@ RefPtr<Range> TextIterator::rangeFromLocationAndLength(ContainerNode* scope, int
     
     // FIXME: the atEnd() check shouldn't be necessary, workaround for <http://bugs.webkit.org/show_bug.cgi?id=6289>.
     if (!rangeLocation && !rangeLength && it.atEnd()) {
-        resultRange->setStart(&textRunRange->startContainer(), 0);
-        resultRange->setEnd(&textRunRange->startContainer(), 0);
+        resultRange->setStart(textRunRange->startContainer(), 0);
+        resultRange->setEnd(textRunRange->startContainer(), 0);
         return WTFMove(resultRange);
     }
 
@@ -2498,12 +2498,12 @@ RefPtr<Range> TextIterator::rangeFromLocationAndLength(ContainerNode* scope, int
                 it.advance();
                 if (!it.atEnd()) {
                     Ref<Range> range = it.range();
-                    textRunRange->setEnd(&range->startContainer(), range->startOffset());
+                    textRunRange->setEnd(range->startContainer(), range->startOffset());
                 } else {
                     Position runStart = textRunRange->startPosition();
                     Position runEnd = VisiblePosition(runStart).next().deepEquivalent();
                     if (runEnd.isNotNull())
-                        textRunRange->setEnd(runEnd.containerNode(), runEnd.computeOffsetInContainerNode());
+                        textRunRange->setEnd(*runEnd.containerNode(), runEnd.computeOffsetInContainerNode());
                 }
             }
         }
@@ -2512,24 +2512,24 @@ RefPtr<Range> TextIterator::rangeFromLocationAndLength(ContainerNode* scope, int
             startRangeFound = true;
             if (textRunRange->startContainer().isTextNode()) {
                 int offset = rangeLocation - docTextPosition;
-                resultRange->setStart(&textRunRange->startContainer(), offset + textRunRange->startOffset());
+                resultRange->setStart(textRunRange->startContainer(), offset + textRunRange->startOffset());
             } else {
                 if (rangeLocation == docTextPosition)
-                    resultRange->setStart(&textRunRange->startContainer(), textRunRange->startOffset());
+                    resultRange->setStart(textRunRange->startContainer(), textRunRange->startOffset());
                 else
-                    resultRange->setStart(&textRunRange->endContainer(), textRunRange->endOffset());
+                    resultRange->setStart(textRunRange->endContainer(), textRunRange->endOffset());
             }
         }
 
         if (foundEnd) {
             if (textRunRange->startContainer().isTextNode()) {
                 int offset = rangeEnd - docTextPosition;
-                resultRange->setEnd(&textRunRange->startContainer(), offset + textRunRange->startOffset());
+                resultRange->setEnd(textRunRange->startContainer(), offset + textRunRange->startOffset());
             } else {
                 if (rangeEnd == docTextPosition)
-                    resultRange->setEnd(&textRunRange->startContainer(), textRunRange->startOffset());
+                    resultRange->setEnd(textRunRange->startContainer(), textRunRange->startOffset());
                 else
-                    resultRange->setEnd(&textRunRange->endContainer(), textRunRange->endOffset());
+                    resultRange->setEnd(textRunRange->endContainer(), textRunRange->endOffset());
             }
             docTextPosition += length;
             break;
@@ -2542,7 +2542,7 @@ RefPtr<Range> TextIterator::rangeFromLocationAndLength(ContainerNode* scope, int
         return nullptr;
     
     if (rangeLength && rangeEnd > docTextPosition) // rangeEnd is out of bounds
-        resultRange->setEnd(&textRunRange->endContainer(), textRunRange->endOffset());
+        resultRange->setEnd(textRunRange->endContainer(), textRunRange->endOffset());
     
     return WTFMove(resultRange);
 }
@@ -2566,7 +2566,7 @@ bool TextIterator::getLocationAndLengthFromRange(Node* scope, const Range* range
     ASSERT(&testRange->startContainer() == scope);
     location = TextIterator::rangeLength(testRange.ptr());
 
-    testRange->setEnd(&range->endContainer(), range->endOffset(), IGNORE_EXCEPTION);
+    testRange->setEnd(range->endContainer(), range->endOffset(), IGNORE_EXCEPTION);
     ASSERT(&testRange->startContainer() == scope);
     length = TextIterator::rangeLength(testRange.ptr()) - location;
     return true;
@@ -2623,7 +2623,7 @@ static size_t findPlainText(const Range& range, const String& target, FindOption
 
     if (buffer.needsMoreContext()) {
         Ref<Range> beforeStartRange = range.ownerDocument().createRange();
-        beforeStartRange->setEnd(&range.startContainer(), range.startOffset());
+        beforeStartRange->setEnd(range.startContainer(), range.startOffset());
         for (SimplifiedBackwardsTextIterator backwardsIterator(beforeStartRange.get()); !backwardsIterator.atEnd(); backwardsIterator.advance()) {
             buffer.prependContext(backwardsIterator.text());
             if (!buffer.needsMoreContext())
index 2fe26d7..421ee2b 100644 (file)
@@ -730,24 +730,32 @@ VisiblePosition endVisiblePosition(const Range *r, EAffinity affinity)
     return VisiblePosition(r->endPosition(), affinity);
 }
 
-bool setStart(Range *r, const VisiblePosition &visiblePosition)
+bool setStart(Range* range, const VisiblePosition& visiblePosition)
 {
-    if (!r)
+    if (!range)
         return false;
+
     Position p = visiblePosition.deepEquivalent().parentAnchoredEquivalent();
-    int code = 0;
-    r->setStart(p.containerNode(), p.offsetInContainerNode(), code);
-    return code == 0;
+    if (!p.containerNode())
+        return false;
+
+    int ec = 0;
+    range->setStart(*p.containerNode(), p.offsetInContainerNode(), ec);
+    return !ec;
 }
 
-bool setEnd(Range *r, const VisiblePosition &visiblePosition)
+bool setEnd(Range* range, const VisiblePosition& visiblePosition)
 {
-    if (!r)
+    if (!range)
         return false;
+
     Position p = visiblePosition.deepEquivalent().parentAnchoredEquivalent();
-    int code = 0;
-    r->setEnd(p.containerNode(), p.offsetInContainerNode(), code);
-    return code == 0;
+    if (!p.containerNode())
+        return false;
+
+    int ec = 0;
+    range->setEnd(*p.containerNode(), p.offsetInContainerNode(), ec);
+    return !ec;
 }
 
 // FIXME: Maybe this should be deprecated too, like the underlying function?
index 7da66a1..f8d9033 100644 (file)
@@ -213,8 +213,8 @@ static RefPtr<Range> makeSearchRange(const Position& pos)
     ExceptionCode ec = 0;
 
     Position start(pos.parentAnchoredEquivalent());
-    searchRange->selectNodeContents(boundary, ec);
-    searchRange->setStart(start.containerNode(), start.offsetInContainerNode(), ec);
+    searchRange->selectNodeContents(*boundary, ec);
+    searchRange->setStart(*start.containerNode(), start.offsetInContainerNode(), ec);
 
     ASSERT(!ec);
     if (ec)
index deb40fd..622f436 100644 (file)
@@ -569,7 +569,11 @@ static VisiblePosition previousBoundary(const VisiblePosition& c, BoundarySearch
     Document& boundaryDocument = boundary->document();
     Position start = createLegacyEditingPosition(boundary, 0).parentAnchoredEquivalent();
     Position end = pos.parentAnchoredEquivalent();
-    RefPtr<Range> searchRange = Range::create(boundaryDocument);
+
+    if (start.isNull() || end.isNull())
+        return VisiblePosition();
+
+    Ref<Range> searchRange = Range::create(boundaryDocument);
     
     Vector<UChar, 1024> string;
     unsigned suffixLength = 0;
@@ -577,19 +581,19 @@ static VisiblePosition previousBoundary(const VisiblePosition& c, BoundarySearch
     ExceptionCode ec = 0;
     if (requiresContextForWordBoundary(c.characterBefore())) {
         RefPtr<Range> forwardsScanRange(boundaryDocument.createRange());
-        forwardsScanRange->setEndAfter(boundary, ec);
-        forwardsScanRange->setStart(end.deprecatedNode(), end.deprecatedEditingOffset(), ec);
+        forwardsScanRange->setEndAfter(*boundary, ec);
+        forwardsScanRange->setStart(*end.deprecatedNode(), end.deprecatedEditingOffset(), ec);
         suffixLength = suffixLengthForRange(forwardsScanRange, string);
     }
 
-    searchRange->setStart(start.deprecatedNode(), start.deprecatedEditingOffset(), ec);
-    searchRange->setEnd(end.deprecatedNode(), end.deprecatedEditingOffset(), ec);
+    searchRange->setStart(*start.deprecatedNode(), start.deprecatedEditingOffset(), ec);
+    searchRange->setEnd(*end.deprecatedNode(), end.deprecatedEditingOffset(), ec);
 
     ASSERT(!ec);
     if (ec)
         return VisiblePosition();
 
-    SimplifiedBackwardsTextIterator it(*searchRange);
+    SimplifiedBackwardsTextIterator it(searchRange);
     unsigned next = backwardSearchForBoundaryWithTextIterator(it, string, suffixLength, searchFunction);
 
     if (!next)
@@ -602,7 +606,7 @@ static VisiblePosition previousBoundary(const VisiblePosition& c, BoundarySearch
     }
 
     // Use the character iterator to translate the next value into a DOM position.
-    BackwardsCharacterIterator charIt(*searchRange);
+    BackwardsCharacterIterator charIt(searchRange);
     charIt.advance(string.size() - suffixLength - next);
     // FIXME: charIt can get out of shadow host.
     return VisiblePosition(charIt.range()->endPosition(), DOWNSTREAM);
@@ -616,7 +620,7 @@ static VisiblePosition nextBoundary(const VisiblePosition& c, BoundarySearchFunc
         return VisiblePosition();
 
     Document& boundaryDocument = boundary->document();
-    RefPtr<Range> searchRange(boundaryDocument.createRange());
+    Ref<Range> searchRange = boundaryDocument.createRange();
     Position start(pos.parentAnchoredEquivalent());
 
     Vector<UChar, 1024> string;
@@ -624,20 +628,22 @@ static VisiblePosition nextBoundary(const VisiblePosition& c, BoundarySearchFunc
 
     if (requiresContextForWordBoundary(c.characterAfter())) {
         RefPtr<Range> backwardsScanRange(boundaryDocument.createRange());
-        backwardsScanRange->setEnd(start.deprecatedNode(), start.deprecatedEditingOffset(), IGNORE_EXCEPTION);
+        if (start.deprecatedNode())
+            backwardsScanRange->setEnd(*start.deprecatedNode(), start.deprecatedEditingOffset(), IGNORE_EXCEPTION);
         prefixLength = prefixLengthForRange(backwardsScanRange, string);
     }
 
-    searchRange->selectNodeContents(boundary, IGNORE_EXCEPTION);
-    searchRange->setStart(start.deprecatedNode(), start.deprecatedEditingOffset(), IGNORE_EXCEPTION);
-    TextIterator it(searchRange.get(), TextIteratorEmitsCharactersBetweenAllVisiblePositions);
+    searchRange->selectNodeContents(*boundary, IGNORE_EXCEPTION);
+    if (start.deprecatedNode())
+        searchRange->setStart(*start.deprecatedNode(), start.deprecatedEditingOffset(), IGNORE_EXCEPTION);
+    TextIterator it(searchRange.ptr(), TextIteratorEmitsCharactersBetweenAllVisiblePositions);
     unsigned next = forwardSearchForBoundaryWithTextIterator(it, string, prefixLength, searchFunction);
     
     if (it.atEnd() && next == string.size())
         pos = searchRange->endPosition();
     else if (next > prefixLength) {
         // Use the character iterator to translate the next value into a DOM position.
-        CharacterIterator charIt(*searchRange, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
+        CharacterIterator charIt(searchRange, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
         charIt.advance(next - prefixLength - 1);
         RefPtr<Range> characterRange = charIt.range();
         pos = characterRange->endPosition();
index 29c9af8..a233517 100644 (file)
@@ -1164,13 +1164,12 @@ VisiblePosition visiblePositionForIndex(int index, ContainerNode* scope)
     return VisiblePosition(range->startPosition());
 }
 
-VisiblePosition visiblePositionForIndexUsingCharacterIterator(Node* node, int index)
+VisiblePosition visiblePositionForIndexUsingCharacterIterator(Node& node, int index)
 {
-    ASSERT(node);
     if (index <= 0)
-        return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM);
+        return VisiblePosition(firstPositionInOrBeforeNode(&node), DOWNSTREAM);
 
-    RefPtr<Range> range = Range::create(node->document());
+    RefPtr<Range> range = Range::create(node.document());
     range->selectNodeContents(node, IGNORE_EXCEPTION);
     CharacterIterator it(*range);
     it.advance(index - 1);
@@ -1186,20 +1185,19 @@ bool isVisiblyAdjacent(const Position& first, const Position& second)
 
 // Determines whether a node is inside a range or visibly starts and ends at the boundaries of the range.
 // Call this function to determine whether a node is visibly fit inside selectedRange
-bool isNodeVisiblyContainedWithin(Node* node, const Range* selectedRange)
+bool isNodeVisiblyContainedWithin(Node& node, const Range* selectedRange)
 {
-    ASSERT(node);
     ASSERT(selectedRange);
     // If the node is inside the range, then it surely is contained within
     if (selectedRange->compareNode(node, IGNORE_EXCEPTION) == Range::NODE_INSIDE)
         return true;
 
-    bool startIsVisuallySame = visiblePositionBeforeNode(node) == selectedRange->startPosition();
-    if (startIsVisuallySame && comparePositions(positionInParentAfterNode(node), selectedRange->endPosition()) < 0)
+    bool startIsVisuallySame = visiblePositionBeforeNode(&node) == selectedRange->startPosition();
+    if (startIsVisuallySame && comparePositions(positionInParentAfterNode(&node), selectedRange->endPosition()) < 0)
         return true;
 
-    bool endIsVisuallySame = visiblePositionAfterNode(node) == selectedRange->endPosition();
-    if (endIsVisuallySame && comparePositions(selectedRange->startPosition(), positionInParentBeforeNode(node)) < 0)
+    bool endIsVisuallySame = visiblePositionAfterNode(&node) == selectedRange->endPosition();
+    if (endIsVisuallySame && comparePositions(selectedRange->startPosition(), positionInParentBeforeNode(&node)) < 0)
         return true;
 
     return startIsVisuallySame && endIsVisuallySame;
index c15479c..41c051d 100644 (file)
@@ -117,7 +117,7 @@ bool isTableStructureNode(const Node*);
 bool isListElement(Node*);
 bool isListItem(const Node*);
 bool isNodeRendered(const Node*);
-bool isNodeVisiblyContainedWithin(Node*, const Range*);
+bool isNodeVisiblyContainedWithin(Node&, const Range*);
 bool isRenderedAsNonInlineTableImageOrHR(const Node*);
 bool areIdenticalElements(const Node*, const Node*);
 bool isNonTableCellHTMLBlockElement(const Node*);
@@ -198,7 +198,7 @@ int comparePositions(const VisiblePosition&, const VisiblePosition&);
 int indexForVisiblePosition(const VisiblePosition&, RefPtr<ContainerNode>& scope);
 int indexForVisiblePosition(Node*, const VisiblePosition&, bool forSelectionPreservation);
 VisiblePosition visiblePositionForIndex(int index, ContainerNode* scope);
-VisiblePosition visiblePositionForIndexUsingCharacterIterator(Node*, int index); // FIXME: Why do we need this version?
+VisiblePosition visiblePositionForIndexUsingCharacterIterator(Node&, int index); // FIXME: Why do we need this version?
 
 // -------------------------------------------------------------------------
 // HTMLElement
index 125c5a9..73c5dac 100644 (file)
@@ -318,7 +318,7 @@ RefPtr<Range> Editor::adjustedSelectionRange()
     ASSERT(commonAncestor);
     auto* enclosingAnchor = enclosingElementWithTag(firstPositionInNode(commonAncestor), HTMLNames::aTag);
     if (enclosingAnchor && comparePositions(firstPositionInOrBeforeNode(range->startPosition().anchorNode()), range->startPosition()) >= 0)
-        range->setStart(enclosingAnchor, 0, IGNORE_EXCEPTION);
+        range->setStart(*enclosingAnchor, 0, IGNORE_EXCEPTION);
     return range;
 }
     
index 1442252..ef22e52 100644 (file)
@@ -413,7 +413,8 @@ void ContextMenuController::contextMenuItemSelected(ContextMenuAction action, co
         if (!selectedRange || selectedRange->collapsed()) {
             Document& document = m_context.hitTestResult().innerNonSharedNode()->document();
             selectedRange = document.createRange();
-            selectedRange->selectNode(document.documentElement(), IGNORE_EXCEPTION);
+            if (document.documentElement())
+                selectedRange->selectNode(*document.documentElement(), IGNORE_EXCEPTION);
         }
         m_client.speak(plainText(selectedRange.get()));
         break;
index e119f64..f605661 100644 (file)
@@ -393,10 +393,13 @@ void DOMSelection::addRange(Range* r)
     }
 
     RefPtr<Range> range = selection.selection().toNormalizedRange();
-    if (r->compareBoundaryPoints(Range::START_TO_START, range.get(), IGNORE_EXCEPTION) == -1) {
+    if (!range)
+        return;
+
+    if (r->compareBoundaryPoints(Range::START_TO_START, *range, IGNORE_EXCEPTION) == -1) {
         // We don't support discontiguous selection. We don't do anything if r and range don't intersect.
-        if (r->compareBoundaryPoints(Range::START_TO_END, range.get(), IGNORE_EXCEPTION) > -1) {
-            if (r->compareBoundaryPoints(Range::END_TO_END, range.get(), IGNORE_EXCEPTION) == -1) {
+        if (r->compareBoundaryPoints(Range::START_TO_END, *range, IGNORE_EXCEPTION) > -1) {
+            if (r->compareBoundaryPoints(Range::END_TO_END, *range, IGNORE_EXCEPTION) == -1) {
                 // The original range and r intersect.
                 selection.moveTo(r->startPosition(), range->endPosition(), DOWNSTREAM);
             } else {
@@ -407,8 +410,8 @@ void DOMSelection::addRange(Range* r)
     } else {
         // We don't support discontiguous selection. We don't do anything if r and range don't intersect.
         ExceptionCode ec = 0;
-        if (r->compareBoundaryPoints(Range::END_TO_START, range.get(), ec) < 1 && !ec) {
-            if (r->compareBoundaryPoints(Range::END_TO_END, range.get(), IGNORE_EXCEPTION) == -1) {
+        if (r->compareBoundaryPoints(Range::END_TO_START, *range, ec) < 1 && !ec) {
+            if (r->compareBoundaryPoints(Range::END_TO_END, *range, IGNORE_EXCEPTION) == -1) {
                 // The original range contains r.
                 selection.moveTo(range.get());
             } else {
index 1cc8384..0c90b41 100644 (file)
@@ -712,7 +712,7 @@ static Image* getImage(Element& element)
 static void selectElement(Element& element)
 {
     RefPtr<Range> range = element.document().createRange();
-    range->selectNode(&element);
+    range->selectNode(element);
     element.document().frame()->selection().setSelection(VisibleSelection(*range, DOWNSTREAM));
 }
 
index 18c475f..1752236 100644 (file)
@@ -2507,7 +2507,7 @@ bool EventHandler::dispatchMouseEvent(const AtomicString& eventType, Node* targe
                 // focused if the user does a mouseup over it, however, because the mouseup
                 // will set a selection inside it, which will call setFocuseNodeIfNeeded.
                 if (m_frame.selection().isRange()
-                    && m_frame.selection().toNormalizedRange()->compareNode(element, IGNORE_EXCEPTION) == Range::NODE_INSIDE
+                    && m_frame.selection().toNormalizedRange()->compareNode(*element, IGNORE_EXCEPTION) == Range::NODE_INSIDE
                     && element->isDescendantOf(m_frame.document()->focusedElement()))
                     return true;
                     
index 9153d04..8df1d36 100644 (file)
@@ -632,14 +632,14 @@ void Page::findStringMatchingRanges(const String& target, FindOptions options, i
         RefPtr<Range> selectedRange = frameWithSelection->selection().selection().firstRange();
         if (options & Backwards) {
             for (size_t i = matchRanges.size(); i > 0; --i) {
-                if (selectedRange->compareBoundaryPoints(Range::END_TO_START, matchRanges[i - 1].get(), IGNORE_EXCEPTION) > 0) {
+                if (selectedRange->compareBoundaryPoints(Range::END_TO_START, *matchRanges[i - 1], IGNORE_EXCEPTION) > 0) {
                     indexForSelection = i - 1;
                     break;
                 }
             }
         } else {
             for (size_t i = 0, size = matchRanges.size(); i < size; ++i) {
-                if (selectedRange->compareBoundaryPoints(Range::START_TO_END, matchRanges[i].get(), IGNORE_EXCEPTION) < 0) {
+                if (selectedRange->compareBoundaryPoints(Range::START_TO_END, *matchRanges[i], IGNORE_EXCEPTION) < 0) {
                     indexForSelection = i;
                     break;
                 }
index 17684c5..26ef37c 100644 (file)
@@ -125,7 +125,7 @@ static bool hasNonInlineOrReplacedElements(const Range& range)
         RenderObject* renderer = node->renderer();
         if (!renderer)
             continue;
-        if ((!renderer->isInline() || renderer->isReplaced()) && range.intersectsNode(node, ASSERT_NO_EXCEPTION))
+        if ((!renderer->isInline() || renderer->isReplaced()) && range.intersectsNode(*node, ASSERT_NO_EXCEPTION))
             return true;
     }
 
index 3292031..b36ea4e 100644 (file)
@@ -694,8 +694,8 @@ void RenderNamedFlowThread::getRanges(Vector<RefPtr<Range>>& rangeObjects, const
             if (!boxIntersectsRegion(logicalTopForRenderer, logicalBottomForRenderer, logicalTopForRegion, logicalBottomForRegion)) {
                 if (foundStartPosition) {
                     if (!startsAboveRegion) {
-                        if (range->intersectsNode(node, IGNORE_EXCEPTION))
-                            range->setEndBefore(node, IGNORE_EXCEPTION);
+                        if (range->intersectsNode(*node, IGNORE_EXCEPTION))
+                            range->setEndBefore(*node, IGNORE_EXCEPTION);
                         rangeObjects.append(range->cloneRange());
                         range = Range::create(contentElement->document());
                         startsAboveRegion = true;
@@ -703,7 +703,7 @@ void RenderNamedFlowThread::getRanges(Vector<RefPtr<Range>>& rangeObjects, const
                         skipOverOutsideNodes = true;
                 }
                 if (skipOverOutsideNodes)
-                    range->setStartAfter(node, IGNORE_EXCEPTION);
+                    range->setStartAfter(*node, IGNORE_EXCEPTION);
                 foundStartPosition = false;
                 continue;
             }
@@ -733,7 +733,7 @@ void RenderNamedFlowThread::getRanges(Vector<RefPtr<Range>>& rangeObjects, const
                 // the range is closed.
                 if (startsAboveRegion) {
                     startsAboveRegion = false;
-                    range->setStartBefore(node, IGNORE_EXCEPTION);
+                    range->setStartBefore(*node, IGNORE_EXCEPTION);
                 }
             }
             skipOverOutsideNodes  = false;
@@ -770,7 +770,7 @@ void RenderNamedFlowThread::getRanges(Vector<RefPtr<Range>>& rangeObjects, const
                 // for elements that ends inside the region, set the end position to be after them
                 // allow this end position to be changed only by other elements that are not descendants of the current end node
                 if (endsBelowRegion || (!endsBelowRegion && !node->isDescendantOf(lastEndNode))) {
-                    range->setEndAfter(node, IGNORE_EXCEPTION);
+                    range->setEndAfter(*node, IGNORE_EXCEPTION);
                     endsBelowRegion = false;
                     lastEndNode = node;
                 }
index e39055c..750971d 100644 (file)
@@ -1,3 +1,13 @@
+2016-04-21  Chris Dumez  <cdumez@apple.com>
+
+        Drop [UsePointersEvenForNonNullableObjectArguments] from Range
+        https://bugs.webkit.org/show_bug.cgi?id=156805
+
+        Reviewed by Youenn Fablet.
+
+        * WebView/WebFrame.mm:
+        (-[WebFrame _smartDeleteRangeForProposedRange:]):
+
 2016-04-20  Brady Eidson  <beidson@apple.com>
 
         Modern IDB (Workers): Enable INDEXED_DATABASE_IN_WORKERS compile time flag, but disabled in RuntimeEnabledFeatures.
index 063307c..a72a0a3 100644 (file)
@@ -873,11 +873,13 @@ static inline WebDataSource *dataSource(DocumentLoader* loader)
     newStart = newStart.parentAnchoredEquivalent();
     newEnd = newEnd.parentAnchoredEquivalent();
 
-    RefPtr<Range> range = _private->coreFrame->document()->createRange();
-    int exception = 0;
-    range->setStart(newStart.containerNode(), newStart.offsetInContainerNode(), exception);
-    range->setEnd(newStart.containerNode(), newStart.offsetInContainerNode(), exception);
-    return kit(range.get());
+    Ref<Range> range = _private->coreFrame->document()->createRange();
+    if (newStart.containerNode()) {
+        int exception = 0;
+        range->setStart(*newStart.containerNode(), newStart.offsetInContainerNode(), exception);
+        range->setEnd(*newStart.containerNode(), newStart.offsetInContainerNode(), exception);
+    }
+    return kit(range.ptr());
 }
 
 - (DOMDocumentFragment *)_documentFragmentWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString 
@@ -1628,11 +1630,11 @@ static WebFrameLoadType toWebFrameLoadType(FrameLoadType frameLoadType)
     if (!doc)
         return;
 
-    Node *node = core(element);
+    Nodenode = core(element);
     if (!node->inDocument())
         return;
         
-    frame->selection().selectRangeOnElement(range.location, range.length, node);
+    frame->selection().selectRangeOnElement(range.location, range.length, *node);
 }
 
 - (DOMRange *)markedTextDOMRange
index 0c5e576..a5ba807 100644 (file)
@@ -6114,7 +6114,7 @@ LRESULT WebView::onIMERequestCharPosition(Frame* targetFrame, IMECHARPOSITION* c
     if (RefPtr<Range> range = targetFrame->editor().hasComposition() ? targetFrame->editor().compositionRange() : targetFrame->selection().selection().toNormalizedRange()) {
         ExceptionCode ec = 0;
         RefPtr<Range> tempRange = range->cloneRange();
-        tempRange->setStart(&tempRange->startContainer(), tempRange->startOffset() + charPos->dwCharPos, ec);
+        tempRange->setStart(tempRange->startContainer(), tempRange->startOffset() + charPos->dwCharPos, ec);
         caret = targetFrame->editor().firstRectForRange(tempRange.get());
     }
     caret = targetFrame->view()->contentsToWindow(caret);
index 76a4a8e..90a1daf 100644 (file)
@@ -1,3 +1,18 @@
+2016-04-21  Chris Dumez  <cdumez@apple.com>
+
+        Drop [UsePointersEvenForNonNullableObjectArguments] from Range
+        https://bugs.webkit.org/show_bug.cgi?id=156805
+
+        Reviewed by Youenn Fablet.
+
+        * WebProcess/InjectedBundle/API/mac/WKDOMRange.mm:
+        (-[WKDOMRange setStart:offset:]):
+        (-[WKDOMRange setEnd:offset:]):
+        (-[WKDOMRange selectNode:]):
+        (-[WKDOMRange selectNodeContents:]):
+        * WebProcess/WebPage/WebFrame.cpp:
+        (WebKit::WebFrame::contentsAsString):
+
 2016-04-21  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] WebKitWebView should claim the contents size as its natural size
index e0806bc..93e849f 100644 (file)
 
 - (void)setStart:(WKDOMNode *)node offset:(int)offset
 {
+    if (!node)
+        return;
     // FIXME: Do something about the exception.
     WebCore::ExceptionCode ec = 0;
-    _impl->setStart(WebKit::toWebCoreNode(node), offset, ec);
+    _impl->setStart(*WebKit::toWebCoreNode(node), offset, ec);
 }
 
 - (void)setEnd:(WKDOMNode *)node offset:(int)offset
 {
+    if (!node)
+        return;
     // FIXME: Do something about the exception.
     WebCore::ExceptionCode ec = 0;
-    _impl->setEnd(WebKit::toWebCoreNode(node), offset, ec);
+    _impl->setEnd(*WebKit::toWebCoreNode(node), offset, ec);
 }
 
 - (void)collapse:(BOOL)toStart
 
 - (void)selectNode:(WKDOMNode *)node
 {
+    if (!node)
+        return;
     // FIXME: Do something about the exception.
     WebCore::ExceptionCode ec = 0;
-    _impl->selectNode(WebKit::toWebCoreNode(node), ec);
+    _impl->selectNode(*WebKit::toWebCoreNode(node), ec);
 }
 
 - (void)selectNodeContents:(WKDOMNode *)node
 {
+    if (!node)
+        return;
     // FIXME: Do something about the exception.
     WebCore::ExceptionCode ec = 0;
-    _impl->selectNodeContents(WebKit::toWebCoreNode(node), ec);
+    _impl->selectNodeContents(*WebKit::toWebCoreNode(node), ec);
 }
 
 - (WKDOMNode *)startContainer
index aa274ba..db22f1e 100644 (file)
@@ -330,7 +330,7 @@ String WebFrame::contentsAsString() const
     RefPtr<Range> range = document->createRange();
 
     ExceptionCode ec = 0;
-    range->selectNode(documentElement.get(), ec);
+    range->selectNode(*documentElement, ec);
     if (ec)
         return String();
 
index ba70a01..290c905 100644 (file)
@@ -940,7 +940,7 @@ PassRefPtr<Range> WebPage::rangeForWebSelectionAtPosition(const IntPoint& point,
 
     flags = IsBlockSelection;
     range = Range::create(bestChoice->document());
-    range->selectNodeContents(bestChoice, ASSERT_NO_EXCEPTION);
+    range->selectNodeContents(*bestChoice, ASSERT_NO_EXCEPTION);
     return range->collapsed() ? nullptr : range;
 }
 
@@ -964,7 +964,7 @@ PassRefPtr<Range> WebPage::rangeForBlockAtPoint(const IntPoint& point)
         return nullptr;
 
     range = Range::create(currentNode->document());
-    range->selectNodeContents(currentNode, ASSERT_NO_EXCEPTION);
+    range->selectNodeContents(*currentNode, ASSERT_NO_EXCEPTION);
     return range;
 }
 
@@ -1220,8 +1220,8 @@ static inline bool containsRange(Range* first, Range* second)
     if (!first || !second)
         return false;
     return (first->commonAncestorContainer()->ownerDocument() == second->commonAncestorContainer()->ownerDocument()
-        && first->compareBoundaryPoints(Range::START_TO_START, second, ASSERT_NO_EXCEPTION) <= 0
-        && first->compareBoundaryPoints(Range::END_TO_END, second, ASSERT_NO_EXCEPTION) >= 0);
+        && first->compareBoundaryPoints(Range::START_TO_START, *second, ASSERT_NO_EXCEPTION) <= 0
+        && first->compareBoundaryPoints(Range::END_TO_END, *second, ASSERT_NO_EXCEPTION) >= 0);
 }
 
 static inline RefPtr<Range> unionDOMRanges(Range* rangeA, Range* rangeB)
@@ -1231,8 +1231,8 @@ static inline RefPtr<Range> unionDOMRanges(Range* rangeA, Range* rangeB)
     if (!rangeA)
         return rangeB;
 
-    Range* start = rangeA->compareBoundaryPoints(Range::START_TO_START, rangeB, ASSERT_NO_EXCEPTION) <= 0 ? rangeA : rangeB;
-    Range* end = rangeA->compareBoundaryPoints(Range::END_TO_END, rangeB, ASSERT_NO_EXCEPTION) <= 0 ? rangeB : rangeA;
+    Range* start = rangeA->compareBoundaryPoints(Range::START_TO_START, *rangeB, ASSERT_NO_EXCEPTION) <= 0 ? rangeA : rangeB;
+    Range* end = rangeA->compareBoundaryPoints(Range::END_TO_END, *rangeB, ASSERT_NO_EXCEPTION) <= 0 ? rangeB : rangeA;
 
     return Range::create(rangeA->ownerDocument(), &start->startContainer(), start->startOffset(), &end->endContainer(), end->endOffset());
 }
@@ -2232,7 +2232,7 @@ void WebPage::getPositionInformation(const IntPoint& point, InteractionInformati
                         info.dataDetectorResults = element->document().frame()->dataDetectionResults();
                         if (DataDetection::requiresExtendedContext(*element)) {
                             RefPtr<Range> linkRange = Range::create(element->document());
-                            linkRange->selectNodeContents(element, ASSERT_NO_EXCEPTION);
+                            linkRange->selectNodeContents(*element, ASSERT_NO_EXCEPTION);
                             info.textBefore = plainTextReplacingNoBreakSpace(rangeExpandedByCharactersInDirectionAtWordBoundary(linkRange->startPosition(), dataDetectionExtendedContextLength, DirectionBackward).get(), TextIteratorDefaultBehavior, true);
                             info.textAfter = plainTextReplacingNoBreakSpace(rangeExpandedByCharactersInDirectionAtWordBoundary(linkRange->endPosition(), dataDetectionExtendedContextLength, DirectionForward).get(), TextIteratorDefaultBehavior, true);
                         }