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

Changeset 265084 in webkit


Ignore:
Timestamp:
Jul 30, 2020, 9:17:17 AM (6 years ago)
Author:
Darin Adler
Message:

Further reduction in the use of live ranges, particularly in headers
​https://bugs.webkit.org/show_bug.cgi?id=214793

Reviewed by Sam Weinig.

Source/WebCore:

  • accessibility/AccessibilityObject.cpp:

(WebCore::AccessibilityObject::performTextOperation): Do not call createLiveRange.
(WebCore::AccessibilityObject::replaceTextInRange): Ditto.

  • dom/SimpleRange.cpp: Moved makeSimpleRange functions to the header.
  • dom/SimpleRange.h: Reworked the makeSimpleRange implementation to avoid a mistake

which made template expansion infinitely recurse while compiling and crash the compiler.
Ended up moving all the code to the header. Should be a good thing; I expect it will
optimize well inlined.

  • editing/CompositeEditCommand.cpp:

(WebCore::CompositeEditCommand::moveParagraphs): Use makeSimpleRange.

  • editing/Editor.cpp:

(WebCore::Editor::replaceSelectionWithText): Do not call createLiveRange.
(WebCore::Editor::setComposition): Use SimpleRange.
(WebCore::Editor::stringForCandidateRequest const): Do not call createLiveRange.
(WebCore::Editor::handleAcceptedCandidate): Use auto intead of RefPtr<Range>.

  • editing/EditorCommand.cpp:

(WebCore::expandSelectionToGranularity): Do not call createLiveRange.
(WebCore::executeDeleteToMark): Ditto.
(WebCore::executeSelectToMark): Ditto.
(WebCore::valueFormatBlock): Ditto.

  • editing/FormatBlockCommand.cpp:

(WebCore::FormatBlockCommand::formatRange): Use makeSimpleRange.
(WebCore::FormatBlockCommand::elementForFormatBlockCommand): Take a
SimpleRange.

  • editing/FormatBlockCommand.h: Updated for above.
  • editing/FrameSelection.cpp:

(WebCore::FrameSelection::moveTo): Deleted overload taking a live range.
(WebCore::FrameSelection::setSelectedRange): Take a SimpleRange.

  • editing/FrameSelection.h: Updated for above.
  • editing/ReplaceSelectionCommand.cpp:

(WebCore::ReplacementFragment::ReplacementFragment): Do not call
createLiveRange.

  • editing/VisibleUnits.cpp:

(WebCore::enclosingTextUnitOfGranularity): Return SimpleRange.
(WebCore::wordRangeFromPosition): Ditto.
(WebCore::closestWordBoundaryForPosition): Use SimpleRange.
(WebCore::rangeExpandedByCharactersInDirectionAtWordBoundary): Return
a SimpleRange.
(WebCore::rangeExpandedAroundPositionByCharacters): Ditto.
(WebCore::wordBoundaryForPositionWithoutCrossingLine): Use SimpleRange.

  • editing/VisibleUnits.h: Updated for above.
  • editing/cocoa/DataDetection.mm:

(WebCore::DataDetection::detectItemAroundHitTestResult):
Use SimpleRange.

  • editing/cocoa/DictionaryLookup.mm:

(WebCore::DictionaryLookup::rangeForSelection): Use SimpleRange.
(WebCore::DictionaryLookup::rangeAtHitTestResult): Ditto.

  • editing/cocoa/EditorCocoa.mm:

(WebCore::Editor::getPasteboardTypesAndDataForAttachment):
Do not call createLiveRange.

  • editing/cocoa/WebContentReaderCocoa.mm:

(WebCore::WebContentReader::readPlainText): Ditto.

  • editing/gtk/WebContentReaderGtk.cpp:

(WebCore::WebContentReader::readPlainText): Ditto.

  • editing/libwpe/EditorLibWPE.cpp:

(WebCore::createFragmentFromPasteboardData): Ditto.

  • editing/mac/DictionaryLookupLegacy.mm:

(WebCore::DictionaryLookup::rangeAtHitTestResult): Use SimpleRange.

  • editing/markup.cpp:

(WebCore::serializePreservingVisualAppearance): Take SimpleRange.
(WebCore::contextPreservesNewline): Ditto.
(WebCore::createFragmentFromText): Ditto.

  • editing/markup.h: Updated for above.
  • loader/archive/cf/LegacyWebArchive.cpp:

(WebCore::LegacyWebArchive::create): Take SimpleRange.

  • loader/archive/cf/LegacyWebArchive.h: Updated for above.
  • page/DragController.cpp:

(WebCore::DragController::performDragOperation): Use SimpleRange.
(WebCore::DragController::concludeEditDrag): Do not call createLiveRange.
(WebCore::selectElement): Use SimpleRange.
(WebCore::DragController::removeAllDroppedImagePlaceholders): Ditto.
(WebCore::DragController::insertDroppedImagePlaceholdersAtCaret): Ditto.

  • page/DragController.h: Use SimpleRange.
  • page/Page.cpp:

(WebCore::Page::findTextMatches): Return vector of SimpleRange, in
structure so we have one return value instead of two out arguments.
Also renamed from findStringMatchingRanges.
(WebCore::Page::rangeOfString): Return SimpleRange.
(WebCore::replaceRanges): Do not call createLiveRange.
(WebCore::Page::replaceRangesWithText): Take SimpleRange.

  • page/Page.h: Updated for above.
  • page/ios/FrameIOS.mm:

(WebCore::Frame::wordsInCurrentParagraph const): Use SimpleRange.

  • rendering/HitTestResult.cpp:

(WebCore::HitTestResult::isOverTextInsideFormControlElement const):
Use SimpleRange, and also use hasAnyPlainText instead of computing
the plain text string and checking if it's empty.

Source/WebKit:

  • Shared/API/c/mac/WKWebArchiveRef.cpp:

(WKWebArchiveCreateFromRange): Use makeSimpleRange.

  • Shared/APIWebArchive.h: Use SimpleRange.
  • Shared/APIWebArchive.mm:

(API::WebArchive::create): Take SimpleRange.

  • Shared/EditingRange.cpp:

(WebKit::EditingRange::toRange): Don't call createLiveRange.
(WebKit::EditingRange::fromRange): Take SimpleRange.

  • Shared/EditingRange.h: Updated for above.
  • WebProcess/InjectedBundle/API/APIInjectedBundleEditorClient.h:

Take SimpleRange, String, StyleProperties instead of
Range, StringImpl, CSSStyleDeclaration.

  • WebProcess/InjectedBundle/API/glib/WebKitWebEditor.cpp:

String instead of StringImpl.

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

(-[WKDOMDocument createDocumentFragmentWithText:]): Use SimpleRange.

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

(-[WKDOMRange rangeByExpandingToWordBoundaryByCharacters:inDirection:]):
Use SimpleRange and createLiveRange.

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

(-[WKWebProcessPlugInBrowserContextController _setEditingDelegate:]):
Updated for changes to bundle editor client.

  • WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp:

(WebKit::InjectedBundleRangeHandle::create): Deleted. Moved the
code into InjectedBundleRangeHandle::getOrCreate.
(WebKit::createHandle): Added. Makes a handle for a SimpleRange.

  • WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h:

Updated for above.

  • WebProcess/InjectedBundle/InjectedBundlePageEditorClient.cpp:

(WebKit::createHandle): Added. Makes a handle for a CSSStyleDeclaration.
(WebKit::InjectedBundlePageEditorClient::shouldBeginEditing):
Updated for changes to bundle editor client.
(WebKit::InjectedBundlePageEditorClient::shouldEndEditing): Ditto.
(WebKit::InjectedBundlePageEditorClient::shouldInsertNode): Ditto.
(WebKit::InjectedBundlePageEditorClient::shouldInsertText): Ditto.
(WebKit::InjectedBundlePageEditorClient::shouldDeleteRange): Ditto.
(WebKit::InjectedBundlePageEditorClient::shouldChangeSelectedRange): Ditto.
(WebKit::InjectedBundlePageEditorClient::shouldApplyStyle): Ditto.
(WebKit::InjectedBundlePageEditorClient::didBeginEditing): Ditto.
(WebKit::InjectedBundlePageEditorClient::didEndEditing): Ditto.
(WebKit::InjectedBundlePageEditorClient::didChange): Ditto.
(WebKit::InjectedBundlePageEditorClient::didChangeSelection): Ditto.
(WebKit::InjectedBundlePageEditorClient::willWriteToPasteboard): Ditto.
(WebKit::InjectedBundlePageEditorClient::getPasteboardDataForRange): Ditto.
(WebKit::InjectedBundlePageEditorClient::performTwoStepDrop): Ditto.

  • WebProcess/InjectedBundle/InjectedBundlePageEditorClient.h:

Updated for above.

  • WebProcess/WebCoreSupport/WebEditorClient.cpp:

(WebKit::WebEditorClient::shouldDeleteRange): Updated to call new
revised bundle editor client.
(WebKit::WebEditorClient::shouldBeginEditing): Ditto.
(WebKit::WebEditorClient::shouldEndEditing): Ditto.
(WebKit::WebEditorClient::shouldInsertNode): Ditto.
(WebKit::WebEditorClient::shouldInsertText): Ditto.
(WebKit::WebEditorClient::shouldChangeSelectedRange): Ditto.
(WebKit::WebEditorClient::shouldApplyStyle): Ditto.
(WebKit::WebEditorClient::willWriteSelectionToPasteboard): Ditto.
(WebKit::WebEditorClient::getClientPasteboardData): Ditto.
(WebKit::WebEditorClient::performTwoStepDrop): Ditto.
(WebKit::insertionPointFromCurrentSelection): Use SimpleRange.

  • WebProcess/WebPage/FindController.cpp:

(WebKit::FindController::replaceMatches): Use SimpleRange.
(WebKit::FindController::findString): Updated for change to
Page::findTextMatches function.
(WebKit::FindController::findStringMatches): Ditto.
(WebKit::FindController::getImageForFindMatch): Use SimpleRange.
(WebKit::FindController::selectFindMatch): Ditto.

  • WebProcess/WebPage/FindController.h: Updated for above.
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::getMarkedRangeAsync): Do not call createLiveRange.
(WebKit::WebPage::getSelectedRangeAsync): Ditto.
(WebKit::WebPage::characterIndexForPointAsync): Call makeSimpleRange.

  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::plainTextForContext): Changed overloads a bit to work
better with Optional<SimpleRange> and removed the ones that explicitly
take a Range, updating callers to compensate.
(WebKit::plainTextForDisplay): Ditto.
(WebKit::WebPage::getPlatformEditorState const): Use SimpleRange.
(WebKit::WebPage::getSelectionContext): Ditto.
(WebKit::WebPage::didConcludeEditDrag): Ditto.
(WebKit::WebPage::handleStylusSingleTapAtPoint): Ditto.
(WebKit::WebPage::selectWithGesture): Ditto.
(WebKit::rangeForPointInRootViewCoordinates): Return SimpleRange.
(WebKit::rangeAtWordBoundaryForPosition): Ditto.
(WebKit::WebPage::updateSelectionWithTouches): Use SimpleRange.
(WebKit::WebPage::selectWithTwoTouches): Ditto.
(WebKit::WebPage::extendSelection): Ditto.
(WebKit::WebPage::selectWordBackward): Ditto.
(WebKit::WebPage::moveSelectionByOffset): Ditto.
(WebKit::WebPage::getRectsForGranularityWithSelectionOffset): Ditto.
(WebKit::WebPage::selectPositionAtPoint): Ditto.
(WebKit::WebPage::selectPositionAtBoundaryWithDirection): Ditto.
(WebKit::WebPage::moveSelectionAtBoundaryWithDirection): Ditto.
(WebKit::WebPage::rangeForGranularityAtPoint): Ditto.
(WebKit::WebPage::selectTextWithGranularityAtPoint): Ditto.
(WebKit::WebPage::updateSelectionWithExtentPointAndBoundary): Ditto.
(WebKit::WebPage::updateSelectionWithExtentPoint): Ditto.
(WebKit::WebPage::replaceSelectedText): Ditto.
(WebKit::WebPage::replaceDictatedText): Ditto.
(WebKit::WebPage::requestAutocorrectionData): Ditto.
(WebKit::WebPage::applyAutocorrectionInternal): Ditto.
(WebKit::WebPage::autocorrectionContext): Ditto.
(WebKit::dataDetectorLinkPositionInformation): Ditto.
(WebKit::WebPage::updateSelectionWithDelta): Ditto.
(WebKit::WebPage::focusTextInputContextAndPlaceCaret): Ditto.

Source/WebKitLegacy/ios:

  • WebCoreSupport/WebVisiblePosition.mm:

(-[WebVisiblePosition enclosingTextUnitOfGranularity:inDirectionIfAtBoundary:]):
Use SimpleRange.

Source/WebKitLegacy/mac:

  • DOM/DOMHTML.mm:

(-[DOMHTMLDocument createDocumentFragmentWithText:]): Use SimpleRange.

  • DOM/DOMUIKitExtensions.mm:

(-[DOMRange move:inDirection:]): Ditto.
(-[DOMRange extend:inDirection:]): Ditto.

  • DOM/WebDOMOperations.mm:

(-[DOMRange webArchive]): Ditto.

  • WebView/WebFrame.mm:

(-[WebFrame _firstRectForDOMRange:]): Moved a "*" to save a little work.
(-[WebFrame setSelectedDOMRange:affinity:closeTyping:userTriggered:]):
Use SimpleRange.
(-[WebFrame _replaceSelectionWithText:selectReplacement:smartReplace:matchStyle:]):
Ditto.
(-[WebFrame _replaceSelectionWithText:selectReplacement:smartReplace:]):
Ditto.
(-[WebFrame _documentFragmentForText:]): Ditto.

  • WebView/WebView.mm:

(-[WebView DOMRangeOfString:relativeTo:options:]): Ditto.
(-[WebView setSelectedDOMRange:affinity:]): Ditto.

Source/WebKitLegacy/win:

  • AccessibleTextImpl.cpp: Added an include of Range.h.
Location:
trunk/Source
Files:
61 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r265079 r265084  
     12020-07-30  Darin Adler  <darin@apple.com>
     2
     3        Further reduction in the use of live ranges, particularly in headers
     4        https://bugs.webkit.org/show_bug.cgi?id=214793
     5
     6        Reviewed by Sam Weinig.
     7
     8        * accessibility/AccessibilityObject.cpp:
     9        (WebCore::AccessibilityObject::performTextOperation): Do not call createLiveRange.
     10        (WebCore::AccessibilityObject::replaceTextInRange): Ditto.
     11
     12        * dom/SimpleRange.cpp: Moved makeSimpleRange functions to the header.
     13        * dom/SimpleRange.h: Reworked the makeSimpleRange implementation to avoid a mistake
     14        which made template expansion infinitely recurse while compiling and crash the compiler.
     15        Ended up moving all the code to the header. Should be a good thing; I expect it will
     16        optimize well inlined.
     17
     18        * editing/CompositeEditCommand.cpp:
     19        (WebCore::CompositeEditCommand::moveParagraphs): Use makeSimpleRange.
     20
     21        * editing/Editor.cpp:
     22        (WebCore::Editor::replaceSelectionWithText): Do not call createLiveRange.
     23        (WebCore::Editor::setComposition): Use SimpleRange.
     24        (WebCore::Editor::stringForCandidateRequest const): Do not call createLiveRange.
     25        (WebCore::Editor::handleAcceptedCandidate): Use auto intead of RefPtr<Range>.
     26
     27        * editing/EditorCommand.cpp:
     28        (WebCore::expandSelectionToGranularity): Do not call createLiveRange.
     29        (WebCore::executeDeleteToMark): Ditto.
     30        (WebCore::executeSelectToMark): Ditto.
     31        (WebCore::valueFormatBlock): Ditto.
     32
     33        * editing/FormatBlockCommand.cpp:
     34        (WebCore::FormatBlockCommand::formatRange): Use makeSimpleRange.
     35        (WebCore::FormatBlockCommand::elementForFormatBlockCommand): Take a
     36        SimpleRange.
     37        * editing/FormatBlockCommand.h: Updated for above.
     38
     39        * editing/FrameSelection.cpp:
     40        (WebCore::FrameSelection::moveTo): Deleted overload taking a live range.
     41        (WebCore::FrameSelection::setSelectedRange): Take a SimpleRange.
     42        * editing/FrameSelection.h: Updated for above.
     43
     44        * editing/ReplaceSelectionCommand.cpp:
     45        (WebCore::ReplacementFragment::ReplacementFragment): Do not call
     46        createLiveRange.
     47
     48        * editing/VisibleUnits.cpp:
     49        (WebCore::enclosingTextUnitOfGranularity): Return SimpleRange.
     50        (WebCore::wordRangeFromPosition): Ditto.
     51        (WebCore::closestWordBoundaryForPosition): Use SimpleRange.
     52        (WebCore::rangeExpandedByCharactersInDirectionAtWordBoundary): Return
     53        a SimpleRange.
     54        (WebCore::rangeExpandedAroundPositionByCharacters): Ditto.
     55        (WebCore::wordBoundaryForPositionWithoutCrossingLine): Use SimpleRange.
     56        * editing/VisibleUnits.h: Updated for above.
     57
     58        * editing/cocoa/DataDetection.mm:
     59        (WebCore::DataDetection::detectItemAroundHitTestResult):
     60        Use SimpleRange.
     61
     62        * editing/cocoa/DictionaryLookup.mm:
     63        (WebCore::DictionaryLookup::rangeForSelection): Use SimpleRange.
     64        (WebCore::DictionaryLookup::rangeAtHitTestResult): Ditto.
     65
     66        * editing/cocoa/EditorCocoa.mm:
     67        (WebCore::Editor::getPasteboardTypesAndDataForAttachment):
     68        Do not call createLiveRange.
     69        * editing/cocoa/WebContentReaderCocoa.mm:
     70        (WebCore::WebContentReader::readPlainText): Ditto.
     71        * editing/gtk/WebContentReaderGtk.cpp:
     72        (WebCore::WebContentReader::readPlainText): Ditto.
     73        * editing/libwpe/EditorLibWPE.cpp:
     74        (WebCore::createFragmentFromPasteboardData): Ditto.
     75
     76        * editing/mac/DictionaryLookupLegacy.mm:
     77        (WebCore::DictionaryLookup::rangeAtHitTestResult): Use SimpleRange.
     78
     79        * editing/markup.cpp:
     80        (WebCore::serializePreservingVisualAppearance): Take SimpleRange.
     81        (WebCore::contextPreservesNewline): Ditto.
     82        (WebCore::createFragmentFromText): Ditto.
     83        * editing/markup.h: Updated for above.
     84
     85        * loader/archive/cf/LegacyWebArchive.cpp:
     86        (WebCore::LegacyWebArchive::create): Take SimpleRange.
     87        * loader/archive/cf/LegacyWebArchive.h: Updated for above.
     88
     89        * page/DragController.cpp:
     90        (WebCore::DragController::performDragOperation): Use SimpleRange.
     91        (WebCore::DragController::concludeEditDrag): Do not call createLiveRange.
     92        (WebCore::selectElement): Use SimpleRange.
     93        (WebCore::DragController::removeAllDroppedImagePlaceholders): Ditto.
     94        (WebCore::DragController::insertDroppedImagePlaceholdersAtCaret): Ditto.
     95
     96        * page/DragController.h: Use SimpleRange.
     97
     98        * page/Page.cpp:
     99        (WebCore::Page::findTextMatches): Return vector of SimpleRange, in
     100        structure so we have one return value instead of two out arguments.
     101        Also renamed from findStringMatchingRanges.
     102        (WebCore::Page::rangeOfString): Return SimpleRange.
     103        (WebCore::replaceRanges): Do not call createLiveRange.
     104        (WebCore::Page::replaceRangesWithText): Take SimpleRange.
     105        * page/Page.h: Updated for above.
     106
     107        * page/ios/FrameIOS.mm:
     108        (WebCore::Frame::wordsInCurrentParagraph const): Use SimpleRange.
     109
     110        * rendering/HitTestResult.cpp:
     111        (WebCore::HitTestResult::isOverTextInsideFormControlElement const):
     112        Use SimpleRange, and also use hasAnyPlainText instead of computing
     113        the plain text string and checking if it's empty.
     114
    11152020-07-30  Brady Eidson  <beidson@apple.com>
    2116
  • trunk/Source/WebCore/accessibility/AccessibilityObject.cpp

    r265044 r265084  
    723723
    724724    for (const auto& textRange : operation.textRanges) {
    725         if (!frame->selection().setSelectedRange(createLiveRange(textRange).ptr(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes))
     725        if (!frame->selection().setSelectedRange(textRange, DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes))
    726726            continue;
    727727
    … …  
    20132013    auto& frame = renderer()->frame();
    20142014    if (element.shouldUseInputMethod()) {
    2015         frame.selection().setSelectedRange(createLiveRange(rangeForPlainTextRange(range)).get(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes);
     2015        frame.selection().setSelectedRange(rangeForPlainTextRange(range), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes);
    20162016        frame.editor().replaceSelectionWithText(replacementString, Editor::SelectReplacement::No, Editor::SmartReplace::No);
    20172017        return true;
  • trunk/Source/WebCore/dom/SimpleRange.cpp

    r265044 r265084  
    8383}
    8484
    85 Optional<SimpleRange> makeSimpleRange(const Optional<BoundaryPoint>& point)
    86 {
    87     if (!point)
    88         return WTF::nullopt;
    89     return { { *point, *point } };
    90 }
    91 
    92 Optional<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 
    100 Optional<SimpleRange> makeSimpleRange(const Optional<BoundaryPoint>& start, const Optional<BoundaryPoint>& end)
    101 {
    102     if (!start || !end)
    103         return WTF::nullopt;
    104     return { { *start, *end } };
    105 }
    106 
    107 Optional<SimpleRange> makeSimpleRange(Optional<BoundaryPoint>&& start, Optional<BoundaryPoint>&& end)
    108 {
    109     if (!start || !end)
    110         return WTF::nullopt;
    111     return { { WTFMove(*start), WTFMove(*end) } };
    112 }
    113 
    11485SimpleRange makeRangeSelectingNodeContents(Node& node)
    11586{
  • trunk/Source/WebCore/dom/SimpleRange.h

    r265044 r265084  
    5252};
    5353
    54 SimpleRange makeSimpleRange(const BoundaryPoint&);
    55 SimpleRange makeSimpleRange(BoundaryPoint&&);
    56 SimpleRange makeSimpleRange(const BoundaryPoint&, const BoundaryPoint&);
    57 SimpleRange makeSimpleRange(BoundaryPoint&&, BoundaryPoint&&);
    58 Optional<SimpleRange> makeSimpleRange(const Optional<BoundaryPoint>&);
    59 WEBCORE_EXPORT Optional<SimpleRange> makeSimpleRange(Optional<BoundaryPoint>&&);
    60 WEBCORE_EXPORT Optional<SimpleRange> makeSimpleRange(const Optional<BoundaryPoint>&, const Optional<BoundaryPoint>&);
    61 WEBCORE_EXPORT Optional<SimpleRange> makeSimpleRange(Optional<BoundaryPoint>&&, Optional<BoundaryPoint>&&);
     54SimpleRange makeSimpleRangeHelper(BoundaryPoint&&, BoundaryPoint&&);
     55Optional<SimpleRange> makeSimpleRangeHelper(Optional<BoundaryPoint>&&, Optional<BoundaryPoint>&&);
     56SimpleRange makeSimpleRangeHelper(BoundaryPoint&&);
     57Optional<SimpleRange> makeSimpleRangeHelper(Optional<BoundaryPoint>&&);
    6258
    6359inline BoundaryPoint makeBoundaryPointHelper(const BoundaryPoint& point) { return point; }
    6460inline BoundaryPoint makeBoundaryPointHelper(BoundaryPoint&& point) { return WTFMove(point); }
    65 template<typename T> auto makeBoundaryPointHelper(T&& argument) -> decltype(makeBoundaryPoint(std::forward<T>(argument)))
    66 {
    67     return makeBoundaryPoint(std::forward<T>(argument));
    68 }
     61inline Optional<BoundaryPoint> makeBoundaryPointHelper(const Optional<BoundaryPoint>& point) { return point; }
     62inline Optional<BoundaryPoint> makeBoundaryPointHelper(Optional<BoundaryPoint>&& point) { return WTFMove(point); }
     63template<typename T> auto makeBoundaryPointHelper(T&& argument) -> decltype(makeBoundaryPoint(std::forward<T>(argument))) { return makeBoundaryPoint(std::forward<T>(argument)); }
    6964
    70 template<typename ...T> auto makeSimpleRange(T&& ...arguments) -> decltype(makeSimpleRange(makeBoundaryPointHelper(std::forward<T>(arguments))...))
    71 {
    72     return makeSimpleRange(makeBoundaryPointHelper(std::forward<T>(arguments))...);
    73 }
     65template<typename ...T> auto makeSimpleRange(T&& ...arguments) -> decltype(makeSimpleRangeHelper(makeBoundaryPointHelper(std::forward<T>(arguments))...)) { return makeSimpleRangeHelper(makeBoundaryPointHelper(std::forward<T>(arguments))...); }
    7466
    7567// FIXME: Would like these to have shorter names; another option is to change prefix to makeSimpleRange.
    … …  
    136128}
    137129
     130inline SimpleRange makeSimpleRangeHelper(BoundaryPoint&& start, BoundaryPoint&& end)
     131{
     132    return { WTFMove(start), WTFMove(end) };
    138133}
     134
     135inline Optional<SimpleRange> makeSimpleRangeHelper(Optional<BoundaryPoint>&& start, Optional<BoundaryPoint>&& end)
     136{
     137    if (!start || !end)
     138        return WTF::nullopt;
     139    return makeSimpleRangeHelper(WTFMove(*start), WTFMove(*end));
     140}
     141
     142inline SimpleRange makeSimpleRangeHelper(BoundaryPoint&& point)
     143{
     144    auto end = point;
     145    return makeSimpleRangeHelper(WTFMove(point), WTFMove(end));
     146}
     147
     148inline Optional<SimpleRange> makeSimpleRangeHelper(Optional<BoundaryPoint>&& point)
     149{
     150    if (!point)
     151        return WTF::nullopt;
     152    return makeSimpleRangeHelper(WTFMove(*point));
     153}
     154
     155}
  • trunk/Source/WebCore/editing/CompositeEditCommand.cpp

    r265044 r265084  
    5656#include "MergeIdenticalElementsCommand.h"
    5757#include "NodeTraversal.h"
    58 #include "Range.h"
    5958#include "RemoveNodeCommand.h"
    6059#include "RemoveNodePreservingChildrenCommand.h"
    … …  
    14411440    Position end = endOfParagraphToMove.deepEquivalent().upstream();
    14421441     
    1443     // start and end can't be used directly to create a Range; they are "editing positions"
    1444     Position startRangeCompliant = start.parentAnchoredEquivalent();
    1445     Position endRangeCompliant = end.parentAnchoredEquivalent();
    1446     auto range = Range::create(document(), startRangeCompliant.deprecatedNode(), startRangeCompliant.deprecatedEditingOffset(), endRangeCompliant.deprecatedNode(), endRangeCompliant.deprecatedEditingOffset());
    1447 
    14481442    // FIXME: This is an inefficient way to preserve style on nodes in the paragraph to move. It
    14491443    // shouldn't matter though, since moved paragraphs will usually be quite small.
    14501444    RefPtr<DocumentFragment> fragment;
    1451     // This used to use a ternary for initialization, but that confused some versions of GCC, see bug 37912
    14521445    if (startOfParagraphToMove != endOfParagraphToMove)
    1453         fragment = createFragmentFromMarkup(document(), serializePreservingVisualAppearance(range.get(), nullptr, AnnotateForInterchange::No, ConvertBlocksToInlines::Yes), emptyString());
     1446        fragment = createFragmentFromMarkup(document(), serializePreservingVisualAppearance(*makeSimpleRange(start, end), nullptr, AnnotateForInterchange::No, ConvertBlocksToInlines::Yes), emptyString());
    14541447
    14551448    // A non-empty paragraph's style is moved when we copy and move it.  We don't move
  • trunk/Source/WebCore/editing/Editor.cpp

    r265059 r265084  
    726726        return;
    727727
    728     replaceSelectionWithFragment(createFragmentFromText(createLiveRange(*range), text), selectReplacement, smartReplace, MatchStyle::Yes, editingAction);
     728    replaceSelectionWithFragment(createFragmentFromText(*range, text), selectReplacement, smartReplace, MatchStyle::Yes, editingAction);
    729729}
    730730
    … …  
    21212121            unsigned start = std::min(baseOffset + selectionStart, extentOffset);
    21222122            unsigned end = std::min(std::max(start, baseOffset + selectionEnd), extentOffset);
    2123             auto selectedRange = Range::create(baseNode->document(), baseNode, start, baseNode, end);
    2124             m_document.selection().setSelectedRange(selectedRange.ptr(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::No);
     2123            auto range = SimpleRange { { *baseNode, start }, { *baseNode, end } };
     2124            m_document.selection().setSelectedRange(range, DOWNSTREAM, FrameSelection::ShouldCloseTyping::No);
    21252125        }
    21262126    }
    … …  
    38943894    auto& selection = m_document.selection().selection();
    38953895    auto range = selection.isCaret()
    3896     ? wordRangeFromPosition(selection.start())
    3897     : createLiveRange(selection.toNormalizedRange());
     3896        ? wordRangeFromPosition(selection.start())
     3897        : selection.toNormalizedRange();
    38983898    if (!range)
    38993899        return { };
    … …  
    41944194        insertText(acceptedCandidate.replacement, nullptr);
    41954195
    4196     RefPtr<Range> insertedCandidateRange = rangeExpandedByCharactersInDirectionAtWordBoundary(selection.visibleStart(), acceptedCandidate.replacement.length(), SelectionDirection::Backward);
    4197     if (insertedCandidateRange)
     4196    if (auto insertedCandidateRange = rangeExpandedByCharactersInDirectionAtWordBoundary(selection.visibleStart(), acceptedCandidate.replacement.length(), SelectionDirection::Backward))
    41984197        addMarker(*insertedCandidateRange, DocumentMarker::AcceptedCandidate, acceptedCandidate.replacement);
    41994198
  • trunk/Source/WebCore/editing/EditorCommand.cpp

    r264692 r265084  
    185185    if (!frame.editor().client()->shouldChangeSelectedRange(*oldRange, *newRange, affinity, false))
    186186        return false;
    187     frame.selection().setSelectedRange(createLiveRange(*newRange).ptr(), affinity, FrameSelection::ShouldCloseTyping::Yes);
     187    frame.selection().setSelectedRange(*newRange, affinity, FrameSelection::ShouldCloseTyping::Yes);
     188    // FIXME: Why do we ignore the return value from setSelectedRange here?
    188189    return true;
    189190}
    … …  
    355356    auto& selection = frame.selection();
    356357    if (mark && frame.editor().selectedRange()) {
    357         bool selected = selection.setSelectedRange(createLiveRange(unionRanges(*mark, *frame.editor().selectedRange())).ptr(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes);
    358         ASSERT(selected);
    359         if (!selected)
     358        if (!selection.setSelectedRange(unionRanges(*mark, *frame.editor().selectedRange()), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes))
    360359            return false;
    361360    }
    … …  
    10571056        return false;
    10581057    }
    1059     frame.selection().setSelectedRange(createLiveRange(unionRanges(*mark, *selection)).ptr(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes);
     1058    frame.selection().setSelectedRange(unionRanges(*mark, *selection), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes);
     1059    // FIXME: Why do we ignore the return value from setSelectedRange here?
    10601060    return true;
    10611061}
    … …  
    15721572    if (selection.isNoneOrOrphaned() || !selection.isContentEditable())
    15731573        return emptyString();
    1574     auto* formatBlockElement = FormatBlockCommand::elementForFormatBlockCommand(createLiveRange(selection.firstRange()).get());
     1574    auto* formatBlockElement = FormatBlockCommand::elementForFormatBlockCommand(selection.firstRange());
    15751575    if (!formatBlockElement)
    15761576        return emptyString();
  • trunk/Source/WebCore/editing/FormatBlockCommand.cpp

    r239535 r265084  
    3232#include "HTMLElement.h"
    3333#include "HTMLNames.h"
    34 #include "Range.h"
    3534#include "VisibleUnits.h"
    3635#include <wtf/NeverDestroyed.h>
    … …  
    6968    RefPtr<Node> nodeAfterInsertionPosition = outerBlock;
    7069
    71     auto range = Range::create(document(), start, endOfSelection);
     70    auto range = makeSimpleRange(start, endOfSelection);
    7271    Element* refNode = enclosingBlockFlowElement(end);
    7372    Element* root = editableRootForPosition(start);
    … …  
    7675        return;
    7776    if (isElementForFormatBlock(refNode->tagQName()) && start == startOfBlock(start)
    78         && (end == endOfBlock(end) || isNodeVisiblyContainedWithin(*refNode, range.get()))
     77        && (end == endOfBlock(end) || (range && isNodeVisiblyContainedWithin(*refNode, *range)))
    7978        && refNode != root && !root->isDescendantOf(*refNode)) {
    8079        // Already in a block element that only contains the current paragraph
    … …  
    10099}
    101100   
    102 Element* FormatBlockCommand::elementForFormatBlockCommand(Range* range)
     101Element* FormatBlockCommand::elementForFormatBlockCommand(const Optional<SimpleRange>& range)
    103102{
    104103    if (!range)
    105104        return nullptr;
    106105
    107     Node* commonAncestor = range->commonAncestorContainer();
    108     while (commonAncestor && !isElementForFormatBlock(commonAncestor))
     106    auto commonAncestor = commonInclusiveAncestor(*range);
     107    while (commonAncestor && !isElementForFormatBlock(commonAncestor.get()))
    109108        commonAncestor = commonAncestor->parentNode();
    110 
    111     if (!commonAncestor)
     109    if (!is<Element>(commonAncestor))
    112110        return nullptr;
    113111
    114     Element* rootEditableElement = range->startContainer().rootEditableElement();
     112    auto rootEditableElement = range->start.container->rootEditableElement();
    115113    if (!rootEditableElement || commonAncestor->contains(rootEditableElement))
    116114        return nullptr;
    117115
    118     return commonAncestor->isElementNode() ? downcast<Element>(commonAncestor) : nullptr;
     116    return &downcast<Element>(*commonAncestor);
    119117}
    120118
  • trunk/Source/WebCore/editing/FormatBlockCommand.h

    r235775 r265084  
    4747    bool preservesTypingStyle() const override { return true; }
    4848
    49     static Element* elementForFormatBlockCommand(Range*);
     49    static Element* elementForFormatBlockCommand(const Optional<SimpleRange>&);
    5050    bool didApply() const { return m_didApply; }
    5151
  • trunk/Source/WebCore/editing/FrameSelection.cpp

    r265044 r265084  
    206206}
    207207
    208 void FrameSelection::moveTo(const Range* range)
    209 {
    210     VisibleSelection selection = range ? VisibleSelection(range->startPosition(), range->endPosition()) : VisibleSelection();
    211     setSelection(selection);
    212 }
    213 
    214208void FrameSelection::moveTo(const Position &base, const Position &extent, EAffinity affinity, EUserTriggered userTriggered)
    215209{
    … …  
    20352029}
    20362030
    2037 bool FrameSelection::setSelectedRange(Range* range, EAffinity affinity, ShouldCloseTyping closeTyping, EUserTriggered userTriggered)
     2031bool FrameSelection::setSelectedRange(const Optional<SimpleRange>& range, EAffinity affinity, ShouldCloseTyping closeTyping, EUserTriggered userTriggered)
    20382032{
    20392033    if (!range)
    20402034        return false;
    2041     ASSERT(&range->startContainer().document() == &range->endContainer().document());
     2035
     2036    if (&range->start.container->document() != &range->end.container->document())
     2037        return false;
    20422038
    20432039    VisibleSelection newSelection(*range, affinity);
  • trunk/Source/WebCore/editing/FrameSelection.h

    r265044 r265084  
    3131#include "IntRect.h"
    3232#include "LayoutRect.h"
    33 #include "Range.h"
    3433#include "ScrollAlignment.h"
    3534#include "Timer.h"
    … …  
    145144    WEBCORE_EXPORT Element* rootEditableElementOrDocumentElement() const;
    146145     
    147     WEBCORE_EXPORT void moveTo(const Range*);
    148146    WEBCORE_EXPORT void moveTo(const VisiblePosition&, EUserTriggered = NotUserTriggered, CursorAlignOnScroll = AlignCursorOnScrollIfNeeded);
    149147    WEBCORE_EXPORT void moveTo(const VisiblePosition&, const VisiblePosition&, EUserTriggered = NotUserTriggered);
    … …  
    156154
    157155    enum class ShouldCloseTyping : bool { No, Yes };
    158     WEBCORE_EXPORT bool setSelectedRange(Range*, EAffinity, ShouldCloseTyping, EUserTriggered = NotUserTriggered);
     156    WEBCORE_EXPORT bool setSelectedRange(const Optional<SimpleRange>&, EAffinity, ShouldCloseTyping, EUserTriggered = NotUserTriggered);
    159157    WEBCORE_EXPORT void selectAll();
    160158    WEBCORE_EXPORT void clear();
  • trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp

    r261967 r265084  
    208208            return;
    209209
    210         m_fragment = createFragmentFromText(createLiveRange(*range), event->text());
     210        m_fragment = createFragmentFromText(*range, event->text());
    211211        if (!m_fragment->firstChild())
    212212            return;
  • trunk/Source/WebCore/editing/VisibleUnits.cpp

    r265044 r265084  
    18341834}
    18351835
    1836 RefPtr<Range> enclosingTextUnitOfGranularity(const VisiblePosition& vp, TextGranularity granularity, SelectionDirection direction)
     1836Optional<SimpleRange> enclosingTextUnitOfGranularity(const VisiblePosition& vp, TextGranularity granularity, SelectionDirection direction)
    18371837{
    18381838    // This is particularly inefficient.  We could easily obtain the answer with the boundaries computed below.
    18391839    if (!withinTextUnitOfGranularity(vp, granularity, direction))
    1840         return nullptr;
     1840        return WTF::nullopt;
    18411841
    18421842    VisiblePosition prevBoundary;
    … …  
    18901890        default:
    18911891            ASSERT_NOT_REACHED();
    1892             return nullptr;
     1892            return WTF::nullopt;
    18931893    }
    18941894
    18951895    if (prevBoundary.isNull() || nextBoundary.isNull())
    1896         return nullptr;
     1896        return WTF::nullopt;
    18971897
    18981898    if (vp < prevBoundary || vp > nextBoundary)
    1899         return nullptr;
    1900 
    1901     return Range::create(prevBoundary.deepEquivalent().deprecatedNode()->document(), prevBoundary, nextBoundary);
     1899        return WTF::nullopt;
     1900
     1901    return makeSimpleRange(prevBoundary, nextBoundary);
    19021902}
    19031903
    … …  
    19451945}
    19461946
    1947 RefPtr<Range> wordRangeFromPosition(const VisiblePosition& position)
     1947Optional<SimpleRange> wordRangeFromPosition(const VisiblePosition& position)
    19481948{
    19491949    if (position.isNull())
    1950         return nullptr;
    1951 
    1952     RefPtr<Range> range = enclosingTextUnitOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Backward);
    1953 
    1954     if (!range) {
    1955         // We could be at the start of a word, try forward.
    1956         range = enclosingTextUnitOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Forward);
    1957     }
    1958 
    1959     if (range)
     1950        return WTF::nullopt;
     1951
     1952    if (auto range = enclosingTextUnitOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Backward))
     1953        return range;
     1954    if (auto range = enclosingTextUnitOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Forward))
    19601955        return range;
    19611956
    … …  
    19661961    if (currentPosition.isNull())
    19671962        currentPosition = positionOfNextBoundaryOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Forward);
    1968 
    1969     if (currentPosition.isNotNull()) {
    1970         range = Range::create(position.deepEquivalent().deprecatedNode()->document(), currentPosition, position);
    1971         ASSERT(range);
    1972     }
    1973 
    1974     return range;
     1963    return makeSimpleRange(currentPosition, position);
    19751964}
    19761965
    … …  
    19831972    } else if (withinTextUnitOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Forward)) {
    19841973        // The position lies within a word.
    1985         RefPtr<Range> wordRange = enclosingTextUnitOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Forward);
    1986 
    1987         result = wordRange->startPosition();
    1988         if (distanceBetweenPositions(position, result) > 1)
    1989             result = wordRange->endPosition();
     1974        if (auto wordRange = enclosingTextUnitOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Forward)) {
     1975            result = createLegacyEditingPosition(wordRange->start);
     1976            if (distanceBetweenPositions(position, result) > 1)
     1977                result = createLegacyEditingPosition(wordRange->end);
     1978        }
    19901979    } else if (atBoundaryOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Backward)) {
    19911980        // The position is at the end of a word.
    … …  
    20031992}
    20041993
    2005 RefPtr<Range> rangeExpandedByCharactersInDirectionAtWordBoundary(const VisiblePosition& position, int numberOfCharactersToExpand, SelectionDirection direction)
     1994Optional<SimpleRange> rangeExpandedByCharactersInDirectionAtWordBoundary(const VisiblePosition& position, int numberOfCharactersToExpand, SelectionDirection direction)
    20061995{
    20071996    Position start = position.deepEquivalent();
    … …  
    20192008        end = endOfWord(end).deepEquivalent();
    20202009
    2021     return makeRange(start, end);
     2010    return makeSimpleRange(start, end);
    20222011}   
    20232012
    2024 RefPtr<Range> rangeExpandedAroundPositionByCharacters(const VisiblePosition& position, int numberOfCharactersToExpand)
     2013Optional<SimpleRange> rangeExpandedAroundPositionByCharacters(const VisiblePosition& position, int numberOfCharactersToExpand)
    20252014{
    20262015    Position start = position.deepEquivalent();
    … …  
    20302019        end = end.next(Character);
    20312020    }
    2032    
    2033     return makeRange(start, end);
     2021    return makeSimpleRange(start, end);
    20342022}
    20352023
    … …  
    20422030        auto adjustedPosition = position;
    20432031        if (auto wordRange = enclosingTextUnitOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Forward)) {
    2044             adjustedPosition = wordRange->startPosition();
     2032            adjustedPosition = createLegacyEditingPosition(wordRange->start);
    20452033            if (distanceBetweenPositions(position, adjustedPosition) > 1)
    2046                 adjustedPosition = wordRange->endPosition();
     2034                adjustedPosition = createLegacyEditingPosition(wordRange->end);
    20472035        }
    20482036        return { adjustedPosition, WithinWordBoundary::Yes };
  • trunk/Source/WebCore/editing/VisibleUnits.h

    r261139 r265084  
    102102WEBCORE_EXPORT bool withinTextUnitOfGranularity(const VisiblePosition&, TextGranularity, SelectionDirection);
    103103WEBCORE_EXPORT VisiblePosition positionOfNextBoundaryOfGranularity(const VisiblePosition&, TextGranularity, SelectionDirection);
    104 WEBCORE_EXPORT RefPtr<Range> enclosingTextUnitOfGranularity(const VisiblePosition&, TextGranularity, SelectionDirection);
     104WEBCORE_EXPORT Optional<SimpleRange> enclosingTextUnitOfGranularity(const VisiblePosition&, TextGranularity, SelectionDirection);
    105105WEBCORE_EXPORT std::ptrdiff_t distanceBetweenPositions(const VisiblePosition&, const VisiblePosition&);
    106 WEBCORE_EXPORT RefPtr<Range> wordRangeFromPosition(const VisiblePosition&);
     106WEBCORE_EXPORT Optional<SimpleRange> wordRangeFromPosition(const VisiblePosition&);
    107107WEBCORE_EXPORT VisiblePosition closestWordBoundaryForPosition(const VisiblePosition& position);
    108108WEBCORE_EXPORT void charactersAroundPosition(const VisiblePosition&, UChar32& oneAfter, UChar32& oneBefore, UChar32& twoBefore);
    109 WEBCORE_EXPORT RefPtr<Range> rangeExpandedAroundPositionByCharacters(const VisiblePosition&, int numberOfCharactersToExpand);
    110 WEBCORE_EXPORT RefPtr<Range> rangeExpandedByCharactersInDirectionAtWordBoundary(const VisiblePosition&, int numberOfCharactersToExpand, SelectionDirection);
     109WEBCORE_EXPORT Optional<SimpleRange> rangeExpandedAroundPositionByCharacters(const VisiblePosition&, int numberOfCharactersToExpand);
     110WEBCORE_EXPORT Optional<SimpleRange> rangeExpandedByCharactersInDirectionAtWordBoundary(const VisiblePosition&, int numberOfCharactersToExpand, SelectionDirection);
    111111enum class WithinWordBoundary : bool { No, Yes };
    112112WEBCORE_EXPORT std::pair<VisiblePosition, WithinWordBoundary> wordBoundaryForPositionWithoutCrossingLine(const VisiblePosition&);
  • trunk/Source/WebCore/editing/cocoa/DataDetection.mm

    r265044 r265084  
    129129
    130130    VisiblePosition position;
    131     RefPtr<Range> contextRange;
     131    Optional<SimpleRange> contextRange;
    132132
    133133    if (!is<HTMLTextFormControlElement>(*node)) {
  • trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm

    r265044 r265084  
    4242#import "NotImplemented.h"
    4343#import "Page.h"
    44 #import "Range.h"
    4544#import "RenderObject.h"
    4645#import "TextIterator.h"
    … …  
    284283    NSRange rangeToPass = NSMakeRange(lengthToSelectionStart, selectionCharacterCount);
    285284
    286     RefPtr<Range> fullCharacterRange = makeRange(paragraphStart, paragraphEnd);
    287     String itemString = plainText(*fullCharacterRange);
     285    auto fullCharacterRange = *makeSimpleRange(paragraphStart, paragraphEnd);
     286    String itemString = plainText(fullCharacterRange);
    288287    NSRange highlightRange = adoptNS([allocRVItemInstance() initWithText:itemString selectedRange:rangeToPass]).get().highlightRange;
    289288
    290     return { { resolveCharacterRange(*fullCharacterRange, highlightRange), nil } };
     289    return { { resolveCharacterRange(fullCharacterRange, highlightRange), nil } };
    291290
    292291    END_BLOCK_OBJC_EXCEPTIONS
    … …  
    342341
    343342        // As context, we are going to use 250 characters of text before and after the point.
    344         auto expandedRange = rangeExpandedAroundPositionByCharacters(position, 250);
    345         if (!expandedRange)
    346             return WTF::nullopt;
    347 
    348         fullCharacterRange = { *expandedRange };
     343        fullCharacterRange = rangeExpandedAroundPositionByCharacters(position, 250);
    349344
    350345        selectionRange = NSMakeRange(NSNotFound, 0);
  • trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm

    r264692 r265084  
    9595    outData.append(PasteboardCustomData { element.document().originIdentifierForPasteboard(), { } }.createSharedBuffer());
    9696
    97     if (auto archive = LegacyWebArchive::create(createLiveRange(elementRange).get())) {
    98         if (auto webArchiveData = archive->rawDataRepresentation()) {
    99             outTypes.append(WebArchivePboardType);
    100             outData.append(SharedBuffer::create(webArchiveData.get()));
     97    if (elementRange) {
     98        if (auto archive = LegacyWebArchive::create(*elementRange)) {
     99            if (auto data = archive->rawDataRepresentation()) {
     100                outTypes.append(WebArchivePboardType);
     101                outData.append(SharedBuffer::create(data.get()));
     102            }
    101103        }
    102104    }
  • trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm

    r265044 r265084  
    670670        return false;
    671671
    672     addFragment(createFragmentFromText(createLiveRange(context), [text precomposedStringWithCanonicalMapping]));
     672    addFragment(createFragmentFromText(context, [text precomposedStringWithCanonicalMapping]));
    673673
    674674    madeFragmentFromPlainText = true;
  • trunk/Source/WebCore/editing/gtk/WebContentReaderGtk.cpp

    r261792 r265084  
    6666        return false;
    6767
    68     addFragment(createFragmentFromText(createLiveRange(context), text));
     68    addFragment(createFragmentFromText(context, text));
    6969
    7070    madeFragmentFromPlainText = true;
  • trunk/Source/WebCore/editing/libwpe/EditorLibWPE.cpp

    r264692 r265084  
    5656    if (types.contains("text/plain;charset=utf-8")) {
    5757        chosePlainText = true;
    58         return createFragmentFromText(createLiveRange(range).get(), pasteboard.readString("text/plain;charset=utf-8"));
     58        return createFragmentFromText(range, pasteboard.readString("text/plain;charset=utf-8"));
    5959    }
    6060
  • trunk/Source/WebCore/editing/mac/DictionaryLookupLegacy.mm

    r265044 r265084  
    132132        return WTF::nullopt;
    133133
    134     auto rangeToPosition = makeSimpleRange(fullCharacterRange->startPosition(), position);
     134    auto rangeToPosition = makeSimpleRange(fullCharacterRange->start, position);
    135135    if (!rangeToPosition)
    136136        return WTF::nullopt;
  • trunk/Source/WebCore/editing/markup.cpp

    r265044 r265084  
    332332};
    333333
    334 inline StyledMarkupAccumulator::StyledMarkupAccumulator(const Position& start, const Position& end, Vector<Node*>* nodes, ResolveURLs urlsToResolve, SerializeComposedTree serializeComposedTree,
    335     AnnotateForInterchange annotate, StandardFontFamilySerializationMode standardFontFamilySerializationMode, MSOListMode msoListMode, bool needsPositionStyleConversion, Node* highestNodeToBeSerialized)
    336     : MarkupAccumulator(nodes, urlsToResolve)
     334inline StyledMarkupAccumulator::StyledMarkupAccumulator(const Position& start, const Position& end, Vector<Node*>* nodes, ResolveURLs resolveURLs, SerializeComposedTree serializeComposedTree, AnnotateForInterchange annotate, StandardFontFamilySerializationMode standardFontFamilySerializationMode, MSOListMode msoListMode, bool needsPositionStyleConversion, Node* highestNodeToBeSerialized)
     335    : MarkupAccumulator(nodes, resolveURLs)
    337336    , m_start(start)
    338337    , m_end(end)
    … …  
    836835}
    837836
    838 static String serializePreservingVisualAppearanceInternal(const Position& start, const Position& end, Vector<Node*>* nodes, ResolveURLs urlsToResolve, SerializeComposedTree serializeComposedTree,
     837static String serializePreservingVisualAppearanceInternal(const Position& start, const Position& end, Vector<Node*>* nodes, ResolveURLs resolveURLs, SerializeComposedTree serializeComposedTree,
    839838    AnnotateForInterchange annotate, ConvertBlocksToInlines convertBlocksToInlines, StandardFontFamilySerializationMode standardFontFamilySerializationMode, MSOListMode msoListMode)
    840839{
    … …  
    863862    Node* specialCommonAncestor = highestAncestorToWrapMarkup(start, end, *commonAncestor, annotate);
    864863
    865     StyledMarkupAccumulator accumulator(start, end, nodes, urlsToResolve, serializeComposedTree, annotate, standardFontFamilySerializationMode, msoListMode, needsPositionStyleConversion, specialCommonAncestor);
     864    StyledMarkupAccumulator accumulator(start, end, nodes, resolveURLs, serializeComposedTree, annotate, standardFontFamilySerializationMode, msoListMode, needsPositionStyleConversion, specialCommonAncestor);
    866865
    867866    Position startAdjustedForInterchangeNewline = start;
    … …  
    935934}
    936935
    937 String serializePreservingVisualAppearance(const Range& range, Vector<Node*>* nodes, AnnotateForInterchange annotate, ConvertBlocksToInlines convertBlocksToInlines, ResolveURLs urlsToReslve)
    938 {
    939     return serializePreservingVisualAppearanceInternal(range.startPosition(), range.endPosition(), nodes, urlsToReslve, SerializeComposedTree::No,
     936String serializePreservingVisualAppearance(const SimpleRange& range, Vector<Node*>* nodes, AnnotateForInterchange annotate, ConvertBlocksToInlines convertBlocksToInlines, ResolveURLs resolveURLs)
     937{
     938    return serializePreservingVisualAppearanceInternal(createLegacyEditingPosition(range.start), createLegacyEditingPosition(range.end),
     939        nodes, resolveURLs, SerializeComposedTree::No,
    940940        annotate, convertBlocksToInlines, StandardFontFamilySerializationMode::Keep, MSOListMode::DoNotPreserve);
    941941}
    … …  
    10441044}
    10451045
    1046 String serializeFragment(const Node& node, SerializedNodes root, Vector<Node*>* nodes, ResolveURLs urlsToResolve, Vector<QualifiedName>* tagNamesToSkip, SerializationSyntax serializationSyntax)
    1047 {
    1048     MarkupAccumulator accumulator(nodes, urlsToResolve, serializationSyntax);
     1046String serializeFragment(const Node& node, SerializedNodes root, Vector<Node*>* nodes, ResolveURLs resolveURLs, Vector<QualifiedName>* tagNamesToSkip, SerializationSyntax serializationSyntax)
     1047{
     1048    MarkupAccumulator accumulator(nodes, resolveURLs, serializationSyntax);
    10491049    return accumulator.serializeNodes(const_cast<Node&>(node), root, tagNamesToSkip);
    10501050}
    … …  
    11131113}
    11141114
    1115 static bool contextPreservesNewline(const Range& context)
    1116 {
    1117     VisiblePosition position(context.startPosition());
    1118     Node* container = position.deepEquivalent().containerNode();
    1119     if (!container || !container->renderer())
    1120         return false;
    1121 
    1122     return container->renderer()->style().preserveNewline();
    1123 }
    1124 
    1125 Ref<DocumentFragment> createFragmentFromText(Range& context, const String& text)
    1126 {
    1127     Document& document = context.ownerDocument();
    1128     Ref<DocumentFragment> fragment = document.createDocumentFragment();
     1115static bool contextPreservesNewline(const SimpleRange& context)
     1116{
     1117    auto container = VisiblePosition(createLegacyEditingPosition(context.start)).deepEquivalent().containerNode();
     1118    return container && container->renderer() && container->renderer()->style().preserveNewline();
     1119}
     1120
     1121Ref<DocumentFragment> createFragmentFromText(const SimpleRange& context, const String& text)
     1122{
     1123    auto& document = context.start.container->document();
     1124    auto fragment = document.createDocumentFragment();
    11291125   
    11301126    if (text.isEmpty())
    … …  
    11621158
    11631159    // Break string into paragraphs. Extra line breaks turn into empty paragraphs.
    1164     Node* blockNode = enclosingBlock(context.firstNode());
     1160    Node* blockNode = enclosingBlock(createLiveRange(context)->firstNode());
    11651161    Element* block = downcast<Element>(blockNode);
    11661162    bool useClonesOfEnclosingBlock = blockNode
    … …  
    11681164        && !block->hasTagName(bodyTag)
    11691165        && !block->hasTagName(htmlTag)
    1170         && block != editableRootForPosition(context.startPosition());
    1171     bool useLineBreak = enclosingTextFormControl(context.startPosition());
     1166        && block != editableRootForPosition(createLegacyEditingPosition(context.start));
     1167    bool useLineBreak = enclosingTextFormControl(createLegacyEditingPosition(context.start));
    11721168
    11731169    Vector<String> list = string.splitAllowingEmptyEntries('\n');
  • trunk/Source/WebCore/editing/markup.h

    r261395 r265084  
    4545class Node;
    4646class Page;
     47class QualifiedName;
     48class VisibleSelection;
     49
    4750struct PresentationSize;
    48 class QualifiedName;
    49 class Range;
    50 class VisibleSelection;
     51struct SimpleRange;
    5152
    5253void replaceSubresourceURLs(Ref<DocumentFragment>&&, HashMap<AtomString, AtomString>&&);
    … …  
    5859String sanitizedMarkupForFragmentInDocument(Ref<DocumentFragment>&&, Document&, MSOListQuirks, const String& originalMarkup);
    5960
    60 WEBCORE_EXPORT Ref<DocumentFragment> createFragmentFromText(Range& context, const String& text);
     61WEBCORE_EXPORT Ref<DocumentFragment> createFragmentFromText(const SimpleRange& context, const String& text);
    6162WEBCORE_EXPORT Ref<DocumentFragment> createFragmentFromMarkup(Document&, const String& markup, const String& baseURL, ParserContentPolicy = AllowScriptingContent);
    6263ExceptionOr<Ref<DocumentFragment>> createFragmentForInnerOuterHTML(Element&, const String& markup, ParserContentPolicy);
    … …  
    7374enum class ConvertBlocksToInlines : uint8_t { No, Yes };
    7475enum class SerializeComposedTree : uint8_t { No, Yes };
    75 WEBCORE_EXPORT String serializePreservingVisualAppearance(const Range&, Vector<Node*>* = nullptr, AnnotateForInterchange = AnnotateForInterchange::No, ConvertBlocksToInlines = ConvertBlocksToInlines::No, ResolveURLs = ResolveURLs::No);
     76WEBCORE_EXPORT String serializePreservingVisualAppearance(const SimpleRange&, Vector<Node*>* = nullptr, AnnotateForInterchange = AnnotateForInterchange::No, ConvertBlocksToInlines = ConvertBlocksToInlines::No, ResolveURLs = ResolveURLs::No);
    7677String serializePreservingVisualAppearance(const VisibleSelection&, ResolveURLs = ResolveURLs::No, SerializeComposedTree = SerializeComposedTree::No, Vector<Node*>* = nullptr);
    7778
  • trunk/Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp

    r262683 r265084  
    4949#include "MemoryCache.h"
    5050#include "Page.h"
    51 #include "Range.h"
    5251#include "RuntimeEnabledFeatures.h"
    5352#include "SerializedAttachmentData.h"
    … …  
    418417        return create();
    419418
    420     // If the page was loaded with javascript enabled, we don't want to archive <noscript> tags
     419    // If the page was loaded with JavaScript enabled, we don't want to archive <noscript> tags
    421420    // In practice we don't actually know whether scripting was enabled when the page was originally loaded
    422421    // but we can approximate that by checking if scripting is enabled right now.
    … …  
    455454}
    456455
    457 RefPtr<LegacyWebArchive> LegacyWebArchive::create(Range* range)
    458 {
    459     if (!range)
    460         return nullptr;
    461        
    462     auto& document = range->startContainer().document();
     456RefPtr<LegacyWebArchive> LegacyWebArchive::create(const SimpleRange& range)
     457{
     458    auto& document = range.start.container->document();
    463459    auto* frame = document.frame();
    464460    if (!frame)
    … …  
    467463    // FIXME: This is always "for interchange". Is that right?
    468464    Vector<Node*> nodeList;
    469     String markupString = documentTypeString(document) + serializePreservingVisualAppearance(*range, &nodeList, AnnotateForInterchange::Yes);
     465    String markupString = documentTypeString(document) + serializePreservingVisualAppearance(range, &nodeList, AnnotateForInterchange::Yes);
    470466    return create(markupString, *frame, nodeList, nullptr);
    471467}
  • trunk/Source/WebCore/loader/archive/cf/LegacyWebArchive.h

    r218501 r265084  
    3636class Frame;
    3737class Node;
    38 class Range;
     38
     39struct SimpleRange;
    3940
    4041class LegacyWebArchive final : public Archive {
    … …  
    4748    WEBCORE_EXPORT static RefPtr<LegacyWebArchive> create(Frame&);
    4849    WEBCORE_EXPORT static RefPtr<LegacyWebArchive> createFromSelection(Frame*);
    49     WEBCORE_EXPORT static RefPtr<LegacyWebArchive> create(Range*);
     50    WEBCORE_EXPORT static RefPtr<LegacyWebArchive> create(const SimpleRange&);
    5051
    5152    WEBCORE_EXPORT RetainPtr<CFDataRef> rawDataRepresentation();
  • trunk/Source/WebCore/page/DragController.cpp

    r264692 r265084  
    7272#include "Position.h"
    7373#include "PromisedAttachmentInfo.h"
     74#include "Range.h"
    7475#include "RenderAttachment.h"
    7576#include "RenderFileUploadControl.h"
    … …  
    240241    if (!m_droppedImagePlaceholders.isEmpty() && m_droppedImagePlaceholderRange && tryToUpdateDroppedImagePlaceholders(dragData)) {
    241242        m_droppedImagePlaceholders.clear();
    242         m_droppedImagePlaceholderRange = nullptr;
     243        m_droppedImagePlaceholderRange = WTF::nullopt;
    243244        m_documentUnderMouse = nullptr;
    244245        clearDragCaret();
    … …  
    634635
    635636        client().willPerformDragDestinationAction(DragDestinationAction::Edit, dragData);
    636         auto fragment = createFragmentFromText(createLiveRange(*range), text);
     637        auto fragment = createFragmentFromText(*range, text);
    637638        if (editor.client() && editor.client()->performTwoStepDrop(fragment.get(), createLiveRange(*range), isMove))
    638639            return true;
    … …  
    857858static void selectElement(Element& element)
    858859{
    859     RefPtr<Range> range = element.document().createRange();
    860     range->selectNode(element);
    861     element.document().frame()->selection().setSelection(VisibleSelection(*range, DOWNSTREAM));
     860    if (auto frame = element.document().frame()) {
     861        if (auto range = makeRangeSelectingNode(element))
     862            frame->selection().setSelection(*range);
     863    }
    862864}
    863865
    … …  
    13741376void DragController::removeAllDroppedImagePlaceholders()
    13751377{
    1376     m_droppedImagePlaceholderRange = nullptr;
     1378    m_droppedImagePlaceholderRange = WTF::nullopt;
    13771379    for (auto& placeholder : std::exchange(m_droppedImagePlaceholders, { })) {
    13781380        if (placeholder->isConnected())
    … …  
    14561458    command->apply();
    14571459
    1458     auto insertedContentRange = command->insertedContentRange();
     1460    auto insertedContentRange = makeSimpleRange(command->insertedContentRange());
    14591461    if (!insertedContentRange) {
    14601462        ASSERT_NOT_REACHED();
    … …  
    14621464    }
    14631465
    1464     auto container = makeRefPtr(insertedContentRange->commonAncestorContainer());
     1466    auto container = commonInclusiveAncestor(*insertedContentRange);
    14651467    if (!is<ContainerNode>(container)) {
    14661468        ASSERT_NOT_REACHED();
    … …  
    14701472    Vector<Ref<HTMLImageElement>> placeholders;
    14711473    for (auto& placeholder : descendantsOfType<HTMLImageElement>(downcast<ContainerNode>(*container))) {
    1472         auto intersectsNode = insertedContentRange->intersectsNode(placeholder);
     1474        auto intersectsNode = createLiveRange(*insertedContentRange)->intersectsNode(placeholder);
    14731475        if (!intersectsNode.hasException() && intersectsNode.returnValue())
    14741476            placeholders.append(placeholder);
    … …  
    14941496
    14951497    frame->selection().clear();
    1496     caretController.setCaretPosition(m_droppedImagePlaceholderRange->startPosition());
     1498    caretController.setCaretPosition(createLegacyEditingPosition(m_droppedImagePlaceholderRange->start));
    14971499}
    14981500
  • trunk/Source/WebCore/page/DragController.h

    r262913 r265084  
    3030#include "IntPoint.h"
    3131#include "IntRect.h"
     32#include "SimpleRange.h"
    3233#include <wtf/URL.h>
    3334
    … …  
    9091
    9192    const Vector<Ref<HTMLImageElement>>& droppedImagePlaceholders() const { return m_droppedImagePlaceholders; }
    92     const RefPtr<Range>& droppedImagePlaceholderRange() const { return m_droppedImagePlaceholderRange; }
     93    const Optional<SimpleRange>& droppedImagePlaceholderRange() const { return m_droppedImagePlaceholderRange; }
    9394
    9495    WEBCORE_EXPORT void finalizeDroppedImagePlaceholder(HTMLImageElement&);
    … …  
    162163    bool m_isPerformingDrop { false };
    163164    Vector<Ref<HTMLImageElement>> m_droppedImagePlaceholders;
    164     RefPtr<Range> m_droppedImagePlaceholderRange;
     165    Optional<SimpleRange> m_droppedImagePlaceholderRange;
    165166};
    166167
  • trunk/Source/WebCore/page/Page.cpp

    r265051 r265084  
    9999#include "PointerLockController.h"
    100100#include "ProgressTracker.h"
     101#include "Range.h"
    101102#include "RenderDescendantIterator.h"
    102103#include "RenderLayerCompositor.h"
    … …  
    712713}
    713714
    714 void Page::findStringMatchingRanges(const String& target, FindOptions options, int limit, Vector<RefPtr<Range>>& matchRanges, int& indexForSelection)
    715 {
    716     Vector<SimpleRange> resultRanges;
    717 
    718     indexForSelection = 0;
     715auto Page::findTextMatches(const String& target, FindOptions options, unsigned limit) -> MatchingRanges
     716{
     717    MatchingRanges result;
    719718
    720719    Frame* frame = &mainFrame();
    721720    Frame* frameWithSelection = nullptr;
    722721    do {
    723         frame->editor().countMatchesForText(target, { }, options, limit ? (limit - resultRanges.size()) : 0, true, &resultRanges);
     722        frame->editor().countMatchesForText(target, { }, options, limit ? (limit - result.ranges.size()) : 0, true, &result.ranges);
    724723        if (frame->selection().isRange())
    725724            frameWithSelection = frame;
    … …  
    727726    } while (frame);
    728727
    729     if (resultRanges.isEmpty())
    730         return;
     728    if (result.ranges.isEmpty())
     729        return result;
    731730
    732731    if (frameWithSelection) {
    733         indexForSelection = NoMatchAfterUserSelection;
     732        result.indexForSelection = NoMatchAfterUserSelection;
    734733        auto selectedRange = frameWithSelection->selection().selection().firstRange();
    735734        if (options.contains(Backwards)) {
    736             for (size_t i = resultRanges.size(); i > 0; --i) {
    737                 auto result = createLiveRange(selectedRange)->compareBoundaryPoints(Range::END_TO_START, createLiveRange(resultRanges[i - 1]));
    738                 if (!result.hasException() && result.releaseReturnValue() > 0) {
    739                     indexForSelection = i - 1;
     735            for (size_t i = result.ranges.size(); i > 0; --i) {
     736                auto comparisonResult = createLiveRange(selectedRange)->compareBoundaryPoints(Range::END_TO_START, createLiveRange(result.ranges[i - 1]));
     737                if (!comparisonResult.hasException() && comparisonResult.returnValue() > 0) {
     738                    result.indexForSelection = i - 1;
    740739                    break;
    741740                }
    742741            }
    743742        } else {
    744             for (size_t i = 0, size = resultRanges.size(); i < size; ++i) {
    745                 auto result = createLiveRange(selectedRange)->compareBoundaryPoints(Range::START_TO_END, createLiveRange(resultRanges[i]));
    746                 if (!result.hasException() && result.releaseReturnValue() < 0) {
    747                     indexForSelection = i;
     743            for (size_t i = 0, size = result.ranges.size(); i < size; ++i) {
     744                auto comparisonResult = createLiveRange(selectedRange)->compareBoundaryPoints(Range::START_TO_END, createLiveRange(result.ranges[i]));
     745                if (!comparisonResult.hasException() && comparisonResult.returnValue() < 0) {
     746                    result.indexForSelection = i;
    748747                    break;
    749748                }
    … …  
    752751    } else {
    753752        if (options.contains(Backwards))
    754             indexForSelection = resultRanges.size() - 1;
     753            result.indexForSelection = result.ranges.size() - 1;
    755754        else
    756             indexForSelection = 0;
    757     }
    758 
    759     for (auto& range : resultRanges)
    760         matchRanges.append(createLiveRange(range));
    761 }
    762 
    763 RefPtr<Range> Page::rangeOfString(const String& target, Range* referenceRange, FindOptions options)
     755            result.indexForSelection = 0;
     756    }
     757
     758    return result;
     759}
     760
     761Optional<SimpleRange> Page::rangeOfString(const String& target, const Optional<SimpleRange>& referenceRange, FindOptions options)
    764762{
    765763    if (target.isEmpty())
    766         return nullptr;
    767 
    768     if (referenceRange && referenceRange->ownerDocument().page() != this)
    769         return nullptr;
     764        return WTF::nullopt;
     765
     766    if (referenceRange && referenceRange->start.container->document().page() != this)
     767        return WTF::nullopt;
    770768
    771769    CanWrap canWrap = options.contains(WrapAround) ? CanWrap::Yes : CanWrap::No;
    772     Frame* frame = referenceRange ? referenceRange->ownerDocument().frame() : &mainFrame();
     770    Frame* frame = referenceRange ? referenceRange->start.container->document().frame() : &mainFrame();
    773771    Frame* startFrame = frame;
    774772    do {
    775         if (auto resultRange = frame->editor().rangeOfString(target, frame == startFrame ? makeSimpleRange(referenceRange) : WTF::nullopt, options - WrapAround))
    776             return createLiveRange(resultRange);
     773        if (auto resultRange = frame->editor().rangeOfString(target, frame == startFrame ? referenceRange : WTF::nullopt, options - WrapAround))
     774            return resultRange;
    777775        frame = incrementFrame(frame, !options.contains(Backwards), canWrap);
    778776    } while (frame && frame != startFrame);
    … …  
    781779    // We cheat a bit and just search again with wrap on.
    782780    if (canWrap == CanWrap::Yes && referenceRange) {
    783         if (auto resultRange = startFrame->editor().rangeOfString(target, makeSimpleRange(*referenceRange), options | WrapAround | StartInSelection))
    784             return createLiveRange(resultRange);
    785     }
    786 
    787     return nullptr;
     781        if (auto resultRange = startFrame->editor().rangeOfString(target, *referenceRange, options | WrapAround | StartInSelection))
     782            return resultRange;
     783    }
     784
     785    return WTF::nullopt;
    788786}
    789787
    … …  
    880878                continue;
    881879
    882             frame->selection().setSelectedRange(createLiveRange(range).ptr(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes);
     880            frame->selection().setSelectedRange(range, DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes);
    883881            frame->editor().replaceSelectionWithText(replacementText, Editor::SelectReplacement::Yes, Editor::SmartReplace::No, EditAction::InsertReplacement);
    884882        }
    … …  
    886884}
    887885
    888 uint32_t Page::replaceRangesWithText(const Vector<Ref<Range>>& rangesToReplace, const String& replacementText, bool selectionOnly)
    889 {
    890     // FIXME: In the future, we should respect the `selectionOnly` flag by checking whether each range being replaced is
    891     // contained within its frame's selection.
    892     UNUSED_PARAM(selectionOnly);
     886uint32_t Page::replaceRangesWithText(const Vector<SimpleRange>& rangesToReplace, const String& replacementText, bool /*selectionOnly*/)
     887{
     888    // FIXME: In the future, we should respect the `selectionOnly` flag by checking whether each range being replaced is contained within its frame's selection.
    893889
    894890    Vector<FindReplacementRange> replacementRanges;
    … …  
    896892
    897893    for (auto& range : rangesToReplace) {
    898         auto highestRoot = makeRefPtr(highestEditableRoot(range->startPosition()));
    899         if (!highestRoot || highestRoot != highestEditableRoot(range->endPosition()) || !highestRoot->document().frame())
     894        auto highestRoot = makeRefPtr(highestEditableRoot(createLegacyEditingPosition(range.start)));
     895        if (!highestRoot || highestRoot != highestEditableRoot(createLegacyEditingPosition(range.end)) || !highestRoot->document().frame())
    900896            continue;
    901897        auto scope = makeRangeSelectingNodeContents(*highestRoot);
  • trunk/Source/WebCore/page/Page.h

    r264856 r265084  
    130130class PointerLockController;
    131131class ProgressTracker;
    132 class Range;
    133132class RenderObject;
    134133class ResourceUsageOverlay;
    … …  
    153152class WheelEventTestMonitor;
    154153
     154struct SimpleRange;
     155
    155156using PlatformDisplayID = uint32_t;
    156157using SharedStringHash = uint32_t;
    … …  
    290291
    291292    WEBCORE_EXPORT bool findString(const String&, FindOptions, DidWrap* = nullptr);
    292     WEBCORE_EXPORT uint32_t replaceRangesWithText(const Vector<Ref<Range>>& rangesToReplace, const String& replacementText, bool selectionOnly);
     293    WEBCORE_EXPORT uint32_t replaceRangesWithText(const Vector<SimpleRange>& rangesToReplace, const String& replacementText, bool selectionOnly);
    293294    WEBCORE_EXPORT uint32_t replaceSelectionWithText(const String& replacementText);
    294295
    295296    WEBCORE_EXPORT void revealCurrentSelection();
    296297
    297     WEBCORE_EXPORT RefPtr<Range> rangeOfString(const String&, Range*, FindOptions);
     298    WEBCORE_EXPORT Optional<SimpleRange> rangeOfString(const String&, const Optional<SimpleRange>& searchRange, FindOptions);
    298299
    299300    WEBCORE_EXPORT unsigned countFindMatches(const String&, FindOptions, unsigned maxMatchCount);
    … …  
    305306    WEBCORE_EXPORT void dispatchAfterPrintEvent();
    306307
    307     // Find all the Ranges for the matching text.
     308    // Find all the ranges for the matching text.
    308309    // Upon return, indexForSelection will be one of the following:
    309310    // 0 if there is no user selection
    310311    // the index of the first range after the user selection
    311312    // NoMatchAfterUserSelection if there is no matching text after the user selection.
    312     enum { NoMatchAfterUserSelection = -1 };
    313     WEBCORE_EXPORT void findStringMatchingRanges(const String&, FindOptions, int maxCount, Vector<RefPtr<Range>>&, int& indexForSelection);
     313    struct MatchingRanges {
     314        Vector<SimpleRange> ranges;
     315        int indexForSelection { 0 }; // FIXME: Consider Optional<unsigned> or unsigned for this instead.
     316    };
     317    static constexpr int NoMatchAfterUserSelection = -1;
     318    WEBCORE_EXPORT MatchingRanges findTextMatches(const String&, FindOptions, unsigned maxCount);
    314319
    315320#if PLATFORM(COCOA)
  • trunk/Source/WebCore/page/ios/FrameIOS.mm

    r260777 r265084  
    5555#import "PlatformScreen.h"
    5656#import "PropertySetCSSStyleDeclaration.h"
     57#import "Range.h"
    5758#import "RenderLayer.h"
    5859#import "RenderLayerCompositor.h"
    … …  
    117118    VisiblePosition position(page()->selection().start(), page()->selection().affinity());
    118119    VisiblePosition end(position);
     120
    119121    if (!isStartOfParagraph(end)) {
    120122        VisiblePosition previous = end.previous();
    121123        UChar c(previous.characterAfter());
     124        // FIXME: Should use something from ICU or ASCIICType that is not subject to POSIX current language rather than iswpunct.
    122125        if (!iswpunct(c) && !isSpaceOrNewline(c) && c != noBreakSpace)
    123126            end = startOfWord(end);
    … …  
    125128    VisiblePosition start(startOfParagraph(end));
    126129
    127     RefPtr<Range> searchRange(rangeOfContents(*document()));
    128     setStart(searchRange.get(), start);
    129     setEnd(searchRange.get(), end);
    130 
    131     if (searchRange->collapsed())
     130    auto searchRange = makeSimpleRange(start, end);
     131    if (!searchRange || searchRange->collapsed())
    132132        return nil;
    133133
  • trunk/Source/WebCore/rendering/HitTestResult.cpp

    r261776 r265084  
    580580        return false;
    581581
    582     RefPtr<Range> wordRange = enclosingTextUnitOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Forward);
    583     if (!wordRange)
    584         return false;
    585 
    586     return !wordRange->text().isEmpty();
     582    auto wordRange = enclosingTextUnitOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Forward);
     583    return wordRange && hasAnyPlainText(*wordRange);
    587584}
    588585
  • trunk/Source/WebKit/ChangeLog

    r265081 r265084  
     12020-07-30  Darin Adler  <darin@apple.com>
     2
     3        Further reduction in the use of live ranges, particularly in headers
     4        https://bugs.webkit.org/show_bug.cgi?id=214793
     5
     6        Reviewed by Sam Weinig.
     7
     8        * Shared/API/c/mac/WKWebArchiveRef.cpp:
     9        (WKWebArchiveCreateFromRange): Use makeSimpleRange.
     10
     11        * Shared/APIWebArchive.h: Use SimpleRange.
     12        * Shared/APIWebArchive.mm:
     13        (API::WebArchive::create): Take SimpleRange.
     14
     15        * Shared/EditingRange.cpp:
     16        (WebKit::EditingRange::toRange): Don't call createLiveRange.
     17        (WebKit::EditingRange::fromRange): Take SimpleRange.
     18        * Shared/EditingRange.h: Updated for above.
     19
     20        * WebProcess/InjectedBundle/API/APIInjectedBundleEditorClient.h:
     21        Take SimpleRange, String, StyleProperties instead of
     22        Range, StringImpl, CSSStyleDeclaration.
     23
     24        * WebProcess/InjectedBundle/API/glib/WebKitWebEditor.cpp:
     25        String instead of StringImpl.
     26
     27        * WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm:
     28        (-[WKDOMDocument createDocumentFragmentWithText:]): Use SimpleRange.
     29        * WebProcess/InjectedBundle/API/mac/WKDOMRange.mm:
     30        (-[WKDOMRange rangeByExpandingToWordBoundaryByCharacters:inDirection:]):
     31        Use SimpleRange and createLiveRange.
     32
     33        * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
     34        (-[WKWebProcessPlugInBrowserContextController _setEditingDelegate:]):
     35        Updated for changes to bundle editor client.
     36
     37        * WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp:
     38        (WebKit::InjectedBundleRangeHandle::create): Deleted. Moved the
     39        code into InjectedBundleRangeHandle::getOrCreate.
     40        (WebKit::createHandle): Added. Makes a handle for a SimpleRange.
     41        * WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h:
     42        Updated for above.
     43
     44        * WebProcess/InjectedBundle/InjectedBundlePageEditorClient.cpp:
     45        (WebKit::createHandle): Added. Makes a handle for a CSSStyleDeclaration.
     46        (WebKit::InjectedBundlePageEditorClient::shouldBeginEditing):
     47        Updated for changes to bundle editor client.
     48        (WebKit::InjectedBundlePageEditorClient::shouldEndEditing): Ditto.
     49        (WebKit::InjectedBundlePageEditorClient::shouldInsertNode): Ditto.
     50        (WebKit::InjectedBundlePageEditorClient::shouldInsertText): Ditto.
     51        (WebKit::InjectedBundlePageEditorClient::shouldDeleteRange): Ditto.
     52        (WebKit::InjectedBundlePageEditorClient::shouldChangeSelectedRange): Ditto.
     53        (WebKit::InjectedBundlePageEditorClient::shouldApplyStyle): Ditto.
     54        (WebKit::InjectedBundlePageEditorClient::didBeginEditing): Ditto.
     55        (WebKit::InjectedBundlePageEditorClient::didEndEditing): Ditto.
     56        (WebKit::InjectedBundlePageEditorClient::didChange): Ditto.
     57        (WebKit::InjectedBundlePageEditorClient::didChangeSelection): Ditto.
     58        (WebKit::InjectedBundlePageEditorClient::willWriteToPasteboard): Ditto.
     59        (WebKit::InjectedBundlePageEditorClient::getPasteboardDataForRange): Ditto.
     60        (WebKit::InjectedBundlePageEditorClient::performTwoStepDrop): Ditto.
     61        * WebProcess/InjectedBundle/InjectedBundlePageEditorClient.h:
     62        Updated for above.
     63
     64        * WebProcess/WebCoreSupport/WebEditorClient.cpp:
     65        (WebKit::WebEditorClient::shouldDeleteRange): Updated to call new
     66        revised bundle editor client.
     67        (WebKit::WebEditorClient::shouldBeginEditing): Ditto.
     68        (WebKit::WebEditorClient::shouldEndEditing): Ditto.
     69        (WebKit::WebEditorClient::shouldInsertNode): Ditto.
     70        (WebKit::WebEditorClient::shouldInsertText): Ditto.
     71        (WebKit::WebEditorClient::shouldChangeSelectedRange): Ditto.
     72        (WebKit::WebEditorClient::shouldApplyStyle): Ditto.
     73        (WebKit::WebEditorClient::willWriteSelectionToPasteboard): Ditto.
     74        (WebKit::WebEditorClient::getClientPasteboardData): Ditto.
     75        (WebKit::WebEditorClient::performTwoStepDrop): Ditto.
     76        (WebKit::insertionPointFromCurrentSelection): Use SimpleRange.
     77
     78        * WebProcess/WebPage/FindController.cpp:
     79        (WebKit::FindController::replaceMatches): Use SimpleRange.
     80        (WebKit::FindController::findString): Updated for change to
     81        Page::findTextMatches function.
     82        (WebKit::FindController::findStringMatches): Ditto.
     83        (WebKit::FindController::getImageForFindMatch): Use SimpleRange.
     84        (WebKit::FindController::selectFindMatch): Ditto.
     85        * WebProcess/WebPage/FindController.h: Updated for above.
     86
     87        * WebProcess/WebPage/WebPage.cpp:
     88        (WebKit::WebPage::getMarkedRangeAsync): Do not call createLiveRange.
     89        (WebKit::WebPage::getSelectedRangeAsync): Ditto.
     90        (WebKit::WebPage::characterIndexForPointAsync): Call makeSimpleRange.
     91
     92        * WebProcess/WebPage/ios/WebPageIOS.mm:
     93        (WebKit::plainTextForContext): Changed overloads a bit to work
     94        better with Optional<SimpleRange> and removed the ones that explicitly
     95        take a Range, updating callers to compensate.
     96        (WebKit::plainTextForDisplay): Ditto.
     97        (WebKit::WebPage::getPlatformEditorState const): Use SimpleRange.
     98        (WebKit::WebPage::getSelectionContext): Ditto.
     99        (WebKit::WebPage::didConcludeEditDrag): Ditto.
     100        (WebKit::WebPage::handleStylusSingleTapAtPoint): Ditto.
     101        (WebKit::WebPage::selectWithGesture): Ditto.
     102        (WebKit::rangeForPointInRootViewCoordinates): Return SimpleRange.
     103        (WebKit::rangeAtWordBoundaryForPosition): Ditto.
     104        (WebKit::WebPage::updateSelectionWithTouches): Use SimpleRange.
     105        (WebKit::WebPage::selectWithTwoTouches): Ditto.
     106        (WebKit::WebPage::extendSelection): Ditto.
     107        (WebKit::WebPage::selectWordBackward): Ditto.
     108        (WebKit::WebPage::moveSelectionByOffset): Ditto.
     109        (WebKit::WebPage::getRectsForGranularityWithSelectionOffset): Ditto.
     110        (WebKit::WebPage::selectPositionAtPoint): Ditto.
     111        (WebKit::WebPage::selectPositionAtBoundaryWithDirection): Ditto.
     112        (WebKit::WebPage::moveSelectionAtBoundaryWithDirection): Ditto.
     113        (WebKit::WebPage::rangeForGranularityAtPoint): Ditto.
     114        (WebKit::WebPage::selectTextWithGranularityAtPoint): Ditto.
     115        (WebKit::WebPage::updateSelectionWithExtentPointAndBoundary): Ditto.
     116        (WebKit::WebPage::updateSelectionWithExtentPoint): Ditto.
     117        (WebKit::WebPage::replaceSelectedText): Ditto.
     118        (WebKit::WebPage::replaceDictatedText): Ditto.
     119        (WebKit::WebPage::requestAutocorrectionData): Ditto.
     120        (WebKit::WebPage::applyAutocorrectionInternal): Ditto.
     121        (WebKit::WebPage::autocorrectionContext): Ditto.
     122        (WebKit::dataDetectorLinkPositionInformation): Ditto.
     123        (WebKit::WebPage::updateSelectionWithDelta): Ditto.
     124        (WebKit::WebPage::focusTextInputContextAndPlaceCaret): Ditto.
     125
    11262020-07-30  Alex Christensen  <achristensen@webkit.org>
    2127
  • trunk/Source/WebKit/Shared/API/c/mac/WKWebArchiveRef.cpp

    r251952 r265084  
    3434#include "WKBundleAPICast.h"
    3535#include "WKSharedAPICast.h"
     36#include <WebCore/Range.h>
     37#include <WebCore/SimpleRange.h>
    3638
    3739WKTypeID WKWebArchiveGetTypeID()
    … …  
    5456WKWebArchiveRef WKWebArchiveCreateFromRange(WKBundleRangeHandleRef rangeHandleRef)
    5557{
    56     auto webArchive = API::WebArchive::create(WebKit::toImpl(rangeHandleRef)->coreRange());
     58    auto webArchive = API::WebArchive::create(makeSimpleRange(WebKit::toImpl(rangeHandleRef)->coreRange()));
    5759    return WebKit::toAPI(&webArchive.leakRef());
    5860}
  • trunk/Source/WebKit/Shared/APIWebArchive.h

    r216810 r265084  
    2424 */
    2525
    26 #ifndef WebArchive_h
    27 #define WebArchive_h
     26#pragma once
    2827
    2928#if PLATFORM(COCOA)
    … …  
    3938namespace WebCore {
    4039class LegacyWebArchive;
    41 class Range;
     40struct SimpleRange;
    4241}
    4342
    … …  
    5352    static Ref<WebArchive> create(API::Data*);
    5453    static Ref<WebArchive> create(RefPtr<WebCore::LegacyWebArchive>&&);
    55     static Ref<WebArchive> create(WebCore::Range&);
     54    static Ref<WebArchive> create(const WebCore::SimpleRange&);
    5655
    5756    WebArchiveResource* mainResource();
    … …  
    7776
    7877#endif // PLATFORM(COCOA)
    79 
    80 #endif // WebArchive_h
  • trunk/Source/WebKit/Shared/APIWebArchive.mm

    r260366 r265084  
    5353}
    5454
    55 Ref<WebArchive> WebArchive::create(Range& range)
     55Ref<WebArchive> WebArchive::create(const SimpleRange& range)
    5656{
    57     return adoptRef(*new WebArchive(LegacyWebArchive::create(&range)));
     57    return adoptRef(*new WebArchive(LegacyWebArchive::create(range)));
    5858}
    5959
  • trunk/Source/WebKit/Shared/EditingRange.cpp

    r259401 r265084  
    3434namespace WebKit {
    3535
    36 RefPtr<WebCore::Range> EditingRange::toRange(WebCore::Frame& frame, const EditingRange& editingRange, EditingRangeIsRelativeTo base)
     36Optional<WebCore::SimpleRange> EditingRange::toRange(WebCore::Frame& frame, const EditingRange& editingRange, EditingRangeIsRelativeTo base)
    3737{
    3838    ASSERT(editingRange.location != notFound);
    … …  
    4848        auto* element = frame.selection().rootEditableElementOrDocumentElement();
    4949        if (!element)
    50             return nullptr;
    51         return createLiveRange(resolveCharacterRange(makeRangeSelectingNodeContents(*element), range));
     50            return WTF::nullopt;
     51        return resolveCharacterRange(makeRangeSelectingNodeContents(*element), range);
    5252    }
    5353
    … …  
    5656    auto paragraphStart = makeBoundaryPoint(startOfParagraph(frame.selection().selection().visibleStart()));
    5757    if (!paragraphStart)
    58         return nullptr;
     58        return WTF::nullopt;
    5959
    60     auto scopeEnd = makeRangeSelectingNodeContents(paragraphStart->container->treeScope().rootNode()).end;
    61     return createLiveRange(WebCore::resolveCharacterRange({ WTFMove(*paragraphStart), WTFMove(scopeEnd) }, range));
     60    auto scopeEnd = makeBoundaryPointAfterNodeContents(paragraphStart->container->treeScope().rootNode());
     61    return WebCore::resolveCharacterRange({ WTFMove(*paragraphStart), WTFMove(scopeEnd) }, range);
    6262}
    6363
    64 EditingRange EditingRange::fromRange(WebCore::Frame& frame, const WebCore::Range* range, EditingRangeIsRelativeTo editingRangeIsRelativeTo)
     64EditingRange EditingRange::fromRange(WebCore::Frame& frame, const Optional<WebCore::SimpleRange>& range, EditingRangeIsRelativeTo editingRangeIsRelativeTo)
    6565{
    6666    ASSERT(editingRangeIsRelativeTo == EditingRangeIsRelativeTo::EditableRoot);
  • trunk/Source/WebKit/Shared/EditingRange.h

    r259184 r265084  
    3232namespace WebCore {
    3333class Frame;
    34 class Range;
     34struct SimpleRange;
    3535}
    3636
    … …  
    5959    bool isValid() const { return location + length >= location; }
    6060
    61     static RefPtr<WebCore::Range> toRange(WebCore::Frame&, const EditingRange&, EditingRangeIsRelativeTo = EditingRangeIsRelativeTo::EditableRoot);
    62     static EditingRange fromRange(WebCore::Frame&, const WebCore::Range*, EditingRangeIsRelativeTo = EditingRangeIsRelativeTo::EditableRoot);
     61    static Optional<WebCore::SimpleRange> toRange(WebCore::Frame&, const EditingRange&, EditingRangeIsRelativeTo = EditingRangeIsRelativeTo::EditableRoot);
     62    static EditingRange fromRange(WebCore::Frame&, const Optional<WebCore::SimpleRange>&, EditingRangeIsRelativeTo = EditingRangeIsRelativeTo::EditableRoot);
    6363
    6464#if defined(__OBJC__)
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/APIInjectedBundleEditorClient.h

    r241749 r265084  
    3232
    3333namespace WebCore {
    34 class CSSStyleDeclaration;
    3534class DocumentFragment;
    3635class Node;
    37 class Range;
    3836class SharedBuffer;
     37class StyleProperties;
     38struct SimpleRange;
    3939}
    4040
    … …  
    5252    virtual ~EditorClient() { }
    5353
    54     virtual bool shouldBeginEditing(WebKit::WebPage&, WebCore::Range*) { return true; }
    55     virtual bool shouldEndEditing(WebKit::WebPage&, WebCore::Range*) { return true; }
    56     virtual bool shouldInsertNode(WebKit::WebPage&, WebCore::Node*, WebCore::Range* rangeToReplace, WebCore::EditorInsertAction) { return true; }
    57     virtual bool shouldInsertText(WebKit::WebPage&, StringImpl*, WebCore::Range* rangeToReplace, WebCore::EditorInsertAction) { return true; }
    58     virtual bool shouldDeleteRange(WebKit::WebPage&, WebCore::Range*) { return true; }
    59     virtual bool shouldChangeSelectedRange(WebKit::WebPage&, WebCore::Range* fromRange, WebCore::Range* toRange, WebCore::EAffinity affinity, bool stillSelecting) { return true; }
    60     virtual bool shouldApplyStyle(WebKit::WebPage&, WebCore::CSSStyleDeclaration*, WebCore::Range*) { return true; }
    61     virtual void didBeginEditing(WebKit::WebPage&, StringImpl* notificationName) { }
    62     virtual void didEndEditing(WebKit::WebPage&, StringImpl* notificationName) { }
    63     virtual void didChange(WebKit::WebPage&, StringImpl* notificationName) { }
    64     virtual void didChangeSelection(WebKit::WebPage&, StringImpl* notificationName) { }
    65     virtual void willWriteToPasteboard(WebKit::WebPage&, WebCore::Range*) { }
    66     virtual void getPasteboardDataForRange(WebKit::WebPage&, WebCore::Range*, Vector<WTF::String>& pasteboardTypes, Vector<RefPtr<WebCore::SharedBuffer>>& pasteboardData) { }
     54    virtual bool shouldBeginEditing(WebKit::WebPage&, const WebCore::SimpleRange&) { return true; }
     55    virtual bool shouldEndEditing(WebKit::WebPage&, const WebCore::SimpleRange&) { return true; }
     56    virtual bool shouldInsertNode(WebKit::WebPage&, WebCore::Node&, const Optional<WebCore::SimpleRange>&, WebCore::EditorInsertAction) { return true; }
     57    virtual bool shouldInsertText(WebKit::WebPage&, const WTF::String&, const Optional<WebCore::SimpleRange>&, WebCore::EditorInsertAction) { return true; }
     58    virtual bool shouldDeleteRange(WebKit::WebPage&, const Optional<WebCore::SimpleRange>&) { return true; }
     59    virtual bool shouldChangeSelectedRange(WebKit::WebPage&, const Optional<WebCore::SimpleRange>&, const Optional<WebCore::SimpleRange>&, WebCore::EAffinity, bool) { return true; }
     60    virtual bool shouldApplyStyle(WebKit::WebPage&, const WebCore::StyleProperties&, const Optional<WebCore::SimpleRange>&) { return true; }
     61    virtual void didBeginEditing(WebKit::WebPage&, const WTF::String&) { }
     62    virtual void didEndEditing(WebKit::WebPage&, const WTF::String&) { }
     63    virtual void didChange(WebKit::WebPage&, const WTF::String&) { }
     64    virtual void didChangeSelection(WebKit::WebPage&, const WTF::String&) { }
     65    virtual void willWriteToPasteboard(WebKit::WebPage&, const Optional<WebCore::SimpleRange>&) { }
     66    virtual void getPasteboardDataForRange(WebKit::WebPage&, const Optional<WebCore::SimpleRange>&, Vector<WTF::String>&, Vector<RefPtr<WebCore::SharedBuffer>>&) { }
    6767    virtual void didWriteToPasteboard(WebKit::WebPage&) { }
    68     virtual bool performTwoStepDrop(WebKit::WebPage&, WebCore::DocumentFragment&, WebCore::Range&, bool) { return false; }
     68    virtual bool performTwoStepDrop(WebKit::WebPage&, WebCore::DocumentFragment&, const WebCore::SimpleRange&, bool) { return false; }
    6969};
    7070
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitWebEditor.cpp

    r248846 r265084  
    8383
    8484private:
    85     void didChangeSelection(WebPage&, StringImpl*) override
     85    void didChangeSelection(WebPage&, const String&) final
    8686    {
    8787        g_signal_emit(m_editor, signals[SELECTION_CHANGED], 0);
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm

    r254241 r265084  
    3131#import <WebCore/DocumentFragment.h>
    3232#import <WebCore/HTMLElement.h>
     33#import <WebCore/SimpleRange.h>
    3334#import <WebCore/Text.h>
    3435#import <WebCore/markup.h>
    … …  
    8081- (WKDOMNode *)createDocumentFragmentWithText:(NSString *)text
    8182{
    82     return WebKit::toWKDOMNode(createFragmentFromText(downcast<WebCore::Document>(*_impl).createRange().get(), text).ptr());
     83    return WebKit::toWKDOMNode(createFragmentFromText(makeRangeSelectingNodeContents(downcast<WebCore::Document>(*_impl)), text).ptr());
    8384}
    8485
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKDOMRange.mm

    r261776 r265084  
    135135- (WKDOMRange *)rangeByExpandingToWordBoundaryByCharacters:(NSUInteger)characters inDirection:(WKDOMRangeDirection)direction
    136136{
    137     RefPtr<WebCore::Range> newRange = rangeExpandedByCharactersInDirectionAtWordBoundary(direction == WKDOMRangeDirectionForward ?  _impl->endPosition() : _impl->startPosition(), characters, direction == WKDOMRangeDirectionForward ? WebCore::SelectionDirection::Forward : WebCore::SelectionDirection::Backward);
    138 
    139     return [[[WKDOMRange alloc] _initWithImpl:newRange.get()] autorelease];
     137    auto newRange = rangeExpandedByCharactersInDirectionAtWordBoundary(direction == WKDOMRangeDirectionForward ?  _impl->endPosition() : _impl->startPosition(), characters, direction == WKDOMRangeDirectionForward ? WebCore::SelectionDirection::Forward : WebCore::SelectionDirection::Backward);
     138    return [[[WKDOMRange alloc] _initWithImpl:createLiveRange(newRange).get()] autorelease];
    140139}
    141140
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm

    r264247 r265084  
    560560
    561561    private:
    562         bool shouldInsertText(WebKit::WebPage&, StringImpl* text, WebCore::Range* rangeToReplace, WebCore::EditorInsertAction action) final
     562        bool shouldInsertText(WebKit::WebPage&, const WTF::String& text, const Optional<WebCore::SimpleRange>& rangeToReplace, WebCore::EditorInsertAction action) final
    563563        {
    564564            if (!m_delegateMethods.shouldInsertText)
    565565                return true;
    566566
    567             return [m_controller->_editingDelegate.get() _webProcessPlugInBrowserContextController:m_controller shouldInsertText:String(text) replacingRange:wrapper(*WebKit::InjectedBundleRangeHandle::getOrCreate(rangeToReplace)) givenAction:toWK(action)];
    568         }
    569 
    570         bool shouldChangeSelectedRange(WebKit::WebPage&, WebCore::Range* fromRange, WebCore::Range* toRange, WebCore::EAffinity affinity, bool stillSelecting) final
     567            return [m_controller->_editingDelegate.get() _webProcessPlugInBrowserContextController:m_controller shouldInsertText:text replacingRange:wrapper(*WebKit::createHandle(rangeToReplace)) givenAction:toWK(action)];
     568        }
     569
     570        bool shouldChangeSelectedRange(WebKit::WebPage&, const Optional<WebCore::SimpleRange>& fromRange, const Optional<WebCore::SimpleRange>& toRange, WebCore::EAffinity affinity, bool stillSelecting) final
    571571        {
    572572            if (!m_delegateMethods.shouldChangeSelectedRange)
    573573                return true;
    574574
    575             auto apiFromRange = fromRange ? adoptNS([[WKDOMRange alloc] _initWithImpl:fromRange]) : nil;
    576             auto apiToRange = toRange ? adoptNS([[WKDOMRange alloc] _initWithImpl:toRange]) : nil;
     575            auto apiFromRange = adoptNS([[WKDOMRange alloc] _initWithImpl:createLiveRange(fromRange).get()]);
     576            auto apiToRange = adoptNS([[WKDOMRange alloc] _initWithImpl:createLiveRange(toRange).get()]);
    577577#if PLATFORM(IOS_FAMILY)
    578578            UITextStorageDirection apiAffinity = affinity == WebCore::UPSTREAM ? UITextStorageDirectionBackward : UITextStorageDirectionForward;
    … …  
    584584        }
    585585
    586         void didChange(WebKit::WebPage&, StringImpl*) final
     586        void didChange(WebKit::WebPage&, const String&) final
    587587        {
    588588            if (!m_delegateMethods.didChange)
    … …  
    592592        }
    593593
    594         void willWriteToPasteboard(WebKit::WebPage&, WebCore::Range* range) final
     594        void willWriteToPasteboard(WebKit::WebPage&, const Optional<WebCore::SimpleRange>& range) final
    595595        {
    596596            if (!m_delegateMethods.willWriteToPasteboard)
    597597                return;
    598598
    599             [m_controller->_editingDelegate.get() _webProcessPlugInBrowserContextController:m_controller willWriteRangeToPasteboard:wrapper(*WebKit::InjectedBundleRangeHandle::getOrCreate(range).get())];
    600         }
    601 
    602         void getPasteboardDataForRange(WebKit::WebPage&, WebCore::Range* range, Vector<String>& pasteboardTypes, Vector<RefPtr<WebCore::SharedBuffer>>& pasteboardData) final
     599            [m_controller->_editingDelegate.get() _webProcessPlugInBrowserContextController:m_controller willWriteRangeToPasteboard:wrapper(WebKit::createHandle(range).get())];
     600        }
     601
     602        void getPasteboardDataForRange(WebKit::WebPage&, const Optional<WebCore::SimpleRange>& range, Vector<String>& pasteboardTypes, Vector<RefPtr<WebCore::SharedBuffer>>& pasteboardData) final
    603603        {
    604604            if (!m_delegateMethods.getPasteboardDataForRange)
    605605                return;
    606606
    607             auto dataByType = [m_controller->_editingDelegate.get() _webProcessPlugInBrowserContextController:m_controller pasteboardDataForRange:wrapper(*WebKit::InjectedBundleRangeHandle::getOrCreate(range).get())];
     607            auto dataByType = [m_controller->_editingDelegate.get() _webProcessPlugInBrowserContextController:m_controller pasteboardDataForRange:wrapper(WebKit::createHandle(range).get())];
    608608            for (NSString *type in dataByType) {
    609609                pasteboardTypes.append(type);
    … …  
    620620        }
    621621
    622         bool performTwoStepDrop(WebKit::WebPage&, WebCore::DocumentFragment& fragment, WebCore::Range& range, bool isMove) final
     622        bool performTwoStepDrop(WebKit::WebPage&, WebCore::DocumentFragment& fragment, const WebCore::SimpleRange& range, bool isMove) final
    623623        {
    624624            if (!m_delegateMethods.performTwoStepDrop)
    625625                return false;
    626626
    627             auto rangeHandle = WebKit::InjectedBundleRangeHandle::getOrCreate(&range);
     627            auto rangeHandle = WebKit::createHandle(range);
    628628            auto nodeHandle = WebKit::InjectedBundleNodeHandle::getOrCreate(&fragment);
    629629            return [m_controller->_editingDelegate.get() _webProcessPlugInBrowserContextController:m_controller performTwoStepDrop:wrapper(*nodeHandle) atDestination:wrapper(*rangeHandle) isMove:isMove];
  • trunk/Source/WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp

    r258129 r265084  
    5555using namespace WebCore;
    5656
    57 typedef HashMap<Range*, InjectedBundleRangeHandle*> DOMRangeHandleCache;
     57using DOMRangeHandleCache = HashMap<Range*, InjectedBundleRangeHandle*>;
    5858
    5959static DOMRangeHandleCache& domRangeHandleCache()
    … …  
    6565RefPtr<InjectedBundleRangeHandle> InjectedBundleRangeHandle::getOrCreate(JSContextRef context, JSObjectRef object)
    6666{
    67     Range* range = JSRange::toWrapped(toJS(context)->vm(), toJS(object));
    68     return getOrCreate(range);
     67    return getOrCreate(JSRange::toWrapped(toJS(context)->vm(), toJS(object)));
    6968}
    7069
    … …  
    7372    if (!range)
    7473        return nullptr;
    75 
    76     DOMRangeHandleCache::AddResult result = domRangeHandleCache().add(range, nullptr);
     74    auto result = domRangeHandleCache().add(range, nullptr);
    7775    if (!result.isNewEntry)
    7876        return result.iterator->value;
    79 
    80     auto rangeHandle = InjectedBundleRangeHandle::create(*range);
     77    auto rangeHandle = adoptRef(*new InjectedBundleRangeHandle(*range));
    8178    result.iterator->value = rangeHandle.ptr();
    8279    return rangeHandle;
    83 }
    84 
    85 Ref<InjectedBundleRangeHandle> InjectedBundleRangeHandle::create(Range& range)
    86 {
    87     return adoptRef(*new InjectedBundleRangeHandle(range));
    8880}
    8981
    … …  
    179171}
    180172
     173RefPtr<InjectedBundleRangeHandle> createHandle(const Optional<WebCore::SimpleRange>& range)
     174{
     175    return InjectedBundleRangeHandle::getOrCreate(createLiveRange(range).get());
     176}
     177
    181178} // namespace WebKit
  • trunk/Source/WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h

    r216810 r265084  
    2424 */
    2525
    26 #ifndef InjectedBundleRangeHandle_h
    27 #define InjectedBundleRangeHandle_h
     26#pragma once
    2827
    2928#include "APIObject.h"
    … …  
    3635class IntRect;
    3736class Range;
     37struct SimpleRange;
    3838}
    3939
    … …  
    6060
    6161private:
    62     static Ref<InjectedBundleRangeHandle> create(WebCore::Range&);
    6362    InjectedBundleRangeHandle(WebCore::Range&);
    6463
    … …  
    6665};
    6766
     67RefPtr<InjectedBundleRangeHandle> createHandle(const Optional<WebCore::SimpleRange>&);
     68
    6869} // namespace WebKit
    69 
    70 #endif // InjectedBundleRangeHandle_h
  • trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageEditorClient.cpp

    r241749 r265084  
    3939#include "WebPage.h"
    4040#include <WebCore/DocumentFragment.h>
     41#include <WebCore/StyleProperties.h>
    4142#include <wtf/text/WTFString.h>
    4243
    4344namespace WebKit {
    4445using namespace WebCore;
     46
     47static RefPtr<InjectedBundleCSSStyleDeclarationHandle> createHandle(const StyleProperties& style)
     48{
     49    return InjectedBundleCSSStyleDeclarationHandle::getOrCreate(&style.mutableCopy()->ensureCSSStyleDeclaration());
     50}
    4551
    4652InjectedBundlePageEditorClient::InjectedBundlePageEditorClient(const WKBundlePageEditorClientBase& client)
    … …  
    4955}
    5056
    51 bool InjectedBundlePageEditorClient::shouldBeginEditing(WebPage& page, Range* range)
     57bool InjectedBundlePageEditorClient::shouldBeginEditing(WebPage& page, const SimpleRange& range)
    5258{
    53     if (m_client.shouldBeginEditing) {
    54         RefPtr<InjectedBundleRangeHandle> rangeHandle = InjectedBundleRangeHandle::getOrCreate(range);
    55         return m_client.shouldBeginEditing(toAPI(&page), toAPI(rangeHandle.get()), m_client.base.clientInfo);
     59    if (m_client.shouldBeginEditing)
     60        return m_client.shouldBeginEditing(toAPI(&page), toAPI(createHandle(range).get()), m_client.base.clientInfo);
     61    return true;
     62}
     63
     64bool InjectedBundlePageEditorClient::shouldEndEditing(WebPage& page, const SimpleRange& range)
     65{
     66    if (m_client.shouldEndEditing)
     67        return m_client.shouldEndEditing(toAPI(&page), toAPI(createHandle(range).get()), m_client.base.clientInfo);
     68    return true;
     69}
     70
     71bool InjectedBundlePageEditorClient::shouldInsertNode(WebPage& page, Node& node, const Optional<SimpleRange>& rangeToReplace, EditorInsertAction action)
     72{
     73    if (m_client.shouldInsertNode) {
     74        RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::getOrCreate(node);
     75        return m_client.shouldInsertNode(toAPI(&page), toAPI(nodeHandle.get()), toAPI(createHandle(rangeToReplace).get()), toAPI(action), m_client.base.clientInfo);
    5676    }
    5777    return true;
    5878}
    5979
    60 bool InjectedBundlePageEditorClient::shouldEndEditing(WebPage& page, Range* range)
     80bool InjectedBundlePageEditorClient::shouldInsertText(WebPage& page, const String& text, const Optional<SimpleRange>& rangeToReplace, EditorInsertAction action)
    6181{
    62     if (m_client.shouldEndEditing) {
    63         RefPtr<InjectedBundleRangeHandle> rangeHandle = InjectedBundleRangeHandle::getOrCreate(range);
    64         return m_client.shouldEndEditing(toAPI(&page), toAPI(rangeHandle.get()), m_client.base.clientInfo);
    65     }
     82    if (m_client.shouldInsertText)
     83        return m_client.shouldInsertText(toAPI(&page), toAPI(text.impl()), toAPI(createHandle(rangeToReplace).get()), toAPI(action), m_client.base.clientInfo);
    6684    return true;
    6785}
    6886
    69 bool InjectedBundlePageEditorClient::shouldInsertNode(WebPage& page, Node* node, Range* rangeToReplace, EditorInsertAction action)
     87bool InjectedBundlePageEditorClient::shouldDeleteRange(WebPage& page, const Optional<WebCore::SimpleRange>& range)
    7088{
    71     if (m_client.shouldInsertNode) {
    72         RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::getOrCreate(node);
    73         RefPtr<InjectedBundleRangeHandle> rangeToReplaceHandle = InjectedBundleRangeHandle::getOrCreate(rangeToReplace);
    74         return m_client.shouldInsertNode(toAPI(&page), toAPI(nodeHandle.get()), toAPI(rangeToReplaceHandle.get()), toAPI(action), m_client.base.clientInfo);
    75     }
     89    if (m_client.shouldDeleteRange)
     90        return m_client.shouldDeleteRange(toAPI(&page), toAPI(createHandle(range).get()), m_client.base.clientInfo);
    7691    return true;
    7792}
    7893
    79 bool InjectedBundlePageEditorClient::shouldInsertText(WebPage& page, StringImpl* text, Range* rangeToReplace, EditorInsertAction action)
     94bool InjectedBundlePageEditorClient::shouldChangeSelectedRange(WebPage& page, const Optional<SimpleRange>& fromRange, const Optional<SimpleRange>& toRange, EAffinity affinity, bool stillSelecting)
    8095{
    81     if (m_client.shouldInsertText) {
    82         RefPtr<InjectedBundleRangeHandle> rangeToReplaceHandle = InjectedBundleRangeHandle::getOrCreate(rangeToReplace);
    83         return m_client.shouldInsertText(toAPI(&page), toAPI(text), toAPI(rangeToReplaceHandle.get()), toAPI(action), m_client.base.clientInfo);
    84     }
     96    if (m_client.shouldChangeSelectedRange)
     97        return m_client.shouldChangeSelectedRange(toAPI(&page), toAPI(createHandle(fromRange).get()), toAPI(createHandle(toRange).get()), toAPI(affinity), stillSelecting, m_client.base.clientInfo);
    8598    return true;
    8699}
    87100
    88 bool InjectedBundlePageEditorClient::shouldDeleteRange(WebPage& page, Range* range)
     101bool InjectedBundlePageEditorClient::shouldApplyStyle(WebPage& page, const StyleProperties& style, const Optional<SimpleRange>& range)
    89102{
    90     if (m_client.shouldDeleteRange) {
    91         RefPtr<InjectedBundleRangeHandle> rangeHandle = InjectedBundleRangeHandle::getOrCreate(range);
    92         return m_client.shouldDeleteRange(toAPI(&page), toAPI(rangeHandle.get()), m_client.base.clientInfo);
    93     }
     103    if (m_client.shouldApplyStyle)
     104        return m_client.shouldApplyStyle(toAPI(&page), toAPI(createHandle(style).get()), toAPI(createHandle(range).get()), m_client.base.clientInfo);
    94105    return true;
    95106}
    96107
    97 bool InjectedBundlePageEditorClient::shouldChangeSelectedRange(WebPage& page, Range* fromRange, Range* toRange, EAffinity affinity, bool stillSelecting)
     108void InjectedBundlePageEditorClient::didBeginEditing(WebPage& page, const String& notificationName)
    98109{
    99     if (m_client.shouldChangeSelectedRange) {
    100         RefPtr<InjectedBundleRangeHandle> fromRangeHandle = InjectedBundleRangeHandle::getOrCreate(fromRange);
    101         RefPtr<InjectedBundleRangeHandle> toRangeHandle = InjectedBundleRangeHandle::getOrCreate(toRange);
    102         return m_client.shouldChangeSelectedRange(toAPI(&page), toAPI(fromRangeHandle.get()), toAPI(toRangeHandle.get()), toAPI(affinity), stillSelecting, m_client.base.clientInfo);
    103     }
    104     return true;
     110    if (m_client.didBeginEditing)
     111        m_client.didBeginEditing(toAPI(&page), toAPI(notificationName.impl()), m_client.base.clientInfo);
    105112}
    106113
    107 bool InjectedBundlePageEditorClient::shouldApplyStyle(WebPage& page, CSSStyleDeclaration* style, Range* range)
     114void InjectedBundlePageEditorClient::didEndEditing(WebPage& page, const String& notificationName)
    108115{
    109     if (m_client.shouldApplyStyle) {
    110         RefPtr<InjectedBundleCSSStyleDeclarationHandle> styleHandle = InjectedBundleCSSStyleDeclarationHandle::getOrCreate(style);
    111         RefPtr<InjectedBundleRangeHandle> rangeHandle = InjectedBundleRangeHandle::getOrCreate(range);
    112         return m_client.shouldApplyStyle(toAPI(&page), toAPI(styleHandle.get()), toAPI(rangeHandle.get()), m_client.base.clientInfo);
    113     }
    114     return true;
     116    if (m_client.didEndEditing)
     117        m_client.didEndEditing(toAPI(&page), toAPI(notificationName.impl()), m_client.base.clientInfo);
    115118}
    116119
    117 void InjectedBundlePageEditorClient::didBeginEditing(WebPage& page, StringImpl* notificationName)
     120void InjectedBundlePageEditorClient::didChange(WebPage& page, const String& notificationName)
    118121{
    119     if (m_client.didBeginEditing)
    120         m_client.didBeginEditing(toAPI(&page), toAPI(notificationName), m_client.base.clientInfo);
     122    if (m_client.didChange)
     123        m_client.didChange(toAPI(&page), toAPI(notificationName.impl()), m_client.base.clientInfo);
    121124}
    122125
    123 void InjectedBundlePageEditorClient::didEndEditing(WebPage& page, StringImpl* notificationName)
     126void InjectedBundlePageEditorClient::didChangeSelection(WebPage& page, const String& notificationName)
    124127{
    125     if (m_client.didEndEditing)
    126         m_client.didEndEditing(toAPI(&page), toAPI(notificationName), m_client.base.clientInfo);
     128    if (m_client.didChangeSelection)
     129        m_client.didChangeSelection(toAPI(&page), toAPI(notificationName.impl()), m_client.base.clientInfo);
    127130}
    128131
    129 void InjectedBundlePageEditorClient::didChange(WebPage& page, StringImpl* notificationName)
     132void InjectedBundlePageEditorClient::willWriteToPasteboard(WebPage& page, const Optional<SimpleRange>& range)
    130133{
    131     if (m_client.didChange)
    132         m_client.didChange(toAPI(&page), toAPI(notificationName), m_client.base.clientInfo);
     134    if (m_client.willWriteToPasteboard)
     135        m_client.willWriteToPasteboard(toAPI(&page), toAPI(createHandle(range).get()), m_client.base.clientInfo);
    133136}
    134137
    135 void InjectedBundlePageEditorClient::didChangeSelection(WebPage& page, StringImpl* notificationName)
    136 {
    137     if (m_client.didChangeSelection)
    138         m_client.didChangeSelection(toAPI(&page), toAPI(notificationName), m_client.base.clientInfo);
    139 }
    140 
    141 void InjectedBundlePageEditorClient::willWriteToPasteboard(WebPage& page, Range* range)
    142 {
    143     if (m_client.willWriteToPasteboard) {
    144         RefPtr<InjectedBundleRangeHandle> rangeHandle = InjectedBundleRangeHandle::getOrCreate(range);
    145         m_client.willWriteToPasteboard(toAPI(&page), toAPI(rangeHandle.get()), m_client.base.clientInfo);
    146     }
    147 }
    148 
    149 void InjectedBundlePageEditorClient::getPasteboardDataForRange(WebPage& page, Range* range, Vector<String>& pasteboardTypes, Vector<RefPtr<SharedBuffer>>& pasteboardData)
     138void InjectedBundlePageEditorClient::getPasteboardDataForRange(WebPage& page, const Optional<SimpleRange>& range, Vector<String>& pasteboardTypes, Vector<RefPtr<SharedBuffer>>& pasteboardData)
    150139{
    151140    if (m_client.getPasteboardDataForRange) {
    152         RefPtr<InjectedBundleRangeHandle> rangeHandle = InjectedBundleRangeHandle::getOrCreate(range);
    153         WKArrayRef types = 0;
    154         WKArrayRef data = 0;
    155         m_client.getPasteboardDataForRange(toAPI(&page), toAPI(rangeHandle.get()), &types, &data, m_client.base.clientInfo);
    156         RefPtr<API::Array> typesArray = adoptRef(toImpl(types));
    157         RefPtr<API::Array> dataArray = adoptRef(toImpl(data));
     141        WKArrayRef types = nullptr;
     142        WKArrayRef data = nullptr;
     143        m_client.getPasteboardDataForRange(toAPI(&page), toAPI(createHandle(range).get()), &types, &data, m_client.base.clientInfo);
     144        auto typesArray = adoptRef(toImpl(types));
     145        auto dataArray = adoptRef(toImpl(data));
    158146
    159147        pasteboardTypes.clear();
    … …  
    175163}
    176164
    177 bool InjectedBundlePageEditorClient::performTwoStepDrop(WebPage& page, DocumentFragment& fragment, Range& destination, bool isMove)
     165bool InjectedBundlePageEditorClient::performTwoStepDrop(WebPage& page, DocumentFragment& fragment, const SimpleRange& destination, bool isMove)
    178166{
    179167    if (!m_client.performTwoStepDrop)
    180168        return false;
    181169
    182     auto rangeHandle = InjectedBundleRangeHandle::getOrCreate(&destination);
    183170    auto nodeHandle = InjectedBundleNodeHandle::getOrCreate(&fragment);
    184     return m_client.performTwoStepDrop(toAPI(&page), toAPI(nodeHandle.get()), toAPI(rangeHandle.get()), isMove, m_client.base.clientInfo);
     171    return m_client.performTwoStepDrop(toAPI(&page), toAPI(nodeHandle.get()), toAPI(createHandle(destination).get()), isMove, m_client.base.clientInfo);
    185172}
    186173
  • trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageEditorClient.h

    r241749 r265084  
    4040class DocumentFragment;
    4141class Node;
    42 class Range;
     42struct SimpleRange;
    4343}
    4444
    … …  
    5353
    5454private:
    55     bool shouldBeginEditing(WebPage&, WebCore::Range*) final;
    56     bool shouldEndEditing(WebPage&, WebCore::Range*) final;
    57     bool shouldInsertNode(WebPage&, WebCore::Node*, WebCore::Range* rangeToReplace, WebCore::EditorInsertAction) final;
    58     bool shouldInsertText(WebPage&, StringImpl*, WebCore::Range* rangeToReplace, WebCore::EditorInsertAction) final;
    59     bool shouldDeleteRange(WebPage&, WebCore::Range*) final;
    60     bool shouldChangeSelectedRange(WebPage&, WebCore::Range* fromRange, WebCore::Range* toRange, WebCore::EAffinity, bool stillSelecting) final;
    61     bool shouldApplyStyle(WebPage&, WebCore::CSSStyleDeclaration*, WebCore::Range*) final;
    62     void didBeginEditing(WebPage&, StringImpl* notificationName) final;
    63     void didEndEditing(WebPage&, StringImpl* notificationName) final;
    64     void didChange(WebPage&, StringImpl* notificationName) final;
    65     void didChangeSelection(WebPage&, StringImpl* notificationName) final;
    66     void willWriteToPasteboard(WebPage&, WebCore::Range*) final;
    67     void getPasteboardDataForRange(WebPage&, WebCore::Range*, Vector<String>& pasteboardTypes, Vector<RefPtr<WebCore::SharedBuffer>>& pasteboardData) final;
     55    bool shouldBeginEditing(WebPage&, const WebCore::SimpleRange&) final;
     56    bool shouldEndEditing(WebPage&, const WebCore::SimpleRange&) final;
     57    bool shouldInsertNode(WebPage&, WebCore::Node&, const Optional<WebCore::SimpleRange>& rangeToReplace, WebCore::EditorInsertAction) final;
     58    bool shouldInsertText(WebPage&, const String&, const Optional<WebCore::SimpleRange>& rangeToReplace, WebCore::EditorInsertAction) final;
     59    bool shouldDeleteRange(WebPage&, const Optional<WebCore::SimpleRange>&) final;
     60    bool shouldChangeSelectedRange(WebPage&, const Optional<WebCore::SimpleRange>& fromRange, const Optional<WebCore::SimpleRange>& toRange, WebCore::EAffinity, bool stillSelecting) final;
     61    bool shouldApplyStyle(WebPage&, const WebCore::StyleProperties&, const Optional<WebCore::SimpleRange>&) final;
     62    void didBeginEditing(WebPage&, const String& notificationName) final;
     63    void didEndEditing(WebPage&, const String& notificationName) final;
     64    void didChange(WebPage&, const String& notificationName) final;
     65    void didChangeSelection(WebPage&, const String& notificationName) final;
     66    void willWriteToPasteboard(WebPage&, const Optional<WebCore::SimpleRange>&) final;
     67    void getPasteboardDataForRange(WebPage&, const Optional<WebCore::SimpleRange>&, Vector<String>& pasteboardTypes, Vector<RefPtr<WebCore::SharedBuffer>>& pasteboardData) final;
    6868    void didWriteToPasteboard(WebPage&) final;
    69     bool performTwoStepDrop(WebPage&, WebCore::DocumentFragment&, WebCore::Range& destination, bool isMove) final;
     69    bool performTwoStepDrop(WebPage&, WebCore::DocumentFragment&, const WebCore::SimpleRange& destination, bool isMove) final;
    7070};
    7171
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp

    r264905 r265084  
    7878bool WebEditorClient::shouldDeleteRange(const Optional<SimpleRange>& range)
    7979{
    80     return m_page->injectedBundleEditorClient().shouldDeleteRange(*m_page, createLiveRange(range).get());
     80    return m_page->injectedBundleEditorClient().shouldDeleteRange(*m_page, range);
    8181}
    8282
    … …  
    119119bool WebEditorClient::shouldBeginEditing(const SimpleRange& range)
    120120{
    121     return m_page->injectedBundleEditorClient().shouldBeginEditing(*m_page, createLiveRange(range).ptr());
     121    return m_page->injectedBundleEditorClient().shouldBeginEditing(*m_page, range);
    122122}
    123123
    124124bool WebEditorClient::shouldEndEditing(const SimpleRange& range)
    125125{
    126     return m_page->injectedBundleEditorClient().shouldEndEditing(*m_page, createLiveRange(range).ptr());
     126    return m_page->injectedBundleEditorClient().shouldEndEditing(*m_page, range);
    127127}
    128128
    129129bool WebEditorClient::shouldInsertNode(Node& node, const Optional<SimpleRange>& rangeToReplace, EditorInsertAction action)
    130130{
    131     return m_page->injectedBundleEditorClient().shouldInsertNode(*m_page, &node, createLiveRange(rangeToReplace).get(), action);
     131    return m_page->injectedBundleEditorClient().shouldInsertNode(*m_page, node, rangeToReplace, action);
    132132}
    133133
    134134bool WebEditorClient::shouldInsertText(const String& text, const Optional<SimpleRange>& rangeToReplace, EditorInsertAction action)
    135135{
    136     return m_page->injectedBundleEditorClient().shouldInsertText(*m_page, text.impl(), createLiveRange(rangeToReplace).get(), action);
     136    return m_page->injectedBundleEditorClient().shouldInsertText(*m_page, text, rangeToReplace, action);
    137137}
    138138
    139139bool WebEditorClient::shouldChangeSelectedRange(const Optional<SimpleRange>& fromRange, const Optional<SimpleRange>& toRange, EAffinity affinity, bool stillSelecting)
    140140{
    141     return m_page->injectedBundleEditorClient().shouldChangeSelectedRange(*m_page, createLiveRange(fromRange).get(), createLiveRange(toRange).get(), affinity, stillSelecting);
     141    return m_page->injectedBundleEditorClient().shouldChangeSelectedRange(*m_page, fromRange, toRange, affinity, stillSelecting);
    142142}
    143143   
    144144bool WebEditorClient::shouldApplyStyle(const StyleProperties& style, const Optional<SimpleRange>& range)
    145145{
    146     return m_page->injectedBundleEditorClient().shouldApplyStyle(*m_page, &style.mutableCopy()->ensureCSSStyleDeclaration(), createLiveRange(range).get());
     146    return m_page->injectedBundleEditorClient().shouldApplyStyle(*m_page, style, range);
    147147}
    148148
    … …  
    269269void WebEditorClient::willWriteSelectionToPasteboard(const Optional<SimpleRange>& range)
    270270{
    271     m_page->injectedBundleEditorClient().willWriteToPasteboard(*m_page, createLiveRange(range).get());
     271    m_page->injectedBundleEditorClient().willWriteToPasteboard(*m_page, range);
    272272}
    273273
    274274void WebEditorClient::getClientPasteboardData(const Optional<SimpleRange>& range, Vector<String>& pasteboardTypes, Vector<RefPtr<SharedBuffer>>& pasteboardData)
    275275{
    276     m_page->injectedBundleEditorClient().getPasteboardDataForRange(*m_page, createLiveRange(range).get(), pasteboardTypes, pasteboardData);
     276    m_page->injectedBundleEditorClient().getPasteboardDataForRange(*m_page, range, pasteboardTypes, pasteboardData);
    277277}
    278278
    279279bool WebEditorClient::performTwoStepDrop(DocumentFragment& fragment, const SimpleRange& destination, bool isMove)
    280280{
    281     return m_page->injectedBundleEditorClient().performTwoStepDrop(*m_page, fragment, createLiveRange(destination), isMove);
     281    return m_page->injectedBundleEditorClient().performTwoStepDrop(*m_page, fragment, destination, isMove);
    282282}
    283283
    … …  
    538538{
    539539    auto selectionStart = currentSelection.visibleStart();
    540     auto selectionStartBoundary = makeBoundaryPoint(selectionStart);
    541     auto paragraphStart = makeBoundaryPoint(startOfParagraph(selectionStart));
    542     if (!selectionStartBoundary || !paragraphStart)
    543         return 0;
    544     return characterCount({ *paragraphStart, *selectionStartBoundary });
     540    auto range = makeSimpleRange(selectionStart, startOfParagraph(selectionStart));
     541    return range ? characterCount(*range) : 0;
    545542}
    546543
  • trunk/Source/WebKit/WebProcess/WebPage/FindController.cpp

    r264584 r265084  
    4747#include <WebCore/PlatformMouseEvent.h>
    4848#include <WebCore/PluginDocument.h>
     49#include <WebCore/Range.h>
    4950#include <WebCore/SimpleRange.h>
    5051
    … …  
    112113    const uint32_t maximumNumberOfMatchesToReplace = 1000;
    113114
    114     Vector<Ref<Range>> rangesToReplace;
     115    Vector<SimpleRange> rangesToReplace;
    115116    rangesToReplace.reserveCapacity(std::min<uint32_t>(maximumNumberOfMatchesToReplace, matchIndices.size()));
    116117    for (auto index : matchIndices) {
    117118        if (index < m_findMatches.size())
    118             rangesToReplace.uncheckedAppend(*m_findMatches[index]);
     119            rangesToReplace.uncheckedAppend(m_findMatches[index]);
    119120        if (rangesToReplace.size() >= maximumNumberOfMatchesToReplace)
    120121            break;
    … …  
    244245    if (!pluginView) {
    245246        if (Frame* selectedFrame = frameWithSelection(m_webPage->corePage())) {
    246             FrameSelection& fs = selectedFrame->selection();
    247             if (fs.selectionBounds().isEmpty()) {
    248                 m_findMatches.clear();
    249                 int indexForSelection;
    250                 m_webPage->corePage()->findStringMatchingRanges(string, coreOptions, maxMatchCount, m_findMatches, indexForSelection);
    251                 m_foundStringMatchIndex = indexForSelection;
     247            if (selectedFrame->selection().selectionBounds().isEmpty()) {
     248                auto result = m_webPage->corePage()->findTextMatches(string, coreOptions, maxMatchCount);
     249                m_findMatches = WTFMove(result.ranges);
     250                m_foundStringMatchIndex = result.indexForSelection;
    252251                foundStringStartsAfterSelection = true;
    253252            }
    … …  
    285284void FindController::findStringMatches(const String& string, OptionSet<FindOptions> options, unsigned maxMatchCount)
    286285{
    287     m_findMatches.clear();
    288     int indexForSelection;
    289 
    290     m_webPage->corePage()->findStringMatchingRanges(string, core(options), maxMatchCount, m_findMatches, indexForSelection);
     286    auto result = m_webPage->corePage()->findTextMatches(string, core(options), maxMatchCount);
     287    m_findMatches = WTFMove(result.ranges);
    291288
    292289    Vector<Vector<IntRect>> matchRects;
    293290    for (auto& range : m_findMatches)
    294         matchRects.append(RenderObject::absoluteTextRects(*range));
    295 
    296     m_webPage->send(Messages::WebPageProxy::DidFindStringMatches(string, matchRects, indexForSelection));
     291        matchRects.append(RenderObject::absoluteTextRects(range));
     292
     293    m_webPage->send(Messages::WebPageProxy::DidFindStringMatches(string, matchRects, result.indexForSelection));
    297294
    298295    if (!options.contains(FindOptions::ShowOverlay) && !options.contains(FindOptions::ShowFindIndicator))
    … …  
    309306    if (matchIndex >= m_findMatches.size())
    310307        return;
    311     Frame* frame = m_findMatches[matchIndex]->startContainer().document().frame();
     308    Frame* frame = m_findMatches[matchIndex].start.container->document().frame();
    312309    if (!frame)
    313310        return;
    314311
    315312    VisibleSelection oldSelection = frame->selection().selection();
    316     frame->selection().setSelection(VisibleSelection(*m_findMatches[matchIndex]));
     313    frame->selection().setSelection(m_findMatches[matchIndex]);
    317314
    318315    RefPtr<ShareableBitmap> selectionSnapshot = WebFrame::fromCoreFrame(*frame)->createSelectionSnapshot();
    … …  
    340337    if (matchIndex >= m_findMatches.size())
    341338        return;
    342     Frame* frame = m_findMatches[matchIndex]->startContainer().document().frame();
     339    Frame* frame = m_findMatches[matchIndex].start.container->document().frame();
    343340    if (!frame)
    344341        return;
    345     frame->selection().setSelection(VisibleSelection(*m_findMatches[matchIndex]));
     342    frame->selection().setSelection(m_findMatches[matchIndex]);
    346343}
    347344
  • trunk/Source/WebKit/WebProcess/WebPage/FindController.h

    r264055 r265084  
    107107    bool m_isShowingFindIndicator { false };
    108108    WebCore::IntRect m_findIndicatorRect;
    109     Vector<RefPtr<WebCore::Range>> m_findMatches;
     109    Vector<WebCore::SimpleRange> m_findMatches;
    110110    // Index value is -1 if not found or if number of matches exceeds provided maximum.
    111111    int m_foundStringMatchIndex { -1 };
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r264842 r265084  
    54385438{
    54395439    Frame& frame = m_page->focusController().focusedOrMainFrame();
    5440     completionHandler(EditingRange::fromRange(frame, createLiveRange(frame.editor().compositionRange()).get()));
     5440    completionHandler(EditingRange::fromRange(frame, frame.editor().compositionRange()));
    54415441}
    54425442
    … …  
    54445444{
    54455445    Frame& frame = m_page->focusController().focusedOrMainFrame();
    5446     completionHandler(EditingRange::fromRange(frame, createLiveRange(frame.selection().selection().toNormalizedRange()).get()));
     5446    completionHandler(EditingRange::fromRange(frame, frame.selection().selection().toNormalizedRange()));
    54475447}
    54485448
    … …  
    54535453    auto& frame = result.innerNonSharedNode() ? *result.innerNodeFrame() : m_page->focusController().focusedOrMainFrame();
    54545454    auto range = frame.rangeForPoint(result.roundedPointInInnerNodeFrame());
    5455     auto editingRange = EditingRange::fromRange(frame, range.get());
    5456     send(Messages::WebPageProxy::UnsignedCallback(static_cast<uint64_t>(editingRange.location), callbackID));
     5455    auto editingRange = EditingRange::fromRange(frame, makeSimpleRange(range));
     5456    send(Messages::WebPageProxy::UnsignedCallback(editingRange.location, callbackID));
    54575457}
    54585458
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r265044 r265084  
    162162}
    163163
    164 static String plainTextForContext(const Range* range)
    165 {
    166     return range ? plainTextForContext(SimpleRange { *range }) : emptyString();
    167 }
    168 
    169164static String plainTextForDisplay(const SimpleRange& range)
    170165{
    … …  
    172167}
    173168
    174 static String plainTextForDisplay(const Range* range)
     169static String plainTextForDisplay(const Optional<SimpleRange>& range)
    175170{
    176171    return range ? plainTextForDisplay(*range) : emptyString();
    … …  
    291286        // FIXME: The following check should take into account writing direction.
    292287        postLayoutData.isReplaceAllowed = result.isContentEditable && atBoundaryOfGranularity(selection.start(), TextGranularity::WordGranularity, SelectionDirection::Forward);
    293         postLayoutData.wordAtSelection = plainTextForContext(wordRangeFromPosition(selection.start()).get());
     288        postLayoutData.wordAtSelection = plainTextForContext(wordRangeFromPosition(selection.start()));
    294289        if (selection.isContentEditable())
    295290            charactersAroundPosition(selection.start(), postLayoutData.characterAfterSelection, postLayoutData.characterBeforeSelection, postLayoutData.twoCharacterBeforeSelection);
    … …  
    553548    }
    554549    const int selectionExtendedContextLength = 350;
    555    
    556     String selectedText = plainTextForContext(frame.selection().selection().toNormalizedRange());
    557     String textBefore = plainTextForDisplay(rangeExpandedByCharactersInDirectionAtWordBoundary(frame.selection().selection().start(), selectionExtendedContextLength, SelectionDirection::Backward).get());
    558     String textAfter = plainTextForDisplay(rangeExpandedByCharactersInDirectionAtWordBoundary(frame.selection().selection().end(), selectionExtendedContextLength, SelectionDirection::Forward).get());
     550
     551    auto& selection = frame.selection().selection();
     552    String selectedText = plainTextForContext(selection.firstRange());
     553    String textBefore = plainTextForDisplay(rangeExpandedByCharactersInDirectionAtWordBoundary(selection.start(), selectionExtendedContextLength, SelectionDirection::Backward));
     554    String textAfter = plainTextForDisplay(rangeExpandedByCharactersInDirectionAtWordBoundary(selection.end(), selectionExtendedContextLength, SelectionDirection::Forward));
    559555
    560556    send(Messages::WebPageProxy::SelectionContextCallback(selectedText, textBefore, textAfter, callbackID));
    … …  
    989985    if (auto selectionRange = frame->selection().selection().toNormalizedRange()) {
    990986        m_pendingImageElementsForDropSnapshot = visibleImageElementsInRangeWithNonLoadedImages(*selectionRange);
    991         auto collapsedRange = SimpleRange { selectionRange->end, selectionRange->end };
    992         frame->selection().setSelectedRange(createLiveRange(collapsedRange).ptr(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     987        frame->selection().setSelectedRange(makeSimpleRange(selectionRange->end), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    993988        m_rangeForDropSnapshot = WTFMove(selectionRange);
    994989    }
    … …  
    11141109        return;
    11151110
    1116     VisiblePosition position = renderer->positionForPoint(hitTest.localPoint(), nullptr);
     1111    auto position = renderer->positionForPoint(hitTest.localPoint(), nullptr);
    11171112    if (position.isNull())
    11181113        position = firstPositionInOrBeforeNode(node);
    1119 
    1120     if (position.isNull())
    1121         return;
    1122 
    1123     auto range = Range::create(*frame.document(), position, position);
    1124     frame.selection().setSelectedRange(range.ptr(), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     1114    auto range = makeSimpleRange(position);
     1115    if (!range)
     1116        return;
     1117
     1118    frame.selection().setSelectedRange(*range, position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    11251119    auto image = frame.editor().insertEditableImage();
    11261120    frame.document()->setFocusedElement(image.get());
    … …  
    13721366        return;
    13731367    }
    1374     RefPtr<Range> range;
     1368    Optional<SimpleRange> range;
    13751369    OptionSet<SelectionFlags> flags;
    13761370    GestureRecognizerState wkGestureState = static_cast<GestureRecognizerState>(gestureState);
    … …  
    13861380        else
    13871381            flags = PhraseBoundaryChanged;
    1388         range = Range::create(*frame.document(), position, position);
    1389     }
     1382        range = makeSimpleRange(position);
    13901383        break;
    1391 
    1392     case GestureType::OneFingerTap:
    1393     {
     1384    }
     1385
     1386    case GestureType::OneFingerTap: {
    13941387        auto [adjustedPosition, withinWordBoundary] = wordBoundaryForPositionWithoutCrossingLine(position);
    13951388        if (withinWordBoundary == WithinWordBoundary::Yes)
    13961389            flags = WordIsNearTap;
    1397         if (adjustedPosition.isNotNull())
    1398             range = Range::create(*frame.document(), adjustedPosition, adjustedPosition);
    1399     }
     1390        range = makeSimpleRange(adjustedPosition);
    14001391        break;
     1392    }
    14011393
    14021394    case GestureType::Loupe:
    14031395        if (position.rootEditableElement())
    1404             range = Range::create(*frame.document(), position, position);
    1405         else
     1396            range = makeSimpleRange(position);
     1397        else {
    14061398#if !PLATFORM(MACCATALYST)
    14071399            range = wordRangeFromPosition(position);
    14081400#else
    14091401            switch (wkGestureState) {
    1410             case GestureRecognizerState::Began: {
    1411                 auto boundary = *makeBoundaryPoint(position);
    1412                 m_startingGestureRange = SimpleRange { boundary, boundary };
     1402            case GestureRecognizerState::Began:
     1403                m_startingGestureRange = makeSimpleRange(position);
    14131404                break;
    1414             }
    14151405            case GestureRecognizerState::Changed:
    14161406                if (m_startingGestureRange) {
    1417                     auto start = createLegacyEditingPosition(m_startingGestureRange->start);
    1418                     if (start < position)
    1419                         range = Range::create(*frame.document(), start, position);
     1407                    auto& start = m_startingGestureRange->start;
     1408                    if (createLegacyEditingPosition(start) < position)
     1409                        range = makeSimpleRange(start, position);
    14201410                    else
    1421                         range = Range::create(*frame.document(), position, start);
     1411                        range = makeSimpleRange(position, start);
    14221412                }
    14231413                break;
    … …  
    14321422            }
    14331423#endif
     1424        }
    14341425        break;
    14351426
    … …  
    14461437            if (!m_currentWordRange)
    14471438                break;
    1448             range = createLiveRange(*m_currentWordRange);
    1449             if (position < range->startPosition())
    1450                 range->setStart(position.deepEquivalent());
    1451             if (position > range->endPosition())
    1452                 range->setEnd(position.deepEquivalent());
     1439            range = m_currentWordRange;
     1440            if (position < createLegacyEditingPosition(range->start))
     1441                range->start = *makeBoundaryPoint(position);
     1442            if (position > createLegacyEditingPosition(range->end))
     1443                range->end = *makeBoundaryPoint(position);
    14531444            break;
    14541445        case GestureRecognizerState::Ended:
    … …  
    14671458            // This helps to get the callout for pasting at ends of lines,
    14681459            // paragraphs, and documents.
    1469             range = Range::create(*frame.document(), position, position);
     1460            range = makeSimpleRange(position);
    14701461         } else
    14711462            range = wordRangeFromPosition(position);
    … …  
    14801471        if (atBoundaryOfGranularity(position, TextGranularity::LineGranularity, SelectionDirection::Forward)) {
    14811472            // Triple-tap at end of line only places insertion point there.
    1482             // This helps to get the callout for pasting at ends of lines,
    1483             // paragraphs, and documents.
    1484             range = Range::create(*frame.document(), position, position);
     1473            // This helps to get the callout for pasting at ends of lines, paragraphs, and documents.
     1474            range = makeSimpleRange(position);
    14851475        } else
    14861476            range = enclosingTextUnitOfGranularity(position, TextGranularity::ParagraphGranularity, SelectionDirection::Forward);
    … …  
    14911481    }
    14921482    if (range)
    1493         frame.selection().setSelectedRange(range.get(), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     1483        frame.selection().setSelectedRange(range, position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    14941484
    14951485    send(Messages::WebPageProxy::GestureCallback(point, gestureType, gestureState, flags, callbackID));
    14961486}
    14971487
    1498 static RefPtr<Range> rangeForPointInRootViewCoordinates(Frame& frame, const IntPoint& pointInRootViewCoordinates, bool baseIsStart)
     1488static Optional<SimpleRange> rangeForPointInRootViewCoordinates(Frame& frame, const IntPoint& pointInRootViewCoordinates, bool baseIsStart)
    14991489{
    15001490    VisibleSelection existingSelection = frame.selection().selection();
    … …  
    15151505   
    15161506    VisiblePosition result;
    1517     RefPtr<Range> range;
     1507    Optional<SimpleRange> range;
    15181508
    15191509    constexpr OptionSet<HitTestRequest::RequestType> hitType { HitTestRequest::ReadOnly, HitTestRequest::Active, HitTestRequest::AllowVisibleChildFrameContentOnly };
    … …  
    15291519        else if (&selectionStart.deepEquivalent().anchorNode()->treeScope() != &hitTest.targetNode()->treeScope())
    15301520            result = VisibleSelection::adjustPositionForEnd(result.deepEquivalent(), selectionStart.deepEquivalent().containerNode());
    1531        
    1532         if (result.isNotNull())
    1533             range = Range::create(*frame.document(), selectionStart, result);
     1521
     1522        range = makeSimpleRange(selectionStart, result);
    15341523    } else {
    15351524        if (comparePositions(selectionEnd, result) <= 0)
    … …  
    15371526        else if (&hitTest.targetNode()->treeScope() != &selectionEnd.deepEquivalent().anchorNode()->treeScope())
    15381527            result = VisibleSelection::adjustPositionForStart(result.deepEquivalent(), selectionEnd.deepEquivalent().containerNode());
    1539        
    1540         if (result.isNotNull())
    1541             range = Range::create(*frame.document(), result.deepEquivalent(), selectionEnd);
     1528
     1529        range = makeSimpleRange(result, selectionEnd);
    15421530    }
    15431531   
    … …  
    15451533}
    15461534
    1547 static RefPtr<Range> rangeAtWordBoundaryForPosition(Frame* frame, const VisiblePosition& position, bool baseIsStart, SelectionDirection direction)
     1535static Optional<SimpleRange> rangeAtWordBoundaryForPosition(Frame* frame, const VisiblePosition& position, bool baseIsStart, SelectionDirection direction)
    15481536{
    15491537    SelectionDirection sameDirection = baseIsStart ? SelectionDirection::Forward : SelectionDirection::Backward;
    … …  
    15551543    if (atBoundaryOfGranularity(extent, TextGranularity::WordGranularity, sameDirection)) {
    15561544        // This is a word boundary. Leave selection where it is.
    1557         return nullptr;
     1545        return WTF::nullopt;
    15581546    }
    15591547
    … …  
    15701558        && initialExtent != wordBoundary) {
    15711559        extent = wordBoundary;
    1572         return (base < extent) ? Range::create(*frame->document(), base, extent) : Range::create(*frame->document(), extent, base);
     1560        if (!(base < extent))
     1561            std::swap(base, extent);
     1562        return makeSimpleRange(base, extent);
    15731563    }
    15741564    // Conversely, if the initial extent equals the current word boundary, then
    … …  
    15901580        extent = wordBoundary;
    15911581    if (extent.isNull())
    1592         return nullptr;
    1593 
    1594     return (base < extent) ? Range::create(*frame->document(), base, extent) : Range::create(*frame->document(), extent, base);
     1582        return WTF::nullopt;
     1583
     1584    if (!(base < extent))
     1585        std::swap(base, extent);
     1586    return makeSimpleRange(base, extent);
    15951587}
    15961588
    … …  
    17071699    }
    17081700
    1709     RefPtr<Range> range;
    1710     VisiblePosition result;
    1711     OptionSet<SelectionFlags> flags;
    1712 
    17131701    if (shouldDispatchSyntheticMouseEventsWhenModifyingSelection())
    17141702        dispatchSyntheticMouseEventsForSelectionGesture(selectionTouch, point);
     1703
     1704    Optional<SimpleRange> range;
     1705    OptionSet<SelectionFlags> flags;
    17151706
    17161707    switch (selectionTouch) {
    … …  
    17181709    case SelectionTouch::EndedNotMoving:
    17191710        break;
    1720    
     1711
    17211712    case SelectionTouch::Ended:
    1722         if (frame.selection().selection().isContentEditable()) {
    1723             result = closestWordBoundaryForPosition(position);
    1724             if (result.isNotNull())
    1725                 range = Range::create(*frame.document(), result, result);
    1726         } else
     1713        if (frame.selection().selection().isContentEditable())
     1714            range = makeSimpleRange(closestWordBoundaryForPosition(position));
     1715        else
    17271716            range = rangeForPointInRootViewCoordinates(frame, point, baseIsStart);
    17281717        break;
    … …  
    17311720        range = rangeAtWordBoundaryForPosition(&frame, position, baseIsStart, SelectionDirection::Forward);
    17321721        break;
    1733        
     1722
    17341723    case SelectionTouch::EndedMovingBackward:
    17351724        range = rangeAtWordBoundaryForPosition(&frame, position, baseIsStart, SelectionDirection::Backward);
    … …  
    17401729        break;
    17411730    }
     1731
    17421732    if (range)
    1743         frame.selection().setSelectedRange(range.get(), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     1733        frame.selection().setSelectedRange(range, position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    17441734
    17451735    send(Messages::WebPageProxy::TouchesCallback(point, selectionTouch, flags, callbackID));
    … …  
    17491739{
    17501740    Frame& frame = m_page->focusController().focusedOrMainFrame();
    1751     VisiblePosition fromPosition = frame.visiblePositionForPoint(frame.view()->rootViewToContents(from));
    1752     VisiblePosition toPosition = frame.visiblePositionForPoint(frame.view()->rootViewToContents(to));
    1753     RefPtr<Range> range;
    1754     if (fromPosition.isNotNull() && toPosition.isNotNull()) {
    1755         if (fromPosition < toPosition)
    1756             range = Range::create(*frame.document(), fromPosition, toPosition);
    1757         else
    1758             range = Range::create(*frame.document(), toPosition, fromPosition);
    1759         frame.selection().setSelectedRange(range.get(), fromPosition.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     1741    auto fromPosition = frame.visiblePositionForPoint(frame.view()->rootViewToContents(from));
     1742    auto toPosition = frame.visiblePositionForPoint(frame.view()->rootViewToContents(to));
     1743    if (auto range = makeSimpleRange(fromPosition, toPosition)) {
     1744        if (!(fromPosition < toPosition))
     1745            std::swap(range->start, range->end);
     1746        frame.selection().setSelectedRange(range, fromPosition.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    17601747    }
    17611748
    … …  
    17811768    bool shouldDispatchMouseEvents = shouldDispatchSyntheticMouseEventsWhenModifyingSelection();
    17821769    if (shouldDispatchMouseEvents) {
    1783         auto startLocationForSyntheticMouseEvents = frame.view()->contentsToRootView(VisiblePosition(wordRange->startPosition()).absoluteCaretBounds()).center();
    1784         endLocationForSyntheticMouseEvents = frame.view()->contentsToRootView(VisiblePosition(wordRange->endPosition()).absoluteCaretBounds()).center();
     1770        auto startLocationForSyntheticMouseEvents = frame.view()->contentsToRootView(VisiblePosition(createLegacyEditingPosition(wordRange->start)).absoluteCaretBounds()).center();
     1771        endLocationForSyntheticMouseEvents = frame.view()->contentsToRootView(VisiblePosition(createLegacyEditingPosition(wordRange->end)).absoluteCaretBounds()).center();
    17851772        dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch::Started, startLocationForSyntheticMouseEvents);
    17861773        dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch::Moved, endLocationForSyntheticMouseEvents);
    17871774    }
    17881775
    1789     frame.selection().setSelectedRange(wordRange.get(), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     1776    frame.selection().setSelectedRange(wordRange, position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    17901777
    17911778    if (shouldDispatchMouseEvents)
    … …  
    18121799        return;
    18131800
    1814     VisiblePosition position = frame.selection().selection().start();
    1815     VisiblePosition startPosition = positionOfNextBoundaryOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Backward);
    1816     if (startPosition.isNotNull() && startPosition != position)
    1817         frame.selection().setSelectedRange(Range::create(*frame.document(), startPosition, position).ptr(), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     1801    auto position = frame.selection().selection().visibleStart();
     1802    auto startPosition = positionOfNextBoundaryOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Backward);
     1803    if (startPosition.isNull() || startPosition == position)
     1804        return;
     1805
     1806    frame.selection().setSelectedRange(makeSimpleRange(startPosition, position), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    18181807}
    18191808
    … …  
    18331822    }
    18341823    if (position.isNotNull() && startPosition != position)
    1835         frame.selection().setSelectedRange(Range::create(*frame.document(), position, position).ptr(), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     1824        frame.selection().setSelectedRange(makeSimpleRange(position), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    18361825    completionHandler();
    18371826}
    … …  
    19851974
    19861975    Vector<WebCore::SelectionRect> selectionRects;
    1987     range->collectSelectionRectsWithoutUnionInteriorLines(selectionRects);
     1976    createLiveRange(*range)->collectSelectionRectsWithoutUnionInteriorLines(selectionRects);
    19881977    convertContentToRootViewSelectionRects(*frame.view(), selectionRects);
    19891978    send(Messages::WebPageProxy::SelectionRectsCallback(selectionRects, callbackID));
    … …  
    20342023    }
    20352024
    2036     if (plainTextForDisplay(range.ptr()) != text) {
     2025    if (plainTextForDisplay(range) != text) {
    20372026        // Try to search for a range which is the closest to the position within the selection range that matches the passed in text.
    20382027        if (auto wordRange = rangeNearPositionMatchesText(startPosition, text, selection)) {
    … …  
    20652054   
    20662055    if (position.isNotNull())
    2067         frame.selection().setSelectedRange(Range::create(*frame.document(), position, position).ptr(), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     2056        frame.selection().setSelectedRange(makeSimpleRange(position), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    20682057    completionHandler();
    20692058}
    … …  
    20772066        position = positionOfNextBoundaryOfGranularity(position, granularity, direction);
    20782067        if (position.isNotNull())
    2079             frame.selection().setSelectedRange(Range::create(*frame.document(), position, position).ptr(), UPSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     2068            frame.selection().setSelectedRange(makeSimpleRange(position), UPSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    20802069    }
    20812070    completionHandler();
    … …  
    20912080        position = positionOfNextBoundaryOfGranularity(position, granularity, direction);
    20922081        if (position.isNotNull())
    2093             frame.selection().setSelectedRange(Range::create(*frame.document(), position, position).ptr(), isForward? UPSTREAM : DOWNSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     2082            frame.selection().setSelectedRange(makeSimpleRange(position), isForward? UPSTREAM : DOWNSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    20942083    }
    20952084    completionHandler();
    … …  
    21002089    auto position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement);
    21012090    switch (granularity) {
    2102     case TextGranularity::CharacterGranularity: {
    2103         auto boundary = makeBoundaryPoint(position);
    2104         if (!boundary)
    2105             return WTF::nullopt;
    2106         return { { *boundary, *boundary } };
    2107     }
    2108     case TextGranularity::WordGranularity: {
    2109         auto range = wordRangeFromPosition(position);
    2110         if (!range)
    2111             return WTF::nullopt;
    2112         return { *range };
    2113     }
     2091    case TextGranularity::CharacterGranularity:
     2092        return makeSimpleRange(position);
     2093    case TextGranularity::WordGranularity:
     2094        return wordRangeFromPosition(position);
    21142095    case TextGranularity::SentenceGranularity:
    2115     case TextGranularity::ParagraphGranularity: {
    2116         auto range = enclosingTextUnitOfGranularity(position, granularity, SelectionDirection::Forward);
    2117         if (!range)
    2118             return WTF::nullopt;
    2119         return { *range };
    2120     }
     2096    case TextGranularity::ParagraphGranularity:
     2097        return enclosingTextUnitOfGranularity(position, granularity, SelectionDirection::Forward);
    21212098    case TextGranularity::DocumentGranularity:
    21222099        // FIXME: Makes no sense that this mutates the current selection and returns null.
    … …  
    21652142    auto range = rangeForGranularityAtPoint(frame, point, granularity, isInteractingWithFocusedElement);
    21662143    if (range)
    2167         frame.selection().setSelectedRange(createLiveRange(*range).ptr(), UPSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     2144        frame.selection().setSelectedRange(*range, UPSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    21682145    m_initialSelection = range;
    21692146    completionHandler();
    … …  
    21972174        selectionStart = createLegacyEditingPosition(newRange->start);
    21982175
    2199     if (selectionStart.isNotNull() && selectionEnd.isNotNull()) {
    2200         auto range = SimpleRange { *makeBoundaryPoint(selectionStart), *makeBoundaryPoint(selectionEnd) };
    2201         frame.selection().setSelectedRange(createLiveRange(range).ptr(), UPSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    2202     }
     2176    if (auto range = makeSimpleRange(selectionStart, selectionEnd))
     2177        frame.selection().setSelectedRange(range, UPSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    22032178
    22042179    send(Messages::WebPageProxy::UnsignedCallback(selectionStart == initialSelectionStartPosition, callbackID));
    … …  
    22152190    }
    22162191
    2217     RefPtr<Range> range;
    22182192    VisiblePosition selectionStart;
    22192193    VisiblePosition selectionEnd;
    … …  
    22492223    }
    22502224   
    2251     if (selectionStart.isNotNull() && selectionEnd.isNotNull())
    2252         range = Range::create(*frame.document(), selectionStart, selectionEnd);
    2253 
    2254     if (range)
    2255         frame.selection().setSelectedRange(range.get(), UPSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     2225    if (auto range = makeSimpleRange(selectionStart, selectionEnd))
     2226        frame.selection().setSelectedRange(range, UPSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    22562227
    22572228    send(Messages::WebPageProxy::UnsignedCallback(m_selectionAnchor == Start, callbackID));
    … …  
    22782249        }
    22792250        if (lastPosition.isNotNull() && lastPosition != startPosition)
    2280             contextBefore = plainTextForContext(Range::create(*frame.document(), lastPosition, startPosition).ptr());
     2251            contextBefore = plainTextForContext(Range::create(*frame.document(), lastPosition, startPosition));
    22812252    }
    22822253
    … …  
    22922263        }
    22932264        if (lastPosition.isNotNull() && lastPosition != endPosition)
    2294             contextAfter = plainTextForContext(Range::create(*frame.document(), endPosition, lastPosition).ptr());
     2265            contextAfter = plainTextForContext(Range::create(*frame.document(), endPosition, lastPosition));
    22952266    }
    22962267
    … …  
    23032274    auto wordRange = frame.selection().isCaret()
    23042275        ? wordRangeFromPosition(frame.selection().selection().start())
    2305         : createLiveRange(frame.selection().selection().toNormalizedRange());
    2306     if (plainTextForContext(wordRange.get()) != oldText)
    2307         return;
    2308    
     2276        : frame.selection().selection().toNormalizedRange();
     2277    if (plainTextForContext(wordRange) != oldText)
     2278        return;
    23092279    frame.editor().setIgnoreSelectionChanges(true);
    2310     frame.selection().setSelectedRange(wordRange.get(), UPSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes);
     2280    frame.selection().setSelectedRange(wordRange, UPSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes);
    23112281    frame.editor().insertText(newText, 0);
    23122282    frame.editor().setIgnoreSelectionChanges(false);
    … …  
    23282298    if (position.isNull())
    23292299        position = startOfDocument(frame.document());
    2330     auto range = Range::create(*frame.document(), position, frame.selection().selection().start());
    2331 
    2332     if (plainTextForContext(range.ptr()) != oldText)
     2300    auto range = makeSimpleRange(position, frame.selection().selection().start());
     2301
     2302    if (plainTextForContext(range) != oldText)
    23332303        return;
    23342304
    23352305    // We don't want to notify the client that the selection has changed until we are done inserting the new text.
    23362306    frame.editor().setIgnoreSelectionChanges(true);
    2337     frame.selection().setSelectedRange(range.ptr(), UPSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes);
     2307    frame.selection().setSelectedRange(range, UPSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes);
    23382308    frame.editor().insertText(newText, 0);
    23392309    frame.editor().setIgnoreSelectionChanges(false);
    … …  
    23482318    }
    23492319
    2350     VisiblePosition position = frame.selection().selection().start();
    2351     auto range = wordRangeFromPosition(position);
     2320    auto range = wordRangeFromPosition(frame.selection().selection().visibleStart());
    23522321    if (!range) {
    23532322        reply({ });
    … …  
    23552324    }
    23562325
    2357     auto textForRange = plainTextForContext(range.get());
     2326    auto textForRange = plainTextForContext(range);
    23582327    const unsigned maxSearchAttempts = 5;
    2359     for (size_t i = 0;  i < maxSearchAttempts && textForRange != textForAutocorrection; ++i)
    2360     {
    2361         position = range->startPosition().previous();
    2362         if (position.isNull() || position == range->startPosition())
     2328    for (size_t i = 0;  i < maxSearchAttempts && textForRange != textForAutocorrection; ++i) {
     2329        auto position = createLegacyEditingPosition(range->start).previous();
     2330        if (position.isNull() || position == createLegacyEditingPosition(range->start))
    23632331            break;
    2364         range = Range::create(*frame.document(), wordRangeFromPosition(position)->startPosition(), range->endPosition());
    2365         textForRange = plainTextForContext(range.get());
     2332        range = { { wordRangeFromPosition(position)->start, range->end } };
     2333        textForRange = plainTextForContext(range);
    23662334    }
    23672335
    23682336    Vector<SelectionRect> selectionRects;
    23692337    if (textForRange == textForAutocorrection)
    2370         range->collectSelectionRects(selectionRects);
     2338        createLiveRange(range)->collectSelectionRects(selectionRects);
    23712339
    23722340    auto rootViewSelectionRects = selectionRects.map([&](const auto& selectionRect) -> FloatRect { return frame.view()->contentsToRootView(selectionRect.rect()); });
    … …  
    24142382        return false;
    24152383
    2416     RefPtr<Range> range;
     2384    Optional<SimpleRange> range;
    24172385    String textForRange;
    24182386    auto originalTextWithFoldedQuoteMarks = foldQuoteMarks(originalText);
    24192387
    24202388    if (frame.selection().isCaret()) {
    2421         VisiblePosition position = frame.selection().selection().start();
     2389        auto position = frame.selection().selection().visibleStart();
    24222390        range = wordRangeFromPosition(position);
    2423         textForRange = plainTextForContext(range.get());
     2391        textForRange = plainTextForContext(range);
    24242392       
    24252393        // If 'originalText' is not the same as 'textForRange' we need to move 'range'
    … …  
    24312399            if (position.isNull())
    24322400                position = startOfDocument(frame.document());
    2433             range = Range::create(*frame.document(), position, frame.selection().selection().start());
    2434             textForRange = plainTextForContext(range.get());
     2401            range = makeSimpleRange(position, frame.selection().selection().start());
     2402            textForRange = plainTextForContext(range);
    24352403            unsigned loopCount = 0;
    24362404            const unsigned maxPositionsAttempts = 10;
    … …  
    24382406                position = position.next();
    24392407                if (position.isNotNull() && position >= frame.selection().selection().start())
    2440                     range = nullptr;
     2408                    range = WTF::nullopt;
    24412409                else
    2442                     range = Range::create(*frame.document(), position, frame.selection().selection().start());
    2443                 textForRange = plainTextForContext(range.get());
     2410                    range = makeSimpleRange(position, frame.selection().selection().start());
     2411                textForRange = plainTextForContext(range);
    24442412                loopCount++;
    24452413            }
    … …  
    24472415            // If 'range' does not include any text but it is not collapsed, we need to set
    24482416            // 'range' to match the selection. Otherwise non-text nodes will be removed.
    2449             range = Range::create(*frame.document(), position, position);
     2417            range = makeSimpleRange(position);
    24502418            if (!range)
    24512419                return false;
    … …  
    24532421    } else {
    24542422        // Range selection.
    2455         range = createLiveRange(frame.selection().selection().toNormalizedRange());
     2423        range = frame.selection().selection().toNormalizedRange();
    24562424        if (!range)
    24572425            return false;
    24582426
    2459         textForRange = plainTextForContext(range.get());
     2427        textForRange = plainTextForContext(range);
    24602428    }
    24612429
    … …  
    24662434    EAffinity affinity = DOWNSTREAM;
    24672435    if (range && range->collapsed())
    2468         affinity = VisiblePosition(range->startPosition(), UPSTREAM).affinity();
     2436        affinity = VisiblePosition(createLegacyEditingPosition(range->start), UPSTREAM).affinity();
    24692437   
    2470     frame.selection().setSelectedRange(range.get(), affinity, WebCore::FrameSelection::ShouldCloseTyping::Yes);
     2438    frame.selection().setSelectedRange(range, affinity, WebCore::FrameSelection::ShouldCloseTyping::Yes);
    24712439    if (correction.length())
    24722440        frame.editor().insertText(correction, 0, originalText.isEmpty() ? TextEventInputKeyboard : TextEventInputAutocompletion);
    … …  
    24952463
    24962464    if (auto compositionRange = frame.editor().compositionRange()) {
    2497         String markedTextBefore;
    2498         if (auto start = makeBoundaryPoint(startPosition))
    2499             markedTextBefore = plainTextForContext({ compositionRange->start, *start });
    2500         String markedTextAfter;
    2501         if (auto end = makeBoundaryPoint(endPosition))
    2502             markedTextAfter = plainTextForContext({ *end, compositionRange->end });
     2465        auto markedTextBefore = plainTextForContext(makeSimpleRange(compositionRange->start, startPosition));
     2466        auto markedTextAfter = plainTextForContext(makeSimpleRange(endPosition, compositionRange->end));
    25032467        markedText = markedTextBefore + selectedText + markedTextAfter;
    25042468        if (!markedText.isEmpty()) {
    … …  
    25172481                if (previousPosition.isNull())
    25182482                    break;
    2519                 String currentWord = plainTextForContext(Range::create(*frame.document(), previousPosition, currentPosition).ptr());
     2483                String currentWord = plainTextForContext(Range::create(*frame.document(), previousPosition, currentPosition));
    25202484                totalContextLength += currentWord.length();
    25212485                if (totalContextLength >= maxContextLength)
    … …  
    25242488            }
    25252489            if (currentPosition.isNotNull() && currentPosition != startPosition) {
    2526                 contextBefore = plainTextForContext(Range::create(*frame.document(), currentPosition, startPosition).ptr());
     2490                contextBefore = plainTextForContext(Range::create(*frame.document(), currentPosition, startPosition));
    25272491                if (atBoundaryOfGranularity(currentPosition, TextGranularity::ParagraphGranularity, SelectionDirection::Backward))
    25282492                    contextBefore = makeString("\n "_s, contextBefore);
    … …  
    25352499                nextPosition = positionOfNextBoundaryOfGranularity(endPosition, TextGranularity::WordGranularity, SelectionDirection::Forward);
    25362500            if (nextPosition.isNotNull())
    2537                 contextAfter = plainTextForContext(Range::create(*frame.document(), endPosition, nextPosition).ptr());
     2501                contextAfter = plainTextForContext(Range::create(*frame.document(), endPosition, nextPosition));
    25382502        }
    25392503    }
    … …  
    26742638    linkRange->selectNodeContents(element);
    26752639    info.textBefore = plainTextForDisplay(rangeExpandedByCharactersInDirectionAtWordBoundary(linkRange->startPosition(),
    2676         dataDetectionExtendedContextLength, SelectionDirection::Backward).get());
     2640        dataDetectionExtendedContextLength, SelectionDirection::Backward));
    26772641    info.textAfter = plainTextForDisplay(rangeExpandedByCharactersInDirectionAtWordBoundary(linkRange->endPosition(),
    2678         dataDetectionExtendedContextLength, SelectionDirection::Forward).get());
     2642        dataDetectionExtendedContextLength, SelectionDirection::Forward));
    26792643}
    26802644#endif
    … …  
    41064070    auto newSelectionRange = CharacterRange(newSelectionLocation.unsafeGet(), newSelectionLength.unsafeGet());
    41074071    auto updatedSelectionRange = resolveCharacterRange(makeRangeSelectingNodeContents(*root), newSelectionRange);
    4108     frame->selection().setSelectedRange(createLiveRange(updatedSelectionRange).ptr(), DOWNSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     4072    frame->selection().setSelectedRange(updatedSelectionRange, DOWNSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    41094073    completionHandler();
    41104074}
    … …  
    43914355        return;
    43924356    }
    4393     targetFrame->selection().setSelectedRange(Range::create(*targetFrame->document(), position, position).ptr(), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     4357    targetFrame->selection().setSelectedRange(makeSimpleRange(position), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    43944358    completionHandler(true);
    43954359}
  • trunk/Source/WebKitLegacy/ios/ChangeLog

    r264692 r265084  
     12020-07-30  Darin Adler  <darin@apple.com>
     2
     3        Further reduction in the use of live ranges, particularly in headers
     4        https://bugs.webkit.org/show_bug.cgi?id=214793
     5
     6        Reviewed by Sam Weinig.
     7
     8        * WebCoreSupport/WebVisiblePosition.mm:
     9        (-[WebVisiblePosition enclosingTextUnitOfGranularity:inDirectionIfAtBoundary:]):
     10        Use SimpleRange.
     11
    1122020-07-19  Darin Adler  <darin@apple.com>
    213
  • trunk/Source/WebKitLegacy/ios/WebCoreSupport/WebVisiblePosition.mm

    r261776 r265084  
    293293- (DOMRange *)enclosingTextUnitOfGranularity:(WebTextGranularity)granularity inDirectionIfAtBoundary:(WebTextAdjustmentDirection)direction
    294294{
    295     return kit(enclosingTextUnitOfGranularity([self _visiblePosition], toTextGranularity(granularity), toSelectionDirection(direction)).get());
     295    return kit(enclosingTextUnitOfGranularity([self _visiblePosition], toTextGranularity(granularity), toSelectionDirection(direction)));
    296296}
    297297
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r265044 r265084  
     12020-07-30  Darin Adler  <darin@apple.com>
     2
     3        Further reduction in the use of live ranges, particularly in headers
     4        https://bugs.webkit.org/show_bug.cgi?id=214793
     5
     6        Reviewed by Sam Weinig.
     7
     8        * DOM/DOMHTML.mm:
     9        (-[DOMHTMLDocument createDocumentFragmentWithText:]): Use SimpleRange.
     10        * DOM/DOMUIKitExtensions.mm:
     11        (-[DOMRange move:inDirection:]): Ditto.
     12        (-[DOMRange extend:inDirection:]): Ditto.
     13        * DOM/WebDOMOperations.mm:
     14        (-[DOMRange webArchive]): Ditto.
     15        * WebView/WebFrame.mm:
     16        (-[WebFrame _firstRectForDOMRange:]): Moved a "*" to save a little work.
     17        (-[WebFrame setSelectedDOMRange:affinity:closeTyping:userTriggered:]):
     18        Use SimpleRange.
     19        (-[WebFrame _replaceSelectionWithText:selectReplacement:smartReplace:matchStyle:]):
     20        Ditto.
     21        (-[WebFrame _replaceSelectionWithText:selectReplacement:smartReplace:]):
     22        Ditto.
     23        (-[WebFrame _documentFragmentForText:]): Ditto.
     24        * WebView/WebView.mm:
     25        (-[WebView DOMRangeOfString:relativeTo:options:]): Ditto.
     26        (-[WebView setSelectedDOMRange:affinity:]): Ditto.
     27
    1282020-07-29  Darin Adler  <darin@apple.com>
    229
  • trunk/Source/WebKitLegacy/mac/DOM/DOMHTML.mm

    r262665 r265084  
    4545#import <WebCore/RenderTextControl.h>
    4646#import <WebCore/Settings.h>
     47#import <WebCore/SimpleRange.h>
    4748#import <WebCore/markup.h>
    4849
    … …  
    153154{
    154155    // FIXME: Since this is not a contextual fragment, it won't handle whitespace properly.
    155     return kit(createFragmentFromText(core(self)->createRange(), text).ptr());
     156    return kit(createFragmentFromText(makeRangeSelectingNodeContents(*core(self)), text).ptr());
    156157}
    157158
  • trunk/Source/WebKitLegacy/mac/DOM/DOMUIKitExtensions.mm

    r261776 r265084  
    7979- (void)move:(UInt32)amount inDirection:(WebTextAdjustmentDirection)direction
    8080{
    81     Range *range = core(self);
     81    auto& range = *core(self);
     82
    8283    WebCore::FrameSelection frameSelection;
    83     frameSelection.moveTo(range);
     84    frameSelection.setSelection(makeSimpleRange(range));
    8485   
    8586    WebCore::TextGranularity granularity = WebCore::TextGranularity::CharacterGranularity;
    … …  
    9394        granularity = WebCore::TextGranularity::LineGranularity;
    9495    }
    95    
     96
    9697    for (UInt32 i = 0; i < amount; i++)
    9798        frameSelection.modify(WebCore::FrameSelection::AlterationMove, (WebCore::SelectionDirection)direction, granularity);
    98    
     99
    99100    Position start = frameSelection.selection().start().parentAnchoredEquivalent();
    100101    Position end = frameSelection.selection().end().parentAnchoredEquivalent();
    101102    if (start.containerNode())
    102         range->setStart(*start.containerNode(), start.offsetInContainerNode());
     103        range.setStart(*start.containerNode(), start.offsetInContainerNode());
    103104    if (end.containerNode())
    104         range->setEnd(*end.containerNode(), end.offsetInContainerNode());
     105        range.setEnd(*end.containerNode(), end.offsetInContainerNode());
    105106}
    106107
    107108- (void)extend:(UInt32)amount inDirection:(WebTextAdjustmentDirection)direction
    108109{
    109     Range *range = core(self);
     110    auto& range = *core(self);
     111
    110112    WebCore::FrameSelection frameSelection;
    111     frameSelection.moveTo(range);
    112    
     113    frameSelection.setSelection(makeSimpleRange(range));
     114
    113115    for (UInt32 i = 0; i < amount; i++)
    114116        frameSelection.modify(WebCore::FrameSelection::AlterationExtend, (WebCore::SelectionDirection)direction, WebCore::TextGranularity::CharacterGranularity);
    115    
     117
    116118    Position start = frameSelection.selection().start().parentAnchoredEquivalent();
    117119    Position end = frameSelection.selection().end().parentAnchoredEquivalent();
    118120    if (start.containerNode())
    119         range->setStart(*start.containerNode(), start.offsetInContainerNode());
     121        range.setStart(*start.containerNode(), start.offsetInContainerNode());
    120122    if (end.containerNode())
    121         range->setEnd(*end.containerNode(), end.offsetInContainerNode());
     123        range.setEnd(*end.containerNode(), end.offsetInContainerNode());
    122124}
    123125
  • trunk/Source/WebKitLegacy/mac/DOM/WebDOMOperations.mm

    r260854 r265084  
    5353#import <WebCore/LegacyWebArchive.h>
    5454#import <WebCore/PlatformWheelEvent.h>
     55#import <WebCore/Range.h>
    5556#import <WebCore/RenderElement.h>
    5657#import <WebCore/RenderTreeAsText.h>
    … …  
    185186- (WebArchive *)webArchive
    186187{
    187     return [[[WebArchive alloc] _initWithCoreLegacyWebArchive:LegacyWebArchive::create(core(self))] autorelease];
     188    return [[[WebArchive alloc] _initWithCoreLegacyWebArchive:LegacyWebArchive::create(*core(self))] autorelease];
    188189}
    189190
  • trunk/Source/WebKitLegacy/mac/WebView/WebFrame.mm

    r265044 r265084  
    9494#import <WebCore/PluginData.h>
    9595#import <WebCore/PrintContext.h>
     96#import <WebCore/Range.h>
    9697#import <WebCore/RenderLayer.h>
    9798#import <WebCore/RenderView.h>
    … …  
    723724    if (!range)
    724725        return NSZeroRect;
    725     return _private->coreFrame->editor().firstRectForRange(*makeSimpleRange(core(range)));
     726    return _private->coreFrame->editor().firstRectForRange(makeSimpleRange(*core(range)));
    726727}
    727728
    … …  
    14801481    auto coreCloseTyping = closeTyping ? FrameSelection::ShouldCloseTyping::Yes : FrameSelection::ShouldCloseTyping::No;
    14811482    auto coreUserTriggered = userTriggered ? UserTriggered : NotUserTriggered;
    1482     frame.selection().setSelectedRange(core(range), core(affinity), coreCloseTyping, coreUserTriggered);
     1483    frame.selection().setSelectedRange(makeSimpleRange(core(range)), core(affinity), coreCloseTyping, coreUserTriggered);
    14831484    if (!closeTyping)
    14841485        frame.editor().ensureLastEditCommandHasCurrentSelectionIfOpenForMoreTyping();
    … …  
    18801881{
    18811882    auto range = _private->coreFrame->selection().selection().toNormalizedRange();
    1882     DOMDocumentFragment* fragment = range ? kit(createFragmentFromText(createLiveRange(*range), text).ptr()) : nil;
     1883    DOMDocumentFragment* fragment = range ? kit(createFragmentFromText(*range, text).ptr()) : nil;
    18831884    [self _replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace matchStyle:matchStyle];
    18841885}
    … …  
    19631964{
    19641965    auto range = _private->coreFrame->selection().selection().toNormalizedRange();
    1965     DOMDocumentFragment* fragment = range ? kit(createFragmentFromText(createLiveRange(*range), text).ptr()) : nil;
     1966    DOMDocumentFragment* fragment = range ? kit(createFragmentFromText(*range, text).ptr()) : nil;
    19661967    [self _replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace matchStyle:YES];
    19671968}
    … …  
    22722273- (DOMDocumentFragment *)_documentFragmentForText:(NSString *)text
    22732274{
    2274     return kit(createFragmentFromText(*createLiveRange(_private->coreFrame->selection().selection().toNormalizedRange()), text).ptr());
     2275    auto range = _private->coreFrame->selection().selection().toNormalizedRange();
     2276    return range ? kit(createFragmentFromText(*range, text).ptr()) : nil;
    22752277}
    22762278
  • trunk/Source/WebKitLegacy/mac/WebView/WebView.mm

    r264692 r265084  
    196196#import <WebCore/PlatformScreen.h>
    197197#import <WebCore/ProgressTracker.h>
     198#import <WebCore/Range.h>
    198199#import <WebCore/RenderTheme.h>
    199200#import <WebCore/RenderView.h>
    … …  
    79307931    if (!_private->page)
    79317932        return nil;
    7932 
    7933     return kit(_private->page->rangeOfString(string, core(previousRange), coreOptions(options)).get());
     7933    return kit(_private->page->rangeOfString(string, makeSimpleRange(core(previousRange)), coreOptions(options)));
    79347934}
    79357935
    … …  
    84578457            return;
    84588458
    8459         coreFrame->selection().setSelectedRange(core(range), core(selectionAffinity), WebCore::FrameSelection::ShouldCloseTyping::Yes);
     8459        coreFrame->selection().setSelectedRange(makeSimpleRange(*core(range)), core(selectionAffinity), WebCore::FrameSelection::ShouldCloseTyping::Yes);
    84608460    }
    84618461}
  • trunk/Source/WebKitLegacy/win/AccessibleTextImpl.cpp

    r265044 r265084  
    3737#include <WebCore/Node.h>
    3838#include <WebCore/Position.h>
     39#include <WebCore/Range.h>
    3940#include <WebCore/RenderTextControl.h>
    4041#include <WebCore/VisibleSelection.h>
  • trunk/Source/WebKitLegacy/win/ChangeLog

    r264811 r265084  
     12020-07-30  Darin Adler  <darin@apple.com>
     2
     3        Further reduction in the use of live ranges, particularly in headers
     4        https://bugs.webkit.org/show_bug.cgi?id=214793
     5
     6        Reviewed by Sam Weinig.
     7
     8        * AccessibleTextImpl.cpp: Added an include of Range.h.
     9
    1102020-07-23  Alex Christensen  <achristensen@webkit.org>
    211
Note: See TracChangeset for help on using the changeset viewer.