Title: [258475] trunk/Source
Revision
258475
Author
[email protected]
Date
2020-03-14 15:59:34 -0700 (Sat, 14 Mar 2020)

Log Message

Change all return values in TextIterator header from live ranges to SimpleRange
https://bugs.webkit.org/show_bug.cgi?id=208906

Reviewed by Antti Koivisto.

Source/WebCore:

This is another step in moving off of live ranges for WebKit internals.

- Change return values of remaining functions that were returning live ranges in
  the TextIterator header to return SimpleRange.
- Change some arguments from live ranges to SimpleRange.
- At some call sites, use createLiveRange to convert the SimpleRange into a live
  range (for now), but at others update the code to use SimpleRange.
- Renamed a version of findPlainText that returns a boolean to containsPlainText.
- Convert call sites that were using createLiveRange just to use the
  Range::startPosition and Range::endPosition functions to instead use a new
  overload of the createLegacyEditingPosition function that can be used with
  SimpleRange::start and SimpleRange::end because it takes a BoundaryPoint.

* accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::rangeMatchesTextNearRange): Return Optional<SimpleRange>
and take SimpleRange argument.
(WebCore::AXObjectCache::previousBoundary): Updated since
SimplifiedBackwardsTextIterator::range now returns SimpleRange.
* accessibility/AXObjectCache.h: Updated for the above.

* accessibility/AccessibilityObjectInterface.h:
(WebCore::AXCoreObject::containsText const): Updated for name change.
Now containsPlainText instead of findPlainText.

* accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
(-[WebAccessibilityObjectWrapper arrayOfTextForTextMarkers:attributed:]):
Use createLegacyEditingPosition instead of createLiveRange.
(-[WebAccessibilityObjectWrapper rangeFromMarkers:withText:]): Use createLiveRange.

* accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(-[WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange:spellCheck:]):
Use createLegacyEditingPosition instead of createLiveRange.

* dom/Position.cpp:
(WebCore::createLegacyEditingPosition): Added an overload that takes a BoundaryPoint.
* dom/Position.h: Updated for the above, also removed unneeded includes and forward
declarations.

* editing/Editing.cpp:
(WebCore::visiblePositionForIndexUsingCharacterIterator): Updated since
CharacterIterator::range is now a SimpleRange, use createLegacyEditingPosition.

* editing/Editor.cpp:
(WebCore::Editor::advanceToNextMisspelling): Updated since CharacterIterator::range
is now a SimpleRange.
(WebCore::Editor::rangeOfString): Updated since findPlainText now returns a
SimpleRange; use createLiveRange.
(WebCore::Editor::countMatchesForText): Ditto.

* editing/TextIterator.cpp:
(WebCore::SimplifiedBackwardsTextIterator::range const): Return a SimpleRange.
(WebCore::CharacterIterator::range const): Ditto.
(WebCore::characterSubrange): Updated since CharacterIterator::range returns
a SimpleRange. Use createLiveRange.
(WebCore::BackwardsCharacterIterator::BackwardsCharacterIterator): Cut down
code here by initializing data members in the class definition.
(WebCore::BackwardsCharacterIterator::range const): Return a SimpleRange.
(WebCore::WordAwareIterator::WordAwareIterator): Cut down code here by
initializing data members in the class definition.
(WebCore::hasAnyPlainText): Take a SimpleRange, use createLiveRange.
(WebCore::plainTextUsingBackwardsTextIteratorForTesting): Take a SimpleRange,
use createLiveRange.
(WebCore::collapsedToBoundary): Take and return a SimpleRange.
(WebCore::findPlainTextMatches): Take a SimpleRange, use createLiveRange.
(WebCore::rangeForMatch): Take and return a SimpleRange.
(WebCore::findClosestPlainText): Ditto.
(WebCore::findPlainText): Ditto.
(WebCore::containsPlainText): Renamed from findPlainText since this returns
a boolean, not a found location of some text.
* editing/TextIterator.h: Updated for the above. Also changed some data
members to use unsigned for offsets rather than int.

* editing/TextManipulationController.cpp:
(WebCore::ParagraphContentIterator::startPosition): Use
createLegacyEditingPosition instead of createLiveRange.
(WebCore::ParagraphContentIterator::endPosition): Ditto.

* editing/VisiblePosition.h: Added a forward declaration here since Position.h
no longer forward declares it.

* editing/VisibleSelection.cpp:
(WebCore::VisibleSelection::appendTrailingWhitespace): Updated since
CharacterIterator::range is now a SimpleRange, use createLegacyEditingPosition.
* editing/VisibleUnits.cpp:
(WebCore::previousBoundary): Ditto.
(WebCore::nextBoundary): Ditto.

* testing/Internals.cpp:
(WebCore::Internals::rangeOfStringNearLocation): Updated since
findClosestPlainText now returns a SimpleRange, use createLiveRange.

Source/WebKit:

* WebProcess/WebPage/Cocoa/WebPageCocoa.mm: Removed unneeded include of
TextIterator.h.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::rangeNearPositionMatchesText): Removed unused originalRange argument,
changed return type to Optional<SimpleRange> since findClosestPlainText now
returns a SimpleRange.
(WebKit::WebPage::getRectsAtSelectionOffsetWithText): Updated since
rangeNearPositionMatchesText now returns Optional<SimpleRange>, use createLiveRange.
(WebKit::WebPage::requestDocumentEditingContext): Updated since
CharacterIterator::range returns SimpleRange, use createLiveRange.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (258474 => 258475)


--- trunk/Source/WebCore/ChangeLog	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebCore/ChangeLog	2020-03-14 22:59:34 UTC (rev 258475)
@@ -1,3 +1,101 @@
+2020-03-10  Darin Adler  <[email protected]>
+
+        Change all return values in TextIterator header from live ranges to SimpleRange
+        https://bugs.webkit.org/show_bug.cgi?id=208906
+
+        Reviewed by Antti Koivisto.
+
+        This is another step in moving off of live ranges for WebKit internals.
+
+        - Change return values of remaining functions that were returning live ranges in
+          the TextIterator header to return SimpleRange.
+        - Change some arguments from live ranges to SimpleRange.
+        - At some call sites, use createLiveRange to convert the SimpleRange into a live
+          range (for now), but at others update the code to use SimpleRange.
+        - Renamed a version of findPlainText that returns a boolean to containsPlainText.
+        - Convert call sites that were using createLiveRange just to use the
+          Range::startPosition and Range::endPosition functions to instead use a new
+          overload of the createLegacyEditingPosition function that can be used with
+          SimpleRange::start and SimpleRange::end because it takes a BoundaryPoint.
+
+        * accessibility/AXObjectCache.cpp:
+        (WebCore::AXObjectCache::rangeMatchesTextNearRange): Return Optional<SimpleRange>
+        and take SimpleRange argument.
+        (WebCore::AXObjectCache::previousBoundary): Updated since
+        SimplifiedBackwardsTextIterator::range now returns SimpleRange.
+        * accessibility/AXObjectCache.h: Updated for the above.
+
+        * accessibility/AccessibilityObjectInterface.h:
+        (WebCore::AXCoreObject::containsText const): Updated for name change.
+        Now containsPlainText instead of findPlainText.
+
+        * accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
+        (-[WebAccessibilityObjectWrapper arrayOfTextForTextMarkers:attributed:]):
+        Use createLegacyEditingPosition instead of createLiveRange.
+        (-[WebAccessibilityObjectWrapper rangeFromMarkers:withText:]): Use createLiveRange.
+
+        * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+        (-[WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange:spellCheck:]):
+        Use createLegacyEditingPosition instead of createLiveRange.
+
+        * dom/Position.cpp:
+        (WebCore::createLegacyEditingPosition): Added an overload that takes a BoundaryPoint.
+        * dom/Position.h: Updated for the above, also removed unneeded includes and forward
+        declarations.
+
+        * editing/Editing.cpp:
+        (WebCore::visiblePositionForIndexUsingCharacterIterator): Updated since
+        CharacterIterator::range is now a SimpleRange, use createLegacyEditingPosition.
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::advanceToNextMisspelling): Updated since CharacterIterator::range
+        is now a SimpleRange.
+        (WebCore::Editor::rangeOfString): Updated since findPlainText now returns a
+        SimpleRange; use createLiveRange.
+        (WebCore::Editor::countMatchesForText): Ditto.
+
+        * editing/TextIterator.cpp:
+        (WebCore::SimplifiedBackwardsTextIterator::range const): Return a SimpleRange.
+        (WebCore::CharacterIterator::range const): Ditto.
+        (WebCore::characterSubrange): Updated since CharacterIterator::range returns
+        a SimpleRange. Use createLiveRange.
+        (WebCore::BackwardsCharacterIterator::BackwardsCharacterIterator): Cut down
+        code here by initializing data members in the class definition.
+        (WebCore::BackwardsCharacterIterator::range const): Return a SimpleRange.
+        (WebCore::WordAwareIterator::WordAwareIterator): Cut down code here by
+        initializing data members in the class definition.
+        (WebCore::hasAnyPlainText): Take a SimpleRange, use createLiveRange.
+        (WebCore::plainTextUsingBackwardsTextIteratorForTesting): Take a SimpleRange,
+        use createLiveRange.
+        (WebCore::collapsedToBoundary): Take and return a SimpleRange.
+        (WebCore::findPlainTextMatches): Take a SimpleRange, use createLiveRange.
+        (WebCore::rangeForMatch): Take and return a SimpleRange.
+        (WebCore::findClosestPlainText): Ditto.
+        (WebCore::findPlainText): Ditto.
+        (WebCore::containsPlainText): Renamed from findPlainText since this returns
+        a boolean, not a found location of some text.
+        * editing/TextIterator.h: Updated for the above. Also changed some data
+        members to use unsigned for offsets rather than int.
+
+        * editing/TextManipulationController.cpp:
+        (WebCore::ParagraphContentIterator::startPosition): Use
+        createLegacyEditingPosition instead of createLiveRange.
+        (WebCore::ParagraphContentIterator::endPosition): Ditto.
+
+        * editing/VisiblePosition.h: Added a forward declaration here since Position.h
+        no longer forward declares it.
+
+        * editing/VisibleSelection.cpp:
+        (WebCore::VisibleSelection::appendTrailingWhitespace): Updated since
+        CharacterIterator::range is now a SimpleRange, use createLegacyEditingPosition.
+        * editing/VisibleUnits.cpp:
+        (WebCore::previousBoundary): Ditto.
+        (WebCore::nextBoundary): Ditto.
+
+        * testing/Internals.cpp:
+        (WebCore::Internals::rangeOfStringNearLocation): Updated since
+        findClosestPlainText now returns a SimpleRange, use createLiveRange.
+
 2020-03-14  Zalan Bujtas  <[email protected]>
 
         [LFC][TFC] Fill in the gaps with anonymous table cell boxes

Modified: trunk/Source/WebCore/accessibility/AXObjectCache.cpp (258474 => 258475)


--- trunk/Source/WebCore/accessibility/AXObjectCache.cpp	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebCore/accessibility/AXObjectCache.cpp	2020-03-14 22:59:34 UTC (rev 258475)
@@ -1934,28 +1934,25 @@
     return range;
 }
     
-RefPtr<Range> AXObjectCache::rangeMatchesTextNearRange(RefPtr<Range> originalRange, const String& matchText)
+Optional<SimpleRange> AXObjectCache::rangeMatchesTextNearRange(const SimpleRange& originalRange, const String& matchText)
 {
-    if (!originalRange)
-        return nullptr;
-    
     // Create a large enough range for searching the text within.
     unsigned textLength = matchText.length();
-    auto startPosition = visiblePositionForPositionWithOffset(originalRange->startPosition(), -textLength);
-    auto endPosition = visiblePositionForPositionWithOffset(originalRange->startPosition(), 2 * textLength);
-    
+    auto startPosition = visiblePositionForPositionWithOffset(createLegacyEditingPosition(originalRange.start), -textLength);
+    auto endPosition = visiblePositionForPositionWithOffset(createLegacyEditingPosition(originalRange.start), 2 * textLength);
+
     if (startPosition.isNull())
-        startPosition = firstPositionInOrBeforeNode(&originalRange->startContainer());
+        startPosition = firstPositionInOrBeforeNode(originalRange.start.container.ptr());
     if (endPosition.isNull())
-        endPosition = lastPositionInOrAfterNode(&originalRange->endContainer());
-    
+        endPosition = lastPositionInOrAfterNode(originalRange.end.container.ptr());
+
     auto searchRange = Range::create(m_document, startPosition, endPosition);
     if (searchRange->collapsed())
-        return nullptr;
-    
-    auto range = Range::create(m_document, startPosition, originalRange->startPosition());
+        return WTF::nullopt;
+
+    auto range = Range::create(m_document, startPosition, createLegacyEditingPosition(originalRange.start));
     unsigned targetOffset = TextIterator::rangeLength(range.ptr(), true);
-    return findClosestPlainText(searchRange.get(), matchText, { }, targetOffset);
+    return findClosestPlainText(searchRange, matchText, { }, targetOffset);
 }
 
 static bool isReplacedNodeOrBR(Node* node)
@@ -2668,7 +2665,7 @@
     if (!next)
         return it.atEnd() ? start : characterOffset;
     
-    Node& node = it.atEnd() ? searchRange->startContainer() : it.range()->startContainer();
+    auto& node = it.atEnd() ? searchRange->startContainer() : it.range().start.container.get();
     
     // SimplifiedBackwardsTextIterator ignores replaced elements.
     if (AccessibilityObject::replacedNodeNeedsCharacter(characterOffset.node))

Modified: trunk/Source/WebCore/accessibility/AXObjectCache.h (258474 => 258475)


--- trunk/Source/WebCore/accessibility/AXObjectCache.h	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebCore/accessibility/AXObjectCache.h	2020-03-14 22:59:34 UTC (rev 258475)
@@ -349,7 +349,7 @@
     void performDeferredCacheUpdate();
     void deferTextReplacementNotificationForTextControl(HTMLTextFormControlElement&, const String& previousValue);
 
-    RefPtr<Range> rangeMatchesTextNearRange(RefPtr<Range>, const String&);
+    Optional<SimpleRange> rangeMatchesTextNearRange(const SimpleRange&, const String&);
 
 #if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
     WEBCORE_EXPORT static bool isIsolatedTreeEnabled();

Modified: trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h (258474 => 258475)


--- trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h	2020-03-14 22:59:34 UTC (rev 258475)
@@ -811,9 +811,9 @@
     {
         // If text is empty we return true.
         return text.isEmpty()
-            || findPlainText(title(), text, CaseInsensitive)
-            || findPlainText(accessibilityDescription(), text, CaseInsensitive)
-            || findPlainText(stringValue(), text, CaseInsensitive);
+            || containsPlainText(title(), text, CaseInsensitive)
+            || containsPlainText(accessibilityDescription(), text, CaseInsensitive)
+            || containsPlainText(stringValue(), text, CaseInsensitive);
     }
 
     // Methods for determining accessibility text.

Modified: trunk/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm (258474 => 258475)


--- trunk/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm	2020-03-14 22:59:34 UTC (rev 258475)
@@ -2273,7 +2273,7 @@
                 if ([self _addAccessibilityObject:headingObject toTextMarkerArray:array])
                     continue;
 
-                String listMarkerText = AccessibilityObject::listMarkerTextForNodeAndPosition(&node, VisiblePosition(createLiveRange(it.range())->startPosition()));
+                String listMarkerText = AccessibilityObject::listMarkerTextForNodeAndPosition(&node, VisiblePosition(createLegacyEditingPosition(it.range().start)));
                 
                 if (!listMarkerText.isEmpty()) 
                     [array addObject:listMarkerText];
@@ -2280,7 +2280,7 @@
                 // There was not an element representation, so just return the text.
                 [array addObject:it.text().createNSString().get()];
             } else {
-                String listMarkerText = AccessibilityObject::listMarkerTextForNodeAndPosition(&node, VisiblePosition(createLiveRange(it.range())->startPosition()));
+                String listMarkerText = AccessibilityObject::listMarkerTextForNodeAndPosition(&node, VisiblePosition(createLegacyEditingPosition(it.range().start)));
 
                 if (!listMarkerText.isEmpty()) {
                     NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] init];
@@ -2711,7 +2711,7 @@
     if (!cache)
         return nil;
     
-    return cache->rangeMatchesTextNearRange(originalRange, text);
+    return createLiveRange(cache->rangeMatchesTextNearRange(*originalRange, text));
 }
 
 // This is only used in the layout test.

Modified: trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm (258474 => 258475)


--- trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm	2020-03-14 22:59:34 UTC (rev 258475)
@@ -1262,7 +1262,7 @@
             // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX)
             if (it.text().length()) {
                 // Add the text of the list marker item if necessary.
-                String listMarkerText = AccessibilityObject::listMarkerTextForNodeAndPosition(&node, VisiblePosition(createLiveRange(it.range())->startPosition()));
+                String listMarkerText = AccessibilityObject::listMarkerTextForNodeAndPosition(&node, VisiblePosition(createLegacyEditingPosition(it.range().start)));
                 if (!listMarkerText.isEmpty())
                     AXAttributedStringAppendText(attrString, &node, listMarkerText, spellCheck);
                 AXAttributedStringAppendText(attrString, &node, it.text(), spellCheck);

Modified: trunk/Source/WebCore/dom/Position.cpp (258474 => 258475)


--- trunk/Source/WebCore/dom/Position.cpp	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebCore/dom/Position.cpp	2020-03-14 22:59:34 UTC (rev 258475)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "Position.h"
 
+#include "BoundaryPoint.h"
 #include "CSSComputedStyleDeclaration.h"
 #include "Editing.h"
 #include "HTMLBRElement.h"
@@ -1592,6 +1593,11 @@
     return Position(ancestor, node->computeNodeIndex() + 1, Position::PositionIsOffsetInAnchor);
 }
 
+Position createLegacyEditingPosition(const BoundaryPoint& point)
+{
+    return createLegacyEditingPosition(point.container.ptr(), point.offset);
+}
+
 } // namespace WebCore
 
 #if ENABLE(TREE_DEBUGGING)

Modified: trunk/Source/WebCore/dom/Position.h (258474 => 258475)


--- trunk/Source/WebCore/dom/Position.h	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebCore/dom/Position.h	2020-03-14 22:59:34 UTC (rev 258475)
@@ -28,8 +28,6 @@
 #include "ContainerNode.h"
 #include "EditingBoundary.h"
 #include "TextAffinity.h"
-#include <wtf/Assertions.h>
-#include <wtf/RefPtr.h>
 
 namespace WTF {
 class TextStream;
@@ -37,15 +35,12 @@
 
 namespace WebCore {
 
-class CSSComputedStyleDeclaration;
-class Element;
 class InlineBox;
-class Node;
-class Range;
 class RenderElement;
-class RenderObject;
 class Text;
 
+struct BoundaryPoint;
+
 enum PositionMoveType {
     CodePoint,       // Move by a single code point.
     Character,       // Move to the next Unicode character break.
@@ -222,6 +217,8 @@
     bool m_isLegacyEditingPosition : 1;
 };
 
+Position createLegacyEditingPosition(const BoundaryPoint&);
+
 inline Position createLegacyEditingPosition(Node* node, unsigned offset)
 {
     return { node, offset, Position::LegacyEditingPositionFlag::On };

Modified: trunk/Source/WebCore/editing/Editing.cpp (258474 => 258475)


--- trunk/Source/WebCore/editing/Editing.cpp	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebCore/editing/Editing.cpp	2020-03-14 22:59:34 UTC (rev 258475)
@@ -51,6 +51,7 @@
 #include "RenderElement.h"
 #include "RenderTableCell.h"
 #include "ShadowRoot.h"
+#include "SimpleRange.h"
 #include "Text.h"
 #include "TextIterator.h"
 #include "VisibleUnits.h"
@@ -1128,10 +1129,10 @@
         // FIXME: workaround for collapsed range (where only start position is correct) emitted for some emitted newlines.
         it.advance(1);
         if (!it.atEnd())
-            return VisiblePosition(it.range()->startPosition());
+            return VisiblePosition(createLegacyEditingPosition(it.range().start));
     }
 
-    return { it.atEnd() ? range->endPosition() : it.range()->endPosition(), UPSTREAM };
+    return { it.atEnd() ? range->endPosition() : createLegacyEditingPosition(it.range().end), UPSTREAM };
 }
 
 // Determines whether two positions are visibly next to each other (first then second)

Modified: trunk/Source/WebCore/editing/Editor.cpp (258474 => 258475)


--- trunk/Source/WebCore/editing/Editor.cpp	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebCore/editing/Editor.cpp	2020-03-14 22:59:34 UTC (rev 258475)
@@ -2253,14 +2253,14 @@
             // Stop looking at start of next misspelled word
             CharacterIterator chars(*grammarSearchRange);
             chars.advance(misspellingOffset);
-            grammarSearchRange->setEnd(chars.range()->startContainer(), chars.range()->startOffset());
+            grammarSearchRange->setEnd(chars.range().start.container, chars.range().start.offset);
         }
-    
+
         if (isGrammarCheckingEnabled())
             badGrammarPhrase = TextCheckingHelper(*client(), *grammarSearchRange).findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false);
 #endif
     }
-    
+
     // 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) {
@@ -2288,7 +2288,7 @@
                 // Stop looking at start of next misspelled word
                 CharacterIterator chars(*grammarSearchRange);
                 chars.advance(misspellingOffset);
-                grammarSearchRange->setEnd(chars.range()->startContainer(), chars.range()->startOffset());
+                grammarSearchRange->setEnd(chars.range().start.container, chars.range().start.offset);
             }
 
             if (isGrammarCheckingEnabled())
@@ -3534,7 +3534,7 @@
             searchRange->setStart(*shadowTreeRoot, 0);
     }
 
-    RefPtr<Range> resultRange = findPlainText(*searchRange, target, options);
+    RefPtr<Range> resultRange = createLiveRange(findPlainText(*searchRange, target, options));
     // If we started in the reference range and the found range exactly matches the reference range, find again.
     // Build a selection with the found range to remove collapsed whitespace.
     // Compare ranges instead of selection objects to ignore the way that the current selection was made.
@@ -3552,7 +3552,7 @@
                 searchRange->setStart(*shadowTreeRoot, 0);
         }
 
-        resultRange = findPlainText(*searchRange, target, options);
+        resultRange = createLiveRange(findPlainText(*searchRange, target, options));
     }
 
     // If nothing was found in the shadow tree, search in main content following the shadow tree.
@@ -3565,14 +3565,13 @@
                 searchRange->setEndBefore(*shadowTreeRoot->shadowHost());
         }
 
-        resultRange = findPlainText(*searchRange, target, options);
+        resultRange = createLiveRange(findPlainText(*searchRange, target, options));
     }
 
     // If we didn't find anything and we're wrapping, search again in the entire document (this will
     // redundantly re-search the area already searched in some cases).
     if (resultRange->collapsed() && options.contains(WrapAround)) {
-        searchRange = rangeOfContents(document());
-        resultRange = findPlainText(*searchRange, target, options);
+        resultRange = createLiveRange(findPlainText(rangeOfContents(document()), target, options));
         // We used to return false here if we ended up with the same range that we started with
         // (e.g., the reference range was already the only instance of this text). But we decided that
         // this should be a success case instead, so we'll just fall through in that case.
@@ -3613,11 +3612,11 @@
     unsigned matchCount = 0;
     do {
         auto resultRange = findPlainText(*searchRange, target, options - Backwards);
-        if (resultRange->collapsed()) {
-            if (!resultRange->startContainer().isInShadowTree())
+        if (resultRange.collapsed()) {
+            if (!resultRange.start.container->isInShadowTree())
                 break;
 
-            searchRange->setStartAfter(*resultRange->startContainer().shadowHost());
+            searchRange->setStartAfter(*resultRange.start.container->shadowHost());
             searchRange->setEnd(originalEndContainer, originalEndOffset);
             continue;
         }
@@ -3624,10 +3623,10 @@
 
         ++matchCount;
         if (matches)
-            matches->append(resultRange.ptr());
-        
+            matches->append(createLiveRange(resultRange));
+
         if (markMatches)
-            document().markers().addMarker(resultRange, DocumentMarker::TextMatch);
+            document().markers().addMarker(createLiveRange(resultRange), DocumentMarker::TextMatch);
 
         // Stop looking if we hit the specified limit. A limit of 0 means no limit.
         if (limit > 0 && matchCount >= limit)
@@ -3637,7 +3636,7 @@
         // 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());
+        searchRange->setStart(WTFMove(resultRange.end.container), resultRange.end.offset);
 
         Node* shadowTreeRoot = searchRange->shadowRoot();
         if (searchRange->collapsed() && shadowTreeRoot)

Modified: trunk/Source/WebCore/editing/TextIterator.cpp (258474 => 258475)


--- trunk/Source/WebCore/editing/TextIterator.cpp	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebCore/editing/TextIterator.cpp	2020-03-14 22:59:34 UTC (rev 258475)
@@ -1382,11 +1382,11 @@
     return true;
 }
 
-Ref<Range> SimplifiedBackwardsTextIterator::range() const
+SimpleRange SimplifiedBackwardsTextIterator::range() const
 {
     ASSERT(!atEnd());
 
-    return Range::create(m_positionNode->document(), m_positionNode, m_positionStartOffset, m_positionNode, m_positionEndOffset);
+    return { { *m_positionNode, static_cast<unsigned>(m_positionStartOffset) }, { *m_positionNode, static_cast<unsigned>(m_positionEndOffset) } };
 }
 
 // --------
@@ -1405,7 +1405,7 @@
         m_underlyingIterator.advance();
 }
 
-Ref<Range> CharacterIterator::range() const
+SimpleRange CharacterIterator::range() const
 {
     SimpleRange range = m_underlyingIterator.range();
     if (!m_underlyingIterator.atEnd()) {
@@ -1417,7 +1417,7 @@
             range = { { node, offset }, { node, offset + 1 } };
         }
     }
-    return createLiveRange(range);
+    return range;
 }
 
 void CharacterIterator::advance(int count)
@@ -1471,7 +1471,7 @@
     if (it.atEnd())
         return Range::create(document);
 
-    Ref<Range> start = it.range();
+    auto start = it.range().start;
 
     if (length > 1)
         it.advance(length - 1);
@@ -1478,36 +1478,31 @@
     if (it.atEnd())
         return Range::create(document);
 
-    Ref<Range> end = it.range();
+    auto end = it.range().end;
 
-    return Range::create(document, &start->startContainer(), start->startOffset(), &end->endContainer(), end->endOffset());
+    return createLiveRange(SimpleRange { start, end });
 }
 
 BackwardsCharacterIterator::BackwardsCharacterIterator(const Range& range)
     : m_underlyingIterator(range)
-    , m_offset(0)
-    , m_runOffset(0)
-    , m_atBreak(true)
 {
     while (!atEnd() && !m_underlyingIterator.text().length())
         m_underlyingIterator.advance();
 }
 
-Ref<Range> BackwardsCharacterIterator::range() const
+SimpleRange BackwardsCharacterIterator::range() const
 {
-    Ref<Range> r = m_underlyingIterator.range();
+    auto range = m_underlyingIterator.range();
     if (!m_underlyingIterator.atEnd()) {
         if (m_underlyingIterator.text().length() <= 1)
             ASSERT(m_runOffset == 0);
         else {
-            Node& node = r->startContainer();
-            ASSERT(&node == &r->endContainer());
-            int offset = r->endOffset() - m_runOffset;
-            r->setStart(node, offset - 1);
-            r->setEnd(node, offset);
+            Node& node = range.start.container;
+            unsigned offset = range.end.offset - m_runOffset;
+            range = { { node, offset - 1 }, { node, offset } };
         }
     }
-    return r;
+    return range;
 }
 
 void BackwardsCharacterIterator::advance(int count)
@@ -1553,7 +1548,6 @@
 
 WordAwareIterator::WordAwareIterator(const Range& range)
     : m_underlyingIterator(&range)
-    , m_didLookAhead(true) // so we consider the first chunk from the text iterator
 {
     advance(); // get in position over the first chunk of text
 }
@@ -2510,9 +2504,9 @@
 
 // --------
 
-bool hasAnyPlainText(const Range& range, TextIteratorBehavior behavior)
+bool hasAnyPlainText(const SimpleRange& range, TextIteratorBehavior behavior)
 {
-    for (TextIterator iterator { &range, behavior }; !iterator.atEnd(); iterator.advance()) {
+    for (TextIterator iterator { createLiveRange(range).ptr(), behavior }; !iterator.atEnd(); iterator.advance()) {
         if (!iterator.text().isEmpty())
             return true;
     }
@@ -2563,10 +2557,10 @@
     return plainText(range->startPosition(), range->endPosition(), defaultBehavior, isDisplayString);
 }
 
-String plainTextUsingBackwardsTextIteratorForTesting(const Range& range)
+String plainTextUsingBackwardsTextIteratorForTesting(const SimpleRange& range)
 {
     String result;
-    for (SimplifiedBackwardsTextIterator backwardsIterator(range); !backwardsIterator.atEnd(); backwardsIterator.advance())
+    for (SimplifiedBackwardsTextIterator backwardsIterator(createLiveRange(range)); !backwardsIterator.atEnd(); backwardsIterator.advance())
         result.insert(backwardsIterator.text().toString(), 0);
     return result;
 }
@@ -2576,11 +2570,10 @@
     return plainText(range, defaultBehavior, isDisplayString).replace(noBreakSpace, ' ');
 }
 
-static Ref<Range> collapsedToBoundary(const Range& range, bool forward)
+static SimpleRange collapsedToBoundary(const SimpleRange& range, bool forward)
 {
-    Ref<Range> result = range.cloneRange();
-    result->collapse(!forward);
-    return result;
+    auto& boundary = forward ? range.end : range.start;
+    return { boundary, boundary };
 }
 
 static TextIteratorBehavior findIteratorOptions(FindOptions options)
@@ -2591,12 +2584,12 @@
     return iteratorOptions;
 }
 
-static void findPlainTextMatches(const Range& range, const String& target, FindOptions options, const WTF::Function<bool(size_t, size_t)>& match)
+static void findPlainTextMatches(const SimpleRange& range, const String& target, FindOptions options, const WTF::Function<bool(size_t, size_t)>& match)
 {
     SearchBuffer buffer(target, options);
     if (buffer.needsMoreContext()) {
-        Ref<Range> beforeStartRange = range.ownerDocument().createRange();
-        beforeStartRange->setEnd(range.startContainer(), range.startOffset());
+        Ref<Range> beforeStartRange = range.start.document().createRange();
+        beforeStartRange->setEnd(range.start.container.copyRef(), range.start.offset);
         for (SimplifiedBackwardsTextIterator backwardsIterator(beforeStartRange.get()); !backwardsIterator.atEnd(); backwardsIterator.advance()) {
             buffer.prependContext(backwardsIterator.text());
             if (!buffer.needsMoreContext())
@@ -2604,7 +2597,7 @@
         }
     }
 
-    CharacterIterator findIterator(range, findIteratorOptions(options));
+    CharacterIterator findIterator(createLiveRange(range), findIteratorOptions(options));
     while (!findIterator.atEnd()) {
         findIterator.advance(buffer.append(findIterator.text()));
         while (1) {
@@ -2625,15 +2618,15 @@
     }
 }
 
-static Ref<Range> rangeForMatch(const Range& range, FindOptions options, size_t matchStart, size_t matchLength, bool searchForward)
+static SimpleRange rangeForMatch(const SimpleRange& range, FindOptions options, size_t matchStart, size_t matchLength, bool searchForward)
 {
     if (!matchLength)
         return collapsedToBoundary(range, searchForward);
-    CharacterIterator rangeComputeIterator(range, findIteratorOptions(options));
-    return characterSubrange(range.ownerDocument(), rangeComputeIterator, matchStart, matchLength);
+    CharacterIterator rangeComputeIterator(createLiveRange(range), findIteratorOptions(options));
+    return characterSubrange(range.start.document(), rangeComputeIterator, matchStart, matchLength);
 }
 
-Ref<Range> findClosestPlainText(const Range& range, const String& target, FindOptions options, unsigned targetOffset)
+SimpleRange findClosestPlainText(const SimpleRange& range, const String& target, FindOptions options, unsigned targetOffset)
 {
     size_t matchStart = 0;
     size_t matchLength = 0;
@@ -2652,7 +2645,7 @@
     return rangeForMatch(range, options, matchStart, matchLength, !options.contains(Backwards));
 }
 
-Ref<Range> findPlainText(const Range& range, const String& target, FindOptions options)
+SimpleRange findPlainText(const SimpleRange& range, const String& target, FindOptions options)
 {
     bool searchForward = !options.contains(Backwards);
     size_t matchStart = 0;
@@ -2668,7 +2661,7 @@
     return rangeForMatch(range, options, matchStart, matchLength, searchForward);
 }
 
-bool findPlainText(const String& document, const String& target, FindOptions options)
+bool containsPlainText(const String& document, const String& target, FindOptions options)
 {
     SearchBuffer buffer { target, options };
     StringView remainingText { document };

Modified: trunk/Source/WebCore/editing/TextIterator.h (258474 => 258475)


--- trunk/Source/WebCore/editing/TextIterator.h	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebCore/editing/TextIterator.h	2020-03-14 22:59:34 UTC (rev 258475)
@@ -43,12 +43,12 @@
 
 WEBCORE_EXPORT String plainText(const Range*, TextIteratorBehavior = TextIteratorDefaultBehavior, bool isDisplayString = false);
 WEBCORE_EXPORT String plainTextReplacingNoBreakSpace(const Range*, TextIteratorBehavior = TextIteratorDefaultBehavior, bool isDisplayString = false);
-WEBCORE_EXPORT String plainTextUsingBackwardsTextIteratorForTesting(const Range&);
+WEBCORE_EXPORT String plainTextUsingBackwardsTextIteratorForTesting(const SimpleRange&);
 
-Ref<Range> findPlainText(const Range&, const String&, FindOptions);
-WEBCORE_EXPORT Ref<Range> findClosestPlainText(const Range&, const String&, FindOptions, unsigned);
-WEBCORE_EXPORT bool hasAnyPlainText(const Range&, TextIteratorBehavior = TextIteratorDefaultBehavior);
-bool findPlainText(const String& document, const String&, FindOptions); // Lets us use the search algorithm on a string.
+SimpleRange findPlainText(const SimpleRange&, const String&, FindOptions);
+WEBCORE_EXPORT SimpleRange findClosestPlainText(const SimpleRange&, const String&, FindOptions, unsigned);
+WEBCORE_EXPORT bool hasAnyPlainText(const SimpleRange&, TextIteratorBehavior = TextIteratorDefaultBehavior);
+bool containsPlainText(const String& document, const String&, FindOptions); // Lets us use the search algorithm on a string.
 WEBCORE_EXPORT String foldQuoteMarks(const String&);
 
 // FIXME: Move this somewhere else in the editing directory. It doesn't belong here.
@@ -183,7 +183,7 @@
     void advance();
 
     StringView text() const { ASSERT(!atEnd()); return m_text; }
-    WEBCORE_EXPORT Ref<Range> range() const;
+    WEBCORE_EXPORT SimpleRange range() const;
     Node* node() const { ASSERT(!atEnd()); return m_node; }
 
 private:
@@ -239,16 +239,16 @@
     WEBCORE_EXPORT void advance(int numCharacters);
     
     StringView text() const { return m_underlyingIterator.text().substring(m_runOffset); }
-    WEBCORE_EXPORT Ref<Range> range() const;
+    WEBCORE_EXPORT SimpleRange range() const;
 
     bool atBreak() const { return m_atBreak; }
-    int characterOffset() const { return m_offset; }
+    unsigned characterOffset() const { return m_offset; }
 
 private:
     TextIterator m_underlyingIterator;
 
-    int m_offset { 0 };
-    int m_runOffset { 0 };
+    unsigned m_offset { 0 };
+    unsigned m_runOffset { 0 };
     bool m_atBreak { true };
 };
     
@@ -259,14 +259,14 @@
     bool atEnd() const { return m_underlyingIterator.atEnd(); }
     void advance(int numCharacters);
 
-    Ref<Range> range() const;
+    SimpleRange range() const;
 
 private:
     SimplifiedBackwardsTextIterator m_underlyingIterator;
 
-    int m_offset;
-    int m_runOffset;
-    bool m_atBreak;
+    unsigned m_offset { 0 };
+    unsigned m_runOffset { 0 };
+    bool m_atBreak { true };
 };
 
 // Similar to the TextIterator, except that the chunks of text returned are "well behaved", meaning
@@ -288,9 +288,9 @@
 
     // Many chunks from text iterator concatenated.
     Vector<UChar> m_buffer;
-    
+
     // Did we have to look ahead in the text iterator to confirm the current chunk?
-    bool m_didLookAhead;
+    bool m_didLookAhead { true };
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/editing/TextManipulationController.cpp (258474 => 258475)


--- trunk/Source/WebCore/editing/TextManipulationController.cpp	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebCore/editing/TextManipulationController.cpp	2020-03-14 22:59:34 UTC (rev 258475)
@@ -194,12 +194,12 @@
 
     Position startPosition()
     {
-        return createLiveRange(m_iterator.range())->startPosition();
+        return createLegacyEditingPosition(m_iterator.range().start);
     }
 
     Position endPosition()
     {
-        return createLiveRange(m_iterator.range())->endPosition();
+        return createLegacyEditingPosition(m_iterator.range().end);
     }
 
     bool atEnd() const { return m_iterator.atEnd() && m_currentNodeForFindingInvisibleContent == m_pastEndNode; }

Modified: trunk/Source/WebCore/editing/VisiblePosition.h (258474 => 258475)


--- trunk/Source/WebCore/editing/VisiblePosition.h	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebCore/editing/VisiblePosition.h	2020-03-14 22:59:34 UTC (rev 258475)
@@ -34,6 +34,8 @@
 
 namespace WebCore {
 
+class Range;
+
 // VisiblePosition default affinity is downstream because
 // the callers do not really care (they just want the
 // deep position without regard to line position), and this

Modified: trunk/Source/WebCore/editing/VisibleSelection.cpp (258474 => 258475)


--- trunk/Source/WebCore/editing/VisibleSelection.cpp	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebCore/editing/VisibleSelection.cpp	2020-03-14 22:59:34 UTC (rev 258475)
@@ -244,7 +244,7 @@
         UChar c = charIt.text()[0];
         if ((!isSpaceOrNewline(c) && c != noBreakSpace) || c == '\n')
             break;
-        m_end = charIt.range()->endPosition();
+        m_end = createLegacyEditingPosition(charIt.range().end);
     }
 }
 

Modified: trunk/Source/WebCore/editing/VisibleUnits.cpp (258474 => 258475)


--- trunk/Source/WebCore/editing/VisibleUnits.cpp	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebCore/editing/VisibleUnits.cpp	2020-03-14 22:59:34 UTC (rev 258475)
@@ -636,7 +636,7 @@
     if (!next)
         return VisiblePosition(it.atEnd() ? searchRange->startPosition() : pos, DOWNSTREAM);
 
-    Node& node = it.atEnd() ? searchRange->startContainer() : it.range()->startContainer();
+    auto& node = it.atEnd() ? searchRange->startContainer() : it.range().start.container.get();
     if ((!suffixLength && node.isTextNode() && static_cast<int>(next) <= node.maxCharacterOffset()) || (node.renderer() && node.renderer()->isBR() && !next)) {
         // The next variable contains a usable index into a text node
         return VisiblePosition(createLegacyEditingPosition(&node, next), DOWNSTREAM);
@@ -647,7 +647,7 @@
     if (next < string.size() - suffixLength)
         charIt.advance(string.size() - suffixLength - next);
     // FIXME: charIt can get out of shadow host.
-    return VisiblePosition(charIt.range()->endPosition(), DOWNSTREAM);
+    return { createLegacyEditingPosition(charIt.range().end), DOWNSTREAM };
 }
 
 static VisiblePosition nextBoundary(const VisiblePosition& c, BoundarySearchFunction searchFunction)
@@ -683,20 +683,18 @@
         // Use the character iterator to translate the next value into a DOM position.
         CharacterIterator charIt(searchRange, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
         charIt.advance(next - prefixLength - 1);
-        RefPtr<Range> characterRange = charIt.range();
-        pos = characterRange->endPosition();
+        auto characterRange = charIt.range();
+        pos = createLegacyEditingPosition(characterRange.end);
         
         if (charIt.text()[0] == '\n') {
             // FIXME: workaround for collapsed range (where only start position is correct) emitted for some emitted newlines (see rdar://5192593)
-            VisiblePosition visPos = VisiblePosition(pos);
-            if (visPos == VisiblePosition(characterRange->startPosition())) {
+            if (VisiblePosition(pos) == VisiblePosition(createLegacyEditingPosition(characterRange.start))) {
                 charIt.advance(1);
-                pos = charIt.range()->startPosition();
+                pos = createLegacyEditingPosition(charIt.range().start);
             }
         }
     }
 
-    // generate VisiblePosition, use UPSTREAM affinity if possible
     return VisiblePosition(pos, VP_UPSTREAM_IF_POSSIBLE);
 }
 

Modified: trunk/Source/WebCore/testing/Internals.cpp (258474 => 258475)


--- trunk/Source/WebCore/testing/Internals.cpp	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebCore/testing/Internals.cpp	2020-03-14 22:59:34 UTC (rev 258475)
@@ -174,6 +174,7 @@
 #include "ServiceWorkerRegistrationData.h"
 #include "Settings.h"
 #include "ShadowRoot.h"
+#include "SimpleRange.h"
 #include "SourceBuffer.h"
 #include "SpellChecker.h"
 #include "StaticNodeList.h"
@@ -2053,7 +2054,7 @@
 
 RefPtr<Range> Internals::rangeOfStringNearLocation(const Range& searchRange, const String& text, unsigned targetOffset)
 {
-    return findClosestPlainText(searchRange, text, { }, targetOffset);
+    return createLiveRange(findClosestPlainText(searchRange, text, { }, targetOffset));
 }
 
 #if !PLATFORM(MAC)

Modified: trunk/Source/WebKit/ChangeLog (258474 => 258475)


--- trunk/Source/WebKit/ChangeLog	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebKit/ChangeLog	2020-03-14 22:59:34 UTC (rev 258475)
@@ -1,3 +1,22 @@
+2020-03-10  Darin Adler  <[email protected]>
+
+        Change all return values in TextIterator header from live ranges to SimpleRange
+        https://bugs.webkit.org/show_bug.cgi?id=208906
+
+        Reviewed by Antti Koivisto.
+
+        * WebProcess/WebPage/Cocoa/WebPageCocoa.mm: Removed unneeded include of
+        TextIterator.h.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::rangeNearPositionMatchesText): Removed unused originalRange argument,
+        changed return type to Optional<SimpleRange> since findClosestPlainText now
+        returns a SimpleRange.
+        (WebKit::WebPage::getRectsAtSelectionOffsetWithText): Updated since
+        rangeNearPositionMatchesText now returns Optional<SimpleRange>, use createLiveRange.
+        (WebKit::WebPage::requestDocumentEditingContext): Updated since
+        CharacterIterator::range returns SimpleRange, use createLiveRange.
+
 2020-03-14  Brady Eidson  <[email protected]>
 
         Gather PDF scripts to run on a background thread.

Modified: trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm (258474 => 258475)


--- trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm	2020-03-14 22:59:34 UTC (rev 258475)
@@ -47,7 +47,6 @@
 #import <WebCore/Range.h>
 #import <WebCore/RenderElement.h>
 #import <WebCore/SimpleRange.h>
-#import <WebCore/TextIterator.h>
 
 #if PLATFORM(COCOA)
 

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


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2020-03-14 22:17:04 UTC (rev 258474)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2020-03-14 22:59:34 UTC (rev 258475)
@@ -124,6 +124,7 @@
 #import <WebCore/Settings.h>
 #import <WebCore/ShadowRoot.h>
 #import <WebCore/SharedBuffer.h>
+#import <WebCore/SimpleRange.h>
 #import <WebCore/StyleProperties.h>
 #import <WebCore/TextIndicator.h>
 #import <WebCore/TextIterator.h>
@@ -1974,11 +1975,13 @@
     }
 }
 
-static RefPtr<Range> rangeNearPositionMatchesText(const VisiblePosition& position, RefPtr<Range> originalRange, const String& matchText, RefPtr<Range> selectionRange)
+static Optional<SimpleRange> rangeNearPositionMatchesText(const VisiblePosition& position, const String& matchText, RefPtr<Range> selectionRange)
 {
+    if (!selectionRange)
+        return WTF::nullopt;
     auto range = Range::create(selectionRange->ownerDocument(), selectionRange->startPosition(), position.deepEquivalent().parentAnchoredEquivalent());
     unsigned targetOffset = TextIterator::rangeLength(range.ptr(), true);
-    return findClosestPlainText(*selectionRange.get(), matchText, { }, targetOffset);
+    return findClosestPlainText(*selectionRange, matchText, { }, targetOffset);
 }
 
 void WebPage::getRectsAtSelectionOffsetWithText(int32_t offset, const String& text, CallbackID callbackID)
@@ -2003,13 +2006,11 @@
         return;
     }
 
-    String rangeText = plainTextReplacingNoBreakSpace(range.ptr(), TextIteratorDefaultBehavior, true);
-    if (rangeText != text) {
-        auto selectionRange = selection.toNormalizedRange();
+    if (plainTextReplacingNoBreakSpace(range.ptr(), TextIteratorDefaultBehavior, true) != text) {
         // Try to search for a range which is the closest to the position within the selection range that matches the passed in text.
-        if (auto wordRange = rangeNearPositionMatchesText(startPosition, range.ptr(), text, selectionRange)) {
+        if (auto wordRange = rangeNearPositionMatchesText(startPosition, text, selection.toNormalizedRange())) {
             if (!wordRange->collapsed())
-                range = *wordRange;
+                range = createLiveRange(*wordRange);
         }
     }
 
@@ -4214,7 +4215,7 @@
                 continue;
             }
 
-            rects.append({ contextIterator.range()->absoluteBoundingBox(Range::BoundingRectBehavior::IgnoreEmptyTextSelections), { currentLocation, 1 } });
+            rects.append({ createLiveRange(contextIterator.range())->absoluteBoundingBox(Range::BoundingRectBehavior::IgnoreEmptyTextSelections), { currentLocation, 1 } });
             currentLocation++;
             contextIterator.advance(1);
         }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to