Title: [264271] trunk/Source
Revision
264271
Author
[email protected]
Date
2020-07-11 15:38:45 -0700 (Sat, 11 Jul 2020)

Log Message

Remove live ranges from AccessibilityObject.h, AccessibilityObjectInterface.h, AccessibilityRenderObject.h, AXIsolatedObject.h
https://bugs.webkit.org/show_bug.cgi?id=214215

Reviewed by Sam Weinig.

Source/WebCore:

Also use the IntPoint and LayoutPoint center() functions instead of rolling our own.

* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::misspellingRange const): Return SimpleRange. Also
renamed from getMisspellingRange.
(WebCore::rangeClosestToRange): Take and return SimpleRange.
(WebCore::AccessibilityObject::rangeOfStringClosestToRangeInDirection const): Ditto.
(WebCore::AccessibilityObject::elementRange const): Return SimpleRange.
(WebCore::AccessibilityObject::findTextRange const): Take and return SimpleRange.
(WebCore::AccessibilityObject::findTextRanges const): Ditto.
(WebCore::AccessibilityObject::performTextOperation): Use SimpleRange.
(WebCore::AccessibilityObject::clickPoint): Use center().
(WebCore::AccessibilityObject::rangeForPlainTextRange const): Return SimpleRange.
(WebCore::AccessibilityObject::stringForRange const): Take SimpleRange.
(WebCore::AccessibilityObject::stringForVisiblePositionRange): Use SimpleRange.
(WebCore::AccessibilityObject::lengthForVisiblePositionRange const): Ditto.
(WebCore::AccessibilityObject::replaceTextInRange): Use SimpleRange.
* accessibility/AccessibilityObject.h: Update for above.

* accessibility/AccessibilityObjectInterface.h: Take and return SimpleRange.

* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::linkClickPoint): Use SimpleRange.
(WebCore::AccessibilityRenderObject::clickPoint): Ditto.
(WebCore::AccessibilityRenderObject::setSelectedTextRange): Ditto.
(WebCore::AccessibilityRenderObject::boundsForRange const): Take SimpleRange.
(WebCore::AccessibilityRenderObject::setSelectedVisiblePositionRange const):
Use SimpleRange.
(WebCore::AccessibilityRenderObject::doAXBoundsForRangeUsingCharacterOffset const):
Use SimpleRange.
* accessibility/AccessibilityRenderObject.h: Update for above.

* accessibility/atk/WebKitAccessibleInterfaceText.cpp: Include Range.h.

* accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
(-[WebAccessibilityObjectWrapper stringForTextMarkers:]): Use SimpleRange.
(-[WebAccessibilityObjectWrapper textMarkerRange]): Ditto.
(-[WebAccessibilityObjectWrapper stringForRange:]): Ditto.
(-[WebAccessibilityObjectWrapper misspellingTextMarkerRange:forward:]): Ditto.
(-[WebAccessibilityObjectWrapper frameForTextMarkers:]): Ditto.

* accessibility/isolatedtree/AXIsolatedObject.cpp:
(WebCore::AXIsolatedObject::stringForRange const): Take SimpleRange.
(WebCore::AXIsolatedObject::findTextRanges const): Return SimpleRange.
* accessibility/isolatedtree/AXIsolatedObject.h: Update for above.

* accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(accessibilityTextOperationForParameterizedAttribute): Use SimpleRange.
(-[WebAccessibilityObjectWrapper doAXAttributedStringForRange:]): Ditto.
(-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]): Ditto.

* dom/Range.cpp:
(WebCore::makeSimpleRange): Added.
* dom/Range.h: Added makeSimpleRange so we can explicitly convert from
live ranges to simple ranges.

* editing/Editing.cpp:
(WebCore::indexForVisiblePosition): Use separate returns for start and end.
* editing/TextCheckingHelper.cpp:
(WebCore::TextCheckingParagraph::offsetTo const): Ditto.
(WebCore::TextCheckingParagraph::automaticReplacementStart const): Ditto.

* page/FocusController.cpp:
(WebCore::updateFocusCandidateIfNeeded): Use center().

Source/WebKit:

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::requestDocumentEditingContext): Use nested if for start and end
so we don't do the work on end if the test fails on start.

Source/WTF:

* wtf/cocoa/VectorCocoa.h: Added a new makeVector that takes a function.
Also updated createNSArray to use std::invoke.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (264270 => 264271)


--- trunk/Source/WTF/ChangeLog	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WTF/ChangeLog	2020-07-11 22:38:45 UTC (rev 264271)
@@ -1,3 +1,13 @@
+2020-07-11  Darin Adler  <[email protected]>
+
+        Remove live ranges from AccessibilityObject.h, AccessibilityObjectInterface.h, AccessibilityRenderObject.h, AXIsolatedObject.h
+        https://bugs.webkit.org/show_bug.cgi?id=214215
+
+        Reviewed by Sam Weinig.
+
+        * wtf/cocoa/VectorCocoa.h: Added a new makeVector that takes a function.
+        Also updated createNSArray to use std::invoke.
+
 2020-07-11  Sam Weinig  <[email protected]>
 
         Make hasher work with tuple-like classes

Modified: trunk/Source/WTF/wtf/cocoa/VectorCocoa.h (264270 => 264271)


--- trunk/Source/WTF/wtf/cocoa/VectorCocoa.h	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WTF/wtf/cocoa/VectorCocoa.h	2020-07-11 22:38:45 UTC (rev 264271)
@@ -52,8 +52,12 @@
 // This overload of createNSArray takes a function to map each vector element to an Objective-C object.
 // The map function has the same interface as the makeNSArrayElement function above, but can be any
 // function including a lambda, a function-like object, or Function<>.
-template<typename CollectionType, typename MapFunctionType> RetainPtr<NSArray> createNSArray(CollectionType&&, const MapFunctionType&);
+template<typename CollectionType, typename MapFunctionType> RetainPtr<NSArray> createNSArray(CollectionType&&, MapFunctionType&&);
 
+// This overload of makeVector takes a function to map each Objective-C object to a vector element.
+// Currently, the map function needs to return an Optional.
+template<typename MapFunctionType> Vector<typename std::invoke_result_t<MapFunctionType, id>::value_type> makeVector(NSArray *, MapFunctionType&&);
+
 // Implementation details of the function templates above.
 
 inline void addUnlessNil(NSMutableArray *array, id value)
@@ -70,11 +74,11 @@
     return array;
 }
 
-template<typename CollectionType, typename MapFunctionType> RetainPtr<NSArray> createNSArray(CollectionType&& collection, const MapFunctionType& function)
+template<typename CollectionType, typename MapFunctionType> RetainPtr<NSArray> createNSArray(CollectionType&& collection, MapFunctionType&& function)
 {
     auto array = adoptNS([[NSMutableArray alloc] initWithCapacity:std::size(collection)]);
     for (auto&& element : collection)
-        addUnlessNil(array.get(), getPtr(function(std::forward<decltype(element)>(element))));
+        addUnlessNil(array.get(), getPtr(std::invoke(std::forward<MapFunctionType>(function), std::forward<decltype(element)>(element))));
     return array;
 }
 
@@ -91,6 +95,18 @@
     return vector;
 }
 
+template<typename MapFunctionType> Vector<typename std::invoke_result_t<MapFunctionType, id>::value_type> makeVector(NSArray *array, MapFunctionType&& function)
+{
+    Vector<typename std::invoke_result_t<MapFunctionType, id>::value_type> vector;
+    vector.reserveInitialCapacity(array.count);
+    for (id element in array) {
+        if (auto vectorElement = std::invoke(std::forward<MapFunctionType>(function), element))
+            vector.uncheckedAppend(WTFMove(*vectorElement));
+    }
+    vector.shrinkToFit();
+    return vector;
+}
+
 } // namespace WTF
 
 using WTF::createNSArray;

Modified: trunk/Source/WebCore/ChangeLog (264270 => 264271)


--- trunk/Source/WebCore/ChangeLog	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebCore/ChangeLog	2020-07-11 22:38:45 UTC (rev 264271)
@@ -1,3 +1,75 @@
+2020-07-11  Darin Adler  <[email protected]>
+
+        Remove live ranges from AccessibilityObject.h, AccessibilityObjectInterface.h, AccessibilityRenderObject.h, AXIsolatedObject.h
+        https://bugs.webkit.org/show_bug.cgi?id=214215
+
+        Reviewed by Sam Weinig.
+
+        Also use the IntPoint and LayoutPoint center() functions instead of rolling our own.
+
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::AccessibilityObject::misspellingRange const): Return SimpleRange. Also
+        renamed from getMisspellingRange.
+        (WebCore::rangeClosestToRange): Take and return SimpleRange.
+        (WebCore::AccessibilityObject::rangeOfStringClosestToRangeInDirection const): Ditto.
+        (WebCore::AccessibilityObject::elementRange const): Return SimpleRange.
+        (WebCore::AccessibilityObject::findTextRange const): Take and return SimpleRange.
+        (WebCore::AccessibilityObject::findTextRanges const): Ditto.
+        (WebCore::AccessibilityObject::performTextOperation): Use SimpleRange.
+        (WebCore::AccessibilityObject::clickPoint): Use center().
+        (WebCore::AccessibilityObject::rangeForPlainTextRange const): Return SimpleRange.
+        (WebCore::AccessibilityObject::stringForRange const): Take SimpleRange.
+        (WebCore::AccessibilityObject::stringForVisiblePositionRange): Use SimpleRange.
+        (WebCore::AccessibilityObject::lengthForVisiblePositionRange const): Ditto.
+        (WebCore::AccessibilityObject::replaceTextInRange): Use SimpleRange.
+        * accessibility/AccessibilityObject.h: Update for above.
+
+        * accessibility/AccessibilityObjectInterface.h: Take and return SimpleRange.
+
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::AccessibilityRenderObject::linkClickPoint): Use SimpleRange.
+        (WebCore::AccessibilityRenderObject::clickPoint): Ditto.
+        (WebCore::AccessibilityRenderObject::setSelectedTextRange): Ditto.
+        (WebCore::AccessibilityRenderObject::boundsForRange const): Take SimpleRange.
+        (WebCore::AccessibilityRenderObject::setSelectedVisiblePositionRange const):
+        Use SimpleRange.
+        (WebCore::AccessibilityRenderObject::doAXBoundsForRangeUsingCharacterOffset const):
+        Use SimpleRange.
+        * accessibility/AccessibilityRenderObject.h: Update for above.
+
+        * accessibility/atk/WebKitAccessibleInterfaceText.cpp: Include Range.h.
+
+        * accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
+        (-[WebAccessibilityObjectWrapper stringForTextMarkers:]): Use SimpleRange.
+        (-[WebAccessibilityObjectWrapper textMarkerRange]): Ditto.
+        (-[WebAccessibilityObjectWrapper stringForRange:]): Ditto.
+        (-[WebAccessibilityObjectWrapper misspellingTextMarkerRange:forward:]): Ditto.
+        (-[WebAccessibilityObjectWrapper frameForTextMarkers:]): Ditto.
+
+        * accessibility/isolatedtree/AXIsolatedObject.cpp:
+        (WebCore::AXIsolatedObject::stringForRange const): Take SimpleRange.
+        (WebCore::AXIsolatedObject::findTextRanges const): Return SimpleRange.
+        * accessibility/isolatedtree/AXIsolatedObject.h: Update for above.
+
+        * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+        (accessibilityTextOperationForParameterizedAttribute): Use SimpleRange.
+        (-[WebAccessibilityObjectWrapper doAXAttributedStringForRange:]): Ditto.
+        (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]): Ditto.
+
+        * dom/Range.cpp:
+        (WebCore::makeSimpleRange): Added.
+        * dom/Range.h: Added makeSimpleRange so we can explicitly convert from
+        live ranges to simple ranges.
+
+        * editing/Editing.cpp:
+        (WebCore::indexForVisiblePosition): Use separate returns for start and end.
+        * editing/TextCheckingHelper.cpp:
+        (WebCore::TextCheckingParagraph::offsetTo const): Ditto.
+        (WebCore::TextCheckingParagraph::automaticReplacementStart const): Ditto.
+
+        * page/FocusController.cpp:
+        (WebCore::updateFocusCandidateIfNeeded): Use center().
+
 2020-07-11  Simon Fraser  <[email protected]>
 
         REGRESSION(r260276): Overflow scrolling layers misplaced inside SVG foreign object

Modified: trunk/Source/WebCore/accessibility/AccessibilityObject.cpp (264270 => 264271)


--- trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2020-07-11 22:38:45 UTC (rev 264271)
@@ -274,24 +274,24 @@
     return isMisspelled;
 }
 
-RefPtr<Range> AccessibilityObject::getMisspellingRange(RefPtr<Range> const& start, AccessibilitySearchDirection direction) const
+Optional<SimpleRange> AccessibilityObject::misspellingRange(const SimpleRange& start, AccessibilitySearchDirection direction) const
 {
     auto node = this->node();
     if (!node)
-        return nullptr;
+        return WTF::nullopt;
 
     Frame* frame = node->document().frame();
     if (!frame)
-        return nullptr;
+        return WTF::nullopt;
 
     if (!unifiedTextCheckerEnabled(frame))
-        return nullptr;
+        return WTF::nullopt;
 
     Editor& editor = frame->editor();
 
     TextCheckerClient* textChecker = editor.textChecker();
     if (!textChecker)
-        return nullptr;
+        return WTF::nullopt;
 
     Vector<TextCheckingResult> misspellings;
     checkTextOfParagraph(*textChecker, stringValue(), TextCheckingType::Spelling, misspellings, frame->selection().selection());
@@ -306,8 +306,8 @@
             if (!misspellingRange)
                 continue;
 
-            if (misspellingRange->compareBoundaryPoints(Range::END_TO_END, *start).releaseReturnValue() > 0)
-                return misspellingRange;
+            if (misspellingRange->compareBoundaryPoints(Range::END_TO_END, createLiveRange(start)).releaseReturnValue() > 0)
+                return makeSimpleRange(*misspellingRange);
         }
     } else if (direction == AccessibilitySearchDirection::Previous) {
         for (auto rit = misspellings.rbegin(); rit != misspellings.rend(); ++rit) {
@@ -315,12 +315,12 @@
             if (!misspellingRange)
                 continue;
 
-            if (misspellingRange->compareBoundaryPoints(Range::START_TO_START, *start).releaseReturnValue() < 0)
-                return misspellingRange;
+            if (misspellingRange->compareBoundaryPoints(Range::START_TO_START, createLiveRange(start)).releaseReturnValue() < 0)
+                return makeSimpleRange(*misspellingRange);
         }
     }
 
-    return nullptr;
+    return WTF::nullopt;
 }
 
 unsigned AccessibilityObject::blockquoteLevel() const
@@ -562,67 +562,63 @@
 // Returns the range that is fewer positions away from the reference range.
 // NOTE: The after range is expected to ACTUALLY be after the reference range and the before
 // range is expected to ACTUALLY be before. These are not checked for performance reasons.
-static RefPtr<Range> rangeClosestToRange(RefPtr<Range> const& referenceRange, RefPtr<Range>&& afterRange, RefPtr<Range>&& beforeRange)
+static Optional<SimpleRange> rangeClosestToRange(const SimpleRange& referenceRange, Optional<SimpleRange>&& afterRange, Optional<SimpleRange>&& beforeRange)
 {
-    if (!referenceRange)
-        return nullptr;
-
     // The treeScope for shadow nodes may not be the same scope as another element in a document.
     // Comparisons may fail in that case, which are expected behavior and should not assert.
-    if (afterRange && (referenceRange->endPosition().isNull() || ((afterRange->startPosition().anchorNode()->compareDocumentPosition(*referenceRange->endPosition().anchorNode()) & Node::DOCUMENT_POSITION_DISCONNECTED) == Node::DOCUMENT_POSITION_DISCONNECTED)))
-        return nullptr;
-    ASSERT(!afterRange || afterRange->compareBoundaryPoints(Range::START_TO_START, *referenceRange).releaseReturnValue() >= 0);
 
-    if (beforeRange && (referenceRange->startPosition().isNull() || ((beforeRange->endPosition().anchorNode()->compareDocumentPosition(*referenceRange->startPosition().anchorNode()) & Node::DOCUMENT_POSITION_DISCONNECTED) == Node::DOCUMENT_POSITION_DISCONNECTED)))
-        return nullptr;
-    ASSERT(!beforeRange || beforeRange->compareBoundaryPoints(Range::START_TO_START, *referenceRange).releaseReturnValue() <= 0);
+    if (afterRange && (afterRange->start.container->compareDocumentPosition(referenceRange.end.container) & Node::DOCUMENT_POSITION_DISCONNECTED))
+        return WTF::nullopt;
+    ASSERT(!afterRange || createLiveRange(afterRange)->compareBoundaryPoints(Range::START_TO_START, createLiveRange(referenceRange)).releaseReturnValue() >= 0);
 
+    if (beforeRange && (beforeRange->end.container->compareDocumentPosition(referenceRange.start.container) & Node::DOCUMENT_POSITION_DISCONNECTED))
+        return WTF::nullopt;
+    ASSERT(!beforeRange || createLiveRange(beforeRange)->compareBoundaryPoints(Range::START_TO_START, createLiveRange(referenceRange)).releaseReturnValue() <= 0);
+
     if (!afterRange && !beforeRange)
-        return nullptr;
-    if (afterRange && !beforeRange)
+        return WTF::nullopt;
+    if (!beforeRange)
         return WTFMove(afterRange);
-    if (!afterRange && beforeRange)
+    if (!afterRange)
         return WTFMove(beforeRange);
-    
-    unsigned positionsToAfterRange = Position::positionCountBetweenPositions(afterRange->startPosition(), referenceRange->endPosition());
-    unsigned positionsToBeforeRange = Position::positionCountBetweenPositions(beforeRange->endPosition(), referenceRange->startPosition());
-    
-    return positionsToAfterRange < positionsToBeforeRange ? afterRange : beforeRange;
+
+    auto positionsToAfterRange = Position::positionCountBetweenPositions(createLegacyEditingPosition(afterRange->start), createLegacyEditingPosition(referenceRange.end));
+    auto positionsToBeforeRange = Position::positionCountBetweenPositions(createLegacyEditingPosition(beforeRange->end), createLegacyEditingPosition(referenceRange.start));
+
+    return WTFMove(positionsToAfterRange < positionsToBeforeRange ? afterRange : beforeRange);
 }
 
-RefPtr<Range> AccessibilityObject::rangeOfStringClosestToRangeInDirection(Range* referenceRange, AccessibilitySearchDirection searchDirection, Vector<String> const& searchStrings) const
+Optional<SimpleRange> AccessibilityObject::rangeOfStringClosestToRangeInDirection(const SimpleRange& referenceRange, AccessibilitySearchDirection searchDirection, const Vector<String>& searchStrings) const
 {
     Frame* frame = this->frame();
     if (!frame)
-        return nullptr;
+        return WTF::nullopt;
     
-    if (!referenceRange)
-        return nullptr;
-    
     bool isBackwardSearch = searchDirection == AccessibilitySearchDirection::Previous;
     FindOptions findOptions { AtWordStarts, AtWordEnds, CaseInsensitive, StartInSelection };
     if (isBackwardSearch)
         findOptions.add(FindOptionFlag::Backwards);
     
-    RefPtr<Range> closestStringRange = nullptr;
-    for (const auto& searchString : searchStrings) {
-        if (RefPtr<Range> searchStringRange = frame->editor().rangeOfString(searchString, referenceRange, findOptions)) {
+    Optional<SimpleRange> closestStringRange;
+    for (auto& searchString : searchStrings) {
+        if (auto searchStringRange = frame->editor().rangeOfString(searchString, createLiveRange(referenceRange).ptr(), findOptions)) {
+            auto foundStringRange = makeSimpleRange(*searchStringRange);
             if (!closestStringRange)
-                closestStringRange = searchStringRange;
+                closestStringRange = foundStringRange;
             else {
                 // If searching backward, use the trailing range edges to correctly determine which
                 // range is closest. Similarly, if searching forward, use the leading range edges.
-                Position closestStringPosition = isBackwardSearch ? closestStringRange->endPosition() : closestStringRange->startPosition();
-                Position searchStringPosition = isBackwardSearch ? searchStringRange->endPosition() : searchStringRange->startPosition();
+                auto& closestStringPosition = isBackwardSearch ? closestStringRange->end : closestStringRange->start;
+                auto& foundStringPosition = isBackwardSearch ? foundStringRange.end : foundStringRange.start;
                 
-                int closestPositionOffset = closestStringPosition.computeOffsetInContainerNode();
-                int searchPositionOffset = searchStringPosition.computeOffsetInContainerNode();
-                Node* closestContainerNode = closestStringPosition.containerNode();
-                Node* searchContainerNode = searchStringPosition.containerNode();
+                auto closestPositionOffset = closestStringPosition.offset;
+                auto searchPositionOffset = foundStringPosition.offset;
+                auto closestContainerNode = closestStringPosition.container.ptr();
+                auto searchContainerNode = foundStringPosition.container.ptr();
                 
-                short result = Range::compareBoundaryPoints(closestContainerNode, closestPositionOffset, searchContainerNode, searchPositionOffset).releaseReturnValue();
+                auto result = Range::compareBoundaryPoints(closestContainerNode, closestPositionOffset, searchContainerNode, searchPositionOffset).releaseReturnValue();
                 if ((!isBackwardSearch && result > 0) || (isBackwardSearch && result < 0))
-                    closestStringRange = searchStringRange;
+                    closestStringRange = foundStringRange;
             }
         }
     }
@@ -644,83 +640,73 @@
     return { { { document, 0 }, { document, 0 } } };
 }
 
-RefPtr<Range> AccessibilityObject::elementRange() const
+Optional<SimpleRange> AccessibilityObject::elementRange() const
 {
     auto node = this->node();
     if (!node)
         return { };
-    return createLiveRange(AXObjectCache::rangeForNodeContents(*node));
+    return AXObjectCache::rangeForNodeContents(*node);
 }
 
-RefPtr<Range> AccessibilityObject::findTextRange(Vector<String> const& searchStrings, RefPtr<Range> const& start, AccessibilitySearchTextDirection direction) const
+Optional<SimpleRange> AccessibilityObject::findTextRange(const Vector<String>& searchStrings, const SimpleRange& start, AccessibilitySearchTextDirection direction) const
 {
-    RefPtr<Range> found;
+    Optional<SimpleRange> found;
     if (direction == AccessibilitySearchTextDirection::Forward)
-        found = rangeOfStringClosestToRangeInDirection(start.get(), AccessibilitySearchDirection::Next, searchStrings);
+        found = rangeOfStringClosestToRangeInDirection(start, AccessibilitySearchDirection::Next, searchStrings);
     else if (direction == AccessibilitySearchTextDirection::Backward)
-        found = rangeOfStringClosestToRangeInDirection(start.get(), AccessibilitySearchDirection::Previous, searchStrings);
+        found = rangeOfStringClosestToRangeInDirection(start, AccessibilitySearchDirection::Previous, searchStrings);
     else if (direction == AccessibilitySearchTextDirection::Closest) {
-        auto foundAfter = rangeOfStringClosestToRangeInDirection(start.get(), AccessibilitySearchDirection::Next, searchStrings);
-        auto foundBefore = rangeOfStringClosestToRangeInDirection(start.get(), AccessibilitySearchDirection::Previous, searchStrings);
-        found = rangeClosestToRange(start.get(), WTFMove(foundAfter), WTFMove(foundBefore));
+        auto foundAfter = rangeOfStringClosestToRangeInDirection(start, AccessibilitySearchDirection::Next, searchStrings);
+        auto foundBefore = rangeOfStringClosestToRangeInDirection(start, AccessibilitySearchDirection::Previous, searchStrings);
+        found = rangeClosestToRange(start, WTFMove(foundAfter), WTFMove(foundBefore));
     }
-
     if (found) {
         // If the search started within a text control, ensure that the result is inside that element.
         if (element() && element()->isTextField()) {
             if (!found->startContainer().isDescendantOrShadowDescendantOf(element())
                 || !found->endContainer().isDescendantOrShadowDescendantOf(element()))
-                return nullptr;
+                return WTF::nullopt;
         }
     }
     return found;
 }
 
-Vector<RefPtr<Range>> AccessibilityObject::findTextRanges(AccessibilitySearchTextCriteria const& criteria) const
+Vector<SimpleRange> AccessibilityObject::findTextRanges(const AccessibilitySearchTextCriteria& criteria) const
 {
-    Vector<RefPtr<Range>> result;
-
-    // Determine start range.
-    RefPtr<Range> startRange;
+    Optional<SimpleRange> range;
     if (criteria.start == AccessibilitySearchTextStartFrom::Selection)
-        startRange = createLiveRange(selectionRange());
+        range = selectionRange();
     else
-        startRange = elementRange();
+        range = elementRange();
+    if (!range)
+        return { };
 
-    if (startRange) {
-        // Collapse the range to the start unless searching from the end of the doc or searching backwards.
-        if (criteria.start == AccessibilitySearchTextStartFrom::Begin)
-            startRange->collapse(true);
-        else if (criteria.start == AccessibilitySearchTextStartFrom::End)
-            startRange->collapse(false);
-        else
-            startRange->collapse(criteria.direction != AccessibilitySearchTextDirection::Backward);
-    } else
-        return result;
+    if (criteria.start == AccessibilitySearchTextStartFrom::Begin)
+        range->end = range->start;
+    else if (criteria.start == AccessibilitySearchTextStartFrom::End)
+        range->start = range->end;
+    else if (criteria.direction == AccessibilitySearchTextDirection::Backward)
+        range->start = range->end;
+    else
+        range->end = range->start;
 
-    RefPtr<Range> found;
+    Vector<SimpleRange> result;
     switch (criteria.direction) {
     case AccessibilitySearchTextDirection::Forward:
     case AccessibilitySearchTextDirection::Backward:
     case AccessibilitySearchTextDirection::Closest:
-        found = findTextRange(criteria.searchStrings, startRange, criteria.direction);
-        if (found)
-            result.append(found);
+        if (auto foundRange = findTextRange(criteria.searchStrings, *range, criteria.direction))
+            result.append(*foundRange);
         break;
-    case AccessibilitySearchTextDirection::All: {
-        auto findAll = [&](AccessibilitySearchTextDirection dir) {
-            found = findTextRange(criteria.searchStrings, startRange, dir);
-            while (found) {
-                result.append(found);
-                found = findTextRange(criteria.searchStrings, found, dir);
-            }
+    case AccessibilitySearchTextDirection::All:
+        auto appendFoundRanges = [&](AccessibilitySearchTextDirection direction) {
+            for (auto foundRange = range; (foundRange = findTextRange(criteria.searchStrings, *foundRange, direction)); )
+                result.append(*foundRange);
         };
-        findAll(AccessibilitySearchTextDirection::Forward);
-        findAll(AccessibilitySearchTextDirection::Backward);
+        appendFoundRanges(AccessibilitySearchTextDirection::Forward);
+        appendFoundRanges(AccessibilitySearchTextDirection::Backward);
         break;
     }
-    }
-
     return result;
 }
 
@@ -736,10 +722,10 @@
         return result;
 
     for (const auto& textRange : operation.textRanges) {
-        if (!frame->selection().setSelectedRange(textRange.get(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes))
+        if (!frame->selection().setSelectedRange(createLiveRange(textRange).ptr(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes))
             continue;
 
-        String text = textRange->text();
+        String text = plainText(textRange);
         String replacementString = operation.replacementText;
         bool replaceSelection = false;
         switch (operation.type) {
@@ -843,8 +829,7 @@
 
 IntPoint AccessibilityObject::clickPoint()
 {
-    LayoutRect rect = elementRect();
-    return roundedIntPoint(LayoutPoint(rect.x() + rect.width() / 2, rect.y() + rect.height() / 2));
+    return roundedIntPoint(elementRect().center());
 }
 
 IntRect AccessibilityObject::boundingBoxForQuads(RenderObject* obj, const Vector<FloatQuad>& quads)
@@ -1180,21 +1165,21 @@
     return VisiblePositionRange(startPosition, endPosition);
 }
 
-RefPtr<Range> AccessibilityObject::rangeForPlainTextRange(const PlainTextRange& range) const
+Optional<SimpleRange> AccessibilityObject::rangeForPlainTextRange(const PlainTextRange& range) const
 {
     unsigned textLength = getLengthForTextRange();
     if (range.start + range.length > textLength)
-        return nullptr;
+        return WTF::nullopt;
     // Avoid setting selection to uneditable parent node in FrameSelection::setSelectedRange. See webkit.org/b/206093.
     if (range.isNull() && !textLength)
-        return nullptr;
+        return WTF::nullopt;
     
     if (AXObjectCache* cache = axObjectCache()) {
         CharacterOffset start = cache->characterOffsetForIndex(range.start, this);
         CharacterOffset end = cache->characterOffsetForIndex(range.start + range.length, this);
-        return createLiveRange(cache->rangeForUnorderedCharacterOffsets(start, end));
+        return cache->rangeForUnorderedCharacterOffsets(start, end);
     }
-    return nullptr;
+    return WTF::nullopt;
 }
 
 VisiblePositionRange AccessibilityObject::lineRangeForPosition(const VisiblePosition& visiblePosition) const
@@ -1259,12 +1244,9 @@
     return listMarkerTextForNode(node);
 }
 
-String AccessibilityObject::stringForRange(RefPtr<Range> range) const
+String AccessibilityObject::stringForRange(const SimpleRange& range) const
 {
-    if (!range)
-        return String();
-    
-    TextIterator it(*range);
+    TextIterator it(range);
     if (it.atEnd())
         return String();
     
@@ -1274,8 +1256,10 @@
         if (it.text().length()) {
             // Add a textual representation for list marker text.
             // Don't add list marker text for new line character.
-            if (it.text().length() != 1 || !isSpaceOrNewline(it.text()[0]))
-                builder.append(listMarkerTextForNodeAndPosition(it.node(), VisiblePosition(range->startPosition())));
+            if (it.text().length() != 1 || !isSpaceOrNewline(it.text()[0])) {
+                // FIXME: Seems like the position should be based on it.range(), not range.
+                builder.append(listMarkerTextForNodeAndPosition(it.node(), VisiblePosition(createLegacyEditingPosition(range.start))));
+            }
             it.appendTextToStringBuilder(builder);
         } else {
             if (replacedNodeNeedsCharacter(it.node()))
@@ -1288,15 +1272,15 @@
 
 String AccessibilityObject::stringForVisiblePositionRange(const VisiblePositionRange& visiblePositionRange)
 {
-    if (visiblePositionRange.isNull())
-        return String();
+    auto start = makeBoundaryPoint(visiblePositionRange.start);
+    if (!start)
+        return { };
+    auto end = makeBoundaryPoint(visiblePositionRange.end);
+    if (!end)
+        return { };
 
     StringBuilder builder;
-    RefPtr<Range> range = makeRange(visiblePositionRange.start, visiblePositionRange.end);
-    if (!range)
-        return String();
-
-    for (TextIterator it(*range); !it.atEnd(); it.advance()) {
+    for (TextIterator it({ *start, *end }); !it.atEnd(); it.advance()) {
         // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX)
         if (it.text().length()) {
             // Add a textual representation for list marker text.
@@ -1308,7 +1292,6 @@
                 builder.append(objectReplacementCharacter);
         }
     }
-
     return builder.toString();
 }
 
@@ -1315,15 +1298,17 @@
 int AccessibilityObject::lengthForVisiblePositionRange(const VisiblePositionRange& visiblePositionRange) const
 {
     // FIXME: Multi-byte support
-    if (visiblePositionRange.isNull())
-        return -1;
 
-    RefPtr<Range> range = makeRange(visiblePositionRange.start, visiblePositionRange.end);
-    if (!range)
-        return -1;
+    auto start = makeBoundaryPoint(visiblePositionRange.start);
+    if (!start)
+        return -1; // FIXME: Why not return 0?
+    auto end = makeBoundaryPoint(visiblePositionRange.end);
+    if (!end)
+        return -1; // FIXME: Why not return 0?
 
+    // FIXME: Use characterCount instead of writing our own loop?
     int length = 0;
-    for (TextIterator it(*range); !it.atEnd(); it.advance()) {
+    for (TextIterator it({ *start, *end }); !it.atEnd(); it.advance()) {
         // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX)
         if (it.text().length())
             length += it.text().length();
@@ -1447,14 +1432,16 @@
 
     // Make sure we move off of a sentence end.
     auto nextPosition = position.next();
-    auto lineRange = makeRange(startOfLine(nextPosition), endOfLine(nextPosition));
-    if (!lineRange)
+    auto start = makeBoundaryPoint(startOfLine(nextPosition));
+    if (!start)
         return { };
+    auto end = makeBoundaryPoint(endOfLine(nextPosition));
+    if (!end)
+        return { };
 
     // An empty line is considered a sentence. If it's skipped, then the sentence parser will not
     // see this empty line. Instead, return the end position of the empty line.
-    // FIXME: It would be more efficient to use hasAnyPlainText instead of plainText.isEmpty.
-    return plainText(*lineRange).isEmpty() ? nextPosition : endOfSentence(nextPosition);
+    return hasAnyPlainText({ *start, *end }) ? endOfSentence(nextPosition) : nextPosition;
 }
 
 VisiblePosition AccessibilityObject::previousSentenceStartPosition(const VisiblePosition& position) const
@@ -1464,13 +1451,15 @@
 
     // Make sure we move off of a sentence start.
     auto previousPosition = position.previous();
-    auto lineRange = makeRange(startOfLine(previousPosition), endOfLine(previousPosition));
-    if (!lineRange)
+    auto start = makeBoundaryPoint(startOfLine(previousPosition));
+    if (!start)
         return { };
+    auto end = makeBoundaryPoint(endOfLine(previousPosition));
+    if (!end)
+        return { };
 
     // Treat empty line as a separate sentence.
-    // FIXME: It would be more efficient to use hasAnyPlainText instead of plainText.isEmpty.
-    return plainText(*lineRange).isEmpty() ? previousPosition : startOfSentence(previousPosition);
+    return hasAnyPlainText({ *start, *end }) ? startOfSentence(previousPosition) : previousPosition;
 }
 
 VisiblePosition AccessibilityObject::nextParagraphEndPosition(const VisiblePosition& position) const
@@ -2043,7 +2032,7 @@
     // Also only do this when the field is in editing mode.
     auto& frame = renderer()->frame();
     if (element.shouldUseInputMethod()) {
-        frame.selection().setSelectedRange(rangeForPlainTextRange(range).get(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes);
+        frame.selection().setSelectedRange(createLiveRange(rangeForPlainTextRange(range)).get(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes);
         frame.editor().replaceSelectionWithText(replacementString, Editor::SelectReplacement::No, Editor::SmartReplace::No);
         return true;
     }

Modified: trunk/Source/WebCore/accessibility/AccessibilityObject.h (264270 => 264271)


--- trunk/Source/WebCore/accessibility/AccessibilityObject.h	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebCore/accessibility/AccessibilityObject.h	2020-07-11 22:38:45 UTC (rev 264271)
@@ -33,7 +33,6 @@
 #include "FloatQuad.h"
 #include "LayoutRect.h"
 #include "Path.h"
-#include "Range.h"
 #include <wtf/Forward.h>
 #include <wtf/Function.h>
 #include <wtf/RefPtr.h>
@@ -232,7 +231,7 @@
     bool hasBoldFont() const override { return false; }
     bool hasItalicFont() const override { return false; }
     bool hasMisspelling() const override;
-    RefPtr<Range> getMisspellingRange(RefPtr<Range> const& start, AccessibilitySearchDirection) const override;
+    Optional<SimpleRange> misspellingRange(const SimpleRange& start, AccessibilitySearchDirection) const override;
     bool hasPlainText() const override { return false; }
     bool hasSameFont(const AXCoreObject&) const override { return false; }
     bool hasSameFontColor(const AXCoreObject&) const override { return false; }
@@ -356,12 +355,7 @@
     bool isDescendantOfRole(AccessibilityRole) const override;
 
     // Text selection
-private:
-    RefPtr<Range> rangeOfStringClosestToRangeInDirection(Range*, AccessibilitySearchDirection, Vector<String> const&) const;
-    Optional<SimpleRange> selectionRange() const;
-    RefPtr<Range> findTextRange(Vector<String> const& searchStrings, RefPtr<Range> const& start, AccessibilitySearchTextDirection) const;
-public:
-    Vector<RefPtr<Range>> findTextRanges(AccessibilitySearchTextCriteria const&) const override;
+    Vector<SimpleRange> findTextRanges(const AccessibilitySearchTextCriteria&) const override;
     Vector<String> performTextOperation(AccessibilityTextOperation const&) override;
 
     AccessibilityObject* observableObject() const override { return nullptr; }
@@ -522,7 +516,7 @@
     VisiblePositionRange visiblePositionRange() const override { return VisiblePositionRange(); }
     VisiblePositionRange visiblePositionRangeForLine(unsigned) const override { return VisiblePositionRange(); }
 
-    RefPtr<Range> elementRange() const override;
+    Optional<SimpleRange> elementRange() const override;
     static bool replacedNodeNeedsCharacter(Node* replacedNode);
 
     VisiblePositionRange visiblePositionRangeForUnorderedPositions(const VisiblePosition&, const VisiblePosition&) const override;
@@ -536,12 +530,12 @@
     VisiblePositionRange visiblePositionRangeForRange(const PlainTextRange&) const override;
     VisiblePositionRange lineRangeForPosition(const VisiblePosition&) const override;
 
-    RefPtr<Range> rangeForPlainTextRange(const PlainTextRange&) const override;
+    Optional<SimpleRange> rangeForPlainTextRange(const PlainTextRange&) const override;
 
     static String stringForVisiblePositionRange(const VisiblePositionRange&);
-    String stringForRange(RefPtr<Range>) const override;
+    String stringForRange(const SimpleRange&) const override;
     IntRect boundsForVisiblePositionRange(const VisiblePositionRange&) const override { return IntRect(); }
-    IntRect boundsForRange(const RefPtr<Range>) const override { return IntRect(); }
+    IntRect boundsForRange(const SimpleRange&) const override { return IntRect(); }
     int lengthForVisiblePositionRange(const VisiblePositionRange&) const override;
     void setSelectedVisiblePositionRange(const VisiblePositionRange&) const override { }
 
@@ -746,7 +740,7 @@
     const AccessibilityScrollView* ancestorAccessibilityScrollView(bool includeSelf) const override;
     AccessibilityObject* webAreaObject() const override { return nullptr; }
 
-    void clearIsIgnoredFromParentData() override { m_isIgnoredFromParentData = AccessibilityIsIgnoredFromParentData(); }
+    void clearIsIgnoredFromParentData() override { m_isIgnoredFromParentData = { }; }
     void setIsIgnoredFromParentDataForChild(AXCoreObject*) override;
 
     uint64_t sessionID() const override;
@@ -756,21 +750,12 @@
 
 protected:
     AccessibilityObject() = default;
+
+    // FIXME: Make more of these member functions private.
+
     void detachRemoteParts(AccessibilityDetachmentType) override;
     void detachPlatformWrapper(AccessibilityDetachmentType) override;
 
-    AXID m_id { 0 };
-    AccessibilityChildrenVector m_children;
-    mutable bool m_haveChildren { false };
-    AccessibilityRole m_role { AccessibilityRole::Unknown };
-    AccessibilityObjectInclusion m_lastKnownIsIgnoredValue { AccessibilityObjectInclusion::DefaultBehavior };
-    AccessibilityIsIgnoredFromParentData m_isIgnoredFromParentData { };
-    bool m_childrenDirty { false };
-    bool m_subtreeDirty { false };
-#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
-    bool m_isolatedTreeNodeInitialized { false };
-#endif
-
     void setIsIgnoredFromParentData(AccessibilityIsIgnoredFromParentData& data) override { m_isIgnoredFromParentData = data; }
 
     virtual bool computeAccessibilityIsIgnored() const { return true; }
@@ -792,12 +777,28 @@
 
     AccessibilityObject* radioGroupAncestor() const;
 
-#if ENABLE(ACCESSIBILITY) && USE(ATK)
     bool allowsTextRanges() const;
     unsigned getLengthForTextRange() const;
-#else
-    bool allowsTextRanges() const { return isTextControl(); }
-    unsigned getLengthForTextRange() const { return text().length(); }
+
+private:
+    Optional<SimpleRange> rangeOfStringClosestToRangeInDirection(const SimpleRange&, AccessibilitySearchDirection, const Vector<String>&) const;
+    Optional<SimpleRange> selectionRange() const;
+    Optional<SimpleRange> findTextRange(const Vector<String>& searchStrings, const SimpleRange& start, AccessibilitySearchTextDirection) const;
+
+    AXID m_id { 0 };
+protected: // FIXME: Make the data members private.
+    AccessibilityChildrenVector m_children;
+    mutable bool m_haveChildren { false };
+    AccessibilityRole m_role { AccessibilityRole::Unknown };
+private:
+    AccessibilityObjectInclusion m_lastKnownIsIgnoredValue { AccessibilityObjectInclusion::DefaultBehavior };
+protected: // FIXME: Make the data members private.
+    AccessibilityIsIgnoredFromParentData m_isIgnoredFromParentData;
+    bool m_childrenDirty { false };
+    bool m_subtreeDirty { false };
+private:
+#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
+    bool m_isolatedTreeNodeInitialized { false };
 #endif
 };
 
@@ -809,6 +810,11 @@
 inline void AccessibilityObject::detachPlatformWrapper(AccessibilityDetachmentType) { }
 #endif
 
+#if !(ENABLE(ACCESSIBILITY) && USE(ATK))
+inline bool AccessibilityObject::allowsTextRanges() const { return isTextControl(); }
+inline unsigned AccessibilityObject::getLengthForTextRange() const { return text().length(); }
+#endif
+
 AccessibilityObject* firstAccessibleObjectFromNode(const Node*, const WTF::Function<bool(const AccessibilityObject&)>& isAccessible);
 
 namespace Accessibility {

Modified: trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h (264270 => 264271)


--- trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h	2020-07-11 22:38:45 UTC (rev 264271)
@@ -25,12 +25,12 @@
 
 #pragma once
 
+// FIXME: Should rename this file AXCoreObject.h.
+
 #include "FrameLoaderClient.h"
 #include "HTMLTextFormControlElement.h"
 #include "LayoutRect.h"
-#include "Range.h"
 #include "TextIterator.h"
-#include "VisiblePosition.h"
 #include "VisibleSelection.h"
 #include <wtf/RefCounted.h>
 
@@ -42,6 +42,7 @@
 #if PLATFORM(COCOA)
 OBJC_CLASS WebAccessibilityObjectWrapper;
 typedef WebAccessibilityObjectWrapper AccessibilityObjectWrapper;
+typedef struct _NSRange NSRange;
 #elif USE(ATK)
 typedef struct _WebKitAccessible WebKitAccessible;
 typedef struct _WebKitAccessible AccessibilityObjectWrapper;
@@ -55,24 +56,25 @@
 
 namespace WebCore {
 
-class Node;
+class AXCoreObject;
+class AXObjectCache;
+class AccessibilityScrollView;
+class Document;
 class Element;
-class RenderObject;
-class QualifiedName;
-class Path;
-class Widget;
-class Page;
-class Document;
 class Frame;
 class FrameView;
+class Node;
+class Page;
+class Path;
+class QualifiedName;
+class RenderObject;
 class ScrollView;
-class AXObjectCache;
-class AXCoreObject;
-class AccessibilityScrollView;
+class Widget;
+
 struct AccessibilityText;
 struct ScrollRectToVisibleOptions;
 
-typedef size_t AXID;
+using AXID = size_t;
 extern const AXID InvalidAXID;
 
 enum class AccessibilityRole {
@@ -371,7 +373,7 @@
 };
 
 struct AccessibilityTextOperation {
-    Vector<RefPtr<Range>> textRanges; // text on which perform the operation.
+    Vector<SimpleRange> textRanges; // text on which perform the operation.
     AccessibilityTextOperationType type;
     String replacementText; // For type = replace.
 
@@ -404,10 +406,7 @@
     { }
 };
 
-#if PLATFORM(COCOA)
-typedef struct _NSRange NSRange;
-#endif
-
+// FIXME: Merge this with CharacterRange (by deleting this and using CharacterRange instead).
 struct PlainTextRange {
     unsigned start { 0 };
     unsigned length { 0 };
@@ -663,7 +662,7 @@
     virtual bool hasBoldFont() const = 0;
     virtual bool hasItalicFont() const = 0;
     virtual bool hasMisspelling() const = 0;
-    virtual RefPtr<Range> getMisspellingRange(RefPtr<Range> const& start, AccessibilitySearchDirection) const = 0;
+    virtual Optional<SimpleRange> misspellingRange(const SimpleRange& start, AccessibilitySearchDirection) const = 0;
     virtual bool hasPlainText() const = 0;
     virtual bool hasSameFont(const AXCoreObject&) const = 0;
     virtual bool hasSameFontColor(const AXCoreObject&) const = 0;
@@ -785,7 +784,7 @@
     virtual bool isDescendantOfRole(AccessibilityRole) const = 0;
 
     // Text selection
-    virtual Vector<RefPtr<Range>> findTextRanges(AccessibilitySearchTextCriteria const&) const = 0;
+    virtual Vector<SimpleRange> findTextRanges(const AccessibilitySearchTextCriteria&) const = 0;
     virtual Vector<String> performTextOperation(AccessibilityTextOperation const&) = 0;
 
     virtual AXCoreObject* observableObject() const = 0;
@@ -954,7 +953,7 @@
 
     virtual VisiblePositionRange visiblePositionRange() const = 0;
     virtual VisiblePositionRange visiblePositionRangeForLine(unsigned) const = 0;
-    virtual RefPtr<Range> elementRange() const = 0;
+    virtual Optional<SimpleRange> elementRange() const = 0;
     virtual VisiblePositionRange visiblePositionRangeForUnorderedPositions(const VisiblePosition&, const VisiblePosition&) const = 0;
     virtual VisiblePositionRange positionOfLeftWord(const VisiblePosition&) const = 0;
     virtual VisiblePositionRange positionOfRightWord(const VisiblePosition&) const = 0;
@@ -966,11 +965,11 @@
     virtual VisiblePositionRange visiblePositionRangeForRange(const PlainTextRange&) const = 0;
     virtual VisiblePositionRange lineRangeForPosition(const VisiblePosition&) const = 0;
 
-    virtual RefPtr<Range> rangeForPlainTextRange(const PlainTextRange&) const = 0;
+    virtual Optional<SimpleRange> rangeForPlainTextRange(const PlainTextRange&) const = 0;
 
-    virtual String stringForRange(RefPtr<Range>) const = 0;
+    virtual String stringForRange(const SimpleRange&) const = 0;
     virtual IntRect boundsForVisiblePositionRange(const VisiblePositionRange&) const = 0;
-    virtual IntRect boundsForRange(const RefPtr<Range>) const = 0;
+    virtual IntRect boundsForRange(const SimpleRange&) const = 0;
     virtual int lengthForVisiblePositionRange(const VisiblePositionRange&) const = 0;
     virtual void setSelectedVisiblePositionRange(const VisiblePositionRange&) const = 0;
 

Modified: trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp (264270 => 264271)


--- trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp	2020-07-11 22:38:45 UTC (rev 264271)
@@ -913,15 +913,11 @@
      may not belong to the link element and thus may not activate the link.
      Hence, return the middle point of the first character in the link if exists.
      */
-    if (RefPtr<Range> range = elementRange()) {
-        VisiblePosition start = range->startPosition();
-        VisiblePosition end = nextVisiblePosition(start);
-        if (start.isNull() || !range->contains(end))
-            return AccessibilityObject::clickPoint();
-
-        RefPtr<Range> charRange = makeRange(start, end);
-        IntRect rect = boundsForRange(charRange);
-        return { rect.x() + rect.width() / 2, rect.y() + rect.height() / 2 };
+    if (auto range = elementRange()) {
+        auto start = VisiblePosition { createLegacyEditingPosition(range->start) };
+        auto end = nextVisiblePosition(start);
+        if (!end.isNull() && createLiveRange(range)->contains(end))
+            return { boundsForRange({ *makeBoundaryPoint(start), *makeBoundaryPoint(end) }).center() };
     }
     return AccessibilityObject::clickPoint();
 }
@@ -941,8 +937,7 @@
     
     VisibleSelection visSelection = selection();
     VisiblePositionRange range = VisiblePositionRange(visSelection.visibleStart(), visSelection.visibleEnd());
-    IntRect bounds = boundsForVisiblePositionRange(range);
-    return { bounds.x() + (bounds.width() / 2), bounds.y() + (bounds.height() / 2) };
+    return boundsForVisiblePositionRange(range).center();
 }
     
 AccessibilityObject* AccessibilityRenderObject::internalLinkElement() const
@@ -1661,17 +1656,15 @@
         HTMLTextFormControlElement& textControl = downcast<RenderTextControl>(*m_renderer).textFormControlElement();
         textControl.setSelectionRange(range.start, range.start + range.length);
     } else {
-        auto node = this->node();
-        ASSERT(node);
+        ASSERT(node());
+        auto& node = *this->node();
         auto elementRange = this->elementRange();
-        VisiblePosition start = visiblePositionForIndexUsingCharacterIterator(*node, range.start);
-        if (!elementRange->contains(start))
-            start = VisiblePosition(elementRange->startPosition());
-        
-        VisiblePosition end = visiblePositionForIndexUsingCharacterIterator(*node, range.start + range.length);
-        if (!elementRange->contains(end))
-            end = VisiblePosition(elementRange->endPosition());
-        
+        auto start = visiblePositionForIndexUsingCharacterIterator(node, range.start);
+        if (!createLiveRange(elementRange)->contains(start))
+            start = createLegacyEditingPosition(elementRange->start);
+        auto end = visiblePositionForIndexUsingCharacterIterator(node, range.start + range.length);
+        if (!createLiveRange(elementRange)->contains(end))
+            end = createLegacyEditingPosition(elementRange->start);
         m_renderer->frame().selection().setSelection(VisibleSelection(start, end), FrameSelection::defaultSetSelectionOptions(UserTriggered));
     }
     
@@ -2167,24 +2160,21 @@
     return boundsForRects(rect1, rect2, *makeRange(range.start, range.end));
 }
 
-IntRect AccessibilityRenderObject::boundsForRange(const RefPtr<Range> range) const
+IntRect AccessibilityRenderObject::boundsForRange(const SimpleRange& range) const
 {
-    if (!range)
-        return IntRect();
-    
-    AXObjectCache* cache = this->axObjectCache();
+    auto cache = axObjectCache();
     if (!cache)
-        return IntRect();
-    
-    CharacterOffset start = cache->startOrEndCharacterOffsetForRange(*range, true);
-    CharacterOffset end = cache->startOrEndCharacterOffsetForRange(*range, false);
-    
-    LayoutRect rect1 = cache->absoluteCaretBoundsForCharacterOffset(start);
-    LayoutRect rect2 = cache->absoluteCaretBoundsForCharacterOffset(end);
-    
-    // readjust for position at the edge of a line. This is to exclude line rect that doesn't need to be accounted in the range bounds.
+        return { };
+
+    auto start = cache->startOrEndCharacterOffsetForRange(range, true);
+    auto end = cache->startOrEndCharacterOffsetForRange(range, false);
+
+    auto rect1 = cache->absoluteCaretBoundsForCharacterOffset(start);
+    auto rect2 = cache->absoluteCaretBoundsForCharacterOffset(end);
+
+    // Readjust for position at the edge of a line. This is to exclude line rect that doesn't need to be accounted in the range bounds.
     if (rect2.y() != rect1.y()) {
-        CharacterOffset endOfFirstLine = cache->endCharacterOffsetOfLine(start);
+        auto endOfFirstLine = cache->endCharacterOffsetOfLine(start);
         if (start.isEqual(endOfFirstLine)) {
             start = cache->nextCharacterOffset(start, false);
             rect1 = cache->absoluteCaretBoundsForCharacterOffset(start);
@@ -2194,8 +2184,8 @@
             rect2 = cache->absoluteCaretBoundsForCharacterOffset(end);
         }
     }
-    
-    return boundsForRects(rect1, rect2, *range);
+
+    return boundsForRects(rect1, rect2, range);
 }
 
 bool AccessibilityRenderObject::isVisiblePositionRangeInDifferentDocument(const VisiblePositionRange& range) const
@@ -2230,10 +2220,11 @@
     if (range.start == range.end) {
         setTextSelectionIntent(axObjectCache(), AXTextStateChangeTypeSelectionMove);
 
-        auto elementRange = this->elementRange();
         auto start = range.start;
-        if (elementRange && !elementRange->contains(start))
-            start = VisiblePosition(elementRange->startPosition());
+        if (auto elementRange = this->elementRange()) {
+            if (!createLiveRange(elementRange)->contains(start))
+                start = createLegacyEditingPosition(elementRange->start);
+        }
 
         m_renderer->frame().selection().moveTo(start, UserTriggered);
     } else {
@@ -2419,11 +2410,14 @@
     return IntRect();
 }
 
-IntRect AccessibilityRenderObject::doAXBoundsForRangeUsingCharacterOffset(const PlainTextRange& range) const
+IntRect AccessibilityRenderObject::doAXBoundsForRangeUsingCharacterOffset(const PlainTextRange& characterRange) const
 {
-    if (allowsTextRanges())
-        return boundsForRange(rangeForPlainTextRange(range));
-    return IntRect();
+    if (!allowsTextRanges())
+        return { };
+    auto range = rangeForPlainTextRange(characterRange);
+    if (!range)
+        return { };
+    return boundsForRange(*range);
 }
 
 AXCoreObject* AccessibilityRenderObject::accessibilityImageMapHitTest(HTMLAreaElement* area, const IntPoint& point) const

Modified: trunk/Source/WebCore/accessibility/AccessibilityRenderObject.h (264270 => 264271)


--- trunk/Source/WebCore/accessibility/AccessibilityRenderObject.h	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebCore/accessibility/AccessibilityRenderObject.h	2020-07-11 22:38:45 UTC (rev 264271)
@@ -166,7 +166,7 @@
     VisiblePositionRange visiblePositionRange() const override;
     VisiblePositionRange visiblePositionRangeForLine(unsigned) const override;
     IntRect boundsForVisiblePositionRange(const VisiblePositionRange&) const override;
-    IntRect boundsForRange(const RefPtr<Range>) const override;
+    IntRect boundsForRange(const SimpleRange&) const override;
     void setSelectedVisiblePositionRange(const VisiblePositionRange&) const override;
     bool isVisiblePositionRangeInDifferentDocument(const VisiblePositionRange&) const;
     bool hasPopup() const override;

Modified: trunk/Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp (264270 => 264271)


--- trunk/Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp	2020-07-11 22:38:45 UTC (rev 264271)
@@ -43,6 +43,7 @@
 #include "HostWindow.h"
 #include "InlineTextBox.h"
 #include "NotImplemented.h"
+#include "Range.h"
 #include "RenderListItem.h"
 #include "RenderListMarker.h"
 #include "RenderText.h"

Modified: trunk/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm (264270 => 264271)


--- trunk/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm	2020-07-11 22:38:45 UTC (rev 264271)
@@ -2129,12 +2129,10 @@
 {
     if (![self _prepareAccessibilityCall])
         return nil;
-    
-    RefPtr<Range> range = [self rangeForTextMarkers:markers];
+    auto range = [self rangeForTextMarkers:markers];
     if (!range)
         return nil;
-    
-    return self.axBackingObject->stringForRange(range);
+    return self.axBackingObject->stringForRange(*range);
 }
 
 static int blockquoteLevel(RenderObject* renderer)
@@ -2411,9 +2409,7 @@
 {
     if (![self _prepareAccessibilityCall])
         return nil;
-    
-    RefPtr<Range> range = self.axBackingObject->elementRange();
-    return [self textMarkersForRange:range];
+    return [self textMarkersForRange:createLiveRange(self.axBackingObject->elementRange()).get()];
 }
 
 // A method to get the normalized text cursor range of an element. Used in DumpRenderTree.
@@ -2551,8 +2547,10 @@
 {
     if (![self _prepareAccessibilityCall])
         return nil;
-
-    return self.axBackingObject->stringForRange([self _convertToDOMRange:range]);
+    auto webRange = [self _convertToDOMRange:range];
+    if (!webRange)
+        return nil;
+    return self.axBackingObject->stringForRange(*webRange);
 }
 
 - (NSAttributedString *)attributedStringForRange:(NSRange)range
@@ -2685,14 +2683,12 @@
 {
     if (![self _prepareAccessibilityCall])
         return nil;
-
-    RefPtr<Range> startRange = [self rangeForTextMarkers:startTextMarkerRange];
+    auto startRange = [self rangeForTextMarkers:startTextMarkerRange];
     if (!startRange)
         return nil;
-
-    RefPtr<Range> misspellingRange = self.axBackingObject->getMisspellingRange(startRange,
+    auto misspellingRange = self.axBackingObject->misspellingRange(*startRange,
         forward ? AccessibilitySearchDirection::Next : AccessibilitySearchDirection::Previous);
-    return [self textMarkersForRange:misspellingRange];
+    return [self textMarkersForRange:createLiveRange(misspellingRange).get()];
 }
 
 - (WebAccessibilityTextMarker *)nextMarkerForMarker:(WebAccessibilityTextMarker *)marker
@@ -2724,15 +2720,13 @@
 {
     if (![self _prepareAccessibilityCall])
         return CGRectZero;
-
     AXObjectCache* cache = self.axBackingObject->axObjectCache();
     if (!cache)
         return CGRectZero;
-    RefPtr<Range> range = [self rangeForTextMarkers:array];
+    auto range = [self rangeForTextMarkers:array];
     if (!range)
         return CGRectZero;
-    
-    auto rect = FloatRect(self.axBackingObject->boundsForRange(range));
+    auto rect = self.axBackingObject->boundsForRange(*range);
     return [self convertRectToSpace:rect space:AccessibilityConversionSpace::Screen];
 }
 

Modified: trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp (264270 => 264271)


--- trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp	2020-07-11 22:38:45 UTC (rev 264271)
@@ -898,7 +898,7 @@
         tree->applyPendingChanges();
 }
 
-String AXIsolatedObject::stringForRange(RefPtr<Range> range) const
+String AXIsolatedObject::stringForRange(const SimpleRange& range) const
 {
     return Accessibility::retrieveValueFromMainThread<String>([&range, this] () -> String {
         if (auto* object = associatedAXObject())
@@ -907,12 +907,12 @@
     });
 }
 
-Vector<RefPtr<Range>> AXIsolatedObject::findTextRanges(AccessibilitySearchTextCriteria const& criteria) const
+Vector<SimpleRange> AXIsolatedObject::findTextRanges(const AccessibilitySearchTextCriteria& criteria) const
 {
-    return Accessibility::retrieveValueFromMainThread<Vector<RefPtr<Range>>>([&criteria, this] () -> Vector<RefPtr<Range>> {
+    return Accessibility::retrieveValueFromMainThread<Vector<SimpleRange>>([&criteria, this] () -> Vector<SimpleRange> {
         if (auto* object = associatedAXObject())
             return object->findTextRanges(criteria);
-        return Vector<RefPtr<Range>>();
+        return { };
     });
 }
 

Modified: trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h (264270 => 264271)


--- trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h	2020-07-11 22:38:45 UTC (rev 264271)
@@ -636,7 +636,7 @@
     String stringValue() const override { return stringAttributeValue(AXPropertyName::StringValue); }
 
     // Parameterized attribute retrieval.
-    Vector<RefPtr<Range>> findTextRanges(AccessibilitySearchTextCriteria const&) const override;
+    Vector<SimpleRange> findTextRanges(const AccessibilitySearchTextCriteria&) const override;
     Vector<String> performTextOperation(AccessibilityTextOperation const&) override;
     void findMatchingObjects(AccessibilitySearchCriteria*, AccessibilityChildrenVector&) override;
 
@@ -655,7 +655,7 @@
     String selectedText() const override { return String(); }
     VisiblePositionRange visiblePositionRange() const override { return VisiblePositionRange(); }
     VisiblePositionRange visiblePositionRangeForLine(unsigned) const override { return VisiblePositionRange(); }
-    RefPtr<Range> elementRange() const override { return nullptr; }
+    Optional<SimpleRange> elementRange() const override { return WTF::nullopt; }
     VisiblePositionRange visiblePositionRangeForUnorderedPositions(const VisiblePosition&, const VisiblePosition&) const override { return VisiblePositionRange(); }
     VisiblePositionRange positionOfLeftWord(const VisiblePosition&) const override { return VisiblePositionRange(); }
     VisiblePositionRange positionOfRightWord(const VisiblePosition&) const override { return VisiblePositionRange(); }
@@ -666,10 +666,10 @@
     VisiblePositionRange styleRangeForPosition(const VisiblePosition&) const override { return VisiblePositionRange(); }
     VisiblePositionRange visiblePositionRangeForRange(const PlainTextRange&) const override { return VisiblePositionRange(); }
     VisiblePositionRange lineRangeForPosition(const VisiblePosition&) const override { return VisiblePositionRange(); }
-    RefPtr<Range> rangeForPlainTextRange(const PlainTextRange&) const override { return nullptr; }
-    String stringForRange(RefPtr<Range>) const override;
+    Optional<SimpleRange> rangeForPlainTextRange(const PlainTextRange&) const override { return WTF::nullopt; }
+    String stringForRange(const SimpleRange&) const override;
     IntRect boundsForVisiblePositionRange(const VisiblePositionRange&) const override { return IntRect(); }
-    IntRect boundsForRange(const RefPtr<Range>) const override { return IntRect(); }
+    IntRect boundsForRange(const SimpleRange&) const override { return IntRect(); }
     int lengthForVisiblePositionRange(const VisiblePositionRange&) const override { return 0; }
     VisiblePosition visiblePositionForBounds(const IntRect&, AccessibilityVisiblePositionForBounds) const override { return VisiblePosition(); }
     VisiblePosition visiblePositionForPoint(const IntPoint&) const override { return VisiblePosition(); }
@@ -717,7 +717,7 @@
 
     // TODO: Functions
     String textUnderElement(AccessibilityTextUnderElementMode = AccessibilityTextUnderElementMode()) const override { return String(); }
-    RefPtr<Range> getMisspellingRange(RefPtr<Range> const&, AccessibilitySearchDirection) const override { return nullptr; }
+    Optional<SimpleRange> misspellingRange(const SimpleRange&, AccessibilitySearchDirection) const override { return WTF::nullopt; }
     FloatRect convertFrameToSpace(const FloatRect&, AccessibilityConversionSpace) const override { return FloatRect(); }
     void increment() override { }
     void decrement() override { }

Modified: trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm (264270 => 264271)


--- trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm	2020-07-11 22:38:45 UTC (rev 264271)
@@ -682,7 +682,7 @@
     return criteria;
 }
 
-static AccessibilityTextOperation accessibilityTextOperationForParameterizedAttribute(WebAccessibilityObjectWrapper *obj, const NSDictionary *parameterizedAttribute)
+static AccessibilityTextOperation accessibilityTextOperationForParameterizedAttribute(WebAccessibilityObjectWrapper *wrapper, const NSDictionary *parameterizedAttribute)
 {
     AccessibilityTextOperation operation;
 
@@ -691,10 +691,9 @@
     NSString *replacementString = [parameterizedAttribute objectForKey:NSAccessibilityTextOperationReplacementString];
 
     if ([markerRanges isKindOfClass:[NSArray class]]) {
-        size_t count = static_cast<size_t>(markerRanges.count);
-        operation.textRanges.reserveInitialCapacity(count);
-        for (id markerRange : markerRanges)
-            operation.textRanges.append([obj rangeForTextMarkerRange:markerRange]);
+        operation.textRanges = makeVector(markerRanges, [wrapper] (id markerRange) {
+            return makeSimpleRange([wrapper rangeForTextMarkerRange:markerRange]);
+        });
     }
 
     if ([operationType isKindOfClass:[NSString class]]) {
@@ -3623,11 +3622,10 @@
 
 // The CFAttributedStringType representation of the text associated with this accessibility
 // object that is specified by the given range.
-- (NSAttributedString*)doAXAttributedStringForRange:(NSRange)range
+- (NSAttributedString *)doAXAttributedStringForRange:(NSRange)range
 {
-    PlainTextRange textRange = PlainTextRange(range.location, range.length);
-    RefPtr<Range> webRange = self.axBackingObject->rangeForPlainTextRange(textRange);
-    return [self doAXAttributedStringForTextMarkerRange:[self textMarkerRangeFromRange:webRange] spellCheck:YES];
+    auto webRange = self.axBackingObject->rangeForPlainTextRange(range);
+    return [self doAXAttributedStringForTextMarkerRange:[self textMarkerRangeFromRange:createLiveRange(webRange)] spellCheck:YES];
 }
 
 - (NSRange)_convertToNSRange:(Range*)range
@@ -3963,7 +3961,7 @@
             if (ranges.isEmpty())
                 return nil;
             return createNSArray(ranges, [&] (auto& range) {
-                return [protectedSelf textMarkerRangeFromRange:range];
+                return [protectedSelf textMarkerRangeFromRange:createLiveRange(range)];
             }).autorelease();
         });
     }
@@ -4038,8 +4036,8 @@
             if (!backingObject)
                 return nil;
 
-            if (auto misspellingRange = backingObject->getMisspellingRange(criteria.first, criteria.second))
-                return [protectedSelf textMarkerRangeFromRange:misspellingRange];
+            if (auto misspellingRange = backingObject->misspellingRange(*criteria.first, criteria.second))
+                return [protectedSelf textMarkerRangeFromRange:createLiveRange(*misspellingRange)];
             return nil;
         });
     }
@@ -4079,8 +4077,7 @@
 
     if ([attribute isEqualToString:@"AXTextMarkerRangeForUIElement"]) {
         return Accessibility::retrieveAutoreleasedValueFromMainThread<id>([&uiElement, protectedSelf = retainPtr(self)] () -> RetainPtr<id> {
-            RefPtr<Range> range = uiElement.get()->elementRange();
-            return [protectedSelf textMarkerRangeFromRange:range];
+            return [protectedSelf textMarkerRangeFromRange:createLiveRange(uiElement.get()->elementRange())];
         });
     }
 
@@ -4111,9 +4108,9 @@
 
     if ([attribute isEqualToString:@"AXStringForTextMarkerRange"]) {
         return Accessibility::retrieveValueFromMainThread<String>([&textMarkerRange, protectedSelf = retainPtr(self)] () -> String {
-            RefPtr<Range> range = [protectedSelf rangeForTextMarkerRange:textMarkerRange];
+            auto range = [protectedSelf rangeForTextMarkerRange:textMarkerRange];
             auto* backingObject = protectedSelf.get().axBackingObject;
-            return backingObject ? backingObject->stringForRange(range) : String();
+            return (range && backingObject) ? backingObject->stringForRange(*range) : String();
         });
     }
 
@@ -4141,9 +4138,10 @@
             auto* backingObject = protectedSelf.get().axBackingObject;
             if (!backingObject)
                 return CGRectZero;
-
-            RefPtr<Range> range = [protectedSelf rangeForTextMarkerRange:textMarkerRange];
-            auto bounds = FloatRect(backingObject->boundsForRange(range));
+            auto range = [protectedSelf rangeForTextMarkerRange:textMarkerRange];
+            if (!range)
+                return CGRectZero;
+            auto bounds = FloatRect(backingObject->boundsForRange(*range));
             return [protectedSelf convertRectToSpace:bounds space:AccessibilityConversionSpace::Screen];
         });
         return [NSValue valueWithRect:rect];
@@ -4154,18 +4152,15 @@
             auto* backingObject = protectedSelf.get().axBackingObject;
             if (!backingObject)
                 return CGRectZero;
-
             auto* cache = backingObject->axObjectCache();
             if (!cache)
                 return CGRectZero;
-
             CharacterOffset start = cache->characterOffsetForIndex(range.location, backingObject);
             CharacterOffset end = cache->characterOffsetForIndex(range.location+range.length, backingObject);
-            if (start.isNull() || end.isNull())
+            auto range = cache->rangeForUnorderedCharacterOffsets(start, end);
+            if (!range)
                 return CGRectZero;
-
-            auto range = cache->rangeForUnorderedCharacterOffsets(start, end);
-            auto bounds = FloatRect(backingObject->boundsForRange(createLiveRange(range)));
+            auto bounds = FloatRect(backingObject->boundsForRange(*range));
             return [protectedSelf convertRectToSpace:bounds space:AccessibilityConversionSpace::Screen];
         });
         return [NSValue valueWithRect:rect];
@@ -4181,18 +4176,15 @@
             auto* backingObject = protectedSelf.get().axBackingObject;
             if (!backingObject)
                 return String();
-
             auto* cache = backingObject->axObjectCache();
             if (!cache)
                 return String();
-
-            CharacterOffset start = cache->characterOffsetForIndex(range.location, backingObject);
-            CharacterOffset end = cache->characterOffsetForIndex(range.location + range.length, backingObject);
-            if (start.isNull() || end.isNull())
-                return String();
-
+            auto start = cache->characterOffsetForIndex(range.location, backingObject);
+            auto end = cache->characterOffsetForIndex(range.location + range.length, backingObject);
             auto range = cache->rangeForUnorderedCharacterOffsets(start, end);
-            return backingObject->stringForRange(createLiveRange(range));
+            if (!range)
+                return { };
+            return backingObject->stringForRange(*range);
         });
     }
 

Modified: trunk/Source/WebCore/dom/Range.cpp (264270 => 264271)


--- trunk/Source/WebCore/dom/Range.cpp	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebCore/dom/Range.cpp	2020-07-11 22:38:45 UTC (rev 264271)
@@ -1833,6 +1833,28 @@
     return boundingRect(CoordinateSpace::Absolute, rectOptions);
 }
 
+SimpleRange makeSimpleRange(const Range& range)
+{
+    return { { range.startContainer(), range.startOffset() }, { range.endContainer(), range.endOffset() } };
+}
+
+SimpleRange makeSimpleRange(const Ref<Range>& range)
+{
+    return makeSimpleRange(range.get());
+}
+
+Optional<SimpleRange> makeSimpleRange(const Range* range)
+{
+    if (!range)
+        return WTF::nullopt;
+    return makeSimpleRange(*range);
+}
+
+Optional<SimpleRange> makeSimpleRange(const RefPtr<Range>& range)
+{
+    return makeSimpleRange(range.get());
+}
+
 Ref<Range> createLiveRange(const SimpleRange& range)
 {
     return Range::create(range.start.document(), range.start.container.ptr(), range.start.offset, range.end.container.ptr(), range.end.offset);

Modified: trunk/Source/WebCore/dom/Range.h (264270 => 264271)


--- trunk/Source/WebCore/dom/Range.h	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebCore/dom/Range.h	2020-07-11 22:38:45 UTC (rev 264271)
@@ -176,6 +176,11 @@
 WEBCORE_EXPORT bool areRangesEqual(const Range*, const Range*);
 WEBCORE_EXPORT bool rangesOverlap(const Range*, const Range*);
 
+SimpleRange makeSimpleRange(const Range&);
+SimpleRange makeSimpleRange(const Ref<Range>&);
+Optional<SimpleRange> makeSimpleRange(const Range*);
+Optional<SimpleRange> makeSimpleRange(const RefPtr<Range>&);
+
 WEBCORE_EXPORT Ref<Range> createLiveRange(const SimpleRange&);
 WEBCORE_EXPORT RefPtr<Range> createLiveRange(const Optional<SimpleRange>&);
 

Modified: trunk/Source/WebCore/dom/SimpleRange.h (264270 => 264271)


--- trunk/Source/WebCore/dom/SimpleRange.h	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebCore/dom/SimpleRange.h	2020-07-11 22:38:45 UTC (rev 264271)
@@ -46,7 +46,7 @@
     WEBCORE_EXPORT SimpleRange(BoundaryPoint&&, BoundaryPoint&&);
 
     // Convenience overloads to help with transition from using a lot of live ranges.
-    // FIXME: Move to the Range class header as either makeSimpleRange or Range::operator SimpleRange.
+    // FIXME: Once transition is over, remove and change callers to use makeSimpleRange instead.
     WEBCORE_EXPORT SimpleRange(const Range&);
     SimpleRange(const Ref<Range>&);
 };

Modified: trunk/Source/WebCore/editing/Editing.cpp (264270 => 264271)


--- trunk/Source/WebCore/editing/Editing.cpp	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebCore/editing/Editing.cpp	2020-07-11 22:38:45 UTC (rev 264271)
@@ -1105,8 +1105,10 @@
     }
 
     auto start = makeBoundaryPoint(firstPositionInNode(scope.get()));
+    if (!start)
+        return 0;
     auto end = makeBoundaryPoint(position.parentAnchoredEquivalent());
-    if (!start || !end)
+    if (!end)
         return 0;
 
     return characterCount({ *start, *end }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
@@ -1116,8 +1118,10 @@
 int indexForVisiblePosition(Node& node, const VisiblePosition& visiblePosition, bool forSelectionPreservation)
 {
     auto start = makeBoundaryPoint(firstPositionInNode(&node));
+    if (!start)
+        return 0;
     auto end = makeBoundaryPoint(visiblePosition.deepEquivalent().parentAnchoredEquivalent());
-    if (!start || !end)
+    if (!end)
         return 0;
 
     return characterCount({ *start, *end }, forSelectionPreservation ? TextIteratorEmitsCharactersBetweenAllVisiblePositions : TextIteratorDefaultBehavior);

Modified: trunk/Source/WebCore/editing/TextCheckingHelper.cpp (264270 => 264271)


--- trunk/Source/WebCore/editing/TextCheckingHelper.cpp	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebCore/editing/TextCheckingHelper.cpp	2020-07-11 22:38:45 UTC (rev 264271)
@@ -159,8 +159,10 @@
 ExceptionOr<uint64_t> TextCheckingParagraph::offsetTo(const Position& position) const
 {
     auto start = makeBoundaryPoint(paragraphRange().startPosition());
+    if (!start)
+        return Exception { TypeError };
     auto end = makeBoundaryPoint(position);
-    if (!start || !end)
+    if (!end)
         return Exception { TypeError };
     return characterCount({ *start, *end });
 }
@@ -212,8 +214,10 @@
         return *m_automaticReplacementStart;
 
     auto start = makeBoundaryPoint(paragraphRange().startPosition());
+    if (!start)
+        return 0;
     auto end = makeBoundaryPoint(m_automaticReplacementRange->startPosition());
-    if (!start || !end)
+    if (!end)
         return 0;
 
     m_automaticReplacementStart = characterCount({ *start, *end });

Modified: trunk/Source/WebCore/page/FocusController.cpp (264270 => 264271)


--- trunk/Source/WebCore/page/FocusController.cpp	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebCore/page/FocusController.cpp	2020-07-11 22:38:45 UTC (rev 264271)
@@ -982,10 +982,9 @@
     LayoutRect intersectionRect = intersection(candidate.rect, closest.rect);
     if (!intersectionRect.isEmpty() && !areElementsOnSameLine(closest, candidate)) {
         // If 2 nodes are intersecting, do hit test to find which node in on top.
-        LayoutUnit x = intersectionRect.x() + intersectionRect.width() / 2;
-        LayoutUnit y = intersectionRect.y() + intersectionRect.height() / 2;
+        auto center = flooredIntPoint(intersectionRect.center()); // FIXME: Would roundedIntPoint be better?
         constexpr OptionSet<HitTestRequest::RequestType> hitType { HitTestRequest::ReadOnly, HitTestRequest::Active, HitTestRequest::IgnoreClipping, HitTestRequest::DisallowUserAgentShadowContent, HitTestRequest::AllowChildFrameContent };
-        HitTestResult result = candidate.visibleNode->document().page()->mainFrame().eventHandler().hitTestResultAtPoint(IntPoint(x, y), hitType);
+        HitTestResult result = candidate.visibleNode->document().page()->mainFrame().eventHandler().hitTestResultAtPoint(center, hitType);
         if (candidate.visibleNode->contains(result.innerNode())) {
             closest = candidate;
             return;

Modified: trunk/Source/WebKit/ChangeLog (264270 => 264271)


--- trunk/Source/WebKit/ChangeLog	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebKit/ChangeLog	2020-07-11 22:38:45 UTC (rev 264271)
@@ -1,3 +1,14 @@
+2020-07-11  Darin Adler  <[email protected]>
+
+        Remove live ranges from AccessibilityObject.h, AccessibilityObjectInterface.h, AccessibilityRenderObject.h, AXIsolatedObject.h
+        https://bugs.webkit.org/show_bug.cgi?id=214215
+
+        Reviewed by Sam Weinig.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::requestDocumentEditingContext): Use nested if for start and end
+        so we don't do the work on end if the test fails on start.
+
 2020-07-10  Brent Fulgham  <[email protected]>
 
         [iOS] Prompt for requestStorageAccess is inverted in WKWebView 

Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (264270 => 264271)


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2020-07-11 22:12:44 UTC (rev 264270)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2020-07-11 22:38:45 UTC (rev 264271)
@@ -4302,11 +4302,11 @@
         if (auto contextRange = makeRange(contextBeforeStart, contextAfterEnd))
             context.textRects = characterRectsForRange(*contextRange, 0);
     } else if (wantsMarkedTextRects && compositionRange) {
-        auto start = makeBoundaryPoint(contextBeforeStart.deepEquivalent());
-        auto end = makeBoundaryPoint(compositionRange->startPosition());
         unsigned compositionStartOffset = 0;
-        if (start && end)
-            compositionStartOffset = WebCore::plainText(SimpleRange { WTFMove(*start), WTFMove(*end) }).length();
+        if (auto start = makeBoundaryPoint(contextBeforeStart.deepEquivalent())) {
+            if (auto end = makeBoundaryPoint(compositionRange->startPosition()))
+                compositionStartOffset = WebCore::plainText(SimpleRange { WTFMove(*start), WTFMove(*end) }).length();
+        }
         context.textRects = characterRectsForRange(*compositionRange, compositionStartOffset);
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to