Remove all uses of live ranges from TextIterator
https://bugs.webkit.org/show_bug.cgi?id=209723
Reviewed by Antti Koivisto.
Source/WebCore:
- Replaced TextIterator::getLocationAndLengthFromRange with a function named
characterRange that computes a CharacterRange given a scope and a range.
- Removed the overload of plainText that takes a pointer to a live range.
- Update the many callers of plainText that pass a pointer to a live range
to pass a reference instead, adding null checks as needed to preserve behavior.
- Rewrote some call sites to not use live ranges at all, or use them minimally.
* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::nextSentenceEndPosition const): Streamlined
the logic in this function, using a smaller number of null checks since the
functions we are calling also do null checks, simpler variable names and
fewer local variables. Pass a reference to a live range rather than a
pointer to the plainText function.
(WebCore::AccessibilityObject::previousSentenceStartPosition const): Ditto.
(WebCore::AccessibilityObject::nextParagraphEndPosition const): Ditto.
(WebCore::AccessibilityObject::previousParagraphStartPosition const): Ditto.
* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::textUnderElement const): Ditto.
(WebCore::boundsForRects): Converted this to a file-local function and changed
it to take a SimpleRange instead of a live range.
(WebCore::AccessibilityRenderObject::boundsForVisiblePositionRange const): Pass
a reference to a live range instead of a pointer.
(WebCore::AccessibilityRenderObject::boundsForRange const): Ditto.
* accessibility/AccessibilityRenderObject.h: Removed boundsForRects.
* accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(-[WebAccessibilityObjectWrapper _convertToNSRange:]): Rewrote to use
characterRange instead of TextIterator::getLocationAndLengthFromRange.
* dom/BoundaryPoint.h:
(WebCore::makeBoundaryPointBeforeNodeContents): Added.
* dom/Element.cpp:
(WebCore::Element::innerText): Pass a SimpleRange instead of a live range
to the plainText function.
* dom/Range.cpp:
(WebCore::Range::text const): Pass a reference to a live range instead of a
pointer to the plainText function.
* dom/SimpleRange.cpp:
(WebCore::makeBoundaryPointAfterNodeContents): Added.
(WebCore::makeRangeSelectingNodeContents): Use makeBoundaryPointBeforeNodeContents
and makeBoundaryPointAfterNodeContents
* editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::applyPendingCorrection): Pass a reference
to a live range to plainText.
(WebCore::AlternativeTextController::show): Ditto.
(WebCore::AlternativeTextController::timerFired): Ditto.
(WebCore::AlternativeTextController::handleAlternativeTextUIResult): Ditto.
(WebCore::AlternativeTextController::recordAutocorrectionResponse): Ditto. Also
take a SimpleRange argument.
(WebCore::AlternativeTextController::markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand):
Ditto.
(WebCore::AlternativeTextController::respondToMarkerAtEndOfWord):Ditto.
* editing/AlternativeTextController.h: Update for the above changes.
* editing/Editor.cpp:
(WebCore::Editor::markMisspellingsAfterTypingToWord): Pass a reference
to a live range to plainText.
(WebCore::correctSpellcheckingPreservingTextCheckingParagraph): Ditto.
Also refactor for simplicity and clarity.
(WebCore::Editor::markAndReplaceFor): Ditto.
(WebCore::Editor::changeBackToReplacedString): Ditto.
(WebCore::Editor::transpose): Ditto.
(WebCore::Editor::addRangeToKillRing): Ditto.
(WebCore::Editor::stringForCandidateRequest const): Ditto.
* editing/ReplaceRangeWithTextCommand.cpp:
(WebCore::ReplaceRangeWithTextCommand::doApply): Ditto.
* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplacementFragment::ReplacementFragment): Ditto.
* editing/SpellingCorrectionCommand.cpp:
(WebCore::SpellingCorrectionCommand::doApply): Ditto.
* editing/TextCheckingHelper.cpp:
(WebCore::TextCheckingParagraph::text const): Ditto.
(WebCore::TextCheckingHelper::findFirstMisspellingOrBadGrammar): Ditto.
* editing/TextIterator.cpp: Use more constexpr.
(WebCore::characterSubrange): Deleted. Moved the logic from this function
into the one place using it, the rangeForMatch function.
(WebCore::resolveCharacterLocation): Deleted. Moved to the header file.
(WebCore::TextIterator::getLocationAndLengthFromRange): Deleted.
(WebCore::plainText): Deleted the overload that takes a live range pointer.
(WebCore::plainTextUsingBackwardsTextIteratorForTesting): Deleted. Moved
the implementation to Internals. There's nothing special about the algorithm,
it uses SimplifiedBackwardsTextIterator in a simple way.
(WebCore::collapsedToBoundary): Deleted. Moved the code to the one place
it's used, the rangeForMatch function.
(WebCore::forEachMatch): Renamed from findPlainTextMatches and changed to
work without any use of live ranges and to use CharacterRange.
(WebCore::rangeForMatch): Rewrote to include more of the logic, removing
the collapsedToBoundary and characterSubrange functions, and to not use
any live ranges.
(WebCore::findClosestPlainText): Rewrote to tighten up the algorithm a
bit, break ties based on the search direction, and have less repetitive code.
(WebCore::findPlainText): Rewrote for clarity.
* editing/TextIterator.h: Removed the forward declaration of Range.
Removed the overload of plainText that takes a live range pointer. Moved
the functions that work with character ranges up to the top of the file,
grouped the other functions more logically. Deleted the
TextIterator::getLocationAndLengthFromRange function. Put some inline
function definitions here.
* editing/TypingCommand.cpp:
(WebCore::TypingCommand::markMisspellingsAfterTyping): Pass a reference
to a live range to plainText.
* editing/VisibleUnits.cpp:
(WebCore::charactersAroundPosition): Pass a SimpleRange to plainText
rather than a live range.
* editing/cocoa/DataDetection.mm:
(WebCore::detectItemAtPositionWithRange): Pass a reference to a live
range to plainText.
* editing/cocoa/DictionaryLookup.mm:
(WebCore::DictionaryLookup::rangeForSelection): Ditto.
* editing/cocoa/HTMLConverter.h: Tweaked #if a bit.
* editing/mac/DictionaryLookupLegacy.mm:
(WebCore::DictionaryLookup::rangeForSelection): Pass a reference to a
live range to plainText. Also rewrote logic to use mostly SimpleRange.
(WebCore::DictionaryLookup::rangeAtHitTestResult): Ditto.
* editing/markup.cpp:
(WebCore::StyledMarkupAccumulator::renderedTextRespectingRange): Ditto.
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::handleBeforeTextInsertedEvent const): Ditto.
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::contextMenuItemSelected): Ditto.
* page/DOMSelection.cpp:
(WebCore::DOMSelection::toString): Ditto.
* page/Page.cpp:
(WebCore::Page::replaceRangesWithText): Rewrote to replaces use of
TextIterator::getLocationAndLengthFromRange with characterRange.
* page/ios/FrameIOS.mm:
(WebCore::Frame::interpretationsForCurrentRoot const): Pass a
reference to a live range to plainText.
* testing/Internals.cpp:
(WebCore::Internals::locationFromRange): Use characterRange.
(WebCore::Internals::lengthFromRange): Ditto.
(WebCore::Internals::rangeAsTextUsingBackwardsTextIterator):
USe SimplifiedBackwardsTextIterator directly since we no longer have
the function plainTextUsingBackwardsTextIteratorForTesting.
Source/WebKit:
* Shared/EditingRange.cpp:
(WebKit::EditingRange::fromRange): Use characterRange.
* Shared/mac/AttributedString.h: Added a constructor that takes rvalue
references so we can initialize this slightly more efficiently.
* Shared/mac/AttributedString.mm:
(IPC::ArgumentCoder<WebKit::AttributedString>::decode): Pass rvalue
references when creating an AttributedString.
* UIProcess/mac/TextCheckerMac.mm:
(WebKit::TextChecker::updateSpellingUIWithGrammarString): Simplify the
code to remove some local variables that weren't helpful.
* WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.h: Made the
annotatedSubstringBetweenPositions a static member function. Also used
const& argument types to cut down on reference count churn a bit.
* WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm:
(WebKit::TextCheckingControllerProxy::rangeAndOffsetRelativeToSelection):
Streamlined and made this use characterCount instead of
TextIterator::getLocationAndLengthFromRange.
(WebKit::TextCheckingControllerProxy::replaceRelativeToSelection): Tweaked
the argument type.
(WebKit::TextCheckingControllerProxy::removeAnnotationRelativeToSelection):
Ditto. Also removed some unnecessary use of NSString.
(WebKit::TextCheckingControllerProxy::annotatedSubstringBetweenPositions):
Rewrote to no longer use live ranges.
* WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
(WebKit::WebPage::getContentsAsAttributedString): Use construction and
rvalue references to tigten things up a bit.
* WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::contentsAsString const): Use a SimpleRange instead of
a live range to pass to plainText.
* WebProcess/WebPage/glib/WebPageGLib.cpp:
(WebKit::WebPage::getPlatformEditorState const): Pass references to
live ranges to plainText.
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::updateSelectionWithDelta): Rewrote to minimize use of
live ranges.
(WebKit::WebPage::requestDocumentEditingContext): Ditto.
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::getPlatformEditorState const): Pass reference to
a live range to plainText.
Source/WebKitLegacy/mac:
* WebCoreSupport/WebEditorClient.mm:
(WebEditorClient::updateSpellingUIWithGrammarString): Remove some unnecessary
use of local variabels for NSString.
(WebEditorClient::requestCandidatesForSelection): Pass a reference to a live
range to plainText.
* WebView/WebFrame.mm:
(-[WebFrame _stringForRange:]): Ditto.
(-[WebFrame _convertToNSRange:]): Use characterRange instead of
TextIterator::getLocationAndLengthFromRange.
Source/WebKitLegacy/win:
* WebFrame.cpp:
(WebFrame::string): Use a SimpleRange instead of a live range
to call plainText.
* WebView.cpp:
(WebView::selectedRangeForTesting): Use a SimpleRange instead
of a live range to call characterRange instead of
TextIterator::getLocationAndLengthFromRange.
LayoutTests:
* editing/text-iterator/find-string-on-flat-tree-expected.txt:
* editing/text-iterator/find-string-on-flat-tree.html:
Updated test for a progress where we properly find strings across a shadow boundary.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@259401 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/editing/TypingCommand.cpp b/Source/WebCore/editing/TypingCommand.cpp
index c4d80fb..5a6c53c 100644
--- a/Source/WebCore/editing/TypingCommand.cpp
+++ b/Source/WebCore/editing/TypingCommand.cpp
@@ -465,7 +465,7 @@
RefPtr<Range> range = makeRange(p1, p2);
String strippedPreviousWord;
if (range && (commandType == TypingCommand::InsertText || commandType == TypingCommand::InsertLineBreak || commandType == TypingCommand::InsertParagraphSeparator || commandType == TypingCommand::InsertParagraphSeparatorInQuotedContent))
- strippedPreviousWord = plainText(range.get()).stripWhiteSpace();
+ strippedPreviousWord = plainText(*range).stripWhiteSpace();
frame.editor().markMisspellingsAfterTypingToWord(p1, endingSelection(), !strippedPreviousWord.isEmpty());
} else if (commandType == TypingCommand::InsertText)
frame.editor().startAlternativeTextUITimer();