Changeset 265084 in webkit
- Timestamp:
- Jul 30, 2020, 9:17:17 AM (6 years ago)
- Location:
- trunk/Source
- Files:
-
- 61 edited
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/accessibility/AccessibilityObject.cpp (modified) (2 diffs)
-
WebCore/dom/SimpleRange.cpp (modified) (1 diff)
-
WebCore/dom/SimpleRange.h (modified) (2 diffs)
-
WebCore/editing/CompositeEditCommand.cpp (modified) (2 diffs)
-
WebCore/editing/Editor.cpp (modified) (4 diffs)
-
WebCore/editing/EditorCommand.cpp (modified) (4 diffs)
-
WebCore/editing/FormatBlockCommand.cpp (modified) (4 diffs)
-
WebCore/editing/FormatBlockCommand.h (modified) (1 diff)
-
WebCore/editing/FrameSelection.cpp (modified) (2 diffs)
-
WebCore/editing/FrameSelection.h (modified) (3 diffs)
-
WebCore/editing/ReplaceSelectionCommand.cpp (modified) (1 diff)
-
WebCore/editing/VisibleUnits.cpp (modified) (9 diffs)
-
WebCore/editing/VisibleUnits.h (modified) (1 diff)
-
WebCore/editing/cocoa/DataDetection.mm (modified) (1 diff)
-
WebCore/editing/cocoa/DictionaryLookup.mm (modified) (3 diffs)
-
WebCore/editing/cocoa/EditorCocoa.mm (modified) (1 diff)
-
WebCore/editing/cocoa/WebContentReaderCocoa.mm (modified) (1 diff)
-
WebCore/editing/gtk/WebContentReaderGtk.cpp (modified) (1 diff)
-
WebCore/editing/libwpe/EditorLibWPE.cpp (modified) (1 diff)
-
WebCore/editing/mac/DictionaryLookupLegacy.mm (modified) (1 diff)
-
WebCore/editing/markup.cpp (modified) (8 diffs)
-
WebCore/editing/markup.h (modified) (3 diffs)
-
WebCore/loader/archive/cf/LegacyWebArchive.cpp (modified) (4 diffs)
-
WebCore/loader/archive/cf/LegacyWebArchive.h (modified) (2 diffs)
-
WebCore/page/DragController.cpp (modified) (9 diffs)
-
WebCore/page/DragController.h (modified) (3 diffs)
-
WebCore/page/Page.cpp (modified) (8 diffs)
-
WebCore/page/Page.h (modified) (4 diffs)
-
WebCore/page/ios/FrameIOS.mm (modified) (3 diffs)
-
WebCore/rendering/HitTestResult.cpp (modified) (1 diff)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/Shared/API/c/mac/WKWebArchiveRef.cpp (modified) (2 diffs)
-
WebKit/Shared/APIWebArchive.h (modified) (4 diffs)
-
WebKit/Shared/APIWebArchive.mm (modified) (1 diff)
-
WebKit/Shared/EditingRange.cpp (modified) (3 diffs)
-
WebKit/Shared/EditingRange.h (modified) (2 diffs)
-
WebKit/WebProcess/InjectedBundle/API/APIInjectedBundleEditorClient.h (modified) (2 diffs)
-
WebKit/WebProcess/InjectedBundle/API/glib/WebKitWebEditor.cpp (modified) (1 diff)
-
WebKit/WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm (modified) (2 diffs)
-
WebKit/WebProcess/InjectedBundle/API/mac/WKDOMRange.mm (modified) (1 diff)
-
WebKit/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm (modified) (4 diffs)
-
WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp (modified) (4 diffs)
-
WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h (modified) (4 diffs)
-
WebKit/WebProcess/InjectedBundle/InjectedBundlePageEditorClient.cpp (modified) (3 diffs)
-
WebKit/WebProcess/InjectedBundle/InjectedBundlePageEditorClient.h (modified) (2 diffs)
-
WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp (modified) (4 diffs)
-
WebKit/WebProcess/WebPage/FindController.cpp (modified) (6 diffs)
-
WebKit/WebProcess/WebPage/FindController.h (modified) (1 diff)
-
WebKit/WebProcess/WebPage/WebPage.cpp (modified) (3 diffs)
-
WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (modified) (57 diffs)
-
WebKitLegacy/ios/ChangeLog (modified) (1 diff)
-
WebKitLegacy/ios/WebCoreSupport/WebVisiblePosition.mm (modified) (1 diff)
-
WebKitLegacy/mac/ChangeLog (modified) (1 diff)
-
WebKitLegacy/mac/DOM/DOMHTML.mm (modified) (2 diffs)
-
WebKitLegacy/mac/DOM/DOMUIKitExtensions.mm (modified) (2 diffs)
-
WebKitLegacy/mac/DOM/WebDOMOperations.mm (modified) (2 diffs)
-
WebKitLegacy/mac/WebView/WebFrame.mm (modified) (6 diffs)
-
WebKitLegacy/mac/WebView/WebView.mm (modified) (3 diffs)
-
WebKitLegacy/win/AccessibleTextImpl.cpp (modified) (1 diff)
-
WebKitLegacy/win/ChangeLog (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r265079 r265084 1 2020-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 1 115 2020-07-30 Brady Eidson <beidson@apple.com> 2 116 -
trunk/Source/WebCore/accessibility/AccessibilityObject.cpp
r265044 r265084 723 723 724 724 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)) 726 726 continue; 727 727 … … 2013 2013 auto& frame = renderer()->frame(); 2014 2014 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); 2016 2016 frame.editor().replaceSelectionWithText(replacementString, Editor::SelectReplacement::No, Editor::SmartReplace::No); 2017 2017 return true; -
trunk/Source/WebCore/dom/SimpleRange.cpp
r265044 r265084 83 83 } 84 84 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 114 85 SimpleRange makeRangeSelectingNodeContents(Node& node) 115 86 { -
trunk/Source/WebCore/dom/SimpleRange.h
r265044 r265084 52 52 }; 53 53 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>&&); 54 SimpleRange makeSimpleRangeHelper(BoundaryPoint&&, BoundaryPoint&&); 55 Optional<SimpleRange> makeSimpleRangeHelper(Optional<BoundaryPoint>&&, Optional<BoundaryPoint>&&); 56 SimpleRange makeSimpleRangeHelper(BoundaryPoint&&); 57 Optional<SimpleRange> makeSimpleRangeHelper(Optional<BoundaryPoint>&&); 62 58 63 59 inline BoundaryPoint makeBoundaryPointHelper(const BoundaryPoint& point) { return point; } 64 60 inline 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 } 61 inline Optional<BoundaryPoint> makeBoundaryPointHelper(const Optional<BoundaryPoint>& point) { return point; } 62 inline Optional<BoundaryPoint> makeBoundaryPointHelper(Optional<BoundaryPoint>&& point) { return WTFMove(point); } 63 template<typename T> auto makeBoundaryPointHelper(T&& argument) -> decltype(makeBoundaryPoint(std::forward<T>(argument))) { return makeBoundaryPoint(std::forward<T>(argument)); } 69 64 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 } 65 template<typename ...T> auto makeSimpleRange(T&& ...arguments) -> decltype(makeSimpleRangeHelper(makeBoundaryPointHelper(std::forward<T>(arguments))...)) { return makeSimpleRangeHelper(makeBoundaryPointHelper(std::forward<T>(arguments))...); } 74 66 75 67 // FIXME: Would like these to have shorter names; another option is to change prefix to makeSimpleRange. … … 136 128 } 137 129 130 inline SimpleRange makeSimpleRangeHelper(BoundaryPoint&& start, BoundaryPoint&& end) 131 { 132 return { WTFMove(start), WTFMove(end) }; 138 133 } 134 135 inline 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 142 inline SimpleRange makeSimpleRangeHelper(BoundaryPoint&& point) 143 { 144 auto end = point; 145 return makeSimpleRangeHelper(WTFMove(point), WTFMove(end)); 146 } 147 148 inline 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 56 56 #include "MergeIdenticalElementsCommand.h" 57 57 #include "NodeTraversal.h" 58 #include "Range.h"59 58 #include "RemoveNodeCommand.h" 60 59 #include "RemoveNodePreservingChildrenCommand.h" … … 1441 1440 Position end = endOfParagraphToMove.deepEquivalent().upstream(); 1442 1441 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 1448 1442 // FIXME: This is an inefficient way to preserve style on nodes in the paragraph to move. It 1449 1443 // shouldn't matter though, since moved paragraphs will usually be quite small. 1450 1444 RefPtr<DocumentFragment> fragment; 1451 // This used to use a ternary for initialization, but that confused some versions of GCC, see bug 379121452 1445 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()); 1454 1447 1455 1448 // 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 726 726 return; 727 727 728 replaceSelectionWithFragment(createFragmentFromText( createLiveRange(*range), text), selectReplacement, smartReplace, MatchStyle::Yes, editingAction);728 replaceSelectionWithFragment(createFragmentFromText(*range, text), selectReplacement, smartReplace, MatchStyle::Yes, editingAction); 729 729 } 730 730 … … 2121 2121 unsigned start = std::min(baseOffset + selectionStart, extentOffset); 2122 2122 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); 2125 2125 } 2126 2126 } … … 3894 3894 auto& selection = m_document.selection().selection(); 3895 3895 auto range = selection.isCaret() 3896 ? wordRangeFromPosition(selection.start())3897 : createLiveRange(selection.toNormalizedRange());3896 ? wordRangeFromPosition(selection.start()) 3897 : selection.toNormalizedRange(); 3898 3898 if (!range) 3899 3899 return { }; … … 4194 4194 insertText(acceptedCandidate.replacement, nullptr); 4195 4195 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)) 4198 4197 addMarker(*insertedCandidateRange, DocumentMarker::AcceptedCandidate, acceptedCandidate.replacement); 4199 4198 -
trunk/Source/WebCore/editing/EditorCommand.cpp
r264692 r265084 185 185 if (!frame.editor().client()->shouldChangeSelectedRange(*oldRange, *newRange, affinity, false)) 186 186 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? 188 189 return true; 189 190 } … … 355 356 auto& selection = frame.selection(); 356 357 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)) 360 359 return false; 361 360 } … … 1057 1056 return false; 1058 1057 } 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? 1060 1060 return true; 1061 1061 } … … 1572 1572 if (selection.isNoneOrOrphaned() || !selection.isContentEditable()) 1573 1573 return emptyString(); 1574 auto* formatBlockElement = FormatBlockCommand::elementForFormatBlockCommand( createLiveRange(selection.firstRange()).get());1574 auto* formatBlockElement = FormatBlockCommand::elementForFormatBlockCommand(selection.firstRange()); 1575 1575 if (!formatBlockElement) 1576 1576 return emptyString(); -
trunk/Source/WebCore/editing/FormatBlockCommand.cpp
r239535 r265084 32 32 #include "HTMLElement.h" 33 33 #include "HTMLNames.h" 34 #include "Range.h"35 34 #include "VisibleUnits.h" 36 35 #include <wtf/NeverDestroyed.h> … … 69 68 RefPtr<Node> nodeAfterInsertionPosition = outerBlock; 70 69 71 auto range = Range::create(document(),start, endOfSelection);70 auto range = makeSimpleRange(start, endOfSelection); 72 71 Element* refNode = enclosingBlockFlowElement(end); 73 72 Element* root = editableRootForPosition(start); … … 76 75 return; 77 76 if (isElementForFormatBlock(refNode->tagQName()) && start == startOfBlock(start) 78 && (end == endOfBlock(end) || isNodeVisiblyContainedWithin(*refNode, range.get()))77 && (end == endOfBlock(end) || (range && isNodeVisiblyContainedWithin(*refNode, *range))) 79 78 && refNode != root && !root->isDescendantOf(*refNode)) { 80 79 // Already in a block element that only contains the current paragraph … … 100 99 } 101 100 102 Element* FormatBlockCommand::elementForFormatBlockCommand( Range*range)101 Element* FormatBlockCommand::elementForFormatBlockCommand(const Optional<SimpleRange>& range) 103 102 { 104 103 if (!range) 105 104 return nullptr; 106 105 107 Node* commonAncestor = range->commonAncestorContainer();108 while (commonAncestor && !isElementForFormatBlock(commonAncestor ))106 auto commonAncestor = commonInclusiveAncestor(*range); 107 while (commonAncestor && !isElementForFormatBlock(commonAncestor.get())) 109 108 commonAncestor = commonAncestor->parentNode(); 110 111 if (!commonAncestor) 109 if (!is<Element>(commonAncestor)) 112 110 return nullptr; 113 111 114 Element* rootEditableElement = range->startContainer().rootEditableElement();112 auto rootEditableElement = range->start.container->rootEditableElement(); 115 113 if (!rootEditableElement || commonAncestor->contains(rootEditableElement)) 116 114 return nullptr; 117 115 118 return commonAncestor->isElementNode() ? downcast<Element>(commonAncestor) : nullptr;116 return &downcast<Element>(*commonAncestor); 119 117 } 120 118 -
trunk/Source/WebCore/editing/FormatBlockCommand.h
r235775 r265084 47 47 bool preservesTypingStyle() const override { return true; } 48 48 49 static Element* elementForFormatBlockCommand( Range*);49 static Element* elementForFormatBlockCommand(const Optional<SimpleRange>&); 50 50 bool didApply() const { return m_didApply; } 51 51 -
trunk/Source/WebCore/editing/FrameSelection.cpp
r265044 r265084 206 206 } 207 207 208 void FrameSelection::moveTo(const Range* range)209 {210 VisibleSelection selection = range ? VisibleSelection(range->startPosition(), range->endPosition()) : VisibleSelection();211 setSelection(selection);212 }213 214 208 void FrameSelection::moveTo(const Position &base, const Position &extent, EAffinity affinity, EUserTriggered userTriggered) 215 209 { … … 2035 2029 } 2036 2030 2037 bool FrameSelection::setSelectedRange( Range*range, EAffinity affinity, ShouldCloseTyping closeTyping, EUserTriggered userTriggered)2031 bool FrameSelection::setSelectedRange(const Optional<SimpleRange>& range, EAffinity affinity, ShouldCloseTyping closeTyping, EUserTriggered userTriggered) 2038 2032 { 2039 2033 if (!range) 2040 2034 return false; 2041 ASSERT(&range->startContainer().document() == &range->endContainer().document()); 2035 2036 if (&range->start.container->document() != &range->end.container->document()) 2037 return false; 2042 2038 2043 2039 VisibleSelection newSelection(*range, affinity); -
trunk/Source/WebCore/editing/FrameSelection.h
r265044 r265084 31 31 #include "IntRect.h" 32 32 #include "LayoutRect.h" 33 #include "Range.h"34 33 #include "ScrollAlignment.h" 35 34 #include "Timer.h" … … 145 144 WEBCORE_EXPORT Element* rootEditableElementOrDocumentElement() const; 146 145 147 WEBCORE_EXPORT void moveTo(const Range*);148 146 WEBCORE_EXPORT void moveTo(const VisiblePosition&, EUserTriggered = NotUserTriggered, CursorAlignOnScroll = AlignCursorOnScrollIfNeeded); 149 147 WEBCORE_EXPORT void moveTo(const VisiblePosition&, const VisiblePosition&, EUserTriggered = NotUserTriggered); … … 156 154 157 155 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); 159 157 WEBCORE_EXPORT void selectAll(); 160 158 WEBCORE_EXPORT void clear(); -
trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp
r261967 r265084 208 208 return; 209 209 210 m_fragment = createFragmentFromText( createLiveRange(*range), event->text());210 m_fragment = createFragmentFromText(*range, event->text()); 211 211 if (!m_fragment->firstChild()) 212 212 return; -
trunk/Source/WebCore/editing/VisibleUnits.cpp
r265044 r265084 1834 1834 } 1835 1835 1836 RefPtr<Range> enclosingTextUnitOfGranularity(const VisiblePosition& vp, TextGranularity granularity, SelectionDirection direction)1836 Optional<SimpleRange> enclosingTextUnitOfGranularity(const VisiblePosition& vp, TextGranularity granularity, SelectionDirection direction) 1837 1837 { 1838 1838 // This is particularly inefficient. We could easily obtain the answer with the boundaries computed below. 1839 1839 if (!withinTextUnitOfGranularity(vp, granularity, direction)) 1840 return nullptr;1840 return WTF::nullopt; 1841 1841 1842 1842 VisiblePosition prevBoundary; … … 1890 1890 default: 1891 1891 ASSERT_NOT_REACHED(); 1892 return nullptr;1892 return WTF::nullopt; 1893 1893 } 1894 1894 1895 1895 if (prevBoundary.isNull() || nextBoundary.isNull()) 1896 return nullptr;1896 return WTF::nullopt; 1897 1897 1898 1898 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); 1902 1902 } 1903 1903 … … 1945 1945 } 1946 1946 1947 RefPtr<Range> wordRangeFromPosition(const VisiblePosition& position)1947 Optional<SimpleRange> wordRangeFromPosition(const VisiblePosition& position) 1948 1948 { 1949 1949 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)) 1960 1955 return range; 1961 1956 … … 1966 1961 if (currentPosition.isNull()) 1967 1962 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); 1975 1964 } 1976 1965 … … 1983 1972 } else if (withinTextUnitOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Forward)) { 1984 1973 // 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 } 1990 1979 } else if (atBoundaryOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Backward)) { 1991 1980 // The position is at the end of a word. … … 2003 1992 } 2004 1993 2005 RefPtr<Range> rangeExpandedByCharactersInDirectionAtWordBoundary(const VisiblePosition& position, int numberOfCharactersToExpand, SelectionDirection direction)1994 Optional<SimpleRange> rangeExpandedByCharactersInDirectionAtWordBoundary(const VisiblePosition& position, int numberOfCharactersToExpand, SelectionDirection direction) 2006 1995 { 2007 1996 Position start = position.deepEquivalent(); … … 2019 2008 end = endOfWord(end).deepEquivalent(); 2020 2009 2021 return make Range(start, end);2010 return makeSimpleRange(start, end); 2022 2011 } 2023 2012 2024 RefPtr<Range> rangeExpandedAroundPositionByCharacters(const VisiblePosition& position, int numberOfCharactersToExpand)2013 Optional<SimpleRange> rangeExpandedAroundPositionByCharacters(const VisiblePosition& position, int numberOfCharactersToExpand) 2025 2014 { 2026 2015 Position start = position.deepEquivalent(); … … 2030 2019 end = end.next(Character); 2031 2020 } 2032 2033 return makeRange(start, end); 2021 return makeSimpleRange(start, end); 2034 2022 } 2035 2023 … … 2042 2030 auto adjustedPosition = position; 2043 2031 if (auto wordRange = enclosingTextUnitOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Forward)) { 2044 adjustedPosition = wordRange->startPosition();2032 adjustedPosition = createLegacyEditingPosition(wordRange->start); 2045 2033 if (distanceBetweenPositions(position, adjustedPosition) > 1) 2046 adjustedPosition = wordRange->endPosition();2034 adjustedPosition = createLegacyEditingPosition(wordRange->end); 2047 2035 } 2048 2036 return { adjustedPosition, WithinWordBoundary::Yes }; -
trunk/Source/WebCore/editing/VisibleUnits.h
r261139 r265084 102 102 WEBCORE_EXPORT bool withinTextUnitOfGranularity(const VisiblePosition&, TextGranularity, SelectionDirection); 103 103 WEBCORE_EXPORT VisiblePosition positionOfNextBoundaryOfGranularity(const VisiblePosition&, TextGranularity, SelectionDirection); 104 WEBCORE_EXPORT RefPtr<Range> enclosingTextUnitOfGranularity(const VisiblePosition&, TextGranularity, SelectionDirection);104 WEBCORE_EXPORT Optional<SimpleRange> enclosingTextUnitOfGranularity(const VisiblePosition&, TextGranularity, SelectionDirection); 105 105 WEBCORE_EXPORT std::ptrdiff_t distanceBetweenPositions(const VisiblePosition&, const VisiblePosition&); 106 WEBCORE_EXPORT RefPtr<Range> wordRangeFromPosition(const VisiblePosition&);106 WEBCORE_EXPORT Optional<SimpleRange> wordRangeFromPosition(const VisiblePosition&); 107 107 WEBCORE_EXPORT VisiblePosition closestWordBoundaryForPosition(const VisiblePosition& position); 108 108 WEBCORE_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);109 WEBCORE_EXPORT Optional<SimpleRange> rangeExpandedAroundPositionByCharacters(const VisiblePosition&, int numberOfCharactersToExpand); 110 WEBCORE_EXPORT Optional<SimpleRange> rangeExpandedByCharactersInDirectionAtWordBoundary(const VisiblePosition&, int numberOfCharactersToExpand, SelectionDirection); 111 111 enum class WithinWordBoundary : bool { No, Yes }; 112 112 WEBCORE_EXPORT std::pair<VisiblePosition, WithinWordBoundary> wordBoundaryForPositionWithoutCrossingLine(const VisiblePosition&); -
trunk/Source/WebCore/editing/cocoa/DataDetection.mm
r265044 r265084 129 129 130 130 VisiblePosition position; 131 RefPtr<Range> contextRange;131 Optional<SimpleRange> contextRange; 132 132 133 133 if (!is<HTMLTextFormControlElement>(*node)) { -
trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm
r265044 r265084 42 42 #import "NotImplemented.h" 43 43 #import "Page.h" 44 #import "Range.h"45 44 #import "RenderObject.h" 46 45 #import "TextIterator.h" … … 284 283 NSRange rangeToPass = NSMakeRange(lengthToSelectionStart, selectionCharacterCount); 285 284 286 RefPtr<Range> fullCharacterRange = makeRange(paragraphStart, paragraphEnd);287 String itemString = plainText( *fullCharacterRange);285 auto fullCharacterRange = *makeSimpleRange(paragraphStart, paragraphEnd); 286 String itemString = plainText(fullCharacterRange); 288 287 NSRange highlightRange = adoptNS([allocRVItemInstance() initWithText:itemString selectedRange:rangeToPass]).get().highlightRange; 289 288 290 return { { resolveCharacterRange( *fullCharacterRange, highlightRange), nil } };289 return { { resolveCharacterRange(fullCharacterRange, highlightRange), nil } }; 291 290 292 291 END_BLOCK_OBJC_EXCEPTIONS … … 342 341 343 342 // 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); 349 344 350 345 selectionRange = NSMakeRange(NSNotFound, 0); -
trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm
r264692 r265084 95 95 outData.append(PasteboardCustomData { element.document().originIdentifierForPasteboard(), { } }.createSharedBuffer()); 96 96 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 } 101 103 } 102 104 } -
trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
r265044 r265084 670 670 return false; 671 671 672 addFragment(createFragmentFromText(c reateLiveRange(context), [text precomposedStringWithCanonicalMapping]));672 addFragment(createFragmentFromText(context, [text precomposedStringWithCanonicalMapping])); 673 673 674 674 madeFragmentFromPlainText = true; -
trunk/Source/WebCore/editing/gtk/WebContentReaderGtk.cpp
r261792 r265084 66 66 return false; 67 67 68 addFragment(createFragmentFromText(c reateLiveRange(context), text));68 addFragment(createFragmentFromText(context, text)); 69 69 70 70 madeFragmentFromPlainText = true; -
trunk/Source/WebCore/editing/libwpe/EditorLibWPE.cpp
r264692 r265084 56 56 if (types.contains("text/plain;charset=utf-8")) { 57 57 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")); 59 59 } 60 60 -
trunk/Source/WebCore/editing/mac/DictionaryLookupLegacy.mm
r265044 r265084 132 132 return WTF::nullopt; 133 133 134 auto rangeToPosition = makeSimpleRange(fullCharacterRange->start Position(), position);134 auto rangeToPosition = makeSimpleRange(fullCharacterRange->start, position); 135 135 if (!rangeToPosition) 136 136 return WTF::nullopt; -
trunk/Source/WebCore/editing/markup.cpp
r265044 r265084 332 332 }; 333 333 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) 334 inline 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) 337 336 , m_start(start) 338 337 , m_end(end) … … 836 835 } 837 836 838 static String serializePreservingVisualAppearanceInternal(const Position& start, const Position& end, Vector<Node*>* nodes, ResolveURLs urlsToResolve, SerializeComposedTree serializeComposedTree,837 static String serializePreservingVisualAppearanceInternal(const Position& start, const Position& end, Vector<Node*>* nodes, ResolveURLs resolveURLs, SerializeComposedTree serializeComposedTree, 839 838 AnnotateForInterchange annotate, ConvertBlocksToInlines convertBlocksToInlines, StandardFontFamilySerializationMode standardFontFamilySerializationMode, MSOListMode msoListMode) 840 839 { … … 863 862 Node* specialCommonAncestor = highestAncestorToWrapMarkup(start, end, *commonAncestor, annotate); 864 863 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); 866 865 867 866 Position startAdjustedForInterchangeNewline = start; … … 935 934 } 936 935 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, 936 String 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, 940 940 annotate, convertBlocksToInlines, StandardFontFamilySerializationMode::Keep, MSOListMode::DoNotPreserve); 941 941 } … … 1044 1044 } 1045 1045 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);1046 String serializeFragment(const Node& node, SerializedNodes root, Vector<Node*>* nodes, ResolveURLs resolveURLs, Vector<QualifiedName>* tagNamesToSkip, SerializationSyntax serializationSyntax) 1047 { 1048 MarkupAccumulator accumulator(nodes, resolveURLs, serializationSyntax); 1049 1049 return accumulator.serializeNodes(const_cast<Node&>(node), root, tagNamesToSkip); 1050 1050 } … … 1113 1113 } 1114 1114 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(); 1115 static 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 1121 Ref<DocumentFragment> createFragmentFromText(const SimpleRange& context, const String& text) 1122 { 1123 auto& document = context.start.container->document(); 1124 auto fragment = document.createDocumentFragment(); 1129 1125 1130 1126 if (text.isEmpty()) … … 1162 1158 1163 1159 // Break string into paragraphs. Extra line breaks turn into empty paragraphs. 1164 Node* blockNode = enclosingBlock(c ontext.firstNode());1160 Node* blockNode = enclosingBlock(createLiveRange(context)->firstNode()); 1165 1161 Element* block = downcast<Element>(blockNode); 1166 1162 bool useClonesOfEnclosingBlock = blockNode … … 1168 1164 && !block->hasTagName(bodyTag) 1169 1165 && !block->hasTagName(htmlTag) 1170 && block != editableRootForPosition(c ontext.startPosition());1171 bool useLineBreak = enclosingTextFormControl(c ontext.startPosition());1166 && block != editableRootForPosition(createLegacyEditingPosition(context.start)); 1167 bool useLineBreak = enclosingTextFormControl(createLegacyEditingPosition(context.start)); 1172 1168 1173 1169 Vector<String> list = string.splitAllowingEmptyEntries('\n'); -
trunk/Source/WebCore/editing/markup.h
r261395 r265084 45 45 class Node; 46 46 class Page; 47 class QualifiedName; 48 class VisibleSelection; 49 47 50 struct PresentationSize; 48 class QualifiedName; 49 class Range; 50 class VisibleSelection; 51 struct SimpleRange; 51 52 52 53 void replaceSubresourceURLs(Ref<DocumentFragment>&&, HashMap<AtomString, AtomString>&&); … … 58 59 String sanitizedMarkupForFragmentInDocument(Ref<DocumentFragment>&&, Document&, MSOListQuirks, const String& originalMarkup); 59 60 60 WEBCORE_EXPORT Ref<DocumentFragment> createFragmentFromText( Range& context, const String& text);61 WEBCORE_EXPORT Ref<DocumentFragment> createFragmentFromText(const SimpleRange& context, const String& text); 61 62 WEBCORE_EXPORT Ref<DocumentFragment> createFragmentFromMarkup(Document&, const String& markup, const String& baseURL, ParserContentPolicy = AllowScriptingContent); 62 63 ExceptionOr<Ref<DocumentFragment>> createFragmentForInnerOuterHTML(Element&, const String& markup, ParserContentPolicy); … … 73 74 enum class ConvertBlocksToInlines : uint8_t { No, Yes }; 74 75 enum 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);76 WEBCORE_EXPORT String serializePreservingVisualAppearance(const SimpleRange&, Vector<Node*>* = nullptr, AnnotateForInterchange = AnnotateForInterchange::No, ConvertBlocksToInlines = ConvertBlocksToInlines::No, ResolveURLs = ResolveURLs::No); 76 77 String serializePreservingVisualAppearance(const VisibleSelection&, ResolveURLs = ResolveURLs::No, SerializeComposedTree = SerializeComposedTree::No, Vector<Node*>* = nullptr); 77 78 -
trunk/Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp
r262683 r265084 49 49 #include "MemoryCache.h" 50 50 #include "Page.h" 51 #include "Range.h"52 51 #include "RuntimeEnabledFeatures.h" 53 52 #include "SerializedAttachmentData.h" … … 418 417 return create(); 419 418 420 // If the page was loaded with javascript enabled, we don't want to archive <noscript> tags419 // If the page was loaded with JavaScript enabled, we don't want to archive <noscript> tags 421 420 // In practice we don't actually know whether scripting was enabled when the page was originally loaded 422 421 // but we can approximate that by checking if scripting is enabled right now. … … 455 454 } 456 455 457 RefPtr<LegacyWebArchive> LegacyWebArchive::create(Range* range) 458 { 459 if (!range) 460 return nullptr; 461 462 auto& document = range->startContainer().document(); 456 RefPtr<LegacyWebArchive> LegacyWebArchive::create(const SimpleRange& range) 457 { 458 auto& document = range.start.container->document(); 463 459 auto* frame = document.frame(); 464 460 if (!frame) … … 467 463 // FIXME: This is always "for interchange". Is that right? 468 464 Vector<Node*> nodeList; 469 String markupString = documentTypeString(document) + serializePreservingVisualAppearance( *range, &nodeList, AnnotateForInterchange::Yes);465 String markupString = documentTypeString(document) + serializePreservingVisualAppearance(range, &nodeList, AnnotateForInterchange::Yes); 470 466 return create(markupString, *frame, nodeList, nullptr); 471 467 } -
trunk/Source/WebCore/loader/archive/cf/LegacyWebArchive.h
r218501 r265084 36 36 class Frame; 37 37 class Node; 38 class Range; 38 39 struct SimpleRange; 39 40 40 41 class LegacyWebArchive final : public Archive { … … 47 48 WEBCORE_EXPORT static RefPtr<LegacyWebArchive> create(Frame&); 48 49 WEBCORE_EXPORT static RefPtr<LegacyWebArchive> createFromSelection(Frame*); 49 WEBCORE_EXPORT static RefPtr<LegacyWebArchive> create( Range*);50 WEBCORE_EXPORT static RefPtr<LegacyWebArchive> create(const SimpleRange&); 50 51 51 52 WEBCORE_EXPORT RetainPtr<CFDataRef> rawDataRepresentation(); -
trunk/Source/WebCore/page/DragController.cpp
r264692 r265084 72 72 #include "Position.h" 73 73 #include "PromisedAttachmentInfo.h" 74 #include "Range.h" 74 75 #include "RenderAttachment.h" 75 76 #include "RenderFileUploadControl.h" … … 240 241 if (!m_droppedImagePlaceholders.isEmpty() && m_droppedImagePlaceholderRange && tryToUpdateDroppedImagePlaceholders(dragData)) { 241 242 m_droppedImagePlaceholders.clear(); 242 m_droppedImagePlaceholderRange = nullptr;243 m_droppedImagePlaceholderRange = WTF::nullopt; 243 244 m_documentUnderMouse = nullptr; 244 245 clearDragCaret(); … … 634 635 635 636 client().willPerformDragDestinationAction(DragDestinationAction::Edit, dragData); 636 auto fragment = createFragmentFromText( createLiveRange(*range), text);637 auto fragment = createFragmentFromText(*range, text); 637 638 if (editor.client() && editor.client()->performTwoStepDrop(fragment.get(), createLiveRange(*range), isMove)) 638 639 return true; … … 857 858 static void selectElement(Element& element) 858 859 { 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 } 862 864 } 863 865 … … 1374 1376 void DragController::removeAllDroppedImagePlaceholders() 1375 1377 { 1376 m_droppedImagePlaceholderRange = nullptr;1378 m_droppedImagePlaceholderRange = WTF::nullopt; 1377 1379 for (auto& placeholder : std::exchange(m_droppedImagePlaceholders, { })) { 1378 1380 if (placeholder->isConnected()) … … 1456 1458 command->apply(); 1457 1459 1458 auto insertedContentRange = command->insertedContentRange();1460 auto insertedContentRange = makeSimpleRange(command->insertedContentRange()); 1459 1461 if (!insertedContentRange) { 1460 1462 ASSERT_NOT_REACHED(); … … 1462 1464 } 1463 1465 1464 auto container = makeRefPtr(insertedContentRange->commonAncestorContainer());1466 auto container = commonInclusiveAncestor(*insertedContentRange); 1465 1467 if (!is<ContainerNode>(container)) { 1466 1468 ASSERT_NOT_REACHED(); … … 1470 1472 Vector<Ref<HTMLImageElement>> placeholders; 1471 1473 for (auto& placeholder : descendantsOfType<HTMLImageElement>(downcast<ContainerNode>(*container))) { 1472 auto intersectsNode = insertedContentRange->intersectsNode(placeholder);1474 auto intersectsNode = createLiveRange(*insertedContentRange)->intersectsNode(placeholder); 1473 1475 if (!intersectsNode.hasException() && intersectsNode.returnValue()) 1474 1476 placeholders.append(placeholder); … … 1494 1496 1495 1497 frame->selection().clear(); 1496 caretController.setCaretPosition( m_droppedImagePlaceholderRange->startPosition());1498 caretController.setCaretPosition(createLegacyEditingPosition(m_droppedImagePlaceholderRange->start)); 1497 1499 } 1498 1500 -
trunk/Source/WebCore/page/DragController.h
r262913 r265084 30 30 #include "IntPoint.h" 31 31 #include "IntRect.h" 32 #include "SimpleRange.h" 32 33 #include <wtf/URL.h> 33 34 … … 90 91 91 92 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; } 93 94 94 95 WEBCORE_EXPORT void finalizeDroppedImagePlaceholder(HTMLImageElement&); … … 162 163 bool m_isPerformingDrop { false }; 163 164 Vector<Ref<HTMLImageElement>> m_droppedImagePlaceholders; 164 RefPtr<Range> m_droppedImagePlaceholderRange;165 Optional<SimpleRange> m_droppedImagePlaceholderRange; 165 166 }; 166 167 -
trunk/Source/WebCore/page/Page.cpp
r265051 r265084 99 99 #include "PointerLockController.h" 100 100 #include "ProgressTracker.h" 101 #include "Range.h" 101 102 #include "RenderDescendantIterator.h" 102 103 #include "RenderLayerCompositor.h" … … 712 713 } 713 714 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; 715 auto Page::findTextMatches(const String& target, FindOptions options, unsigned limit) -> MatchingRanges 716 { 717 MatchingRanges result; 719 718 720 719 Frame* frame = &mainFrame(); 721 720 Frame* frameWithSelection = nullptr; 722 721 do { 723 frame->editor().countMatchesForText(target, { }, options, limit ? (limit - result Ranges.size()) : 0, true, &resultRanges);722 frame->editor().countMatchesForText(target, { }, options, limit ? (limit - result.ranges.size()) : 0, true, &result.ranges); 724 723 if (frame->selection().isRange()) 725 724 frameWithSelection = frame; … … 727 726 } while (frame); 728 727 729 if (result Ranges.isEmpty())730 return ;728 if (result.ranges.isEmpty()) 729 return result; 731 730 732 731 if (frameWithSelection) { 733 indexForSelection = NoMatchAfterUserSelection;732 result.indexForSelection = NoMatchAfterUserSelection; 734 733 auto selectedRange = frameWithSelection->selection().selection().firstRange(); 735 734 if (options.contains(Backwards)) { 736 for (size_t i = result Ranges.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; 740 739 break; 741 740 } 742 741 } 743 742 } else { 744 for (size_t i = 0, size = result Ranges.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; 748 747 break; 749 748 } … … 752 751 } else { 753 752 if (options.contains(Backwards)) 754 indexForSelection = resultRanges.size() - 1;753 result.indexForSelection = result.ranges.size() - 1; 755 754 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 761 Optional<SimpleRange> Page::rangeOfString(const String& target, const Optional<SimpleRange>& referenceRange, FindOptions options) 764 762 { 765 763 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; 770 768 771 769 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(); 773 771 Frame* startFrame = frame; 774 772 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; 777 775 frame = incrementFrame(frame, !options.contains(Backwards), canWrap); 778 776 } while (frame && frame != startFrame); … … 781 779 // We cheat a bit and just search again with wrap on. 782 780 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; 788 786 } 789 787 … … 880 878 continue; 881 879 882 frame->selection().setSelectedRange( createLiveRange(range).ptr(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes);880 frame->selection().setSelectedRange(range, DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes); 883 881 frame->editor().replaceSelectionWithText(replacementText, Editor::SelectReplacement::Yes, Editor::SmartReplace::No, EditAction::InsertReplacement); 884 882 } … … 886 884 } 887 885 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); 886 uint32_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. 893 889 894 890 Vector<FindReplacementRange> replacementRanges; … … 896 892 897 893 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()) 900 896 continue; 901 897 auto scope = makeRangeSelectingNodeContents(*highestRoot); -
trunk/Source/WebCore/page/Page.h
r264856 r265084 130 130 class PointerLockController; 131 131 class ProgressTracker; 132 class Range;133 132 class RenderObject; 134 133 class ResourceUsageOverlay; … … 153 152 class WheelEventTestMonitor; 154 153 154 struct SimpleRange; 155 155 156 using PlatformDisplayID = uint32_t; 156 157 using SharedStringHash = uint32_t; … … 290 291 291 292 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); 293 294 WEBCORE_EXPORT uint32_t replaceSelectionWithText(const String& replacementText); 294 295 295 296 WEBCORE_EXPORT void revealCurrentSelection(); 296 297 297 WEBCORE_EXPORT RefPtr<Range> rangeOfString(const String&, Range*, FindOptions);298 WEBCORE_EXPORT Optional<SimpleRange> rangeOfString(const String&, const Optional<SimpleRange>& searchRange, FindOptions); 298 299 299 300 WEBCORE_EXPORT unsigned countFindMatches(const String&, FindOptions, unsigned maxMatchCount); … … 305 306 WEBCORE_EXPORT void dispatchAfterPrintEvent(); 306 307 307 // Find all the Ranges for the matching text.308 // Find all the ranges for the matching text. 308 309 // Upon return, indexForSelection will be one of the following: 309 310 // 0 if there is no user selection 310 311 // the index of the first range after the user selection 311 312 // 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); 314 319 315 320 #if PLATFORM(COCOA) -
trunk/Source/WebCore/page/ios/FrameIOS.mm
r260777 r265084 55 55 #import "PlatformScreen.h" 56 56 #import "PropertySetCSSStyleDeclaration.h" 57 #import "Range.h" 57 58 #import "RenderLayer.h" 58 59 #import "RenderLayerCompositor.h" … … 117 118 VisiblePosition position(page()->selection().start(), page()->selection().affinity()); 118 119 VisiblePosition end(position); 120 119 121 if (!isStartOfParagraph(end)) { 120 122 VisiblePosition previous = end.previous(); 121 123 UChar c(previous.characterAfter()); 124 // FIXME: Should use something from ICU or ASCIICType that is not subject to POSIX current language rather than iswpunct. 122 125 if (!iswpunct(c) && !isSpaceOrNewline(c) && c != noBreakSpace) 123 126 end = startOfWord(end); … … 125 128 VisiblePosition start(startOfParagraph(end)); 126 129 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()) 132 132 return nil; 133 133 -
trunk/Source/WebCore/rendering/HitTestResult.cpp
r261776 r265084 580 580 return false; 581 581 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); 587 584 } 588 585 -
trunk/Source/WebKit/ChangeLog
r265081 r265084 1 2020-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 1 126 2020-07-30 Alex Christensen <achristensen@webkit.org> 2 127 -
trunk/Source/WebKit/Shared/API/c/mac/WKWebArchiveRef.cpp
r251952 r265084 34 34 #include "WKBundleAPICast.h" 35 35 #include "WKSharedAPICast.h" 36 #include <WebCore/Range.h> 37 #include <WebCore/SimpleRange.h> 36 38 37 39 WKTypeID WKWebArchiveGetTypeID() … … 54 56 WKWebArchiveRef WKWebArchiveCreateFromRange(WKBundleRangeHandleRef rangeHandleRef) 55 57 { 56 auto webArchive = API::WebArchive::create( WebKit::toImpl(rangeHandleRef)->coreRange());58 auto webArchive = API::WebArchive::create(makeSimpleRange(WebKit::toImpl(rangeHandleRef)->coreRange())); 57 59 return WebKit::toAPI(&webArchive.leakRef()); 58 60 } -
trunk/Source/WebKit/Shared/APIWebArchive.h
r216810 r265084 24 24 */ 25 25 26 #ifndef WebArchive_h 27 #define WebArchive_h 26 #pragma once 28 27 29 28 #if PLATFORM(COCOA) … … 39 38 namespace WebCore { 40 39 class LegacyWebArchive; 41 classRange;40 struct SimpleRange; 42 41 } 43 42 … … 53 52 static Ref<WebArchive> create(API::Data*); 54 53 static Ref<WebArchive> create(RefPtr<WebCore::LegacyWebArchive>&&); 55 static Ref<WebArchive> create( WebCore::Range&);54 static Ref<WebArchive> create(const WebCore::SimpleRange&); 56 55 57 56 WebArchiveResource* mainResource(); … … 77 76 78 77 #endif // PLATFORM(COCOA) 79 80 #endif // WebArchive_h -
trunk/Source/WebKit/Shared/APIWebArchive.mm
r260366 r265084 53 53 } 54 54 55 Ref<WebArchive> WebArchive::create( Range& range)55 Ref<WebArchive> WebArchive::create(const SimpleRange& range) 56 56 { 57 return adoptRef(*new WebArchive(LegacyWebArchive::create( &range)));57 return adoptRef(*new WebArchive(LegacyWebArchive::create(range))); 58 58 } 59 59 -
trunk/Source/WebKit/Shared/EditingRange.cpp
r259401 r265084 34 34 namespace WebKit { 35 35 36 RefPtr<WebCore::Range> EditingRange::toRange(WebCore::Frame& frame, const EditingRange& editingRange, EditingRangeIsRelativeTo base)36 Optional<WebCore::SimpleRange> EditingRange::toRange(WebCore::Frame& frame, const EditingRange& editingRange, EditingRangeIsRelativeTo base) 37 37 { 38 38 ASSERT(editingRange.location != notFound); … … 48 48 auto* element = frame.selection().rootEditableElementOrDocumentElement(); 49 49 if (!element) 50 return nullptr;51 return createLiveRange(resolveCharacterRange(makeRangeSelectingNodeContents(*element), range));50 return WTF::nullopt; 51 return resolveCharacterRange(makeRangeSelectingNodeContents(*element), range); 52 52 } 53 53 … … 56 56 auto paragraphStart = makeBoundaryPoint(startOfParagraph(frame.selection().selection().visibleStart())); 57 57 if (!paragraphStart) 58 return nullptr;58 return WTF::nullopt; 59 59 60 auto scopeEnd = make RangeSelectingNodeContents(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); 62 62 } 63 63 64 EditingRange EditingRange::fromRange(WebCore::Frame& frame, const WebCore::Range*range, EditingRangeIsRelativeTo editingRangeIsRelativeTo)64 EditingRange EditingRange::fromRange(WebCore::Frame& frame, const Optional<WebCore::SimpleRange>& range, EditingRangeIsRelativeTo editingRangeIsRelativeTo) 65 65 { 66 66 ASSERT(editingRangeIsRelativeTo == EditingRangeIsRelativeTo::EditableRoot); -
trunk/Source/WebKit/Shared/EditingRange.h
r259184 r265084 32 32 namespace WebCore { 33 33 class Frame; 34 classRange;34 struct SimpleRange; 35 35 } 36 36 … … 59 59 bool isValid() const { return location + length >= location; } 60 60 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); 63 63 64 64 #if defined(__OBJC__) -
trunk/Source/WebKit/WebProcess/InjectedBundle/API/APIInjectedBundleEditorClient.h
r241749 r265084 32 32 33 33 namespace WebCore { 34 class CSSStyleDeclaration;35 34 class DocumentFragment; 36 35 class Node; 37 class Range;38 36 class SharedBuffer; 37 class StyleProperties; 38 struct SimpleRange; 39 39 } 40 40 … … 52 52 virtual ~EditorClient() { } 53 53 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>>&) { } 67 67 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; } 69 69 }; 70 70 -
trunk/Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitWebEditor.cpp
r248846 r265084 83 83 84 84 private: 85 void didChangeSelection(WebPage&, StringImpl*) override85 void didChangeSelection(WebPage&, const String&) final 86 86 { 87 87 g_signal_emit(m_editor, signals[SELECTION_CHANGED], 0); -
trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm
r254241 r265084 31 31 #import <WebCore/DocumentFragment.h> 32 32 #import <WebCore/HTMLElement.h> 33 #import <WebCore/SimpleRange.h> 33 34 #import <WebCore/Text.h> 34 35 #import <WebCore/markup.h> … … 80 81 - (WKDOMNode *)createDocumentFragmentWithText:(NSString *)text 81 82 { 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()); 83 84 } 84 85 -
trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKDOMRange.mm
r261776 r265084 135 135 - (WKDOMRange *)rangeByExpandingToWordBoundaryByCharacters:(NSUInteger)characters inDirection:(WKDOMRangeDirection)direction 136 136 { 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]; 140 139 } 141 140 -
trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm
r264247 r265084 560 560 561 561 private: 562 bool shouldInsertText(WebKit::WebPage&, StringImpl* text, WebCore::Range*rangeToReplace, WebCore::EditorInsertAction action) final562 bool shouldInsertText(WebKit::WebPage&, const WTF::String& text, const Optional<WebCore::SimpleRange>& rangeToReplace, WebCore::EditorInsertAction action) final 563 563 { 564 564 if (!m_delegateMethods.shouldInsertText) 565 565 return true; 566 566 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) final567 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 571 571 { 572 572 if (!m_delegateMethods.shouldChangeSelectedRange) 573 573 return true; 574 574 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()]); 577 577 #if PLATFORM(IOS_FAMILY) 578 578 UITextStorageDirection apiAffinity = affinity == WebCore::UPSTREAM ? UITextStorageDirectionBackward : UITextStorageDirectionForward; … … 584 584 } 585 585 586 void didChange(WebKit::WebPage&, StringImpl*) final586 void didChange(WebKit::WebPage&, const String&) final 587 587 { 588 588 if (!m_delegateMethods.didChange) … … 592 592 } 593 593 594 void willWriteToPasteboard(WebKit::WebPage&, WebCore::Range*range) final594 void willWriteToPasteboard(WebKit::WebPage&, const Optional<WebCore::SimpleRange>& range) final 595 595 { 596 596 if (!m_delegateMethods.willWriteToPasteboard) 597 597 return; 598 598 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) final599 [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 603 603 { 604 604 if (!m_delegateMethods.getPasteboardDataForRange) 605 605 return; 606 606 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())]; 608 608 for (NSString *type in dataByType) { 609 609 pasteboardTypes.append(type); … … 620 620 } 621 621 622 bool performTwoStepDrop(WebKit::WebPage&, WebCore::DocumentFragment& fragment, WebCore::Range& range, bool isMove) final622 bool performTwoStepDrop(WebKit::WebPage&, WebCore::DocumentFragment& fragment, const WebCore::SimpleRange& range, bool isMove) final 623 623 { 624 624 if (!m_delegateMethods.performTwoStepDrop) 625 625 return false; 626 626 627 auto rangeHandle = WebKit:: InjectedBundleRangeHandle::getOrCreate(&range);627 auto rangeHandle = WebKit::createHandle(range); 628 628 auto nodeHandle = WebKit::InjectedBundleNodeHandle::getOrCreate(&fragment); 629 629 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 55 55 using namespace WebCore; 56 56 57 typedef HashMap<Range*, InjectedBundleRangeHandle*> DOMRangeHandleCache;57 using DOMRangeHandleCache = HashMap<Range*, InjectedBundleRangeHandle*>; 58 58 59 59 static DOMRangeHandleCache& domRangeHandleCache() … … 65 65 RefPtr<InjectedBundleRangeHandle> InjectedBundleRangeHandle::getOrCreate(JSContextRef context, JSObjectRef object) 66 66 { 67 Range* range = JSRange::toWrapped(toJS(context)->vm(), toJS(object)); 68 return getOrCreate(range); 67 return getOrCreate(JSRange::toWrapped(toJS(context)->vm(), toJS(object))); 69 68 } 70 69 … … 73 72 if (!range) 74 73 return nullptr; 75 76 DOMRangeHandleCache::AddResult result = domRangeHandleCache().add(range, nullptr); 74 auto result = domRangeHandleCache().add(range, nullptr); 77 75 if (!result.isNewEntry) 78 76 return result.iterator->value; 79 80 auto rangeHandle = InjectedBundleRangeHandle::create(*range); 77 auto rangeHandle = adoptRef(*new InjectedBundleRangeHandle(*range)); 81 78 result.iterator->value = rangeHandle.ptr(); 82 79 return rangeHandle; 83 }84 85 Ref<InjectedBundleRangeHandle> InjectedBundleRangeHandle::create(Range& range)86 {87 return adoptRef(*new InjectedBundleRangeHandle(range));88 80 } 89 81 … … 179 171 } 180 172 173 RefPtr<InjectedBundleRangeHandle> createHandle(const Optional<WebCore::SimpleRange>& range) 174 { 175 return InjectedBundleRangeHandle::getOrCreate(createLiveRange(range).get()); 176 } 177 181 178 } // namespace WebKit -
trunk/Source/WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h
r216810 r265084 24 24 */ 25 25 26 #ifndef InjectedBundleRangeHandle_h 27 #define InjectedBundleRangeHandle_h 26 #pragma once 28 27 29 28 #include "APIObject.h" … … 36 35 class IntRect; 37 36 class Range; 37 struct SimpleRange; 38 38 } 39 39 … … 60 60 61 61 private: 62 static Ref<InjectedBundleRangeHandle> create(WebCore::Range&);63 62 InjectedBundleRangeHandle(WebCore::Range&); 64 63 … … 66 65 }; 67 66 67 RefPtr<InjectedBundleRangeHandle> createHandle(const Optional<WebCore::SimpleRange>&); 68 68 69 } // namespace WebKit 69 70 #endif // InjectedBundleRangeHandle_h -
trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageEditorClient.cpp
r241749 r265084 39 39 #include "WebPage.h" 40 40 #include <WebCore/DocumentFragment.h> 41 #include <WebCore/StyleProperties.h> 41 42 #include <wtf/text/WTFString.h> 42 43 43 44 namespace WebKit { 44 45 using namespace WebCore; 46 47 static RefPtr<InjectedBundleCSSStyleDeclarationHandle> createHandle(const StyleProperties& style) 48 { 49 return InjectedBundleCSSStyleDeclarationHandle::getOrCreate(&style.mutableCopy()->ensureCSSStyleDeclaration()); 50 } 45 51 46 52 InjectedBundlePageEditorClient::InjectedBundlePageEditorClient(const WKBundlePageEditorClientBase& client) … … 49 55 } 50 56 51 bool InjectedBundlePageEditorClient::shouldBeginEditing(WebPage& page, Range*range)57 bool InjectedBundlePageEditorClient::shouldBeginEditing(WebPage& page, const SimpleRange& range) 52 58 { 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 64 bool 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 71 bool 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); 56 76 } 57 77 return true; 58 78 } 59 79 60 bool InjectedBundlePageEditorClient::should EndEditing(WebPage& page, Range* range)80 bool InjectedBundlePageEditorClient::shouldInsertText(WebPage& page, const String& text, const Optional<SimpleRange>& rangeToReplace, EditorInsertAction action) 61 81 { 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); 66 84 return true; 67 85 } 68 86 69 bool InjectedBundlePageEditorClient::should InsertNode(WebPage& page, Node* node, Range* rangeToReplace, EditorInsertAction action)87 bool InjectedBundlePageEditorClient::shouldDeleteRange(WebPage& page, const Optional<WebCore::SimpleRange>& range) 70 88 { 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); 76 91 return true; 77 92 } 78 93 79 bool InjectedBundlePageEditorClient::should InsertText(WebPage& page, StringImpl* text, Range* rangeToReplace, EditorInsertAction action)94 bool InjectedBundlePageEditorClient::shouldChangeSelectedRange(WebPage& page, const Optional<SimpleRange>& fromRange, const Optional<SimpleRange>& toRange, EAffinity affinity, bool stillSelecting) 80 95 { 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); 85 98 return true; 86 99 } 87 100 88 bool InjectedBundlePageEditorClient::should DeleteRange(WebPage& page, Range*range)101 bool InjectedBundlePageEditorClient::shouldApplyStyle(WebPage& page, const StyleProperties& style, const Optional<SimpleRange>& range) 89 102 { 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); 94 105 return true; 95 106 } 96 107 97 bool InjectedBundlePageEditorClient::shouldChangeSelectedRange(WebPage& page, Range* fromRange, Range* toRange, EAffinity affinity, bool stillSelecting)108 void InjectedBundlePageEditorClient::didBeginEditing(WebPage& page, const String& notificationName) 98 109 { 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); 105 112 } 106 113 107 bool InjectedBundlePageEditorClient::shouldApplyStyle(WebPage& page, CSSStyleDeclaration* style, Range* range)114 void InjectedBundlePageEditorClient::didEndEditing(WebPage& page, const String& notificationName) 108 115 { 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); 115 118 } 116 119 117 void InjectedBundlePageEditorClient::did BeginEditing(WebPage& page, StringImpl*notificationName)120 void InjectedBundlePageEditorClient::didChange(WebPage& page, const String& notificationName) 118 121 { 119 if (m_client.did BeginEditing)120 m_client.did BeginEditing(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); 121 124 } 122 125 123 void InjectedBundlePageEditorClient::did EndEditing(WebPage& page, StringImpl*notificationName)126 void InjectedBundlePageEditorClient::didChangeSelection(WebPage& page, const String& notificationName) 124 127 { 125 if (m_client.did EndEditing)126 m_client.did EndEditing(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); 127 130 } 128 131 129 void InjectedBundlePageEditorClient:: didChange(WebPage& page, StringImpl* notificationName)132 void InjectedBundlePageEditorClient::willWriteToPasteboard(WebPage& page, const Optional<SimpleRange>& range) 130 133 { 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); 133 136 } 134 137 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) 138 void InjectedBundlePageEditorClient::getPasteboardDataForRange(WebPage& page, const Optional<SimpleRange>& range, Vector<String>& pasteboardTypes, Vector<RefPtr<SharedBuffer>>& pasteboardData) 150 139 { 151 140 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)); 158 146 159 147 pasteboardTypes.clear(); … … 175 163 } 176 164 177 bool InjectedBundlePageEditorClient::performTwoStepDrop(WebPage& page, DocumentFragment& fragment, Range& destination, bool isMove)165 bool InjectedBundlePageEditorClient::performTwoStepDrop(WebPage& page, DocumentFragment& fragment, const SimpleRange& destination, bool isMove) 178 166 { 179 167 if (!m_client.performTwoStepDrop) 180 168 return false; 181 169 182 auto rangeHandle = InjectedBundleRangeHandle::getOrCreate(&destination);183 170 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); 185 172 } 186 173 -
trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageEditorClient.h
r241749 r265084 40 40 class DocumentFragment; 41 41 class Node; 42 classRange;42 struct SimpleRange; 43 43 } 44 44 … … 53 53 54 54 private: 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; 68 68 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; 70 70 }; 71 71 -
trunk/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp
r264905 r265084 78 78 bool WebEditorClient::shouldDeleteRange(const Optional<SimpleRange>& range) 79 79 { 80 return m_page->injectedBundleEditorClient().shouldDeleteRange(*m_page, createLiveRange(range).get());80 return m_page->injectedBundleEditorClient().shouldDeleteRange(*m_page, range); 81 81 } 82 82 … … 119 119 bool WebEditorClient::shouldBeginEditing(const SimpleRange& range) 120 120 { 121 return m_page->injectedBundleEditorClient().shouldBeginEditing(*m_page, createLiveRange(range).ptr());121 return m_page->injectedBundleEditorClient().shouldBeginEditing(*m_page, range); 122 122 } 123 123 124 124 bool WebEditorClient::shouldEndEditing(const SimpleRange& range) 125 125 { 126 return m_page->injectedBundleEditorClient().shouldEndEditing(*m_page, createLiveRange(range).ptr());126 return m_page->injectedBundleEditorClient().shouldEndEditing(*m_page, range); 127 127 } 128 128 129 129 bool WebEditorClient::shouldInsertNode(Node& node, const Optional<SimpleRange>& rangeToReplace, EditorInsertAction action) 130 130 { 131 return m_page->injectedBundleEditorClient().shouldInsertNode(*m_page, &node, createLiveRange(rangeToReplace).get(), action);131 return m_page->injectedBundleEditorClient().shouldInsertNode(*m_page, node, rangeToReplace, action); 132 132 } 133 133 134 134 bool WebEditorClient::shouldInsertText(const String& text, const Optional<SimpleRange>& rangeToReplace, EditorInsertAction action) 135 135 { 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); 137 137 } 138 138 139 139 bool WebEditorClient::shouldChangeSelectedRange(const Optional<SimpleRange>& fromRange, const Optional<SimpleRange>& toRange, EAffinity affinity, bool stillSelecting) 140 140 { 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); 142 142 } 143 143 144 144 bool WebEditorClient::shouldApplyStyle(const StyleProperties& style, const Optional<SimpleRange>& range) 145 145 { 146 return m_page->injectedBundleEditorClient().shouldApplyStyle(*m_page, &style.mutableCopy()->ensureCSSStyleDeclaration(), createLiveRange(range).get());146 return m_page->injectedBundleEditorClient().shouldApplyStyle(*m_page, style, range); 147 147 } 148 148 … … 269 269 void WebEditorClient::willWriteSelectionToPasteboard(const Optional<SimpleRange>& range) 270 270 { 271 m_page->injectedBundleEditorClient().willWriteToPasteboard(*m_page, createLiveRange(range).get());271 m_page->injectedBundleEditorClient().willWriteToPasteboard(*m_page, range); 272 272 } 273 273 274 274 void WebEditorClient::getClientPasteboardData(const Optional<SimpleRange>& range, Vector<String>& pasteboardTypes, Vector<RefPtr<SharedBuffer>>& pasteboardData) 275 275 { 276 m_page->injectedBundleEditorClient().getPasteboardDataForRange(*m_page, createLiveRange(range).get(), pasteboardTypes, pasteboardData);276 m_page->injectedBundleEditorClient().getPasteboardDataForRange(*m_page, range, pasteboardTypes, pasteboardData); 277 277 } 278 278 279 279 bool WebEditorClient::performTwoStepDrop(DocumentFragment& fragment, const SimpleRange& destination, bool isMove) 280 280 { 281 return m_page->injectedBundleEditorClient().performTwoStepDrop(*m_page, fragment, createLiveRange(destination), isMove);281 return m_page->injectedBundleEditorClient().performTwoStepDrop(*m_page, fragment, destination, isMove); 282 282 } 283 283 … … 538 538 { 539 539 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; 545 542 } 546 543 -
trunk/Source/WebKit/WebProcess/WebPage/FindController.cpp
r264584 r265084 47 47 #include <WebCore/PlatformMouseEvent.h> 48 48 #include <WebCore/PluginDocument.h> 49 #include <WebCore/Range.h> 49 50 #include <WebCore/SimpleRange.h> 50 51 … … 112 113 const uint32_t maximumNumberOfMatchesToReplace = 1000; 113 114 114 Vector< Ref<Range>> rangesToReplace;115 Vector<SimpleRange> rangesToReplace; 115 116 rangesToReplace.reserveCapacity(std::min<uint32_t>(maximumNumberOfMatchesToReplace, matchIndices.size())); 116 117 for (auto index : matchIndices) { 117 118 if (index < m_findMatches.size()) 118 rangesToReplace.uncheckedAppend( *m_findMatches[index]);119 rangesToReplace.uncheckedAppend(m_findMatches[index]); 119 120 if (rangesToReplace.size() >= maximumNumberOfMatchesToReplace) 120 121 break; … … 244 245 if (!pluginView) { 245 246 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; 252 251 foundStringStartsAfterSelection = true; 253 252 } … … 285 284 void FindController::findStringMatches(const String& string, OptionSet<FindOptions> options, unsigned maxMatchCount) 286 285 { 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); 291 288 292 289 Vector<Vector<IntRect>> matchRects; 293 290 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)); 297 294 298 295 if (!options.contains(FindOptions::ShowOverlay) && !options.contains(FindOptions::ShowFindIndicator)) … … 309 306 if (matchIndex >= m_findMatches.size()) 310 307 return; 311 Frame* frame = m_findMatches[matchIndex] ->startContainer().document().frame();308 Frame* frame = m_findMatches[matchIndex].start.container->document().frame(); 312 309 if (!frame) 313 310 return; 314 311 315 312 VisibleSelection oldSelection = frame->selection().selection(); 316 frame->selection().setSelection( VisibleSelection(*m_findMatches[matchIndex]));313 frame->selection().setSelection(m_findMatches[matchIndex]); 317 314 318 315 RefPtr<ShareableBitmap> selectionSnapshot = WebFrame::fromCoreFrame(*frame)->createSelectionSnapshot(); … … 340 337 if (matchIndex >= m_findMatches.size()) 341 338 return; 342 Frame* frame = m_findMatches[matchIndex] ->startContainer().document().frame();339 Frame* frame = m_findMatches[matchIndex].start.container->document().frame(); 343 340 if (!frame) 344 341 return; 345 frame->selection().setSelection( VisibleSelection(*m_findMatches[matchIndex]));342 frame->selection().setSelection(m_findMatches[matchIndex]); 346 343 } 347 344 -
trunk/Source/WebKit/WebProcess/WebPage/FindController.h
r264055 r265084 107 107 bool m_isShowingFindIndicator { false }; 108 108 WebCore::IntRect m_findIndicatorRect; 109 Vector< RefPtr<WebCore::Range>> m_findMatches;109 Vector<WebCore::SimpleRange> m_findMatches; 110 110 // Index value is -1 if not found or if number of matches exceeds provided maximum. 111 111 int m_foundStringMatchIndex { -1 }; -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r264842 r265084 5438 5438 { 5439 5439 Frame& frame = m_page->focusController().focusedOrMainFrame(); 5440 completionHandler(EditingRange::fromRange(frame, createLiveRange(frame.editor().compositionRange()).get()));5440 completionHandler(EditingRange::fromRange(frame, frame.editor().compositionRange())); 5441 5441 } 5442 5442 … … 5444 5444 { 5445 5445 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())); 5447 5447 } 5448 5448 … … 5453 5453 auto& frame = result.innerNonSharedNode() ? *result.innerNodeFrame() : m_page->focusController().focusedOrMainFrame(); 5454 5454 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)); 5457 5457 } 5458 5458 -
trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
r265044 r265084 162 162 } 163 163 164 static String plainTextForContext(const Range* range)165 {166 return range ? plainTextForContext(SimpleRange { *range }) : emptyString();167 }168 169 164 static String plainTextForDisplay(const SimpleRange& range) 170 165 { … … 172 167 } 173 168 174 static String plainTextForDisplay(const Range*range)169 static String plainTextForDisplay(const Optional<SimpleRange>& range) 175 170 { 176 171 return range ? plainTextForDisplay(*range) : emptyString(); … … 291 286 // FIXME: The following check should take into account writing direction. 292 287 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())); 294 289 if (selection.isContentEditable()) 295 290 charactersAroundPosition(selection.start(), postLayoutData.characterAfterSelection, postLayoutData.characterBeforeSelection, postLayoutData.twoCharacterBeforeSelection); … … 553 548 } 554 549 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)); 559 555 560 556 send(Messages::WebPageProxy::SelectionContextCallback(selectedText, textBefore, textAfter, callbackID)); … … 989 985 if (auto selectionRange = frame->selection().selection().toNormalizedRange()) { 990 986 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); 993 988 m_rangeForDropSnapshot = WTFMove(selectionRange); 994 989 } … … 1114 1109 return; 1115 1110 1116 VisiblePositionposition = renderer->positionForPoint(hitTest.localPoint(), nullptr);1111 auto position = renderer->positionForPoint(hitTest.localPoint(), nullptr); 1117 1112 if (position.isNull()) 1118 1113 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); 1125 1119 auto image = frame.editor().insertEditableImage(); 1126 1120 frame.document()->setFocusedElement(image.get()); … … 1372 1366 return; 1373 1367 } 1374 RefPtr<Range> range;1368 Optional<SimpleRange> range; 1375 1369 OptionSet<SelectionFlags> flags; 1376 1370 GestureRecognizerState wkGestureState = static_cast<GestureRecognizerState>(gestureState); … … 1386 1380 else 1387 1381 flags = PhraseBoundaryChanged; 1388 range = Range::create(*frame.document(), position, position); 1389 } 1382 range = makeSimpleRange(position); 1390 1383 break; 1391 1392 case GestureType::OneFingerTap: 1393 {1384 } 1385 1386 case GestureType::OneFingerTap: { 1394 1387 auto [adjustedPosition, withinWordBoundary] = wordBoundaryForPositionWithoutCrossingLine(position); 1395 1388 if (withinWordBoundary == WithinWordBoundary::Yes) 1396 1389 flags = WordIsNearTap; 1397 if (adjustedPosition.isNotNull()) 1398 range = Range::create(*frame.document(), adjustedPosition, adjustedPosition); 1399 } 1390 range = makeSimpleRange(adjustedPosition); 1400 1391 break; 1392 } 1401 1393 1402 1394 case GestureType::Loupe: 1403 1395 if (position.rootEditableElement()) 1404 range = Range::create(*frame.document(), position,position);1405 else 1396 range = makeSimpleRange(position); 1397 else { 1406 1398 #if !PLATFORM(MACCATALYST) 1407 1399 range = wordRangeFromPosition(position); 1408 1400 #else 1409 1401 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); 1413 1404 break; 1414 }1415 1405 case GestureRecognizerState::Changed: 1416 1406 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); 1420 1410 else 1421 range = Range::create(*frame.document(),position, start);1411 range = makeSimpleRange(position, start); 1422 1412 } 1423 1413 break; … … 1432 1422 } 1433 1423 #endif 1424 } 1434 1425 break; 1435 1426 … … 1446 1437 if (!m_currentWordRange) 1447 1438 break; 1448 range = createLiveRange(*m_currentWordRange);1449 if (position < range->startPosition())1450 range->s etStart(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); 1453 1444 break; 1454 1445 case GestureRecognizerState::Ended: … … 1467 1458 // This helps to get the callout for pasting at ends of lines, 1468 1459 // paragraphs, and documents. 1469 range = Range::create(*frame.document(), position,position);1460 range = makeSimpleRange(position); 1470 1461 } else 1471 1462 range = wordRangeFromPosition(position); … … 1480 1471 if (atBoundaryOfGranularity(position, TextGranularity::LineGranularity, SelectionDirection::Forward)) { 1481 1472 // 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); 1485 1475 } else 1486 1476 range = enclosingTextUnitOfGranularity(position, TextGranularity::ParagraphGranularity, SelectionDirection::Forward); … … 1491 1481 } 1492 1482 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); 1494 1484 1495 1485 send(Messages::WebPageProxy::GestureCallback(point, gestureType, gestureState, flags, callbackID)); 1496 1486 } 1497 1487 1498 static RefPtr<Range> rangeForPointInRootViewCoordinates(Frame& frame, const IntPoint& pointInRootViewCoordinates, bool baseIsStart)1488 static Optional<SimpleRange> rangeForPointInRootViewCoordinates(Frame& frame, const IntPoint& pointInRootViewCoordinates, bool baseIsStart) 1499 1489 { 1500 1490 VisibleSelection existingSelection = frame.selection().selection(); … … 1515 1505 1516 1506 VisiblePosition result; 1517 RefPtr<Range> range;1507 Optional<SimpleRange> range; 1518 1508 1519 1509 constexpr OptionSet<HitTestRequest::RequestType> hitType { HitTestRequest::ReadOnly, HitTestRequest::Active, HitTestRequest::AllowVisibleChildFrameContentOnly }; … … 1529 1519 else if (&selectionStart.deepEquivalent().anchorNode()->treeScope() != &hitTest.targetNode()->treeScope()) 1530 1520 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); 1534 1523 } else { 1535 1524 if (comparePositions(selectionEnd, result) <= 0) … … 1537 1526 else if (&hitTest.targetNode()->treeScope() != &selectionEnd.deepEquivalent().anchorNode()->treeScope()) 1538 1527 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); 1542 1530 } 1543 1531 … … 1545 1533 } 1546 1534 1547 static RefPtr<Range> rangeAtWordBoundaryForPosition(Frame* frame, const VisiblePosition& position, bool baseIsStart, SelectionDirection direction)1535 static Optional<SimpleRange> rangeAtWordBoundaryForPosition(Frame* frame, const VisiblePosition& position, bool baseIsStart, SelectionDirection direction) 1548 1536 { 1549 1537 SelectionDirection sameDirection = baseIsStart ? SelectionDirection::Forward : SelectionDirection::Backward; … … 1555 1543 if (atBoundaryOfGranularity(extent, TextGranularity::WordGranularity, sameDirection)) { 1556 1544 // This is a word boundary. Leave selection where it is. 1557 return nullptr;1545 return WTF::nullopt; 1558 1546 } 1559 1547 … … 1570 1558 && initialExtent != wordBoundary) { 1571 1559 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); 1573 1563 } 1574 1564 // Conversely, if the initial extent equals the current word boundary, then … … 1590 1580 extent = wordBoundary; 1591 1581 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); 1595 1587 } 1596 1588 … … 1707 1699 } 1708 1700 1709 RefPtr<Range> range;1710 VisiblePosition result;1711 OptionSet<SelectionFlags> flags;1712 1713 1701 if (shouldDispatchSyntheticMouseEventsWhenModifyingSelection()) 1714 1702 dispatchSyntheticMouseEventsForSelectionGesture(selectionTouch, point); 1703 1704 Optional<SimpleRange> range; 1705 OptionSet<SelectionFlags> flags; 1715 1706 1716 1707 switch (selectionTouch) { … … 1718 1709 case SelectionTouch::EndedNotMoving: 1719 1710 break; 1720 1711 1721 1712 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 1727 1716 range = rangeForPointInRootViewCoordinates(frame, point, baseIsStart); 1728 1717 break; … … 1731 1720 range = rangeAtWordBoundaryForPosition(&frame, position, baseIsStart, SelectionDirection::Forward); 1732 1721 break; 1733 1722 1734 1723 case SelectionTouch::EndedMovingBackward: 1735 1724 range = rangeAtWordBoundaryForPosition(&frame, position, baseIsStart, SelectionDirection::Backward); … … 1740 1729 break; 1741 1730 } 1731 1742 1732 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); 1744 1734 1745 1735 send(Messages::WebPageProxy::TouchesCallback(point, selectionTouch, flags, callbackID)); … … 1749 1739 { 1750 1740 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); 1760 1747 } 1761 1748 … … 1781 1768 bool shouldDispatchMouseEvents = shouldDispatchSyntheticMouseEventsWhenModifyingSelection(); 1782 1769 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(); 1785 1772 dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch::Started, startLocationForSyntheticMouseEvents); 1786 1773 dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch::Moved, endLocationForSyntheticMouseEvents); 1787 1774 } 1788 1775 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); 1790 1777 1791 1778 if (shouldDispatchMouseEvents) … … 1812 1799 return; 1813 1800 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); 1818 1807 } 1819 1808 … … 1833 1822 } 1834 1823 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); 1836 1825 completionHandler(); 1837 1826 } … … 1985 1974 1986 1975 Vector<WebCore::SelectionRect> selectionRects; 1987 range->collectSelectionRectsWithoutUnionInteriorLines(selectionRects);1976 createLiveRange(*range)->collectSelectionRectsWithoutUnionInteriorLines(selectionRects); 1988 1977 convertContentToRootViewSelectionRects(*frame.view(), selectionRects); 1989 1978 send(Messages::WebPageProxy::SelectionRectsCallback(selectionRects, callbackID)); … … 2034 2023 } 2035 2024 2036 if (plainTextForDisplay(range .ptr()) != text) {2025 if (plainTextForDisplay(range) != text) { 2037 2026 // Try to search for a range which is the closest to the position within the selection range that matches the passed in text. 2038 2027 if (auto wordRange = rangeNearPositionMatchesText(startPosition, text, selection)) { … … 2065 2054 2066 2055 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); 2068 2057 completionHandler(); 2069 2058 } … … 2077 2066 position = positionOfNextBoundaryOfGranularity(position, granularity, direction); 2078 2067 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); 2080 2069 } 2081 2070 completionHandler(); … … 2091 2080 position = positionOfNextBoundaryOfGranularity(position, granularity, direction); 2092 2081 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); 2094 2083 } 2095 2084 completionHandler(); … … 2100 2089 auto position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement); 2101 2090 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); 2114 2095 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); 2121 2098 case TextGranularity::DocumentGranularity: 2122 2099 // FIXME: Makes no sense that this mutates the current selection and returns null. … … 2165 2142 auto range = rangeForGranularityAtPoint(frame, point, granularity, isInteractingWithFocusedElement); 2166 2143 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); 2168 2145 m_initialSelection = range; 2169 2146 completionHandler(); … … 2197 2174 selectionStart = createLegacyEditingPosition(newRange->start); 2198 2175 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); 2203 2178 2204 2179 send(Messages::WebPageProxy::UnsignedCallback(selectionStart == initialSelectionStartPosition, callbackID)); … … 2215 2190 } 2216 2191 2217 RefPtr<Range> range;2218 2192 VisiblePosition selectionStart; 2219 2193 VisiblePosition selectionEnd; … … 2249 2223 } 2250 2224 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); 2256 2227 2257 2228 send(Messages::WebPageProxy::UnsignedCallback(m_selectionAnchor == Start, callbackID)); … … 2278 2249 } 2279 2250 if (lastPosition.isNotNull() && lastPosition != startPosition) 2280 contextBefore = plainTextForContext(Range::create(*frame.document(), lastPosition, startPosition) .ptr());2251 contextBefore = plainTextForContext(Range::create(*frame.document(), lastPosition, startPosition)); 2281 2252 } 2282 2253 … … 2292 2263 } 2293 2264 if (lastPosition.isNotNull() && lastPosition != endPosition) 2294 contextAfter = plainTextForContext(Range::create(*frame.document(), endPosition, lastPosition) .ptr());2265 contextAfter = plainTextForContext(Range::create(*frame.document(), endPosition, lastPosition)); 2295 2266 } 2296 2267 … … 2303 2274 auto wordRange = frame.selection().isCaret() 2304 2275 ? 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; 2309 2279 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); 2311 2281 frame.editor().insertText(newText, 0); 2312 2282 frame.editor().setIgnoreSelectionChanges(false); … … 2328 2298 if (position.isNull()) 2329 2299 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) 2333 2303 return; 2334 2304 2335 2305 // We don't want to notify the client that the selection has changed until we are done inserting the new text. 2336 2306 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); 2338 2308 frame.editor().insertText(newText, 0); 2339 2309 frame.editor().setIgnoreSelectionChanges(false); … … 2348 2318 } 2349 2319 2350 VisiblePosition position = frame.selection().selection().start(); 2351 auto range = wordRangeFromPosition(position); 2320 auto range = wordRangeFromPosition(frame.selection().selection().visibleStart()); 2352 2321 if (!range) { 2353 2322 reply({ }); … … 2355 2324 } 2356 2325 2357 auto textForRange = plainTextForContext(range .get());2326 auto textForRange = plainTextForContext(range); 2358 2327 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)) 2363 2331 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); 2366 2334 } 2367 2335 2368 2336 Vector<SelectionRect> selectionRects; 2369 2337 if (textForRange == textForAutocorrection) 2370 range->collectSelectionRects(selectionRects);2338 createLiveRange(range)->collectSelectionRects(selectionRects); 2371 2339 2372 2340 auto rootViewSelectionRects = selectionRects.map([&](const auto& selectionRect) -> FloatRect { return frame.view()->contentsToRootView(selectionRect.rect()); }); … … 2414 2382 return false; 2415 2383 2416 RefPtr<Range> range;2384 Optional<SimpleRange> range; 2417 2385 String textForRange; 2418 2386 auto originalTextWithFoldedQuoteMarks = foldQuoteMarks(originalText); 2419 2387 2420 2388 if (frame.selection().isCaret()) { 2421 VisiblePosition position = frame.selection().selection().start();2389 auto position = frame.selection().selection().visibleStart(); 2422 2390 range = wordRangeFromPosition(position); 2423 textForRange = plainTextForContext(range .get());2391 textForRange = plainTextForContext(range); 2424 2392 2425 2393 // If 'originalText' is not the same as 'textForRange' we need to move 'range' … … 2431 2399 if (position.isNull()) 2432 2400 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); 2435 2403 unsigned loopCount = 0; 2436 2404 const unsigned maxPositionsAttempts = 10; … … 2438 2406 position = position.next(); 2439 2407 if (position.isNotNull() && position >= frame.selection().selection().start()) 2440 range = nullptr;2408 range = WTF::nullopt; 2441 2409 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); 2444 2412 loopCount++; 2445 2413 } … … 2447 2415 // If 'range' does not include any text but it is not collapsed, we need to set 2448 2416 // 'range' to match the selection. Otherwise non-text nodes will be removed. 2449 range = Range::create(*frame.document(), position,position);2417 range = makeSimpleRange(position); 2450 2418 if (!range) 2451 2419 return false; … … 2453 2421 } else { 2454 2422 // Range selection. 2455 range = createLiveRange(frame.selection().selection().toNormalizedRange());2423 range = frame.selection().selection().toNormalizedRange(); 2456 2424 if (!range) 2457 2425 return false; 2458 2426 2459 textForRange = plainTextForContext(range .get());2427 textForRange = plainTextForContext(range); 2460 2428 } 2461 2429 … … 2466 2434 EAffinity affinity = DOWNSTREAM; 2467 2435 if (range && range->collapsed()) 2468 affinity = VisiblePosition( range->startPosition(), UPSTREAM).affinity();2436 affinity = VisiblePosition(createLegacyEditingPosition(range->start), UPSTREAM).affinity(); 2469 2437 2470 frame.selection().setSelectedRange(range .get(), affinity, WebCore::FrameSelection::ShouldCloseTyping::Yes);2438 frame.selection().setSelectedRange(range, affinity, WebCore::FrameSelection::ShouldCloseTyping::Yes); 2471 2439 if (correction.length()) 2472 2440 frame.editor().insertText(correction, 0, originalText.isEmpty() ? TextEventInputKeyboard : TextEventInputAutocompletion); … … 2495 2463 2496 2464 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)); 2503 2467 markedText = markedTextBefore + selectedText + markedTextAfter; 2504 2468 if (!markedText.isEmpty()) { … … 2517 2481 if (previousPosition.isNull()) 2518 2482 break; 2519 String currentWord = plainTextForContext(Range::create(*frame.document(), previousPosition, currentPosition) .ptr());2483 String currentWord = plainTextForContext(Range::create(*frame.document(), previousPosition, currentPosition)); 2520 2484 totalContextLength += currentWord.length(); 2521 2485 if (totalContextLength >= maxContextLength) … … 2524 2488 } 2525 2489 if (currentPosition.isNotNull() && currentPosition != startPosition) { 2526 contextBefore = plainTextForContext(Range::create(*frame.document(), currentPosition, startPosition) .ptr());2490 contextBefore = plainTextForContext(Range::create(*frame.document(), currentPosition, startPosition)); 2527 2491 if (atBoundaryOfGranularity(currentPosition, TextGranularity::ParagraphGranularity, SelectionDirection::Backward)) 2528 2492 contextBefore = makeString("\n "_s, contextBefore); … … 2535 2499 nextPosition = positionOfNextBoundaryOfGranularity(endPosition, TextGranularity::WordGranularity, SelectionDirection::Forward); 2536 2500 if (nextPosition.isNotNull()) 2537 contextAfter = plainTextForContext(Range::create(*frame.document(), endPosition, nextPosition) .ptr());2501 contextAfter = plainTextForContext(Range::create(*frame.document(), endPosition, nextPosition)); 2538 2502 } 2539 2503 } … … 2674 2638 linkRange->selectNodeContents(element); 2675 2639 info.textBefore = plainTextForDisplay(rangeExpandedByCharactersInDirectionAtWordBoundary(linkRange->startPosition(), 2676 dataDetectionExtendedContextLength, SelectionDirection::Backward) .get());2640 dataDetectionExtendedContextLength, SelectionDirection::Backward)); 2677 2641 info.textAfter = plainTextForDisplay(rangeExpandedByCharactersInDirectionAtWordBoundary(linkRange->endPosition(), 2678 dataDetectionExtendedContextLength, SelectionDirection::Forward) .get());2642 dataDetectionExtendedContextLength, SelectionDirection::Forward)); 2679 2643 } 2680 2644 #endif … … 4106 4070 auto newSelectionRange = CharacterRange(newSelectionLocation.unsafeGet(), newSelectionLength.unsafeGet()); 4107 4071 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); 4109 4073 completionHandler(); 4110 4074 } … … 4391 4355 return; 4392 4356 } 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); 4394 4358 completionHandler(true); 4395 4359 } -
trunk/Source/WebKitLegacy/ios/ChangeLog
r264692 r265084 1 2020-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 1 12 2020-07-19 Darin Adler <darin@apple.com> 2 13 -
trunk/Source/WebKitLegacy/ios/WebCoreSupport/WebVisiblePosition.mm
r261776 r265084 293 293 - (DOMRange *)enclosingTextUnitOfGranularity:(WebTextGranularity)granularity inDirectionIfAtBoundary:(WebTextAdjustmentDirection)direction 294 294 { 295 return kit(enclosingTextUnitOfGranularity([self _visiblePosition], toTextGranularity(granularity), toSelectionDirection(direction)) .get());295 return kit(enclosingTextUnitOfGranularity([self _visiblePosition], toTextGranularity(granularity), toSelectionDirection(direction))); 296 296 } 297 297 -
trunk/Source/WebKitLegacy/mac/ChangeLog
r265044 r265084 1 2020-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 1 28 2020-07-29 Darin Adler <darin@apple.com> 2 29 -
trunk/Source/WebKitLegacy/mac/DOM/DOMHTML.mm
r262665 r265084 45 45 #import <WebCore/RenderTextControl.h> 46 46 #import <WebCore/Settings.h> 47 #import <WebCore/SimpleRange.h> 47 48 #import <WebCore/markup.h> 48 49 … … 153 154 { 154 155 // 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()); 156 157 } 157 158 -
trunk/Source/WebKitLegacy/mac/DOM/DOMUIKitExtensions.mm
r261776 r265084 79 79 - (void)move:(UInt32)amount inDirection:(WebTextAdjustmentDirection)direction 80 80 { 81 Range *range = core(self); 81 auto& range = *core(self); 82 82 83 WebCore::FrameSelection frameSelection; 83 frameSelection. moveTo(range);84 frameSelection.setSelection(makeSimpleRange(range)); 84 85 85 86 WebCore::TextGranularity granularity = WebCore::TextGranularity::CharacterGranularity; … … 93 94 granularity = WebCore::TextGranularity::LineGranularity; 94 95 } 95 96 96 97 for (UInt32 i = 0; i < amount; i++) 97 98 frameSelection.modify(WebCore::FrameSelection::AlterationMove, (WebCore::SelectionDirection)direction, granularity); 98 99 99 100 Position start = frameSelection.selection().start().parentAnchoredEquivalent(); 100 101 Position end = frameSelection.selection().end().parentAnchoredEquivalent(); 101 102 if (start.containerNode()) 102 range ->setStart(*start.containerNode(), start.offsetInContainerNode());103 range.setStart(*start.containerNode(), start.offsetInContainerNode()); 103 104 if (end.containerNode()) 104 range ->setEnd(*end.containerNode(), end.offsetInContainerNode());105 range.setEnd(*end.containerNode(), end.offsetInContainerNode()); 105 106 } 106 107 107 108 - (void)extend:(UInt32)amount inDirection:(WebTextAdjustmentDirection)direction 108 109 { 109 Range *range = core(self); 110 auto& range = *core(self); 111 110 112 WebCore::FrameSelection frameSelection; 111 frameSelection. moveTo(range);112 113 frameSelection.setSelection(makeSimpleRange(range)); 114 113 115 for (UInt32 i = 0; i < amount; i++) 114 116 frameSelection.modify(WebCore::FrameSelection::AlterationExtend, (WebCore::SelectionDirection)direction, WebCore::TextGranularity::CharacterGranularity); 115 117 116 118 Position start = frameSelection.selection().start().parentAnchoredEquivalent(); 117 119 Position end = frameSelection.selection().end().parentAnchoredEquivalent(); 118 120 if (start.containerNode()) 119 range ->setStart(*start.containerNode(), start.offsetInContainerNode());121 range.setStart(*start.containerNode(), start.offsetInContainerNode()); 120 122 if (end.containerNode()) 121 range ->setEnd(*end.containerNode(), end.offsetInContainerNode());123 range.setEnd(*end.containerNode(), end.offsetInContainerNode()); 122 124 } 123 125 -
trunk/Source/WebKitLegacy/mac/DOM/WebDOMOperations.mm
r260854 r265084 53 53 #import <WebCore/LegacyWebArchive.h> 54 54 #import <WebCore/PlatformWheelEvent.h> 55 #import <WebCore/Range.h> 55 56 #import <WebCore/RenderElement.h> 56 57 #import <WebCore/RenderTreeAsText.h> … … 185 186 - (WebArchive *)webArchive 186 187 { 187 return [[[WebArchive alloc] _initWithCoreLegacyWebArchive:LegacyWebArchive::create( core(self))] autorelease];188 return [[[WebArchive alloc] _initWithCoreLegacyWebArchive:LegacyWebArchive::create(*core(self))] autorelease]; 188 189 } 189 190 -
trunk/Source/WebKitLegacy/mac/WebView/WebFrame.mm
r265044 r265084 94 94 #import <WebCore/PluginData.h> 95 95 #import <WebCore/PrintContext.h> 96 #import <WebCore/Range.h> 96 97 #import <WebCore/RenderLayer.h> 97 98 #import <WebCore/RenderView.h> … … 723 724 if (!range) 724 725 return NSZeroRect; 725 return _private->coreFrame->editor().firstRectForRange( *makeSimpleRange(core(range)));726 return _private->coreFrame->editor().firstRectForRange(makeSimpleRange(*core(range))); 726 727 } 727 728 … … 1480 1481 auto coreCloseTyping = closeTyping ? FrameSelection::ShouldCloseTyping::Yes : FrameSelection::ShouldCloseTyping::No; 1481 1482 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); 1483 1484 if (!closeTyping) 1484 1485 frame.editor().ensureLastEditCommandHasCurrentSelectionIfOpenForMoreTyping(); … … 1880 1881 { 1881 1882 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; 1883 1884 [self _replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace matchStyle:matchStyle]; 1884 1885 } … … 1963 1964 { 1964 1965 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; 1966 1967 [self _replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace matchStyle:YES]; 1967 1968 } … … 2272 2273 - (DOMDocumentFragment *)_documentFragmentForText:(NSString *)text 2273 2274 { 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; 2275 2277 } 2276 2278 -
trunk/Source/WebKitLegacy/mac/WebView/WebView.mm
r264692 r265084 196 196 #import <WebCore/PlatformScreen.h> 197 197 #import <WebCore/ProgressTracker.h> 198 #import <WebCore/Range.h> 198 199 #import <WebCore/RenderTheme.h> 199 200 #import <WebCore/RenderView.h> … … 7930 7931 if (!_private->page) 7931 7932 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))); 7934 7934 } 7935 7935 … … 8457 8457 return; 8458 8458 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); 8460 8460 } 8461 8461 } -
trunk/Source/WebKitLegacy/win/AccessibleTextImpl.cpp
r265044 r265084 37 37 #include <WebCore/Node.h> 38 38 #include <WebCore/Position.h> 39 #include <WebCore/Range.h> 39 40 #include <WebCore/RenderTextControl.h> 40 41 #include <WebCore/VisibleSelection.h> -
trunk/Source/WebKitLegacy/win/ChangeLog
r264811 r265084 1 2020-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 1 10 2020-07-23 Alex Christensen <achristensen@webkit.org> 2 11
Note:
See TracChangeset
for help on using the changeset viewer.