Changeset 265044 in webkit


Ignore:
Timestamp:
Jul 29, 2020 9:36:40 AM (4 years ago)
Author:
Darin Adler
Message:

Improve range idioms and other changes to prepare the way for more reduction in live range use
https://bugs.webkit.org/show_bug.cgi?id=214882

Reviewed by Sam Weinig.

Source/WebCore:

  • accessibility/AXObjectCache.cpp:

(WebCore::AccessibilityReplacedText::AccessibilityReplacedText): Call the
VisiblePosition versions of start and end instead of converting to Position
and then back to VisiblePosition.
(WebCore::AXObjectCache::rangeMatchesTextNearRange): Simplify with makeSimpleRange.
(WebCore::AXObjectCache::characterOffsetForPoint): Ditto.

  • accessibility/AccessibilityObject.cpp:

(WebCore::AccessibilityObject::visiblePositionRangeForUnorderedPositions const):
Update idiom for creating VisiblePositionRange since it's just a struct now
without explicit constructors.
(WebCore::AccessibilityObject::positionOfLeftWord const): Ditto.
(WebCore::AccessibilityObject::positionOfRightWord const): Ditto.
(WebCore::AccessibilityObject::leftLineVisiblePositionRange const): Ditto.
(WebCore::AccessibilityObject::rightLineVisiblePositionRange const): Ditto.
(WebCore::AccessibilityObject::sentenceForPosition const): Ditto.
(WebCore::AccessibilityObject::paragraphForPosition const): Ditto.
(WebCore::AccessibilityObject::styleRangeForPosition const): Ditto.
(WebCore::AccessibilityObject::visiblePositionRangeForRange const): Ditto.
(WebCore::AccessibilityObject::lineRangeForPosition const): Ditto.
(WebCore::AccessibilityObject::stringForVisiblePositionRange): Ditto.
(WebCore::AccessibilityObject::lengthForVisiblePositionRange const): Ditto.
(WebCore::AccessibilityObject::nextSentenceEndPosition const): Ditto.
(WebCore::AccessibilityObject::previousSentenceStartPosition const): Ditto.

  • accessibility/AccessibilityObjectInterface.h: Moved VisiblePositionRange

to VisiblePosition.h for wider use. Also removed constructors.

  • accessibility/AccessibilityRenderObject.cpp:

(WebCore::AccessibilityRenderObject::textUnderElement const): Simplify with
makeSimpleRange.
(WebCore::AccessibilityRenderObject::linkClickPoint): Ditto.
(WebCore::AccessibilityRenderObject::clickPoint): Ditto.
(WebCore::AccessibilityRenderObject::visiblePositionRange const): Updated
for removal of VisiblePositionRange constructor.
(WebCore::AccessibilityRenderObject::visiblePositionRangeForLine const):
Remove unnecessary explicit conversion to VisiblePositionRange.

  • accessibility/mac/WebAccessibilityObjectWrapperMac.mm:

(visiblePositionRangeForTextMarkerRange): Added, replacing separate functions
for start and end.
(-[WebAccessibilityObjectWrapper visiblePositionRangeForTextMarkerRange:]):
Simplify using visiblePositionRangeForTextMarkerRange.

  • dom/Document.cpp: Added include of "Range.h", may not be needed right now,

but highly likely to be needed after future live range work.

  • dom/Node.cpp: Removed include of "Range.h".
  • dom/Position.h: Added PositionRange. This will be a more efficient

alternative to SimpleRange that can avoid computing node offets for positions
before and after anchor nodes in some cases. Not used yet.

  • dom/RadioButtonGroups.cpp: Removed include of "Range.h".
  • dom/Range.h: Export makeSimpleRange overload now used outside WebCore.
  • dom/SimpleRange.cpp:

(WebCore::makeSimpleRange): Added overloads for ranges that consist of just
a single boundary point, so the argument does not have to be passed twice.
(WebCore::commonInclusiveAncestor): Added overload so caller can just pass
a simple range rather than passing two boundary point container nodes.

  • dom/SimpleRange.h: Added makeSimpleRange overloads that take one or more

argument that can be passed to makeBoundaryPoint or actual boundary points.

  • dom/StaticRange.cpp: Removed include of "Range.h".
  • editing/AlternativeTextController.cpp:

(WebCore::AlternativeTextController::markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand):
Simplify with makeSimpleRange.
(WebCore::AlternativeTextController::processMarkersOnTextToBeReplacedByResult):
Ditto.

  • editing/ApplyStyleCommand.cpp:

(WebCore::ApplyStyleCommand::applyBlockStyle): Ditto.

  • editing/CompositeEditCommand.cpp:

(WebCore::stringForVisiblePositionIndexRange): Updated for removal of
VisiblePositionRange constructor; also use move to reduce reference count
churn a tiny bit.
(WebCore::CompositeEditCommand::moveParagraphs): Simplify with makeSimpleRange.

  • editing/DeleteSelectionCommand.cpp: Added include of "Range.h", may not be needed now,

but highly likely to be needed after future live range work.

  • editing/Editing.cpp:

(WebCore::indexForVisiblePosition): Simplify using makeSimpleRange and
makeBoundaryPointBeforeNodeContents.

  • editing/Editor.cpp:

(WebCore::Editor::selectedText const): Simplify using VisibleSelection::firstRange.
(WebCore::extendSelection): Simplify using makeSimpleRange.
(WebCore::Editor::contextRangeForCandidateRequest const): Ditto.
(WebCore::Editor::adjustedSelectionRange): Simplify with the new overload
of commonInclusiveAncestor.

  • editing/FrameSelection.cpp:

(WebCore::FrameSelection::wordOffsetInRange const): Deleted. Moved the code
into the iOS-specific part of WebKitLegacy WebFrame.
(WebCore::FrameSelection::spaceFollowsWordInRange const): Deleted. Moved the
code into the iOS-specific part of WebKitLegacy WebFrame.
(WebCore::FrameSelection::selectionAtSentenceStart const): Merged in with
actualSelectionAtSentenceStart.
(WebCore::FrameSelection::actualSelectionAtSentenceStart const): Deleted.

  • editing/FrameSelection.h: Updated for the above deletion.
  • editing/TextCheckingHelper.cpp:

(WebCore::TextCheckingParagraph::offsetTo const): Simplify with makeSimpleRange.

  • editing/TextManipulationController.cpp:

(WebCore::ParagraphContentIterator::ParagraphContentIterator): Simplify with
makeSimpleRange.

  • editing/TypingCommand.cpp:

(WebCore::TypingCommand::postTextStateChangeNotificationForDeletion): Pass
visibleStart/End instead of converting to Position and back to VisiblePosition.

  • editing/VisiblePosition.cpp:

(WebCore::makeSimpleRange): Added. Converts a VisiblePositionRange into
a SimpleRange.

  • editing/VisiblePosition.h: Moved VisiblePositionRange here.
  • editing/VisibleSelection.cpp:

(WebCore::VisibleSelection::firstRange const): Simplify using makeSimpleRange.
(WebCore::VisibleSelection::toNormalizedRange const): Ditto.
(WebCore::makeSearchRange): Deleted. This was confusingly named given that
it was only used in appendTrailingWhitespace.
(WebCore::VisibleSelection::appendTrailingWhitespace): Merged makeSearchRange
in here and simplified using makeSimpleRange.

  • editing/VisibleSelection.h: Added conversion to VisiblePositionRange.

Previously this was implemented as a constructor for VisiblePositionRange,
but that was a layering inversion since this is built on top of VisiblePosition.

  • editing/VisibleUnits.cpp:

(WebCore::distanceBetweenPositions): Simplified using makeSimpleRange.
(WebCore::charactersAroundPosition): Ditto.
(WebCore::wordRangeFromPosition): Removed an unhelpful comment.
(WebCore::closestWordBoundaryForPosition): Ditto.

  • editing/cocoa/DataDetection.mm:

(WebCore::detectItem): Simplify using makeSimpleRange.
(WebCore::searchForLinkRemovingExistingDDLinks): Removed out argument
about modifying the DOM. This was used to work around a problem caused by
using live ranges. The problem no longer exists because the code does not
use live ranges any more.
(WebCore::DataDetection::detectContentInRange): Removed the workaround.

  • editing/cocoa/DictionaryLookup.mm:

(WebCore::DictionaryLookup::rangeForSelection): Simplify using makeSimpleRange.
(WebCore::DictionaryLookup::rangeAtHitTestResult): Ditto.

  • editing/cocoa/WebContentReaderCocoa.mm: Added include of "Range.h", may

not be needed now, but highly likely to be needed after future live range work.

  • editing/ios/DictationCommandIOS.cpp: Removed include of "Range.h".
  • editing/mac/DictionaryLookupLegacy.mm:

(WebCore::DictionaryLookup::rangeForSelection): Simplify using makeSimpleRange.
(WebCore::DictionaryLookup::rangeAtHitTestResult): Ditto.

  • editing/mac/EditorMac.mm: Removed include of "Range.h".
  • editing/markup.cpp:

(WebCore::StyledMarkupAccumulator::renderedTextRespectingRange): Simplify
using makeSimpleRange.

  • editing/win/EditorWin.cpp: Added include of "Range.h", may not be needed now,

but highly likely to be needed after future live range work.

  • html/shadow/mac/ImageControlsButtonElementMac.cpp: Removed include of "Range.h".
  • page/DOMSelection.cpp:

(WebCore::DOMSelection::addRange): Call setSelection instead of moveTo.
No need to have two functions that do the same thing.

  • page/EventHandler.cpp:

(WebCore::textDistance): Simplify using makeSimpleRange.

  • page/Frame.cpp:

(WebCore::Frame::rangeForPoint): Simplify using makeSimpleRange.

  • page/TextIndicator.cpp:

(WebCore::estimatedBackgroundColorForRange): Simplify using the
commonInclusiveAncestor overload that takes a range.
(WebCore::initializeIndicator): Ditto.

Source/WebKit:

  • WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp:

(WKBundleNodeHandleGetRenderRect): Emptied out this unused function and added
ASSERT_NOT_REACHED. Later, we can delete this once we deal with any link-time
dependencies. I believe Safari may link with this but never calls it.
(WKBundleNodeHandleCopyVisibleRange): Ditto.
(WKBundleNodeHandleSetHTMLInputElementSpellcheckEnabled): Ditto.
(WKBundleNodeHandleGetHTMLInputElementAutoFilled): Ditto.
(WKBundleNodeHandleGetHTMLInputElementAutoFillButtonEnabled): Ditto.
(WKBundleNodeHandleGetHTMLInputElementAutoFillAvailable): Ditto.
(WKBundleNodeHandleGetHTMLInputElementAutoFillButtonBounds): Ditto.
(WKBundleNodeHandleCopyHTMLTableCellElementCellAbove): Ditto.
(WKBundleNodeHandleCopyHTMLFrameElementContentFrame): Ditto.
(WKBundleNodeHandleGetHTMLInputElementAutofilled): Ditto.
(WKBundleNodeHandleSetHTMLInputElementAutofilled): Ditto.
(WKBundleNodeHandleSetHTMLInputElementAutoFillButtonEnabled): Ditto.

  • WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm:

(WebKit::TextCheckingControllerProxy::annotatedSubstringBetweenPositions):
Simplify with makeSimpleRange.

  • WebProcess/WebPage/glib/WebPageGLib.cpp: Added include of "Range.h",

may not be needed right now, but highly likely to be needed after
future live range work.

  • WebProcess/WebPage/ios/WebPageIOS.mm: Ditto.

(WebKit::WebPage::selectWithGesture): Simplify with makeSimpleRange.
(WebKit::WebPage::requestDocumentEditingContext): Ditto.

  • WebProcess/WebPage/mac/WebPageMac.mm:

(WebKit::WebPage::attributedSubstringForCharacterRangeAsync):
Use auto for range to prepare for possible change of type from live
range to SimpleRange.

Source/WebKitLegacy:

  • WebKitLegacy.xcodeproj/project.pbxproj: Removed singly-building

DOMUIKitExtensions.mm, which also is built in a unified source file.
We don't need to build it twice.

Source/WebKitLegacy/mac:

  • WebCoreSupport/WebEditorClient.mm:

(insertionPointFromCurrentSelection): Simplify with makeSimpleRange.
(WebEditorClient::requestCandidatesForSelection): Ditto.

  • WebView/WebFrame.mm:

(-[WebFrame _convertToDOMRange:rangeIsRelativeTo:]): Get rid of
unnecessary construction of a range just to get an end point.
(-[WebFrame wordOffsetInRange:]): Moved logic here from VisibleSelection.
(-[WebFrame spaceFollowsWordInRange:]): Ditto.

Location:
trunk/Source
Files:
55 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r265039 r265044  
     12020-07-29  Darin Adler  <darin@apple.com>
     2
     3        Improve range idioms and other changes to prepare the way for more reduction in live range use
     4        https://bugs.webkit.org/show_bug.cgi?id=214882
     5
     6        Reviewed by Sam Weinig.
     7
     8        * accessibility/AXObjectCache.cpp:
     9        (WebCore::AccessibilityReplacedText::AccessibilityReplacedText): Call the
     10        VisiblePosition versions of start and end instead of converting to Position
     11        and then back to VisiblePosition.
     12        (WebCore::AXObjectCache::rangeMatchesTextNearRange): Simplify with makeSimpleRange.
     13        (WebCore::AXObjectCache::characterOffsetForPoint): Ditto.
     14
     15        * accessibility/AccessibilityObject.cpp:
     16        (WebCore::AccessibilityObject::visiblePositionRangeForUnorderedPositions const):
     17        Update idiom for creating VisiblePositionRange since it's just a struct now
     18        without explicit constructors.
     19        (WebCore::AccessibilityObject::positionOfLeftWord const): Ditto.
     20        (WebCore::AccessibilityObject::positionOfRightWord const): Ditto.
     21        (WebCore::AccessibilityObject::leftLineVisiblePositionRange const): Ditto.
     22        (WebCore::AccessibilityObject::rightLineVisiblePositionRange const): Ditto.
     23        (WebCore::AccessibilityObject::sentenceForPosition const): Ditto.
     24        (WebCore::AccessibilityObject::paragraphForPosition const): Ditto.
     25        (WebCore::AccessibilityObject::styleRangeForPosition const): Ditto.
     26        (WebCore::AccessibilityObject::visiblePositionRangeForRange const): Ditto.
     27        (WebCore::AccessibilityObject::lineRangeForPosition const): Ditto.
     28        (WebCore::AccessibilityObject::stringForVisiblePositionRange): Ditto.
     29        (WebCore::AccessibilityObject::lengthForVisiblePositionRange const): Ditto.
     30        (WebCore::AccessibilityObject::nextSentenceEndPosition const): Ditto.
     31        (WebCore::AccessibilityObject::previousSentenceStartPosition const): Ditto.
     32
     33        * accessibility/AccessibilityObjectInterface.h: Moved VisiblePositionRange
     34        to VisiblePosition.h for wider use. Also removed constructors.
     35
     36        * accessibility/AccessibilityRenderObject.cpp:
     37        (WebCore::AccessibilityRenderObject::textUnderElement const): Simplify with
     38        makeSimpleRange.
     39        (WebCore::AccessibilityRenderObject::linkClickPoint): Ditto.
     40        (WebCore::AccessibilityRenderObject::clickPoint): Ditto.
     41        (WebCore::AccessibilityRenderObject::visiblePositionRange const): Updated
     42        for removal of VisiblePositionRange constructor.
     43        (WebCore::AccessibilityRenderObject::visiblePositionRangeForLine const):
     44        Remove unnecessary explicit conversion to VisiblePositionRange.
     45
     46        * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
     47        (visiblePositionRangeForTextMarkerRange): Added, replacing separate functions
     48        for start and end.
     49        (-[WebAccessibilityObjectWrapper visiblePositionRangeForTextMarkerRange:]):
     50        Simplify using visiblePositionRangeForTextMarkerRange.
     51
     52        * dom/Document.cpp: Added include of "Range.h", may not be needed right now,
     53        but highly likely to be needed after future live range work.
     54        * dom/Node.cpp: Removed include of "Range.h".
     55
     56        * dom/Position.h: Added PositionRange. This will be a more efficient
     57        alternative to SimpleRange that can avoid computing node offets for positions
     58        before and after anchor nodes in some cases. Not used yet.
     59
     60        * dom/RadioButtonGroups.cpp: Removed include of "Range.h".
     61
     62        * dom/Range.h: Export makeSimpleRange overload now used outside WebCore.
     63
     64        * dom/SimpleRange.cpp:
     65        (WebCore::makeSimpleRange): Added overloads for ranges that consist of just
     66        a single boundary point, so the argument does not have to be passed twice.
     67        (WebCore::commonInclusiveAncestor): Added overload so caller can just pass
     68        a simple range rather than passing two boundary point container nodes.
     69
     70        * dom/SimpleRange.h: Added makeSimpleRange overloads that take one or more
     71        argument that can be passed to makeBoundaryPoint or actual boundary points.
     72
     73        * dom/StaticRange.cpp: Removed include of "Range.h".
     74
     75        * editing/AlternativeTextController.cpp:
     76        (WebCore::AlternativeTextController::markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand):
     77        Simplify with makeSimpleRange.
     78        (WebCore::AlternativeTextController::processMarkersOnTextToBeReplacedByResult):
     79        Ditto.
     80        * editing/ApplyStyleCommand.cpp:
     81        (WebCore::ApplyStyleCommand::applyBlockStyle): Ditto.
     82
     83        * editing/CompositeEditCommand.cpp:
     84        (WebCore::stringForVisiblePositionIndexRange): Updated for removal of
     85        VisiblePositionRange constructor; also use move to reduce reference count
     86        churn a tiny bit.
     87        (WebCore::CompositeEditCommand::moveParagraphs): Simplify with makeSimpleRange.
     88
     89        * editing/DeleteSelectionCommand.cpp: Added include of "Range.h", may not be needed now,
     90        but highly likely to be needed after future live range work.
     91
     92        * editing/Editing.cpp:
     93        (WebCore::indexForVisiblePosition): Simplify using makeSimpleRange and
     94        makeBoundaryPointBeforeNodeContents.
     95
     96        * editing/Editor.cpp:
     97        (WebCore::Editor::selectedText const): Simplify using VisibleSelection::firstRange.
     98        (WebCore::extendSelection): Simplify using makeSimpleRange.
     99        (WebCore::Editor::contextRangeForCandidateRequest const): Ditto.
     100        (WebCore::Editor::adjustedSelectionRange): Simplify with the new overload
     101        of commonInclusiveAncestor.
     102
     103        * editing/FrameSelection.cpp:
     104        (WebCore::FrameSelection::wordOffsetInRange const): Deleted. Moved the code
     105        into the iOS-specific part of WebKitLegacy WebFrame.
     106        (WebCore::FrameSelection::spaceFollowsWordInRange const): Deleted. Moved the
     107        code into the iOS-specific part of WebKitLegacy WebFrame.
     108        (WebCore::FrameSelection::selectionAtSentenceStart const): Merged in with
     109        actualSelectionAtSentenceStart.
     110        (WebCore::FrameSelection::actualSelectionAtSentenceStart const): Deleted.
     111        * editing/FrameSelection.h: Updated for the above deletion.
     112
     113        * editing/TextCheckingHelper.cpp:
     114        (WebCore::TextCheckingParagraph::offsetTo const): Simplify with makeSimpleRange.
     115
     116        * editing/TextManipulationController.cpp:
     117        (WebCore::ParagraphContentIterator::ParagraphContentIterator): Simplify with
     118        makeSimpleRange.
     119
     120        * editing/TypingCommand.cpp:
     121        (WebCore::TypingCommand::postTextStateChangeNotificationForDeletion): Pass
     122        visibleStart/End instead of converting to Position and back to VisiblePosition.
     123
     124        * editing/VisiblePosition.cpp:
     125        (WebCore::makeSimpleRange): Added. Converts a VisiblePositionRange into
     126        a SimpleRange.
     127        * editing/VisiblePosition.h: Moved VisiblePositionRange here.
     128
     129        * editing/VisibleSelection.cpp:
     130        (WebCore::VisibleSelection::firstRange const): Simplify using makeSimpleRange.
     131        (WebCore::VisibleSelection::toNormalizedRange const): Ditto.
     132        (WebCore::makeSearchRange): Deleted. This was confusingly named given that
     133        it was only used in appendTrailingWhitespace.
     134        (WebCore::VisibleSelection::appendTrailingWhitespace): Merged makeSearchRange
     135        in here and simplified using makeSimpleRange.
     136
     137        * editing/VisibleSelection.h: Added conversion to VisiblePositionRange.
     138        Previously this was implemented as a constructor for VisiblePositionRange,
     139        but that was a layering inversion since this is built on top of VisiblePosition.
     140
     141        * editing/VisibleUnits.cpp:
     142        (WebCore::distanceBetweenPositions): Simplified using makeSimpleRange.
     143        (WebCore::charactersAroundPosition): Ditto.
     144        (WebCore::wordRangeFromPosition): Removed an unhelpful comment.
     145        (WebCore::closestWordBoundaryForPosition): Ditto.
     146
     147        * editing/cocoa/DataDetection.mm:
     148        (WebCore::detectItem): Simplify using makeSimpleRange.
     149        (WebCore::searchForLinkRemovingExistingDDLinks): Removed out argument
     150        about modifying the DOM. This was used to work around a problem caused by
     151        using live ranges. The problem no longer exists because the code does not
     152        use live ranges any more.
     153        (WebCore::DataDetection::detectContentInRange): Removed the workaround.
     154
     155        * editing/cocoa/DictionaryLookup.mm:
     156        (WebCore::DictionaryLookup::rangeForSelection): Simplify using makeSimpleRange.
     157        (WebCore::DictionaryLookup::rangeAtHitTestResult): Ditto.
     158
     159        * editing/cocoa/WebContentReaderCocoa.mm: Added include of "Range.h", may
     160        not be needed now, but highly likely to be needed after future live range work.
     161
     162        * editing/ios/DictationCommandIOS.cpp: Removed include of "Range.h".
     163
     164        * editing/mac/DictionaryLookupLegacy.mm:
     165        (WebCore::DictionaryLookup::rangeForSelection): Simplify using makeSimpleRange.
     166        (WebCore::DictionaryLookup::rangeAtHitTestResult): Ditto.
     167
     168        * editing/mac/EditorMac.mm: Removed include of "Range.h".
     169
     170        * editing/markup.cpp:
     171        (WebCore::StyledMarkupAccumulator::renderedTextRespectingRange): Simplify
     172        using makeSimpleRange.
     173
     174        * editing/win/EditorWin.cpp: Added include of "Range.h", may not be needed now,
     175        but highly likely to be needed after future live range work.
     176
     177        * html/shadow/mac/ImageControlsButtonElementMac.cpp: Removed include of "Range.h".
     178
     179        * page/DOMSelection.cpp:
     180        (WebCore::DOMSelection::addRange): Call setSelection instead of moveTo.
     181        No need to have two functions that do the same thing.
     182
     183        * page/EventHandler.cpp:
     184        (WebCore::textDistance): Simplify using makeSimpleRange.
     185
     186        * page/Frame.cpp:
     187        (WebCore::Frame::rangeForPoint): Simplify using makeSimpleRange.
     188
     189        * page/TextIndicator.cpp:
     190        (WebCore::estimatedBackgroundColorForRange): Simplify using the
     191        commonInclusiveAncestor overload that takes a range.
     192        (WebCore::initializeIndicator): Ditto.
     193
    11942020-07-29  Adrian Perez de Castro  <aperez@igalia.com>
    2195
  • trunk/Source/WebCore/accessibility/AXObjectCache.cpp

    r264784 r265044  
    8484#include "MathMLElement.h"
    8585#include "Page.h"
     86#include "Range.h"
    8687#include "RenderAttachment.h"
    8788#include "RenderLineBreak.h"
     
    167168{
    168169    if (AXObjectCache::accessibilityEnabled()) {
    169         m_replacedRange.startIndex.value = indexForVisiblePosition(selection.start(), m_replacedRange.startIndex.scope);
     170        m_replacedRange.startIndex.value = indexForVisiblePosition(selection.visibleStart(), m_replacedRange.startIndex.scope);
    170171        if (selection.isRange()) {
    171172            m_replacedText = AccessibilityObject::stringForVisiblePositionRange(selection);
    172             m_replacedRange.endIndex.value = indexForVisiblePosition(selection.end(), m_replacedRange.endIndex.scope);
     173            m_replacedRange.endIndex.value = indexForVisiblePosition(selection.visibleEnd(), m_replacedRange.endIndex.scope);
    173174        } else
    174175            m_replacedRange.endIndex = m_replacedRange.startIndex;
     
    19861987        endPosition = lastPositionInOrAfterNode(originalRange.end.container.ptr());
    19871988
    1988     auto searchRange = SimpleRange { *makeBoundaryPoint(startPosition), *makeBoundaryPoint(endPosition) };
    1989     if (searchRange.collapsed())
     1989    auto searchRange = makeSimpleRange(startPosition, endPosition);
     1990    if (!searchRange || searchRange->collapsed())
    19901991        return WTF::nullopt;
    19911992
    1992     auto targetOffset = characterCount({ searchRange.start, originalRange.start }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
    1993     return findClosestPlainText(searchRange, matchText, { }, targetOffset);
     1993    auto targetOffset = characterCount({ searchRange->start, originalRange.start }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
     1994    return findClosestPlainText(*searchRange, matchText, { }, targetOffset);
    19941995}
    19951996
     
    28812882    if (!object)
    28822883        return { };
    2883     auto boundary = makeBoundaryPoint(object->visiblePositionForPoint(point));
    2884     if (!boundary)
     2884    auto range = makeSimpleRange(object->visiblePositionForPoint(point));
     2885    if (!range)
    28852886        return { };
    2886     return startOrEndCharacterOffsetForRange({ *boundary, *boundary }, true);
     2887    return startOrEndCharacterOffsetForRange(*range, true);
    28872888}
    28882889
    28892890CharacterOffset AXObjectCache::characterOffsetForPoint(const IntPoint& point)
    28902891{
    2891     auto boundary = m_document.caretPositionFromPoint(point);
    2892     if (!boundary)
     2892    auto range = makeSimpleRange(m_document.caretPositionFromPoint(point));
     2893    if (!range)
    28932894        return { };
    2894     return startOrEndCharacterOffsetForRange({ *boundary, *boundary }, true);
     2895    return startOrEndCharacterOffsetForRange(*range, true);
    28952896}
    28962897
  • trunk/Source/WebCore/accessibility/AccessibilityObject.cpp

    r264692 r265044  
    6464#include "NodeTraversal.h"
    6565#include "Page.h"
     66#include "Range.h"
    6667#include "RenderImage.h"
    6768#include "RenderInline.h"
     
    981982    }
    982983
    983     return VisiblePositionRange(startPos, endPos);
     984    return { startPos, endPos };
    984985}
    985986
    986987VisiblePositionRange AccessibilityObject::positionOfLeftWord(const VisiblePosition& visiblePos) const
    987988{
    988     VisiblePosition startPosition = startOfWord(visiblePos, LeftWordIfOnBoundary);
    989     VisiblePosition endPosition = endOfWord(startPosition);
    990     return VisiblePositionRange(startPosition, endPosition);
     989    auto start = startOfWord(visiblePos, LeftWordIfOnBoundary);
     990    return { start, endOfWord(start) };
    991991}
    992992
    993993VisiblePositionRange AccessibilityObject::positionOfRightWord(const VisiblePosition& visiblePos) const
    994994{
    995     VisiblePosition startPosition = startOfWord(visiblePos, RightWordIfOnBoundary);
    996     VisiblePosition endPosition = endOfWord(startPosition);
    997     return VisiblePositionRange(startPosition, endPosition);
     995    auto start = startOfWord(visiblePos, RightWordIfOnBoundary);
     996    return { start, endOfWord(start) };
    998997}
    999998
     
    10451044        startPosition = updateAXLineStartForVisiblePosition(startPosition);
    10461045
    1047     VisiblePosition endPosition = endOfLine(prevVisiblePos);
    1048     return VisiblePositionRange(startPosition, endPosition);
     1046    return { startPosition, endOfLine(prevVisiblePos) };
    10491047}
    10501048
     
    10791077    }
    10801078
    1081     return VisiblePositionRange(startPosition, endPosition);
     1079    return { startPosition, endPosition };
    10821080}
    10831081
     
    10861084    // FIXME: FO 2 IMPLEMENT (currently returns incorrect answer)
    10871085    // Related? <rdar://problem/3927736> Text selection broken in 8A336
    1088     VisiblePosition startPosition = startOfSentence(visiblePos);
    1089     VisiblePosition endPosition = endOfSentence(startPosition);
    1090     return VisiblePositionRange(startPosition, endPosition);
     1086    auto startPosition = startOfSentence(visiblePos);
     1087    return { startPosition, endOfSentence(startPosition) };
    10911088}
    10921089
    10931090VisiblePositionRange AccessibilityObject::paragraphForPosition(const VisiblePosition& visiblePos) const
    10941091{
    1095     VisiblePosition startPosition = startOfParagraph(visiblePos);
    1096     VisiblePosition endPosition = endOfParagraph(startPosition);
    1097     return VisiblePositionRange(startPosition, endPosition);
     1092    auto startPosition = startOfParagraph(visiblePos);
     1093    return { startPosition, endOfParagraph(startPosition) };
    10981094}
    10991095
     
    11471143{
    11481144    if (visiblePos.isNull())
    1149         return VisiblePositionRange();
    1150 
    1151     return VisiblePositionRange(startOfStyleRange(visiblePos), endOfStyleRange(visiblePos));
     1145        return { };
     1146
     1147    return { startOfStyleRange(visiblePos), endOfStyleRange(visiblePos) };
    11521148}
    11531149
     
    11571153    unsigned textLength = getLengthForTextRange();
    11581154    if (range.start + range.length > textLength)
    1159         return VisiblePositionRange();
    1160 
    1161     VisiblePosition startPosition = visiblePositionForIndex(range.start);
     1155        return { };
     1156
     1157    auto startPosition = visiblePositionForIndex(range.start);
    11621158    startPosition.setAffinity(DOWNSTREAM);
    1163     VisiblePosition endPosition = visiblePositionForIndex(range.start + range.length);
    1164     return VisiblePositionRange(startPosition, endPosition);
     1159    return { startPosition, visiblePositionForIndex(range.start + range.length) };
    11651160}
    11661161
     
    11841179VisiblePositionRange AccessibilityObject::lineRangeForPosition(const VisiblePosition& visiblePosition) const
    11851180{
    1186     VisiblePosition startPosition = startOfLine(visiblePosition);
    1187     VisiblePosition endPosition = endOfLine(visiblePosition);
    1188     return VisiblePositionRange(startPosition, endPosition);
     1181    return { startOfLine(visiblePosition), endOfLine(visiblePosition) };
    11891182}
    11901183
     
    12721265String AccessibilityObject::stringForVisiblePositionRange(const VisiblePositionRange& visiblePositionRange)
    12731266{
    1274     auto start = makeBoundaryPoint(visiblePositionRange.start);
    1275     if (!start)
     1267    auto range = makeSimpleRange(visiblePositionRange);
     1268    if (!range)
    12761269        return { };
    1277     auto end = makeBoundaryPoint(visiblePositionRange.end);
    1278     if (!end)
    1279         return { };
    12801270
    12811271    StringBuilder builder;
    1282     for (TextIterator it({ *start, *end }); !it.atEnd(); it.advance()) {
     1272    for (TextIterator it(*range); !it.atEnd(); it.advance()) {
    12831273        // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX)
    12841274        if (it.text().length()) {
     
    12991289    // FIXME: Multi-byte support
    13001290
    1301     auto start = makeBoundaryPoint(visiblePositionRange.start);
    1302     if (!start)
    1303         return -1; // FIXME: Why not return 0?
    1304     auto end = makeBoundaryPoint(visiblePositionRange.end);
    1305     if (!end)
     1291    auto range = makeSimpleRange(visiblePositionRange);
     1292    if (!range)
    13061293        return -1; // FIXME: Why not return 0?
    13071294
    13081295    // FIXME: Use characterCount instead of writing our own loop?
    13091296    int length = 0;
    1310     for (TextIterator it({ *start, *end }); !it.atEnd(); it.advance()) {
     1297    for (TextIterator it(*range); !it.atEnd(); it.advance()) {
    13111298        // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX)
    13121299        if (it.text().length())
     
    14321419    // Make sure we move off of a sentence end.
    14331420    auto nextPosition = position.next();
    1434     auto start = makeBoundaryPoint(startOfLine(nextPosition));
    1435     if (!start)
    1436         return { };
    1437     auto end = makeBoundaryPoint(endOfLine(nextPosition));
    1438     if (!end)
     1421    auto range = makeSimpleRange(startOfLine(nextPosition), endOfLine(nextPosition));
     1422    if (!range)
    14391423        return { };
    14401424
    14411425    // An empty line is considered a sentence. If it's skipped, then the sentence parser will not
    14421426    // see this empty line. Instead, return the end position of the empty line.
    1443     return hasAnyPlainText({ *start, *end }) ? endOfSentence(nextPosition) : nextPosition;
     1427    return hasAnyPlainText(*range) ? endOfSentence(nextPosition) : nextPosition;
    14441428}
    14451429
     
    14511435    // Make sure we move off of a sentence start.
    14521436    auto previousPosition = position.previous();
    1453     auto start = makeBoundaryPoint(startOfLine(previousPosition));
    1454     if (!start)
     1437    auto range = makeSimpleRange(startOfLine(previousPosition), endOfLine(previousPosition));
     1438    if (!range)
    14551439        return { };
    1456     auto end = makeBoundaryPoint(endOfLine(previousPosition));
    1457     if (!end)
    1458         return { };
    14591440
    14601441    // Treat empty line as a separate sentence.
    1461     return hasAnyPlainText({ *start, *end }) ? startOfSentence(previousPosition) : previousPosition;
     1442    return hasAnyPlainText(*range) ? startOfSentence(previousPosition) : previousPosition;
    14621443}
    14631444
  • trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h

    r264284 r265044  
    431431};
    432432
    433 struct VisiblePositionRange {
    434     VisiblePosition start;
    435     VisiblePosition end;
    436 
    437     VisiblePositionRange() = default;
    438     VisiblePositionRange(const VisiblePosition& s, const VisiblePosition& e)
    439         : start(s)
    440         , end(e)
    441     { }
    442 
    443     VisiblePositionRange(const VisibleSelection& selection)
    444         : start(selection.start())
    445         , end(selection.end())
    446     { }
    447 
    448     bool isNull() const { return start.isNull() || end.isNull(); }
    449 };
    450 
    451433enum class AccessibilityMathScriptObjectType { Subscript, Superscript };
    452434enum class AccessibilityMathMultiscriptObjectType { PreSubscript, PreSuperscript, PostSubscript, PostSuperscript };
  • trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp

    r264271 r265044  
    650650                // We define the start and end positions for the range as the ones right before and after
    651651                // the first and the last nodes in the DOM tree that is wrapped inside the anonymous block.
    652                 Node* firstNodeInBlock = firstChildRenderer->node();
    653                 Position startPosition = positionInParentBeforeNode(firstNodeInBlock);
    654                 Position endPosition = positionInParentAfterNode(lastChildRenderer->node());
    655 
    656                 nodeDocument = &firstNodeInBlock->document();
    657                 textRange = { { *makeBoundaryPoint(startPosition), *makeBoundaryPoint(endPosition) } };
     652                auto& firstNodeInBlock = *firstChildRenderer->node();
     653                nodeDocument = &firstNodeInBlock.document();
     654                textRange = makeSimpleRange(positionInParentBeforeNode(&firstNodeInBlock), positionInParentAfterNode(lastChildRenderer->node()));
    658655            }
    659656        }
     
    918915        auto end = nextVisiblePosition(start);
    919916        if (!end.isNull() && createLiveRange(range)->contains(end))
    920             return { boundsForRange({ *makeBoundaryPoint(start), *makeBoundaryPoint(end) }).center() };
     917            return { boundsForRange(*makeSimpleRange(start, end)).center() };
    921918    }
    922919    return AccessibilityObject::clickPoint();
     
    936933        return AccessibilityObject::clickPoint();
    937934   
    938     VisibleSelection visSelection = selection();
    939     VisiblePositionRange range = VisiblePositionRange(visSelection.visibleStart(), visSelection.visibleEnd());
    940     return boundsForVisiblePositionRange(range).center();
     935    return boundsForVisiblePositionRange(selection()).center();
    941936}
    942937   
     
    19911986        return VisiblePositionRange();
    19921987   
    1993     // construct VisiblePositions for start and end
    19941988    Node* node = m_renderer->node();
    19951989    if (!node)
     
    20092003    }
    20102004
    2011     return VisiblePositionRange(startPos, endPos);
     2005    return { WTFMove(startPos), WTFMove(endPos) };
    20122006}
    20132007
     
    20392033    selection.modify(FrameSelection::AlterationExtend, SelectionDirection::Right, TextGranularity::LineBoundary);
    20402034   
    2041     return VisiblePositionRange(selection.selection().visibleStart(), selection.selection().visibleEnd());
     2035    return selection.selection();
    20422036}
    20432037   
  • trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm

    r264470 r265044  
    6767#import "PluginDocument.h"
    6868#import "PluginViewBase.h"
     69#import "Range.h"
    6970#import "RenderInline.h"
    7071#import "RenderTextControl.h"
     
    924925{
    925926    ASSERT(cache);
    926    
    927927    if (!textMarker)
    928928        return VisiblePosition();
     
    930930    if (!getBytesFromAXTextMarker(textMarker, &textMarkerData, sizeof(textMarkerData)))
    931931        return VisiblePosition();
    932    
    933932    return cache->visiblePositionForTextMarkerData(textMarkerData);
    934933}
    935934
     935static VisiblePositionRange visiblePositionRangeForTextMarkerRange(AXObjectCache* cache, id textMarkerRange)
     936{
     937    return {
     938        visiblePositionForTextMarker(cache, (__bridge CFTypeRef)AXTextMarkerRangeStart(textMarkerRange)),
     939        visiblePositionForTextMarker(cache, (__bridge CFTypeRef)AXTextMarkerRangeEnd(textMarkerRange))
     940    };
     941}
     942
    936943- (VisiblePosition)visiblePositionForTextMarker:(id)textMarker
    937944{
    938945    return visiblePositionForTextMarker(self.axBackingObject->axObjectCache(), (__bridge CFTypeRef)textMarker);
    939 }
    940 
    941 static VisiblePosition visiblePositionForStartOfTextMarkerRange(AXObjectCache* cache, id textMarkerRange)
    942 {
    943     return visiblePositionForTextMarker(cache, (__bridge CFTypeRef)AXTextMarkerRangeStart(textMarkerRange));
    944 }
    945 
    946 static VisiblePosition visiblePositionForEndOfTextMarkerRange(AXObjectCache* cache, id textMarkerRange)
    947 {
    948     return visiblePositionForTextMarker(cache, (__bridge CFTypeRef)AXTextMarkerRangeEnd(textMarkerRange));
    949946}
    950947
     
    18481845- (VisiblePositionRange)visiblePositionRangeForTextMarkerRange:(id)textMarkerRange
    18491846{
    1850     if (!textMarkerRange)
    1851         return VisiblePositionRange();
    1852     AXObjectCache* cache = self.axBackingObject->axObjectCache();
    1853     return VisiblePositionRange(visiblePositionForStartOfTextMarkerRange(cache, textMarkerRange), visiblePositionForEndOfTextMarkerRange(cache, textMarkerRange));
     1847    return visiblePositionRangeForTextMarkerRange(self.axBackingObject->axObjectCache(), textMarkerRange);
    18541848}
    18551849
  • trunk/Source/WebCore/dom/Document.cpp

    r264880 r265044  
    164164#include "PublicSuffix.h"
    165165#include "Quirks.h"
     166#include "Range.h"
    166167#include "RealtimeMediaSourceCenter.h"
    167168#include "RenderChildIterator.h"
  • trunk/Source/WebCore/dom/Node.cpp

    r263563 r265044  
    6060#include "ProcessingInstruction.h"
    6161#include "ProgressEvent.h"
    62 #include "Range.h"
    6362#include "RenderBlock.h"
    6463#include "RenderBox.h"
  • trunk/Source/WebCore/dom/Position.h

    r259930 r265044  
    4242
    4343struct BoundaryPoint;
     44struct SimpleRange;
    4445
    4546enum PositionMoveType {
     
    250251WTF::TextStream& operator<<(WTF::TextStream&, const Position&);
    251252
     253struct PositionRange {
     254    Position start;
     255    Position end;
     256};
     257
     258Optional<SimpleRange> makeSimpleRange(const PositionRange&);
     259
    252260// inlines
    253261
  • trunk/Source/WebCore/dom/RadioButtonGroups.cpp

    r259911 r265044  
    2323
    2424#include "HTMLInputElement.h"
    25 #include "Range.h"
    2625#include <wtf/WeakHashSet.h>
    2726#include <wtf/WeakPtr.h>
  • trunk/Source/WebCore/dom/Range.h

    r264692 r265044  
    177177WEBCORE_EXPORT bool rangesOverlap(const Range*, const Range*);
    178178
    179 SimpleRange makeSimpleRange(const Range&);
     179WEBCORE_EXPORT SimpleRange makeSimpleRange(const Range&);
    180180SimpleRange makeSimpleRange(const Ref<Range>&);
    181181WEBCORE_EXPORT Optional<SimpleRange> makeSimpleRange(const Range*);
  • trunk/Source/WebCore/dom/SimpleRange.cpp

    r264692 r265044  
    8383}
    8484
     85Optional<SimpleRange> makeSimpleRange(const Optional<BoundaryPoint>& point)
     86{
     87    if (!point)
     88        return WTF::nullopt;
     89    return { { *point, *point } };
     90}
     91
     92Optional<SimpleRange> makeSimpleRange(Optional<BoundaryPoint>&& point)
     93{
     94    if (!point)
     95        return WTF::nullopt;
     96    auto end = *point;
     97    return { { WTFMove(*point), WTFMove(end) } };
     98}
     99
    85100Optional<SimpleRange> makeSimpleRange(const Optional<BoundaryPoint>& start, const Optional<BoundaryPoint>& end)
    86101{
     
    152167}
    153168
     169RefPtr<Node> commonInclusiveAncestor(const SimpleRange& range)
     170{
     171    return commonInclusiveAncestor(range.start.container, range.end.container);
    154172}
     173
     174}
  • trunk/Source/WebCore/dom/SimpleRange.h

    r264692 r265044  
    5252};
    5353
     54SimpleRange makeSimpleRange(const BoundaryPoint&);
     55SimpleRange makeSimpleRange(BoundaryPoint&&);
     56SimpleRange makeSimpleRange(const BoundaryPoint&, const BoundaryPoint&);
     57SimpleRange makeSimpleRange(BoundaryPoint&&, BoundaryPoint&&);
     58Optional<SimpleRange> makeSimpleRange(const Optional<BoundaryPoint>&);
     59WEBCORE_EXPORT Optional<SimpleRange> makeSimpleRange(Optional<BoundaryPoint>&&);
    5460WEBCORE_EXPORT Optional<SimpleRange> makeSimpleRange(const Optional<BoundaryPoint>&, const Optional<BoundaryPoint>&);
    5561WEBCORE_EXPORT Optional<SimpleRange> makeSimpleRange(Optional<BoundaryPoint>&&, Optional<BoundaryPoint>&&);
     62
     63inline BoundaryPoint makeBoundaryPointHelper(const BoundaryPoint& point) { return point; }
     64inline BoundaryPoint makeBoundaryPointHelper(BoundaryPoint&& point) { return WTFMove(point); }
     65template<typename T> auto makeBoundaryPointHelper(T&& argument) -> decltype(makeBoundaryPoint(std::forward<T>(argument)))
     66{
     67    return makeBoundaryPoint(std::forward<T>(argument));
     68}
     69
     70template<typename ...T> auto makeSimpleRange(T&& ...arguments) -> decltype(makeSimpleRange(makeBoundaryPointHelper(std::forward<T>(arguments))...))
     71{
     72    return makeSimpleRange(makeBoundaryPointHelper(std::forward<T>(arguments))...);
     73}
    5674
    5775// FIXME: Would like these to have shorter names; another option is to change prefix to makeSimpleRange.
    5876WEBCORE_EXPORT Optional<SimpleRange> makeRangeSelectingNode(Node&);
    5977WEBCORE_EXPORT SimpleRange makeRangeSelectingNodeContents(Node&);
     78
     79RefPtr<Node> commonInclusiveAncestor(const SimpleRange&);
    6080
    6181bool operator==(const SimpleRange&, const SimpleRange&);
  • trunk/Source/WebCore/dom/StaticRange.cpp

    r258248 r265044  
    2828
    2929#include "ContainerNode.h"
    30 #include "Range.h"
    3130#include "Text.h"
    3231
  • trunk/Source/WebCore/editing/AlternativeTextController.cpp

    r264905 r265044  
    473473        return;
    474474
    475     auto precedingCharacterRange = SimpleRange { *makeBoundaryPoint(precedingCharacterPosition), *makeBoundaryPoint(endOfSelection) };
    476     String string = plainText(precedingCharacterRange);
     475    auto precedingCharacterRange = makeSimpleRange(precedingCharacterPosition, endOfSelection);
     476    if (!precedingCharacterRange)
     477        return;
     478    String string = plainText(*precedingCharacterRange);
    477479    if (string.isEmpty() || !deprecatedIsEditingWhitespace(string[string.length() - 1]))
    478480        return;
     
    481483    // whitespace. So if the user types the same original word again at this position, we
    482484    // won't autocorrect it again.
    483     addMarker(precedingCharacterRange, DocumentMarker::DeletedAutocorrection, m_originalStringForLastDeletedAutocorrection);
     485    addMarker(*precedingCharacterRange, DocumentMarker::DeletedAutocorrection, m_originalStringForLastDeletedAutocorrection);
    484486}
    485487
     
    499501        return false;
    500502
    501     auto beforePrecedingCharacter = createLegacyEditingPosition(rangeWithAlternative.start).previous();
    502     auto precedingCharacterRange = SimpleRange { *makeBoundaryPoint(beforePrecedingCharacter), rangeWithAlternative.start };
    503 
    504     for (auto& marker : markers.markersInRange(precedingCharacterRange, DocumentMarker::DeletedAutocorrection)) {
     503    auto precedingCharacterRange = makeSimpleRange(createLegacyEditingPosition(rangeWithAlternative.start).previous(), rangeWithAlternative.start);
     504    if (!precedingCharacterRange)
     505        return false;
     506
     507    for (auto& marker : markers.markersInRange(*precedingCharacterRange, DocumentMarker::DeletedAutocorrection)) {
    505508        if (marker->description() == stringToBeReplaced)
    506509            return false;
  • trunk/Source/WebCore/editing/ApplyStyleCommand.cpp

    r259930 r265044  
    242242    // addBlockStyleIfNeeded may moveParagraphs, which can remove these endpoints.
    243243    // Calculate start and end indices from the start of the tree that they're in.
    244     auto scope = makeRefPtr(highestEditableRoot(visibleStart.deepEquivalent()));
    245     if (!scope)
    246         return;
    247 
    248     auto scopeStart = BoundaryPoint { *scope, 0 };
    249     auto startBoundaryPoint = makeBoundaryPoint(visibleStart.deepEquivalent().parentAnchoredEquivalent());
    250     auto endBoundaryPoint = makeBoundaryPoint(visibleEnd.deepEquivalent().parentAnchoredEquivalent());
    251     if (!startBoundaryPoint || !endBoundaryPoint)
    252         return;
    253 
    254     auto startIndex = characterCount({ scopeStart, *startBoundaryPoint }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
    255     auto endIndex = characterCount({ scopeStart, *endBoundaryPoint }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
     244    auto scopeRoot = makeRefPtr(highestEditableRoot(visibleStart.deepEquivalent()));
     245    if (!scopeRoot)
     246        return;
     247
     248    auto scope = makeRangeSelectingNodeContents(*scopeRoot);
     249    auto range = *makeSimpleRange(visibleStart, visibleEnd);
     250    auto startIndex = characterCount({ scope.start, range.start }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
     251    auto endIndex = characterCount({ scope.start, range.end }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
    256252
    257253    VisiblePosition paragraphStart(startOfParagraph(visibleStart));
     
    284280    }
    285281   
    286     auto startPosition = createLegacyEditingPosition(resolveCharacterLocation(makeRangeSelectingNodeContents(*scope), startIndex, TextIteratorEmitsCharactersBetweenAllVisiblePositions));
    287     auto endPosition = createLegacyEditingPosition(resolveCharacterLocation(makeRangeSelectingNodeContents(*scope), endIndex, TextIteratorEmitsCharactersBetweenAllVisiblePositions));
     282    auto startPosition = createLegacyEditingPosition(resolveCharacterLocation(scope, startIndex, TextIteratorEmitsCharactersBetweenAllVisiblePositions));
     283    auto endPosition = createLegacyEditingPosition(resolveCharacterLocation(scope, endIndex, TextIteratorEmitsCharactersBetweenAllVisiblePositions));
    288284    updateStartEnd(startPosition, endPosition);
    289285}
  • trunk/Source/WebCore/editing/CompositeEditCommand.cpp

    r264905 r265044  
    132132    VisiblePosition start = visiblePositionForIndex(range.startIndex.value, range.startIndex.scope.get());
    133133    VisiblePosition end = visiblePositionForIndex(range.endIndex.value, range.endIndex.scope.get());
    134     return AccessibilityObject::stringForVisiblePositionRange(VisiblePositionRange(start, end));
     134    return AccessibilityObject::stringForVisiblePositionRange({ WTFMove(start), WTFMove(end) });
    135135}
    136136
     
    14211421            startIndex = 0;
    14221422            if (startInParagraph) {
    1423                 auto paragraphStart = makeBoundaryPoint(startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent());
    1424                 auto selectionStart = makeBoundaryPoint(visibleStart.deepEquivalent().parentAnchoredEquivalent());
    1425                 if (paragraphStart && selectionStart)
    1426                     startIndex = characterCount({ *paragraphStart, *selectionStart }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
     1423                if (auto rangeToSelectionStart = makeSimpleRange(startOfParagraphToMove, visibleStart))
     1424                    startIndex = characterCount(*rangeToSelectionStart, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
    14271425            }
    14281426
    14291427            endIndex = 0;
    14301428            if (endInParagraph) {
    1431                 auto paragraphStart = makeBoundaryPoint(startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent());
    1432                 auto selectionEnd = makeBoundaryPoint(visibleEnd.deepEquivalent().parentAnchoredEquivalent());
    1433                 if (paragraphStart && selectionEnd)
    1434                     endIndex = characterCount({ *paragraphStart, *selectionEnd }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
     1429                if (auto rangeToSelectionEnd = makeSimpleRange(startOfParagraphToMove, visibleEnd))
     1430                    endIndex = characterCount(*rangeToSelectionEnd, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
    14351431            }
    14361432        }
     
    15051501        editableRoot = &document();
    15061502
    1507     auto destinationIndex = characterCount({ { *editableRoot, 0 }, *makeBoundaryPoint(destination.deepEquivalent().parentAnchoredEquivalent()) }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
     1503    auto destinationIndex = characterCount({ { *editableRoot, 0 }, *makeBoundaryPoint(destination) }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
    15081504
    15091505    setEndingSelection(VisibleSelection(destination, originalIsDirectional));
  • trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp

    r264692 r265044  
    4040#include "HTMLTableElement.h"
    4141#include "NodeTraversal.h"
     42#include "Range.h"
    4243#include "RenderTableCell.h"
    4344#include "RenderText.h"
  • trunk/Source/WebCore/editing/Editing.cpp

    r264386 r265044  
    11051105    }
    11061106
    1107     auto start = makeBoundaryPoint(firstPositionInNode(scope.get()));
    1108     if (!start)
    1109         return 0;
    1110     auto end = makeBoundaryPoint(position.parentAnchoredEquivalent());
    1111     if (!end)
    1112         return 0;
    1113 
    1114     return characterCount({ *start, *end }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
     1107    auto range = *makeSimpleRange(makeBoundaryPointBeforeNodeContents(*scope), position);
     1108    return characterCount(range, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
    11151109}
    11161110
     
    11181112int indexForVisiblePosition(Node& node, const VisiblePosition& visiblePosition, bool forSelectionPreservation)
    11191113{
    1120     auto start = makeBoundaryPoint(firstPositionInNode(&node));
    1121     if (!start)
    1122         return 0;
    1123     auto end = makeBoundaryPoint(visiblePosition.deepEquivalent().parentAnchoredEquivalent());
    1124     if (!end)
    1125         return 0;
    1126 
    1127     return characterCount({ *start, *end }, forSelectionPreservation ? TextIteratorEmitsCharactersBetweenAllVisiblePositions : TextIteratorDefaultBehavior);
     1114    auto range = makeSimpleRange(makeBoundaryPointBeforeNodeContents(node), visiblePosition);
     1115    return range ? characterCount(*range, forSelectionPreservation ? TextIteratorEmitsCharactersBetweenAllVisiblePositions : TextIteratorDefaultBehavior) : 0;
    11281116}
    11291117
  • trunk/Source/WebCore/editing/Editor.cpp

    r264905 r265044  
    32603260{
    32613261    // We remove '\0' characters because they are not visibly rendered to the user.
    3262     auto& selection = m_document.selection().selection();
    3263     auto start = selection.start();
    3264     auto end = selection.end();
    3265     if (start.isNull() || start.isOrphan() || end.isNull() || end.isOrphan())
    3266         return emptyString();
    3267     return plainText(SimpleRange { *makeBoundaryPoint(start), *makeBoundaryPoint(end) }, behavior).replaceWithLiteral('\0', "");
     3262    auto range = m_document.selection().selection().firstRange();
     3263    return range ? plainText(*range, behavior).replaceWithLiteral('\0', "") : emptyString();
    32683264}
    32693265
     
    36833679        end = end.next(Character);
    36843680    }
    3685     return { *makeBoundaryPoint(start), *makeBoundaryPoint(end)};
     3681    return *makeSimpleRange(start, end);
    36863682}
    36873683
     
    39103906{
    39113907    auto& selection = m_document.selection().selection();
    3912     auto start = makeBoundaryPoint(startOfParagraph(selection.visibleStart()));
    3913     auto end = makeBoundaryPoint(endOfParagraph(selection.visibleEnd()));
    3914     if (!start || !end)
    3915         return WTF::nullopt;
    3916     return { { *start, *end } };
     3908    return makeSimpleRange(startOfParagraph(selection.visibleStart()), endOfParagraph(selection.visibleEnd()));
    39173909}
    39183910
     
    42324224    auto range = selectedRange();
    42334225    if (range) {
    4234         if (auto enclosingAnchor = enclosingElementWithTag(firstPositionInNode(commonInclusiveAncestor(range->start.container, range->end.container).get()), HTMLNames::aTag)) {
     4226        if (auto enclosingAnchor = enclosingElementWithTag(firstPositionInNode(commonInclusiveAncestor(*range).get()), HTMLNames::aTag)) {
    42354227            if (comparePositions(firstPositionInOrBeforeNode(range->start.container.ptr()), createLegacyEditingPosition(range->start)) >= 0)
    42364228                range->start = makeBoundaryPointBeforeNodeContents(*enclosingAnchor);
  • trunk/Source/WebCore/editing/FrameSelection.cpp

    r264878 r265044  
    26192619}
    26202620
    2621 int FrameSelection::wordOffsetInRange(const Range *range) const
    2622 {
    2623     if (!range)
    2624         return -1;
    2625 
    2626     VisibleSelection selection = m_selection;
    2627     if (!selection.isCaret())
    2628         return -1;
    2629 
    2630     // FIXME: This will only work in cases where the selection remains in
    2631     // the same node after it is expanded. Improve to handle more complicated
    2632     // cases.
    2633     int result = selection.start().deprecatedEditingOffset() - range->startOffset();
    2634     if (result < 0)
    2635         result = 0;
    2636     return result;
    2637 }
    2638 
    2639 bool FrameSelection::spaceFollowsWordInRange(const Range *range) const
    2640 {
    2641     if (!range)
    2642         return false;
    2643     Node& node = range->endContainer();
    2644     int endOffset = range->endOffset();
    2645     VisiblePosition pos(createLegacyEditingPosition(&node, endOffset), VP_DEFAULT_AFFINITY);
    2646     return isSpaceOrNewline(pos.characterAfter());
    2647 }
    2648 
    26492621bool FrameSelection::selectionAtDocumentStart() const
    26502622{
     
    26592631
    26602632    return isStartOfDocument(pos);
    2661 }
    2662 
    2663 bool FrameSelection::selectionAtSentenceStart() const
    2664 {
    2665     VisibleSelection selection = m_selection;
    2666     if (selection.isNone())
    2667         return false;
    2668 
    2669     return actualSelectionAtSentenceStart(selection);
    26702633}
    26712634
     
    28352798}
    28362799
    2837 bool FrameSelection::actualSelectionAtSentenceStart(const VisibleSelection& sel) const
    2838 {
    2839     Position startPos(sel.start());
     2800bool FrameSelection::selectionAtSentenceStart() const
     2801{
     2802    if (m_selection.isNone())
     2803        return false;
     2804
     2805    Position startPos(m_selection.start());
    28402806    VisiblePosition pos(createLegacyEditingPosition(startPos.deprecatedNode(), startPos.deprecatedEditingOffset()), VP_DEFAULT_AFFINITY);
    28412807    if (pos.isNull())
  • trunk/Source/WebCore/editing/FrameSelection.h

    r264386 r265044  
    233233    WEBCORE_EXPORT UChar characterBeforeCaretSelection() const;
    234234    WEBCORE_EXPORT UChar characterAfterCaretSelection() const;
    235     WEBCORE_EXPORT int wordOffsetInRange(const Range*) const;
    236     WEBCORE_EXPORT bool spaceFollowsWordInRange(const Range*) const;
    237235    WEBCORE_EXPORT bool selectionAtDocumentStart() const;
    238236    WEBCORE_EXPORT bool selectionAtSentenceStart() const;
     
    334332
    335333#if PLATFORM(IOS_FAMILY)
    336     bool actualSelectionAtSentenceStart(const VisibleSelection&) const;
    337334    Optional<SimpleRange> rangeByAlteringCurrentSelection(EAlteration, int amount) const;
    338335#endif
  • trunk/Source/WebCore/editing/TextCheckingHelper.cpp

    r264905 r265044  
    3333#include "Frame.h"
    3434#include "FrameSelection.h"
     35#include "Range.h"
    3536#include "Settings.h"
    3637#include "TextCheckerClient.h"
     
    161162ExceptionOr<uint64_t> TextCheckingParagraph::offsetTo(const Position& position) const
    162163{
    163     auto end = makeBoundaryPoint(position);
    164     if (!end)
     164    auto range = makeSimpleRange(paragraphRange().start, position);
     165    if (!range)
    165166        return Exception { TypeError };
    166     return characterCount({ paragraphRange().start, *end });
     167    return characterCount(*range);
    167168}
    168169
  • trunk/Source/WebCore/editing/TextManipulationController.cpp

    r264947 r265044  
    4141#include "NodeTraversal.h"
    4242#include "PseudoElement.h"
    43 #include "Range.h"
    4443#include "ScriptDisallowedScope.h"
    4544#include "Text.h"
     
    155154public:
    156155    ParagraphContentIterator(const Position& start, const Position& end)
    157         : m_iterator({ *makeBoundaryPoint(start), *makeBoundaryPoint(end) }, TextIteratorIgnoresStyleVisibility)
     156        : m_iterator(*makeSimpleRange(start, end), TextIteratorIgnoresStyleVisibility)
    158157        , m_node(start.firstNode())
    159158        , m_pastEndNode(end.firstNode())
  • trunk/Source/WebCore/editing/TypingCommand.cpp

    r261776 r265044  
    333333    postTextStateChangeNotification(AXTextEditTypeDelete, AccessibilityObject::stringForVisiblePositionRange(selection), selection.start());
    334334    VisiblePositionIndexRange range;
    335     range.startIndex.value = indexForVisiblePosition(selection.start(), range.startIndex.scope);
    336     range.endIndex.value = indexForVisiblePosition(selection.end(), range.endIndex.scope);
     335    range.startIndex.value = indexForVisiblePosition(selection.visibleStart(), range.startIndex.scope);
     336    range.endIndex.value = indexForVisiblePosition(selection.visibleEnd(), range.endIndex.scope);
    337337    composition()->setRangeDeletedByUnapply(range);
    338338}
  • trunk/Source/WebCore/editing/VisiblePosition.cpp

    r259241 r265044  
    850850}
    851851
     852Optional<SimpleRange> makeSimpleRange(const VisiblePositionRange& range)
     853{
     854    return makeSimpleRange(range.start, range.end);
     855}
     856
    852857}  // namespace WebCore
    853858
  • trunk/Source/WebCore/editing/VisiblePosition.h

    r258871 r265044  
    3333class Range;
    3434
     35struct SimpleRange;
     36
    3537// VisiblePosition default affinity is downstream because
    3638// the callers do not really care (they just want the
     
    141143WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const VisiblePosition&);
    142144
     145struct VisiblePositionRange {
     146    VisiblePosition start;
     147    VisiblePosition end;
     148
     149    bool isNull() const { return start.isNull() || end.isNull(); }
     150};
     151
     152Optional<SimpleRange> makeSimpleRange(const VisiblePositionRange&);
     153
    143154// inlines
    144155
  • trunk/Source/WebCore/editing/VisibleSelection.cpp

    r261939 r265044  
    3131#include "Element.h"
    3232#include "HTMLInputElement.h"
    33 #include "Range.h"
    3433#include "Settings.h"
    3534#include "ShadowRoot.h"
     
    133132    if (isNoneOrOrphaned())
    134133        return WTF::nullopt;
    135     Position start = m_start.parentAnchoredEquivalent();
    136     Position end = m_end.parentAnchoredEquivalent();
    137     if (start.isNull() || start.isOrphan() || end.isNull() || end.isOrphan())
    138         return WTF::nullopt;
    139     return SimpleRange { *makeBoundaryPoint(start), *makeBoundaryPoint(end) };
     134    // FIXME: Seems likely we don't need to call parentAnchoredEquivalent here.
     135    return makeSimpleRange(m_start.parentAnchoredEquivalent(), m_end.parentAnchoredEquivalent());
    140136}
    141137
     
    180176            // Make sure the start is before the end.
    181177            // The end can wind up before the start if collapsed whitespace is the only thing selected.
    182             Position tmp = s;
    183             s = e;
    184             e = tmp;
     178            std::swap(s, e);
    185179        }
    186180        s = s.parentAnchoredEquivalent();
     
    188182    }
    189183
    190     if (s.isNull() || e.isNull())
    191         return WTF::nullopt;
    192 
    193     return SimpleRange { *makeBoundaryPoint(s), *makeBoundaryPoint(e) };
     184    return makeSimpleRange(s, e);
    194185}
    195186
     
    203194}
    204195
    205 static Optional<SimpleRange> makeSearchRange(const Position& position)
    206 {
    207     auto node = position.deprecatedNode();
    208     auto scope = deprecatedEnclosingBlockFlowElement(node);
     196bool VisibleSelection::isAll(EditingBoundaryCrossingRule rule) const
     197{
     198    return !nonBoundaryShadowTreeRootNode() && visibleStart().previous(rule).isNull() && visibleEnd().next(rule).isNull();
     199}
     200
     201void VisibleSelection::appendTrailingWhitespace()
     202{
     203    auto scope = deprecatedEnclosingBlockFlowElement(m_end.deprecatedNode());
    209204    if (!scope)
    210         return { };
    211     auto start = makeBoundaryPoint(position.parentAnchoredEquivalent());
    212     if (!start)
    213         return { };
    214     return { { WTFMove(*start), makeBoundaryPointAfterNodeContents(*scope) } };
    215 }
    216 
    217 bool VisibleSelection::isAll(EditingBoundaryCrossingRule rule) const
    218 {
    219     return !nonBoundaryShadowTreeRootNode() && visibleStart().previous(rule).isNull() && visibleEnd().next(rule).isNull();
    220 }
    221 
    222 void VisibleSelection::appendTrailingWhitespace()
    223 {
    224     auto searchRange = makeSearchRange(m_end);
    225     if (!searchRange)
    226205        return;
    227206
    228     CharacterIterator charIt(*searchRange, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
    229 
     207    CharacterIterator charIt(*makeSimpleRange(m_end, makeBoundaryPointAfterNodeContents(*scope)), TextIteratorEmitsCharactersBetweenAllVisiblePositions);
    230208    for (; !charIt.atEnd() && charIt.text().length(); charIt.advance(1)) {
    231209        UChar c = charIt.text()[0];
  • trunk/Source/WebCore/editing/VisibleSelection.h

    r261776 r265044  
    7272    VisiblePosition visibleBase() const { return VisiblePosition(m_base, isRange() ? (isBaseFirst() ? UPSTREAM : DOWNSTREAM) : affinity()); }
    7373    VisiblePosition visibleExtent() const { return VisiblePosition(m_extent, isRange() ? (isBaseFirst() ? DOWNSTREAM : UPSTREAM) : affinity()); }
     74
     75    operator VisiblePositionRange() const { return { visibleStart(), visibleEnd() }; }
    7476
    7577    bool isNone() const { return selectionType() == NoSelection; }
  • trunk/Source/WebCore/editing/VisibleUnits.cpp

    r261776 r265044  
    19061906    if (a.isNull() || b.isNull())
    19071907        return 0;
    1908     return a < b
    1909         ? -characterCount({ *makeBoundaryPoint(a), *makeBoundaryPoint(b) })
    1910         : characterCount({ *makeBoundaryPoint(b), *makeBoundaryPoint(a) });
     1908    return a < b ? -characterCount(*makeSimpleRange(a, b)) : characterCount(*makeSimpleRange(b, a));
    19111909}
    19121910
     
    19351933
    19361934    if (startPosition != endPosition) {
    1937         String characterString = plainText({ *makeBoundaryPoint(startPosition), *makeBoundaryPoint(endPosition) }).replace(noBreakSpace, ' ');
     1935        String characterString = plainText(*makeSimpleRange(startPosition, endPosition)).replace(noBreakSpace, ' ');
    19381936        for (int i = characterString.length() - 1, index = 0; i >= 0 && index < maxCharacters; --i) {
    19391937            if (!index && nextPosition.isNull())
     
    19491947RefPtr<Range> wordRangeFromPosition(const VisiblePosition& position)
    19501948{
    1951     // The selection could be in a non visible element and we don't have a VisiblePosition.
    19521949    if (position.isNull())
    19531950        return nullptr;
     
    19671964        currentPosition = positionOfNextBoundaryOfGranularity(currentPosition, TextGranularity::WordGranularity, SelectionDirection::Backward);
    19681965    } while (currentPosition.isNotNull() && !atBoundaryOfGranularity(currentPosition, TextGranularity::WordGranularity, SelectionDirection::Backward));
    1969 
    19701966    if (currentPosition.isNull())
    19711967        currentPosition = positionOfNextBoundaryOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Forward);
     
    19821978{
    19831979    VisiblePosition result;
    1984 
    1985     // move the position at the end of the word
    19861980    if (atBoundaryOfGranularity(position, TextGranularity::LineGranularity, SelectionDirection::Forward)) {
    19871981        // Don't cross line boundaries.
  • trunk/Source/WebCore/editing/cocoa/DataDetection.mm

    r264311 r265044  
    7474        return { };
    7575    String fullPlainTextString = plainText(contextRange);
    76     CFIndex hitLocation = characterCount({ contextRange.start, *makeBoundaryPoint(position) });
     76    CFIndex hitLocation = characterCount(*makeSimpleRange(contextRange.start, position));
    7777
    7878    auto scanner = adoptCF(DDScannerCreate(DDScannerTypeStandard, 0, nullptr));
     
    273273}
    274274
    275 static bool searchForLinkRemovingExistingDDLinks(Node& startNode, Node& endNode, bool& didModifyDOM)
    276 {
    277     didModifyDOM = false;
     275static bool searchForLinkRemovingExistingDDLinks(Node& startNode, Node& endNode)
     276{
    278277    for (Node* node = &startNode; node; node = NodeTraversal::next(*node)) {
    279278        if (is<HTMLAnchorElement>(*node)) {
     
    282281                return true;
    283282            removeResultLinksFromAnchor(anchor);
    284             didModifyDOM = true;
    285283        }
    286284       
     
    292290                    return true;
    293291                removeResultLinksFromAnchor(anchor);
    294                 didModifyDOM = true;
    295292            }
    296293            return false;
     
    554551            continue;
    555552       
    556         // Store the range boundaries as Position, because the DOM could change if we find
    557         // old data detector link.
    558         Vector<std::pair<Position, Position>> rangeBoundaries;
    559         rangeBoundaries.reserveInitialCapacity(resultRanges.size());
    560         for (auto& range : resultRanges)
    561             rangeBoundaries.uncheckedAppend({ createLegacyEditingPosition(range.start), createLegacyEditingPosition(range.end) });
    562 
    563553        NSString *identifier = dataDetectorStringForPath(indexPaths[resultIndex].get());
    564554        NSString *correspondingURL = constructURLStringForResult(coreResult, identifier, referenceDate, (NSTimeZone *)tz.get(), types);
    565         bool didModifyDOM = false;
    566 
    567         if (!correspondingURL || searchForLinkRemovingExistingDDLinks(resultRanges.first().start.container, resultRanges.last().end.container, didModifyDOM))
     555
     556        if (!correspondingURL || searchForLinkRemovingExistingDDLinks(resultRanges.first().start.container, resultRanges.last().end.container))
    568557            continue;
    569        
    570         if (didModifyDOM) {
    571             // If the DOM was modified because some old links were removed,
    572             // we need to recreate the ranges because they could no longer be valid.
    573             ASSERT(resultRanges.size() == rangeBoundaries.size());
    574             resultRanges.shrink(0); // Keep capacity as we are going to repopulate the Vector right away with the same number of items.
    575             for (auto& rangeBoundary : rangeBoundaries)
    576                 resultRanges.uncheckedAppend({ *makeBoundaryPoint(rangeBoundary.first), *makeBoundaryPoint(rangeBoundary.second) });
    577         }
    578        
     558
    579559        lastModifiedQueryOffset = queryRange.end;
    580560        BOOL shouldUseLightLinks = softLink_DataDetectorsCore_DDShouldUseLightLinksForResult(coreResult, [indexPaths[resultIndex] length] > 1);
  • trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm

    r264251 r265044  
    280280        return WTF::nullopt;
    281281
    282     auto lengthToSelectionStart = characterCount({ *makeBoundaryPoint(paragraphStart), *makeBoundaryPoint(selectionStart) });
    283     auto selectionCharacterCount = characterCount({ *makeBoundaryPoint(selectionStart), *makeBoundaryPoint(selectionEnd) });
     282    auto lengthToSelectionStart = characterCount(*makeSimpleRange(paragraphStart, selectionStart));
     283    auto selectionCharacterCount = characterCount(*makeSimpleRange(selectionStart, selectionEnd));
    284284    NSRange rangeToPass = NSMakeRange(lengthToSelectionStart, selectionCharacterCount);
    285285
     
    329329
    330330        // As context, we are going to use the surrounding paragraphs of text.
    331         auto paragraphStart = makeBoundaryPoint(startOfParagraph(selectionStart));
    332         auto paragraphEnd = makeBoundaryPoint(endOfParagraph(selectionEnd));
    333         if (!paragraphStart || !paragraphEnd)
     331        fullCharacterRange = makeSimpleRange(startOfParagraph(selectionStart), endOfParagraph(selectionEnd));
     332        if (!fullCharacterRange)
    334333            return WTF::nullopt;
    335334
    336         fullCharacterRange = { { *paragraphStart, *paragraphEnd } };
    337         selectionRange = NSMakeRange(characterCount({ *paragraphStart, *makeBoundaryPoint(selectionStart) }),
    338             characterCount({ *makeBoundaryPoint(selectionStart), *makeBoundaryPoint(selectionEnd) }));
    339         hitIndex = characterCount({ *paragraphStart, *makeBoundaryPoint(position) });
     335        selectionRange = NSMakeRange(characterCount(*makeSimpleRange(fullCharacterRange->start, selectionStart)),
     336            characterCount(*makeSimpleRange(selectionStart, selectionEnd)));
     337        hitIndex = characterCount(*makeSimpleRange(fullCharacterRange->start, position));
    340338    } else {
    341339        VisibleSelection selectionAccountingForLineRules { position };
     
    351349
    352350        selectionRange = NSMakeRange(NSNotFound, 0);
    353         hitIndex = characterCount({ fullCharacterRange->start, *makeBoundaryPoint(position) });
     351        hitIndex = characterCount(*makeSimpleRange(fullCharacterRange->start, position));
    354352    }
    355353
  • trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm

    r262683 r265044  
    5454#import "PublicURLManager.h"
    5555#import "Quirks.h"
     56#import "Range.h"
    5657#import "RenderView.h"
    5758#import "RuntimeEnabledFeatures.h"
  • trunk/Source/WebCore/editing/ios/DictationCommandIOS.cpp

    r264905 r265044  
    3333#include "Element.h"
    3434#include "Position.h"
    35 #include "Range.h"
    3635#include "SmartReplace.h"
    3736#include "TextIterator.h"
  • trunk/Source/WebCore/editing/mac/DictionaryLookupLegacy.mm

    r264247 r265044  
    8787
    8888    // As context, we are going to use the surrounding paragraphs of text.
    89     auto paragraphStart = makeBoundaryPoint(startOfParagraph(selectionStart));
    90     auto paragraphEnd = makeBoundaryPoint(endOfParagraph(selectionEnd));
    91     if (!paragraphStart || !paragraphEnd)
    92         return WTF::nullopt;
    93 
    94     auto selectionRange = SimpleRange { *makeBoundaryPoint(selectionStart), *makeBoundaryPoint(selectionEnd) };
    95     auto paragraphRange = SimpleRange { *paragraphStart, *paragraphEnd };
     89    auto paragraphRange = makeSimpleRange(startOfParagraph(selectionStart), endOfParagraph(selectionEnd));
     90    if (!paragraphRange)
     91        return WTF::nullopt;
     92
     93    auto selectionRange = *makeSimpleRange(selectionStart, selectionEnd);
    9694
    9795    NSDictionary *options = nil;
    98     tokenRange(plainText(paragraphRange), characterRange(paragraphRange, selectionRange), &options);
     96    tokenRange(plainText(*paragraphRange), characterRange(*paragraphRange, selectionRange), &options);
    9997
    10098    return { { *selectedRange, options } };
     
    134132        return WTF::nullopt;
    135133
    136     auto fullCharacterStart = makeBoundaryPoint(fullCharacterRange->startPosition());
    137     auto positionBoundary = makeBoundaryPoint(position);
    138     if (!fullCharacterStart || !positionBoundary)
    139         return WTF::nullopt;
    140 
    141     NSRange rangeToPass = NSMakeRange(characterCount({ *fullCharacterStart, *positionBoundary }), 0);
     134    auto rangeToPosition = makeSimpleRange(fullCharacterRange->startPosition(), position);
     135    if (!rangeToPosition)
     136        return WTF::nullopt;
     137
     138    NSRange rangeToPass = NSMakeRange(characterCount(*rangeToPosition), 0);
    142139    NSDictionary *options = nil;
    143140    auto extractedRange = tokenRange(plainText(*fullCharacterRange), rangeToPass, &options);
  • trunk/Source/WebCore/editing/mac/EditorMac.mm

    r264692 r265044  
    4646#import "PasteboardStrategy.h"
    4747#import "PlatformStrategies.h"
    48 #import "Range.h"
    4948#import "RenderBlock.h"
    5049#import "RenderImage.h"
  • trunk/Source/WebCore/editing/markup.cpp

    r264305 r265044  
    452452    }
    453453
    454     auto startBoundary = makeBoundaryPoint(start);
    455     auto endBoundary = makeBoundaryPoint(end);
    456     if (!startBoundary || !endBoundary)
    457         return emptyString();
    458 
    459     return plainText({ WTFMove(*startBoundary), WTFMove(*endBoundary) }, behavior);
     454    auto range = makeSimpleRange(start, end);
     455    return range ? plainText(*range, behavior) : emptyString();
    460456}
    461457
  • trunk/Source/WebCore/editing/win/EditorWin.cpp

    r264692 r265044  
    3232#include "FrameSelection.h"
    3333#include "Pasteboard.h"
     34#include "Range.h"
    3435#include "windows.h"
    3536
  • trunk/Source/WebCore/html/shadow/mac/ImageControlsButtonElementMac.cpp

    r261013 r265044  
    3636#include "HTMLDivElement.h"
    3737#include "Page.h"
    38 #include "Range.h"
    3938#include "RenderBlockFlow.h"
    4039#include "RenderStyle.h"
  • trunk/Source/WebCore/page/DOMSelection.cpp

    r261776 r265044  
    338338    auto& selection = frame->selection();
    339339    if (selection.isNone()) {
    340         selection.moveTo(&range);
     340        selection.setSelection(SimpleRange { range });
    341341        return;
    342342    }
     
    357357            } else {
    358358                // The new range contains the original range.
    359                 selection.moveTo(&range);
     359                selection.setSelection(SimpleRange { range });
    360360            }
    361361        }
     
    367367            if (!result.hasException() && result.releaseReturnValue() == -1) {
    368368                // The original range contains the new range.
    369                 selection.moveTo(normalizedRange.get());
     369                selection.setSelection(SimpleRange { *normalizedRange });
    370370            } else {
    371371                // The ranges intersect.
  • trunk/Source/WebCore/page/EventHandler.cpp

    r264692 r265044  
    676676static uint64_t textDistance(const Position& start, const Position& end)
    677677{
    678     auto startBoundary = makeBoundaryPoint(start);
    679     auto endBoundary = makeBoundaryPoint(end);
    680     if (!startBoundary || !endBoundary)
     678    auto range = makeSimpleRange(start, end);
     679    if (!range)
    681680        return 0;
    682     return characterCount({ *startBoundary, *endBoundary }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
     681    return characterCount(*range, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
    683682}
    684683
  • trunk/Source/WebCore/page/Frame.cpp

    r264692 r265044  
    820820{
    821821    auto position = visiblePositionForPoint(framePoint);
    822     auto positionBoundary = makeBoundaryPoint(position);
    823     if (!positionBoundary)
    824         return nullptr;
    825822
    826823    auto containerText = position.deepEquivalent().containerText();
     
    828825        return nullptr;
    829826
    830     if (auto previous = makeBoundaryPoint(position.previous())) {
    831         auto previousCharacterRange = SimpleRange { *previous, *positionBoundary };
    832         if (editor().firstRectForRange(previousCharacterRange).contains(framePoint))
    833             return createLiveRange(previousCharacterRange);
    834     }
    835 
    836     if (auto next = makeBoundaryPoint(position.next())) {
    837         auto nextCharacterRange = SimpleRange { *positionBoundary, *next };
    838         if (editor().firstRectForRange(nextCharacterRange).contains(framePoint))
    839             return createLiveRange(nextCharacterRange);
     827    if (auto previousCharacterRange = makeSimpleRange(position.previous(), position)) {
     828        if (editor().firstRectForRange(*previousCharacterRange).contains(framePoint))
     829            return createLiveRange(*previousCharacterRange);
     830    }
     831
     832    if (auto nextCharacterRange = makeSimpleRange(position, position.next())) {
     833        if (editor().firstRectForRange(*nextCharacterRange).contains(framePoint))
     834            return createLiveRange(*nextCharacterRange);
    840835    }
    841836
  • trunk/Source/WebCore/page/TextIndicator.cpp

    r264585 r265044  
    225225
    226226    RenderElement* renderer = nullptr;
    227     auto commonAncestor = commonInclusiveAncestor(range.start.container, range.end.container);
     227    auto commonAncestor = commonInclusiveAncestor(range);
    228228    while (commonAncestor) {
    229229        if (is<RenderElement>(commonAncestor->renderer())) {
     
    310310    bool useBoundingRectAndPaintAllContentForComplexRanges = data.options.contains(TextIndicatorOption::UseBoundingRectAndPaintAllContentForComplexRanges);
    311311    if (useBoundingRectAndPaintAllContentForComplexRanges && containsOnlyWhiteSpaceText(range)) {
    312         if (auto* containerRenderer = commonInclusiveAncestor(range.start.container, range.end.container)->renderer()) {
     312        if (auto* containerRenderer = commonInclusiveAncestor(range)->renderer()) {
    313313            data.options.add(TextIndicatorOption::PaintAllContent);
    314314            textRects.append(containerRenderer->absoluteBoundingBoxRect());
  • trunk/Source/WebKit/ChangeLog

    r265043 r265044  
     12020-07-29  Darin Adler  <darin@apple.com>
     2
     3        Improve range idioms and other changes to prepare the way for more reduction in live range use
     4        https://bugs.webkit.org/show_bug.cgi?id=214882
     5
     6        Reviewed by Sam Weinig.
     7
     8        * WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp:
     9        (WKBundleNodeHandleGetRenderRect): Emptied out this unused function and added
     10        ASSERT_NOT_REACHED. Later, we can delete this once we deal with any link-time
     11        dependencies. I believe Safari may link with this but never calls it.
     12        (WKBundleNodeHandleCopyVisibleRange): Ditto.
     13        (WKBundleNodeHandleSetHTMLInputElementSpellcheckEnabled): Ditto.
     14        (WKBundleNodeHandleGetHTMLInputElementAutoFilled): Ditto.
     15        (WKBundleNodeHandleGetHTMLInputElementAutoFillButtonEnabled): Ditto.
     16        (WKBundleNodeHandleGetHTMLInputElementAutoFillAvailable): Ditto.
     17        (WKBundleNodeHandleGetHTMLInputElementAutoFillButtonBounds): Ditto.
     18        (WKBundleNodeHandleCopyHTMLTableCellElementCellAbove): Ditto.
     19        (WKBundleNodeHandleCopyHTMLFrameElementContentFrame): Ditto.
     20        (WKBundleNodeHandleGetHTMLInputElementAutofilled): Ditto.
     21        (WKBundleNodeHandleSetHTMLInputElementAutofilled): Ditto.
     22        (WKBundleNodeHandleSetHTMLInputElementAutoFillButtonEnabled): Ditto.
     23
     24        * WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm:
     25        (WebKit::TextCheckingControllerProxy::annotatedSubstringBetweenPositions):
     26        Simplify with makeSimpleRange.
     27
     28        * WebProcess/WebPage/glib/WebPageGLib.cpp: Added include of "Range.h",
     29        may not be needed right now, but highly likely to be needed after
     30        future live range work.
     31        * WebProcess/WebPage/ios/WebPageIOS.mm: Ditto.
     32        (WebKit::WebPage::selectWithGesture): Simplify with makeSimpleRange.
     33        (WebKit::WebPage::requestDocumentEditingContext): Ditto.
     34
     35        * WebProcess/WebPage/mac/WebPageMac.mm:
     36        (WebKit::WebPage::attributedSubstringForCharacterRangeAsync):
     37        Use auto for range to prepare for possible change of type from live
     38        range to SimpleRange.
     39
    1402020-07-29  Noam Rosenthal  <noam@webkit.org>
    241
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp

    r248373 r265044  
    2929
    3030#include "InjectedBundleNodeHandle.h"
    31 #include "InjectedBundleRangeHandle.h"
    3231#include "WKAPICast.h"
    3332#include "WKBundleAPICast.h"
     
    9190WKRect WKBundleNodeHandleGetRenderRect(WKBundleNodeHandleRef nodeHandleRef, bool* isReplaced)
    9291{
    93     return WebKit::toAPI(WebKit::toImpl(nodeHandleRef)->renderRect(isReplaced));
     92    ASSERT_NOT_REACHED();
     93    return { };
    9494}
    9595
     
    100100}
    101101
    102 WKBundleRangeHandleRef WKBundleNodeHandleCopyVisibleRange(WKBundleNodeHandleRef nodeHandleRef)
    103 {
    104     RefPtr<WebKit::InjectedBundleRangeHandle> rangeHandle = WebKit::toImpl(nodeHandleRef)->visibleRange();
    105     return toAPI(rangeHandle.leakRef());
     102WKBundleRangeHandleRef WKBundleNodeHandleCopyVisibleRange(WKBundleNodeHandleRef)
     103{
     104    ASSERT_NOT_REACHED();
     105    return nullptr;
    106106}
    107107
     
    116116}
    117117
    118 void WKBundleNodeHandleSetHTMLInputElementSpellcheckEnabled(WKBundleNodeHandleRef htmlInputElementHandleRef, bool enabled)
    119 {
    120     WebKit::toImpl(htmlInputElementHandleRef)->setHTMLInputElementSpellcheckEnabled(enabled);
    121 }
    122 
    123 bool WKBundleNodeHandleGetHTMLInputElementAutoFilled(WKBundleNodeHandleRef htmlInputElementHandleRef)
    124 {
    125     return WebKit::toImpl(htmlInputElementHandleRef)->isHTMLInputElementAutoFilled();
     118void WKBundleNodeHandleSetHTMLInputElementSpellcheckEnabled(WKBundleNodeHandleRef, bool)
     119{
     120    // FIXME: Would put ASSERT_NOT_REACHED() here but some compilers are warning the function is "noreturn".
     121}
     122
     123bool WKBundleNodeHandleGetHTMLInputElementAutoFilled(WKBundleNodeHandleRef)
     124{
     125    ASSERT_NOT_REACHED();
     126    return false;
    126127}
    127128
     
    136137}
    137138
    138 bool WKBundleNodeHandleGetHTMLInputElementAutoFillButtonEnabled(WKBundleNodeHandleRef htmlInputElementHandleRef)
    139 {
    140     return WebKit::toImpl(htmlInputElementHandleRef)->isHTMLInputElementAutoFillButtonEnabled();
     139bool WKBundleNodeHandleGetHTMLInputElementAutoFillButtonEnabled(WKBundleNodeHandleRef)
     140{
     141    ASSERT_NOT_REACHED();
     142    return false;
    141143}
    142144
     
    156158}
    157159
    158 bool WKBundleNodeHandleGetHTMLInputElementAutoFillAvailable(WKBundleNodeHandleRef htmlInputElementHandleRef)
    159 {
    160     return WebKit::toImpl(htmlInputElementHandleRef)->isAutoFillAvailable();
     160bool WKBundleNodeHandleGetHTMLInputElementAutoFillAvailable(WKBundleNodeHandleRef)
     161{
     162    ASSERT_NOT_REACHED();
     163    return false;
    161164}
    162165
     
    166169}
    167170
    168 WKRect WKBundleNodeHandleGetHTMLInputElementAutoFillButtonBounds(WKBundleNodeHandleRef htmlInputElementHandleRef)
    169 {
    170     return WebKit::toAPI(WebKit::toImpl(htmlInputElementHandleRef)->htmlInputElementAutoFillButtonBounds());
     171WKRect WKBundleNodeHandleGetHTMLInputElementAutoFillButtonBounds(WKBundleNodeHandleRef)
     172{
     173    ASSERT_NOT_REACHED();
     174    return { };
    171175}
    172176
     
    181185}
    182186
    183 WKBundleNodeHandleRef WKBundleNodeHandleCopyHTMLTableCellElementCellAbove(WKBundleNodeHandleRef htmlTableCellElementHandleRef)
    184 {
    185     RefPtr<WebKit::InjectedBundleNodeHandle> nodeHandle = WebKit::toImpl(htmlTableCellElementHandleRef)->htmlTableCellElementCellAbove();
    186     return toAPI(nodeHandle.leakRef());
     187WKBundleNodeHandleRef WKBundleNodeHandleCopyHTMLTableCellElementCellAbove(WKBundleNodeHandleRef)
     188{
     189    ASSERT_NOT_REACHED();
     190    return nullptr;
    187191}
    188192
     
    195199WKBundleFrameRef WKBundleNodeHandleCopyHTMLFrameElementContentFrame(WKBundleNodeHandleRef htmlFrameElementHandleRef)
    196200{
    197     RefPtr<WebKit::WebFrame> frame = WebKit::toImpl(htmlFrameElementHandleRef)->htmlFrameElementContentFrame();
    198     return toAPI(frame.leakRef());
     201    ASSERT_NOT_REACHED();
     202    return nullptr;
    199203}
    200204
     
    205209}
    206210
    207 // Deprecated - use WKBundleNodeHandleGetHTMLInputElementAutoFilled(WKBundleNodeHandleRef).
    208211bool WKBundleNodeHandleGetHTMLInputElementAutofilled(WKBundleNodeHandleRef htmlInputElementHandleRef)
    209212{
    210     return WebKit::toImpl(htmlInputElementHandleRef)->isHTMLInputElementAutoFilled();
    211 }
    212 
    213 // Deprecated - use WKBundleNodeHandleSetHTMLInputElementAutoFilled(WKBundleNodeHandleRef, bool).
    214 void WKBundleNodeHandleSetHTMLInputElementAutofilled(WKBundleNodeHandleRef htmlInputElementHandleRef, bool filled)
    215 {
    216     WebKit::toImpl(htmlInputElementHandleRef)->setHTMLInputElementAutoFilled(filled);
    217 }
    218 
    219 // Deprecated - use WKBundleNodeHandleSetHTMLInputElementAutoFillButtonEnabledWithButtonType(WKBundleNodeHandleRef, WKAutoFillButtonType).
    220 void WKBundleNodeHandleSetHTMLInputElementAutoFillButtonEnabled(WKBundleNodeHandleRef htmlInputElementHandleRef, bool enabled)
    221 {
    222     WebCore::AutoFillButtonType autoFillButtonType = enabled ? WebCore::AutoFillButtonType::Credentials : WebCore::AutoFillButtonType::None;
    223 
    224     WebKit::toImpl(htmlInputElementHandleRef)->setHTMLInputElementAutoFillButtonEnabled(autoFillButtonType);
    225 }
     213    ASSERT_NOT_REACHED();
     214    return false;
     215}
     216
     217void WKBundleNodeHandleSetHTMLInputElementAutofilled(WKBundleNodeHandleRef handle, bool enabled)
     218{
     219    WKBundleNodeHandleSetHTMLInputElementAutoFilled(handle, enabled);
     220}
     221
     222void WKBundleNodeHandleSetHTMLInputElementAutoFillButtonEnabled(WKBundleNodeHandleRef, bool)
     223{
     224    // FIXME: Would put ASSERT_NOT_REACHED() here but some compilers are warning the function is "noreturn".
     225}
  • trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm

    r260768 r265044  
    177177WebCore::AttributedString TextCheckingControllerProxy::annotatedSubstringBetweenPositions(const WebCore::VisiblePosition& start, const WebCore::VisiblePosition& end)
    178178{
    179     auto startBoundary = makeBoundaryPoint(start);
    180     auto endBoundary = makeBoundaryPoint(end);
    181     if (!startBoundary || !endBoundary)
     179    auto entireRange = makeSimpleRange(start, end);
     180    if (!entireRange)
    182181        return { };
    183     auto entireRange = SimpleRange { *startBoundary, *endBoundary };
    184182
    185183    auto string = adoptNS([[NSMutableAttributedString alloc] init]);
    186184
    187     for (TextIterator it(entireRange); !it.atEnd(); it.advance()) {
     185    for (TextIterator it(*entireRange); !it.atEnd(); it.advance()) {
    188186        if (!it.text().length())
    189187            continue;
     
    193191            auto& data = WTF::get<DocumentMarker::PlatformTextCheckingData>(marker->data());
    194192            auto subrange = resolveCharacterRange(range, { marker->startOffset(), marker->endOffset() - marker->startOffset() });
    195             [string addAttribute:data.key value:data.value range:characterRange(entireRange, subrange)];
     193            [string addAttribute:data.key value:data.value range:characterRange(*entireRange, subrange)];
    196194        }
    197195    }
  • trunk/Source/WebKit/WebProcess/WebPage/glib/WebPageGLib.cpp

    r264692 r265044  
    4040#include <WebCore/HTMLInputElement.h>
    4141#include <WebCore/HTMLTextAreaElement.h>
     42#include <WebCore/Range.h>
    4243#include <WebCore/TextIterator.h>
    4344#include <WebCore/VisiblePosition.h>
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r264907 r265044  
    115115#import <WebCore/PointerCaptureController.h>
    116116#import <WebCore/Quirks.h>
     117#import <WebCore/Range.h>
    117118#import <WebCore/RenderBlock.h>
    118119#import <WebCore/RenderImage.h>
     
    13751376    GestureRecognizerState wkGestureState = static_cast<GestureRecognizerState>(gestureState);
    13761377    switch (static_cast<GestureType>(gestureType)) {
    1377     case GestureType::PhraseBoundary:
    1378     {
     1378    case GestureType::PhraseBoundary: {
    13791379        if (!frame.editor().hasComposition())
    13801380            break;
     
    42664266
    42674267    auto makeString = [] (const VisiblePosition& start, const VisiblePosition& end) -> AttributedString {
    4268         auto startBoundary = makeBoundaryPoint(start.deepEquivalent());
    4269         auto endBoundary = makeBoundaryPoint(end.deepEquivalent());
    4270         if (!startBoundary || !endBoundary || *startBoundary == *endBoundary)
     4268        auto range = makeSimpleRange(start, end);
     4269        if (!range || range->collapsed())
    42714270            return { };
    42724271        // FIXME: This should return editing-offset-compatible attributed strings if that option is requested.
    4273         return { adoptNS([[NSAttributedString alloc] initWithString:WebCore::plainTextReplacingNoBreakSpace({ WTFMove(*startBoundary), WTFMove(*endBoundary) })]), nil };
     4272        return { adoptNS([[NSAttributedString alloc] initWithString:WebCore::plainTextReplacingNoBreakSpace(*range)]), nil };
    42744273    };
    42754274
     
    43064305    } else if (wantsMarkedTextRects && compositionRange) {
    43074306        unsigned compositionStartOffset = 0;
    4308         if (auto start = makeBoundaryPoint(contextBeforeStart.deepEquivalent()))
    4309             compositionStartOffset = WebCore::plainText({ WTFMove(*start), compositionRange->start }).length();
     4307        if (auto range = makeSimpleRange(contextBeforeStart, compositionRange->start))
     4308            compositionStartOffset = characterCount(*range);
    43104309        context.textRects = characterRectsForRange(*compositionRange, compositionStartOffset);
    43114310    }
  • trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm

    r264247 r265044  
    339339    }
    340340
    341     RefPtr<Range> range = EditingRange::toRange(frame, editingRange);
     341    auto range = EditingRange::toRange(frame, editingRange);
    342342    if (!range) {
    343343        send(Messages::WebPageProxy::AttributedStringForCharacterRangeCallback({ }, EditingRange(), callbackID));
  • trunk/Source/WebKitLegacy/ChangeLog

    r263961 r265044  
     12020-07-29  Darin Adler  <darin@apple.com>
     2
     3        Improve range idioms and other changes to prepare the way for more reduction in live range use
     4        https://bugs.webkit.org/show_bug.cgi?id=214882
     5
     6        Reviewed by Sam Weinig.
     7
     8        * WebKitLegacy.xcodeproj/project.pbxproj: Removed singly-building
     9        DOMUIKitExtensions.mm, which also is built in a unified source file.
     10        We don't need to build it twice.
     11
    1122020-07-05  Commit Queue  <commit-queue@webkit.org>
    213
  • trunk/Source/WebKitLegacy/WebKitLegacy.xcodeproj/project.pbxproj

    r263961 r265044  
    189189                5C97EF632342C534006020D4 /* UnifiedSource19-mm.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C97EF612342C534006020D4 /* UnifiedSource19-mm.mm */; };
    190190                5C97EF642342C534006020D4 /* UnifiedSource20-mm.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C97EF622342C534006020D4 /* UnifiedSource20-mm.mm */; };
    191                 5C9A4E5322DE4627007DB353 /* DOMUIKitExtensions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93D436371D57ABEE00AB85EA /* DOMUIKitExtensions.mm */; };
    192191                5C9D925A22D7E8AD008E9266 /* Sources.txt in Resources */ = {isa = PBXBuildFile; fileRef = 5C9D925822D7E8AD008E9266 /* Sources.txt */; };
    193192                5C9D925B22D7E8AD008E9266 /* SourcesCocoa.txt in Resources */ = {isa = PBXBuildFile; fileRef = 5C9D925922D7E8AD008E9266 /* SourcesCocoa.txt */; };
     
    34013400                                1A60519117502A5D00BC62F5 /* BinaryPropertyList.cpp in Sources */,
    34023401                                B82958D4132707D0000D0E79 /* CorrectionPanel.mm in Sources */,
    3403                                 5C9A4E5322DE4627007DB353 /* DOMUIKitExtensions.mm in Sources */,
    34043402                                1A60519317502A5D00BC62F5 /* HistoryPropertyList.mm in Sources */,
    34053403                                1A8DED510EE88B8A00F25022 /* HostedNetscapePluginStream.mm in Sources */,
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r264905 r265044  
     12020-07-29  Darin Adler  <darin@apple.com>
     2
     3        Improve range idioms and other changes to prepare the way for more reduction in live range use
     4        https://bugs.webkit.org/show_bug.cgi?id=214882
     5
     6        Reviewed by Sam Weinig.
     7
     8        * WebCoreSupport/WebEditorClient.mm:
     9        (insertionPointFromCurrentSelection): Simplify with makeSimpleRange.
     10        (WebEditorClient::requestCandidatesForSelection): Ditto.
     11
     12        * WebView/WebFrame.mm:
     13        (-[WebFrame _convertToDOMRange:rangeIsRelativeTo:]): Get rid of
     14        unnecessary construction of a range just to get an end point.
     15        (-[WebFrame wordOffsetInRange:]): Moved logic here from VisibleSelection.
     16        (-[WebFrame spaceFollowsWordInRange:]): Ditto.
     17
    1182020-07-23  Darin Adler  <darin@apple.com>
    219
  • trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm

    r264905 r265044  
    10261026{
    10271027    auto selectionStart = selection.visibleStart();
    1028     auto selectionStartBoundary = makeBoundaryPoint(selectionStart);
    1029     auto paragraphStart = makeBoundaryPoint(startOfParagraph(selectionStart));
    1030     if (!selectionStartBoundary || !paragraphStart)
     1028    auto range = makeSimpleRange(startOfParagraph(selectionStart), selectionStart);
     1029    if (!range)
    10311030        return 0;
    1032     return characterCount({ *paragraphStart, *selectionStartBoundary });
     1031    return characterCount(*range);
    10331032}
    10341033
     
    11111110
    11121111    auto selectionStart = selection.visibleStart();
    1113     auto selectionStartOffsetInParagraph = characterCount({ *makeBoundaryPoint(startOfParagraph(selectionStart)), *makeBoundaryPoint(selectionStart) });
    1114     auto selectionLength = characterCount({ *makeBoundaryPoint(selectionStart), *makeBoundaryPoint(selection.visibleEnd()) });
     1112    auto selectionStartOffsetInParagraph = characterCount(*makeSimpleRange(startOfParagraph(selectionStart), selectionStart));
     1113    auto selectionLength = characterCount(*makeSimpleRange(selectionStart, selection.visibleEnd()));
    11151114    auto contextRangeForCandidateRequest = frame->editor().contextRangeForCandidateRequest();
    11161115    String contextForCandidateReqeuest = contextRangeForCandidateRequest ? plainText(*contextRangeForCandidateRequest) : String();
  • trunk/Source/WebKitLegacy/mac/WebView/WebFrame.mm

    r264692 r265044  
    838838        return nullptr;
    839839
    840     auto scopeEnd = makeRangeSelectingNodeContents(paragraphStart->container->treeScope().rootNode()).end;
     840    auto scopeEnd = makeBoundaryPointAfterNodeContents(paragraphStart->container->treeScope().rootNode());
    841841    return createLiveRange(WebCore::resolveCharacterRange({ WTFMove(*paragraphStart), WTFMove(scopeEnd) }, range));
    842842}
     
    15411541- (int)wordOffsetInRange:(DOMRange *)range
    15421542{
    1543     return core(self)->selection().wordOffsetInRange(core(range));
     1543    if (!range)
     1544        return -1;
     1545
     1546    auto selection = core(self)->selection().selection();
     1547    if (!selection.isCaret())
     1548        return -1;
     1549
     1550    // FIXME: This will only work in cases where the selection remains in the same node after it is expanded.
     1551    return std::max<int>(0, selection.start().deprecatedEditingOffset() - core(range)->startOffset());
    15441552}
    15451553
    15461554- (BOOL)spaceFollowsWordInRange:(DOMRange *)range
    15471555{
    1548     return core(self)->selection().spaceFollowsWordInRange(core(range));
     1556    return range && isSpaceOrNewline(WebCore::VisiblePosition(createLegacyEditingPosition(makeSimpleRange(core(range))->end)).characterAfter());
    15491557}
    15501558
  • trunk/Source/WebKitLegacy/win/AccessibleTextImpl.cpp

    r238454 r265044  
    9999        return E_POINTER;
    100100
    101     IntRect boundingRect = m_object->boundsForVisiblePositionRange(VisiblePositionRange(VisiblePosition(Position(node, offset, Position::PositionIsOffsetInAnchor)), VisiblePosition(Position(node, offset+1, Position::PositionIsOffsetInAnchor))));
     101    IntRect boundingRect = m_object->boundsForVisiblePositionRange({
     102        VisiblePosition(Position(node, offset, Position::PositionIsOffsetInAnchor)),
     103        VisiblePosition(Position(node, offset + 1, Position::PositionIsOffsetInAnchor))
     104    });
    102105    *width = boundingRect.width();
    103106    *height = boundingRect.height();
Note: See TracChangeset for help on using the changeset viewer.