⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 258525 in webkit


Ignore:
Timestamp:
Mar 16, 2020, 4:02:10 PM (6 years ago)
Author:
Darin Adler
Message:

Move most of TextIterator off of live ranges
https://bugs.webkit.org/show_bug.cgi?id=209129

Reviewed by Antti Koivisto.

Source/WebCore:

  • Change almost all arguments and return values of functions in TextIterator.h to use SimpleRange instead of live ranges. Exceptions are an overload of plainText TextIterator::rangeLength, TextIterator::rangeFromLocationAndLength, TextIterator::getLocationAndLengthFromRange, and TextIterator::subrange. Those five are a little trickier to convert, so I will do them each in separate patches.
  • Go with the flow in adding an include of Node.h to BoundaryPoint.h. I had avoided this in the initial version, but now it seems practical to just leave it that way. This led to removing BoundaryPoint.cpp and moving all functions to the header.
  • Converted many member functions of the Position class from using int to unsigned for offsets. The DOM specifies unsigned for offsets, but for some reason we used int for them a lot historically, even though negative numbers don't make sense. New classes like StaticRange, SimpleRange, and BoundaryPoint are already using unsigned exclusively and we'll eventually convert everything.
  • Remove includes of SimpleRange.h from files that also include TextIterator.h, now that TextIterator.h pulls it in.
  • Sources.txt: Removed BoundaryPoint.cpp.
  • WebCore.xcodeproj/project.pbxproj: Ditto.
  • accessibility/AXObjectCache.cpp:

(WebCore::AXObjectCache::traverseToOffsetInRange): Updated to pass a reference
to a range rather than a pointer, after null-checking it.
(WebCore::AXObjectCache::lengthForRange): Ditto.
(WebCore::AXObjectCache::nextBoundary): Ditto.
(WebCore::AXObjectCache::previousBoundary): Ditto.

  • accessibility/AccessibilityObject.cpp:

(WebCore::AccessibilityObject::stringForRange const): Ditto.
(WebCore::AccessibilityObject::stringForVisiblePositionRange): Ditto.
(WebCore::AccessibilityObject::lengthForVisiblePositionRange const): Ditto.

  • accessibility/AccessibilityObjectInterface.h: Removed an extra include.
  • accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:

(-[WebAccessibilityObjectWrapper arrayOfTextForTextMarkers:attributed:]):
Updated to pass a reference to a range rather than a pointer, after null-checking it.

  • accessibility/mac/WebAccessibilityObjectWrapperMac.mm:

(-[WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange:spellCheck:]): Ditto.

  • dom/BoundaryPoint.cpp: Removed.
  • dom/BoundaryPoint.h: Removed redundant includes and forward declarations

since we're now committing to including "Node.h" here. Moved functions
all out of the .cpp file and made them inlines.

  • dom/DocumentMarkerController.cpp:

(WebCore::DocumentMarkerController::collectTextRanges): Pass a reference to
a range instead of a pointer.

  • dom/Position.cpp:

(WebCore::Position::Position): Take unsigned.
(WebCore::Position::moveToPosition): Ditto.
(WebCore::Position::moveToOffset): Ditto.
(WebCore::Position::parentAnchoredEquivalent const): Cast to unsigned.
(WebCore::Position::anchorTypeForLegacyEditingPosition): Take unsigned.
(WebCore::Position::previous const): Use unsigned.
(WebCore::Position::next const): Ditto.
(WebCore::Position::uncheckedPreviousOffset): Take unsigned.
(WebCore::Position::uncheckedPreviousOffsetForBackwardDeletion): Ditto.
(WebCore::Position::uncheckedNextOffset): Ditto.
(WebCore::Position::atLastEditingPositionForNode const): Cast to unsigned.
(WebCore::Position::atEndOfTree const): Ditto.
(WebCore::Position::rendersInDifferentPosition const): Added casts to
unsigned and also removed unneeded redundant checks. In a place where
we had already checked that both nodes were the same and both offsets
were different, we were checking the types of both nodes (but they are
the same so only need to check one) and we were checking that both
offsets were different (but we already knew they were different).
(WebCore::searchAheadForBetterMatch): Use unsigned.
(WebCore::Position::getInlineBoxAndOffset const): Ditto.
(WebCore::Position::equals const): Removed a cast to int.
(WebCore::makeBoundaryPoint): Moved this function here so now it can be
used in more places.

  • dom/Position.h: Changed many argument types to unsigned. Moved declarations

of all the functions up above all the inline implementations of the functions
to separate interface from implementation a bit better. Wrote a FIXME about
the name createLegacyEditingPosition. Moved makeBoundaryPoint here and exported
it from WebCore so we can use it from more places.

  • dom/Range.cpp:

(WebCore::createLiveRange): Moved these functions here from SimpleRange.cpp
because a live range is more advanced concept, so makes more sense for live
range to know about simple range rather than vice versa.

  • dom/Range.h: Removed some unneeded includes and forward declarations.

Added a FIXME about renaming to LiveRange. Moved the createLiveRange
functions here. Moved declarations of functions above inline function bodies.

  • dom/SimpleRange.cpp:

(WebCore::createLiveRange): Moved to Range.cpp.

  • dom/SimpleRange.h: Exported the constructor. Removed unneeded overload

that takes a Range*.

  • editing/ApplyStyleCommand.cpp:

(WebCore::ApplyStyleCommand::mergeStartWithPreviousIfIdentical):
Refactored code a bit and use unsigned.
(WebCore::ApplyStyleCommand::mergeEndWithNextIfIdentical): Use unsigned.

  • editing/Editing.cpp:

(WebCore::visibleImageElementsInRangeWithNonLoadedImages): Use a reference
to a range rather than a pointer.

  • editing/Editing.h: Added a forward declaration of Range that now seems to

be needed to compile.

  • editing/Editor.cpp:

(WebCore::Editor::selectedText const): Call makeBoundaryPoint twice here to
convert two Position objects into a SimpleRange.

  • editing/HTMLInterchange.cpp: Removed some extra includes.

(WebCore::convertHTMLTextToInterchangeFormat): Use variadic
StringBuilder::append.

  • editing/TextIterator.cpp:

(WebCore::firstNode): Added. We use this instead of Range::firstNode.
If we find we need it outside TextIterator we can find a header for it.
Not sure it would be great to add it to in BoundaryPoint.h, nor is it
obviously better as a BoundaryPoint member function.
(WebCore::TextIterator::TextIterator): Cut down on the extra constructors
and have the single remaining one take a SimpleRange.
(WebCore::SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator):
Ditto. Also change some int to unsigned.
(WebCore::CharacterIterator::CharacterIterator): Ditto.
(WebCore::BackwardsCharacterIterator::BackwardsCharacterIterator): Ditto.
(WebCore::WordAwareIterator::WordAwareIterator): Ditto.
(WebCore::TextIterator::rangeLength): Since this is one of the functions
that still takes a live range pointer, updated it to check for null and
pass a reference rather than a pointer.
(WebCore::TextIterator::rangeFromLocationAndLength): Ditto.
(WebCore::hasAnyPlainText): Removed now-unneeded call to createLiveRange.
(WebCore::plainText): Updated the main implementation to take a SimpleRange,
eliminating the version that takes two Position objects, but keeping the
one that takes a live range pointer for now.
(WebCore::plainTextReplacingNoBreakSpace): Removed all but the one, and
have that one take a SimpleRange.

  • editing/TextIterator.h: Removed the include of SimpleRange.h. Also

Updated for the changes above, eliminating five different constructors
that take a live range and also overloads that take two Position objects.

  • editing/TextManipulationController.cpp:

(WebCore::ParagraphContentIterator::ParagraphContentIterator):
Call makeBoundaryPoint twice here to convert two Position objects into
a SimpleRange.

  • editing/VisibleSelection.cpp: Removed an include.
  • editing/VisibleUnits.cpp:

(WebCore::suffixLengthForRange): Pass a reference to a range known to
not be null.
(WebCore::previousBoundary): Ditto.
(WebCore::nextBoundary): Ditto.

  • editing/cocoa/DataDetection.mm:

(WebCore::buildQuery): Take a SimpleRange.
(WebCore::DataDetection::detectContentInRange): Added a null check on
a live range and pass a reference to it.

  • editing/cocoa/DictionaryLookup.mm:

(WebCOre::DictionaryLookup::rangeAtHitTestResult): Ditto.

  • editing/cocoa/HTMLConverter.mm:

(WebCore::editingAttributedStringFromRange): Pass a reference to a range
known to not be null.

  • page/TextIndicator.cpp:

(WebCore::estimatedTextColorsForRange): Ditto.
(WebCore::containsOnlyWhiteSpaceText): Ditto.

  • page/ios/FrameIOS.mm:

(WebCore::Frame::interpretationsForCurrentRoot const): Ditto.

  • rendering/HitTestResult.cpp:

(WebCore::HitTestResult::selectedText const): Added a null check on
a live range and pass a reference to it.

Source/WebKit:

  • WebProcess/InjectedBundle/API/mac/WKDOMTextIterator.mm:

(-[WKDOMTextIterator initWithRange:]): Leave _textIterator as a nullptr
if the passed-in range is nil since we no longer offer a way to create
an empty TextIterator; other clients don't seem to need one.
(-[WKDOMTextIterator advance]): Add a null check.
(-[WKDOMTextIterator atEnd]): Ditto.
(-[WKDOMTextIterator currentRange]): Ditto.
(-[WKDOMTextIterator currentTextPointer]): Ditto.
(-[WKDOMTextIterator currentTextLength]): Ditto.

  • WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm: Removed include.
  • WebProcess/WebPage/ViewGestureGeometryCollector.cpp:

(WebKit::ViewGestureGeometryCollector::computeTextLegibilityScales): Pass
a reference to a range known not to be null.

  • WebProcess/WebPage/WebPage.cpp: Removed an include.
  • WebProcess/WebPage/ios/WebPageIOS.mm: Removed a "using naemsapce WebCore".

Added two local functions
(WebKit::plainTextForContext): Added. Helper for just this file where calling
plainTextReplacingNoBreakSpace on a possibly null Range is common.
(WebKit::plainTextForDisplay): Ditto. This one passes true for isDisplayString.
Not entirely clear how carefully we chose which of the two to call, or if there
is sufficient test coverage.
(WebKit::WebPage::platformEditorState const): Use plainTextForContext
and plainTextForDisplay.
(WebKit::WebPage::getSelectionContext): Ditto.
(WebKit::WebPage::getRectsAtSelectionOffsetWithText): Use plainTextForDisplay.
(WebKit::WebPage::requestDictationContext): Use plainTextForContext.
(WebKit::WebPage::replaceSelectedText): Ditto.
(WebKit::WebPage::replaceDictatedText): Ditto.
(WebKit::WebPage::requestAutocorrectionData): Ditto.
(WebKit::WebPage::applyAutocorrectionInternal): Ditto.
(WebKit::WebPage::autocorrectionContext): Ditto.
(WebKit::dataDetectorLinkPositionInformation): Use plainTextForDisplay.
(WebKit::WebPage::requestDocumentEditingContext): Use RetainPtr instead of
autorelease. Use makeBoundaryPoint to convert Position objects to SimpleRange.

Source/WebKitLegacy/mac:

  • WebView/WebFrame.mm: Removed an include.
  • WebView/WebHTMLView.mm:

(-[WebHTMLView _legacyAttributedStringFrom:offset:to:offset:]):
Add casts to unsigned.

  • WebView/WebTextIterator.mm:

(-[WebTextIterator initWithRange:]): Leave _private->_textIterator
as a nullptr if the passed-in range is nil since we no longer offer
a way to create an empty TextIterator; other clients don't seem to
need one.
(-[WebTextIterator advance]): Check _private->_textIterator for null.
(-[WebTextIterator atEnd]): Ditto.
(-[WebTextIterator currentRange]): Ditto.
(-[WebTextIterator currentTextPointer]): Ditto.
(-[WebTextIterator currentTextLength]): Ditto.
(-[WebTextIterator currentNode]): Ditto.
(-[WebTextIterator currentText]): Ditto.

Location:
trunk/Source
Files:
1 deleted
45 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r258522 r258525  
     12020-03-15  Darin Adler  <darin@apple.com>
     2
     3        Move most of TextIterator off of live ranges
     4        https://bugs.webkit.org/show_bug.cgi?id=209129
     5
     6        Reviewed by Antti Koivisto.
     7
     8        - Change almost all arguments and return values of functions in TextIterator.h
     9          to use SimpleRange instead of live ranges. Exceptions are an overload of plainText
     10          TextIterator::rangeLength, TextIterator::rangeFromLocationAndLength,
     11          TextIterator::getLocationAndLengthFromRange, and TextIterator::subrange. Those
     12          five are a little trickier to convert, so I will do them each in separate patches.
     13
     14        - Go with the flow in adding an include of Node.h to BoundaryPoint.h. I had avoided
     15          this in the initial version, but now it seems practical to just leave it that way.
     16          This led to removing BoundaryPoint.cpp and moving all functions to the header.
     17
     18        - Converted many member functions of the Position class from using int to unsigned
     19          for offsets. The DOM specifies unsigned for offsets, but for some reason we used
     20          int for them a lot historically, even though negative numbers don't make sense.
     21          New classes like StaticRange, SimpleRange, and BoundaryPoint are already using
     22          unsigned exclusively and we'll eventually convert everything.
     23
     24        - Remove includes of SimpleRange.h from files that also include TextIterator.h,
     25          now that TextIterator.h pulls it in.
     26
     27        * Sources.txt: Removed BoundaryPoint.cpp.
     28        * WebCore.xcodeproj/project.pbxproj: Ditto.
     29
     30        * accessibility/AXObjectCache.cpp:
     31        (WebCore::AXObjectCache::traverseToOffsetInRange): Updated to pass a reference
     32        to a range rather than a pointer, after null-checking it.
     33        (WebCore::AXObjectCache::lengthForRange): Ditto.
     34        (WebCore::AXObjectCache::nextBoundary): Ditto.
     35        (WebCore::AXObjectCache::previousBoundary): Ditto.
     36        * accessibility/AccessibilityObject.cpp:
     37        (WebCore::AccessibilityObject::stringForRange const): Ditto.
     38        (WebCore::AccessibilityObject::stringForVisiblePositionRange): Ditto.
     39        (WebCore::AccessibilityObject::lengthForVisiblePositionRange const): Ditto.
     40
     41        * accessibility/AccessibilityObjectInterface.h: Removed an extra include.
     42
     43        * accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
     44        (-[WebAccessibilityObjectWrapper arrayOfTextForTextMarkers:attributed:]):
     45        Updated to pass a reference to a range rather than a pointer, after null-checking it.
     46        * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
     47        (-[WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange:spellCheck:]): Ditto.
     48
     49        * dom/BoundaryPoint.cpp: Removed.
     50
     51        * dom/BoundaryPoint.h: Removed redundant includes and forward declarations
     52        since we're now committing to including "Node.h" here. Moved functions
     53        all out of the .cpp file and made them inlines.
     54
     55        * dom/DocumentMarkerController.cpp:
     56        (WebCore::DocumentMarkerController::collectTextRanges): Pass a reference to
     57        a range instead of a pointer.
     58
     59        * dom/Position.cpp:
     60        (WebCore::Position::Position): Take unsigned.
     61        (WebCore::Position::moveToPosition): Ditto.
     62        (WebCore::Position::moveToOffset): Ditto.
     63        (WebCore::Position::parentAnchoredEquivalent const): Cast to unsigned.
     64        (WebCore::Position::anchorTypeForLegacyEditingPosition): Take unsigned.
     65        (WebCore::Position::previous const): Use unsigned.
     66        (WebCore::Position::next const): Ditto.
     67        (WebCore::Position::uncheckedPreviousOffset): Take unsigned.
     68        (WebCore::Position::uncheckedPreviousOffsetForBackwardDeletion): Ditto.
     69        (WebCore::Position::uncheckedNextOffset): Ditto.
     70        (WebCore::Position::atLastEditingPositionForNode const): Cast to unsigned.
     71        (WebCore::Position::atEndOfTree const): Ditto.
     72        (WebCore::Position::rendersInDifferentPosition const): Added casts to
     73        unsigned and also removed unneeded redundant checks. In a place where
     74        we had already checked that both nodes were the same and both offsets
     75        were different, we were checking the types of both nodes (but they are
     76        the same so only need to check one) and we were checking that both
     77        offsets were different (but we already knew they were different).
     78        (WebCore::searchAheadForBetterMatch): Use unsigned.
     79        (WebCore::Position::getInlineBoxAndOffset const): Ditto.
     80        (WebCore::Position::equals const): Removed a cast to int.
     81        (WebCore::makeBoundaryPoint): Moved this function here so now it can be
     82        used in more places.
     83
     84        * dom/Position.h: Changed many argument types to unsigned. Moved declarations
     85        of all the functions up above all the inline implementations of the functions
     86        to separate interface from implementation a bit better. Wrote a FIXME about
     87        the name createLegacyEditingPosition. Moved makeBoundaryPoint here and exported
     88        it from WebCore so we can use it from more places.
     89
     90        * dom/Range.cpp:
     91        (WebCore::createLiveRange): Moved these functions here from SimpleRange.cpp
     92        because a live range is more advanced concept, so makes more sense for live
     93        range to know about simple range rather than vice versa.
     94
     95        * dom/Range.h: Removed some unneeded includes and forward declarations.
     96        Added a FIXME about renaming to LiveRange. Moved the createLiveRange
     97        functions here. Moved declarations of functions above inline function bodies.
     98
     99        * dom/SimpleRange.cpp:
     100        (WebCore::createLiveRange): Moved to Range.cpp.
     101
     102        * dom/SimpleRange.h: Exported the constructor. Removed unneeded overload
     103        that takes a Range*.
     104
     105        * editing/ApplyStyleCommand.cpp:
     106        (WebCore::ApplyStyleCommand::mergeStartWithPreviousIfIdentical):
     107        Refactored code a bit and use unsigned.
     108        (WebCore::ApplyStyleCommand::mergeEndWithNextIfIdentical): Use unsigned.
     109
     110        * editing/Editing.cpp:
     111        (WebCore::visibleImageElementsInRangeWithNonLoadedImages): Use a reference
     112        to a range rather than a pointer.
     113
     114        * editing/Editing.h: Added a forward declaration of Range that now seems to
     115        be needed to compile.
     116
     117        * editing/Editor.cpp:
     118        (WebCore::Editor::selectedText const): Call makeBoundaryPoint twice here to
     119        convert two Position objects into a SimpleRange.
     120
     121        * editing/HTMLInterchange.cpp: Removed some extra includes.
     122        (WebCore::convertHTMLTextToInterchangeFormat): Use variadic
     123        StringBuilder::append.
     124
     125        * editing/TextIterator.cpp:
     126        (WebCore::firstNode): Added. We use this instead of Range::firstNode.
     127        If we find we need it outside TextIterator we can find a header for it.
     128        Not sure it would be great to add it to in BoundaryPoint.h, nor is it
     129        obviously better as a BoundaryPoint member function.
     130        (WebCore::TextIterator::TextIterator): Cut down on the extra constructors
     131        and have the single remaining one take a SimpleRange.
     132        (WebCore::SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator):
     133        Ditto. Also change some int to unsigned.
     134        (WebCore::CharacterIterator::CharacterIterator): Ditto.
     135        (WebCore::BackwardsCharacterIterator::BackwardsCharacterIterator): Ditto.
     136        (WebCore::WordAwareIterator::WordAwareIterator): Ditto.
     137        (WebCore::TextIterator::rangeLength): Since this is one of the functions
     138        that still takes a live range pointer, updated it to check for null and
     139        pass a reference rather than a pointer.
     140        (WebCore::TextIterator::rangeFromLocationAndLength): Ditto.
     141        (WebCore::hasAnyPlainText): Removed now-unneeded call to createLiveRange.
     142        (WebCore::plainText): Updated the main implementation to take a SimpleRange,
     143        eliminating the version that takes two Position objects, but keeping the
     144        one that takes a live range pointer for now.
     145        (WebCore::plainTextReplacingNoBreakSpace): Removed all but the one, and
     146        have that one take a SimpleRange.
     147
     148        * editing/TextIterator.h: Removed the include of SimpleRange.h. Also
     149        Updated for the changes above, eliminating five different constructors
     150        that take a live range and also overloads that take two Position objects.
     151
     152        * editing/TextManipulationController.cpp:
     153        (WebCore::ParagraphContentIterator::ParagraphContentIterator):
     154        Call makeBoundaryPoint twice here to convert two Position objects into
     155        a SimpleRange.
     156
     157        * editing/VisibleSelection.cpp: Removed an include.
     158
     159        * editing/VisibleUnits.cpp:
     160        (WebCore::suffixLengthForRange): Pass a reference to a range known to
     161        not be null.
     162        (WebCore::previousBoundary): Ditto.
     163        (WebCore::nextBoundary): Ditto.
     164
     165        * editing/cocoa/DataDetection.mm:
     166        (WebCore::buildQuery): Take a SimpleRange.
     167        (WebCore::DataDetection::detectContentInRange): Added a null check on
     168        a live range and pass a reference to it.
     169        * editing/cocoa/DictionaryLookup.mm:
     170        (WebCOre::DictionaryLookup::rangeAtHitTestResult): Ditto.
     171
     172        * editing/cocoa/HTMLConverter.mm:
     173        (WebCore::editingAttributedStringFromRange): Pass a reference to a range
     174        known to not be null.
     175        * page/TextIndicator.cpp:
     176        (WebCore::estimatedTextColorsForRange): Ditto.
     177        (WebCore::containsOnlyWhiteSpaceText): Ditto.
     178        * page/ios/FrameIOS.mm:
     179        (WebCore::Frame::interpretationsForCurrentRoot const): Ditto.
     180
     181        * rendering/HitTestResult.cpp:
     182        (WebCore::HitTestResult::selectedText const): Added a null check on
     183        a live range and pass a reference to it.
     184
    11852020-03-16  Pinki Gyanchandani  <pgyanchandani@apple.com>
    2186
     
    231415        * Modules/mediastream/RTCRtpSender.cpp:
    232416        (WebCore::RTCRtpSender::dtmf):
     417
     418        * rendering/line/LineLayoutTraversal.h: Removed some unneeded includes.
     419        * testing/Internals.cpp: Ditto.
    233420
    2344212020-03-13  Sergio Villar Senin  <svillar@igalia.com>
  • trunk/Source/WebCore/Sources.txt

    r258498 r258525  
    851851dom/BeforeTextInsertedEvent.cpp
    852852dom/BeforeUnloadEvent.cpp
    853 dom/BoundaryPoint.cpp
    854853dom/CDATASection.cpp
    855854dom/CharacterData.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r258504 r258525  
    1070910709                9316DDF8240C64B3009340AA /* SimpleRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleRange.h; sourceTree = "<group>"; };
    1071010710                9316DDFA240C64B3009340AA /* SimpleRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SimpleRange.cpp; sourceTree = "<group>"; };
    10711                 9316DDFD240C64F8009340AA /* BoundaryPoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BoundaryPoint.cpp; sourceTree = "<group>"; };
    1071210711                9316DDFE240C64F8009340AA /* BoundaryPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BoundaryPoint.h; sourceTree = "<group>"; };
    1071310712                931AE3B81FB80EAE00F5EFB2 /* JSValueInWrappedObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSValueInWrappedObject.h; sourceTree = "<group>"; };
     
    2832428323                                85031B270A44EFC700F992E0 /* BeforeUnloadEvent.h */,
    2832528324                                7C1E8CFF1ED0C2BE00B1D983 /* BeforeUnloadEvent.idl */,
    28326                                 9316DDFD240C64F8009340AA /* BoundaryPoint.cpp */,
    2832728325                                9316DDFE240C64F8009340AA /* BoundaryPoint.h */,
    2832828326                                7C1E8D001ED0C2BE00B1D983 /* CallbackResult.h */,
  • trunk/Source/WebCore/accessibility/AXObjectCache.cpp

    r258475 r258525  
    100100#include "ScriptDisallowedScope.h"
    101101#include "ScrollView.h"
    102 #include "SimpleRange.h"
    103102#include "TextBoundaries.h"
    104103#include "TextControlInnerElements.h"
     
    17921791    int lastStartOffset = 0;
    17931792   
    1794     TextIterator iterator(range.get(), doNotEnterTextControls ? TextIteratorDefaultBehavior : TextIteratorEntersTextControls);
     1793    TextIterator iterator(*range, doNotEnterTextControls ? TextIteratorDefaultBehavior : TextIteratorEntersTextControls);
    17951794   
    17961795    // When the range has zero length, there might be replaced node or brTag that we need to increment the characterOffset.
     
    19031902        return -1;
    19041903    int length = 0;
    1905     for (TextIterator it(range); !it.atEnd(); it.advance()) {
     1904    for (TextIterator it(*range); !it.atEnd(); it.advance()) {
    19061905        // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX)
    19071906        if (it.text().length())
     
    26032602    CharacterOffset end = startOrEndCharacterOffsetForRange(searchRange, false);
    26042603   
    2605     TextIterator it(searchRange.get(), TextIteratorEmitsObjectReplacementCharacters);
     2604    TextIterator it(*searchRange, TextIteratorEmitsObjectReplacementCharacters);
    26062605    unsigned next = forwardSearchForBoundaryWithTextIterator(it, string, prefixLength, searchFunction);
    26072606   
     
    26442643        if (!setRangeStartOrEndWithCharacterOffset(forwardsScanRange, endOfCurrentParagraph, false))
    26452644            return { };
    2646         for (TextIterator forwardsIterator(forwardsScanRange.ptr()); !forwardsIterator.atEnd(); forwardsIterator.advance())
     2645        for (TextIterator forwardsIterator(forwardsScanRange); !forwardsIterator.atEnd(); forwardsIterator.advance())
    26472646            append(string, forwardsIterator.text());
    26482647        suffixLength = string.size();
     
    26672666   
    26682667    auto& node = it.atEnd() ? searchRange->startContainer() : it.range().start.container.get();
    2669    
     2668
    26702669    // SimplifiedBackwardsTextIterator ignores replaced elements.
    26712670    if (AccessibilityObject::replacedNodeNeedsCharacter(characterOffset.node))
  • trunk/Source/WebCore/accessibility/AccessibilityObject.cpp

    r258250 r258525  
    12681268        return String();
    12691269   
    1270     TextIterator it(range.get());
     1270    TextIterator it(*range);
    12711271    if (it.atEnd())
    12721272        return String();
     
    12971297    StringBuilder builder;
    12981298    RefPtr<Range> range = makeRange(visiblePositionRange.start, visiblePositionRange.end);
    1299     for (TextIterator it(range.get()); !it.atEnd(); it.advance()) {
     1299    if (!range)
     1300        return String();
     1301
     1302    for (TextIterator it(*range); !it.atEnd(); it.advance()) {
    13001303        // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX)
    13011304        if (it.text().length()) {
     
    13191322        return -1;
    13201323
     1324    RefPtr<Range> range = makeRange(visiblePositionRange.start, visiblePositionRange.end);
     1325    if (!range)
     1326        return -1;
     1327
    13211328    int length = 0;
    1322     RefPtr<Range> range = makeRange(visiblePositionRange.start, visiblePositionRange.end);
    1323     for (TextIterator it(range.get()); !it.atEnd(); it.advance()) {
     1329    for (TextIterator it(*range); !it.atEnd(); it.advance()) {
    13241330        // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX)
    13251331        if (it.text().length())
     
    13301336        }
    13311337    }
    1332 
    13331338    return length;
    13341339}
  • trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h

    r258475 r258525  
    3030#include "Range.h"
    3131#include "TextIterator.h"
    32 #include "TextIteratorBehavior.h"
    3332#include "VisiblePosition.h"
    3433#include "VisibleSelection.h"
  • trunk/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm

    r258475 r258525  
    5555#import "SVGElement.h"
    5656#import "SelectionRect.h"
    57 #import "SimpleRange.h"
    5857#import "TextIterator.h"
    5958#import "WAKScrollView.h"
     
    22542253    if (endVisiblePosition.isNull())
    22552254        return nil;
    2256    
     2255
     2256    auto range = makeRange(startVisiblePosition, endVisiblePosition);
     2257    if (!range)
     2258        return nil;
     2259
    22572260    // iterate over the range to build the AX attributed string
    22582261    NSMutableArray* array = [[NSMutableArray alloc] init];
    2259     TextIterator it(makeRange(startVisiblePosition, endVisiblePosition).get());
     2262    TextIterator it(*range);
    22602263    for (; !it.atEnd(); it.advance()) {
    22612264        Node& node = it.range().start.container;
  • trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm

    r258475 r258525  
    7171#import "RenderWidget.h"
    7272#import "ScrollView.h"
    73 #import "SimpleRange.h"
    7473#import "TextCheckerClient.h"
    7574#import "TextCheckingHelper.h"
     
    12561255        RefPtr<Range> range = [protectedSelf rangeForTextMarkerRange:textMarkerRange];
    12571256        NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] init];
    1258         TextIterator it(range.get());
     1257        if (!range)
     1258            return nil;
     1259        TextIterator it(*range);
    12591260        while (!it.atEnd()) {
    12601261            Node& node = it.range().start.container;
  • trunk/Source/WebCore/dom/BoundaryPoint.h

    r258248 r258525  
    2828#include "Node.h"
    2929
    30 #include <wtf/Ref.h>
    31 
    3230namespace WebCore {
    33 
    34 class Document;
    3531
    3632struct BoundaryPoint {
     
    4440    BoundaryPoint(BoundaryPoint&&) = default;
    4541    BoundaryPoint& operator=(const BoundaryPoint&);
    46     BoundaryPoint& operator=(BoundaryPoint&&);
     42    BoundaryPoint& operator=(BoundaryPoint&&) = default;
    4743
    4844    Document& document() const;
     
    5753}
    5854
     55inline BoundaryPoint::BoundaryPoint(const BoundaryPoint& other)
     56    : container(other.container.copyRef())
     57    , offset(other.offset)
     58{
     59}
     60
     61inline BoundaryPoint& BoundaryPoint::operator=(const BoundaryPoint& other)
     62{
     63    container = other.container.copyRef();
     64    offset = other.offset;
     65    return *this;
     66}
     67
     68inline Document& BoundaryPoint::document() const
     69{
     70    return container->document();
     71}
     72
    5973inline bool operator==(const BoundaryPoint& a, const BoundaryPoint& b)
    6074{
  • trunk/Source/WebCore/dom/DocumentMarkerController.cpp

    r258250 r258525  
    6464{
    6565    Vector<RefPtr<Range>> textRange;
    66     for (TextIterator textIterator(&range); !textIterator.atEnd(); textIterator.advance())
     66    for (TextIterator textIterator(range); !textIterator.atEnd(); textIterator.advance())
    6767        textRange.append(createLiveRange(textIterator.range()));
    6868    return textRange;
  • trunk/Source/WebCore/dom/Position.cpp

    r258475 r258525  
    11/*
    2  * Copyright (C) 2004, 2005, 2006, 2009, 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2004-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    126126}
    127127
    128 Position::Position(Node* anchorNode, int offset, AnchorType anchorType)
     128Position::Position(Node* anchorNode, unsigned offset, AnchorType anchorType)
    129129    : m_anchorNode(anchorNode)
    130130    , m_offset(offset)
     
    146146}
    147147
    148 void Position::moveToPosition(Node* node, int offset)
     148void Position::moveToPosition(Node* node, unsigned offset)
    149149{
    150150    ASSERT(!editingIgnoresContent(*node));
     
    155155        m_anchorType = anchorTypeForLegacyEditingPosition(m_anchorNode.get(), m_offset);
    156156}
    157 void Position::moveToOffset(int offset)
     157
     158void Position::moveToOffset(unsigned offset)
    158159{
    159160    ASSERT(anchorType() == PositionIsOffsetInAnchor || m_isLegacyEditingPosition);
     
    248249    }
    249250
    250     return { containerNode(), computeOffsetInContainerNode(), PositionIsOffsetInAnchor };
     251    return { containerNode(), static_cast<unsigned>(computeOffsetInContainerNode()), PositionIsOffsetInAnchor };
    251252}
    252253
     
    307308}
    308309
    309 Position::AnchorType Position::anchorTypeForLegacyEditingPosition(Node* anchorNode, int offset)
     310Position::AnchorType Position::anchorTypeForLegacyEditingPosition(Node* anchorNode, unsigned offset)
    310311{
    311312    if (anchorNode && editingIgnoresContent(*anchorNode)) {
     
    332333        return *this;
    333334
    334     int offset = deprecatedEditingOffset();
    335335    // FIXME: Negative offsets shouldn't be allowed. We should catch this earlier.
    336     ASSERT(offset >= 0);
     336    ASSERT(deprecatedEditingOffset() >= 0);
     337
     338    unsigned offset = deprecatedEditingOffset();
    337339
    338340    if (anchorType() == PositionIsBeforeAnchor) {
     
    385387        return *this;
    386388
    387     int offset = deprecatedEditingOffset();
    388389    // FIXME: Negative offsets shouldn't be allowed. We should catch this earlier.
    389     ASSERT(offset >= 0);
     390    ASSERT(deprecatedEditingOffset() >= 0);
     391
     392    unsigned offset = deprecatedEditingOffset();
    390393
    391394    if (anchorType() == PositionIsAfterAnchor) {
     
    398401
    399402    Node* child = node->traverseToChildAt(offset);
    400     if (child || (!node->hasChildNodes() && offset < lastOffsetForEditing(*node))) {
     403    if (child || (!node->hasChildNodes() && offset < static_cast<unsigned>(lastOffsetForEditing(*node)))) {
    401404        if (child)
    402405            return firstPositionInOrBeforeNode(child);
     
    424427}
    425428
    426 int Position::uncheckedPreviousOffset(const Node* n, int current)
     429int Position::uncheckedPreviousOffset(const Node* n, unsigned current)
    427430{
    428431    return n->renderer() ? n->renderer()->previousOffset(current) : current - 1;
    429432}
    430433
    431 int Position::uncheckedPreviousOffsetForBackwardDeletion(const Node* n, int current)
     434int Position::uncheckedPreviousOffsetForBackwardDeletion(const Node* n, unsigned current)
    432435{
    433436    return n->renderer() ? n->renderer()->previousOffsetForBackwardDeletion(current) : current - 1;
    434437}
    435438
    436 int Position::uncheckedNextOffset(const Node* n, int current)
     439int Position::uncheckedNextOffset(const Node* n, unsigned current)
    437440{
    438441    return n->renderer() ? n->renderer()->nextOffset(current) : current + 1;
     
    463466    if (isNull())
    464467        return true;
    465     // FIXME: Position after anchor shouldn't be considered as at the first editing position for node
    466     // since that position resides outside of the node.
    467     return m_anchorType == PositionIsAfterAnchor || m_anchorType == PositionIsAfterChildren || m_offset >= lastOffsetForEditing(*deprecatedNode());
     468    // FIXME: Position after anchor shouldn't be considered as at the first editing position for node since that position resides outside of the node.
     469    return m_anchorType == PositionIsAfterAnchor || m_anchorType == PositionIsAfterChildren || m_offset >= static_cast<unsigned>(lastOffsetForEditing(*deprecatedNode()));
    468470}
    469471
     
    542544    switch (m_anchorType) {
    543545    case PositionIsOffsetInAnchor:
    544         return m_offset >= lastOffsetForEditing(*m_anchorNode);
     546        return m_offset >= static_cast<unsigned>(lastOffsetForEditing(*m_anchorNode));
    545547    case PositionIsBeforeAnchor:
    546548        return false;
     
    10391041            return false;
    10401042
    1041         if (m_offset == position.deprecatedEditingOffset())
     1043        if (m_offset == static_cast<unsigned>(position.deprecatedEditingOffset()))
    10421044            return false;
    10431045
    1044         if (!is<Text>(*deprecatedNode()) && !is<Text>(*position.deprecatedNode())) {
    1045             if (m_offset != position.deprecatedEditingOffset())
    1046                 return true;
    1047         }
     1046        if (!is<Text>(*deprecatedNode()))
     1047            return true;
    10481048    }
    10491049
     
    10631063        return false;
    10641064
    1065     int thisRenderedOffset = is<RenderText>(*renderer) ? downcast<RenderText>(*renderer).countRenderedCharacterOffsetsUntil(m_offset) : m_offset;
    1066     int positionRenderedOffset = is<RenderText>(*positionRenderer) ? downcast<RenderText>(*positionRenderer).countRenderedCharacterOffsetsUntil(position.m_offset) : position.m_offset;
     1065    unsigned thisRenderedOffset = is<RenderText>(*renderer) ? downcast<RenderText>(*renderer).countRenderedCharacterOffsetsUntil(m_offset) : m_offset;
     1066    unsigned positionRenderedOffset = is<RenderText>(*positionRenderer) ? downcast<RenderText>(*positionRenderer).countRenderedCharacterOffsetsUntil(position.m_offset) : position.m_offset;
    10671067
    10681068    if (renderer == positionRenderer && thisRenderedOffset == positionRenderedOffset)
     
    10921092
    10931093    if (nextRenderedEditable(deprecatedNode()) == position.deprecatedNode()
    1094         && thisRenderedOffset == caretMaxOffset(*deprecatedNode()) && !positionRenderedOffset) {
     1094        && thisRenderedOffset == static_cast<unsigned>(caretMaxOffset(*deprecatedNode())) && !positionRenderedOffset) {
    10951095        return false;
    10961096    }
    10971097   
    10981098    if (previousRenderedEditable(deprecatedNode()) == position.deprecatedNode()
    1099         && !thisRenderedOffset && positionRenderedOffset == caretMaxOffset(*position.deprecatedNode())) {
     1099        && !thisRenderedOffset && positionRenderedOffset == static_cast<unsigned>(caretMaxOffset(*position.deprecatedNode()))) {
    11001100        return false;
    11011101    }
     
    11681168        if (is<RenderText>(*next)) {
    11691169            InlineTextBox* match = nullptr;
    1170             int minOffset = INT_MAX;
     1170            unsigned minOffset = std::numeric_limits<unsigned>::max();
    11711171            for (InlineTextBox* box = downcast<RenderText>(*next).firstTextBox(); box; box = box->nextTextBox()) {
    1172                 int caretMinOffset = box->caretMinOffset();
     1172                unsigned caretMinOffset = box->caretMinOffset();
    11731173                if (caretMinOffset < minOffset) {
    11741174                    match = box;
     
    12201220
    12211221        for (box = textRenderer.firstTextBox(); box; box = box->nextTextBox()) {
    1222             int caretMinOffset = box->caretMinOffset();
    1223             int caretMaxOffset = box->caretMaxOffset();
    1224 
    1225             if (caretOffset < caretMinOffset || caretOffset > caretMaxOffset || (caretOffset == caretMaxOffset && box->isLineBreak()))
     1222            unsigned caretMinOffset = box->caretMinOffset();
     1223            unsigned caretMaxOffset = box->caretMaxOffset();
     1224
     1225            if (static_cast<unsigned>(caretOffset) < caretMinOffset || static_cast<unsigned>(caretOffset) > caretMaxOffset || (static_cast<unsigned>(caretOffset) == caretMaxOffset && box->isLineBreak()))
    12261226                continue;
    12271227
    1228             if (caretOffset > caretMinOffset && caretOffset < caretMaxOffset) {
     1228            if (static_cast<unsigned>(caretOffset) > caretMinOffset && static_cast<unsigned>(caretOffset) < caretMaxOffset) {
    12291229                inlineBox = box;
    12301230                return;
    12311231            }
    12321232
    1233             if (((caretOffset == caretMaxOffset) ^ (affinity == DOWNSTREAM))
    1234                 || ((caretOffset == caretMinOffset) ^ (affinity == UPSTREAM))
    1235                 || (caretOffset == caretMaxOffset && box->nextLeafOnLine() && box->nextLeafOnLine()->isLineBreak()))
     1233            if (((static_cast<unsigned>(caretOffset) == caretMaxOffset) ^ (affinity == DOWNSTREAM))
     1234                || ((static_cast<unsigned>(caretOffset) == caretMinOffset) ^ (affinity == UPSTREAM))
     1235                || (static_cast<unsigned>(caretOffset) == caretMaxOffset && box->nextLeafOnLine() && box->nextLeafOnLine()->isLineBreak()))
    12361236                break;
    12371237
     
    14791479        case PositionIsAfterChildren:
    14801480            ASSERT(!is<Text>(*other.m_anchorNode));
    1481             return m_anchorNode == other.m_anchorNode && m_offset == static_cast<int>(other.m_anchorNode->countChildNodes());
     1481            return m_anchorNode == other.m_anchorNode && m_offset == other.m_anchorNode->countChildNodes();
    14821482        case PositionIsOffsetInAnchor:
    14831483            return m_anchorNode == other.m_anchorNode && m_offset == other.m_offset;
     
    15991599}
    16001600
     1601Optional<BoundaryPoint> makeBoundaryPoint(const Position& position)
     1602{
     1603    if (position.isNull())
     1604        return WTF::nullopt;
     1605    return BoundaryPoint { *position.containerNode(), static_cast<unsigned>(position.computeOffsetInContainerNode()) };
     1606}
     1607
    16011608} // namespace WebCore
    16021609
  • trunk/Source/WebCore/dom/Position.h

    r258475 r258525  
    11/*
    2  * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
     2 * Copyright (C) 2004-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    7070    // For creating offset positions:
    7171    // FIXME: This constructor should eventually go away. See bug 63040.
    72     WEBCORE_EXPORT Position(Node* anchorNode, int offset, AnchorType);
     72    WEBCORE_EXPORT Position(Node* anchorNode, unsigned offset, AnchorType);
    7373
    7474    AnchorType anchorType() const { return static_cast<AnchorType>(m_anchorType); }
     
    122122    // These should only be used for PositionIsOffsetInAnchor positions, unless
    123123    // the position is a legacy editing position.
    124     void moveToPosition(Node* anchorNode, int offset);
    125     void moveToOffset(int offset);
     124    void moveToPosition(Node* anchorNode, unsigned offset);
     125    void moveToOffset(unsigned offset);
    126126
    127127    bool isNull() const { return !m_anchorNode; }
     
    136136    WEBCORE_EXPORT Position previous(PositionMoveType = CodePoint) const;
    137137    WEBCORE_EXPORT Position next(PositionMoveType = CodePoint) const;
    138     static int uncheckedPreviousOffset(const Node*, int current);
    139     static int uncheckedPreviousOffsetForBackwardDeletion(const Node*, int current);
    140     static int uncheckedNextOffset(const Node*, int current);
     138    static int uncheckedPreviousOffset(const Node*, unsigned current);
     139    static int uncheckedPreviousOffsetForBackwardDeletion(const Node*, unsigned current);
     140    static int uncheckedNextOffset(const Node*, unsigned current);
    141141
    142142    // These can be either inside or just before/after the node, depending on
     
    207207    Position nextCharacterPosition(EAffinity) const;
    208208
    209     static AnchorType anchorTypeForLegacyEditingPosition(Node* anchorNode, int offset);
     209    static AnchorType anchorTypeForLegacyEditingPosition(Node* anchorNode, unsigned offset);
    210210
    211211    RefPtr<Node> m_anchorNode;
     
    213213    // returns true, then other places in editing will treat m_offset == 0 as "before the anchor"
    214214    // and m_offset > 0 as "after the anchor node".  See parentAnchoredEquivalent for more info.
    215     int m_offset { 0 };
     215    unsigned m_offset { 0 };
    216216    unsigned m_anchorType : 3;
    217217    bool m_isLegacyEditingPosition : 1;
    218218};
    219219
     220bool operator==(const Position&, const Position&);
     221bool operator!=(const Position&, const Position&);
     222bool operator<(const Position&, const Position&);
     223bool operator>(const Position&, const Position&);
     224bool operator>=(const Position&, const Position&);
     225bool operator<=(const Position&, const Position&);
     226
     227// FIXME: Consider renaming this to "make" instead of "create" since we normally use "create" for functions that allocate heap objects.
     228Position createLegacyEditingPosition(Node*, unsigned offset);
    220229Position createLegacyEditingPosition(const BoundaryPoint&);
     230
     231WEBCORE_EXPORT Optional<BoundaryPoint> makeBoundaryPoint(const Position&);
     232
     233Position positionInParentBeforeNode(Node*);
     234Position positionInParentAfterNode(Node*);
     235
     236// positionBeforeNode and positionAfterNode return neighbor-anchored positions, construction is O(1)
     237Position positionBeforeNode(Node* anchorNode);
     238Position positionAfterNode(Node* anchorNode);
     239
     240int lastOffsetInNode(Node*);
     241
     242// firstPositionInNode and lastPositionInNode return parent-anchored positions, lastPositionInNode construction is O(n) due to countChildNodes()
     243Position firstPositionInNode(Node* anchorNode);
     244Position lastPositionInNode(Node* anchorNode);
     245
     246int minOffsetForNode(Node* anchorNode, unsigned offset);
     247bool offsetIsBeforeLastNodeOffset(unsigned offset, Node* anchorNode);
     248
     249RefPtr<Node> commonShadowIncludingAncestor(const Position&, const Position&);
     250
     251WTF::TextStream& operator<<(WTF::TextStream&, const Position&);
     252
     253// inlines
    221254
    222255inline Position createLegacyEditingPosition(Node* node, unsigned offset)
     
    261294}
    262295
    263 Position positionInParentBeforeNode(Node*);
    264 Position positionInParentAfterNode(Node*);
    265 
    266296// positionBeforeNode and positionAfterNode return neighbor-anchored positions, construction is O(1)
    267297inline Position positionBeforeNode(Node* anchorNode)
     
    279309inline int lastOffsetInNode(Node* node)
    280310{
    281     return node->isCharacterDataNode() ? node->maxCharacterOffset() : static_cast<int>(node->countChildNodes());
     311    return node->isCharacterDataNode() ? node->maxCharacterOffset() : node->countChildNodes();
    282312}
    283313
     
    297327}
    298328
    299 inline int minOffsetForNode(Node* anchorNode, int offset)
     329inline int minOffsetForNode(Node* anchorNode, unsigned offset)
    300330{
    301331    if (anchorNode->isCharacterDataNode())
    302         return std::min(offset, anchorNode->maxCharacterOffset());
    303 
    304     int newOffset = 0;
     332        return std::min<unsigned>(offset, anchorNode->maxCharacterOffset());
     333
     334    unsigned newOffset = 0;
    305335    for (Node* node = anchorNode->firstChild(); node && newOffset < offset; node = node->nextSibling())
    306336        newOffset++;
     
    309339}
    310340
    311 inline bool offsetIsBeforeLastNodeOffset(int offset, Node* anchorNode)
     341inline bool offsetIsBeforeLastNodeOffset(unsigned offset, Node* anchorNode)
    312342{
    313343    if (anchorNode->isCharacterDataNode())
    314         return offset < anchorNode->maxCharacterOffset();
    315 
    316     int currentOffset = 0;
     344        return offset < static_cast<unsigned>(anchorNode->maxCharacterOffset());
     345
     346    unsigned currentOffset = 0;
    317347    for (Node* node = anchorNode->firstChild(); node && currentOffset < offset; node = node->nextSibling())
    318348        currentOffset++;
     
    321351    return offset < currentOffset;
    322352}
    323 
    324 RefPtr<Node> commonShadowIncludingAncestor(const Position&, const Position&);
    325 
    326 WTF::TextStream& operator<<(WTF::TextStream&, const Position&);
    327353
    328354} // namespace WebCore
  • trunk/Source/WebCore/dom/Range.cpp

    r254153 r258525  
    18701870}
    18711871
     1872Ref<Range> createLiveRange(const SimpleRange& range)
     1873{
     1874    return Range::create(range.start.document(), range.start.container.ptr(), range.start.offset, range.end.container.ptr(), range.end.offset);
     1875}
     1876
     1877RefPtr<Range> createLiveRange(const Optional<SimpleRange>& range)
     1878{
     1879    if (!range)
     1880        return nullptr;
     1881    return createLiveRange(*range);
     1882}
     1883
    18721884WTF::TextStream& operator<<(WTF::TextStream& ts, const RangeBoundaryPoint& r)
    18731885{
  • trunk/Source/WebCore/dom/Range.h

    r254153 r258525  
    44 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no)
    55 * (C) 2001 Peter Kelly (pmk@post.com)
    6  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
     6 * Copyright (C) 2004-2020 Apple Inc. All rights reserved.
    77 *
    88 * This library is free software; you can redistribute it and/or
     
    2828#include "IntRect.h"
    2929#include "RangeBoundaryPoint.h"
    30 #include <wtf/Forward.h>
    3130#include <wtf/OptionSet.h>
    32 #include <wtf/RefCounted.h>
    33 #include <wtf/Vector.h>
    3431
    3532namespace WebCore {
    3633
    37 class ContainerNode;
    3834class DOMRect;
    3935class DOMRectList;
    40 class Document;
    4136class DocumentFragment;
    4237class FloatQuad;
    43 class Node;
    4438class NodeWithIndex;
    4539class RenderText;
     
    4842class VisiblePosition;
    4943
     44struct SimpleRange;
     45
     46// FIXME: Rename to LiveRange, while leaving the DOM-exposed name as Range.
    5047class Range : public RefCounted<Range> {
    5148public:
     
    186183WEBCORE_EXPORT bool rangesOverlap(const Range*, const Range*);
    187184
     185WEBCORE_EXPORT Ref<Range> createLiveRange(const SimpleRange&);
     186WEBCORE_EXPORT RefPtr<Range> createLiveRange(const Optional<SimpleRange>&);
     187
     188bool documentOrderComparator(const Node*, const Node*);
     189
     190WTF::TextStream& operator<<(WTF::TextStream&, const RangeBoundaryPoint&);
     191WTF::TextStream& operator<<(WTF::TextStream&, const Range&);
     192
    188193inline bool documentOrderComparator(const Node* a, const Node* b)
    189194{
    190195    return Range::compareBoundaryPoints(const_cast<Node*>(a), 0, const_cast<Node*>(b), 0).releaseReturnValue() < 0;
    191196}
    192    
    193 WTF::TextStream& operator<<(WTF::TextStream&, const RangeBoundaryPoint&);
    194 WTF::TextStream& operator<<(WTF::TextStream&, const Range&);
    195 
    196 } // namespace
     197
     198} // namespace WebCore
    197199
    198200#if ENABLE(TREE_DEBUGGING)
  • trunk/Source/WebCore/dom/SimpleRange.cpp

    r258129 r258525  
    5454}
    5555
    56 Ref<Range> createLiveRange(const SimpleRange& range)
    57 {
    58     return Range::create(range.start.document(), range.start.container.ptr(), range.start.offset, range.end.container.ptr(), range.end.offset);
    5956}
    60 
    61 RefPtr<Range> createLiveRange(const Optional<SimpleRange>& range)
    62 {
    63     if (!range)
    64         return nullptr;
    65     return createLiveRange(*range);
    66 }
    67 
    68 }
  • trunk/Source/WebCore/dom/SimpleRange.h

    r258129 r258525  
    4444
    4545    SimpleRange(const BoundaryPoint&, const BoundaryPoint&);
    46     SimpleRange(BoundaryPoint&&, BoundaryPoint&&);
     46    WEBCORE_EXPORT SimpleRange(BoundaryPoint&&, BoundaryPoint&&);
    4747
     48    // Convenience overloads to help with transition from using a lot of live ranges.
     49    // FIXME: Move to the Range class header as either makeSimpleRange or Range::operator SimpleRange.
    4850    WEBCORE_EXPORT SimpleRange(const Range&);
    49 
    50     // Convenience overloads to help with transition from using a lot of live ranges. Consider removing these eventually.
    51     SimpleRange(const Range*); // Crashes if passed a nullptr.
    5251    SimpleRange(const Ref<Range>&);
    5352};
    5453
    5554bool operator==(const SimpleRange&, const SimpleRange&);
    56 
    57 WEBCORE_EXPORT Ref<Range> createLiveRange(const SimpleRange&);
    58 WEBCORE_EXPORT RefPtr<Range> createLiveRange(const Optional<SimpleRange>&);
    59 
    60 inline SimpleRange::SimpleRange(const Range* range)
    61     : SimpleRange(*range)
    62 {
    63 }
    6455
    6556inline SimpleRange::SimpleRange(const Ref<Range>& range)
  • trunk/Source/WebCore/editing/ApplyStyleCommand.cpp

    r258522 r258525  
    12671267{
    12681268    auto* startNode = start.containerNode();
    1269     int startOffset = start.computeOffsetInContainerNode();
    1270     if (startOffset)
     1269    if (start.computeOffsetInContainerNode())
    12711270        return false;
    12721271
     
    12901289    mergeIdenticalElements(previousElement, element);
    12911290
    1292     int startOffsetAdjustment = startChild->computeNodeIndex();
    1293     int endOffsetAdjustment = startNode == end.deprecatedNode() ? startOffsetAdjustment : 0;
    1294     updateStartEnd({ startNode, startOffsetAdjustment, Position::PositionIsOffsetInAnchor},
    1295         { end.deprecatedNode(), end.deprecatedEditingOffset() + endOffsetAdjustment, Position::PositionIsOffsetInAnchor });
     1291    // FIXME: Inconsistent that we use computeOffsetInContainerNode for start, but deprecatedEditingOffset for end.
     1292    unsigned startOffset = startChild->computeNodeIndex();
     1293    unsigned endOffset = end.deprecatedEditingOffset() + (startNode == end.deprecatedNode() ? startOffset : 0);
     1294    updateStartEnd({ startNode, startOffset, Position::PositionIsOffsetInAnchor },
     1295        { end.deprecatedNode(), endOffset, Position::PositionIsOffsetInAnchor });
    12961296    return true;
    12971297}
     
    13231323
    13241324    bool shouldUpdateStart = start.containerNode() == endNode;
    1325     int endOffset = nextChild ? nextChild->computeNodeIndex() : nextElement.countChildNodes();
     1325    unsigned endOffset = nextChild ? nextChild->computeNodeIndex() : nextElement.countChildNodes();
    13261326    updateStartEnd(shouldUpdateStart ? Position(&nextElement, start.offsetInContainerNode(), Position::PositionIsOffsetInAnchor) : start,
    13271327        { &nextElement, endOffset, Position::PositionIsOffsetInAnchor });
  • trunk/Source/WebCore/editing/Editing.cpp

    r258475 r258525  
    5252#include "RenderTableCell.h"
    5353#include "ShadowRoot.h"
    54 #include "SimpleRange.h"
    5554#include "Text.h"
    5655#include "TextIterator.h"
     
    13091308{
    13101309    HashSet<RefPtr<HTMLImageElement>> result;
    1311     for (TextIterator iterator(&range); !iterator.atEnd(); iterator.advance()) {
     1310    for (TextIterator iterator(range); !iterator.atEnd(); iterator.advance()) {
    13121311        if (!is<HTMLImageElement>(iterator.node()))
    13131312            continue;
  • trunk/Source/WebCore/editing/Editing.h

    r256563 r258525  
    3838class HTMLSpanElement;
    3939class HTMLTextFormControlElement;
     40class Range;
    4041class RenderBlock;
    4142class VisiblePosition;
  • trunk/Source/WebCore/editing/Editor.cpp

    r258475 r258525  
    33143314    // We remove '\0' characters because they are not visibly rendered to the user.
    33153315    auto& selection = m_frame.selection().selection();
    3316     return plainText(selection.start(), selection.end(), behavior).replaceWithLiteral('\0', "");
     3316    auto start = selection.start();
     3317    auto end = selection.end();
     3318    if (start.isNull() || start.isOrphan() || end.isNull() || end.isOrphan())
     3319        return emptyString();
     3320    return plainText(SimpleRange { *makeBoundaryPoint(start), *makeBoundaryPoint(end) }, behavior).replaceWithLiteral('\0', "");
    33173321}
    33183322
  • trunk/Source/WebCore/editing/HTMLInterchange.cpp

    r213355 r258525  
    2828
    2929#include "Editing.h"
    30 #include "RenderElement.h"
    3130#include "RenderText.h"
    3231#include "Text.h"
    33 #include "TextIterator.h"
    3432#include <wtf/text/StringBuilder.h>
    3533#include <wtf/unicode/CharacterNames.h>
     
    6361                switch (add) {
    6462                    case 0:
    65                         s.appendLiteral(convertedSpaceString);
    66                         s.append(' ');
    67                         s.appendLiteral(convertedSpaceString);
     63                        s.append(convertedSpaceString, ' ', convertedSpaceString);
    6864                        add = 3;
    6965                        break;
     
    7773                        if (i == 0) {
    7874                             // at start of string
    79                             s.appendLiteral(convertedSpaceString);
    80                             s.append(' ');
     75                            s.append(convertedSpaceString, ' ');
    8176                        } else if (i + 2 == in.length()) {
    8277                             // at end of string
    83                             s.appendLiteral(convertedSpaceString);
    84                             s.appendLiteral(convertedSpaceString);
     78                            s.append(convertedSpaceString, convertedSpaceString);
    8579                        } else {
    86                             s.appendLiteral(convertedSpaceString);
    87                             s.append(' ');
     80                            s.append(convertedSpaceString, ' ');
    8881                        }
    8982                        break;
  • trunk/Source/WebCore/editing/TextIterator.cpp

    r258475 r258525  
    330330// --------
    331331
    332 
    333 TextIterator::TextIterator(Position start, Position end, TextIteratorBehavior behavior)
     332static Node* firstNode(const BoundaryPoint& point)
     333{
     334    if (point.container->isCharacterDataNode())
     335        return point.container.ptr();
     336    if (Node* child = point.container->traverseToChildAt(point.offset))
     337        return child;
     338    if (!point.offset)
     339        return point.container.ptr();
     340    return NodeTraversal::nextSkippingChildren(point.container);
     341}
     342
     343TextIterator::TextIterator(const SimpleRange& range, TextIteratorBehavior behavior)
    334344    : m_behavior(behavior)
    335345{
    336     if (start.isNull() || end.isNull())
    337         return;
    338     ASSERT(comparePositions(start, end) <= 0);
    339 
    340     RELEASE_ASSERT(behavior & TextIteratorTraversesFlatTree || start.treeScope() == end.treeScope());
    341 
    342     start.document()->updateLayoutIgnorePendingStylesheets();
    343 
    344     // FIXME: Use Position / PositionIterator instead to avoid offset computation.
    345     m_startContainer = start.containerNode();
    346     m_startOffset = start.computeOffsetInContainerNode();
    347 
    348     m_endContainer = end.containerNode();
    349     m_endOffset = end.computeOffsetInContainerNode();
    350 
    351     m_node = start.firstNode().get();
    352     if (!m_node)
    353         return;
    354 
    355     init();
    356 }
    357 
    358 TextIterator::TextIterator(const Range* range, TextIteratorBehavior behavior)
    359     : m_behavior(behavior)
    360 {
    361     if (!range)
    362         return;
    363 
    364     range->ownerDocument().updateLayoutIgnorePendingStylesheets();
    365 
    366     m_startContainer = &range->startContainer();
    367 
    368     // Callers should be handing us well-formed ranges. If we discover that this isn't
    369     // the case, we could consider changing this assertion to an early return.
    370     ASSERT(range->boundaryPointsValid());
    371 
    372     m_startOffset = range->startOffset();
    373     m_endContainer = &range->endContainer();
    374     m_endOffset = range->endOffset();
    375 
    376     m_node = range->firstNode();
     346    range.start.document().updateLayoutIgnorePendingStylesheets();
     347
     348    m_startContainer = range.start.container.ptr();
     349    m_startOffset = range.start.offset;
     350    m_endContainer = range.end.container.ptr();
     351    m_endOffset = range.end.offset;
     352
     353    m_node = firstNode(range.start);
    377354    if (!m_node)
    378355        return;
     
    11411118// --------
    11421119
    1143 SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator(const Range& range)
    1144 {
    1145     range.ownerDocument().updateLayoutIgnorePendingStylesheets();
    1146 
    1147     Node* startNode = &range.startContainer();
    1148     Node* endNode = &range.endContainer();
    1149     int startOffset = range.startOffset();
    1150     int endOffset = range.endOffset();
     1120SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator(const SimpleRange& range)
     1121{
     1122    range.start.document().updateLayoutIgnorePendingStylesheets();
     1123
     1124    Node* startNode = range.start.container.ptr();
     1125    Node* endNode = range.end.container.ptr();
     1126    unsigned startOffset = range.start.offset;
     1127    unsigned endOffset = range.end.offset;
    11511128
    11521129    if (!startNode->isCharacterDataNode()) {
    1153         if (startOffset >= 0 && startOffset < static_cast<int>(startNode->countChildNodes())) {
     1130        if (startOffset < startNode->countChildNodes()) {
    11541131            startNode = startNode->traverseToChildAt(startOffset);
    11551132            startOffset = 0;
     
    11571134    }
    11581135    if (!endNode->isCharacterDataNode()) {
    1159         if (endOffset > 0 && endOffset <= static_cast<int>(endNode->countChildNodes())) {
     1136        if (endOffset > 0 && endOffset <= endNode->countChildNodes()) {
    11601137            endNode = endNode->traverseToChildAt(endOffset - 1);
    11611138            endOffset = lastOffsetInNode(endNode);
     
    13921369// --------
    13931370
    1394 CharacterIterator::CharacterIterator(const Range& range, TextIteratorBehavior behavior)
    1395     : m_underlyingIterator(&range, behavior)
    1396 {
    1397     while (!atEnd() && !m_underlyingIterator.text().length())
    1398         m_underlyingIterator.advance();
    1399 }
    1400 
    1401 CharacterIterator::CharacterIterator(Position start, Position end, TextIteratorBehavior behavior)
    1402     : m_underlyingIterator(start, end, behavior)
     1371CharacterIterator::CharacterIterator(const SimpleRange& range, TextIteratorBehavior behavior)
     1372    : m_underlyingIterator(range, behavior)
    14031373{
    14041374    while (!atEnd() && !m_underlyingIterator.text().length())
     
    14841454}
    14851455
    1486 BackwardsCharacterIterator::BackwardsCharacterIterator(const Range& range)
     1456BackwardsCharacterIterator::BackwardsCharacterIterator(const SimpleRange& range)
    14871457    : m_underlyingIterator(range)
    14881458{
     
    15471517// --------
    15481518
    1549 WordAwareIterator::WordAwareIterator(const Range& range)
    1550     : m_underlyingIterator(&range)
     1519WordAwareIterator::WordAwareIterator(const SimpleRange& range)
     1520    : m_underlyingIterator(range)
    15511521{
    15521522    advance(); // get in position over the first chunk of text
     
    23762346int TextIterator::rangeLength(const Range* range, bool forSelectionPreservation)
    23772347{
     2348    if (!range)
     2349        return 0;
    23782350    unsigned length = 0;
    2379     for (TextIterator it(range, forSelectionPreservation ? TextIteratorEmitsCharactersBetweenAllVisiblePositions : TextIteratorDefaultBehavior); !it.atEnd(); it.advance())
     2351    for (TextIterator it(*range, forSelectionPreservation ? TextIteratorEmitsCharactersBetweenAllVisiblePositions : TextIteratorDefaultBehavior); !it.atEnd(); it.advance())
    23802352        length += it.text().length();
    23812353    return length;
     
    24062378    Ref<Range> textRunRange = rangeOfContents(*scope);
    24072379
    2408     TextIterator it(textRunRange.ptr(), forSelectionPreservation ? TextIteratorEmitsCharactersBetweenAllVisiblePositions : TextIteratorDefaultBehavior);
     2380    TextIterator it(textRunRange, forSelectionPreservation ? TextIteratorEmitsCharactersBetweenAllVisiblePositions : TextIteratorDefaultBehavior);
    24092381   
    24102382    // FIXME: the atEnd() check shouldn't be necessary, workaround for <http://bugs.webkit.org/show_bug.cgi?id=6289>.
     
    25072479bool hasAnyPlainText(const SimpleRange& range, TextIteratorBehavior behavior)
    25082480{
    2509     for (TextIterator iterator { createLiveRange(range).ptr(), behavior }; !iterator.atEnd(); iterator.advance()) {
     2481    for (TextIterator iterator { range, behavior }; !iterator.atEnd(); iterator.advance()) {
    25102482        if (!iterator.text().isEmpty())
    25112483            return true;
     
    25142486}
    25152487
    2516 String plainText(Position start, Position end, TextIteratorBehavior defaultBehavior, bool isDisplayString)
     2488String plainText(const SimpleRange& range, TextIteratorBehavior defaultBehavior, bool isDisplayString)
    25172489{
    25182490    // The initial buffer size can be critical for performance: https://bugs.webkit.org/show_bug.cgi?id=81192
    25192491    static const unsigned initialCapacity = 1 << 15;
    25202492
    2521     if (!start.document())
    2522         return { };
    2523     auto document = makeRef(*start.document());
     2493    auto document = makeRef(range.start.document());
    25242494
    25252495    unsigned bufferLength = 0;
     
    25302500        behavior = static_cast<TextIteratorBehavior>(behavior | TextIteratorEmitsTextsWithoutTranscoding);
    25312501
    2532     for (TextIterator it(start, end, behavior); !it.atEnd(); it.advance()) {
     2502    for (TextIterator it(range, behavior); !it.atEnd(); it.advance()) {
    25332503        it.appendTextToStringBuilder(builder);
    25342504        bufferLength += it.text().length();
     
    25462516}
    25472517
    2548 String plainTextReplacingNoBreakSpace(Position start, Position end, TextIteratorBehavior defaultBehavior, bool isDisplayString)
    2549 {
    2550     return plainText(start, end, defaultBehavior, isDisplayString).replace(noBreakSpace, ' ');
    2551 }
    2552 
    25532518String plainText(const Range* range, TextIteratorBehavior defaultBehavior, bool isDisplayString)
    25542519{
    25552520    if (!range)
    25562521        return emptyString();
    2557     return plainText(range->startPosition(), range->endPosition(), defaultBehavior, isDisplayString);
     2522    return plainText(*range, defaultBehavior, isDisplayString);
    25582523}
    25592524
     
    25662531}
    25672532
    2568 String plainTextReplacingNoBreakSpace(const Range* range, TextIteratorBehavior defaultBehavior, bool isDisplayString)
     2533String plainTextReplacingNoBreakSpace(const SimpleRange& range, TextIteratorBehavior defaultBehavior, bool isDisplayString)
    25692534{
    25702535    return plainText(range, defaultBehavior, isDisplayString).replace(noBreakSpace, ' ');
  • trunk/Source/WebCore/editing/TextIterator.h

    r258475 r258525  
    3131#include "TextIteratorBehavior.h"
    3232#include <wtf/Vector.h>
    33 #include <wtf/text/StringView.h>
    3433
    3534namespace WebCore {
    3635
    3736class Range;
    38 class RenderText;
    3937class RenderTextFragment;
    4038
    41 WEBCORE_EXPORT String plainText(Position start, Position end, TextIteratorBehavior = TextIteratorDefaultBehavior, bool isDisplayString = false);
    42 WEBCORE_EXPORT String plainTextReplacingNoBreakSpace(Position start, Position end, TextIteratorBehavior = TextIteratorDefaultBehavior, bool isDisplayString = false);
    43 
    4439WEBCORE_EXPORT String plainText(const Range*, TextIteratorBehavior = TextIteratorDefaultBehavior, bool isDisplayString = false);
    45 WEBCORE_EXPORT String plainTextReplacingNoBreakSpace(const Range*, TextIteratorBehavior = TextIteratorDefaultBehavior, bool isDisplayString = false);
     40WEBCORE_EXPORT String plainText(const SimpleRange&, TextIteratorBehavior = TextIteratorDefaultBehavior, bool isDisplayString = false);
     41WEBCORE_EXPORT String plainTextReplacingNoBreakSpace(const SimpleRange&, TextIteratorBehavior = TextIteratorDefaultBehavior, bool isDisplayString = false);
    4642WEBCORE_EXPORT String plainTextUsingBackwardsTextIteratorForTesting(const SimpleRange&);
    4743
     
    9288    WTF_MAKE_FAST_ALLOCATED;
    9389public:
    94     WEBCORE_EXPORT TextIterator(Position start, Position end, TextIteratorBehavior = TextIteratorDefaultBehavior);
    95     WEBCORE_EXPORT explicit TextIterator(const Range*, TextIteratorBehavior = TextIteratorDefaultBehavior);
     90    WEBCORE_EXPORT explicit TextIterator(const SimpleRange&, TextIteratorBehavior = TextIteratorDefaultBehavior);
    9691    WEBCORE_EXPORT ~TextIterator();
    9792
     
    178173class SimplifiedBackwardsTextIterator {
    179174public:
    180     explicit SimplifiedBackwardsTextIterator(const Range&);
     175    explicit SimplifiedBackwardsTextIterator(const SimpleRange&);
    181176
    182177    bool atEnd() const { return !m_positionNode; }
     
    233228class CharacterIterator {
    234229public:
    235     WEBCORE_EXPORT explicit CharacterIterator(const Range&, TextIteratorBehavior = TextIteratorDefaultBehavior);
    236     WEBCORE_EXPORT explicit CharacterIterator(Position start, Position end, TextIteratorBehavior = TextIteratorDefaultBehavior);
     230    WEBCORE_EXPORT explicit CharacterIterator(const SimpleRange&, TextIteratorBehavior = TextIteratorDefaultBehavior);
    237231   
    238232    bool atEnd() const { return m_underlyingIterator.atEnd(); }
     
    255249class BackwardsCharacterIterator {
    256250public:
    257     explicit BackwardsCharacterIterator(const Range&);
     251    explicit BackwardsCharacterIterator(const SimpleRange&);
    258252
    259253    bool atEnd() const { return m_underlyingIterator.atEnd(); }
     
    274268class WordAwareIterator {
    275269public:
    276     explicit WordAwareIterator(const Range&);
     270    explicit WordAwareIterator(const SimpleRange&);
    277271
    278272    bool atEnd() const { return !m_didLookAhead && m_underlyingIterator.atEnd(); }
  • trunk/Source/WebCore/editing/TextManipulationController.cpp

    r258475 r258525  
    142142public:
    143143    ParagraphContentIterator(const Position& start, const Position& end)
    144         : m_iterator(start, end)
     144        : m_iterator({ *makeBoundaryPoint(start), *makeBoundaryPoint(end) })
    145145        , m_iteratorNode(m_iterator.atEnd() ? nullptr : createLiveRange(m_iterator.range())->firstNode())
    146146        , m_currentNodeForFindingInvisibleContent(start.firstNode())
     
    463463    HashMap<TokenIdentifier, TokenExchangeData> tokenExchangeMap;
    464464
    465     if (item.start.isNull() && item.end.isNull()) {
     465    if (item.start.isNull() || item.end.isNull()) {
    466466        RELEASE_ASSERT(item.tokens.size() == 1);
    467467        auto element = makeRefPtr(item.element.get());
  • trunk/Source/WebCore/editing/VisibleSelection.cpp

    r258475 r258525  
    3434#include "Settings.h"
    3535#include "ShadowRoot.h"
    36 #include "SimpleRange.h"
    3736#include "TextIterator.h"
    3837#include "VisibleUnits.h"
  • trunk/Source/WebCore/editing/VisibleUnits.cpp

    r258475 r258525  
    490490{
    491491    unsigned suffixLength = 0;
    492     TextIterator forwardsIterator(&forwardsScanRange);
     492    TextIterator forwardsIterator(forwardsScanRange);
    493493    while (!forwardsIterator.atEnd()) {
    494494        StringView text = forwardsIterator.text();
     
    610610        if (result.hasException())
    611611            return { };
    612         for (TextIterator forwardsIterator(forwardsScanRange.ptr()); !forwardsIterator.atEnd(); forwardsIterator.advance())
     612        for (TextIterator forwardsIterator(forwardsScanRange); !forwardsIterator.atEnd(); forwardsIterator.advance())
    613613            append(string, forwardsIterator.text());
    614614        suffixLength = string.size();
     
    675675    if (start.deprecatedNode())
    676676        searchRange->setStart(*start.deprecatedNode(), start.deprecatedEditingOffset());
    677     TextIterator it(searchRange.ptr(), TextIteratorEmitsCharactersBetweenAllVisiblePositions);
     677    TextIterator it(searchRange, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
    678678    unsigned next = forwardSearchForBoundaryWithTextIterator(it, string, prefixLength, searchFunction);
    679679   
  • trunk/Source/WebCore/editing/cocoa/DataDetection.mm

    r258250 r258525  
    4444#import "Range.h"
    4545#import "RenderObject.h"
    46 #import "SimpleRange.h"
    4746#import "StyleProperties.h"
    4847#import "Text.h"
     
    163162    return detectItemAtPositionWithRange(position, contextRange, detectedDataBoundingBox, detectedDataRange);
    164163}
     164
    165165#endif // PLATFORM(MAC)
    166166
     
    346346}
    347347
    348 static void buildQuery(DDScanQueryRef scanQuery, Range* contextRange)
     348static void buildQuery(DDScanQueryRef scanQuery, const SimpleRange& contextRange)
    349349{
    350350    // Once we're over this number of fragments, stop at the first hard break.
     
    445445NSArray *DataDetection::detectContentInRange(RefPtr<Range>& contextRange, DataDetectorTypes types, NSDictionary *context)
    446446{
     447    if (!contextRange)
     448        return nil;
     449
    447450    RetainPtr<DDScannerRef> scanner = adoptCF(softLink_DataDetectorsCore_DDScannerCreate(DDScannerTypeStandard, 0, nullptr));
    448451    RetainPtr<DDScanQueryRef> scanQuery = adoptCF(softLink_DataDetectorsCore_DDScanQueryCreate(NULL));
    449     buildQuery(scanQuery.get(), contextRange.get());
     452    buildQuery(scanQuery.get(), *contextRange);
    450453   
    451454    if (types & DataDetectorTypeLookupSuggestion)
     
    488491
    489492    Vector<Vector<RefPtr<Range>>> allResultRanges;
    490     TextIterator iterator(contextRange.get());
     493    TextIterator iterator(*contextRange);
    491494    CFIndex iteratorCount = 0;
    492495
  • trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm

    r252729 r258525  
    338338       
    339339        fullCharacterRange = makeRange(paragraphStart, paragraphEnd);
    340        
     340        if (!fullCharacterRange)
     341            return { nullptr, nil };
     342
    341343        selectionRange = NSMakeRange(TextIterator::rangeLength(rangeToSelectionStart.get()), TextIterator::rangeLength(makeRange(selectionStart, selectionEnd).get()));
    342344       
     
    358360    NSRange selectedRange = [getRVSelectionClass() revealRangeAtIndex:hitIndex selectedRanges:@[[NSValue valueWithRange:selectionRange]] shouldUpdateSelection:nil];
    359361   
    360     String itemString = plainText(fullCharacterRange.get());
     362    String itemString = plainText(*fullCharacterRange);
    361363    RetainPtr<RVItem> item = adoptNS([allocRVItemInstance() initWithText:itemString selectedRange:selectedRange]);
    362364    NSRange highlightRange = item.get().highlightRange;
  • trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm

    r258250 r258525  
    6262#import "RenderImage.h"
    6363#import "RenderText.h"
    64 #import "SimpleRange.h"
    6564#import "StyleProperties.h"
    6665#import "StyledElement.h"
     
    23972396    RetainPtr<NSMutableDictionary> attrs = adoptNS([[NSMutableDictionary alloc] init]);
    23982397
    2399     for (TextIterator it(&range); !it.atEnd(); it.advance()) {
     2398    for (TextIterator it(range); !it.atEnd(); it.advance()) {
    24002399        SimpleRange currentTextRange = it.range();
    24012400        Node& startContainer = currentTextRange.start.container;
  • trunk/Source/WebCore/page/TextIndicator.cpp

    r258129 r258525  
    4444#include "RenderObject.h"
    4545#include "RenderText.h"
    46 #include "SimpleRange.h"
    4746#include "TextIterator.h"
    4847#include "TextPaintStyle.h"
     
    214213{
    215214    HashSet<Color> colors;
    216     for (TextIterator iterator(&range); !iterator.atEnd(); iterator.advance()) {
     215    for (TextIterator iterator(range); !iterator.atEnd(); iterator.advance()) {
    217216        auto* node = iterator.node();
    218217        if (!is<Text>(node) || !is<RenderText>(node->renderer()))
     
    300299            return false;
    301300    }
    302     return plainTextReplacingNoBreakSpace(&range).stripWhiteSpace().isEmpty();
     301    return plainTextReplacingNoBreakSpace(range).stripWhiteSpace().isEmpty();
    303302}
    304303
  • trunk/Source/WebCore/page/ios/FrameIOS.mm

    r257592 r258525  
    761761
    762762            auto rangeForMarker = Range::create(*document(), createLegacyEditingPosition(node, marker->startOffset()), createLegacyEditingPosition(node, marker->endOffset()));
    763             String visibleTextForMarker = plainText(rangeForMarker.ptr());
     763            String visibleTextForMarker = plainText(rangeForMarker);
    764764            size_t interpretationsCountForCurrentMarker = marker->alternatives().size() + 1;
    765765            for (size_t i = 0; i < interpretationsCount; ++i) {
     
    782782    // Finally, add any text after the last marker.
    783783    auto afterLastMarkerRange = Range::create(*document(), precedingTextStartPosition, createLegacyEditingPosition(root, rootChildCount));
    784     String textAfterLastMarker = plainText(afterLastMarkerRange.ptr());
     784    String textAfterLastMarker = plainText(afterLastMarkerRange);
    785785    if (!textAfterLastMarker.isEmpty()) {
    786786        for (auto& interpretation : interpretations)
  • trunk/Source/WebCore/rendering/HitTestResult.cpp

    r258468 r258525  
    203203        return emptyString();
    204204
     205    auto range = frame->selection().toNormalizedRange();
     206    if (!range)
     207        return emptyString();
     208
    205209    // Look for a character that's not just a separator.
    206     for (TextIterator it(frame->selection().toNormalizedRange().get()); !it.atEnd(); it.advance()) {
     210    for (TextIterator it(*range); !it.atEnd(); it.advance()) {
    207211        int length = it.text().length();
    208212        for (int i = 0; i < length; ++i) {
  • trunk/Source/WebCore/rendering/line/LineLayoutTraversal.h

    r255143 r258525  
    3030#include "LineLayoutTraversalDisplayRunPath.h"
    3131#include "LineLayoutTraversalSimplePath.h"
    32 #include "RenderText.h"
    33 #include <wtf/HashMap.h>
    34 #include <wtf/IteratorRange.h>
    3532#include <wtf/Variant.h>
    36 #include <wtf/text/StringView.h>
    3733
    3834namespace WebCore {
    3935
    4036class RenderLineBreak;
     37class RenderText;
    4138
    4239namespace LineLayoutTraversal {
  • trunk/Source/WebCore/testing/Internals.cpp

    r258475 r258525  
    175175#include "Settings.h"
    176176#include "ShadowRoot.h"
    177 #include "SimpleRange.h"
    178177#include "SourceBuffer.h"
    179178#include "SpellChecker.h"
  • trunk/Source/WebKit/ChangeLog

    r258521 r258525  
     12020-03-15  Darin Adler  <darin@apple.com>
     2
     3        Move most of TextIterator off of live ranges
     4        https://bugs.webkit.org/show_bug.cgi?id=209129
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * WebProcess/InjectedBundle/API/mac/WKDOMTextIterator.mm:
     9        (-[WKDOMTextIterator initWithRange:]): Leave _textIterator as a nullptr
     10        if the passed-in range is nil since we no longer offer a way to create
     11        an empty TextIterator; other clients don't seem to need one.
     12        (-[WKDOMTextIterator advance]): Add a null check.
     13        (-[WKDOMTextIterator atEnd]): Ditto.
     14        (-[WKDOMTextIterator currentRange]): Ditto.
     15        (-[WKDOMTextIterator currentTextPointer]): Ditto.
     16        (-[WKDOMTextIterator currentTextLength]): Ditto.
     17
     18        * WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm: Removed include.
     19
     20        * WebProcess/WebPage/ViewGestureGeometryCollector.cpp:
     21        (WebKit::ViewGestureGeometryCollector::computeTextLegibilityScales): Pass
     22        a reference to a range known not to be null.
     23
     24        * WebProcess/WebPage/WebPage.cpp: Removed an include.
     25
     26        * WebProcess/WebPage/ios/WebPageIOS.mm: Removed a "using naemsapce WebCore".
     27        Added two local functions
     28        (WebKit::plainTextForContext): Added. Helper for just this file where calling
     29        plainTextReplacingNoBreakSpace on a possibly null Range is common.
     30        (WebKit::plainTextForDisplay): Ditto. This one passes true for isDisplayString.
     31        Not entirely clear how carefully we chose which of the two to call, or if there
     32        is sufficient test coverage.
     33        (WebKit::WebPage::platformEditorState const): Use plainTextForContext
     34        and plainTextForDisplay.
     35        (WebKit::WebPage::getSelectionContext): Ditto.
     36        (WebKit::WebPage::getRectsAtSelectionOffsetWithText): Use plainTextForDisplay.
     37        (WebKit::WebPage::requestDictationContext): Use plainTextForContext.
     38        (WebKit::WebPage::replaceSelectedText): Ditto.
     39        (WebKit::WebPage::replaceDictatedText): Ditto.
     40        (WebKit::WebPage::requestAutocorrectionData): Ditto.
     41        (WebKit::WebPage::applyAutocorrectionInternal): Ditto.
     42        (WebKit::WebPage::autocorrectionContext): Ditto.
     43        (WebKit::dataDetectorLinkPositionInformation): Use plainTextForDisplay.
     44        (WebKit::WebPage::requestDocumentEditingContext): Use RetainPtr instead of
     45        autorelease. Use makeBoundaryPoint to convert Position objects to SimpleRange.
     46
    1472020-03-16  Chris Dumez  <cdumez@apple.com>
    248
     
    125171        * WebProcess/cocoa/UserMediaCaptureManager.cpp:
    126172        (WebKit::UserMediaCaptureManager::Source::setShouldApplyRotation):
     173
     174        * WebProcess/WebPage/mac/WebPageMac.mm: Removed an include.
    127175
    1281762020-03-13  Sergio Villar Senin  <svillar@igalia.com>
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKDOMTextIterator.mm

    r258250 r258525  
    2929#import "WKDOMInternals.h"
    3030#import "WKDOMRange.h"
    31 #import <WebCore/SimpleRange.h>
    3231#import <WebCore/TextIterator.h>
    3332
     
    4746        return nil;
    4847
    49     _textIterator = makeUnique<WebCore::TextIterator>(WebKit::toWebCoreRange(range));
     48    if (!range)
     49        return self;
     50
     51    _textIterator = makeUnique<WebCore::TextIterator>(*WebKit::toWebCoreRange(range));
    5052    return self;
    5153}
     
    5355- (void)advance
    5456{
    55     _textIterator->advance();
     57    if (_textIterator)
     58        _textIterator->advance();
    5659    _upconvertedText.shrink(0);
    5760}
     
    5962- (BOOL)atEnd
    6063{
    61     return _textIterator->atEnd();
     64    return _textIterator && _textIterator->atEnd();
    6265}
    6366
    6467- (WKDOMRange *)currentRange
    6568{
    66     return WebKit::toWKDOMRange(createLiveRange(_textIterator->range()).ptr());
     69    return _textIterator ? WebKit::toWKDOMRange(createLiveRange(_textIterator->range()).ptr()) : nil;
    6770}
    6871
     
    7073- (const unichar*)currentTextPointer
    7174{
     75    if (!_textIterator)
     76        return nullptr;
    7277    StringView text = _textIterator->text();
    7378    unsigned length = text.length();
     
    8489- (NSUInteger)currentTextLength
    8590{
    86     return _textIterator->text().length();
     91    return _textIterator ? _textIterator->text().length() : 0;
    8792}
    8893
  • trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm

    r258280 r258525  
    4141#import <WebCore/RenderObject.h>
    4242#import <WebCore/RenderedDocumentMarker.h>
    43 #import <WebCore/SimpleRange.h>
    4443#import <WebCore/TextIterator.h>
    4544#import <WebCore/VisibleUnits.h>
  • trunk/Source/WebKit/WebProcess/WebPage/ViewGestureGeometryCollector.cpp

    r249435 r258525  
    162162    unsigned totalSampledTextLength = 0;
    163163
    164     for (TextIterator documentTextIterator { documentRange.ptr(), TextIteratorEntersTextControls }; !documentTextIterator.atEnd(); documentTextIterator.advance()) {
     164    for (TextIterator documentTextIterator { documentRange.get(), TextIteratorEntersTextControls }; !documentTextIterator.atEnd(); documentTextIterator.advance()) {
    165165        if (++numberOfIterations >= maximumNumberOfTextRunsToConsider)
    166166            break;
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r258421 r258525  
    227227#include <WebCore/ShadowRoot.h>
    228228#include <WebCore/SharedBuffer.h>
    229 #include <WebCore/SimpleRange.h>
    230229#include <WebCore/StyleProperties.h>
    231230#include <WebCore/SubframeLoader.h>
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r258475 r258525  
    125125#import <WebCore/ShadowRoot.h>
    126126#import <WebCore/SharedBuffer.h>
    127 #import <WebCore/SimpleRange.h>
    128127#import <WebCore/StyleProperties.h>
    129128#import <WebCore/TextIndicator.h>
     
    144143
    145144namespace WebKit {
    146 using namespace WebCore;
     145
     146// FIXME: Unclear if callers in this file are correctly choosing which of these two functions to use.
     147
     148static String plainTextForContext(const Range* range)
     149{
     150    if (!range)
     151        return emptyString();
     152    return WebCore::plainTextReplacingNoBreakSpace(*range);
     153}
     154
     155static String plainTextForDisplay(const Range* range)
     156{
     157    if (!range)
     158        return emptyString();
     159    return WebCore::plainTextReplacingNoBreakSpace(*range, TextIteratorDefaultBehavior, true);
     160}
    147161
    148162void WebPage::platformInitialize()
     
    229243            else
    230244                result.lastMarkedRect = result.firstMarkedRect;
    231             result.markedText = plainTextReplacingNoBreakSpace(compositionRange.get());
     245            result.markedText = plainTextForContext(compositionRange.get());
    232246        }
    233247    }
     
    259273        // FIXME: The following check should take into account writing direction.
    260274        postLayoutData.isReplaceAllowed = result.isContentEditable && atBoundaryOfGranularity(selection.start(), WordGranularity, DirectionForward);
    261         postLayoutData.wordAtSelection = plainTextReplacingNoBreakSpace(wordRangeFromPosition(selection.start()).get());
     275        postLayoutData.wordAtSelection = plainTextForContext(wordRangeFromPosition(selection.start()).get());
    262276        if (selection.isContentEditable())
    263277            charactersAroundPosition(selection.start(), postLayoutData.characterAfterSelection, postLayoutData.characterBeforeSelection, postLayoutData.twoCharacterBeforeSelection);
     
    270284            selectedRange->collectSelectionRects(postLayoutData.selectionRects);
    271285            convertSelectionRectsToRootView(view, postLayoutData.selectionRects);
    272             selectedText = plainTextReplacingNoBreakSpace(selectedRange.get(), TextIteratorDefaultBehavior, true);
     286            selectedText = plainTextForDisplay(selectedRange.get());
    273287            postLayoutData.selectedTextLength = selectedText.length();
    274288            const int maxSelectedTextLength = 200;
     
    503517    const int selectionExtendedContextLength = 350;
    504518   
    505     String selectedText = plainTextReplacingNoBreakSpace(frame.selection().selection().toNormalizedRange().get());
    506     String textBefore = plainTextReplacingNoBreakSpace(rangeExpandedByCharactersInDirectionAtWordBoundary(frame.selection().selection().start(), selectionExtendedContextLength, DirectionBackward).get(), TextIteratorDefaultBehavior, true);
    507     String textAfter = plainTextReplacingNoBreakSpace(rangeExpandedByCharactersInDirectionAtWordBoundary(frame.selection().selection().end(), selectionExtendedContextLength, DirectionForward).get(), TextIteratorDefaultBehavior, true);
     519    String selectedText = plainTextForContext(frame.selection().selection().toNormalizedRange().get());
     520    String textBefore = plainTextForDisplay(rangeExpandedByCharactersInDirectionAtWordBoundary(frame.selection().selection().start(), selectionExtendedContextLength, DirectionBackward).get());
     521    String textAfter = plainTextForDisplay(rangeExpandedByCharactersInDirectionAtWordBoundary(frame.selection().selection().end(), selectionExtendedContextLength, DirectionForward).get());
    508522
    509523    send(Messages::WebPageProxy::SelectionContextCallback(selectedText, textBefore, textAfter, callbackID));
     
    20072021    }
    20082022
    2009     if (plainTextReplacingNoBreakSpace(range.ptr(), TextIteratorDefaultBehavior, true) != text) {
     2023    if (plainTextForDisplay(range.ptr()) != text) {
    20102024        // Try to search for a range which is the closest to the position within the selection range that matches the passed in text.
    20112025        if (auto wordRange = rangeNearPositionMatchesText(startPosition, text, selection.toNormalizedRange())) {
     
    22272241    String selectedText;
    22282242    if (frame.selection().isRange())
    2229         selectedText = plainTextReplacingNoBreakSpace(frame.selection().selection().toNormalizedRange().get());
     2243        selectedText = plainTextForContext(frame.selection().selection().toNormalizedRange().get());
    22302244
    22312245    String contextBefore;
     
    22402254        }
    22412255        if (lastPosition.isNotNull() && lastPosition != startPosition)
    2242             contextBefore = plainTextReplacingNoBreakSpace(Range::create(*frame.document(), lastPosition, startPosition).ptr());
     2256            contextBefore = plainTextForContext(Range::create(*frame.document(), lastPosition, startPosition).ptr());
    22432257    }
    22442258
     
    22542268        }
    22552269        if (lastPosition.isNotNull() && lastPosition != endPosition)
    2256             contextAfter = plainTextReplacingNoBreakSpace(Range::create(*frame.document(), endPosition, lastPosition).ptr());
     2270            contextAfter = plainTextForContext(Range::create(*frame.document(), endPosition, lastPosition).ptr());
    22572271    }
    22582272
     
    22642278    Frame& frame = m_page->focusController().focusedOrMainFrame();
    22652279    RefPtr<Range> wordRange = frame.selection().isCaret() ? wordRangeFromPosition(frame.selection().selection().start()) : frame.selection().toNormalizedRange();
    2266     if (plainTextReplacingNoBreakSpace(wordRange.get()) != oldText)
     2280    if (plainTextForContext(wordRange.get()) != oldText)
    22672281        return;
    22682282   
     
    22902304    auto range = Range::create(*frame.document(), position, frame.selection().selection().start());
    22912305
    2292     if (plainTextReplacingNoBreakSpace(range.ptr()) != oldText)
     2306    if (plainTextForContext(range.ptr()) != oldText)
    22932307        return;
    22942308
     
    23152329    }
    23162330
    2317     auto textForRange = plainTextReplacingNoBreakSpace(range.get());
     2331    auto textForRange = plainTextForContext(range.get());
    23182332    const unsigned maxSearchAttempts = 5;
    23192333    for (size_t i = 0;  i < maxSearchAttempts && textForRange != textForAutocorrection; ++i)
     
    23232337            break;
    23242338        range = Range::create(*frame.document(), wordRangeFromPosition(position)->startPosition(), range->endPosition());
    2325         textForRange = plainTextReplacingNoBreakSpace(range.get());
     2339        textForRange = plainTextForContext(range.get());
    23262340    }
    23272341
     
    23862400        VisiblePosition position = frame.selection().selection().start();
    23872401        range = wordRangeFromPosition(position);
    2388         textForRange = plainTextReplacingNoBreakSpace(range.get());
     2402        textForRange = plainTextForContext(range.get());
    23892403       
    23902404        // If 'originalText' is not the same as 'textForRange' we need to move 'range'
     
    23972411                position = startOfDocument(static_cast<Node*>(frame.document()->documentElement()));
    23982412            range = Range::create(*frame.document(), position, frame.selection().selection().start());
    2399             textForRange = plainTextReplacingNoBreakSpace(range.get());
     2413            textForRange = plainTextForContext(range.get());
    24002414            unsigned loopCount = 0;
    24012415            const unsigned maxPositionsAttempts = 10;
     
    24062420                else
    24072421                    range = Range::create(*frame.document(), position, frame.selection().selection().start());
    2408                 textForRange = plainTextReplacingNoBreakSpace(range.get());
     2422                textForRange = plainTextForContext(range.get());
    24092423                loopCount++;
    24102424            }
     
    24222436            return false;
    24232437
    2424         textForRange = plainTextReplacingNoBreakSpace(range.get());
     2438        textForRange = plainTextForContext(range.get());
    24252439    }
    24262440
     
    24582472
    24592473    if (frame.selection().isRange())
    2460         selectedText = plainTextReplacingNoBreakSpace(frame.selection().selection().toNormalizedRange().get());
     2474        selectedText = plainTextForContext(frame.selection().selection().toNormalizedRange().get());
    24612475
    24622476    if (auto compositionRange = frame.editor().compositionRange()) {
     
    24642478        String markedTextBefore;
    24652479        if (range)
    2466             markedTextBefore = plainTextReplacingNoBreakSpace(range.get());
     2480            markedTextBefore = plainTextForContext(range.get());
    24672481        range = Range::create(*frame.document(), endPosition, compositionRange->endPosition());
    24682482        String markedTextAfter;
    24692483        if (range)
    2470             markedTextAfter = plainTextReplacingNoBreakSpace(range.get());
     2484            markedTextAfter = plainTextForContext(range.get());
    24712485        markedText = markedTextBefore + selectedText + markedTextAfter;
    24722486        if (!markedText.isEmpty()) {
     
    24852499                if (previousPosition.isNull())
    24862500                    break;
    2487                 String currentWord = plainTextReplacingNoBreakSpace(Range::create(*frame.document(), previousPosition, currentPosition).ptr());
     2501                String currentWord = plainTextForContext(Range::create(*frame.document(), previousPosition, currentPosition).ptr());
    24882502                totalContextLength += currentWord.length();
    24892503                if (totalContextLength >= maxContextLength)
     
    24922506            }
    24932507            if (currentPosition.isNotNull() && currentPosition != startPosition) {
    2494                 contextBefore = plainTextReplacingNoBreakSpace(Range::create(*frame.document(), currentPosition, startPosition).ptr());
     2508                contextBefore = plainTextForContext(Range::create(*frame.document(), currentPosition, startPosition).ptr());
    24952509                if (atBoundaryOfGranularity(currentPosition, ParagraphGranularity, DirectionBackward))
    24962510                    contextBefore = makeString("\n "_s, contextBefore);
     
    25032517                nextPosition = positionOfNextBoundaryOfGranularity(endPosition, WordGranularity, DirectionForward);
    25042518            if (nextPosition.isNotNull())
    2505                 contextAfter = plainTextReplacingNoBreakSpace(Range::create(*frame.document(), endPosition, nextPosition).ptr());
     2519                contextAfter = plainTextForContext(Range::create(*frame.document(), endPosition, nextPosition).ptr());
    25062520        }
    25072521    }
     
    26322646    auto linkRange = Range::create(element.document());
    26332647    linkRange->selectNodeContents(element);
    2634     info.textBefore = plainTextReplacingNoBreakSpace(rangeExpandedByCharactersInDirectionAtWordBoundary(linkRange->startPosition(),
    2635         dataDetectionExtendedContextLength, DirectionBackward).get(), TextIteratorDefaultBehavior, true);
    2636     info.textAfter = plainTextReplacingNoBreakSpace(rangeExpandedByCharactersInDirectionAtWordBoundary(linkRange->endPosition(),
    2637         dataDetectionExtendedContextLength, DirectionForward).get(), TextIteratorDefaultBehavior, true);
     2648    info.textBefore = plainTextForDisplay(rangeExpandedByCharactersInDirectionAtWordBoundary(linkRange->startPosition(),
     2649        dataDetectionExtendedContextLength, DirectionBackward).get());
     2650    info.textAfter = plainTextForDisplay(rangeExpandedByCharactersInDirectionAtWordBoundary(linkRange->endPosition(),
     2651        dataDetectionExtendedContextLength, DirectionForward).get());
    26382652}
    26392653#endif
     
    41874201    }
    41884202
    4189     auto makeString = [&](VisiblePosition& start, VisiblePosition& end) -> NSAttributedString * {
    4190         if (start.isNull() || end.isNull() || start == end)
     4203    auto makeString = [] (const VisiblePosition& start, const VisiblePosition& end) -> RetainPtr<NSAttributedString> {
     4204        auto startBoundary = makeBoundaryPoint(start.deepEquivalent());
     4205        auto endBoundary = makeBoundaryPoint(end.deepEquivalent());
     4206        if (!startBoundary || !endBoundary || *startBoundary == *endBoundary)
    41914207            return nil;
    41924208        // FIXME: This should return editing-offset-compatible attributed strings if that option is requested.
    4193         return adoptNS([[NSAttributedString alloc] initWithString:plainTextReplacingNoBreakSpace(start.deepEquivalent(), end.deepEquivalent())]).autorelease();
     4209        return adoptNS([[NSAttributedString alloc] initWithString:WebCore::plainTextReplacingNoBreakSpace({ WTFMove(*startBoundary), WTFMove(*endBoundary) })]);
    41944210    };
    41954211
    4196     context.contextBefore = makeString(contextBeforeStart, startOfRangeOfInterestInSelection);
    4197     context.selectedText = makeString(startOfRangeOfInterestInSelection, endOfRangeOfInterestInSelection);
    4198     context.contextAfter = makeString(endOfRangeOfInterestInSelection, contextAfterEnd);
     4212    context.contextBefore = makeString(contextBeforeStart, startOfRangeOfInterestInSelection).get();
     4213    context.selectedText = makeString(startOfRangeOfInterestInSelection, endOfRangeOfInterestInSelection).get();
     4214    context.contextAfter = makeString(endOfRangeOfInterestInSelection, contextAfterEnd).get();
    41994215    if (compositionRange && rangesOverlap(rangeOfInterest.get(), compositionRange.get())) {
    42004216        VisiblePosition compositionStart(compositionRange->startPosition());
    42014217        VisiblePosition compositionEnd(compositionRange->endPosition());
    4202         context.markedText = makeString(compositionStart, compositionEnd);
     4218        context.markedText = makeString(compositionStart, compositionEnd).get();
    42034219        context.selectedRangeInMarkedText.location = distanceBetweenPositions(startOfRangeOfInterestInSelection, compositionStart);
    42044220        context.selectedRangeInMarkedText.length = [context.selectedText.string length];
     
    42274243            context.textRects = characterRectsForRange(*contextRange, 0);
    42284244    } else if (wantsMarkedTextRects && compositionRange) {
    4229         auto compositionStartOffset = plainTextReplacingNoBreakSpace(contextBeforeStart.deepEquivalent(), compositionRange->startPosition()).length();
     4245        auto start = makeBoundaryPoint(contextBeforeStart.deepEquivalent());
     4246        auto end = makeBoundaryPoint(compositionRange->startPosition());
     4247        unsigned compositionStartOffset = 0;
     4248        if (start && end)
     4249            compositionStartOffset = WebCore::plainText(SimpleRange { WTFMove(*start), WTFMove(*end) }).length();
    42304250        context.textRects = characterRectsForRange(*compositionRange, compositionStartOffset);
    42314251    }
  • trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm

    r258129 r258525  
    8787#import <WebCore/RuntimeApplicationChecks.h>
    8888#import <WebCore/ScrollView.h>
    89 #import <WebCore/SimpleRange.h>
    9089#import <WebCore/StyleInheritedData.h>
    9190#import <WebCore/TextIterator.h>
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r258519 r258525  
     12020-03-15  Darin Adler  <darin@apple.com>
     2
     3        Move most of TextIterator off of live ranges
     4        https://bugs.webkit.org/show_bug.cgi?id=209129
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * WebView/WebFrame.mm: Removed an include.
     9
     10        * WebView/WebHTMLView.mm:
     11        (-[WebHTMLView _legacyAttributedStringFrom:offset:to:offset:]):
     12        Add casts to unsigned.
     13
     14        * WebView/WebTextIterator.mm:
     15        (-[WebTextIterator initWithRange:]): Leave _private->_textIterator
     16        as a nullptr if the passed-in range is nil since we no longer offer
     17        a way to create an empty TextIterator; other clients don't seem to
     18        need one.
     19        (-[WebTextIterator advance]): Check _private->_textIterator for null.
     20        (-[WebTextIterator atEnd]): Ditto.
     21        (-[WebTextIterator currentRange]): Ditto.
     22        (-[WebTextIterator currentTextPointer]): Ditto.
     23        (-[WebTextIterator currentTextLength]): Ditto.
     24        (-[WebTextIterator currentNode]): Ditto.
     25        (-[WebTextIterator currentText]): Ditto.
     26
    1272020-03-16  Timothy Horton  <timothy_horton@apple.com>
    228
  • trunk/Source/WebKitLegacy/mac/WebView/WebFrame.mm

    r258339 r258525  
    101101#import <WebCore/ScriptController.h>
    102102#import <WebCore/SecurityOrigin.h>
    103 #import <WebCore/SimpleRange.h>
    104103#import <WebCore/SmartReplace.h>
    105104#import <WebCore/StyleProperties.h>
  • trunk/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm

    r257592 r258525  
    70247024{
    70257025    return attributedStringBetweenStartAndEnd(
    7026         WebCore::Position { core(startContainer), startOffset, WebCore::Position::PositionIsOffsetInAnchor },
    7027         WebCore::Position { core(endContainer), endOffset, WebCore::Position::PositionIsOffsetInAnchor });
     7026        WebCore::Position { core(startContainer), static_cast<unsigned>(startOffset), WebCore::Position::PositionIsOffsetInAnchor },
     7027        WebCore::Position { core(endContainer), static_cast<unsigned>(endOffset), WebCore::Position::PositionIsOffsetInAnchor });
    70287028}
    70297029
  • trunk/Source/WebKitLegacy/mac/WebView/WebTextIterator.mm

    r258250 r258525  
    3131#import <JavaScriptCore/InitializeThreading.h>
    3232#import <WebCore/Range.h>
    33 #import <WebCore/SimpleRange.h>
    3433#import <WebCore/TextIterator.h>
    3534#import <wtf/MainThread.h>
     
    7170   
    7271    _private = [[WebTextIteratorPrivate alloc] init];
    73     _private->_textIterator = makeUnique<WebCore::TextIterator>(core(range));
     72    if (!range)
     73        return self;
     74
     75    _private->_textIterator = makeUnique<WebCore::TextIterator>(*core(range));
    7476    return self;
    7577}
     
    7779- (void)advance
    7880{
    79     _private->_textIterator->advance();
     81    if (_private->_textIterator)
     82        _private->_textIterator->advance();
    8083    _private->_upconvertedText.shrink(0);
    8184}
     
    8386- (BOOL)atEnd
    8487{
    85     return _private->_textIterator->atEnd();
     88    return _private->_textIterator && _private->_textIterator->atEnd();
    8689}
    8790
    8891- (DOMRange *)currentRange
    8992{
     93    if (!_private->_textIterator)
     94        return nil;
    9095    auto& textIterator = *_private->_textIterator;
    9196    if (textIterator.atEnd())
    92         return nullptr;
     97        return nil;
    9398    return kit(createLiveRange(textIterator.range()).ptr());
    9499}
     
    97102- (const unichar*)currentTextPointer
    98103{
     104    if (!_private->_textIterator)
     105        return nullptr;
    99106    StringView text = _private->_textIterator->text();
    100107    unsigned length = text.length();
     
    111118- (NSUInteger)currentTextLength
    112119{
    113     return _private->_textIterator->text().length();
     120    return _private->_textIterator ? _private->_textIterator->text().length() : 0;
    114121}
    115122
     
    120127- (DOMNode *)currentNode
    121128{
    122     return kit(_private->_textIterator->node());
     129    return _private->_textIterator ? kit(_private->_textIterator->node()) : nil;
    123130}
    124131
    125132- (NSString *)currentText
    126133{
    127     return [[_private->_textIterator->text().createNSString().get() retain] autorelease];
     134    return _private->_textIterator ? _private->_textIterator->text().createNSString().autorelease() : @"";
    128135}
    129136
Note: See TracChangeset for help on using the changeset viewer.