Improve range idioms and other changes to prepare the way for more reduction in live range use
https://bugs.webkit.org/show_bug.cgi?id=214882
Reviewed by Sam Weinig.
Source/WebCore:
* accessibility/AXObjectCache.cpp:
(WebCore::AccessibilityReplacedText::AccessibilityReplacedText): Call the
VisiblePosition versions of start and end instead of converting to Position
and then back to VisiblePosition.
(WebCore::AXObjectCache::rangeMatchesTextNearRange): Simplify with makeSimpleRange.
(WebCore::AXObjectCache::characterOffsetForPoint): Ditto.
* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::visiblePositionRangeForUnorderedPositions const):
Update idiom for creating VisiblePositionRange since it's just a struct now
without explicit constructors.
(WebCore::AccessibilityObject::positionOfLeftWord const): Ditto.
(WebCore::AccessibilityObject::positionOfRightWord const): Ditto.
(WebCore::AccessibilityObject::leftLineVisiblePositionRange const): Ditto.
(WebCore::AccessibilityObject::rightLineVisiblePositionRange const): Ditto.
(WebCore::AccessibilityObject::sentenceForPosition const): Ditto.
(WebCore::AccessibilityObject::paragraphForPosition const): Ditto.
(WebCore::AccessibilityObject::styleRangeForPosition const): Ditto.
(WebCore::AccessibilityObject::visiblePositionRangeForRange const): Ditto.
(WebCore::AccessibilityObject::lineRangeForPosition const): Ditto.
(WebCore::AccessibilityObject::stringForVisiblePositionRange): Ditto.
(WebCore::AccessibilityObject::lengthForVisiblePositionRange const): Ditto.
(WebCore::AccessibilityObject::nextSentenceEndPosition const): Ditto.
(WebCore::AccessibilityObject::previousSentenceStartPosition const): Ditto.
* accessibility/AccessibilityObjectInterface.h: Moved VisiblePositionRange
to VisiblePosition.h for wider use. Also removed constructors.
* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::textUnderElement const): Simplify with
makeSimpleRange.
(WebCore::AccessibilityRenderObject::linkClickPoint): Ditto.
(WebCore::AccessibilityRenderObject::clickPoint): Ditto.
(WebCore::AccessibilityRenderObject::visiblePositionRange const): Updated
for removal of VisiblePositionRange constructor.
(WebCore::AccessibilityRenderObject::visiblePositionRangeForLine const):
Remove unnecessary explicit conversion to VisiblePositionRange.
* accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(visiblePositionRangeForTextMarkerRange): Added, replacing separate functions
for start and end.
(-[WebAccessibilityObjectWrapper visiblePositionRangeForTextMarkerRange:]):
Simplify using visiblePositionRangeForTextMarkerRange.
* dom/Document.cpp: Added include of "Range.h", may not be needed right now,
but highly likely to be needed after future live range work.
* dom/Node.cpp: Removed include of "Range.h".
* dom/Position.h: Added PositionRange. This will be a more efficient
alternative to SimpleRange that can avoid computing node offets for positions
before and after anchor nodes in some cases. Not used yet.
* dom/RadioButtonGroups.cpp: Removed include of "Range.h".
* dom/Range.h: Export makeSimpleRange overload now used outside WebCore.
* dom/SimpleRange.cpp:
(WebCore::makeSimpleRange): Added overloads for ranges that consist of just
a single boundary point, so the argument does not have to be passed twice.
(WebCore::commonInclusiveAncestor): Added overload so caller can just pass
a simple range rather than passing two boundary point container nodes.
* dom/SimpleRange.h: Added makeSimpleRange overloads that take one or more
argument that can be passed to makeBoundaryPoint or actual boundary points.
* dom/StaticRange.cpp: Removed include of "Range.h".
* editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand):
Simplify with makeSimpleRange.
(WebCore::AlternativeTextController::processMarkersOnTextToBeReplacedByResult):
Ditto.
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::applyBlockStyle): Ditto.
* editing/CompositeEditCommand.cpp:
(WebCore::stringForVisiblePositionIndexRange): Updated for removal of
VisiblePositionRange constructor; also use move to reduce reference count
churn a tiny bit.
(WebCore::CompositeEditCommand::moveParagraphs): Simplify with makeSimpleRange.
* editing/DeleteSelectionCommand.cpp: Added include of "Range.h", may not be needed now,
but highly likely to be needed after future live range work.
* editing/Editing.cpp:
(WebCore::indexForVisiblePosition): Simplify using makeSimpleRange and
makeBoundaryPointBeforeNodeContents.
* editing/Editor.cpp:
(WebCore::Editor::selectedText const): Simplify using VisibleSelection::firstRange.
(WebCore::extendSelection): Simplify using makeSimpleRange.
(WebCore::Editor::contextRangeForCandidateRequest const): Ditto.
(WebCore::Editor::adjustedSelectionRange): Simplify with the new overload
of commonInclusiveAncestor.
* editing/FrameSelection.cpp:
(WebCore::FrameSelection::wordOffsetInRange const): Deleted. Moved the code
into the iOS-specific part of WebKitLegacy WebFrame.
(WebCore::FrameSelection::spaceFollowsWordInRange const): Deleted. Moved the
code into the iOS-specific part of WebKitLegacy WebFrame.
(WebCore::FrameSelection::selectionAtSentenceStart const): Merged in with
actualSelectionAtSentenceStart.
(WebCore::FrameSelection::actualSelectionAtSentenceStart const): Deleted.
* editing/FrameSelection.h: Updated for the above deletion.
* editing/TextCheckingHelper.cpp:
(WebCore::TextCheckingParagraph::offsetTo const): Simplify with makeSimpleRange.
* editing/TextManipulationController.cpp:
(WebCore::ParagraphContentIterator::ParagraphContentIterator): Simplify with
makeSimpleRange.
* editing/TypingCommand.cpp:
(WebCore::TypingCommand::postTextStateChangeNotificationForDeletion): Pass
visibleStart/End instead of converting to Position and back to VisiblePosition.
* editing/VisiblePosition.cpp:
(WebCore::makeSimpleRange): Added. Converts a VisiblePositionRange into
a SimpleRange.
* editing/VisiblePosition.h: Moved VisiblePositionRange here.
* editing/VisibleSelection.cpp:
(WebCore::VisibleSelection::firstRange const): Simplify using makeSimpleRange.
(WebCore::VisibleSelection::toNormalizedRange const): Ditto.
(WebCore::makeSearchRange): Deleted. This was confusingly named given that
it was only used in appendTrailingWhitespace.
(WebCore::VisibleSelection::appendTrailingWhitespace): Merged makeSearchRange
in here and simplified using makeSimpleRange.
* editing/VisibleSelection.h: Added conversion to VisiblePositionRange.
Previously this was implemented as a constructor for VisiblePositionRange,
but that was a layering inversion since this is built on top of VisiblePosition.
* editing/VisibleUnits.cpp:
(WebCore::distanceBetweenPositions): Simplified using makeSimpleRange.
(WebCore::charactersAroundPosition): Ditto.
(WebCore::wordRangeFromPosition): Removed an unhelpful comment.
(WebCore::closestWordBoundaryForPosition): Ditto.
* editing/cocoa/DataDetection.mm:
(WebCore::detectItem): Simplify using makeSimpleRange.
(WebCore::searchForLinkRemovingExistingDDLinks): Removed out argument
about modifying the DOM. This was used to work around a problem caused by
using live ranges. The problem no longer exists because the code does not
use live ranges any more.
(WebCore::DataDetection::detectContentInRange): Removed the workaround.
* editing/cocoa/DictionaryLookup.mm:
(WebCore::DictionaryLookup::rangeForSelection): Simplify using makeSimpleRange.
(WebCore::DictionaryLookup::rangeAtHitTestResult): Ditto.
* editing/cocoa/WebContentReaderCocoa.mm: Added include of "Range.h", may
not be needed now, but highly likely to be needed after future live range work.
* editing/ios/DictationCommandIOS.cpp: Removed include of "Range.h".
* editing/mac/DictionaryLookupLegacy.mm:
(WebCore::DictionaryLookup::rangeForSelection): Simplify using makeSimpleRange.
(WebCore::DictionaryLookup::rangeAtHitTestResult): Ditto.
* editing/mac/EditorMac.mm: Removed include of "Range.h".
* editing/markup.cpp:
(WebCore::StyledMarkupAccumulator::renderedTextRespectingRange): Simplify
using makeSimpleRange.
* editing/win/EditorWin.cpp: Added include of "Range.h", may not be needed now,
but highly likely to be needed after future live range work.
* html/shadow/mac/ImageControlsButtonElementMac.cpp: Removed include of "Range.h".
* page/DOMSelection.cpp:
(WebCore::DOMSelection::addRange): Call setSelection instead of moveTo.
No need to have two functions that do the same thing.
* page/EventHandler.cpp:
(WebCore::textDistance): Simplify using makeSimpleRange.
* page/Frame.cpp:
(WebCore::Frame::rangeForPoint): Simplify using makeSimpleRange.
* page/TextIndicator.cpp:
(WebCore::estimatedBackgroundColorForRange): Simplify using the
commonInclusiveAncestor overload that takes a range.
(WebCore::initializeIndicator): Ditto.
Source/WebKit:
* WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp:
(WKBundleNodeHandleGetRenderRect): Emptied out this unused function and added
ASSERT_NOT_REACHED. Later, we can delete this once we deal with any link-time
dependencies. I believe Safari may link with this but never calls it.
(WKBundleNodeHandleCopyVisibleRange): Ditto.
(WKBundleNodeHandleSetHTMLInputElementSpellcheckEnabled): Ditto.
(WKBundleNodeHandleGetHTMLInputElementAutoFilled): Ditto.
(WKBundleNodeHandleGetHTMLInputElementAutoFillButtonEnabled): Ditto.
(WKBundleNodeHandleGetHTMLInputElementAutoFillAvailable): Ditto.
(WKBundleNodeHandleGetHTMLInputElementAutoFillButtonBounds): Ditto.
(WKBundleNodeHandleCopyHTMLTableCellElementCellAbove): Ditto.
(WKBundleNodeHandleCopyHTMLFrameElementContentFrame): Ditto.
(WKBundleNodeHandleGetHTMLInputElementAutofilled): Ditto.
(WKBundleNodeHandleSetHTMLInputElementAutofilled): Ditto.
(WKBundleNodeHandleSetHTMLInputElementAutoFillButtonEnabled): Ditto.
* WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm:
(WebKit::TextCheckingControllerProxy::annotatedSubstringBetweenPositions):
Simplify with makeSimpleRange.
* WebProcess/WebPage/glib/WebPageGLib.cpp: Added include of "Range.h",
may not be needed right now, but highly likely to be needed after
future live range work.
* WebProcess/WebPage/ios/WebPageIOS.mm: Ditto.
(WebKit::WebPage::selectWithGesture): Simplify with makeSimpleRange.
(WebKit::WebPage::requestDocumentEditingContext): Ditto.
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::attributedSubstringForCharacterRangeAsync):
Use auto for range to prepare for possible change of type from live
range to SimpleRange.
Source/WebKitLegacy:
* WebKitLegacy.xcodeproj/project.pbxproj: Removed singly-building
DOMUIKitExtensions.mm, which also is built in a unified source file.
We don't need to build it twice.
Source/WebKitLegacy/mac:
* WebCoreSupport/WebEditorClient.mm:
(insertionPointFromCurrentSelection): Simplify with makeSimpleRange.
(WebEditorClient::requestCandidatesForSelection): Ditto.
* WebView/WebFrame.mm:
(-[WebFrame _convertToDOMRange:rangeIsRelativeTo:]): Get rid of
unnecessary construction of a range just to get an end point.
(-[WebFrame wordOffsetInRange:]): Moved logic here from VisibleSelection.
(-[WebFrame spaceFollowsWordInRange:]): Ditto.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@265044 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index c527403..e6eb5e1 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,196 @@
+2020-07-29 Darin Adler <darin@apple.com>
+
+ Improve range idioms and other changes to prepare the way for more reduction in live range use
+ https://bugs.webkit.org/show_bug.cgi?id=214882
+
+ Reviewed by Sam Weinig.
+
+ * accessibility/AXObjectCache.cpp:
+ (WebCore::AccessibilityReplacedText::AccessibilityReplacedText): Call the
+ VisiblePosition versions of start and end instead of converting to Position
+ and then back to VisiblePosition.
+ (WebCore::AXObjectCache::rangeMatchesTextNearRange): Simplify with makeSimpleRange.
+ (WebCore::AXObjectCache::characterOffsetForPoint): Ditto.
+
+ * accessibility/AccessibilityObject.cpp:
+ (WebCore::AccessibilityObject::visiblePositionRangeForUnorderedPositions const):
+ Update idiom for creating VisiblePositionRange since it's just a struct now
+ without explicit constructors.
+ (WebCore::AccessibilityObject::positionOfLeftWord const): Ditto.
+ (WebCore::AccessibilityObject::positionOfRightWord const): Ditto.
+ (WebCore::AccessibilityObject::leftLineVisiblePositionRange const): Ditto.
+ (WebCore::AccessibilityObject::rightLineVisiblePositionRange const): Ditto.
+ (WebCore::AccessibilityObject::sentenceForPosition const): Ditto.
+ (WebCore::AccessibilityObject::paragraphForPosition const): Ditto.
+ (WebCore::AccessibilityObject::styleRangeForPosition const): Ditto.
+ (WebCore::AccessibilityObject::visiblePositionRangeForRange const): Ditto.
+ (WebCore::AccessibilityObject::lineRangeForPosition const): Ditto.
+ (WebCore::AccessibilityObject::stringForVisiblePositionRange): Ditto.
+ (WebCore::AccessibilityObject::lengthForVisiblePositionRange const): Ditto.
+ (WebCore::AccessibilityObject::nextSentenceEndPosition const): Ditto.
+ (WebCore::AccessibilityObject::previousSentenceStartPosition const): Ditto.
+
+ * accessibility/AccessibilityObjectInterface.h: Moved VisiblePositionRange
+ to VisiblePosition.h for wider use. Also removed constructors.
+
+ * accessibility/AccessibilityRenderObject.cpp:
+ (WebCore::AccessibilityRenderObject::textUnderElement const): Simplify with
+ makeSimpleRange.
+ (WebCore::AccessibilityRenderObject::linkClickPoint): Ditto.
+ (WebCore::AccessibilityRenderObject::clickPoint): Ditto.
+ (WebCore::AccessibilityRenderObject::visiblePositionRange const): Updated
+ for removal of VisiblePositionRange constructor.
+ (WebCore::AccessibilityRenderObject::visiblePositionRangeForLine const):
+ Remove unnecessary explicit conversion to VisiblePositionRange.
+
+ * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+ (visiblePositionRangeForTextMarkerRange): Added, replacing separate functions
+ for start and end.
+ (-[WebAccessibilityObjectWrapper visiblePositionRangeForTextMarkerRange:]):
+ Simplify using visiblePositionRangeForTextMarkerRange.
+
+ * dom/Document.cpp: Added include of "Range.h", may not be needed right now,
+ but highly likely to be needed after future live range work.
+ * dom/Node.cpp: Removed include of "Range.h".
+
+ * dom/Position.h: Added PositionRange. This will be a more efficient
+ alternative to SimpleRange that can avoid computing node offets for positions
+ before and after anchor nodes in some cases. Not used yet.
+
+ * dom/RadioButtonGroups.cpp: Removed include of "Range.h".
+
+ * dom/Range.h: Export makeSimpleRange overload now used outside WebCore.
+
+ * dom/SimpleRange.cpp:
+ (WebCore::makeSimpleRange): Added overloads for ranges that consist of just
+ a single boundary point, so the argument does not have to be passed twice.
+ (WebCore::commonInclusiveAncestor): Added overload so caller can just pass
+ a simple range rather than passing two boundary point container nodes.
+
+ * dom/SimpleRange.h: Added makeSimpleRange overloads that take one or more
+ argument that can be passed to makeBoundaryPoint or actual boundary points.
+
+ * dom/StaticRange.cpp: Removed include of "Range.h".
+
+ * editing/AlternativeTextController.cpp:
+ (WebCore::AlternativeTextController::markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand):
+ Simplify with makeSimpleRange.
+ (WebCore::AlternativeTextController::processMarkersOnTextToBeReplacedByResult):
+ Ditto.
+ * editing/ApplyStyleCommand.cpp:
+ (WebCore::ApplyStyleCommand::applyBlockStyle): Ditto.
+
+ * editing/CompositeEditCommand.cpp:
+ (WebCore::stringForVisiblePositionIndexRange): Updated for removal of
+ VisiblePositionRange constructor; also use move to reduce reference count
+ churn a tiny bit.
+ (WebCore::CompositeEditCommand::moveParagraphs): Simplify with makeSimpleRange.
+
+ * editing/DeleteSelectionCommand.cpp: Added include of "Range.h", may not be needed now,
+ but highly likely to be needed after future live range work.
+
+ * editing/Editing.cpp:
+ (WebCore::indexForVisiblePosition): Simplify using makeSimpleRange and
+ makeBoundaryPointBeforeNodeContents.
+
+ * editing/Editor.cpp:
+ (WebCore::Editor::selectedText const): Simplify using VisibleSelection::firstRange.
+ (WebCore::extendSelection): Simplify using makeSimpleRange.
+ (WebCore::Editor::contextRangeForCandidateRequest const): Ditto.
+ (WebCore::Editor::adjustedSelectionRange): Simplify with the new overload
+ of commonInclusiveAncestor.
+
+ * editing/FrameSelection.cpp:
+ (WebCore::FrameSelection::wordOffsetInRange const): Deleted. Moved the code
+ into the iOS-specific part of WebKitLegacy WebFrame.
+ (WebCore::FrameSelection::spaceFollowsWordInRange const): Deleted. Moved the
+ code into the iOS-specific part of WebKitLegacy WebFrame.
+ (WebCore::FrameSelection::selectionAtSentenceStart const): Merged in with
+ actualSelectionAtSentenceStart.
+ (WebCore::FrameSelection::actualSelectionAtSentenceStart const): Deleted.
+ * editing/FrameSelection.h: Updated for the above deletion.
+
+ * editing/TextCheckingHelper.cpp:
+ (WebCore::TextCheckingParagraph::offsetTo const): Simplify with makeSimpleRange.
+
+ * editing/TextManipulationController.cpp:
+ (WebCore::ParagraphContentIterator::ParagraphContentIterator): Simplify with
+ makeSimpleRange.
+
+ * editing/TypingCommand.cpp:
+ (WebCore::TypingCommand::postTextStateChangeNotificationForDeletion): Pass
+ visibleStart/End instead of converting to Position and back to VisiblePosition.
+
+ * editing/VisiblePosition.cpp:
+ (WebCore::makeSimpleRange): Added. Converts a VisiblePositionRange into
+ a SimpleRange.
+ * editing/VisiblePosition.h: Moved VisiblePositionRange here.
+
+ * editing/VisibleSelection.cpp:
+ (WebCore::VisibleSelection::firstRange const): Simplify using makeSimpleRange.
+ (WebCore::VisibleSelection::toNormalizedRange const): Ditto.
+ (WebCore::makeSearchRange): Deleted. This was confusingly named given that
+ it was only used in appendTrailingWhitespace.
+ (WebCore::VisibleSelection::appendTrailingWhitespace): Merged makeSearchRange
+ in here and simplified using makeSimpleRange.
+
+ * editing/VisibleSelection.h: Added conversion to VisiblePositionRange.
+ Previously this was implemented as a constructor for VisiblePositionRange,
+ but that was a layering inversion since this is built on top of VisiblePosition.
+
+ * editing/VisibleUnits.cpp:
+ (WebCore::distanceBetweenPositions): Simplified using makeSimpleRange.
+ (WebCore::charactersAroundPosition): Ditto.
+ (WebCore::wordRangeFromPosition): Removed an unhelpful comment.
+ (WebCore::closestWordBoundaryForPosition): Ditto.
+
+ * editing/cocoa/DataDetection.mm:
+ (WebCore::detectItem): Simplify using makeSimpleRange.
+ (WebCore::searchForLinkRemovingExistingDDLinks): Removed out argument
+ about modifying the DOM. This was used to work around a problem caused by
+ using live ranges. The problem no longer exists because the code does not
+ use live ranges any more.
+ (WebCore::DataDetection::detectContentInRange): Removed the workaround.
+
+ * editing/cocoa/DictionaryLookup.mm:
+ (WebCore::DictionaryLookup::rangeForSelection): Simplify using makeSimpleRange.
+ (WebCore::DictionaryLookup::rangeAtHitTestResult): Ditto.
+
+ * editing/cocoa/WebContentReaderCocoa.mm: Added include of "Range.h", may
+ not be needed now, but highly likely to be needed after future live range work.
+
+ * editing/ios/DictationCommandIOS.cpp: Removed include of "Range.h".
+
+ * editing/mac/DictionaryLookupLegacy.mm:
+ (WebCore::DictionaryLookup::rangeForSelection): Simplify using makeSimpleRange.
+ (WebCore::DictionaryLookup::rangeAtHitTestResult): Ditto.
+
+ * editing/mac/EditorMac.mm: Removed include of "Range.h".
+
+ * editing/markup.cpp:
+ (WebCore::StyledMarkupAccumulator::renderedTextRespectingRange): Simplify
+ using makeSimpleRange.
+
+ * editing/win/EditorWin.cpp: Added include of "Range.h", may not be needed now,
+ but highly likely to be needed after future live range work.
+
+ * html/shadow/mac/ImageControlsButtonElementMac.cpp: Removed include of "Range.h".
+
+ * page/DOMSelection.cpp:
+ (WebCore::DOMSelection::addRange): Call setSelection instead of moveTo.
+ No need to have two functions that do the same thing.
+
+ * page/EventHandler.cpp:
+ (WebCore::textDistance): Simplify using makeSimpleRange.
+
+ * page/Frame.cpp:
+ (WebCore::Frame::rangeForPoint): Simplify using makeSimpleRange.
+
+ * page/TextIndicator.cpp:
+ (WebCore::estimatedBackgroundColorForRange): Simplify using the
+ commonInclusiveAncestor overload that takes a range.
+ (WebCore::initializeIndicator): Ditto.
+
2020-07-29 Adrian Perez de Castro <aperez@igalia.com>
Non-unified build fixes, late July 2020 edition
diff --git a/Source/WebCore/accessibility/AXObjectCache.cpp b/Source/WebCore/accessibility/AXObjectCache.cpp
index 2240424..beb7212 100644
--- a/Source/WebCore/accessibility/AXObjectCache.cpp
+++ b/Source/WebCore/accessibility/AXObjectCache.cpp
@@ -83,6 +83,7 @@
#include "InlineElementBox.h"
#include "MathMLElement.h"
#include "Page.h"
+#include "Range.h"
#include "RenderAttachment.h"
#include "RenderLineBreak.h"
#include "RenderListBox.h"
@@ -166,10 +167,10 @@
AccessibilityReplacedText::AccessibilityReplacedText(const VisibleSelection& selection)
{
if (AXObjectCache::accessibilityEnabled()) {
- m_replacedRange.startIndex.value = indexForVisiblePosition(selection.start(), m_replacedRange.startIndex.scope);
+ m_replacedRange.startIndex.value = indexForVisiblePosition(selection.visibleStart(), m_replacedRange.startIndex.scope);
if (selection.isRange()) {
m_replacedText = AccessibilityObject::stringForVisiblePositionRange(selection);
- m_replacedRange.endIndex.value = indexForVisiblePosition(selection.end(), m_replacedRange.endIndex.scope);
+ m_replacedRange.endIndex.value = indexForVisiblePosition(selection.visibleEnd(), m_replacedRange.endIndex.scope);
} else
m_replacedRange.endIndex = m_replacedRange.startIndex;
}
@@ -1985,12 +1986,12 @@
if (endPosition.isNull())
endPosition = lastPositionInOrAfterNode(originalRange.end.container.ptr());
- auto searchRange = SimpleRange { *makeBoundaryPoint(startPosition), *makeBoundaryPoint(endPosition) };
- if (searchRange.collapsed())
+ auto searchRange = makeSimpleRange(startPosition, endPosition);
+ if (!searchRange || searchRange->collapsed())
return WTF::nullopt;
- auto targetOffset = characterCount({ searchRange.start, originalRange.start }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
- return findClosestPlainText(searchRange, matchText, { }, targetOffset);
+ auto targetOffset = characterCount({ searchRange->start, originalRange.start }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
+ return findClosestPlainText(*searchRange, matchText, { }, targetOffset);
}
static bool isReplacedNodeOrBR(Node* node)
@@ -2880,18 +2881,18 @@
{
if (!object)
return { };
- auto boundary = makeBoundaryPoint(object->visiblePositionForPoint(point));
- if (!boundary)
+ auto range = makeSimpleRange(object->visiblePositionForPoint(point));
+ if (!range)
return { };
- return startOrEndCharacterOffsetForRange({ *boundary, *boundary }, true);
+ return startOrEndCharacterOffsetForRange(*range, true);
}
CharacterOffset AXObjectCache::characterOffsetForPoint(const IntPoint& point)
{
- auto boundary = m_document.caretPositionFromPoint(point);
- if (!boundary)
+ auto range = makeSimpleRange(m_document.caretPositionFromPoint(point));
+ if (!range)
return { };
- return startOrEndCharacterOffsetForRange({ *boundary, *boundary }, true);
+ return startOrEndCharacterOffsetForRange(*range, true);
}
CharacterOffset AXObjectCache::characterOffsetForBounds(const IntRect& rect, bool first)
diff --git a/Source/WebCore/accessibility/AccessibilityObject.cpp b/Source/WebCore/accessibility/AccessibilityObject.cpp
index 97d3088..27421a1 100644
--- a/Source/WebCore/accessibility/AccessibilityObject.cpp
+++ b/Source/WebCore/accessibility/AccessibilityObject.cpp
@@ -63,6 +63,7 @@
#include "NodeList.h"
#include "NodeTraversal.h"
#include "Page.h"
+#include "Range.h"
#include "RenderImage.h"
#include "RenderInline.h"
#include "RenderLayer.h"
@@ -980,21 +981,19 @@
endPos = visiblePos1;
}
- return VisiblePositionRange(startPos, endPos);
+ return { startPos, endPos };
}
VisiblePositionRange AccessibilityObject::positionOfLeftWord(const VisiblePosition& visiblePos) const
{
- VisiblePosition startPosition = startOfWord(visiblePos, LeftWordIfOnBoundary);
- VisiblePosition endPosition = endOfWord(startPosition);
- return VisiblePositionRange(startPosition, endPosition);
+ auto start = startOfWord(visiblePos, LeftWordIfOnBoundary);
+ return { start, endOfWord(start) };
}
VisiblePositionRange AccessibilityObject::positionOfRightWord(const VisiblePosition& visiblePos) const
{
- VisiblePosition startPosition = startOfWord(visiblePos, RightWordIfOnBoundary);
- VisiblePosition endPosition = endOfWord(startPosition);
- return VisiblePositionRange(startPosition, endPosition);
+ auto start = startOfWord(visiblePos, RightWordIfOnBoundary);
+ return { start, endOfWord(start) };
}
static VisiblePosition updateAXLineStartForVisiblePosition(const VisiblePosition& visiblePosition)
@@ -1044,8 +1043,7 @@
} else
startPosition = updateAXLineStartForVisiblePosition(startPosition);
- VisiblePosition endPosition = endOfLine(prevVisiblePos);
- return VisiblePositionRange(startPosition, endPosition);
+ return { startPosition, endOfLine(prevVisiblePos) };
}
VisiblePositionRange AccessibilityObject::rightLineVisiblePositionRange(const VisiblePosition& visiblePos) const
@@ -1078,23 +1076,21 @@
endPosition = endOfLine(nextVisiblePos);
}
- return VisiblePositionRange(startPosition, endPosition);
+ return { startPosition, endPosition };
}
VisiblePositionRange AccessibilityObject::sentenceForPosition(const VisiblePosition& visiblePos) const
{
// FIXME: FO 2 IMPLEMENT (currently returns incorrect answer)
// Related? <rdar://problem/3927736> Text selection broken in 8A336
- VisiblePosition startPosition = startOfSentence(visiblePos);
- VisiblePosition endPosition = endOfSentence(startPosition);
- return VisiblePositionRange(startPosition, endPosition);
+ auto startPosition = startOfSentence(visiblePos);
+ return { startPosition, endOfSentence(startPosition) };
}
VisiblePositionRange AccessibilityObject::paragraphForPosition(const VisiblePosition& visiblePos) const
{
- VisiblePosition startPosition = startOfParagraph(visiblePos);
- VisiblePosition endPosition = endOfParagraph(startPosition);
- return VisiblePositionRange(startPosition, endPosition);
+ auto startPosition = startOfParagraph(visiblePos);
+ return { startPosition, endOfParagraph(startPosition) };
}
static VisiblePosition startOfStyleRange(const VisiblePosition& visiblePos)
@@ -1146,9 +1142,9 @@
VisiblePositionRange AccessibilityObject::styleRangeForPosition(const VisiblePosition& visiblePos) const
{
if (visiblePos.isNull())
- return VisiblePositionRange();
+ return { };
- return VisiblePositionRange(startOfStyleRange(visiblePos), endOfStyleRange(visiblePos));
+ return { startOfStyleRange(visiblePos), endOfStyleRange(visiblePos) };
}
// NOTE: Consider providing this utility method as AX API
@@ -1156,12 +1152,11 @@
{
unsigned textLength = getLengthForTextRange();
if (range.start + range.length > textLength)
- return VisiblePositionRange();
+ return { };
- VisiblePosition startPosition = visiblePositionForIndex(range.start);
+ auto startPosition = visiblePositionForIndex(range.start);
startPosition.setAffinity(DOWNSTREAM);
- VisiblePosition endPosition = visiblePositionForIndex(range.start + range.length);
- return VisiblePositionRange(startPosition, endPosition);
+ return { startPosition, visiblePositionForIndex(range.start + range.length) };
}
Optional<SimpleRange> AccessibilityObject::rangeForPlainTextRange(const PlainTextRange& range) const
@@ -1183,9 +1178,7 @@
VisiblePositionRange AccessibilityObject::lineRangeForPosition(const VisiblePosition& visiblePosition) const
{
- VisiblePosition startPosition = startOfLine(visiblePosition);
- VisiblePosition endPosition = endOfLine(visiblePosition);
- return VisiblePositionRange(startPosition, endPosition);
+ return { startOfLine(visiblePosition), endOfLine(visiblePosition) };
}
bool AccessibilityObject::replacedNodeNeedsCharacter(Node* replacedNode)
@@ -1271,15 +1264,12 @@
String AccessibilityObject::stringForVisiblePositionRange(const VisiblePositionRange& visiblePositionRange)
{
- auto start = makeBoundaryPoint(visiblePositionRange.start);
- if (!start)
- return { };
- auto end = makeBoundaryPoint(visiblePositionRange.end);
- if (!end)
+ auto range = makeSimpleRange(visiblePositionRange);
+ if (!range)
return { };
StringBuilder builder;
- for (TextIterator it({ *start, *end }); !it.atEnd(); it.advance()) {
+ for (TextIterator it(*range); !it.atEnd(); it.advance()) {
// non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX)
if (it.text().length()) {
// Add a textual representation for list marker text.
@@ -1298,16 +1288,13 @@
{
// FIXME: Multi-byte support
- auto start = makeBoundaryPoint(visiblePositionRange.start);
- if (!start)
- return -1; // FIXME: Why not return 0?
- auto end = makeBoundaryPoint(visiblePositionRange.end);
- if (!end)
+ auto range = makeSimpleRange(visiblePositionRange);
+ if (!range)
return -1; // FIXME: Why not return 0?
// FIXME: Use characterCount instead of writing our own loop?
int length = 0;
- for (TextIterator it({ *start, *end }); !it.atEnd(); it.advance()) {
+ for (TextIterator it(*range); !it.atEnd(); it.advance()) {
// non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX)
if (it.text().length())
length += it.text().length();
@@ -1431,16 +1418,13 @@
// Make sure we move off of a sentence end.
auto nextPosition = position.next();
- auto start = makeBoundaryPoint(startOfLine(nextPosition));
- if (!start)
- return { };
- auto end = makeBoundaryPoint(endOfLine(nextPosition));
- if (!end)
+ auto range = makeSimpleRange(startOfLine(nextPosition), endOfLine(nextPosition));
+ if (!range)
return { };
// An empty line is considered a sentence. If it's skipped, then the sentence parser will not
// see this empty line. Instead, return the end position of the empty line.
- return hasAnyPlainText({ *start, *end }) ? endOfSentence(nextPosition) : nextPosition;
+ return hasAnyPlainText(*range) ? endOfSentence(nextPosition) : nextPosition;
}
VisiblePosition AccessibilityObject::previousSentenceStartPosition(const VisiblePosition& position) const
@@ -1450,15 +1434,12 @@
// Make sure we move off of a sentence start.
auto previousPosition = position.previous();
- auto start = makeBoundaryPoint(startOfLine(previousPosition));
- if (!start)
- return { };
- auto end = makeBoundaryPoint(endOfLine(previousPosition));
- if (!end)
+ auto range = makeSimpleRange(startOfLine(previousPosition), endOfLine(previousPosition));
+ if (!range)
return { };
// Treat empty line as a separate sentence.
- return hasAnyPlainText({ *start, *end }) ? startOfSentence(previousPosition) : previousPosition;
+ return hasAnyPlainText(*range) ? startOfSentence(previousPosition) : previousPosition;
}
VisiblePosition AccessibilityObject::nextParagraphEndPosition(const VisiblePosition& position) const
diff --git a/Source/WebCore/accessibility/AccessibilityObjectInterface.h b/Source/WebCore/accessibility/AccessibilityObjectInterface.h
index dc654fc..45cd8ea 100644
--- a/Source/WebCore/accessibility/AccessibilityObjectInterface.h
+++ b/Source/WebCore/accessibility/AccessibilityObjectInterface.h
@@ -430,24 +430,6 @@
Last,
};
-struct VisiblePositionRange {
- VisiblePosition start;
- VisiblePosition end;
-
- VisiblePositionRange() = default;
- VisiblePositionRange(const VisiblePosition& s, const VisiblePosition& e)
- : start(s)
- , end(e)
- { }
-
- VisiblePositionRange(const VisibleSelection& selection)
- : start(selection.start())
- , end(selection.end())
- { }
-
- bool isNull() const { return start.isNull() || end.isNull(); }
-};
-
enum class AccessibilityMathScriptObjectType { Subscript, Superscript };
enum class AccessibilityMathMultiscriptObjectType { PreSubscript, PreSuperscript, PostSubscript, PostSuperscript };
diff --git a/Source/WebCore/accessibility/AccessibilityRenderObject.cpp b/Source/WebCore/accessibility/AccessibilityRenderObject.cpp
index bb4ba0d..44862ab 100644
--- a/Source/WebCore/accessibility/AccessibilityRenderObject.cpp
+++ b/Source/WebCore/accessibility/AccessibilityRenderObject.cpp
@@ -649,12 +649,9 @@
if (firstChildRenderer && firstChildRenderer->node() && lastChildRenderer && lastChildRenderer->node()) {
// We define the start and end positions for the range as the ones right before and after
// the first and the last nodes in the DOM tree that is wrapped inside the anonymous block.
- Node* firstNodeInBlock = firstChildRenderer->node();
- Position startPosition = positionInParentBeforeNode(firstNodeInBlock);
- Position endPosition = positionInParentAfterNode(lastChildRenderer->node());
-
- nodeDocument = &firstNodeInBlock->document();
- textRange = { { *makeBoundaryPoint(startPosition), *makeBoundaryPoint(endPosition) } };
+ auto& firstNodeInBlock = *firstChildRenderer->node();
+ nodeDocument = &firstNodeInBlock.document();
+ textRange = makeSimpleRange(positionInParentBeforeNode(&firstNodeInBlock), positionInParentAfterNode(lastChildRenderer->node()));
}
}
@@ -917,7 +914,7 @@
auto start = VisiblePosition { createLegacyEditingPosition(range->start) };
auto end = nextVisiblePosition(start);
if (!end.isNull() && createLiveRange(range)->contains(end))
- return { boundsForRange({ *makeBoundaryPoint(start), *makeBoundaryPoint(end) }).center() };
+ return { boundsForRange(*makeSimpleRange(start, end)).center() };
}
return AccessibilityObject::clickPoint();
}
@@ -935,9 +932,7 @@
if (!isWebArea() || !canSetValueAttribute())
return AccessibilityObject::clickPoint();
- VisibleSelection visSelection = selection();
- VisiblePositionRange range = VisiblePositionRange(visSelection.visibleStart(), visSelection.visibleEnd());
- return boundsForVisiblePositionRange(range).center();
+ return boundsForVisiblePositionRange(selection()).center();
}
AccessibilityObject* AccessibilityRenderObject::internalLinkElement() const
@@ -1990,7 +1985,6 @@
if (!m_renderer)
return VisiblePositionRange();
- // construct VisiblePositions for start and end
Node* node = m_renderer->node();
if (!node)
return VisiblePositionRange();
@@ -2008,7 +2002,7 @@
endPos = startPos;
}
- return VisiblePositionRange(startPos, endPos);
+ return { WTFMove(startPos), WTFMove(endPos) };
}
VisiblePositionRange AccessibilityRenderObject::visiblePositionRangeForLine(unsigned lineCount) const
@@ -2038,7 +2032,7 @@
selection.setSelection(VisibleSelection(visiblePos));
selection.modify(FrameSelection::AlterationExtend, SelectionDirection::Right, TextGranularity::LineBoundary);
- return VisiblePositionRange(selection.selection().visibleStart(), selection.selection().visibleEnd());
+ return selection.selection();
}
VisiblePosition AccessibilityRenderObject::visiblePositionForIndex(int index) const
diff --git a/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm b/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm
index e44cb4b7..c361c40 100644
--- a/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm
+++ b/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm
@@ -66,6 +66,7 @@
#import "Page.h"
#import "PluginDocument.h"
#import "PluginViewBase.h"
+#import "Range.h"
#import "RenderInline.h"
#import "RenderTextControl.h"
#import "RenderView.h"
@@ -923,31 +924,27 @@
static VisiblePosition visiblePositionForTextMarker(AXObjectCache* cache, CFTypeRef textMarker)
{
ASSERT(cache);
-
if (!textMarker)
return VisiblePosition();
TextMarkerData textMarkerData;
if (!getBytesFromAXTextMarker(textMarker, &textMarkerData, sizeof(textMarkerData)))
return VisiblePosition();
-
return cache->visiblePositionForTextMarkerData(textMarkerData);
}
+static VisiblePositionRange visiblePositionRangeForTextMarkerRange(AXObjectCache* cache, id textMarkerRange)
+{
+ return {
+ visiblePositionForTextMarker(cache, (__bridge CFTypeRef)AXTextMarkerRangeStart(textMarkerRange)),
+ visiblePositionForTextMarker(cache, (__bridge CFTypeRef)AXTextMarkerRangeEnd(textMarkerRange))
+ };
+}
+
- (VisiblePosition)visiblePositionForTextMarker:(id)textMarker
{
return visiblePositionForTextMarker(self.axBackingObject->axObjectCache(), (__bridge CFTypeRef)textMarker);
}
-static VisiblePosition visiblePositionForStartOfTextMarkerRange(AXObjectCache* cache, id textMarkerRange)
-{
- return visiblePositionForTextMarker(cache, (__bridge CFTypeRef)AXTextMarkerRangeStart(textMarkerRange));
-}
-
-static VisiblePosition visiblePositionForEndOfTextMarkerRange(AXObjectCache* cache, id textMarkerRange)
-{
- return visiblePositionForTextMarker(cache, (__bridge CFTypeRef)AXTextMarkerRangeEnd(textMarkerRange));
-}
-
// When modifying attributed strings, the range can come from a source which may provide faulty information (e.g. the spell checker).
// To protect against such cases the range should be validated before adding or removing attributes.
static BOOL AXAttributedStringRangeIsValid(NSAttributedString *attrString, NSRange range)
@@ -1847,10 +1844,7 @@
- (VisiblePositionRange)visiblePositionRangeForTextMarkerRange:(id)textMarkerRange
{
- if (!textMarkerRange)
- return VisiblePositionRange();
- AXObjectCache* cache = self.axBackingObject->axObjectCache();
- return VisiblePositionRange(visiblePositionForStartOfTextMarkerRange(cache, textMarkerRange), visiblePositionForEndOfTextMarkerRange(cache, textMarkerRange));
+ return visiblePositionRangeForTextMarkerRange(self.axBackingObject->axObjectCache(), textMarkerRange);
}
- (NSArray*)renderWidgetChildren
diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp
index 3d742e7..b65fe9c 100644
--- a/Source/WebCore/dom/Document.cpp
+++ b/Source/WebCore/dom/Document.cpp
@@ -163,6 +163,7 @@
#include "ProcessingInstruction.h"
#include "PublicSuffix.h"
#include "Quirks.h"
+#include "Range.h"
#include "RealtimeMediaSourceCenter.h"
#include "RenderChildIterator.h"
#include "RenderInline.h"
diff --git a/Source/WebCore/dom/Node.cpp b/Source/WebCore/dom/Node.cpp
index 69e5a9b..c5660fc 100644
--- a/Source/WebCore/dom/Node.cpp
+++ b/Source/WebCore/dom/Node.cpp
@@ -59,7 +59,6 @@
#include "NodeRenderStyle.h"
#include "ProcessingInstruction.h"
#include "ProgressEvent.h"
-#include "Range.h"
#include "RenderBlock.h"
#include "RenderBox.h"
#include "RenderTextControl.h"
diff --git a/Source/WebCore/dom/Position.h b/Source/WebCore/dom/Position.h
index 2c2d6a2..bb99308 100644
--- a/Source/WebCore/dom/Position.h
+++ b/Source/WebCore/dom/Position.h
@@ -41,6 +41,7 @@
class Text;
struct BoundaryPoint;
+struct SimpleRange;
enum PositionMoveType {
CodePoint, // Move by a single code point.
@@ -249,6 +250,13 @@
WTF::TextStream& operator<<(WTF::TextStream&, const Position&);
+struct PositionRange {
+ Position start;
+ Position end;
+};
+
+Optional<SimpleRange> makeSimpleRange(const PositionRange&);
+
// inlines
inline Position createLegacyEditingPosition(Node* node, unsigned offset)
diff --git a/Source/WebCore/dom/RadioButtonGroups.cpp b/Source/WebCore/dom/RadioButtonGroups.cpp
index cfb55f39..7a20a5f 100644
--- a/Source/WebCore/dom/RadioButtonGroups.cpp
+++ b/Source/WebCore/dom/RadioButtonGroups.cpp
@@ -22,7 +22,6 @@
#include "RadioButtonGroups.h"
#include "HTMLInputElement.h"
-#include "Range.h"
#include <wtf/WeakHashSet.h>
#include <wtf/WeakPtr.h>
diff --git a/Source/WebCore/dom/Range.h b/Source/WebCore/dom/Range.h
index 373b2c8..d312254 100644
--- a/Source/WebCore/dom/Range.h
+++ b/Source/WebCore/dom/Range.h
@@ -176,7 +176,7 @@
WEBCORE_EXPORT bool areRangesEqual(const Range*, const Range*);
WEBCORE_EXPORT bool rangesOverlap(const Range*, const Range*);
-SimpleRange makeSimpleRange(const Range&);
+WEBCORE_EXPORT SimpleRange makeSimpleRange(const Range&);
SimpleRange makeSimpleRange(const Ref<Range>&);
WEBCORE_EXPORT Optional<SimpleRange> makeSimpleRange(const Range*);
WEBCORE_EXPORT Optional<SimpleRange> makeSimpleRange(const RefPtr<Range>&);
diff --git a/Source/WebCore/dom/SimpleRange.cpp b/Source/WebCore/dom/SimpleRange.cpp
index e755490..dbb7d34 100644
--- a/Source/WebCore/dom/SimpleRange.cpp
+++ b/Source/WebCore/dom/SimpleRange.cpp
@@ -82,6 +82,21 @@
return SimpleRange { { *parent, offset }, { *parent, offset + 1 } };
}
+Optional<SimpleRange> makeSimpleRange(const Optional<BoundaryPoint>& point)
+{
+ if (!point)
+ return WTF::nullopt;
+ return { { *point, *point } };
+}
+
+Optional<SimpleRange> makeSimpleRange(Optional<BoundaryPoint>&& point)
+{
+ if (!point)
+ return WTF::nullopt;
+ auto end = *point;
+ return { { WTFMove(*point), WTFMove(end) } };
+}
+
Optional<SimpleRange> makeSimpleRange(const Optional<BoundaryPoint>& start, const Optional<BoundaryPoint>& end)
{
if (!start || !end)
@@ -151,4 +166,9 @@
}
}
+RefPtr<Node> commonInclusiveAncestor(const SimpleRange& range)
+{
+ return commonInclusiveAncestor(range.start.container, range.end.container);
+}
+
}
diff --git a/Source/WebCore/dom/SimpleRange.h b/Source/WebCore/dom/SimpleRange.h
index 0ce0ba1..fa6af54 100644
--- a/Source/WebCore/dom/SimpleRange.h
+++ b/Source/WebCore/dom/SimpleRange.h
@@ -51,13 +51,33 @@
SimpleRange(const Ref<Range>&);
};
+SimpleRange makeSimpleRange(const BoundaryPoint&);
+SimpleRange makeSimpleRange(BoundaryPoint&&);
+SimpleRange makeSimpleRange(const BoundaryPoint&, const BoundaryPoint&);
+SimpleRange makeSimpleRange(BoundaryPoint&&, BoundaryPoint&&);
+Optional<SimpleRange> makeSimpleRange(const Optional<BoundaryPoint>&);
+WEBCORE_EXPORT Optional<SimpleRange> makeSimpleRange(Optional<BoundaryPoint>&&);
WEBCORE_EXPORT Optional<SimpleRange> makeSimpleRange(const Optional<BoundaryPoint>&, const Optional<BoundaryPoint>&);
WEBCORE_EXPORT Optional<SimpleRange> makeSimpleRange(Optional<BoundaryPoint>&&, Optional<BoundaryPoint>&&);
+inline BoundaryPoint makeBoundaryPointHelper(const BoundaryPoint& point) { return point; }
+inline BoundaryPoint makeBoundaryPointHelper(BoundaryPoint&& point) { return WTFMove(point); }
+template<typename T> auto makeBoundaryPointHelper(T&& argument) -> decltype(makeBoundaryPoint(std::forward<T>(argument)))
+{
+ return makeBoundaryPoint(std::forward<T>(argument));
+}
+
+template<typename ...T> auto makeSimpleRange(T&& ...arguments) -> decltype(makeSimpleRange(makeBoundaryPointHelper(std::forward<T>(arguments))...))
+{
+ return makeSimpleRange(makeBoundaryPointHelper(std::forward<T>(arguments))...);
+}
+
// FIXME: Would like these to have shorter names; another option is to change prefix to makeSimpleRange.
WEBCORE_EXPORT Optional<SimpleRange> makeRangeSelectingNode(Node&);
WEBCORE_EXPORT SimpleRange makeRangeSelectingNodeContents(Node&);
+RefPtr<Node> commonInclusiveAncestor(const SimpleRange&);
+
bool operator==(const SimpleRange&, const SimpleRange&);
class IntersectingNodeRange;
diff --git a/Source/WebCore/dom/StaticRange.cpp b/Source/WebCore/dom/StaticRange.cpp
index 8a4843b..7e094a9 100644
--- a/Source/WebCore/dom/StaticRange.cpp
+++ b/Source/WebCore/dom/StaticRange.cpp
@@ -27,7 +27,6 @@
#include "StaticRange.h"
#include "ContainerNode.h"
-#include "Range.h"
#include "Text.h"
namespace WebCore {
diff --git a/Source/WebCore/editing/AlternativeTextController.cpp b/Source/WebCore/editing/AlternativeTextController.cpp
index 29c497e..2b33fe5 100644
--- a/Source/WebCore/editing/AlternativeTextController.cpp
+++ b/Source/WebCore/editing/AlternativeTextController.cpp
@@ -472,15 +472,17 @@
if (endOfSelection == precedingCharacterPosition)
return;
- auto precedingCharacterRange = SimpleRange { *makeBoundaryPoint(precedingCharacterPosition), *makeBoundaryPoint(endOfSelection) };
- String string = plainText(precedingCharacterRange);
+ auto precedingCharacterRange = makeSimpleRange(precedingCharacterPosition, endOfSelection);
+ if (!precedingCharacterRange)
+ return;
+ String string = plainText(*precedingCharacterRange);
if (string.isEmpty() || !deprecatedIsEditingWhitespace(string[string.length() - 1]))
return;
// Mark this whitespace to indicate we have deleted an autocorrection following this
// whitespace. So if the user types the same original word again at this position, we
// won't autocorrect it again.
- addMarker(precedingCharacterRange, DocumentMarker::DeletedAutocorrection, m_originalStringForLastDeletedAutocorrection);
+ addMarker(*precedingCharacterRange, DocumentMarker::DeletedAutocorrection, m_originalStringForLastDeletedAutocorrection);
}
bool AlternativeTextController::processMarkersOnTextToBeReplacedByResult(const TextCheckingResult& result, const SimpleRange& rangeWithAlternative, const String& stringToBeReplaced)
@@ -498,10 +500,11 @@
if (markers.hasMarkers(rangeWithAlternative, DocumentMarker::AcceptedCandidate))
return false;
- auto beforePrecedingCharacter = createLegacyEditingPosition(rangeWithAlternative.start).previous();
- auto precedingCharacterRange = SimpleRange { *makeBoundaryPoint(beforePrecedingCharacter), rangeWithAlternative.start };
+ auto precedingCharacterRange = makeSimpleRange(createLegacyEditingPosition(rangeWithAlternative.start).previous(), rangeWithAlternative.start);
+ if (!precedingCharacterRange)
+ return false;
- for (auto& marker : markers.markersInRange(precedingCharacterRange, DocumentMarker::DeletedAutocorrection)) {
+ for (auto& marker : markers.markersInRange(*precedingCharacterRange, DocumentMarker::DeletedAutocorrection)) {
if (marker->description() == stringToBeReplaced)
return false;
}
diff --git a/Source/WebCore/editing/ApplyStyleCommand.cpp b/Source/WebCore/editing/ApplyStyleCommand.cpp
index 4f49969..5edc1e7 100644
--- a/Source/WebCore/editing/ApplyStyleCommand.cpp
+++ b/Source/WebCore/editing/ApplyStyleCommand.cpp
@@ -241,18 +241,14 @@
// Save and restore the selection endpoints using their indices in the editable root, since
// addBlockStyleIfNeeded may moveParagraphs, which can remove these endpoints.
// Calculate start and end indices from the start of the tree that they're in.
- auto scope = makeRefPtr(highestEditableRoot(visibleStart.deepEquivalent()));
- if (!scope)
+ auto scopeRoot = makeRefPtr(highestEditableRoot(visibleStart.deepEquivalent()));
+ if (!scopeRoot)
return;
- auto scopeStart = BoundaryPoint { *scope, 0 };
- auto startBoundaryPoint = makeBoundaryPoint(visibleStart.deepEquivalent().parentAnchoredEquivalent());
- auto endBoundaryPoint = makeBoundaryPoint(visibleEnd.deepEquivalent().parentAnchoredEquivalent());
- if (!startBoundaryPoint || !endBoundaryPoint)
- return;
-
- auto startIndex = characterCount({ scopeStart, *startBoundaryPoint }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
- auto endIndex = characterCount({ scopeStart, *endBoundaryPoint }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
+ auto scope = makeRangeSelectingNodeContents(*scopeRoot);
+ auto range = *makeSimpleRange(visibleStart, visibleEnd);
+ auto startIndex = characterCount({ scope.start, range.start }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
+ auto endIndex = characterCount({ scope.start, range.end }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
VisiblePosition paragraphStart(startOfParagraph(visibleStart));
VisiblePosition nextParagraphStart(endOfParagraph(paragraphStart).next());
@@ -283,8 +279,8 @@
nextParagraphStart = endOfParagraph(paragraphStart).next();
}
- auto startPosition = createLegacyEditingPosition(resolveCharacterLocation(makeRangeSelectingNodeContents(*scope), startIndex, TextIteratorEmitsCharactersBetweenAllVisiblePositions));
- auto endPosition = createLegacyEditingPosition(resolveCharacterLocation(makeRangeSelectingNodeContents(*scope), endIndex, TextIteratorEmitsCharactersBetweenAllVisiblePositions));
+ auto startPosition = createLegacyEditingPosition(resolveCharacterLocation(scope, startIndex, TextIteratorEmitsCharactersBetweenAllVisiblePositions));
+ auto endPosition = createLegacyEditingPosition(resolveCharacterLocation(scope, endIndex, TextIteratorEmitsCharactersBetweenAllVisiblePositions));
updateStartEnd(startPosition, endPosition);
}
diff --git a/Source/WebCore/editing/CompositeEditCommand.cpp b/Source/WebCore/editing/CompositeEditCommand.cpp
index 6fb12fd..1c7fd14 100644
--- a/Source/WebCore/editing/CompositeEditCommand.cpp
+++ b/Source/WebCore/editing/CompositeEditCommand.cpp
@@ -131,7 +131,7 @@
return String();
VisiblePosition start = visiblePositionForIndex(range.startIndex.value, range.startIndex.scope.get());
VisiblePosition end = visiblePositionForIndex(range.endIndex.value, range.endIndex.scope.get());
- return AccessibilityObject::stringForVisiblePositionRange(VisiblePositionRange(start, end));
+ return AccessibilityObject::stringForVisiblePositionRange({ WTFMove(start), WTFMove(end) });
}
String AccessibilityUndoReplacedText::textDeletedByUnapply()
@@ -1420,18 +1420,14 @@
startIndex = 0;
if (startInParagraph) {
- auto paragraphStart = makeBoundaryPoint(startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent());
- auto selectionStart = makeBoundaryPoint(visibleStart.deepEquivalent().parentAnchoredEquivalent());
- if (paragraphStart && selectionStart)
- startIndex = characterCount({ *paragraphStart, *selectionStart }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
+ if (auto rangeToSelectionStart = makeSimpleRange(startOfParagraphToMove, visibleStart))
+ startIndex = characterCount(*rangeToSelectionStart, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
}
endIndex = 0;
if (endInParagraph) {
- auto paragraphStart = makeBoundaryPoint(startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent());
- auto selectionEnd = makeBoundaryPoint(visibleEnd.deepEquivalent().parentAnchoredEquivalent());
- if (paragraphStart && selectionEnd)
- endIndex = characterCount({ *paragraphStart, *selectionEnd }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
+ if (auto rangeToSelectionEnd = makeSimpleRange(startOfParagraphToMove, visibleEnd))
+ endIndex = characterCount(*rangeToSelectionEnd, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
}
}
}
@@ -1504,7 +1500,7 @@
if (!editableRoot)
editableRoot = &document();
- auto destinationIndex = characterCount({ { *editableRoot, 0 }, *makeBoundaryPoint(destination.deepEquivalent().parentAnchoredEquivalent()) }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
+ auto destinationIndex = characterCount({ { *editableRoot, 0 }, *makeBoundaryPoint(destination) }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
setEndingSelection(VisibleSelection(destination, originalIsDirectional));
ASSERT(endingSelection().isCaretOrRange());
diff --git a/Source/WebCore/editing/DeleteSelectionCommand.cpp b/Source/WebCore/editing/DeleteSelectionCommand.cpp
index 870c4db..f65df44 100644
--- a/Source/WebCore/editing/DeleteSelectionCommand.cpp
+++ b/Source/WebCore/editing/DeleteSelectionCommand.cpp
@@ -39,6 +39,7 @@
#include "HTMLStyleElement.h"
#include "HTMLTableElement.h"
#include "NodeTraversal.h"
+#include "Range.h"
#include "RenderTableCell.h"
#include "RenderText.h"
#include "RenderedDocumentMarker.h"
diff --git a/Source/WebCore/editing/Editing.cpp b/Source/WebCore/editing/Editing.cpp
index a787dfa..ba6cccf 100644
--- a/Source/WebCore/editing/Editing.cpp
+++ b/Source/WebCore/editing/Editing.cpp
@@ -1104,27 +1104,15 @@
scope = &document;
}
- auto start = makeBoundaryPoint(firstPositionInNode(scope.get()));
- if (!start)
- return 0;
- auto end = makeBoundaryPoint(position.parentAnchoredEquivalent());
- if (!end)
- return 0;
-
- return characterCount({ *start, *end }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
+ auto range = *makeSimpleRange(makeBoundaryPointBeforeNodeContents(*scope), position);
+ return characterCount(range, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
}
// FIXME: Merge this function with the one above.
int indexForVisiblePosition(Node& node, const VisiblePosition& visiblePosition, bool forSelectionPreservation)
{
- auto start = makeBoundaryPoint(firstPositionInNode(&node));
- if (!start)
- return 0;
- auto end = makeBoundaryPoint(visiblePosition.deepEquivalent().parentAnchoredEquivalent());
- if (!end)
- return 0;
-
- return characterCount({ *start, *end }, forSelectionPreservation ? TextIteratorEmitsCharactersBetweenAllVisiblePositions : TextIteratorDefaultBehavior);
+ auto range = makeSimpleRange(makeBoundaryPointBeforeNodeContents(node), visiblePosition);
+ return range ? characterCount(*range, forSelectionPreservation ? TextIteratorEmitsCharactersBetweenAllVisiblePositions : TextIteratorDefaultBehavior) : 0;
}
VisiblePosition visiblePositionForPositionWithOffset(const VisiblePosition& position, int offset)
diff --git a/Source/WebCore/editing/Editor.cpp b/Source/WebCore/editing/Editor.cpp
index e87b894..77ed680 100644
--- a/Source/WebCore/editing/Editor.cpp
+++ b/Source/WebCore/editing/Editor.cpp
@@ -3259,12 +3259,8 @@
String Editor::selectedText(TextIteratorBehavior behavior) const
{
// We remove '\0' characters because they are not visibly rendered to the user.
- auto& selection = m_document.selection().selection();
- auto start = selection.start();
- auto end = selection.end();
- if (start.isNull() || start.isOrphan() || end.isNull() || end.isOrphan())
- return emptyString();
- return plainText(SimpleRange { *makeBoundaryPoint(start), *makeBoundaryPoint(end) }, behavior).replaceWithLiteral('\0', "");
+ auto range = m_document.selection().selection().firstRange();
+ return range ? plainText(*range, behavior).replaceWithLiteral('\0', "") : emptyString();
}
RefPtr<TextPlaceholderElement> Editor::insertTextPlaceholder(const IntSize& size)
@@ -3682,7 +3678,7 @@
start = start.previous(Character);
end = end.next(Character);
}
- return { *makeBoundaryPoint(start), *makeBoundaryPoint(end)};
+ return *makeSimpleRange(start, end);
}
void Editor::scanSelectionForTelephoneNumbers()
@@ -3909,11 +3905,7 @@
Optional<SimpleRange> Editor::contextRangeForCandidateRequest() const
{
auto& selection = m_document.selection().selection();
- auto start = makeBoundaryPoint(startOfParagraph(selection.visibleStart()));
- auto end = makeBoundaryPoint(endOfParagraph(selection.visibleEnd()));
- if (!start || !end)
- return WTF::nullopt;
- return { { *start, *end } };
+ return makeSimpleRange(startOfParagraph(selection.visibleStart()), endOfParagraph(selection.visibleEnd()));
}
Optional<SimpleRange> Editor::rangeForTextCheckingResult(const TextCheckingResult& result) const
@@ -4231,7 +4223,7 @@
// FIXME: Why do we need to adjust the selection to include the anchor tag it's in? Whoever wrote this code originally forgot to leave us a comment explaining the rationale.
auto range = selectedRange();
if (range) {
- if (auto enclosingAnchor = enclosingElementWithTag(firstPositionInNode(commonInclusiveAncestor(range->start.container, range->end.container).get()), HTMLNames::aTag)) {
+ if (auto enclosingAnchor = enclosingElementWithTag(firstPositionInNode(commonInclusiveAncestor(*range).get()), HTMLNames::aTag)) {
if (comparePositions(firstPositionInOrBeforeNode(range->start.container.ptr()), createLegacyEditingPosition(range->start)) >= 0)
range->start = makeBoundaryPointBeforeNodeContents(*enclosingAnchor);
}
diff --git a/Source/WebCore/editing/FrameSelection.cpp b/Source/WebCore/editing/FrameSelection.cpp
index 4a63ad8..0d28ccd 100644
--- a/Source/WebCore/editing/FrameSelection.cpp
+++ b/Source/WebCore/editing/FrameSelection.cpp
@@ -2618,34 +2618,6 @@
return visiblePosition.characterAfter();
}
-int FrameSelection::wordOffsetInRange(const Range *range) const
-{
- if (!range)
- return -1;
-
- VisibleSelection selection = m_selection;
- if (!selection.isCaret())
- return -1;
-
- // FIXME: This will only work in cases where the selection remains in
- // the same node after it is expanded. Improve to handle more complicated
- // cases.
- int result = selection.start().deprecatedEditingOffset() - range->startOffset();
- if (result < 0)
- result = 0;
- return result;
-}
-
-bool FrameSelection::spaceFollowsWordInRange(const Range *range) const
-{
- if (!range)
- return false;
- Node& node = range->endContainer();
- int endOffset = range->endOffset();
- VisiblePosition pos(createLegacyEditingPosition(&node, endOffset), VP_DEFAULT_AFFINITY);
- return isSpaceOrNewline(pos.characterAfter());
-}
-
bool FrameSelection::selectionAtDocumentStart() const
{
VisibleSelection selection = m_selection;
@@ -2660,15 +2632,6 @@
return isStartOfDocument(pos);
}
-bool FrameSelection::selectionAtSentenceStart() const
-{
- VisibleSelection selection = m_selection;
- if (selection.isNone())
- return false;
-
- return actualSelectionAtSentenceStart(selection);
-}
-
bool FrameSelection::selectionAtWordStart() const
{
VisibleSelection selection = m_selection;
@@ -2834,9 +2797,12 @@
return VisibleSelection(startVisiblePos, endVisiblePos);
}
-bool FrameSelection::actualSelectionAtSentenceStart(const VisibleSelection& sel) const
+bool FrameSelection::selectionAtSentenceStart() const
{
- Position startPos(sel.start());
+ if (m_selection.isNone())
+ return false;
+
+ Position startPos(m_selection.start());
VisiblePosition pos(createLegacyEditingPosition(startPos.deprecatedNode(), startPos.deprecatedEditingOffset()), VP_DEFAULT_AFFINITY);
if (pos.isNull())
return false;
diff --git a/Source/WebCore/editing/FrameSelection.h b/Source/WebCore/editing/FrameSelection.h
index da42e0f..211ca8b 100644
--- a/Source/WebCore/editing/FrameSelection.h
+++ b/Source/WebCore/editing/FrameSelection.h
@@ -232,8 +232,6 @@
WEBCORE_EXPORT UChar characterInRelationToCaretSelection(int amount) const;
WEBCORE_EXPORT UChar characterBeforeCaretSelection() const;
WEBCORE_EXPORT UChar characterAfterCaretSelection() const;
- WEBCORE_EXPORT int wordOffsetInRange(const Range*) const;
- WEBCORE_EXPORT bool spaceFollowsWordInRange(const Range*) const;
WEBCORE_EXPORT bool selectionAtDocumentStart() const;
WEBCORE_EXPORT bool selectionAtSentenceStart() const;
WEBCORE_EXPORT bool selectionAtWordStart() const;
@@ -333,7 +331,6 @@
bool dispatchSelectStart();
#if PLATFORM(IOS_FAMILY)
- bool actualSelectionAtSentenceStart(const VisibleSelection&) const;
Optional<SimpleRange> rangeByAlteringCurrentSelection(EAlteration, int amount) const;
#endif
diff --git a/Source/WebCore/editing/TextCheckingHelper.cpp b/Source/WebCore/editing/TextCheckingHelper.cpp
index 4b2f545..8fff4f4 100644
--- a/Source/WebCore/editing/TextCheckingHelper.cpp
+++ b/Source/WebCore/editing/TextCheckingHelper.cpp
@@ -32,6 +32,7 @@
#include "EditorClient.h"
#include "Frame.h"
#include "FrameSelection.h"
+#include "Range.h"
#include "Settings.h"
#include "TextCheckerClient.h"
#include "TextIterator.h"
@@ -160,10 +161,10 @@
ExceptionOr<uint64_t> TextCheckingParagraph::offsetTo(const Position& position) const
{
- auto end = makeBoundaryPoint(position);
- if (!end)
+ auto range = makeSimpleRange(paragraphRange().start, position);
+ if (!range)
return Exception { TypeError };
- return characterCount({ paragraphRange().start, *end });
+ return characterCount(*range);
}
bool TextCheckingParagraph::isEmpty() const
diff --git a/Source/WebCore/editing/TextManipulationController.cpp b/Source/WebCore/editing/TextManipulationController.cpp
index 969a7c3..40c46a9 100644
--- a/Source/WebCore/editing/TextManipulationController.cpp
+++ b/Source/WebCore/editing/TextManipulationController.cpp
@@ -40,7 +40,6 @@
#include "NodeRenderStyle.h"
#include "NodeTraversal.h"
#include "PseudoElement.h"
-#include "Range.h"
#include "ScriptDisallowedScope.h"
#include "Text.h"
#include "TextIterator.h"
@@ -154,7 +153,7 @@
class ParagraphContentIterator {
public:
ParagraphContentIterator(const Position& start, const Position& end)
- : m_iterator({ *makeBoundaryPoint(start), *makeBoundaryPoint(end) }, TextIteratorIgnoresStyleVisibility)
+ : m_iterator(*makeSimpleRange(start, end), TextIteratorIgnoresStyleVisibility)
, m_node(start.firstNode())
, m_pastEndNode(end.firstNode())
{
diff --git a/Source/WebCore/editing/TypingCommand.cpp b/Source/WebCore/editing/TypingCommand.cpp
index af5eb1b7..d015102 100644
--- a/Source/WebCore/editing/TypingCommand.cpp
+++ b/Source/WebCore/editing/TypingCommand.cpp
@@ -332,8 +332,8 @@
return;
postTextStateChangeNotification(AXTextEditTypeDelete, AccessibilityObject::stringForVisiblePositionRange(selection), selection.start());
VisiblePositionIndexRange range;
- range.startIndex.value = indexForVisiblePosition(selection.start(), range.startIndex.scope);
- range.endIndex.value = indexForVisiblePosition(selection.end(), range.endIndex.scope);
+ range.startIndex.value = indexForVisiblePosition(selection.visibleStart(), range.startIndex.scope);
+ range.endIndex.value = indexForVisiblePosition(selection.visibleEnd(), range.endIndex.scope);
composition()->setRangeDeletedByUnapply(range);
}
diff --git a/Source/WebCore/editing/VisiblePosition.cpp b/Source/WebCore/editing/VisiblePosition.cpp
index df3eafd..0168eb8 100644
--- a/Source/WebCore/editing/VisiblePosition.cpp
+++ b/Source/WebCore/editing/VisiblePosition.cpp
@@ -849,6 +849,11 @@
return stream;
}
+Optional<SimpleRange> makeSimpleRange(const VisiblePositionRange& range)
+{
+ return makeSimpleRange(range.start, range.end);
+}
+
} // namespace WebCore
#if ENABLE(TREE_DEBUGGING)
diff --git a/Source/WebCore/editing/VisiblePosition.h b/Source/WebCore/editing/VisiblePosition.h
index f84bcdf..91ed4cc 100644
--- a/Source/WebCore/editing/VisiblePosition.h
+++ b/Source/WebCore/editing/VisiblePosition.h
@@ -32,6 +32,8 @@
class Range;
+struct SimpleRange;
+
// VisiblePosition default affinity is downstream because
// the callers do not really care (they just want the
// deep position without regard to line position), and this
@@ -140,6 +142,15 @@
WTF::TextStream& operator<<(WTF::TextStream&, EAffinity);
WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const VisiblePosition&);
+struct VisiblePositionRange {
+ VisiblePosition start;
+ VisiblePosition end;
+
+ bool isNull() const { return start.isNull() || end.isNull(); }
+};
+
+Optional<SimpleRange> makeSimpleRange(const VisiblePositionRange&);
+
// inlines
// FIXME: This shouldn't ignore affinity.
diff --git a/Source/WebCore/editing/VisibleSelection.cpp b/Source/WebCore/editing/VisibleSelection.cpp
index 04f884b..57119db 100644
--- a/Source/WebCore/editing/VisibleSelection.cpp
+++ b/Source/WebCore/editing/VisibleSelection.cpp
@@ -30,7 +30,6 @@
#include "Editing.h"
#include "Element.h"
#include "HTMLInputElement.h"
-#include "Range.h"
#include "Settings.h"
#include "ShadowRoot.h"
#include "TextIterator.h"
@@ -132,11 +131,8 @@
{
if (isNoneOrOrphaned())
return WTF::nullopt;
- Position start = m_start.parentAnchoredEquivalent();
- Position end = m_end.parentAnchoredEquivalent();
- if (start.isNull() || start.isOrphan() || end.isNull() || end.isOrphan())
- return WTF::nullopt;
- return SimpleRange { *makeBoundaryPoint(start), *makeBoundaryPoint(end) };
+ // FIXME: Seems likely we don't need to call parentAnchoredEquivalent here.
+ return makeSimpleRange(m_start.parentAnchoredEquivalent(), m_end.parentAnchoredEquivalent());
}
Optional<SimpleRange> VisibleSelection::toNormalizedRange() const
@@ -179,18 +175,13 @@
if (comparePositions(s, e) > 0) {
// Make sure the start is before the end.
// The end can wind up before the start if collapsed whitespace is the only thing selected.
- Position tmp = s;
- s = e;
- e = tmp;
+ std::swap(s, e);
}
s = s.parentAnchoredEquivalent();
e = e.parentAnchoredEquivalent();
}
- if (s.isNull() || e.isNull())
- return WTF::nullopt;
-
- return SimpleRange { *makeBoundaryPoint(s), *makeBoundaryPoint(e) };
+ return makeSimpleRange(s, e);
}
bool VisibleSelection::expandUsingGranularity(TextGranularity granularity)
@@ -202,18 +193,6 @@
return true;
}
-static Optional<SimpleRange> makeSearchRange(const Position& position)
-{
- auto node = position.deprecatedNode();
- auto scope = deprecatedEnclosingBlockFlowElement(node);
- if (!scope)
- return { };
- auto start = makeBoundaryPoint(position.parentAnchoredEquivalent());
- if (!start)
- return { };
- return { { WTFMove(*start), makeBoundaryPointAfterNodeContents(*scope) } };
-}
-
bool VisibleSelection::isAll(EditingBoundaryCrossingRule rule) const
{
return !nonBoundaryShadowTreeRootNode() && visibleStart().previous(rule).isNull() && visibleEnd().next(rule).isNull();
@@ -221,12 +200,11 @@
void VisibleSelection::appendTrailingWhitespace()
{
- auto searchRange = makeSearchRange(m_end);
- if (!searchRange)
+ auto scope = deprecatedEnclosingBlockFlowElement(m_end.deprecatedNode());
+ if (!scope)
return;
- CharacterIterator charIt(*searchRange, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
-
+ CharacterIterator charIt(*makeSimpleRange(m_end, makeBoundaryPointAfterNodeContents(*scope)), TextIteratorEmitsCharactersBetweenAllVisiblePositions);
for (; !charIt.atEnd() && charIt.text().length(); charIt.advance(1)) {
UChar c = charIt.text()[0];
if ((!isSpaceOrNewline(c) && c != noBreakSpace) || c == '\n')
diff --git a/Source/WebCore/editing/VisibleSelection.h b/Source/WebCore/editing/VisibleSelection.h
index 3f882e1..876de18 100644
--- a/Source/WebCore/editing/VisibleSelection.h
+++ b/Source/WebCore/editing/VisibleSelection.h
@@ -72,6 +72,8 @@
VisiblePosition visibleBase() const { return VisiblePosition(m_base, isRange() ? (isBaseFirst() ? UPSTREAM : DOWNSTREAM) : affinity()); }
VisiblePosition visibleExtent() const { return VisiblePosition(m_extent, isRange() ? (isBaseFirst() ? DOWNSTREAM : UPSTREAM) : affinity()); }
+ operator VisiblePositionRange() const { return { visibleStart(), visibleEnd() }; }
+
bool isNone() const { return selectionType() == NoSelection; }
bool isCaret() const { return selectionType() == CaretSelection; }
bool isRange() const { return selectionType() == RangeSelection; }
diff --git a/Source/WebCore/editing/VisibleUnits.cpp b/Source/WebCore/editing/VisibleUnits.cpp
index 12d4cac..920d6bd 100644
--- a/Source/WebCore/editing/VisibleUnits.cpp
+++ b/Source/WebCore/editing/VisibleUnits.cpp
@@ -1905,9 +1905,7 @@
{
if (a.isNull() || b.isNull())
return 0;
- return a < b
- ? -characterCount({ *makeBoundaryPoint(a), *makeBoundaryPoint(b) })
- : characterCount({ *makeBoundaryPoint(b), *makeBoundaryPoint(a) });
+ return a < b ? -characterCount(*makeSimpleRange(a, b)) : characterCount(*makeSimpleRange(b, a));
}
void charactersAroundPosition(const VisiblePosition& position, UChar32& oneAfter, UChar32& oneBefore, UChar32& twoBefore)
@@ -1934,7 +1932,7 @@
}
if (startPosition != endPosition) {
- String characterString = plainText({ *makeBoundaryPoint(startPosition), *makeBoundaryPoint(endPosition) }).replace(noBreakSpace, ' ');
+ String characterString = plainText(*makeSimpleRange(startPosition, endPosition)).replace(noBreakSpace, ' ');
for (int i = characterString.length() - 1, index = 0; i >= 0 && index < maxCharacters; --i) {
if (!index && nextPosition.isNull())
index++;
@@ -1948,7 +1946,6 @@
RefPtr<Range> wordRangeFromPosition(const VisiblePosition& position)
{
- // The selection could be in a non visible element and we don't have a VisiblePosition.
if (position.isNull())
return nullptr;
@@ -1966,7 +1963,6 @@
do {
currentPosition = positionOfNextBoundaryOfGranularity(currentPosition, TextGranularity::WordGranularity, SelectionDirection::Backward);
} while (currentPosition.isNotNull() && !atBoundaryOfGranularity(currentPosition, TextGranularity::WordGranularity, SelectionDirection::Backward));
-
if (currentPosition.isNull())
currentPosition = positionOfNextBoundaryOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Forward);
@@ -1981,8 +1977,6 @@
VisiblePosition closestWordBoundaryForPosition(const VisiblePosition& position)
{
VisiblePosition result;
-
- // move the position at the end of the word
if (atBoundaryOfGranularity(position, TextGranularity::LineGranularity, SelectionDirection::Forward)) {
// Don't cross line boundaries.
result = position;
diff --git a/Source/WebCore/editing/cocoa/DataDetection.mm b/Source/WebCore/editing/cocoa/DataDetection.mm
index 236a3ab..6b08fd2 100644
--- a/Source/WebCore/editing/cocoa/DataDetection.mm
+++ b/Source/WebCore/editing/cocoa/DataDetection.mm
@@ -73,7 +73,7 @@
if (position.isNull())
return { };
String fullPlainTextString = plainText(contextRange);
- CFIndex hitLocation = characterCount({ contextRange.start, *makeBoundaryPoint(position) });
+ CFIndex hitLocation = characterCount(*makeSimpleRange(contextRange.start, position));
auto scanner = adoptCF(DDScannerCreate(DDScannerTypeStandard, 0, nullptr));
auto scanQuery = adoptCF(DDScanQueryCreateFromString(kCFAllocatorDefault, fullPlainTextString.createCFString().get(), CFRangeMake(0, fullPlainTextString.length())));
@@ -272,16 +272,14 @@
elementParent->removeChild(element);
}
-static bool searchForLinkRemovingExistingDDLinks(Node& startNode, Node& endNode, bool& didModifyDOM)
+static bool searchForLinkRemovingExistingDDLinks(Node& startNode, Node& endNode)
{
- didModifyDOM = false;
for (Node* node = &startNode; node; node = NodeTraversal::next(*node)) {
if (is<HTMLAnchorElement>(*node)) {
auto& anchor = downcast<HTMLAnchorElement>(*node);
if (!equalIgnoringASCIICase(anchor.attributeWithoutSynchronization(x_apple_data_detectorsAttr), "true"))
return true;
removeResultLinksFromAnchor(anchor);
- didModifyDOM = true;
}
if (node == &endNode) {
@@ -291,7 +289,6 @@
if (!equalIgnoringASCIICase(anchor.attributeWithoutSynchronization(x_apple_data_detectorsAttr), "true"))
return true;
removeResultLinksFromAnchor(anchor);
- didModifyDOM = true;
}
return false;
}
@@ -553,29 +550,12 @@
if (resultRanges.isEmpty())
continue;
- // Store the range boundaries as Position, because the DOM could change if we find
- // old data detector link.
- Vector<std::pair<Position, Position>> rangeBoundaries;
- rangeBoundaries.reserveInitialCapacity(resultRanges.size());
- for (auto& range : resultRanges)
- rangeBoundaries.uncheckedAppend({ createLegacyEditingPosition(range.start), createLegacyEditingPosition(range.end) });
-
NSString *identifier = dataDetectorStringForPath(indexPaths[resultIndex].get());
NSString *correspondingURL = constructURLStringForResult(coreResult, identifier, referenceDate, (NSTimeZone *)tz.get(), types);
- bool didModifyDOM = false;
- if (!correspondingURL || searchForLinkRemovingExistingDDLinks(resultRanges.first().start.container, resultRanges.last().end.container, didModifyDOM))
+ if (!correspondingURL || searchForLinkRemovingExistingDDLinks(resultRanges.first().start.container, resultRanges.last().end.container))
continue;
-
- if (didModifyDOM) {
- // If the DOM was modified because some old links were removed,
- // we need to recreate the ranges because they could no longer be valid.
- ASSERT(resultRanges.size() == rangeBoundaries.size());
- resultRanges.shrink(0); // Keep capacity as we are going to repopulate the Vector right away with the same number of items.
- for (auto& rangeBoundary : rangeBoundaries)
- resultRanges.uncheckedAppend({ *makeBoundaryPoint(rangeBoundary.first), *makeBoundaryPoint(rangeBoundary.second) });
- }
-
+
lastModifiedQueryOffset = queryRange.end;
BOOL shouldUseLightLinks = softLink_DataDetectorsCore_DDShouldUseLightLinksForResult(coreResult, [indexPaths[resultIndex] length] > 1);
diff --git a/Source/WebCore/editing/cocoa/DictionaryLookup.mm b/Source/WebCore/editing/cocoa/DictionaryLookup.mm
index bccb0f0..2dd05e1 100644
--- a/Source/WebCore/editing/cocoa/DictionaryLookup.mm
+++ b/Source/WebCore/editing/cocoa/DictionaryLookup.mm
@@ -279,8 +279,8 @@
if (paragraphStart.isNull() || paragraphEnd.isNull())
return WTF::nullopt;
- auto lengthToSelectionStart = characterCount({ *makeBoundaryPoint(paragraphStart), *makeBoundaryPoint(selectionStart) });
- auto selectionCharacterCount = characterCount({ *makeBoundaryPoint(selectionStart), *makeBoundaryPoint(selectionEnd) });
+ auto lengthToSelectionStart = characterCount(*makeSimpleRange(paragraphStart, selectionStart));
+ auto selectionCharacterCount = characterCount(*makeSimpleRange(selectionStart, selectionEnd));
NSRange rangeToPass = NSMakeRange(lengthToSelectionStart, selectionCharacterCount);
RefPtr<Range> fullCharacterRange = makeRange(paragraphStart, paragraphEnd);
@@ -328,15 +328,13 @@
auto selectionEnd = selection.visibleEnd();
// As context, we are going to use the surrounding paragraphs of text.
- auto paragraphStart = makeBoundaryPoint(startOfParagraph(selectionStart));
- auto paragraphEnd = makeBoundaryPoint(endOfParagraph(selectionEnd));
- if (!paragraphStart || !paragraphEnd)
+ fullCharacterRange = makeSimpleRange(startOfParagraph(selectionStart), endOfParagraph(selectionEnd));
+ if (!fullCharacterRange)
return WTF::nullopt;
- fullCharacterRange = { { *paragraphStart, *paragraphEnd } };
- selectionRange = NSMakeRange(characterCount({ *paragraphStart, *makeBoundaryPoint(selectionStart) }),
- characterCount({ *makeBoundaryPoint(selectionStart), *makeBoundaryPoint(selectionEnd) }));
- hitIndex = characterCount({ *paragraphStart, *makeBoundaryPoint(position) });
+ selectionRange = NSMakeRange(characterCount(*makeSimpleRange(fullCharacterRange->start, selectionStart)),
+ characterCount(*makeSimpleRange(selectionStart, selectionEnd)));
+ hitIndex = characterCount(*makeSimpleRange(fullCharacterRange->start, position));
} else {
VisibleSelection selectionAccountingForLineRules { position };
selectionAccountingForLineRules.expandUsingGranularity(TextGranularity::WordGranularity);
@@ -350,7 +348,7 @@
fullCharacterRange = { *expandedRange };
selectionRange = NSMakeRange(NSNotFound, 0);
- hitIndex = characterCount({ fullCharacterRange->start, *makeBoundaryPoint(position) });
+ hitIndex = characterCount(*makeSimpleRange(fullCharacterRange->start, position));
}
NSRange selectedRange = [getRVSelectionClass() revealRangeAtIndex:hitIndex selectedRanges:@[[NSValue valueWithRange:selectionRange]] shouldUpdateSelection:nil];
diff --git a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
index 51ae234..28733ee 100644
--- a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
+++ b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
@@ -53,6 +53,7 @@
#import "Page.h"
#import "PublicURLManager.h"
#import "Quirks.h"
+#import "Range.h"
#import "RenderView.h"
#import "RuntimeEnabledFeatures.h"
#import "SerializedAttachmentData.h"
diff --git a/Source/WebCore/editing/ios/DictationCommandIOS.cpp b/Source/WebCore/editing/ios/DictationCommandIOS.cpp
index 1f88104..905efb4 100644
--- a/Source/WebCore/editing/ios/DictationCommandIOS.cpp
+++ b/Source/WebCore/editing/ios/DictationCommandIOS.cpp
@@ -32,7 +32,6 @@
#include "DocumentMarkerController.h"
#include "Element.h"
#include "Position.h"
-#include "Range.h"
#include "SmartReplace.h"
#include "TextIterator.h"
#include "VisibleUnits.h"
diff --git a/Source/WebCore/editing/mac/DictionaryLookupLegacy.mm b/Source/WebCore/editing/mac/DictionaryLookupLegacy.mm
index 4f272ee..7fa356b 100644
--- a/Source/WebCore/editing/mac/DictionaryLookupLegacy.mm
+++ b/Source/WebCore/editing/mac/DictionaryLookupLegacy.mm
@@ -86,16 +86,14 @@
auto selectionEnd = selection.visibleEnd();
// As context, we are going to use the surrounding paragraphs of text.
- auto paragraphStart = makeBoundaryPoint(startOfParagraph(selectionStart));
- auto paragraphEnd = makeBoundaryPoint(endOfParagraph(selectionEnd));
- if (!paragraphStart || !paragraphEnd)
+ auto paragraphRange = makeSimpleRange(startOfParagraph(selectionStart), endOfParagraph(selectionEnd));
+ if (!paragraphRange)
return WTF::nullopt;
- auto selectionRange = SimpleRange { *makeBoundaryPoint(selectionStart), *makeBoundaryPoint(selectionEnd) };
- auto paragraphRange = SimpleRange { *paragraphStart, *paragraphEnd };
+ auto selectionRange = *makeSimpleRange(selectionStart, selectionEnd);
NSDictionary *options = nil;
- tokenRange(plainText(paragraphRange), characterRange(paragraphRange, selectionRange), &options);
+ tokenRange(plainText(*paragraphRange), characterRange(*paragraphRange, selectionRange), &options);
return { { *selectedRange, options } };
}
@@ -133,12 +131,11 @@
if (!fullCharacterRange)
return WTF::nullopt;
- auto fullCharacterStart = makeBoundaryPoint(fullCharacterRange->startPosition());
- auto positionBoundary = makeBoundaryPoint(position);
- if (!fullCharacterStart || !positionBoundary)
+ auto rangeToPosition = makeSimpleRange(fullCharacterRange->startPosition(), position);
+ if (!rangeToPosition)
return WTF::nullopt;
- NSRange rangeToPass = NSMakeRange(characterCount({ *fullCharacterStart, *positionBoundary }), 0);
+ NSRange rangeToPass = NSMakeRange(characterCount(*rangeToPosition), 0);
NSDictionary *options = nil;
auto extractedRange = tokenRange(plainText(*fullCharacterRange), rangeToPass, &options);
diff --git a/Source/WebCore/editing/mac/EditorMac.mm b/Source/WebCore/editing/mac/EditorMac.mm
index ba31c18..e7325c5 100644
--- a/Source/WebCore/editing/mac/EditorMac.mm
+++ b/Source/WebCore/editing/mac/EditorMac.mm
@@ -45,7 +45,6 @@
#import "Pasteboard.h"
#import "PasteboardStrategy.h"
#import "PlatformStrategies.h"
-#import "Range.h"
#import "RenderBlock.h"
#import "RenderImage.h"
#import "RuntimeApplicationChecks.h"
diff --git a/Source/WebCore/editing/markup.cpp b/Source/WebCore/editing/markup.cpp
index d574a49..bff1320 100644
--- a/Source/WebCore/editing/markup.cpp
+++ b/Source/WebCore/editing/markup.cpp
@@ -451,12 +451,8 @@
behavior = TextIteratorBehavesAsIfNodesFollowing;
}
- auto startBoundary = makeBoundaryPoint(start);
- auto endBoundary = makeBoundaryPoint(end);
- if (!startBoundary || !endBoundary)
- return emptyString();
-
- return plainText({ WTFMove(*startBoundary), WTFMove(*endBoundary) }, behavior);
+ auto range = makeSimpleRange(start, end);
+ return range ? plainText(*range, behavior) : emptyString();
}
String StyledMarkupAccumulator::textContentRespectingRange(const Text& text)
diff --git a/Source/WebCore/editing/win/EditorWin.cpp b/Source/WebCore/editing/win/EditorWin.cpp
index 93ddeaf..dff12c3 100644
--- a/Source/WebCore/editing/win/EditorWin.cpp
+++ b/Source/WebCore/editing/win/EditorWin.cpp
@@ -31,6 +31,7 @@
#include "Frame.h"
#include "FrameSelection.h"
#include "Pasteboard.h"
+#include "Range.h"
#include "windows.h"
namespace WebCore {
diff --git a/Source/WebCore/html/shadow/mac/ImageControlsButtonElementMac.cpp b/Source/WebCore/html/shadow/mac/ImageControlsButtonElementMac.cpp
index 6d801a6..584ec63 100644
--- a/Source/WebCore/html/shadow/mac/ImageControlsButtonElementMac.cpp
+++ b/Source/WebCore/html/shadow/mac/ImageControlsButtonElementMac.cpp
@@ -35,7 +35,6 @@
#include "FrameSelection.h"
#include "HTMLDivElement.h"
#include "Page.h"
-#include "Range.h"
#include "RenderBlockFlow.h"
#include "RenderStyle.h"
#include "RenderTheme.h"
diff --git a/Source/WebCore/page/DOMSelection.cpp b/Source/WebCore/page/DOMSelection.cpp
index df135af..59ea4fb 100644
--- a/Source/WebCore/page/DOMSelection.cpp
+++ b/Source/WebCore/page/DOMSelection.cpp
@@ -337,7 +337,7 @@
auto& selection = frame->selection();
if (selection.isNone()) {
- selection.moveTo(&range);
+ selection.setSelection(SimpleRange { range });
return;
}
@@ -356,7 +356,7 @@
selection.moveTo(range.startPosition(), normalizedRange->endPosition(), DOWNSTREAM);
} else {
// The new range contains the original range.
- selection.moveTo(&range);
+ selection.setSelection(SimpleRange { range });
}
}
} else {
@@ -366,7 +366,7 @@
result = range.compareBoundaryPoints(Range::END_TO_END, *normalizedRange);
if (!result.hasException() && result.releaseReturnValue() == -1) {
// The original range contains the new range.
- selection.moveTo(normalizedRange.get());
+ selection.setSelection(SimpleRange { *normalizedRange });
} else {
// The ranges intersect.
selection.moveTo(normalizedRange->startPosition(), range.endPosition(), DOWNSTREAM);
diff --git a/Source/WebCore/page/EventHandler.cpp b/Source/WebCore/page/EventHandler.cpp
index 5eda830..9675581 100644
--- a/Source/WebCore/page/EventHandler.cpp
+++ b/Source/WebCore/page/EventHandler.cpp
@@ -675,11 +675,10 @@
static uint64_t textDistance(const Position& start, const Position& end)
{
- auto startBoundary = makeBoundaryPoint(start);
- auto endBoundary = makeBoundaryPoint(end);
- if (!startBoundary || !endBoundary)
+ auto range = makeSimpleRange(start, end);
+ if (!range)
return 0;
- return characterCount({ *startBoundary, *endBoundary }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
+ return characterCount(*range, TextIteratorEmitsCharactersBetweenAllVisiblePositions);
}
bool EventHandler::handleMousePressEventSingleClick(const MouseEventWithHitTestResults& event)
diff --git a/Source/WebCore/page/Frame.cpp b/Source/WebCore/page/Frame.cpp
index 3551b4d..6410548 100644
--- a/Source/WebCore/page/Frame.cpp
+++ b/Source/WebCore/page/Frame.cpp
@@ -819,24 +819,19 @@
RefPtr<Range> Frame::rangeForPoint(const IntPoint& framePoint)
{
auto position = visiblePositionForPoint(framePoint);
- auto positionBoundary = makeBoundaryPoint(position);
- if (!positionBoundary)
- return nullptr;
auto containerText = position.deepEquivalent().containerText();
if (!containerText || !containerText->renderer() || containerText->renderer()->style().userSelect() == UserSelect::None)
return nullptr;
- if (auto previous = makeBoundaryPoint(position.previous())) {
- auto previousCharacterRange = SimpleRange { *previous, *positionBoundary };
- if (editor().firstRectForRange(previousCharacterRange).contains(framePoint))
- return createLiveRange(previousCharacterRange);
+ if (auto previousCharacterRange = makeSimpleRange(position.previous(), position)) {
+ if (editor().firstRectForRange(*previousCharacterRange).contains(framePoint))
+ return createLiveRange(*previousCharacterRange);
}
- if (auto next = makeBoundaryPoint(position.next())) {
- auto nextCharacterRange = SimpleRange { *positionBoundary, *next };
- if (editor().firstRectForRange(nextCharacterRange).contains(framePoint))
- return createLiveRange(nextCharacterRange);
+ if (auto nextCharacterRange = makeSimpleRange(position, position.next())) {
+ if (editor().firstRectForRange(*nextCharacterRange).contains(framePoint))
+ return createLiveRange(*nextCharacterRange);
}
return nullptr;
diff --git a/Source/WebCore/page/TextIndicator.cpp b/Source/WebCore/page/TextIndicator.cpp
index dd942e9..9e62109 100644
--- a/Source/WebCore/page/TextIndicator.cpp
+++ b/Source/WebCore/page/TextIndicator.cpp
@@ -224,7 +224,7 @@
auto estimatedBackgroundColor = frame.view() ? frame.view()->documentBackgroundColor() : Color::transparentBlack;
RenderElement* renderer = nullptr;
- auto commonAncestor = commonInclusiveAncestor(range.start.container, range.end.container);
+ auto commonAncestor = commonInclusiveAncestor(range);
while (commonAncestor) {
if (is<RenderElement>(commonAncestor->renderer())) {
renderer = downcast<RenderElement>(commonAncestor->renderer());
@@ -309,7 +309,7 @@
bool useBoundingRectAndPaintAllContentForComplexRanges = data.options.contains(TextIndicatorOption::UseBoundingRectAndPaintAllContentForComplexRanges);
if (useBoundingRectAndPaintAllContentForComplexRanges && containsOnlyWhiteSpaceText(range)) {
- if (auto* containerRenderer = commonInclusiveAncestor(range.start.container, range.end.container)->renderer()) {
+ if (auto* containerRenderer = commonInclusiveAncestor(range)->renderer()) {
data.options.add(TextIndicatorOption::PaintAllContent);
textRects.append(containerRenderer->absoluteBoundingBoxRect());
}
diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog
index c4b02b56..d73be36 100644
--- a/Source/WebKit/ChangeLog
+++ b/Source/WebKit/ChangeLog
@@ -1,3 +1,42 @@
+2020-07-29 Darin Adler <darin@apple.com>
+
+ Improve range idioms and other changes to prepare the way for more reduction in live range use
+ https://bugs.webkit.org/show_bug.cgi?id=214882
+
+ Reviewed by Sam Weinig.
+
+ * WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp:
+ (WKBundleNodeHandleGetRenderRect): Emptied out this unused function and added
+ ASSERT_NOT_REACHED. Later, we can delete this once we deal with any link-time
+ dependencies. I believe Safari may link with this but never calls it.
+ (WKBundleNodeHandleCopyVisibleRange): Ditto.
+ (WKBundleNodeHandleSetHTMLInputElementSpellcheckEnabled): Ditto.
+ (WKBundleNodeHandleGetHTMLInputElementAutoFilled): Ditto.
+ (WKBundleNodeHandleGetHTMLInputElementAutoFillButtonEnabled): Ditto.
+ (WKBundleNodeHandleGetHTMLInputElementAutoFillAvailable): Ditto.
+ (WKBundleNodeHandleGetHTMLInputElementAutoFillButtonBounds): Ditto.
+ (WKBundleNodeHandleCopyHTMLTableCellElementCellAbove): Ditto.
+ (WKBundleNodeHandleCopyHTMLFrameElementContentFrame): Ditto.
+ (WKBundleNodeHandleGetHTMLInputElementAutofilled): Ditto.
+ (WKBundleNodeHandleSetHTMLInputElementAutofilled): Ditto.
+ (WKBundleNodeHandleSetHTMLInputElementAutoFillButtonEnabled): Ditto.
+
+ * WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm:
+ (WebKit::TextCheckingControllerProxy::annotatedSubstringBetweenPositions):
+ Simplify with makeSimpleRange.
+
+ * WebProcess/WebPage/glib/WebPageGLib.cpp: Added include of "Range.h",
+ may not be needed right now, but highly likely to be needed after
+ future live range work.
+ * WebProcess/WebPage/ios/WebPageIOS.mm: Ditto.
+ (WebKit::WebPage::selectWithGesture): Simplify with makeSimpleRange.
+ (WebKit::WebPage::requestDocumentEditingContext): Ditto.
+
+ * WebProcess/WebPage/mac/WebPageMac.mm:
+ (WebKit::WebPage::attributedSubstringForCharacterRangeAsync):
+ Use auto for range to prepare for possible change of type from live
+ range to SimpleRange.
+
2020-07-29 Noam Rosenthal <noam@webkit.org>
Enable paint timing by default
diff --git a/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp b/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp
index fc7e00b..5373f3b 100644
--- a/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp
+++ b/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp
@@ -28,7 +28,6 @@
#include "WKBundleNodeHandlePrivate.h"
#include "InjectedBundleNodeHandle.h"
-#include "InjectedBundleRangeHandle.h"
#include "WKAPICast.h"
#include "WKBundleAPICast.h"
#include "WebFrame.h"
@@ -90,7 +89,8 @@
WKRect WKBundleNodeHandleGetRenderRect(WKBundleNodeHandleRef nodeHandleRef, bool* isReplaced)
{
- return WebKit::toAPI(WebKit::toImpl(nodeHandleRef)->renderRect(isReplaced));
+ ASSERT_NOT_REACHED();
+ return { };
}
WKImageRef WKBundleNodeHandleCopySnapshotWithOptions(WKBundleNodeHandleRef nodeHandleRef, WKSnapshotOptions options)
@@ -99,10 +99,10 @@
return toAPI(image.leakRef());
}
-WKBundleRangeHandleRef WKBundleNodeHandleCopyVisibleRange(WKBundleNodeHandleRef nodeHandleRef)
+WKBundleRangeHandleRef WKBundleNodeHandleCopyVisibleRange(WKBundleNodeHandleRef)
{
- RefPtr<WebKit::InjectedBundleRangeHandle> rangeHandle = WebKit::toImpl(nodeHandleRef)->visibleRange();
- return toAPI(rangeHandle.leakRef());
+ ASSERT_NOT_REACHED();
+ return nullptr;
}
WKRect WKBundleNodeHandleGetElementBounds(WKBundleNodeHandleRef elementHandleRef)
@@ -115,14 +115,15 @@
WebKit::toImpl(htmlInputElementHandleRef)->setHTMLInputElementValueForUser(WebKit::toWTFString(valueRef));
}
-void WKBundleNodeHandleSetHTMLInputElementSpellcheckEnabled(WKBundleNodeHandleRef htmlInputElementHandleRef, bool enabled)
+void WKBundleNodeHandleSetHTMLInputElementSpellcheckEnabled(WKBundleNodeHandleRef, bool)
{
- WebKit::toImpl(htmlInputElementHandleRef)->setHTMLInputElementSpellcheckEnabled(enabled);
+ // FIXME: Would put ASSERT_NOT_REACHED() here but some compilers are warning the function is "noreturn".
}
-bool WKBundleNodeHandleGetHTMLInputElementAutoFilled(WKBundleNodeHandleRef htmlInputElementHandleRef)
+bool WKBundleNodeHandleGetHTMLInputElementAutoFilled(WKBundleNodeHandleRef)
{
- return WebKit::toImpl(htmlInputElementHandleRef)->isHTMLInputElementAutoFilled();
+ ASSERT_NOT_REACHED();
+ return false;
}
void WKBundleNodeHandleSetHTMLInputElementAutoFilled(WKBundleNodeHandleRef htmlInputElementHandleRef, bool filled)
@@ -135,9 +136,10 @@
WebKit::toImpl(htmlInputElementHandleRef)->setHTMLInputElementAutoFilledAndViewable(autoFilledAndViewable);
}
-bool WKBundleNodeHandleGetHTMLInputElementAutoFillButtonEnabled(WKBundleNodeHandleRef htmlInputElementHandleRef)
+bool WKBundleNodeHandleGetHTMLInputElementAutoFillButtonEnabled(WKBundleNodeHandleRef)
{
- return WebKit::toImpl(htmlInputElementHandleRef)->isHTMLInputElementAutoFillButtonEnabled();
+ ASSERT_NOT_REACHED();
+ return false;
}
void WKBundleNodeHandleSetHTMLInputElementAutoFillButtonEnabledWithButtonType(WKBundleNodeHandleRef htmlInputElementHandleRef, WKAutoFillButtonType autoFillButtonType)
@@ -155,9 +157,10 @@
return toWKAutoFillButtonType(WebKit::toImpl(htmlInputElementHandleRef)->htmlInputElementLastAutoFillButtonType());
}
-bool WKBundleNodeHandleGetHTMLInputElementAutoFillAvailable(WKBundleNodeHandleRef htmlInputElementHandleRef)
+bool WKBundleNodeHandleGetHTMLInputElementAutoFillAvailable(WKBundleNodeHandleRef)
{
- return WebKit::toImpl(htmlInputElementHandleRef)->isAutoFillAvailable();
+ ASSERT_NOT_REACHED();
+ return false;
}
void WKBundleNodeHandleSetHTMLInputElementAutoFillAvailable(WKBundleNodeHandleRef htmlInputElementHandleRef, bool autoFillAvailable)
@@ -165,9 +168,10 @@
WebKit::toImpl(htmlInputElementHandleRef)->setAutoFillAvailable(autoFillAvailable);
}
-WKRect WKBundleNodeHandleGetHTMLInputElementAutoFillButtonBounds(WKBundleNodeHandleRef htmlInputElementHandleRef)
+WKRect WKBundleNodeHandleGetHTMLInputElementAutoFillButtonBounds(WKBundleNodeHandleRef)
{
- return WebKit::toAPI(WebKit::toImpl(htmlInputElementHandleRef)->htmlInputElementAutoFillButtonBounds());
+ ASSERT_NOT_REACHED();
+ return { };
}
bool WKBundleNodeHandleGetHTMLInputElementLastChangeWasUserEdit(WKBundleNodeHandleRef htmlInputElementHandleRef)
@@ -180,10 +184,10 @@
return WebKit::toImpl(htmlTextAreaElementHandleRef)->htmlTextAreaElementLastChangeWasUserEdit();
}
-WKBundleNodeHandleRef WKBundleNodeHandleCopyHTMLTableCellElementCellAbove(WKBundleNodeHandleRef htmlTableCellElementHandleRef)
+WKBundleNodeHandleRef WKBundleNodeHandleCopyHTMLTableCellElementCellAbove(WKBundleNodeHandleRef)
{
- RefPtr<WebKit::InjectedBundleNodeHandle> nodeHandle = WebKit::toImpl(htmlTableCellElementHandleRef)->htmlTableCellElementCellAbove();
- return toAPI(nodeHandle.leakRef());
+ ASSERT_NOT_REACHED();
+ return nullptr;
}
WKBundleFrameRef WKBundleNodeHandleCopyDocumentFrame(WKBundleNodeHandleRef documentHandleRef)
@@ -194,8 +198,8 @@
WKBundleFrameRef WKBundleNodeHandleCopyHTMLFrameElementContentFrame(WKBundleNodeHandleRef htmlFrameElementHandleRef)
{
- RefPtr<WebKit::WebFrame> frame = WebKit::toImpl(htmlFrameElementHandleRef)->htmlFrameElementContentFrame();
- return toAPI(frame.leakRef());
+ ASSERT_NOT_REACHED();
+ return nullptr;
}
WKBundleFrameRef WKBundleNodeHandleCopyHTMLIFrameElementContentFrame(WKBundleNodeHandleRef htmlIFrameElementHandleRef)
@@ -204,22 +208,18 @@
return toAPI(frame.leakRef());
}
-// Deprecated - use WKBundleNodeHandleGetHTMLInputElementAutoFilled(WKBundleNodeHandleRef).
bool WKBundleNodeHandleGetHTMLInputElementAutofilled(WKBundleNodeHandleRef htmlInputElementHandleRef)
{
- return WebKit::toImpl(htmlInputElementHandleRef)->isHTMLInputElementAutoFilled();
+ ASSERT_NOT_REACHED();
+ return false;
}
-// Deprecated - use WKBundleNodeHandleSetHTMLInputElementAutoFilled(WKBundleNodeHandleRef, bool).
-void WKBundleNodeHandleSetHTMLInputElementAutofilled(WKBundleNodeHandleRef htmlInputElementHandleRef, bool filled)
+void WKBundleNodeHandleSetHTMLInputElementAutofilled(WKBundleNodeHandleRef handle, bool enabled)
{
- WebKit::toImpl(htmlInputElementHandleRef)->setHTMLInputElementAutoFilled(filled);
+ WKBundleNodeHandleSetHTMLInputElementAutoFilled(handle, enabled);
}
-// Deprecated - use WKBundleNodeHandleSetHTMLInputElementAutoFillButtonEnabledWithButtonType(WKBundleNodeHandleRef, WKAutoFillButtonType).
-void WKBundleNodeHandleSetHTMLInputElementAutoFillButtonEnabled(WKBundleNodeHandleRef htmlInputElementHandleRef, bool enabled)
+void WKBundleNodeHandleSetHTMLInputElementAutoFillButtonEnabled(WKBundleNodeHandleRef, bool)
{
- WebCore::AutoFillButtonType autoFillButtonType = enabled ? WebCore::AutoFillButtonType::Credentials : WebCore::AutoFillButtonType::None;
-
- WebKit::toImpl(htmlInputElementHandleRef)->setHTMLInputElementAutoFillButtonEnabled(autoFillButtonType);
+ // FIXME: Would put ASSERT_NOT_REACHED() here but some compilers are warning the function is "noreturn".
}
diff --git a/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm b/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm
index 95f163c..66e3d99 100644
--- a/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm
+++ b/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm
@@ -176,15 +176,13 @@
WebCore::AttributedString TextCheckingControllerProxy::annotatedSubstringBetweenPositions(const WebCore::VisiblePosition& start, const WebCore::VisiblePosition& end)
{
- auto startBoundary = makeBoundaryPoint(start);
- auto endBoundary = makeBoundaryPoint(end);
- if (!startBoundary || !endBoundary)
+ auto entireRange = makeSimpleRange(start, end);
+ if (!entireRange)
return { };
- auto entireRange = SimpleRange { *startBoundary, *endBoundary };
auto string = adoptNS([[NSMutableAttributedString alloc] init]);
- for (TextIterator it(entireRange); !it.atEnd(); it.advance()) {
+ for (TextIterator it(*entireRange); !it.atEnd(); it.advance()) {
if (!it.text().length())
continue;
[string appendAttributedString:adoptNS([[NSAttributedString alloc] initWithString:it.text().createNSStringWithoutCopying().get()]).get()];
@@ -192,7 +190,7 @@
for (auto* marker : range.start.document().markers().markersInRange(range, DocumentMarker::PlatformTextChecking)) {
auto& data = WTF::get<DocumentMarker::PlatformTextCheckingData>(marker->data());
auto subrange = resolveCharacterRange(range, { marker->startOffset(), marker->endOffset() - marker->startOffset() });
- [string addAttribute:data.key value:data.value range:characterRange(entireRange, subrange)];
+ [string addAttribute:data.key value:data.value range:characterRange(*entireRange, subrange)];
}
}
diff --git a/Source/WebKit/WebProcess/WebPage/glib/WebPageGLib.cpp b/Source/WebKit/WebProcess/WebPage/glib/WebPageGLib.cpp
index 4692553a..8198235 100644
--- a/Source/WebKit/WebProcess/WebPage/glib/WebPageGLib.cpp
+++ b/Source/WebKit/WebProcess/WebPage/glib/WebPageGLib.cpp
@@ -39,6 +39,7 @@
#include <WebCore/FrameView.h>
#include <WebCore/HTMLInputElement.h>
#include <WebCore/HTMLTextAreaElement.h>
+#include <WebCore/Range.h>
#include <WebCore/TextIterator.h>
#include <WebCore/VisiblePosition.h>
#include <WebCore/VisibleUnits.h>
diff --git a/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm b/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
index 6b355d1..5fea2b1 100644
--- a/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
+++ b/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
@@ -114,6 +114,7 @@
#import <WebCore/PlatformMouseEvent.h>
#import <WebCore/PointerCaptureController.h>
#import <WebCore/Quirks.h>
+#import <WebCore/Range.h>
#import <WebCore/RenderBlock.h>
#import <WebCore/RenderImage.h>
#import <WebCore/RenderLayer.h>
@@ -1374,8 +1375,7 @@
OptionSet<SelectionFlags> flags;
GestureRecognizerState wkGestureState = static_cast<GestureRecognizerState>(gestureState);
switch (static_cast<GestureType>(gestureType)) {
- case GestureType::PhraseBoundary:
- {
+ case GestureType::PhraseBoundary: {
if (!frame.editor().hasComposition())
break;
auto markedRange = frame.editor().compositionRange();
@@ -4265,12 +4265,11 @@
}
auto makeString = [] (const VisiblePosition& start, const VisiblePosition& end) -> AttributedString {
- auto startBoundary = makeBoundaryPoint(start.deepEquivalent());
- auto endBoundary = makeBoundaryPoint(end.deepEquivalent());
- if (!startBoundary || !endBoundary || *startBoundary == *endBoundary)
+ auto range = makeSimpleRange(start, end);
+ if (!range || range->collapsed())
return { };
// FIXME: This should return editing-offset-compatible attributed strings if that option is requested.
- return { adoptNS([[NSAttributedString alloc] initWithString:WebCore::plainTextReplacingNoBreakSpace({ WTFMove(*startBoundary), WTFMove(*endBoundary) })]), nil };
+ return { adoptNS([[NSAttributedString alloc] initWithString:WebCore::plainTextReplacingNoBreakSpace(*range)]), nil };
};
context.contextBefore = makeString(contextBeforeStart, startOfRangeOfInterestInSelection);
@@ -4305,8 +4304,8 @@
context.textRects = characterRectsForRange(*contextRange, 0);
} else if (wantsMarkedTextRects && compositionRange) {
unsigned compositionStartOffset = 0;
- if (auto start = makeBoundaryPoint(contextBeforeStart.deepEquivalent()))
- compositionStartOffset = WebCore::plainText({ WTFMove(*start), compositionRange->start }).length();
+ if (auto range = makeSimpleRange(contextBeforeStart, compositionRange->start))
+ compositionStartOffset = characterCount(*range);
context.textRects = characterRectsForRange(*compositionRange, compositionStartOffset);
}
diff --git a/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm b/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm
index adb9923..ca1c95e 100644
--- a/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm
+++ b/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm
@@ -338,7 +338,7 @@
return;
}
- RefPtr<Range> range = EditingRange::toRange(frame, editingRange);
+ auto range = EditingRange::toRange(frame, editingRange);
if (!range) {
send(Messages::WebPageProxy::AttributedStringForCharacterRangeCallback({ }, EditingRange(), callbackID));
return;
diff --git a/Source/WebKitLegacy/ChangeLog b/Source/WebKitLegacy/ChangeLog
index e9f9dd8..28fd133 100644
--- a/Source/WebKitLegacy/ChangeLog
+++ b/Source/WebKitLegacy/ChangeLog
@@ -1,3 +1,14 @@
+2020-07-29 Darin Adler <darin@apple.com>
+
+ Improve range idioms and other changes to prepare the way for more reduction in live range use
+ https://bugs.webkit.org/show_bug.cgi?id=214882
+
+ Reviewed by Sam Weinig.
+
+ * WebKitLegacy.xcodeproj/project.pbxproj: Removed singly-building
+ DOMUIKitExtensions.mm, which also is built in a unified source file.
+ We don't need to build it twice.
+
2020-07-05 Commit Queue <commit-queue@webkit.org>
Unreviewed, reverting r263960.
diff --git a/Source/WebKitLegacy/WebKitLegacy.xcodeproj/project.pbxproj b/Source/WebKitLegacy/WebKitLegacy.xcodeproj/project.pbxproj
index 40144b5..c7c6cc2 100644
--- a/Source/WebKitLegacy/WebKitLegacy.xcodeproj/project.pbxproj
+++ b/Source/WebKitLegacy/WebKitLegacy.xcodeproj/project.pbxproj
@@ -188,7 +188,6 @@
5C7E787622D95FE20006A230 /* UnifiedSource11-mm.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C7E786922D95FE20006A230 /* UnifiedSource11-mm.mm */; };
5C97EF632342C534006020D4 /* UnifiedSource19-mm.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C97EF612342C534006020D4 /* UnifiedSource19-mm.mm */; };
5C97EF642342C534006020D4 /* UnifiedSource20-mm.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C97EF622342C534006020D4 /* UnifiedSource20-mm.mm */; };
- 5C9A4E5322DE4627007DB353 /* DOMUIKitExtensions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93D436371D57ABEE00AB85EA /* DOMUIKitExtensions.mm */; };
5C9D925A22D7E8AD008E9266 /* Sources.txt in Resources */ = {isa = PBXBuildFile; fileRef = 5C9D925822D7E8AD008E9266 /* Sources.txt */; };
5C9D925B22D7E8AD008E9266 /* SourcesCocoa.txt in Resources */ = {isa = PBXBuildFile; fileRef = 5C9D925922D7E8AD008E9266 /* SourcesCocoa.txt */; };
5C9EF2F521F061BE003BDC56 /* PageStorageSessionProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C9EF2F421F061BE003BDC56 /* PageStorageSessionProvider.h */; };
@@ -3400,7 +3399,6 @@
1A9119F61DB0470A0087D1FD /* BackForwardList.mm in Sources */,
1A60519117502A5D00BC62F5 /* BinaryPropertyList.cpp in Sources */,
B82958D4132707D0000D0E79 /* CorrectionPanel.mm in Sources */,
- 5C9A4E5322DE4627007DB353 /* DOMUIKitExtensions.mm in Sources */,
1A60519317502A5D00BC62F5 /* HistoryPropertyList.mm in Sources */,
1A8DED510EE88B8A00F25022 /* HostedNetscapePluginStream.mm in Sources */,
9364006E23996E81001E185E /* InProcessIDBServer.cpp in Sources */,
diff --git a/Source/WebKitLegacy/mac/ChangeLog b/Source/WebKitLegacy/mac/ChangeLog
index 7bc3363..19f3bd7 100644
--- a/Source/WebKitLegacy/mac/ChangeLog
+++ b/Source/WebKitLegacy/mac/ChangeLog
@@ -1,3 +1,20 @@
+2020-07-29 Darin Adler <darin@apple.com>
+
+ Improve range idioms and other changes to prepare the way for more reduction in live range use
+ https://bugs.webkit.org/show_bug.cgi?id=214882
+
+ Reviewed by Sam Weinig.
+
+ * WebCoreSupport/WebEditorClient.mm:
+ (insertionPointFromCurrentSelection): Simplify with makeSimpleRange.
+ (WebEditorClient::requestCandidatesForSelection): Ditto.
+
+ * WebView/WebFrame.mm:
+ (-[WebFrame _convertToDOMRange:rangeIsRelativeTo:]): Get rid of
+ unnecessary construction of a range just to get an end point.
+ (-[WebFrame wordOffsetInRange:]): Moved logic here from VisibleSelection.
+ (-[WebFrame spaceFollowsWordInRange:]): Ditto.
+
2020-07-23 Darin Adler <darin@apple.com>
Stop using live ranges in SpellChecker.h and TextCheckingHelper.h
diff --git a/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm b/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm
index 9935004..25ad7de 100644
--- a/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm
+++ b/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm
@@ -1025,11 +1025,10 @@
static NSUInteger insertionPointFromCurrentSelection(const VisibleSelection& selection)
{
auto selectionStart = selection.visibleStart();
- auto selectionStartBoundary = makeBoundaryPoint(selectionStart);
- auto paragraphStart = makeBoundaryPoint(startOfParagraph(selectionStart));
- if (!selectionStartBoundary || !paragraphStart)
+ auto range = makeSimpleRange(startOfParagraph(selectionStart), selectionStart);
+ if (!range)
return 0;
- return characterCount({ *paragraphStart, *selectionStartBoundary });
+ return characterCount(*range);
}
Vector<TextCheckingResult> WebEditorClient::checkTextOfParagraph(StringView string, OptionSet<TextCheckingType> coreCheckingTypes, const VisibleSelection& currentSelection)
@@ -1110,8 +1109,8 @@
m_lastSelectionForRequestedCandidates = selection;
auto selectionStart = selection.visibleStart();
- auto selectionStartOffsetInParagraph = characterCount({ *makeBoundaryPoint(startOfParagraph(selectionStart)), *makeBoundaryPoint(selectionStart) });
- auto selectionLength = characterCount({ *makeBoundaryPoint(selectionStart), *makeBoundaryPoint(selection.visibleEnd()) });
+ auto selectionStartOffsetInParagraph = characterCount(*makeSimpleRange(startOfParagraph(selectionStart), selectionStart));
+ auto selectionLength = characterCount(*makeSimpleRange(selectionStart, selection.visibleEnd()));
auto contextRangeForCandidateRequest = frame->editor().contextRangeForCandidateRequest();
String contextForCandidateReqeuest = contextRangeForCandidateRequest ? plainText(*contextRangeForCandidateRequest) : String();
diff --git a/Source/WebKitLegacy/mac/WebView/WebFrame.mm b/Source/WebKitLegacy/mac/WebView/WebFrame.mm
index b3209db..34e68f0 100644
--- a/Source/WebKitLegacy/mac/WebView/WebFrame.mm
+++ b/Source/WebKitLegacy/mac/WebView/WebFrame.mm
@@ -837,7 +837,7 @@
if (!paragraphStart)
return nullptr;
- auto scopeEnd = makeRangeSelectingNodeContents(paragraphStart->container->treeScope().rootNode()).end;
+ auto scopeEnd = makeBoundaryPointAfterNodeContents(paragraphStart->container->treeScope().rootNode());
return createLiveRange(WebCore::resolveCharacterRange({ WTFMove(*paragraphStart), WTFMove(scopeEnd) }, range));
}
@@ -1540,12 +1540,20 @@
- (int)wordOffsetInRange:(DOMRange *)range
{
- return core(self)->selection().wordOffsetInRange(core(range));
+ if (!range)
+ return -1;
+
+ auto selection = core(self)->selection().selection();
+ if (!selection.isCaret())
+ return -1;
+
+ // FIXME: This will only work in cases where the selection remains in the same node after it is expanded.
+ return std::max<int>(0, selection.start().deprecatedEditingOffset() - core(range)->startOffset());
}
- (BOOL)spaceFollowsWordInRange:(DOMRange *)range
{
- return core(self)->selection().spaceFollowsWordInRange(core(range));
+ return range && isSpaceOrNewline(WebCore::VisiblePosition(createLegacyEditingPosition(makeSimpleRange(core(range))->end)).characterAfter());
}
- (NSArray *)wordsInCurrentParagraph
diff --git a/Source/WebKitLegacy/win/AccessibleTextImpl.cpp b/Source/WebKitLegacy/win/AccessibleTextImpl.cpp
index 9f84568..3ddd00f 100644
--- a/Source/WebKitLegacy/win/AccessibleTextImpl.cpp
+++ b/Source/WebKitLegacy/win/AccessibleTextImpl.cpp
@@ -98,7 +98,10 @@
if (!node)
return E_POINTER;
- IntRect boundingRect = m_object->boundsForVisiblePositionRange(VisiblePositionRange(VisiblePosition(Position(node, offset, Position::PositionIsOffsetInAnchor)), VisiblePosition(Position(node, offset+1, Position::PositionIsOffsetInAnchor))));
+ IntRect boundingRect = m_object->boundsForVisiblePositionRange({
+ VisiblePosition(Position(node, offset, Position::PositionIsOffsetInAnchor)),
+ VisiblePosition(Position(node, offset + 1, Position::PositionIsOffsetInAnchor))
+ });
*width = boundingRect.width();
*height = boundingRect.height();
switch (coordType) {