Changeset 265044 in webkit
- Timestamp:
- Jul 29, 2020 9:36:40 AM (4 years ago)
- Location:
- trunk/Source
- Files:
-
- 55 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r265039 r265044 1 2020-07-29 Darin Adler <darin@apple.com> 2 3 Improve range idioms and other changes to prepare the way for more reduction in live range use 4 https://bugs.webkit.org/show_bug.cgi?id=214882 5 6 Reviewed by Sam Weinig. 7 8 * accessibility/AXObjectCache.cpp: 9 (WebCore::AccessibilityReplacedText::AccessibilityReplacedText): Call the 10 VisiblePosition versions of start and end instead of converting to Position 11 and then back to VisiblePosition. 12 (WebCore::AXObjectCache::rangeMatchesTextNearRange): Simplify with makeSimpleRange. 13 (WebCore::AXObjectCache::characterOffsetForPoint): Ditto. 14 15 * accessibility/AccessibilityObject.cpp: 16 (WebCore::AccessibilityObject::visiblePositionRangeForUnorderedPositions const): 17 Update idiom for creating VisiblePositionRange since it's just a struct now 18 without explicit constructors. 19 (WebCore::AccessibilityObject::positionOfLeftWord const): Ditto. 20 (WebCore::AccessibilityObject::positionOfRightWord const): Ditto. 21 (WebCore::AccessibilityObject::leftLineVisiblePositionRange const): Ditto. 22 (WebCore::AccessibilityObject::rightLineVisiblePositionRange const): Ditto. 23 (WebCore::AccessibilityObject::sentenceForPosition const): Ditto. 24 (WebCore::AccessibilityObject::paragraphForPosition const): Ditto. 25 (WebCore::AccessibilityObject::styleRangeForPosition const): Ditto. 26 (WebCore::AccessibilityObject::visiblePositionRangeForRange const): Ditto. 27 (WebCore::AccessibilityObject::lineRangeForPosition const): Ditto. 28 (WebCore::AccessibilityObject::stringForVisiblePositionRange): Ditto. 29 (WebCore::AccessibilityObject::lengthForVisiblePositionRange const): Ditto. 30 (WebCore::AccessibilityObject::nextSentenceEndPosition const): Ditto. 31 (WebCore::AccessibilityObject::previousSentenceStartPosition const): Ditto. 32 33 * accessibility/AccessibilityObjectInterface.h: Moved VisiblePositionRange 34 to VisiblePosition.h for wider use. Also removed constructors. 35 36 * accessibility/AccessibilityRenderObject.cpp: 37 (WebCore::AccessibilityRenderObject::textUnderElement const): Simplify with 38 makeSimpleRange. 39 (WebCore::AccessibilityRenderObject::linkClickPoint): Ditto. 40 (WebCore::AccessibilityRenderObject::clickPoint): Ditto. 41 (WebCore::AccessibilityRenderObject::visiblePositionRange const): Updated 42 for removal of VisiblePositionRange constructor. 43 (WebCore::AccessibilityRenderObject::visiblePositionRangeForLine const): 44 Remove unnecessary explicit conversion to VisiblePositionRange. 45 46 * accessibility/mac/WebAccessibilityObjectWrapperMac.mm: 47 (visiblePositionRangeForTextMarkerRange): Added, replacing separate functions 48 for start and end. 49 (-[WebAccessibilityObjectWrapper visiblePositionRangeForTextMarkerRange:]): 50 Simplify using visiblePositionRangeForTextMarkerRange. 51 52 * dom/Document.cpp: Added include of "Range.h", may not be needed right now, 53 but highly likely to be needed after future live range work. 54 * dom/Node.cpp: Removed include of "Range.h". 55 56 * dom/Position.h: Added PositionRange. This will be a more efficient 57 alternative to SimpleRange that can avoid computing node offets for positions 58 before and after anchor nodes in some cases. Not used yet. 59 60 * dom/RadioButtonGroups.cpp: Removed include of "Range.h". 61 62 * dom/Range.h: Export makeSimpleRange overload now used outside WebCore. 63 64 * dom/SimpleRange.cpp: 65 (WebCore::makeSimpleRange): Added overloads for ranges that consist of just 66 a single boundary point, so the argument does not have to be passed twice. 67 (WebCore::commonInclusiveAncestor): Added overload so caller can just pass 68 a simple range rather than passing two boundary point container nodes. 69 70 * dom/SimpleRange.h: Added makeSimpleRange overloads that take one or more 71 argument that can be passed to makeBoundaryPoint or actual boundary points. 72 73 * dom/StaticRange.cpp: Removed include of "Range.h". 74 75 * editing/AlternativeTextController.cpp: 76 (WebCore::AlternativeTextController::markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand): 77 Simplify with makeSimpleRange. 78 (WebCore::AlternativeTextController::processMarkersOnTextToBeReplacedByResult): 79 Ditto. 80 * editing/ApplyStyleCommand.cpp: 81 (WebCore::ApplyStyleCommand::applyBlockStyle): Ditto. 82 83 * editing/CompositeEditCommand.cpp: 84 (WebCore::stringForVisiblePositionIndexRange): Updated for removal of 85 VisiblePositionRange constructor; also use move to reduce reference count 86 churn a tiny bit. 87 (WebCore::CompositeEditCommand::moveParagraphs): Simplify with makeSimpleRange. 88 89 * editing/DeleteSelectionCommand.cpp: Added include of "Range.h", may not be needed now, 90 but highly likely to be needed after future live range work. 91 92 * editing/Editing.cpp: 93 (WebCore::indexForVisiblePosition): Simplify using makeSimpleRange and 94 makeBoundaryPointBeforeNodeContents. 95 96 * editing/Editor.cpp: 97 (WebCore::Editor::selectedText const): Simplify using VisibleSelection::firstRange. 98 (WebCore::extendSelection): Simplify using makeSimpleRange. 99 (WebCore::Editor::contextRangeForCandidateRequest const): Ditto. 100 (WebCore::Editor::adjustedSelectionRange): Simplify with the new overload 101 of commonInclusiveAncestor. 102 103 * editing/FrameSelection.cpp: 104 (WebCore::FrameSelection::wordOffsetInRange const): Deleted. Moved the code 105 into the iOS-specific part of WebKitLegacy WebFrame. 106 (WebCore::FrameSelection::spaceFollowsWordInRange const): Deleted. Moved the 107 code into the iOS-specific part of WebKitLegacy WebFrame. 108 (WebCore::FrameSelection::selectionAtSentenceStart const): Merged in with 109 actualSelectionAtSentenceStart. 110 (WebCore::FrameSelection::actualSelectionAtSentenceStart const): Deleted. 111 * editing/FrameSelection.h: Updated for the above deletion. 112 113 * editing/TextCheckingHelper.cpp: 114 (WebCore::TextCheckingParagraph::offsetTo const): Simplify with makeSimpleRange. 115 116 * editing/TextManipulationController.cpp: 117 (WebCore::ParagraphContentIterator::ParagraphContentIterator): Simplify with 118 makeSimpleRange. 119 120 * editing/TypingCommand.cpp: 121 (WebCore::TypingCommand::postTextStateChangeNotificationForDeletion): Pass 122 visibleStart/End instead of converting to Position and back to VisiblePosition. 123 124 * editing/VisiblePosition.cpp: 125 (WebCore::makeSimpleRange): Added. Converts a VisiblePositionRange into 126 a SimpleRange. 127 * editing/VisiblePosition.h: Moved VisiblePositionRange here. 128 129 * editing/VisibleSelection.cpp: 130 (WebCore::VisibleSelection::firstRange const): Simplify using makeSimpleRange. 131 (WebCore::VisibleSelection::toNormalizedRange const): Ditto. 132 (WebCore::makeSearchRange): Deleted. This was confusingly named given that 133 it was only used in appendTrailingWhitespace. 134 (WebCore::VisibleSelection::appendTrailingWhitespace): Merged makeSearchRange 135 in here and simplified using makeSimpleRange. 136 137 * editing/VisibleSelection.h: Added conversion to VisiblePositionRange. 138 Previously this was implemented as a constructor for VisiblePositionRange, 139 but that was a layering inversion since this is built on top of VisiblePosition. 140 141 * editing/VisibleUnits.cpp: 142 (WebCore::distanceBetweenPositions): Simplified using makeSimpleRange. 143 (WebCore::charactersAroundPosition): Ditto. 144 (WebCore::wordRangeFromPosition): Removed an unhelpful comment. 145 (WebCore::closestWordBoundaryForPosition): Ditto. 146 147 * editing/cocoa/DataDetection.mm: 148 (WebCore::detectItem): Simplify using makeSimpleRange. 149 (WebCore::searchForLinkRemovingExistingDDLinks): Removed out argument 150 about modifying the DOM. This was used to work around a problem caused by 151 using live ranges. The problem no longer exists because the code does not 152 use live ranges any more. 153 (WebCore::DataDetection::detectContentInRange): Removed the workaround. 154 155 * editing/cocoa/DictionaryLookup.mm: 156 (WebCore::DictionaryLookup::rangeForSelection): Simplify using makeSimpleRange. 157 (WebCore::DictionaryLookup::rangeAtHitTestResult): Ditto. 158 159 * editing/cocoa/WebContentReaderCocoa.mm: Added include of "Range.h", may 160 not be needed now, but highly likely to be needed after future live range work. 161 162 * editing/ios/DictationCommandIOS.cpp: Removed include of "Range.h". 163 164 * editing/mac/DictionaryLookupLegacy.mm: 165 (WebCore::DictionaryLookup::rangeForSelection): Simplify using makeSimpleRange. 166 (WebCore::DictionaryLookup::rangeAtHitTestResult): Ditto. 167 168 * editing/mac/EditorMac.mm: Removed include of "Range.h". 169 170 * editing/markup.cpp: 171 (WebCore::StyledMarkupAccumulator::renderedTextRespectingRange): Simplify 172 using makeSimpleRange. 173 174 * editing/win/EditorWin.cpp: Added include of "Range.h", may not be needed now, 175 but highly likely to be needed after future live range work. 176 177 * html/shadow/mac/ImageControlsButtonElementMac.cpp: Removed include of "Range.h". 178 179 * page/DOMSelection.cpp: 180 (WebCore::DOMSelection::addRange): Call setSelection instead of moveTo. 181 No need to have two functions that do the same thing. 182 183 * page/EventHandler.cpp: 184 (WebCore::textDistance): Simplify using makeSimpleRange. 185 186 * page/Frame.cpp: 187 (WebCore::Frame::rangeForPoint): Simplify using makeSimpleRange. 188 189 * page/TextIndicator.cpp: 190 (WebCore::estimatedBackgroundColorForRange): Simplify using the 191 commonInclusiveAncestor overload that takes a range. 192 (WebCore::initializeIndicator): Ditto. 193 1 194 2020-07-29 Adrian Perez de Castro <aperez@igalia.com> 2 195 -
trunk/Source/WebCore/accessibility/AXObjectCache.cpp
r264784 r265044 84 84 #include "MathMLElement.h" 85 85 #include "Page.h" 86 #include "Range.h" 86 87 #include "RenderAttachment.h" 87 88 #include "RenderLineBreak.h" … … 167 168 { 168 169 if (AXObjectCache::accessibilityEnabled()) { 169 m_replacedRange.startIndex.value = indexForVisiblePosition(selection. start(), m_replacedRange.startIndex.scope);170 m_replacedRange.startIndex.value = indexForVisiblePosition(selection.visibleStart(), m_replacedRange.startIndex.scope); 170 171 if (selection.isRange()) { 171 172 m_replacedText = AccessibilityObject::stringForVisiblePositionRange(selection); 172 m_replacedRange.endIndex.value = indexForVisiblePosition(selection. end(), m_replacedRange.endIndex.scope);173 m_replacedRange.endIndex.value = indexForVisiblePosition(selection.visibleEnd(), m_replacedRange.endIndex.scope); 173 174 } else 174 175 m_replacedRange.endIndex = m_replacedRange.startIndex; … … 1986 1987 endPosition = lastPositionInOrAfterNode(originalRange.end.container.ptr()); 1987 1988 1988 auto searchRange = SimpleRange { *makeBoundaryPoint(startPosition), *makeBoundaryPoint(endPosition) };1989 if ( searchRange.collapsed())1989 auto searchRange = makeSimpleRange(startPosition, endPosition); 1990 if (!searchRange || searchRange->collapsed()) 1990 1991 return WTF::nullopt; 1991 1992 1992 auto targetOffset = characterCount({ searchRange .start, originalRange.start }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);1993 return findClosestPlainText( searchRange, matchText, { }, targetOffset);1993 auto targetOffset = characterCount({ searchRange->start, originalRange.start }, TextIteratorEmitsCharactersBetweenAllVisiblePositions); 1994 return findClosestPlainText(*searchRange, matchText, { }, targetOffset); 1994 1995 } 1995 1996 … … 2881 2882 if (!object) 2882 2883 return { }; 2883 auto boundary = makeBoundaryPoint(object->visiblePositionForPoint(point));2884 if (! boundary)2884 auto range = makeSimpleRange(object->visiblePositionForPoint(point)); 2885 if (!range) 2885 2886 return { }; 2886 return startOrEndCharacterOffsetForRange( { *boundary, *boundary }, true);2887 return startOrEndCharacterOffsetForRange(*range, true); 2887 2888 } 2888 2889 2889 2890 CharacterOffset AXObjectCache::characterOffsetForPoint(const IntPoint& point) 2890 2891 { 2891 auto boundary = m_document.caretPositionFromPoint(point);2892 if (! boundary)2892 auto range = makeSimpleRange(m_document.caretPositionFromPoint(point)); 2893 if (!range) 2893 2894 return { }; 2894 return startOrEndCharacterOffsetForRange( { *boundary, *boundary }, true);2895 return startOrEndCharacterOffsetForRange(*range, true); 2895 2896 } 2896 2897 -
trunk/Source/WebCore/accessibility/AccessibilityObject.cpp
r264692 r265044 64 64 #include "NodeTraversal.h" 65 65 #include "Page.h" 66 #include "Range.h" 66 67 #include "RenderImage.h" 67 68 #include "RenderInline.h" … … 981 982 } 982 983 983 return VisiblePositionRange(startPos, endPos);984 return { startPos, endPos }; 984 985 } 985 986 986 987 VisiblePositionRange AccessibilityObject::positionOfLeftWord(const VisiblePosition& visiblePos) const 987 988 { 988 VisiblePosition startPosition = startOfWord(visiblePos, LeftWordIfOnBoundary); 989 VisiblePosition endPosition = endOfWord(startPosition); 990 return VisiblePositionRange(startPosition, endPosition); 989 auto start = startOfWord(visiblePos, LeftWordIfOnBoundary); 990 return { start, endOfWord(start) }; 991 991 } 992 992 993 993 VisiblePositionRange AccessibilityObject::positionOfRightWord(const VisiblePosition& visiblePos) const 994 994 { 995 VisiblePosition startPosition = startOfWord(visiblePos, RightWordIfOnBoundary); 996 VisiblePosition endPosition = endOfWord(startPosition); 997 return VisiblePositionRange(startPosition, endPosition); 995 auto start = startOfWord(visiblePos, RightWordIfOnBoundary); 996 return { start, endOfWord(start) }; 998 997 } 999 998 … … 1045 1044 startPosition = updateAXLineStartForVisiblePosition(startPosition); 1046 1045 1047 VisiblePosition endPosition = endOfLine(prevVisiblePos); 1048 return VisiblePositionRange(startPosition, endPosition); 1046 return { startPosition, endOfLine(prevVisiblePos) }; 1049 1047 } 1050 1048 … … 1079 1077 } 1080 1078 1081 return VisiblePositionRange(startPosition, endPosition);1079 return { startPosition, endPosition }; 1082 1080 } 1083 1081 … … 1086 1084 // FIXME: FO 2 IMPLEMENT (currently returns incorrect answer) 1087 1085 // Related? <rdar://problem/3927736> Text selection broken in 8A336 1088 VisiblePosition startPosition = startOfSentence(visiblePos); 1089 VisiblePosition endPosition = endOfSentence(startPosition); 1090 return VisiblePositionRange(startPosition, endPosition); 1086 auto startPosition = startOfSentence(visiblePos); 1087 return { startPosition, endOfSentence(startPosition) }; 1091 1088 } 1092 1089 1093 1090 VisiblePositionRange AccessibilityObject::paragraphForPosition(const VisiblePosition& visiblePos) const 1094 1091 { 1095 VisiblePosition startPosition = startOfParagraph(visiblePos); 1096 VisiblePosition endPosition = endOfParagraph(startPosition); 1097 return VisiblePositionRange(startPosition, endPosition); 1092 auto startPosition = startOfParagraph(visiblePos); 1093 return { startPosition, endOfParagraph(startPosition) }; 1098 1094 } 1099 1095 … … 1147 1143 { 1148 1144 if (visiblePos.isNull()) 1149 return VisiblePositionRange();1150 1151 return VisiblePositionRange(startOfStyleRange(visiblePos), endOfStyleRange(visiblePos));1145 return { }; 1146 1147 return { startOfStyleRange(visiblePos), endOfStyleRange(visiblePos) }; 1152 1148 } 1153 1149 … … 1157 1153 unsigned textLength = getLengthForTextRange(); 1158 1154 if (range.start + range.length > textLength) 1159 return VisiblePositionRange();1160 1161 VisiblePositionstartPosition = visiblePositionForIndex(range.start);1155 return { }; 1156 1157 auto startPosition = visiblePositionForIndex(range.start); 1162 1158 startPosition.setAffinity(DOWNSTREAM); 1163 VisiblePosition endPosition = visiblePositionForIndex(range.start + range.length); 1164 return VisiblePositionRange(startPosition, endPosition); 1159 return { startPosition, visiblePositionForIndex(range.start + range.length) }; 1165 1160 } 1166 1161 … … 1184 1179 VisiblePositionRange AccessibilityObject::lineRangeForPosition(const VisiblePosition& visiblePosition) const 1185 1180 { 1186 VisiblePosition startPosition = startOfLine(visiblePosition); 1187 VisiblePosition endPosition = endOfLine(visiblePosition); 1188 return VisiblePositionRange(startPosition, endPosition); 1181 return { startOfLine(visiblePosition), endOfLine(visiblePosition) }; 1189 1182 } 1190 1183 … … 1272 1265 String AccessibilityObject::stringForVisiblePositionRange(const VisiblePositionRange& visiblePositionRange) 1273 1266 { 1274 auto start = makeBoundaryPoint(visiblePositionRange.start);1275 if (! start)1267 auto range = makeSimpleRange(visiblePositionRange); 1268 if (!range) 1276 1269 return { }; 1277 auto end = makeBoundaryPoint(visiblePositionRange.end);1278 if (!end)1279 return { };1280 1270 1281 1271 StringBuilder builder; 1282 for (TextIterator it( { *start, *end }); !it.atEnd(); it.advance()) {1272 for (TextIterator it(*range); !it.atEnd(); it.advance()) { 1283 1273 // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX) 1284 1274 if (it.text().length()) { … … 1299 1289 // FIXME: Multi-byte support 1300 1290 1301 auto start = makeBoundaryPoint(visiblePositionRange.start); 1302 if (!start) 1303 return -1; // FIXME: Why not return 0? 1304 auto end = makeBoundaryPoint(visiblePositionRange.end); 1305 if (!end) 1291 auto range = makeSimpleRange(visiblePositionRange); 1292 if (!range) 1306 1293 return -1; // FIXME: Why not return 0? 1307 1294 1308 1295 // FIXME: Use characterCount instead of writing our own loop? 1309 1296 int length = 0; 1310 for (TextIterator it( { *start, *end }); !it.atEnd(); it.advance()) {1297 for (TextIterator it(*range); !it.atEnd(); it.advance()) { 1311 1298 // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX) 1312 1299 if (it.text().length()) … … 1432 1419 // Make sure we move off of a sentence end. 1433 1420 auto nextPosition = position.next(); 1434 auto start = makeBoundaryPoint(startOfLine(nextPosition)); 1435 if (!start) 1436 return { }; 1437 auto end = makeBoundaryPoint(endOfLine(nextPosition)); 1438 if (!end) 1421 auto range = makeSimpleRange(startOfLine(nextPosition), endOfLine(nextPosition)); 1422 if (!range) 1439 1423 return { }; 1440 1424 1441 1425 // An empty line is considered a sentence. If it's skipped, then the sentence parser will not 1442 1426 // see this empty line. Instead, return the end position of the empty line. 1443 return hasAnyPlainText( { *start, *end }) ? endOfSentence(nextPosition) : nextPosition;1427 return hasAnyPlainText(*range) ? endOfSentence(nextPosition) : nextPosition; 1444 1428 } 1445 1429 … … 1451 1435 // Make sure we move off of a sentence start. 1452 1436 auto previousPosition = position.previous(); 1453 auto start = makeBoundaryPoint(startOfLine(previousPosition));1454 if (! start)1437 auto range = makeSimpleRange(startOfLine(previousPosition), endOfLine(previousPosition)); 1438 if (!range) 1455 1439 return { }; 1456 auto end = makeBoundaryPoint(endOfLine(previousPosition));1457 if (!end)1458 return { };1459 1440 1460 1441 // Treat empty line as a separate sentence. 1461 return hasAnyPlainText( { *start, *end }) ? startOfSentence(previousPosition) : previousPosition;1442 return hasAnyPlainText(*range) ? startOfSentence(previousPosition) : previousPosition; 1462 1443 } 1463 1444 -
trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h
r264284 r265044 431 431 }; 432 432 433 struct VisiblePositionRange {434 VisiblePosition start;435 VisiblePosition end;436 437 VisiblePositionRange() = default;438 VisiblePositionRange(const VisiblePosition& s, const VisiblePosition& e)439 : start(s)440 , end(e)441 { }442 443 VisiblePositionRange(const VisibleSelection& selection)444 : start(selection.start())445 , end(selection.end())446 { }447 448 bool isNull() const { return start.isNull() || end.isNull(); }449 };450 451 433 enum class AccessibilityMathScriptObjectType { Subscript, Superscript }; 452 434 enum class AccessibilityMathMultiscriptObjectType { PreSubscript, PreSuperscript, PostSubscript, PostSuperscript }; -
trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp
r264271 r265044 650 650 // We define the start and end positions for the range as the ones right before and after 651 651 // the first and the last nodes in the DOM tree that is wrapped inside the anonymous block. 652 Node* firstNodeInBlock = firstChildRenderer->node(); 653 Position startPosition = positionInParentBeforeNode(firstNodeInBlock); 654 Position endPosition = positionInParentAfterNode(lastChildRenderer->node()); 655 656 nodeDocument = &firstNodeInBlock->document(); 657 textRange = { { *makeBoundaryPoint(startPosition), *makeBoundaryPoint(endPosition) } }; 652 auto& firstNodeInBlock = *firstChildRenderer->node(); 653 nodeDocument = &firstNodeInBlock.document(); 654 textRange = makeSimpleRange(positionInParentBeforeNode(&firstNodeInBlock), positionInParentAfterNode(lastChildRenderer->node())); 658 655 } 659 656 } … … 918 915 auto end = nextVisiblePosition(start); 919 916 if (!end.isNull() && createLiveRange(range)->contains(end)) 920 return { boundsForRange( { *makeBoundaryPoint(start), *makeBoundaryPoint(end) }).center() };917 return { boundsForRange(*makeSimpleRange(start, end)).center() }; 921 918 } 922 919 return AccessibilityObject::clickPoint(); … … 936 933 return AccessibilityObject::clickPoint(); 937 934 938 VisibleSelection visSelection = selection(); 939 VisiblePositionRange range = VisiblePositionRange(visSelection.visibleStart(), visSelection.visibleEnd()); 940 return boundsForVisiblePositionRange(range).center(); 935 return boundsForVisiblePositionRange(selection()).center(); 941 936 } 942 937 … … 1991 1986 return VisiblePositionRange(); 1992 1987 1993 // construct VisiblePositions for start and end1994 1988 Node* node = m_renderer->node(); 1995 1989 if (!node) … … 2009 2003 } 2010 2004 2011 return VisiblePositionRange(startPos, endPos);2005 return { WTFMove(startPos), WTFMove(endPos) }; 2012 2006 } 2013 2007 … … 2039 2033 selection.modify(FrameSelection::AlterationExtend, SelectionDirection::Right, TextGranularity::LineBoundary); 2040 2034 2041 return VisiblePositionRange(selection.selection().visibleStart(), selection.selection().visibleEnd());2035 return selection.selection(); 2042 2036 } 2043 2037 -
trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm
r264470 r265044 67 67 #import "PluginDocument.h" 68 68 #import "PluginViewBase.h" 69 #import "Range.h" 69 70 #import "RenderInline.h" 70 71 #import "RenderTextControl.h" … … 924 925 { 925 926 ASSERT(cache); 926 927 927 if (!textMarker) 928 928 return VisiblePosition(); … … 930 930 if (!getBytesFromAXTextMarker(textMarker, &textMarkerData, sizeof(textMarkerData))) 931 931 return VisiblePosition(); 932 933 932 return cache->visiblePositionForTextMarkerData(textMarkerData); 934 933 } 935 934 935 static VisiblePositionRange visiblePositionRangeForTextMarkerRange(AXObjectCache* cache, id textMarkerRange) 936 { 937 return { 938 visiblePositionForTextMarker(cache, (__bridge CFTypeRef)AXTextMarkerRangeStart(textMarkerRange)), 939 visiblePositionForTextMarker(cache, (__bridge CFTypeRef)AXTextMarkerRangeEnd(textMarkerRange)) 940 }; 941 } 942 936 943 - (VisiblePosition)visiblePositionForTextMarker:(id)textMarker 937 944 { 938 945 return visiblePositionForTextMarker(self.axBackingObject->axObjectCache(), (__bridge CFTypeRef)textMarker); 939 }940 941 static VisiblePosition visiblePositionForStartOfTextMarkerRange(AXObjectCache* cache, id textMarkerRange)942 {943 return visiblePositionForTextMarker(cache, (__bridge CFTypeRef)AXTextMarkerRangeStart(textMarkerRange));944 }945 946 static VisiblePosition visiblePositionForEndOfTextMarkerRange(AXObjectCache* cache, id textMarkerRange)947 {948 return visiblePositionForTextMarker(cache, (__bridge CFTypeRef)AXTextMarkerRangeEnd(textMarkerRange));949 946 } 950 947 … … 1848 1845 - (VisiblePositionRange)visiblePositionRangeForTextMarkerRange:(id)textMarkerRange 1849 1846 { 1850 if (!textMarkerRange) 1851 return VisiblePositionRange(); 1852 AXObjectCache* cache = self.axBackingObject->axObjectCache(); 1853 return VisiblePositionRange(visiblePositionForStartOfTextMarkerRange(cache, textMarkerRange), visiblePositionForEndOfTextMarkerRange(cache, textMarkerRange)); 1847 return visiblePositionRangeForTextMarkerRange(self.axBackingObject->axObjectCache(), textMarkerRange); 1854 1848 } 1855 1849 -
trunk/Source/WebCore/dom/Document.cpp
r264880 r265044 164 164 #include "PublicSuffix.h" 165 165 #include "Quirks.h" 166 #include "Range.h" 166 167 #include "RealtimeMediaSourceCenter.h" 167 168 #include "RenderChildIterator.h" -
trunk/Source/WebCore/dom/Node.cpp
r263563 r265044 60 60 #include "ProcessingInstruction.h" 61 61 #include "ProgressEvent.h" 62 #include "Range.h"63 62 #include "RenderBlock.h" 64 63 #include "RenderBox.h" -
trunk/Source/WebCore/dom/Position.h
r259930 r265044 42 42 43 43 struct BoundaryPoint; 44 struct SimpleRange; 44 45 45 46 enum PositionMoveType { … … 250 251 WTF::TextStream& operator<<(WTF::TextStream&, const Position&); 251 252 253 struct PositionRange { 254 Position start; 255 Position end; 256 }; 257 258 Optional<SimpleRange> makeSimpleRange(const PositionRange&); 259 252 260 // inlines 253 261 -
trunk/Source/WebCore/dom/RadioButtonGroups.cpp
r259911 r265044 23 23 24 24 #include "HTMLInputElement.h" 25 #include "Range.h"26 25 #include <wtf/WeakHashSet.h> 27 26 #include <wtf/WeakPtr.h> -
trunk/Source/WebCore/dom/Range.h
r264692 r265044 177 177 WEBCORE_EXPORT bool rangesOverlap(const Range*, const Range*); 178 178 179 SimpleRange makeSimpleRange(const Range&);179 WEBCORE_EXPORT SimpleRange makeSimpleRange(const Range&); 180 180 SimpleRange makeSimpleRange(const Ref<Range>&); 181 181 WEBCORE_EXPORT Optional<SimpleRange> makeSimpleRange(const Range*); -
trunk/Source/WebCore/dom/SimpleRange.cpp
r264692 r265044 83 83 } 84 84 85 Optional<SimpleRange> makeSimpleRange(const Optional<BoundaryPoint>& point) 86 { 87 if (!point) 88 return WTF::nullopt; 89 return { { *point, *point } }; 90 } 91 92 Optional<SimpleRange> makeSimpleRange(Optional<BoundaryPoint>&& point) 93 { 94 if (!point) 95 return WTF::nullopt; 96 auto end = *point; 97 return { { WTFMove(*point), WTFMove(end) } }; 98 } 99 85 100 Optional<SimpleRange> makeSimpleRange(const Optional<BoundaryPoint>& start, const Optional<BoundaryPoint>& end) 86 101 { … … 152 167 } 153 168 169 RefPtr<Node> commonInclusiveAncestor(const SimpleRange& range) 170 { 171 return commonInclusiveAncestor(range.start.container, range.end.container); 154 172 } 173 174 } -
trunk/Source/WebCore/dom/SimpleRange.h
r264692 r265044 52 52 }; 53 53 54 SimpleRange makeSimpleRange(const BoundaryPoint&); 55 SimpleRange makeSimpleRange(BoundaryPoint&&); 56 SimpleRange makeSimpleRange(const BoundaryPoint&, const BoundaryPoint&); 57 SimpleRange makeSimpleRange(BoundaryPoint&&, BoundaryPoint&&); 58 Optional<SimpleRange> makeSimpleRange(const Optional<BoundaryPoint>&); 59 WEBCORE_EXPORT Optional<SimpleRange> makeSimpleRange(Optional<BoundaryPoint>&&); 54 60 WEBCORE_EXPORT Optional<SimpleRange> makeSimpleRange(const Optional<BoundaryPoint>&, const Optional<BoundaryPoint>&); 55 61 WEBCORE_EXPORT Optional<SimpleRange> makeSimpleRange(Optional<BoundaryPoint>&&, Optional<BoundaryPoint>&&); 62 63 inline BoundaryPoint makeBoundaryPointHelper(const BoundaryPoint& point) { return point; } 64 inline BoundaryPoint makeBoundaryPointHelper(BoundaryPoint&& point) { return WTFMove(point); } 65 template<typename T> auto makeBoundaryPointHelper(T&& argument) -> decltype(makeBoundaryPoint(std::forward<T>(argument))) 66 { 67 return makeBoundaryPoint(std::forward<T>(argument)); 68 } 69 70 template<typename ...T> auto makeSimpleRange(T&& ...arguments) -> decltype(makeSimpleRange(makeBoundaryPointHelper(std::forward<T>(arguments))...)) 71 { 72 return makeSimpleRange(makeBoundaryPointHelper(std::forward<T>(arguments))...); 73 } 56 74 57 75 // FIXME: Would like these to have shorter names; another option is to change prefix to makeSimpleRange. 58 76 WEBCORE_EXPORT Optional<SimpleRange> makeRangeSelectingNode(Node&); 59 77 WEBCORE_EXPORT SimpleRange makeRangeSelectingNodeContents(Node&); 78 79 RefPtr<Node> commonInclusiveAncestor(const SimpleRange&); 60 80 61 81 bool operator==(const SimpleRange&, const SimpleRange&); -
trunk/Source/WebCore/dom/StaticRange.cpp
r258248 r265044 28 28 29 29 #include "ContainerNode.h" 30 #include "Range.h"31 30 #include "Text.h" 32 31 -
trunk/Source/WebCore/editing/AlternativeTextController.cpp
r264905 r265044 473 473 return; 474 474 475 auto precedingCharacterRange = SimpleRange { *makeBoundaryPoint(precedingCharacterPosition), *makeBoundaryPoint(endOfSelection) }; 476 String string = plainText(precedingCharacterRange); 475 auto precedingCharacterRange = makeSimpleRange(precedingCharacterPosition, endOfSelection); 476 if (!precedingCharacterRange) 477 return; 478 String string = plainText(*precedingCharacterRange); 477 479 if (string.isEmpty() || !deprecatedIsEditingWhitespace(string[string.length() - 1])) 478 480 return; … … 481 483 // whitespace. So if the user types the same original word again at this position, we 482 484 // won't autocorrect it again. 483 addMarker( precedingCharacterRange, DocumentMarker::DeletedAutocorrection, m_originalStringForLastDeletedAutocorrection);485 addMarker(*precedingCharacterRange, DocumentMarker::DeletedAutocorrection, m_originalStringForLastDeletedAutocorrection); 484 486 } 485 487 … … 499 501 return false; 500 502 501 auto beforePrecedingCharacter = createLegacyEditingPosition(rangeWithAlternative.start).previous(); 502 auto precedingCharacterRange = SimpleRange { *makeBoundaryPoint(beforePrecedingCharacter), rangeWithAlternative.start }; 503 504 for (auto& marker : markers.markersInRange(precedingCharacterRange, DocumentMarker::DeletedAutocorrection)) { 503 auto precedingCharacterRange = makeSimpleRange(createLegacyEditingPosition(rangeWithAlternative.start).previous(), rangeWithAlternative.start); 504 if (!precedingCharacterRange) 505 return false; 506 507 for (auto& marker : markers.markersInRange(*precedingCharacterRange, DocumentMarker::DeletedAutocorrection)) { 505 508 if (marker->description() == stringToBeReplaced) 506 509 return false; -
trunk/Source/WebCore/editing/ApplyStyleCommand.cpp
r259930 r265044 242 242 // addBlockStyleIfNeeded may moveParagraphs, which can remove these endpoints. 243 243 // Calculate start and end indices from the start of the tree that they're in. 244 auto scope = makeRefPtr(highestEditableRoot(visibleStart.deepEquivalent())); 245 if (!scope) 246 return; 247 248 auto scopeStart = BoundaryPoint { *scope, 0 }; 249 auto startBoundaryPoint = makeBoundaryPoint(visibleStart.deepEquivalent().parentAnchoredEquivalent()); 250 auto endBoundaryPoint = makeBoundaryPoint(visibleEnd.deepEquivalent().parentAnchoredEquivalent()); 251 if (!startBoundaryPoint || !endBoundaryPoint) 252 return; 253 254 auto startIndex = characterCount({ scopeStart, *startBoundaryPoint }, TextIteratorEmitsCharactersBetweenAllVisiblePositions); 255 auto endIndex = characterCount({ scopeStart, *endBoundaryPoint }, TextIteratorEmitsCharactersBetweenAllVisiblePositions); 244 auto scopeRoot = makeRefPtr(highestEditableRoot(visibleStart.deepEquivalent())); 245 if (!scopeRoot) 246 return; 247 248 auto scope = makeRangeSelectingNodeContents(*scopeRoot); 249 auto range = *makeSimpleRange(visibleStart, visibleEnd); 250 auto startIndex = characterCount({ scope.start, range.start }, TextIteratorEmitsCharactersBetweenAllVisiblePositions); 251 auto endIndex = characterCount({ scope.start, range.end }, TextIteratorEmitsCharactersBetweenAllVisiblePositions); 256 252 257 253 VisiblePosition paragraphStart(startOfParagraph(visibleStart)); … … 284 280 } 285 281 286 auto startPosition = createLegacyEditingPosition(resolveCharacterLocation( makeRangeSelectingNodeContents(*scope), startIndex, TextIteratorEmitsCharactersBetweenAllVisiblePositions));287 auto endPosition = createLegacyEditingPosition(resolveCharacterLocation( makeRangeSelectingNodeContents(*scope), endIndex, TextIteratorEmitsCharactersBetweenAllVisiblePositions));282 auto startPosition = createLegacyEditingPosition(resolveCharacterLocation(scope, startIndex, TextIteratorEmitsCharactersBetweenAllVisiblePositions)); 283 auto endPosition = createLegacyEditingPosition(resolveCharacterLocation(scope, endIndex, TextIteratorEmitsCharactersBetweenAllVisiblePositions)); 288 284 updateStartEnd(startPosition, endPosition); 289 285 } -
trunk/Source/WebCore/editing/CompositeEditCommand.cpp
r264905 r265044 132 132 VisiblePosition start = visiblePositionForIndex(range.startIndex.value, range.startIndex.scope.get()); 133 133 VisiblePosition end = visiblePositionForIndex(range.endIndex.value, range.endIndex.scope.get()); 134 return AccessibilityObject::stringForVisiblePositionRange( VisiblePositionRange(start, end));134 return AccessibilityObject::stringForVisiblePositionRange({ WTFMove(start), WTFMove(end) }); 135 135 } 136 136 … … 1421 1421 startIndex = 0; 1422 1422 if (startInParagraph) { 1423 auto paragraphStart = makeBoundaryPoint(startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent()); 1424 auto selectionStart = makeBoundaryPoint(visibleStart.deepEquivalent().parentAnchoredEquivalent()); 1425 if (paragraphStart && selectionStart) 1426 startIndex = characterCount({ *paragraphStart, *selectionStart }, TextIteratorEmitsCharactersBetweenAllVisiblePositions); 1423 if (auto rangeToSelectionStart = makeSimpleRange(startOfParagraphToMove, visibleStart)) 1424 startIndex = characterCount(*rangeToSelectionStart, TextIteratorEmitsCharactersBetweenAllVisiblePositions); 1427 1425 } 1428 1426 1429 1427 endIndex = 0; 1430 1428 if (endInParagraph) { 1431 auto paragraphStart = makeBoundaryPoint(startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent()); 1432 auto selectionEnd = makeBoundaryPoint(visibleEnd.deepEquivalent().parentAnchoredEquivalent()); 1433 if (paragraphStart && selectionEnd) 1434 endIndex = characterCount({ *paragraphStart, *selectionEnd }, TextIteratorEmitsCharactersBetweenAllVisiblePositions); 1429 if (auto rangeToSelectionEnd = makeSimpleRange(startOfParagraphToMove, visibleEnd)) 1430 endIndex = characterCount(*rangeToSelectionEnd, TextIteratorEmitsCharactersBetweenAllVisiblePositions); 1435 1431 } 1436 1432 } … … 1505 1501 editableRoot = &document(); 1506 1502 1507 auto destinationIndex = characterCount({ { *editableRoot, 0 }, *makeBoundaryPoint(destination .deepEquivalent().parentAnchoredEquivalent()) }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);1503 auto destinationIndex = characterCount({ { *editableRoot, 0 }, *makeBoundaryPoint(destination) }, TextIteratorEmitsCharactersBetweenAllVisiblePositions); 1508 1504 1509 1505 setEndingSelection(VisibleSelection(destination, originalIsDirectional)); -
trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp
r264692 r265044 40 40 #include "HTMLTableElement.h" 41 41 #include "NodeTraversal.h" 42 #include "Range.h" 42 43 #include "RenderTableCell.h" 43 44 #include "RenderText.h" -
trunk/Source/WebCore/editing/Editing.cpp
r264386 r265044 1105 1105 } 1106 1106 1107 auto start = makeBoundaryPoint(firstPositionInNode(scope.get())); 1108 if (!start) 1109 return 0; 1110 auto end = makeBoundaryPoint(position.parentAnchoredEquivalent()); 1111 if (!end) 1112 return 0; 1113 1114 return characterCount({ *start, *end }, TextIteratorEmitsCharactersBetweenAllVisiblePositions); 1107 auto range = *makeSimpleRange(makeBoundaryPointBeforeNodeContents(*scope), position); 1108 return characterCount(range, TextIteratorEmitsCharactersBetweenAllVisiblePositions); 1115 1109 } 1116 1110 … … 1118 1112 int indexForVisiblePosition(Node& node, const VisiblePosition& visiblePosition, bool forSelectionPreservation) 1119 1113 { 1120 auto start = makeBoundaryPoint(firstPositionInNode(&node)); 1121 if (!start) 1122 return 0; 1123 auto end = makeBoundaryPoint(visiblePosition.deepEquivalent().parentAnchoredEquivalent()); 1124 if (!end) 1125 return 0; 1126 1127 return characterCount({ *start, *end }, forSelectionPreservation ? TextIteratorEmitsCharactersBetweenAllVisiblePositions : TextIteratorDefaultBehavior); 1114 auto range = makeSimpleRange(makeBoundaryPointBeforeNodeContents(node), visiblePosition); 1115 return range ? characterCount(*range, forSelectionPreservation ? TextIteratorEmitsCharactersBetweenAllVisiblePositions : TextIteratorDefaultBehavior) : 0; 1128 1116 } 1129 1117 -
trunk/Source/WebCore/editing/Editor.cpp
r264905 r265044 3260 3260 { 3261 3261 // We remove '\0' characters because they are not visibly rendered to the user. 3262 auto& selection = m_document.selection().selection(); 3263 auto start = selection.start(); 3264 auto end = selection.end(); 3265 if (start.isNull() || start.isOrphan() || end.isNull() || end.isOrphan()) 3266 return emptyString(); 3267 return plainText(SimpleRange { *makeBoundaryPoint(start), *makeBoundaryPoint(end) }, behavior).replaceWithLiteral('\0', ""); 3262 auto range = m_document.selection().selection().firstRange(); 3263 return range ? plainText(*range, behavior).replaceWithLiteral('\0', "") : emptyString(); 3268 3264 } 3269 3265 … … 3683 3679 end = end.next(Character); 3684 3680 } 3685 return { *makeBoundaryPoint(start), *makeBoundaryPoint(end)};3681 return *makeSimpleRange(start, end); 3686 3682 } 3687 3683 … … 3910 3906 { 3911 3907 auto& selection = m_document.selection().selection(); 3912 auto start = makeBoundaryPoint(startOfParagraph(selection.visibleStart())); 3913 auto end = makeBoundaryPoint(endOfParagraph(selection.visibleEnd())); 3914 if (!start || !end) 3915 return WTF::nullopt; 3916 return { { *start, *end } }; 3908 return makeSimpleRange(startOfParagraph(selection.visibleStart()), endOfParagraph(selection.visibleEnd())); 3917 3909 } 3918 3910 … … 4232 4224 auto range = selectedRange(); 4233 4225 if (range) { 4234 if (auto enclosingAnchor = enclosingElementWithTag(firstPositionInNode(commonInclusiveAncestor( range->start.container, range->end.container).get()), HTMLNames::aTag)) {4226 if (auto enclosingAnchor = enclosingElementWithTag(firstPositionInNode(commonInclusiveAncestor(*range).get()), HTMLNames::aTag)) { 4235 4227 if (comparePositions(firstPositionInOrBeforeNode(range->start.container.ptr()), createLegacyEditingPosition(range->start)) >= 0) 4236 4228 range->start = makeBoundaryPointBeforeNodeContents(*enclosingAnchor); -
trunk/Source/WebCore/editing/FrameSelection.cpp
r264878 r265044 2619 2619 } 2620 2620 2621 int FrameSelection::wordOffsetInRange(const Range *range) const2622 {2623 if (!range)2624 return -1;2625 2626 VisibleSelection selection = m_selection;2627 if (!selection.isCaret())2628 return -1;2629 2630 // FIXME: This will only work in cases where the selection remains in2631 // the same node after it is expanded. Improve to handle more complicated2632 // cases.2633 int result = selection.start().deprecatedEditingOffset() - range->startOffset();2634 if (result < 0)2635 result = 0;2636 return result;2637 }2638 2639 bool FrameSelection::spaceFollowsWordInRange(const Range *range) const2640 {2641 if (!range)2642 return false;2643 Node& node = range->endContainer();2644 int endOffset = range->endOffset();2645 VisiblePosition pos(createLegacyEditingPosition(&node, endOffset), VP_DEFAULT_AFFINITY);2646 return isSpaceOrNewline(pos.characterAfter());2647 }2648 2649 2621 bool FrameSelection::selectionAtDocumentStart() const 2650 2622 { … … 2659 2631 2660 2632 return isStartOfDocument(pos); 2661 }2662 2663 bool FrameSelection::selectionAtSentenceStart() const2664 {2665 VisibleSelection selection = m_selection;2666 if (selection.isNone())2667 return false;2668 2669 return actualSelectionAtSentenceStart(selection);2670 2633 } 2671 2634 … … 2835 2798 } 2836 2799 2837 bool FrameSelection::actualSelectionAtSentenceStart(const VisibleSelection& sel) const 2838 { 2839 Position startPos(sel.start()); 2800 bool FrameSelection::selectionAtSentenceStart() const 2801 { 2802 if (m_selection.isNone()) 2803 return false; 2804 2805 Position startPos(m_selection.start()); 2840 2806 VisiblePosition pos(createLegacyEditingPosition(startPos.deprecatedNode(), startPos.deprecatedEditingOffset()), VP_DEFAULT_AFFINITY); 2841 2807 if (pos.isNull()) -
trunk/Source/WebCore/editing/FrameSelection.h
r264386 r265044 233 233 WEBCORE_EXPORT UChar characterBeforeCaretSelection() const; 234 234 WEBCORE_EXPORT UChar characterAfterCaretSelection() const; 235 WEBCORE_EXPORT int wordOffsetInRange(const Range*) const;236 WEBCORE_EXPORT bool spaceFollowsWordInRange(const Range*) const;237 235 WEBCORE_EXPORT bool selectionAtDocumentStart() const; 238 236 WEBCORE_EXPORT bool selectionAtSentenceStart() const; … … 334 332 335 333 #if PLATFORM(IOS_FAMILY) 336 bool actualSelectionAtSentenceStart(const VisibleSelection&) const;337 334 Optional<SimpleRange> rangeByAlteringCurrentSelection(EAlteration, int amount) const; 338 335 #endif -
trunk/Source/WebCore/editing/TextCheckingHelper.cpp
r264905 r265044 33 33 #include "Frame.h" 34 34 #include "FrameSelection.h" 35 #include "Range.h" 35 36 #include "Settings.h" 36 37 #include "TextCheckerClient.h" … … 161 162 ExceptionOr<uint64_t> TextCheckingParagraph::offsetTo(const Position& position) const 162 163 { 163 auto end = makeBoundaryPoint(position);164 if (! end)164 auto range = makeSimpleRange(paragraphRange().start, position); 165 if (!range) 165 166 return Exception { TypeError }; 166 return characterCount( { paragraphRange().start, *end });167 return characterCount(*range); 167 168 } 168 169 -
trunk/Source/WebCore/editing/TextManipulationController.cpp
r264947 r265044 41 41 #include "NodeTraversal.h" 42 42 #include "PseudoElement.h" 43 #include "Range.h"44 43 #include "ScriptDisallowedScope.h" 45 44 #include "Text.h" … … 155 154 public: 156 155 ParagraphContentIterator(const Position& start, const Position& end) 157 : m_iterator( { *makeBoundaryPoint(start), *makeBoundaryPoint(end) }, TextIteratorIgnoresStyleVisibility)156 : m_iterator(*makeSimpleRange(start, end), TextIteratorIgnoresStyleVisibility) 158 157 , m_node(start.firstNode()) 159 158 , m_pastEndNode(end.firstNode()) -
trunk/Source/WebCore/editing/TypingCommand.cpp
r261776 r265044 333 333 postTextStateChangeNotification(AXTextEditTypeDelete, AccessibilityObject::stringForVisiblePositionRange(selection), selection.start()); 334 334 VisiblePositionIndexRange range; 335 range.startIndex.value = indexForVisiblePosition(selection. start(), range.startIndex.scope);336 range.endIndex.value = indexForVisiblePosition(selection. end(), range.endIndex.scope);335 range.startIndex.value = indexForVisiblePosition(selection.visibleStart(), range.startIndex.scope); 336 range.endIndex.value = indexForVisiblePosition(selection.visibleEnd(), range.endIndex.scope); 337 337 composition()->setRangeDeletedByUnapply(range); 338 338 } -
trunk/Source/WebCore/editing/VisiblePosition.cpp
r259241 r265044 850 850 } 851 851 852 Optional<SimpleRange> makeSimpleRange(const VisiblePositionRange& range) 853 { 854 return makeSimpleRange(range.start, range.end); 855 } 856 852 857 } // namespace WebCore 853 858 -
trunk/Source/WebCore/editing/VisiblePosition.h
r258871 r265044 33 33 class Range; 34 34 35 struct SimpleRange; 36 35 37 // VisiblePosition default affinity is downstream because 36 38 // the callers do not really care (they just want the … … 141 143 WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const VisiblePosition&); 142 144 145 struct VisiblePositionRange { 146 VisiblePosition start; 147 VisiblePosition end; 148 149 bool isNull() const { return start.isNull() || end.isNull(); } 150 }; 151 152 Optional<SimpleRange> makeSimpleRange(const VisiblePositionRange&); 153 143 154 // inlines 144 155 -
trunk/Source/WebCore/editing/VisibleSelection.cpp
r261939 r265044 31 31 #include "Element.h" 32 32 #include "HTMLInputElement.h" 33 #include "Range.h"34 33 #include "Settings.h" 35 34 #include "ShadowRoot.h" … … 133 132 if (isNoneOrOrphaned()) 134 133 return WTF::nullopt; 135 Position start = m_start.parentAnchoredEquivalent(); 136 Position end = m_end.parentAnchoredEquivalent(); 137 if (start.isNull() || start.isOrphan() || end.isNull() || end.isOrphan()) 138 return WTF::nullopt; 139 return SimpleRange { *makeBoundaryPoint(start), *makeBoundaryPoint(end) }; 134 // FIXME: Seems likely we don't need to call parentAnchoredEquivalent here. 135 return makeSimpleRange(m_start.parentAnchoredEquivalent(), m_end.parentAnchoredEquivalent()); 140 136 } 141 137 … … 180 176 // Make sure the start is before the end. 181 177 // The end can wind up before the start if collapsed whitespace is the only thing selected. 182 Position tmp = s; 183 s = e; 184 e = tmp; 178 std::swap(s, e); 185 179 } 186 180 s = s.parentAnchoredEquivalent(); … … 188 182 } 189 183 190 if (s.isNull() || e.isNull()) 191 return WTF::nullopt; 192 193 return SimpleRange { *makeBoundaryPoint(s), *makeBoundaryPoint(e) }; 184 return makeSimpleRange(s, e); 194 185 } 195 186 … … 203 194 } 204 195 205 static Optional<SimpleRange> makeSearchRange(const Position& position) 206 { 207 auto node = position.deprecatedNode(); 208 auto scope = deprecatedEnclosingBlockFlowElement(node); 196 bool VisibleSelection::isAll(EditingBoundaryCrossingRule rule) const 197 { 198 return !nonBoundaryShadowTreeRootNode() && visibleStart().previous(rule).isNull() && visibleEnd().next(rule).isNull(); 199 } 200 201 void VisibleSelection::appendTrailingWhitespace() 202 { 203 auto scope = deprecatedEnclosingBlockFlowElement(m_end.deprecatedNode()); 209 204 if (!scope) 210 return { };211 auto start = makeBoundaryPoint(position.parentAnchoredEquivalent());212 if (!start)213 return { };214 return { { WTFMove(*start), makeBoundaryPointAfterNodeContents(*scope) } };215 }216 217 bool VisibleSelection::isAll(EditingBoundaryCrossingRule rule) const218 {219 return !nonBoundaryShadowTreeRootNode() && visibleStart().previous(rule).isNull() && visibleEnd().next(rule).isNull();220 }221 222 void VisibleSelection::appendTrailingWhitespace()223 {224 auto searchRange = makeSearchRange(m_end);225 if (!searchRange)226 205 return; 227 206 228 CharacterIterator charIt(*searchRange, TextIteratorEmitsCharactersBetweenAllVisiblePositions); 229 207 CharacterIterator charIt(*makeSimpleRange(m_end, makeBoundaryPointAfterNodeContents(*scope)), TextIteratorEmitsCharactersBetweenAllVisiblePositions); 230 208 for (; !charIt.atEnd() && charIt.text().length(); charIt.advance(1)) { 231 209 UChar c = charIt.text()[0]; -
trunk/Source/WebCore/editing/VisibleSelection.h
r261776 r265044 72 72 VisiblePosition visibleBase() const { return VisiblePosition(m_base, isRange() ? (isBaseFirst() ? UPSTREAM : DOWNSTREAM) : affinity()); } 73 73 VisiblePosition visibleExtent() const { return VisiblePosition(m_extent, isRange() ? (isBaseFirst() ? DOWNSTREAM : UPSTREAM) : affinity()); } 74 75 operator VisiblePositionRange() const { return { visibleStart(), visibleEnd() }; } 74 76 75 77 bool isNone() const { return selectionType() == NoSelection; } -
trunk/Source/WebCore/editing/VisibleUnits.cpp
r261776 r265044 1906 1906 if (a.isNull() || b.isNull()) 1907 1907 return 0; 1908 return a < b 1909 ? -characterCount({ *makeBoundaryPoint(a), *makeBoundaryPoint(b) }) 1910 : characterCount({ *makeBoundaryPoint(b), *makeBoundaryPoint(a) }); 1908 return a < b ? -characterCount(*makeSimpleRange(a, b)) : characterCount(*makeSimpleRange(b, a)); 1911 1909 } 1912 1910 … … 1935 1933 1936 1934 if (startPosition != endPosition) { 1937 String characterString = plainText( { *makeBoundaryPoint(startPosition), *makeBoundaryPoint(endPosition) }).replace(noBreakSpace, ' ');1935 String characterString = plainText(*makeSimpleRange(startPosition, endPosition)).replace(noBreakSpace, ' '); 1938 1936 for (int i = characterString.length() - 1, index = 0; i >= 0 && index < maxCharacters; --i) { 1939 1937 if (!index && nextPosition.isNull()) … … 1949 1947 RefPtr<Range> wordRangeFromPosition(const VisiblePosition& position) 1950 1948 { 1951 // The selection could be in a non visible element and we don't have a VisiblePosition.1952 1949 if (position.isNull()) 1953 1950 return nullptr; … … 1967 1964 currentPosition = positionOfNextBoundaryOfGranularity(currentPosition, TextGranularity::WordGranularity, SelectionDirection::Backward); 1968 1965 } while (currentPosition.isNotNull() && !atBoundaryOfGranularity(currentPosition, TextGranularity::WordGranularity, SelectionDirection::Backward)); 1969 1970 1966 if (currentPosition.isNull()) 1971 1967 currentPosition = positionOfNextBoundaryOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Forward); … … 1982 1978 { 1983 1979 VisiblePosition result; 1984 1985 // move the position at the end of the word1986 1980 if (atBoundaryOfGranularity(position, TextGranularity::LineGranularity, SelectionDirection::Forward)) { 1987 1981 // Don't cross line boundaries. -
trunk/Source/WebCore/editing/cocoa/DataDetection.mm
r264311 r265044 74 74 return { }; 75 75 String fullPlainTextString = plainText(contextRange); 76 CFIndex hitLocation = characterCount( { contextRange.start, *makeBoundaryPoint(position) });76 CFIndex hitLocation = characterCount(*makeSimpleRange(contextRange.start, position)); 77 77 78 78 auto scanner = adoptCF(DDScannerCreate(DDScannerTypeStandard, 0, nullptr)); … … 273 273 } 274 274 275 static bool searchForLinkRemovingExistingDDLinks(Node& startNode, Node& endNode, bool& didModifyDOM) 276 { 277 didModifyDOM = false; 275 static bool searchForLinkRemovingExistingDDLinks(Node& startNode, Node& endNode) 276 { 278 277 for (Node* node = &startNode; node; node = NodeTraversal::next(*node)) { 279 278 if (is<HTMLAnchorElement>(*node)) { … … 282 281 return true; 283 282 removeResultLinksFromAnchor(anchor); 284 didModifyDOM = true;285 283 } 286 284 … … 292 290 return true; 293 291 removeResultLinksFromAnchor(anchor); 294 didModifyDOM = true;295 292 } 296 293 return false; … … 554 551 continue; 555 552 556 // Store the range boundaries as Position, because the DOM could change if we find557 // old data detector link.558 Vector<std::pair<Position, Position>> rangeBoundaries;559 rangeBoundaries.reserveInitialCapacity(resultRanges.size());560 for (auto& range : resultRanges)561 rangeBoundaries.uncheckedAppend({ createLegacyEditingPosition(range.start), createLegacyEditingPosition(range.end) });562 563 553 NSString *identifier = dataDetectorStringForPath(indexPaths[resultIndex].get()); 564 554 NSString *correspondingURL = constructURLStringForResult(coreResult, identifier, referenceDate, (NSTimeZone *)tz.get(), types); 565 bool didModifyDOM = false; 566 567 if (!correspondingURL || searchForLinkRemovingExistingDDLinks(resultRanges.first().start.container, resultRanges.last().end.container, didModifyDOM)) 555 556 if (!correspondingURL || searchForLinkRemovingExistingDDLinks(resultRanges.first().start.container, resultRanges.last().end.container)) 568 557 continue; 569 570 if (didModifyDOM) { 571 // If the DOM was modified because some old links were removed, 572 // we need to recreate the ranges because they could no longer be valid. 573 ASSERT(resultRanges.size() == rangeBoundaries.size()); 574 resultRanges.shrink(0); // Keep capacity as we are going to repopulate the Vector right away with the same number of items. 575 for (auto& rangeBoundary : rangeBoundaries) 576 resultRanges.uncheckedAppend({ *makeBoundaryPoint(rangeBoundary.first), *makeBoundaryPoint(rangeBoundary.second) }); 577 } 578 558 579 559 lastModifiedQueryOffset = queryRange.end; 580 560 BOOL shouldUseLightLinks = softLink_DataDetectorsCore_DDShouldUseLightLinksForResult(coreResult, [indexPaths[resultIndex] length] > 1); -
trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm
r264251 r265044 280 280 return WTF::nullopt; 281 281 282 auto lengthToSelectionStart = characterCount( { *makeBoundaryPoint(paragraphStart), *makeBoundaryPoint(selectionStart) });283 auto selectionCharacterCount = characterCount( { *makeBoundaryPoint(selectionStart), *makeBoundaryPoint(selectionEnd) });282 auto lengthToSelectionStart = characterCount(*makeSimpleRange(paragraphStart, selectionStart)); 283 auto selectionCharacterCount = characterCount(*makeSimpleRange(selectionStart, selectionEnd)); 284 284 NSRange rangeToPass = NSMakeRange(lengthToSelectionStart, selectionCharacterCount); 285 285 … … 329 329 330 330 // As context, we are going to use the surrounding paragraphs of text. 331 auto paragraphStart = makeBoundaryPoint(startOfParagraph(selectionStart)); 332 auto paragraphEnd = makeBoundaryPoint(endOfParagraph(selectionEnd)); 333 if (!paragraphStart || !paragraphEnd) 331 fullCharacterRange = makeSimpleRange(startOfParagraph(selectionStart), endOfParagraph(selectionEnd)); 332 if (!fullCharacterRange) 334 333 return WTF::nullopt; 335 334 336 fullCharacterRange = { { *paragraphStart, *paragraphEnd } }; 337 selectionRange = NSMakeRange(characterCount({ *paragraphStart, *makeBoundaryPoint(selectionStart) }), 338 characterCount({ *makeBoundaryPoint(selectionStart), *makeBoundaryPoint(selectionEnd) })); 339 hitIndex = characterCount({ *paragraphStart, *makeBoundaryPoint(position) }); 335 selectionRange = NSMakeRange(characterCount(*makeSimpleRange(fullCharacterRange->start, selectionStart)), 336 characterCount(*makeSimpleRange(selectionStart, selectionEnd))); 337 hitIndex = characterCount(*makeSimpleRange(fullCharacterRange->start, position)); 340 338 } else { 341 339 VisibleSelection selectionAccountingForLineRules { position }; … … 351 349 352 350 selectionRange = NSMakeRange(NSNotFound, 0); 353 hitIndex = characterCount( { fullCharacterRange->start, *makeBoundaryPoint(position) });351 hitIndex = characterCount(*makeSimpleRange(fullCharacterRange->start, position)); 354 352 } 355 353 -
trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
r262683 r265044 54 54 #import "PublicURLManager.h" 55 55 #import "Quirks.h" 56 #import "Range.h" 56 57 #import "RenderView.h" 57 58 #import "RuntimeEnabledFeatures.h" -
trunk/Source/WebCore/editing/ios/DictationCommandIOS.cpp
r264905 r265044 33 33 #include "Element.h" 34 34 #include "Position.h" 35 #include "Range.h"36 35 #include "SmartReplace.h" 37 36 #include "TextIterator.h" -
trunk/Source/WebCore/editing/mac/DictionaryLookupLegacy.mm
r264247 r265044 87 87 88 88 // As context, we are going to use the surrounding paragraphs of text. 89 auto paragraphStart = makeBoundaryPoint(startOfParagraph(selectionStart)); 90 auto paragraphEnd = makeBoundaryPoint(endOfParagraph(selectionEnd)); 91 if (!paragraphStart || !paragraphEnd) 92 return WTF::nullopt; 93 94 auto selectionRange = SimpleRange { *makeBoundaryPoint(selectionStart), *makeBoundaryPoint(selectionEnd) }; 95 auto paragraphRange = SimpleRange { *paragraphStart, *paragraphEnd }; 89 auto paragraphRange = makeSimpleRange(startOfParagraph(selectionStart), endOfParagraph(selectionEnd)); 90 if (!paragraphRange) 91 return WTF::nullopt; 92 93 auto selectionRange = *makeSimpleRange(selectionStart, selectionEnd); 96 94 97 95 NSDictionary *options = nil; 98 tokenRange(plainText( paragraphRange), characterRange(paragraphRange, selectionRange), &options);96 tokenRange(plainText(*paragraphRange), characterRange(*paragraphRange, selectionRange), &options); 99 97 100 98 return { { *selectedRange, options } }; … … 134 132 return WTF::nullopt; 135 133 136 auto fullCharacterStart = makeBoundaryPoint(fullCharacterRange->startPosition()); 137 auto positionBoundary = makeBoundaryPoint(position); 138 if (!fullCharacterStart || !positionBoundary) 139 return WTF::nullopt; 140 141 NSRange rangeToPass = NSMakeRange(characterCount({ *fullCharacterStart, *positionBoundary }), 0); 134 auto rangeToPosition = makeSimpleRange(fullCharacterRange->startPosition(), position); 135 if (!rangeToPosition) 136 return WTF::nullopt; 137 138 NSRange rangeToPass = NSMakeRange(characterCount(*rangeToPosition), 0); 142 139 NSDictionary *options = nil; 143 140 auto extractedRange = tokenRange(plainText(*fullCharacterRange), rangeToPass, &options); -
trunk/Source/WebCore/editing/mac/EditorMac.mm
r264692 r265044 46 46 #import "PasteboardStrategy.h" 47 47 #import "PlatformStrategies.h" 48 #import "Range.h"49 48 #import "RenderBlock.h" 50 49 #import "RenderImage.h" -
trunk/Source/WebCore/editing/markup.cpp
r264305 r265044 452 452 } 453 453 454 auto startBoundary = makeBoundaryPoint(start); 455 auto endBoundary = makeBoundaryPoint(end); 456 if (!startBoundary || !endBoundary) 457 return emptyString(); 458 459 return plainText({ WTFMove(*startBoundary), WTFMove(*endBoundary) }, behavior); 454 auto range = makeSimpleRange(start, end); 455 return range ? plainText(*range, behavior) : emptyString(); 460 456 } 461 457 -
trunk/Source/WebCore/editing/win/EditorWin.cpp
r264692 r265044 32 32 #include "FrameSelection.h" 33 33 #include "Pasteboard.h" 34 #include "Range.h" 34 35 #include "windows.h" 35 36 -
trunk/Source/WebCore/html/shadow/mac/ImageControlsButtonElementMac.cpp
r261013 r265044 36 36 #include "HTMLDivElement.h" 37 37 #include "Page.h" 38 #include "Range.h"39 38 #include "RenderBlockFlow.h" 40 39 #include "RenderStyle.h" -
trunk/Source/WebCore/page/DOMSelection.cpp
r261776 r265044 338 338 auto& selection = frame->selection(); 339 339 if (selection.isNone()) { 340 selection. moveTo(&range);340 selection.setSelection(SimpleRange { range }); 341 341 return; 342 342 } … … 357 357 } else { 358 358 // The new range contains the original range. 359 selection. moveTo(&range);359 selection.setSelection(SimpleRange { range }); 360 360 } 361 361 } … … 367 367 if (!result.hasException() && result.releaseReturnValue() == -1) { 368 368 // The original range contains the new range. 369 selection. moveTo(normalizedRange.get());369 selection.setSelection(SimpleRange { *normalizedRange }); 370 370 } else { 371 371 // The ranges intersect. -
trunk/Source/WebCore/page/EventHandler.cpp
r264692 r265044 676 676 static uint64_t textDistance(const Position& start, const Position& end) 677 677 { 678 auto startBoundary = makeBoundaryPoint(start); 679 auto endBoundary = makeBoundaryPoint(end); 680 if (!startBoundary || !endBoundary) 678 auto range = makeSimpleRange(start, end); 679 if (!range) 681 680 return 0; 682 return characterCount( { *startBoundary, *endBoundary }, TextIteratorEmitsCharactersBetweenAllVisiblePositions);681 return characterCount(*range, TextIteratorEmitsCharactersBetweenAllVisiblePositions); 683 682 } 684 683 -
trunk/Source/WebCore/page/Frame.cpp
r264692 r265044 820 820 { 821 821 auto position = visiblePositionForPoint(framePoint); 822 auto positionBoundary = makeBoundaryPoint(position);823 if (!positionBoundary)824 return nullptr;825 822 826 823 auto containerText = position.deepEquivalent().containerText(); … … 828 825 return nullptr; 829 826 830 if (auto previous = makeBoundaryPoint(position.previous())) { 831 auto previousCharacterRange = SimpleRange { *previous, *positionBoundary }; 832 if (editor().firstRectForRange(previousCharacterRange).contains(framePoint)) 833 return createLiveRange(previousCharacterRange); 834 } 835 836 if (auto next = makeBoundaryPoint(position.next())) { 837 auto nextCharacterRange = SimpleRange { *positionBoundary, *next }; 838 if (editor().firstRectForRange(nextCharacterRange).contains(framePoint)) 839 return createLiveRange(nextCharacterRange); 827 if (auto previousCharacterRange = makeSimpleRange(position.previous(), position)) { 828 if (editor().firstRectForRange(*previousCharacterRange).contains(framePoint)) 829 return createLiveRange(*previousCharacterRange); 830 } 831 832 if (auto nextCharacterRange = makeSimpleRange(position, position.next())) { 833 if (editor().firstRectForRange(*nextCharacterRange).contains(framePoint)) 834 return createLiveRange(*nextCharacterRange); 840 835 } 841 836 -
trunk/Source/WebCore/page/TextIndicator.cpp
r264585 r265044 225 225 226 226 RenderElement* renderer = nullptr; 227 auto commonAncestor = commonInclusiveAncestor(range .start.container, range.end.container);227 auto commonAncestor = commonInclusiveAncestor(range); 228 228 while (commonAncestor) { 229 229 if (is<RenderElement>(commonAncestor->renderer())) { … … 310 310 bool useBoundingRectAndPaintAllContentForComplexRanges = data.options.contains(TextIndicatorOption::UseBoundingRectAndPaintAllContentForComplexRanges); 311 311 if (useBoundingRectAndPaintAllContentForComplexRanges && containsOnlyWhiteSpaceText(range)) { 312 if (auto* containerRenderer = commonInclusiveAncestor(range .start.container, range.end.container)->renderer()) {312 if (auto* containerRenderer = commonInclusiveAncestor(range)->renderer()) { 313 313 data.options.add(TextIndicatorOption::PaintAllContent); 314 314 textRects.append(containerRenderer->absoluteBoundingBoxRect()); -
trunk/Source/WebKit/ChangeLog
r265043 r265044 1 2020-07-29 Darin Adler <darin@apple.com> 2 3 Improve range idioms and other changes to prepare the way for more reduction in live range use 4 https://bugs.webkit.org/show_bug.cgi?id=214882 5 6 Reviewed by Sam Weinig. 7 8 * WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp: 9 (WKBundleNodeHandleGetRenderRect): Emptied out this unused function and added 10 ASSERT_NOT_REACHED. Later, we can delete this once we deal with any link-time 11 dependencies. I believe Safari may link with this but never calls it. 12 (WKBundleNodeHandleCopyVisibleRange): Ditto. 13 (WKBundleNodeHandleSetHTMLInputElementSpellcheckEnabled): Ditto. 14 (WKBundleNodeHandleGetHTMLInputElementAutoFilled): Ditto. 15 (WKBundleNodeHandleGetHTMLInputElementAutoFillButtonEnabled): Ditto. 16 (WKBundleNodeHandleGetHTMLInputElementAutoFillAvailable): Ditto. 17 (WKBundleNodeHandleGetHTMLInputElementAutoFillButtonBounds): Ditto. 18 (WKBundleNodeHandleCopyHTMLTableCellElementCellAbove): Ditto. 19 (WKBundleNodeHandleCopyHTMLFrameElementContentFrame): Ditto. 20 (WKBundleNodeHandleGetHTMLInputElementAutofilled): Ditto. 21 (WKBundleNodeHandleSetHTMLInputElementAutofilled): Ditto. 22 (WKBundleNodeHandleSetHTMLInputElementAutoFillButtonEnabled): Ditto. 23 24 * WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm: 25 (WebKit::TextCheckingControllerProxy::annotatedSubstringBetweenPositions): 26 Simplify with makeSimpleRange. 27 28 * WebProcess/WebPage/glib/WebPageGLib.cpp: Added include of "Range.h", 29 may not be needed right now, but highly likely to be needed after 30 future live range work. 31 * WebProcess/WebPage/ios/WebPageIOS.mm: Ditto. 32 (WebKit::WebPage::selectWithGesture): Simplify with makeSimpleRange. 33 (WebKit::WebPage::requestDocumentEditingContext): Ditto. 34 35 * WebProcess/WebPage/mac/WebPageMac.mm: 36 (WebKit::WebPage::attributedSubstringForCharacterRangeAsync): 37 Use auto for range to prepare for possible change of type from live 38 range to SimpleRange. 39 1 40 2020-07-29 Noam Rosenthal <noam@webkit.org> 2 41 -
trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp
r248373 r265044 29 29 30 30 #include "InjectedBundleNodeHandle.h" 31 #include "InjectedBundleRangeHandle.h"32 31 #include "WKAPICast.h" 33 32 #include "WKBundleAPICast.h" … … 91 90 WKRect WKBundleNodeHandleGetRenderRect(WKBundleNodeHandleRef nodeHandleRef, bool* isReplaced) 92 91 { 93 return WebKit::toAPI(WebKit::toImpl(nodeHandleRef)->renderRect(isReplaced)); 92 ASSERT_NOT_REACHED(); 93 return { }; 94 94 } 95 95 … … 100 100 } 101 101 102 WKBundleRangeHandleRef WKBundleNodeHandleCopyVisibleRange(WKBundleNodeHandleRef nodeHandleRef)103 { 104 RefPtr<WebKit::InjectedBundleRangeHandle> rangeHandle = WebKit::toImpl(nodeHandleRef)->visibleRange();105 return toAPI(rangeHandle.leakRef());102 WKBundleRangeHandleRef WKBundleNodeHandleCopyVisibleRange(WKBundleNodeHandleRef) 103 { 104 ASSERT_NOT_REACHED(); 105 return nullptr; 106 106 } 107 107 … … 116 116 } 117 117 118 void WKBundleNodeHandleSetHTMLInputElementSpellcheckEnabled(WKBundleNodeHandleRef htmlInputElementHandleRef, bool enabled) 119 { 120 WebKit::toImpl(htmlInputElementHandleRef)->setHTMLInputElementSpellcheckEnabled(enabled); 121 } 122 123 bool WKBundleNodeHandleGetHTMLInputElementAutoFilled(WKBundleNodeHandleRef htmlInputElementHandleRef) 124 { 125 return WebKit::toImpl(htmlInputElementHandleRef)->isHTMLInputElementAutoFilled(); 118 void WKBundleNodeHandleSetHTMLInputElementSpellcheckEnabled(WKBundleNodeHandleRef, bool) 119 { 120 // FIXME: Would put ASSERT_NOT_REACHED() here but some compilers are warning the function is "noreturn". 121 } 122 123 bool WKBundleNodeHandleGetHTMLInputElementAutoFilled(WKBundleNodeHandleRef) 124 { 125 ASSERT_NOT_REACHED(); 126 return false; 126 127 } 127 128 … … 136 137 } 137 138 138 bool WKBundleNodeHandleGetHTMLInputElementAutoFillButtonEnabled(WKBundleNodeHandleRef htmlInputElementHandleRef) 139 { 140 return WebKit::toImpl(htmlInputElementHandleRef)->isHTMLInputElementAutoFillButtonEnabled(); 139 bool WKBundleNodeHandleGetHTMLInputElementAutoFillButtonEnabled(WKBundleNodeHandleRef) 140 { 141 ASSERT_NOT_REACHED(); 142 return false; 141 143 } 142 144 … … 156 158 } 157 159 158 bool WKBundleNodeHandleGetHTMLInputElementAutoFillAvailable(WKBundleNodeHandleRef htmlInputElementHandleRef) 159 { 160 return WebKit::toImpl(htmlInputElementHandleRef)->isAutoFillAvailable(); 160 bool WKBundleNodeHandleGetHTMLInputElementAutoFillAvailable(WKBundleNodeHandleRef) 161 { 162 ASSERT_NOT_REACHED(); 163 return false; 161 164 } 162 165 … … 166 169 } 167 170 168 WKRect WKBundleNodeHandleGetHTMLInputElementAutoFillButtonBounds(WKBundleNodeHandleRef htmlInputElementHandleRef) 169 { 170 return WebKit::toAPI(WebKit::toImpl(htmlInputElementHandleRef)->htmlInputElementAutoFillButtonBounds()); 171 WKRect WKBundleNodeHandleGetHTMLInputElementAutoFillButtonBounds(WKBundleNodeHandleRef) 172 { 173 ASSERT_NOT_REACHED(); 174 return { }; 171 175 } 172 176 … … 181 185 } 182 186 183 WKBundleNodeHandleRef WKBundleNodeHandleCopyHTMLTableCellElementCellAbove(WKBundleNodeHandleRef htmlTableCellElementHandleRef)184 { 185 RefPtr<WebKit::InjectedBundleNodeHandle> nodeHandle = WebKit::toImpl(htmlTableCellElementHandleRef)->htmlTableCellElementCellAbove();186 return toAPI(nodeHandle.leakRef());187 WKBundleNodeHandleRef WKBundleNodeHandleCopyHTMLTableCellElementCellAbove(WKBundleNodeHandleRef) 188 { 189 ASSERT_NOT_REACHED(); 190 return nullptr; 187 191 } 188 192 … … 195 199 WKBundleFrameRef WKBundleNodeHandleCopyHTMLFrameElementContentFrame(WKBundleNodeHandleRef htmlFrameElementHandleRef) 196 200 { 197 RefPtr<WebKit::WebFrame> frame = WebKit::toImpl(htmlFrameElementHandleRef)->htmlFrameElementContentFrame();198 return toAPI(frame.leakRef());201 ASSERT_NOT_REACHED(); 202 return nullptr; 199 203 } 200 204 … … 205 209 } 206 210 207 // Deprecated - use WKBundleNodeHandleGetHTMLInputElementAutoFilled(WKBundleNodeHandleRef).208 211 bool WKBundleNodeHandleGetHTMLInputElementAutofilled(WKBundleNodeHandleRef htmlInputElementHandleRef) 209 212 { 210 return WebKit::toImpl(htmlInputElementHandleRef)->isHTMLInputElementAutoFilled(); 211 } 212 213 // Deprecated - use WKBundleNodeHandleSetHTMLInputElementAutoFilled(WKBundleNodeHandleRef, bool). 214 void WKBundleNodeHandleSetHTMLInputElementAutofilled(WKBundleNodeHandleRef htmlInputElementHandleRef, bool filled) 215 { 216 WebKit::toImpl(htmlInputElementHandleRef)->setHTMLInputElementAutoFilled(filled); 217 } 218 219 // Deprecated - use WKBundleNodeHandleSetHTMLInputElementAutoFillButtonEnabledWithButtonType(WKBundleNodeHandleRef, WKAutoFillButtonType). 220 void WKBundleNodeHandleSetHTMLInputElementAutoFillButtonEnabled(WKBundleNodeHandleRef htmlInputElementHandleRef, bool enabled) 221 { 222 WebCore::AutoFillButtonType autoFillButtonType = enabled ? WebCore::AutoFillButtonType::Credentials : WebCore::AutoFillButtonType::None; 223 224 WebKit::toImpl(htmlInputElementHandleRef)->setHTMLInputElementAutoFillButtonEnabled(autoFillButtonType); 225 } 213 ASSERT_NOT_REACHED(); 214 return false; 215 } 216 217 void WKBundleNodeHandleSetHTMLInputElementAutofilled(WKBundleNodeHandleRef handle, bool enabled) 218 { 219 WKBundleNodeHandleSetHTMLInputElementAutoFilled(handle, enabled); 220 } 221 222 void WKBundleNodeHandleSetHTMLInputElementAutoFillButtonEnabled(WKBundleNodeHandleRef, bool) 223 { 224 // FIXME: Would put ASSERT_NOT_REACHED() here but some compilers are warning the function is "noreturn". 225 } -
trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm
r260768 r265044 177 177 WebCore::AttributedString TextCheckingControllerProxy::annotatedSubstringBetweenPositions(const WebCore::VisiblePosition& start, const WebCore::VisiblePosition& end) 178 178 { 179 auto startBoundary = makeBoundaryPoint(start); 180 auto endBoundary = makeBoundaryPoint(end); 181 if (!startBoundary || !endBoundary) 179 auto entireRange = makeSimpleRange(start, end); 180 if (!entireRange) 182 181 return { }; 183 auto entireRange = SimpleRange { *startBoundary, *endBoundary };184 182 185 183 auto string = adoptNS([[NSMutableAttributedString alloc] init]); 186 184 187 for (TextIterator it( entireRange); !it.atEnd(); it.advance()) {185 for (TextIterator it(*entireRange); !it.atEnd(); it.advance()) { 188 186 if (!it.text().length()) 189 187 continue; … … 193 191 auto& data = WTF::get<DocumentMarker::PlatformTextCheckingData>(marker->data()); 194 192 auto subrange = resolveCharacterRange(range, { marker->startOffset(), marker->endOffset() - marker->startOffset() }); 195 [string addAttribute:data.key value:data.value range:characterRange( entireRange, subrange)];193 [string addAttribute:data.key value:data.value range:characterRange(*entireRange, subrange)]; 196 194 } 197 195 } -
trunk/Source/WebKit/WebProcess/WebPage/glib/WebPageGLib.cpp
r264692 r265044 40 40 #include <WebCore/HTMLInputElement.h> 41 41 #include <WebCore/HTMLTextAreaElement.h> 42 #include <WebCore/Range.h> 42 43 #include <WebCore/TextIterator.h> 43 44 #include <WebCore/VisiblePosition.h> -
trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
r264907 r265044 115 115 #import <WebCore/PointerCaptureController.h> 116 116 #import <WebCore/Quirks.h> 117 #import <WebCore/Range.h> 117 118 #import <WebCore/RenderBlock.h> 118 119 #import <WebCore/RenderImage.h> … … 1375 1376 GestureRecognizerState wkGestureState = static_cast<GestureRecognizerState>(gestureState); 1376 1377 switch (static_cast<GestureType>(gestureType)) { 1377 case GestureType::PhraseBoundary: 1378 { 1378 case GestureType::PhraseBoundary: { 1379 1379 if (!frame.editor().hasComposition()) 1380 1380 break; … … 4266 4266 4267 4267 auto makeString = [] (const VisiblePosition& start, const VisiblePosition& end) -> AttributedString { 4268 auto startBoundary = makeBoundaryPoint(start.deepEquivalent()); 4269 auto endBoundary = makeBoundaryPoint(end.deepEquivalent()); 4270 if (!startBoundary || !endBoundary || *startBoundary == *endBoundary) 4268 auto range = makeSimpleRange(start, end); 4269 if (!range || range->collapsed()) 4271 4270 return { }; 4272 4271 // FIXME: This should return editing-offset-compatible attributed strings if that option is requested. 4273 return { adoptNS([[NSAttributedString alloc] initWithString:WebCore::plainTextReplacingNoBreakSpace( { WTFMove(*startBoundary), WTFMove(*endBoundary) })]), nil };4272 return { adoptNS([[NSAttributedString alloc] initWithString:WebCore::plainTextReplacingNoBreakSpace(*range)]), nil }; 4274 4273 }; 4275 4274 … … 4306 4305 } else if (wantsMarkedTextRects && compositionRange) { 4307 4306 unsigned compositionStartOffset = 0; 4308 if (auto start = makeBoundaryPoint(contextBeforeStart.deepEquivalent()))4309 compositionStartOffset = WebCore::plainText({ WTFMove(*start), compositionRange->start }).length();4307 if (auto range = makeSimpleRange(contextBeforeStart, compositionRange->start)) 4308 compositionStartOffset = characterCount(*range); 4310 4309 context.textRects = characterRectsForRange(*compositionRange, compositionStartOffset); 4311 4310 } -
trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm
r264247 r265044 339 339 } 340 340 341 RefPtr<Range>range = EditingRange::toRange(frame, editingRange);341 auto range = EditingRange::toRange(frame, editingRange); 342 342 if (!range) { 343 343 send(Messages::WebPageProxy::AttributedStringForCharacterRangeCallback({ }, EditingRange(), callbackID)); -
trunk/Source/WebKitLegacy/ChangeLog
r263961 r265044 1 2020-07-29 Darin Adler <darin@apple.com> 2 3 Improve range idioms and other changes to prepare the way for more reduction in live range use 4 https://bugs.webkit.org/show_bug.cgi?id=214882 5 6 Reviewed by Sam Weinig. 7 8 * WebKitLegacy.xcodeproj/project.pbxproj: Removed singly-building 9 DOMUIKitExtensions.mm, which also is built in a unified source file. 10 We don't need to build it twice. 11 1 12 2020-07-05 Commit Queue <commit-queue@webkit.org> 2 13 -
trunk/Source/WebKitLegacy/WebKitLegacy.xcodeproj/project.pbxproj
r263961 r265044 189 189 5C97EF632342C534006020D4 /* UnifiedSource19-mm.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C97EF612342C534006020D4 /* UnifiedSource19-mm.mm */; }; 190 190 5C97EF642342C534006020D4 /* UnifiedSource20-mm.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C97EF622342C534006020D4 /* UnifiedSource20-mm.mm */; }; 191 5C9A4E5322DE4627007DB353 /* DOMUIKitExtensions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93D436371D57ABEE00AB85EA /* DOMUIKitExtensions.mm */; };192 191 5C9D925A22D7E8AD008E9266 /* Sources.txt in Resources */ = {isa = PBXBuildFile; fileRef = 5C9D925822D7E8AD008E9266 /* Sources.txt */; }; 193 192 5C9D925B22D7E8AD008E9266 /* SourcesCocoa.txt in Resources */ = {isa = PBXBuildFile; fileRef = 5C9D925922D7E8AD008E9266 /* SourcesCocoa.txt */; }; … … 3401 3400 1A60519117502A5D00BC62F5 /* BinaryPropertyList.cpp in Sources */, 3402 3401 B82958D4132707D0000D0E79 /* CorrectionPanel.mm in Sources */, 3403 5C9A4E5322DE4627007DB353 /* DOMUIKitExtensions.mm in Sources */,3404 3402 1A60519317502A5D00BC62F5 /* HistoryPropertyList.mm in Sources */, 3405 3403 1A8DED510EE88B8A00F25022 /* HostedNetscapePluginStream.mm in Sources */, -
trunk/Source/WebKitLegacy/mac/ChangeLog
r264905 r265044 1 2020-07-29 Darin Adler <darin@apple.com> 2 3 Improve range idioms and other changes to prepare the way for more reduction in live range use 4 https://bugs.webkit.org/show_bug.cgi?id=214882 5 6 Reviewed by Sam Weinig. 7 8 * WebCoreSupport/WebEditorClient.mm: 9 (insertionPointFromCurrentSelection): Simplify with makeSimpleRange. 10 (WebEditorClient::requestCandidatesForSelection): Ditto. 11 12 * WebView/WebFrame.mm: 13 (-[WebFrame _convertToDOMRange:rangeIsRelativeTo:]): Get rid of 14 unnecessary construction of a range just to get an end point. 15 (-[WebFrame wordOffsetInRange:]): Moved logic here from VisibleSelection. 16 (-[WebFrame spaceFollowsWordInRange:]): Ditto. 17 1 18 2020-07-23 Darin Adler <darin@apple.com> 2 19 -
trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm
r264905 r265044 1026 1026 { 1027 1027 auto selectionStart = selection.visibleStart(); 1028 auto selectionStartBoundary = makeBoundaryPoint(selectionStart); 1029 auto paragraphStart = makeBoundaryPoint(startOfParagraph(selectionStart)); 1030 if (!selectionStartBoundary || !paragraphStart) 1028 auto range = makeSimpleRange(startOfParagraph(selectionStart), selectionStart); 1029 if (!range) 1031 1030 return 0; 1032 return characterCount( { *paragraphStart, *selectionStartBoundary });1031 return characterCount(*range); 1033 1032 } 1034 1033 … … 1111 1110 1112 1111 auto selectionStart = selection.visibleStart(); 1113 auto selectionStartOffsetInParagraph = characterCount( { *makeBoundaryPoint(startOfParagraph(selectionStart)), *makeBoundaryPoint(selectionStart) });1114 auto selectionLength = characterCount( { *makeBoundaryPoint(selectionStart), *makeBoundaryPoint(selection.visibleEnd()) });1112 auto selectionStartOffsetInParagraph = characterCount(*makeSimpleRange(startOfParagraph(selectionStart), selectionStart)); 1113 auto selectionLength = characterCount(*makeSimpleRange(selectionStart, selection.visibleEnd())); 1115 1114 auto contextRangeForCandidateRequest = frame->editor().contextRangeForCandidateRequest(); 1116 1115 String contextForCandidateReqeuest = contextRangeForCandidateRequest ? plainText(*contextRangeForCandidateRequest) : String(); -
trunk/Source/WebKitLegacy/mac/WebView/WebFrame.mm
r264692 r265044 838 838 return nullptr; 839 839 840 auto scopeEnd = make RangeSelectingNodeContents(paragraphStart->container->treeScope().rootNode()).end;840 auto scopeEnd = makeBoundaryPointAfterNodeContents(paragraphStart->container->treeScope().rootNode()); 841 841 return createLiveRange(WebCore::resolveCharacterRange({ WTFMove(*paragraphStart), WTFMove(scopeEnd) }, range)); 842 842 } … … 1541 1541 - (int)wordOffsetInRange:(DOMRange *)range 1542 1542 { 1543 return core(self)->selection().wordOffsetInRange(core(range)); 1543 if (!range) 1544 return -1; 1545 1546 auto selection = core(self)->selection().selection(); 1547 if (!selection.isCaret()) 1548 return -1; 1549 1550 // FIXME: This will only work in cases where the selection remains in the same node after it is expanded. 1551 return std::max<int>(0, selection.start().deprecatedEditingOffset() - core(range)->startOffset()); 1544 1552 } 1545 1553 1546 1554 - (BOOL)spaceFollowsWordInRange:(DOMRange *)range 1547 1555 { 1548 return core(self)->selection().spaceFollowsWordInRange(core(range));1556 return range && isSpaceOrNewline(WebCore::VisiblePosition(createLegacyEditingPosition(makeSimpleRange(core(range))->end)).characterAfter()); 1549 1557 } 1550 1558 -
trunk/Source/WebKitLegacy/win/AccessibleTextImpl.cpp
r238454 r265044 99 99 return E_POINTER; 100 100 101 IntRect boundingRect = m_object->boundsForVisiblePositionRange(VisiblePositionRange(VisiblePosition(Position(node, offset, Position::PositionIsOffsetInAnchor)), VisiblePosition(Position(node, offset+1, Position::PositionIsOffsetInAnchor)))); 101 IntRect boundingRect = m_object->boundsForVisiblePositionRange({ 102 VisiblePosition(Position(node, offset, Position::PositionIsOffsetInAnchor)), 103 VisiblePosition(Position(node, offset + 1, Position::PositionIsOffsetInAnchor)) 104 }); 102 105 *width = boundingRect.width(); 103 106 *height = boundingRect.height();
Note: See TracChangeset
for help on using the changeset viewer.