Changeset 258525 in webkit
- Timestamp:
- Mar 16, 2020, 4:02:10 PM (6 years ago)
- Location:
- trunk/Source
- Files:
-
- 1 deleted
- 45 edited
-
WebCore/ChangeLog (modified) (2 diffs)
-
WebCore/Sources.txt (modified) (1 diff)
-
WebCore/WebCore.xcodeproj/project.pbxproj (modified) (2 diffs)
-
WebCore/accessibility/AXObjectCache.cpp (modified) (6 diffs)
-
WebCore/accessibility/AccessibilityObject.cpp (modified) (4 diffs)
-
WebCore/accessibility/AccessibilityObjectInterface.h (modified) (1 diff)
-
WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm (modified) (2 diffs)
-
WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm (modified) (2 diffs)
-
WebCore/dom/BoundaryPoint.cpp (deleted)
-
WebCore/dom/BoundaryPoint.h (modified) (3 diffs)
-
WebCore/dom/DocumentMarkerController.cpp (modified) (1 diff)
-
WebCore/dom/Position.cpp (modified) (19 diffs)
-
WebCore/dom/Position.h (modified) (11 diffs)
-
WebCore/dom/Range.cpp (modified) (1 diff)
-
WebCore/dom/Range.h (modified) (4 diffs)
-
WebCore/dom/SimpleRange.cpp (modified) (1 diff)
-
WebCore/dom/SimpleRange.h (modified) (1 diff)
-
WebCore/editing/ApplyStyleCommand.cpp (modified) (3 diffs)
-
WebCore/editing/Editing.cpp (modified) (2 diffs)
-
WebCore/editing/Editing.h (modified) (1 diff)
-
WebCore/editing/Editor.cpp (modified) (1 diff)
-
WebCore/editing/HTMLInterchange.cpp (modified) (3 diffs)
-
WebCore/editing/TextIterator.cpp (modified) (13 diffs)
-
WebCore/editing/TextIterator.h (modified) (6 diffs)
-
WebCore/editing/TextManipulationController.cpp (modified) (2 diffs)
-
WebCore/editing/VisibleSelection.cpp (modified) (1 diff)
-
WebCore/editing/VisibleUnits.cpp (modified) (3 diffs)
-
WebCore/editing/cocoa/DataDetection.mm (modified) (5 diffs)
-
WebCore/editing/cocoa/DictionaryLookup.mm (modified) (2 diffs)
-
WebCore/editing/cocoa/HTMLConverter.mm (modified) (2 diffs)
-
WebCore/page/TextIndicator.cpp (modified) (3 diffs)
-
WebCore/page/ios/FrameIOS.mm (modified) (2 diffs)
-
WebCore/rendering/HitTestResult.cpp (modified) (1 diff)
-
WebCore/rendering/line/LineLayoutTraversal.h (modified) (1 diff)
-
WebCore/testing/Internals.cpp (modified) (1 diff)
-
WebKit/ChangeLog (modified) (2 diffs)
-
WebKit/WebProcess/InjectedBundle/API/mac/WKDOMTextIterator.mm (modified) (6 diffs)
-
WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm (modified) (1 diff)
-
WebKit/WebProcess/WebPage/ViewGestureGeometryCollector.cpp (modified) (1 diff)
-
WebKit/WebProcess/WebPage/WebPage.cpp (modified) (1 diff)
-
WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (modified) (26 diffs)
-
WebKit/WebProcess/WebPage/mac/WebPageMac.mm (modified) (1 diff)
-
WebKitLegacy/mac/ChangeLog (modified) (1 diff)
-
WebKitLegacy/mac/WebView/WebFrame.mm (modified) (1 diff)
-
WebKitLegacy/mac/WebView/WebHTMLView.mm (modified) (1 diff)
-
WebKitLegacy/mac/WebView/WebTextIterator.mm (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r258522 r258525 1 2020-03-15 Darin Adler <darin@apple.com> 2 3 Move most of TextIterator off of live ranges 4 https://bugs.webkit.org/show_bug.cgi?id=209129 5 6 Reviewed by Antti Koivisto. 7 8 - Change almost all arguments and return values of functions in TextIterator.h 9 to use SimpleRange instead of live ranges. Exceptions are an overload of plainText 10 TextIterator::rangeLength, TextIterator::rangeFromLocationAndLength, 11 TextIterator::getLocationAndLengthFromRange, and TextIterator::subrange. Those 12 five are a little trickier to convert, so I will do them each in separate patches. 13 14 - Go with the flow in adding an include of Node.h to BoundaryPoint.h. I had avoided 15 this in the initial version, but now it seems practical to just leave it that way. 16 This led to removing BoundaryPoint.cpp and moving all functions to the header. 17 18 - Converted many member functions of the Position class from using int to unsigned 19 for offsets. The DOM specifies unsigned for offsets, but for some reason we used 20 int for them a lot historically, even though negative numbers don't make sense. 21 New classes like StaticRange, SimpleRange, and BoundaryPoint are already using 22 unsigned exclusively and we'll eventually convert everything. 23 24 - Remove includes of SimpleRange.h from files that also include TextIterator.h, 25 now that TextIterator.h pulls it in. 26 27 * Sources.txt: Removed BoundaryPoint.cpp. 28 * WebCore.xcodeproj/project.pbxproj: Ditto. 29 30 * accessibility/AXObjectCache.cpp: 31 (WebCore::AXObjectCache::traverseToOffsetInRange): Updated to pass a reference 32 to a range rather than a pointer, after null-checking it. 33 (WebCore::AXObjectCache::lengthForRange): Ditto. 34 (WebCore::AXObjectCache::nextBoundary): Ditto. 35 (WebCore::AXObjectCache::previousBoundary): Ditto. 36 * accessibility/AccessibilityObject.cpp: 37 (WebCore::AccessibilityObject::stringForRange const): Ditto. 38 (WebCore::AccessibilityObject::stringForVisiblePositionRange): Ditto. 39 (WebCore::AccessibilityObject::lengthForVisiblePositionRange const): Ditto. 40 41 * accessibility/AccessibilityObjectInterface.h: Removed an extra include. 42 43 * accessibility/ios/WebAccessibilityObjectWrapperIOS.mm: 44 (-[WebAccessibilityObjectWrapper arrayOfTextForTextMarkers:attributed:]): 45 Updated to pass a reference to a range rather than a pointer, after null-checking it. 46 * accessibility/mac/WebAccessibilityObjectWrapperMac.mm: 47 (-[WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange:spellCheck:]): Ditto. 48 49 * dom/BoundaryPoint.cpp: Removed. 50 51 * dom/BoundaryPoint.h: Removed redundant includes and forward declarations 52 since we're now committing to including "Node.h" here. Moved functions 53 all out of the .cpp file and made them inlines. 54 55 * dom/DocumentMarkerController.cpp: 56 (WebCore::DocumentMarkerController::collectTextRanges): Pass a reference to 57 a range instead of a pointer. 58 59 * dom/Position.cpp: 60 (WebCore::Position::Position): Take unsigned. 61 (WebCore::Position::moveToPosition): Ditto. 62 (WebCore::Position::moveToOffset): Ditto. 63 (WebCore::Position::parentAnchoredEquivalent const): Cast to unsigned. 64 (WebCore::Position::anchorTypeForLegacyEditingPosition): Take unsigned. 65 (WebCore::Position::previous const): Use unsigned. 66 (WebCore::Position::next const): Ditto. 67 (WebCore::Position::uncheckedPreviousOffset): Take unsigned. 68 (WebCore::Position::uncheckedPreviousOffsetForBackwardDeletion): Ditto. 69 (WebCore::Position::uncheckedNextOffset): Ditto. 70 (WebCore::Position::atLastEditingPositionForNode const): Cast to unsigned. 71 (WebCore::Position::atEndOfTree const): Ditto. 72 (WebCore::Position::rendersInDifferentPosition const): Added casts to 73 unsigned and also removed unneeded redundant checks. In a place where 74 we had already checked that both nodes were the same and both offsets 75 were different, we were checking the types of both nodes (but they are 76 the same so only need to check one) and we were checking that both 77 offsets were different (but we already knew they were different). 78 (WebCore::searchAheadForBetterMatch): Use unsigned. 79 (WebCore::Position::getInlineBoxAndOffset const): Ditto. 80 (WebCore::Position::equals const): Removed a cast to int. 81 (WebCore::makeBoundaryPoint): Moved this function here so now it can be 82 used in more places. 83 84 * dom/Position.h: Changed many argument types to unsigned. Moved declarations 85 of all the functions up above all the inline implementations of the functions 86 to separate interface from implementation a bit better. Wrote a FIXME about 87 the name createLegacyEditingPosition. Moved makeBoundaryPoint here and exported 88 it from WebCore so we can use it from more places. 89 90 * dom/Range.cpp: 91 (WebCore::createLiveRange): Moved these functions here from SimpleRange.cpp 92 because a live range is more advanced concept, so makes more sense for live 93 range to know about simple range rather than vice versa. 94 95 * dom/Range.h: Removed some unneeded includes and forward declarations. 96 Added a FIXME about renaming to LiveRange. Moved the createLiveRange 97 functions here. Moved declarations of functions above inline function bodies. 98 99 * dom/SimpleRange.cpp: 100 (WebCore::createLiveRange): Moved to Range.cpp. 101 102 * dom/SimpleRange.h: Exported the constructor. Removed unneeded overload 103 that takes a Range*. 104 105 * editing/ApplyStyleCommand.cpp: 106 (WebCore::ApplyStyleCommand::mergeStartWithPreviousIfIdentical): 107 Refactored code a bit and use unsigned. 108 (WebCore::ApplyStyleCommand::mergeEndWithNextIfIdentical): Use unsigned. 109 110 * editing/Editing.cpp: 111 (WebCore::visibleImageElementsInRangeWithNonLoadedImages): Use a reference 112 to a range rather than a pointer. 113 114 * editing/Editing.h: Added a forward declaration of Range that now seems to 115 be needed to compile. 116 117 * editing/Editor.cpp: 118 (WebCore::Editor::selectedText const): Call makeBoundaryPoint twice here to 119 convert two Position objects into a SimpleRange. 120 121 * editing/HTMLInterchange.cpp: Removed some extra includes. 122 (WebCore::convertHTMLTextToInterchangeFormat): Use variadic 123 StringBuilder::append. 124 125 * editing/TextIterator.cpp: 126 (WebCore::firstNode): Added. We use this instead of Range::firstNode. 127 If we find we need it outside TextIterator we can find a header for it. 128 Not sure it would be great to add it to in BoundaryPoint.h, nor is it 129 obviously better as a BoundaryPoint member function. 130 (WebCore::TextIterator::TextIterator): Cut down on the extra constructors 131 and have the single remaining one take a SimpleRange. 132 (WebCore::SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator): 133 Ditto. Also change some int to unsigned. 134 (WebCore::CharacterIterator::CharacterIterator): Ditto. 135 (WebCore::BackwardsCharacterIterator::BackwardsCharacterIterator): Ditto. 136 (WebCore::WordAwareIterator::WordAwareIterator): Ditto. 137 (WebCore::TextIterator::rangeLength): Since this is one of the functions 138 that still takes a live range pointer, updated it to check for null and 139 pass a reference rather than a pointer. 140 (WebCore::TextIterator::rangeFromLocationAndLength): Ditto. 141 (WebCore::hasAnyPlainText): Removed now-unneeded call to createLiveRange. 142 (WebCore::plainText): Updated the main implementation to take a SimpleRange, 143 eliminating the version that takes two Position objects, but keeping the 144 one that takes a live range pointer for now. 145 (WebCore::plainTextReplacingNoBreakSpace): Removed all but the one, and 146 have that one take a SimpleRange. 147 148 * editing/TextIterator.h: Removed the include of SimpleRange.h. Also 149 Updated for the changes above, eliminating five different constructors 150 that take a live range and also overloads that take two Position objects. 151 152 * editing/TextManipulationController.cpp: 153 (WebCore::ParagraphContentIterator::ParagraphContentIterator): 154 Call makeBoundaryPoint twice here to convert two Position objects into 155 a SimpleRange. 156 157 * editing/VisibleSelection.cpp: Removed an include. 158 159 * editing/VisibleUnits.cpp: 160 (WebCore::suffixLengthForRange): Pass a reference to a range known to 161 not be null. 162 (WebCore::previousBoundary): Ditto. 163 (WebCore::nextBoundary): Ditto. 164 165 * editing/cocoa/DataDetection.mm: 166 (WebCore::buildQuery): Take a SimpleRange. 167 (WebCore::DataDetection::detectContentInRange): Added a null check on 168 a live range and pass a reference to it. 169 * editing/cocoa/DictionaryLookup.mm: 170 (WebCOre::DictionaryLookup::rangeAtHitTestResult): Ditto. 171 172 * editing/cocoa/HTMLConverter.mm: 173 (WebCore::editingAttributedStringFromRange): Pass a reference to a range 174 known to not be null. 175 * page/TextIndicator.cpp: 176 (WebCore::estimatedTextColorsForRange): Ditto. 177 (WebCore::containsOnlyWhiteSpaceText): Ditto. 178 * page/ios/FrameIOS.mm: 179 (WebCore::Frame::interpretationsForCurrentRoot const): Ditto. 180 181 * rendering/HitTestResult.cpp: 182 (WebCore::HitTestResult::selectedText const): Added a null check on 183 a live range and pass a reference to it. 184 1 185 2020-03-16 Pinki Gyanchandani <pgyanchandani@apple.com> 2 186 … … 231 415 * Modules/mediastream/RTCRtpSender.cpp: 232 416 (WebCore::RTCRtpSender::dtmf): 417 418 * rendering/line/LineLayoutTraversal.h: Removed some unneeded includes. 419 * testing/Internals.cpp: Ditto. 233 420 234 421 2020-03-13 Sergio Villar Senin <svillar@igalia.com> -
trunk/Source/WebCore/Sources.txt
r258498 r258525 851 851 dom/BeforeTextInsertedEvent.cpp 852 852 dom/BeforeUnloadEvent.cpp 853 dom/BoundaryPoint.cpp854 853 dom/CDATASection.cpp 855 854 dom/CharacterData.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r258504 r258525 10709 10709 9316DDF8240C64B3009340AA /* SimpleRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleRange.h; sourceTree = "<group>"; }; 10710 10710 9316DDFA240C64B3009340AA /* SimpleRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SimpleRange.cpp; sourceTree = "<group>"; }; 10711 9316DDFD240C64F8009340AA /* BoundaryPoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BoundaryPoint.cpp; sourceTree = "<group>"; };10712 10711 9316DDFE240C64F8009340AA /* BoundaryPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BoundaryPoint.h; sourceTree = "<group>"; }; 10713 10712 931AE3B81FB80EAE00F5EFB2 /* JSValueInWrappedObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSValueInWrappedObject.h; sourceTree = "<group>"; }; … … 28324 28323 85031B270A44EFC700F992E0 /* BeforeUnloadEvent.h */, 28325 28324 7C1E8CFF1ED0C2BE00B1D983 /* BeforeUnloadEvent.idl */, 28326 9316DDFD240C64F8009340AA /* BoundaryPoint.cpp */,28327 28325 9316DDFE240C64F8009340AA /* BoundaryPoint.h */, 28328 28326 7C1E8D001ED0C2BE00B1D983 /* CallbackResult.h */, -
trunk/Source/WebCore/accessibility/AXObjectCache.cpp
r258475 r258525 100 100 #include "ScriptDisallowedScope.h" 101 101 #include "ScrollView.h" 102 #include "SimpleRange.h"103 102 #include "TextBoundaries.h" 104 103 #include "TextControlInnerElements.h" … … 1792 1791 int lastStartOffset = 0; 1793 1792 1794 TextIterator iterator( range.get(), doNotEnterTextControls ? TextIteratorDefaultBehavior : TextIteratorEntersTextControls);1793 TextIterator iterator(*range, doNotEnterTextControls ? TextIteratorDefaultBehavior : TextIteratorEntersTextControls); 1795 1794 1796 1795 // When the range has zero length, there might be replaced node or brTag that we need to increment the characterOffset. … … 1903 1902 return -1; 1904 1903 int length = 0; 1905 for (TextIterator it( range); !it.atEnd(); it.advance()) {1904 for (TextIterator it(*range); !it.atEnd(); it.advance()) { 1906 1905 // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX) 1907 1906 if (it.text().length()) … … 2603 2602 CharacterOffset end = startOrEndCharacterOffsetForRange(searchRange, false); 2604 2603 2605 TextIterator it( searchRange.get(), TextIteratorEmitsObjectReplacementCharacters);2604 TextIterator it(*searchRange, TextIteratorEmitsObjectReplacementCharacters); 2606 2605 unsigned next = forwardSearchForBoundaryWithTextIterator(it, string, prefixLength, searchFunction); 2607 2606 … … 2644 2643 if (!setRangeStartOrEndWithCharacterOffset(forwardsScanRange, endOfCurrentParagraph, false)) 2645 2644 return { }; 2646 for (TextIterator forwardsIterator(forwardsScanRange .ptr()); !forwardsIterator.atEnd(); forwardsIterator.advance())2645 for (TextIterator forwardsIterator(forwardsScanRange); !forwardsIterator.atEnd(); forwardsIterator.advance()) 2647 2646 append(string, forwardsIterator.text()); 2648 2647 suffixLength = string.size(); … … 2667 2666 2668 2667 auto& node = it.atEnd() ? searchRange->startContainer() : it.range().start.container.get(); 2669 2668 2670 2669 // SimplifiedBackwardsTextIterator ignores replaced elements. 2671 2670 if (AccessibilityObject::replacedNodeNeedsCharacter(characterOffset.node)) -
trunk/Source/WebCore/accessibility/AccessibilityObject.cpp
r258250 r258525 1268 1268 return String(); 1269 1269 1270 TextIterator it( range.get());1270 TextIterator it(*range); 1271 1271 if (it.atEnd()) 1272 1272 return String(); … … 1297 1297 StringBuilder builder; 1298 1298 RefPtr<Range> range = makeRange(visiblePositionRange.start, visiblePositionRange.end); 1299 for (TextIterator it(range.get()); !it.atEnd(); it.advance()) { 1299 if (!range) 1300 return String(); 1301 1302 for (TextIterator it(*range); !it.atEnd(); it.advance()) { 1300 1303 // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX) 1301 1304 if (it.text().length()) { … … 1319 1322 return -1; 1320 1323 1324 RefPtr<Range> range = makeRange(visiblePositionRange.start, visiblePositionRange.end); 1325 if (!range) 1326 return -1; 1327 1321 1328 int length = 0; 1322 RefPtr<Range> range = makeRange(visiblePositionRange.start, visiblePositionRange.end); 1323 for (TextIterator it(range.get()); !it.atEnd(); it.advance()) { 1329 for (TextIterator it(*range); !it.atEnd(); it.advance()) { 1324 1330 // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX) 1325 1331 if (it.text().length()) … … 1330 1336 } 1331 1337 } 1332 1333 1338 return length; 1334 1339 } -
trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h
r258475 r258525 30 30 #include "Range.h" 31 31 #include "TextIterator.h" 32 #include "TextIteratorBehavior.h"33 32 #include "VisiblePosition.h" 34 33 #include "VisibleSelection.h" -
trunk/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm
r258475 r258525 55 55 #import "SVGElement.h" 56 56 #import "SelectionRect.h" 57 #import "SimpleRange.h"58 57 #import "TextIterator.h" 59 58 #import "WAKScrollView.h" … … 2254 2253 if (endVisiblePosition.isNull()) 2255 2254 return nil; 2256 2255 2256 auto range = makeRange(startVisiblePosition, endVisiblePosition); 2257 if (!range) 2258 return nil; 2259 2257 2260 // iterate over the range to build the AX attributed string 2258 2261 NSMutableArray* array = [[NSMutableArray alloc] init]; 2259 TextIterator it( makeRange(startVisiblePosition, endVisiblePosition).get());2262 TextIterator it(*range); 2260 2263 for (; !it.atEnd(); it.advance()) { 2261 2264 Node& node = it.range().start.container; -
trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm
r258475 r258525 71 71 #import "RenderWidget.h" 72 72 #import "ScrollView.h" 73 #import "SimpleRange.h"74 73 #import "TextCheckerClient.h" 75 74 #import "TextCheckingHelper.h" … … 1256 1255 RefPtr<Range> range = [protectedSelf rangeForTextMarkerRange:textMarkerRange]; 1257 1256 NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] init]; 1258 TextIterator it(range.get()); 1257 if (!range) 1258 return nil; 1259 TextIterator it(*range); 1259 1260 while (!it.atEnd()) { 1260 1261 Node& node = it.range().start.container; -
trunk/Source/WebCore/dom/BoundaryPoint.h
r258248 r258525 28 28 #include "Node.h" 29 29 30 #include <wtf/Ref.h>31 32 30 namespace WebCore { 33 34 class Document;35 31 36 32 struct BoundaryPoint { … … 44 40 BoundaryPoint(BoundaryPoint&&) = default; 45 41 BoundaryPoint& operator=(const BoundaryPoint&); 46 BoundaryPoint& operator=(BoundaryPoint&&) ;42 BoundaryPoint& operator=(BoundaryPoint&&) = default; 47 43 48 44 Document& document() const; … … 57 53 } 58 54 55 inline BoundaryPoint::BoundaryPoint(const BoundaryPoint& other) 56 : container(other.container.copyRef()) 57 , offset(other.offset) 58 { 59 } 60 61 inline BoundaryPoint& BoundaryPoint::operator=(const BoundaryPoint& other) 62 { 63 container = other.container.copyRef(); 64 offset = other.offset; 65 return *this; 66 } 67 68 inline Document& BoundaryPoint::document() const 69 { 70 return container->document(); 71 } 72 59 73 inline bool operator==(const BoundaryPoint& a, const BoundaryPoint& b) 60 74 { -
trunk/Source/WebCore/dom/DocumentMarkerController.cpp
r258250 r258525 64 64 { 65 65 Vector<RefPtr<Range>> textRange; 66 for (TextIterator textIterator( &range); !textIterator.atEnd(); textIterator.advance())66 for (TextIterator textIterator(range); !textIterator.atEnd(); textIterator.advance()) 67 67 textRange.append(createLiveRange(textIterator.range())); 68 68 return textRange; -
trunk/Source/WebCore/dom/Position.cpp
r258475 r258525 1 1 /* 2 * Copyright (C) 2004 , 2005, 2006, 2009, 2013Apple Inc. All rights reserved.2 * Copyright (C) 2004-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 126 126 } 127 127 128 Position::Position(Node* anchorNode, intoffset, AnchorType anchorType)128 Position::Position(Node* anchorNode, unsigned offset, AnchorType anchorType) 129 129 : m_anchorNode(anchorNode) 130 130 , m_offset(offset) … … 146 146 } 147 147 148 void Position::moveToPosition(Node* node, intoffset)148 void Position::moveToPosition(Node* node, unsigned offset) 149 149 { 150 150 ASSERT(!editingIgnoresContent(*node)); … … 155 155 m_anchorType = anchorTypeForLegacyEditingPosition(m_anchorNode.get(), m_offset); 156 156 } 157 void Position::moveToOffset(int offset) 157 158 void Position::moveToOffset(unsigned offset) 158 159 { 159 160 ASSERT(anchorType() == PositionIsOffsetInAnchor || m_isLegacyEditingPosition); … … 248 249 } 249 250 250 return { containerNode(), computeOffsetInContainerNode(), PositionIsOffsetInAnchor };251 return { containerNode(), static_cast<unsigned>(computeOffsetInContainerNode()), PositionIsOffsetInAnchor }; 251 252 } 252 253 … … 307 308 } 308 309 309 Position::AnchorType Position::anchorTypeForLegacyEditingPosition(Node* anchorNode, intoffset)310 Position::AnchorType Position::anchorTypeForLegacyEditingPosition(Node* anchorNode, unsigned offset) 310 311 { 311 312 if (anchorNode && editingIgnoresContent(*anchorNode)) { … … 332 333 return *this; 333 334 334 int offset = deprecatedEditingOffset();335 335 // FIXME: Negative offsets shouldn't be allowed. We should catch this earlier. 336 ASSERT(offset >= 0); 336 ASSERT(deprecatedEditingOffset() >= 0); 337 338 unsigned offset = deprecatedEditingOffset(); 337 339 338 340 if (anchorType() == PositionIsBeforeAnchor) { … … 385 387 return *this; 386 388 387 int offset = deprecatedEditingOffset();388 389 // FIXME: Negative offsets shouldn't be allowed. We should catch this earlier. 389 ASSERT(offset >= 0); 390 ASSERT(deprecatedEditingOffset() >= 0); 391 392 unsigned offset = deprecatedEditingOffset(); 390 393 391 394 if (anchorType() == PositionIsAfterAnchor) { … … 398 401 399 402 Node* child = node->traverseToChildAt(offset); 400 if (child || (!node->hasChildNodes() && offset < lastOffsetForEditing(*node))) {403 if (child || (!node->hasChildNodes() && offset < static_cast<unsigned>(lastOffsetForEditing(*node)))) { 401 404 if (child) 402 405 return firstPositionInOrBeforeNode(child); … … 424 427 } 425 428 426 int Position::uncheckedPreviousOffset(const Node* n, intcurrent)429 int Position::uncheckedPreviousOffset(const Node* n, unsigned current) 427 430 { 428 431 return n->renderer() ? n->renderer()->previousOffset(current) : current - 1; 429 432 } 430 433 431 int Position::uncheckedPreviousOffsetForBackwardDeletion(const Node* n, intcurrent)434 int Position::uncheckedPreviousOffsetForBackwardDeletion(const Node* n, unsigned current) 432 435 { 433 436 return n->renderer() ? n->renderer()->previousOffsetForBackwardDeletion(current) : current - 1; 434 437 } 435 438 436 int Position::uncheckedNextOffset(const Node* n, intcurrent)439 int Position::uncheckedNextOffset(const Node* n, unsigned current) 437 440 { 438 441 return n->renderer() ? n->renderer()->nextOffset(current) : current + 1; … … 463 466 if (isNull()) 464 467 return true; 465 // FIXME: Position after anchor shouldn't be considered as at the first editing position for node 466 // since that position resides outside of the node. 467 return m_anchorType == PositionIsAfterAnchor || m_anchorType == PositionIsAfterChildren || m_offset >= lastOffsetForEditing(*deprecatedNode()); 468 // FIXME: Position after anchor shouldn't be considered as at the first editing position for node since that position resides outside of the node. 469 return m_anchorType == PositionIsAfterAnchor || m_anchorType == PositionIsAfterChildren || m_offset >= static_cast<unsigned>(lastOffsetForEditing(*deprecatedNode())); 468 470 } 469 471 … … 542 544 switch (m_anchorType) { 543 545 case PositionIsOffsetInAnchor: 544 return m_offset >= lastOffsetForEditing(*m_anchorNode);546 return m_offset >= static_cast<unsigned>(lastOffsetForEditing(*m_anchorNode)); 545 547 case PositionIsBeforeAnchor: 546 548 return false; … … 1039 1041 return false; 1040 1042 1041 if (m_offset == position.deprecatedEditingOffset())1043 if (m_offset == static_cast<unsigned>(position.deprecatedEditingOffset())) 1042 1044 return false; 1043 1045 1044 if (!is<Text>(*deprecatedNode()) && !is<Text>(*position.deprecatedNode())) { 1045 if (m_offset != position.deprecatedEditingOffset()) 1046 return true; 1047 } 1046 if (!is<Text>(*deprecatedNode())) 1047 return true; 1048 1048 } 1049 1049 … … 1063 1063 return false; 1064 1064 1065 intthisRenderedOffset = is<RenderText>(*renderer) ? downcast<RenderText>(*renderer).countRenderedCharacterOffsetsUntil(m_offset) : m_offset;1066 intpositionRenderedOffset = is<RenderText>(*positionRenderer) ? downcast<RenderText>(*positionRenderer).countRenderedCharacterOffsetsUntil(position.m_offset) : position.m_offset;1065 unsigned thisRenderedOffset = is<RenderText>(*renderer) ? downcast<RenderText>(*renderer).countRenderedCharacterOffsetsUntil(m_offset) : m_offset; 1066 unsigned positionRenderedOffset = is<RenderText>(*positionRenderer) ? downcast<RenderText>(*positionRenderer).countRenderedCharacterOffsetsUntil(position.m_offset) : position.m_offset; 1067 1067 1068 1068 if (renderer == positionRenderer && thisRenderedOffset == positionRenderedOffset) … … 1092 1092 1093 1093 if (nextRenderedEditable(deprecatedNode()) == position.deprecatedNode() 1094 && thisRenderedOffset == caretMaxOffset(*deprecatedNode()) && !positionRenderedOffset) {1094 && thisRenderedOffset == static_cast<unsigned>(caretMaxOffset(*deprecatedNode())) && !positionRenderedOffset) { 1095 1095 return false; 1096 1096 } 1097 1097 1098 1098 if (previousRenderedEditable(deprecatedNode()) == position.deprecatedNode() 1099 && !thisRenderedOffset && positionRenderedOffset == caretMaxOffset(*position.deprecatedNode())) {1099 && !thisRenderedOffset && positionRenderedOffset == static_cast<unsigned>(caretMaxOffset(*position.deprecatedNode()))) { 1100 1100 return false; 1101 1101 } … … 1168 1168 if (is<RenderText>(*next)) { 1169 1169 InlineTextBox* match = nullptr; 1170 int minOffset = INT_MAX;1170 unsigned minOffset = std::numeric_limits<unsigned>::max(); 1171 1171 for (InlineTextBox* box = downcast<RenderText>(*next).firstTextBox(); box; box = box->nextTextBox()) { 1172 intcaretMinOffset = box->caretMinOffset();1172 unsigned caretMinOffset = box->caretMinOffset(); 1173 1173 if (caretMinOffset < minOffset) { 1174 1174 match = box; … … 1220 1220 1221 1221 for (box = textRenderer.firstTextBox(); box; box = box->nextTextBox()) { 1222 intcaretMinOffset = box->caretMinOffset();1223 intcaretMaxOffset = box->caretMaxOffset();1224 1225 if ( caretOffset < caretMinOffset || caretOffset > caretMaxOffset || (caretOffset== caretMaxOffset && box->isLineBreak()))1222 unsigned caretMinOffset = box->caretMinOffset(); 1223 unsigned caretMaxOffset = box->caretMaxOffset(); 1224 1225 if (static_cast<unsigned>(caretOffset) < caretMinOffset || static_cast<unsigned>(caretOffset) > caretMaxOffset || (static_cast<unsigned>(caretOffset) == caretMaxOffset && box->isLineBreak())) 1226 1226 continue; 1227 1227 1228 if ( caretOffset > caretMinOffset && caretOffset< caretMaxOffset) {1228 if (static_cast<unsigned>(caretOffset) > caretMinOffset && static_cast<unsigned>(caretOffset) < caretMaxOffset) { 1229 1229 inlineBox = box; 1230 1230 return; 1231 1231 } 1232 1232 1233 if ((( caretOffset== caretMaxOffset) ^ (affinity == DOWNSTREAM))1234 || (( caretOffset== caretMinOffset) ^ (affinity == UPSTREAM))1235 || ( caretOffset== caretMaxOffset && box->nextLeafOnLine() && box->nextLeafOnLine()->isLineBreak()))1233 if (((static_cast<unsigned>(caretOffset) == caretMaxOffset) ^ (affinity == DOWNSTREAM)) 1234 || ((static_cast<unsigned>(caretOffset) == caretMinOffset) ^ (affinity == UPSTREAM)) 1235 || (static_cast<unsigned>(caretOffset) == caretMaxOffset && box->nextLeafOnLine() && box->nextLeafOnLine()->isLineBreak())) 1236 1236 break; 1237 1237 … … 1479 1479 case PositionIsAfterChildren: 1480 1480 ASSERT(!is<Text>(*other.m_anchorNode)); 1481 return m_anchorNode == other.m_anchorNode && m_offset == static_cast<int>(other.m_anchorNode->countChildNodes());1481 return m_anchorNode == other.m_anchorNode && m_offset == other.m_anchorNode->countChildNodes(); 1482 1482 case PositionIsOffsetInAnchor: 1483 1483 return m_anchorNode == other.m_anchorNode && m_offset == other.m_offset; … … 1599 1599 } 1600 1600 1601 Optional<BoundaryPoint> makeBoundaryPoint(const Position& position) 1602 { 1603 if (position.isNull()) 1604 return WTF::nullopt; 1605 return BoundaryPoint { *position.containerNode(), static_cast<unsigned>(position.computeOffsetInContainerNode()) }; 1606 } 1607 1601 1608 } // namespace WebCore 1602 1609 -
trunk/Source/WebCore/dom/Position.h
r258475 r258525 1 1 /* 2 * Copyright (C) 2004 , 2006, 2008Apple Inc. All rights reserved.2 * Copyright (C) 2004-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 70 70 // For creating offset positions: 71 71 // FIXME: This constructor should eventually go away. See bug 63040. 72 WEBCORE_EXPORT Position(Node* anchorNode, intoffset, AnchorType);72 WEBCORE_EXPORT Position(Node* anchorNode, unsigned offset, AnchorType); 73 73 74 74 AnchorType anchorType() const { return static_cast<AnchorType>(m_anchorType); } … … 122 122 // These should only be used for PositionIsOffsetInAnchor positions, unless 123 123 // the position is a legacy editing position. 124 void moveToPosition(Node* anchorNode, intoffset);125 void moveToOffset( intoffset);124 void moveToPosition(Node* anchorNode, unsigned offset); 125 void moveToOffset(unsigned offset); 126 126 127 127 bool isNull() const { return !m_anchorNode; } … … 136 136 WEBCORE_EXPORT Position previous(PositionMoveType = CodePoint) const; 137 137 WEBCORE_EXPORT Position next(PositionMoveType = CodePoint) const; 138 static int uncheckedPreviousOffset(const Node*, intcurrent);139 static int uncheckedPreviousOffsetForBackwardDeletion(const Node*, intcurrent);140 static int uncheckedNextOffset(const Node*, intcurrent);138 static int uncheckedPreviousOffset(const Node*, unsigned current); 139 static int uncheckedPreviousOffsetForBackwardDeletion(const Node*, unsigned current); 140 static int uncheckedNextOffset(const Node*, unsigned current); 141 141 142 142 // These can be either inside or just before/after the node, depending on … … 207 207 Position nextCharacterPosition(EAffinity) const; 208 208 209 static AnchorType anchorTypeForLegacyEditingPosition(Node* anchorNode, intoffset);209 static AnchorType anchorTypeForLegacyEditingPosition(Node* anchorNode, unsigned offset); 210 210 211 211 RefPtr<Node> m_anchorNode; … … 213 213 // returns true, then other places in editing will treat m_offset == 0 as "before the anchor" 214 214 // and m_offset > 0 as "after the anchor node". See parentAnchoredEquivalent for more info. 215 intm_offset { 0 };215 unsigned m_offset { 0 }; 216 216 unsigned m_anchorType : 3; 217 217 bool m_isLegacyEditingPosition : 1; 218 218 }; 219 219 220 bool operator==(const Position&, const Position&); 221 bool operator!=(const Position&, const Position&); 222 bool operator<(const Position&, const Position&); 223 bool operator>(const Position&, const Position&); 224 bool operator>=(const Position&, const Position&); 225 bool operator<=(const Position&, const Position&); 226 227 // FIXME: Consider renaming this to "make" instead of "create" since we normally use "create" for functions that allocate heap objects. 228 Position createLegacyEditingPosition(Node*, unsigned offset); 220 229 Position createLegacyEditingPosition(const BoundaryPoint&); 230 231 WEBCORE_EXPORT Optional<BoundaryPoint> makeBoundaryPoint(const Position&); 232 233 Position positionInParentBeforeNode(Node*); 234 Position positionInParentAfterNode(Node*); 235 236 // positionBeforeNode and positionAfterNode return neighbor-anchored positions, construction is O(1) 237 Position positionBeforeNode(Node* anchorNode); 238 Position positionAfterNode(Node* anchorNode); 239 240 int lastOffsetInNode(Node*); 241 242 // firstPositionInNode and lastPositionInNode return parent-anchored positions, lastPositionInNode construction is O(n) due to countChildNodes() 243 Position firstPositionInNode(Node* anchorNode); 244 Position lastPositionInNode(Node* anchorNode); 245 246 int minOffsetForNode(Node* anchorNode, unsigned offset); 247 bool offsetIsBeforeLastNodeOffset(unsigned offset, Node* anchorNode); 248 249 RefPtr<Node> commonShadowIncludingAncestor(const Position&, const Position&); 250 251 WTF::TextStream& operator<<(WTF::TextStream&, const Position&); 252 253 // inlines 221 254 222 255 inline Position createLegacyEditingPosition(Node* node, unsigned offset) … … 261 294 } 262 295 263 Position positionInParentBeforeNode(Node*);264 Position positionInParentAfterNode(Node*);265 266 296 // positionBeforeNode and positionAfterNode return neighbor-anchored positions, construction is O(1) 267 297 inline Position positionBeforeNode(Node* anchorNode) … … 279 309 inline int lastOffsetInNode(Node* node) 280 310 { 281 return node->isCharacterDataNode() ? node->maxCharacterOffset() : static_cast<int>(node->countChildNodes());311 return node->isCharacterDataNode() ? node->maxCharacterOffset() : node->countChildNodes(); 282 312 } 283 313 … … 297 327 } 298 328 299 inline int minOffsetForNode(Node* anchorNode, intoffset)329 inline int minOffsetForNode(Node* anchorNode, unsigned offset) 300 330 { 301 331 if (anchorNode->isCharacterDataNode()) 302 return std::min (offset, anchorNode->maxCharacterOffset());303 304 intnewOffset = 0;332 return std::min<unsigned>(offset, anchorNode->maxCharacterOffset()); 333 334 unsigned newOffset = 0; 305 335 for (Node* node = anchorNode->firstChild(); node && newOffset < offset; node = node->nextSibling()) 306 336 newOffset++; … … 309 339 } 310 340 311 inline bool offsetIsBeforeLastNodeOffset( intoffset, Node* anchorNode)341 inline bool offsetIsBeforeLastNodeOffset(unsigned offset, Node* anchorNode) 312 342 { 313 343 if (anchorNode->isCharacterDataNode()) 314 return offset < anchorNode->maxCharacterOffset();315 316 intcurrentOffset = 0;344 return offset < static_cast<unsigned>(anchorNode->maxCharacterOffset()); 345 346 unsigned currentOffset = 0; 317 347 for (Node* node = anchorNode->firstChild(); node && currentOffset < offset; node = node->nextSibling()) 318 348 currentOffset++; … … 321 351 return offset < currentOffset; 322 352 } 323 324 RefPtr<Node> commonShadowIncludingAncestor(const Position&, const Position&);325 326 WTF::TextStream& operator<<(WTF::TextStream&, const Position&);327 353 328 354 } // namespace WebCore -
trunk/Source/WebCore/dom/Range.cpp
r254153 r258525 1870 1870 } 1871 1871 1872 Ref<Range> createLiveRange(const SimpleRange& range) 1873 { 1874 return Range::create(range.start.document(), range.start.container.ptr(), range.start.offset, range.end.container.ptr(), range.end.offset); 1875 } 1876 1877 RefPtr<Range> createLiveRange(const Optional<SimpleRange>& range) 1878 { 1879 if (!range) 1880 return nullptr; 1881 return createLiveRange(*range); 1882 } 1883 1872 1884 WTF::TextStream& operator<<(WTF::TextStream& ts, const RangeBoundaryPoint& r) 1873 1885 { -
trunk/Source/WebCore/dom/Range.h
r254153 r258525 4 4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no) 5 5 * (C) 2001 Peter Kelly (pmk@post.com) 6 * Copyright (C) 2004 , 2005, 2006, 2007, 2008, 2009Apple Inc. All rights reserved.6 * Copyright (C) 2004-2020 Apple Inc. All rights reserved. 7 7 * 8 8 * This library is free software; you can redistribute it and/or … … 28 28 #include "IntRect.h" 29 29 #include "RangeBoundaryPoint.h" 30 #include <wtf/Forward.h>31 30 #include <wtf/OptionSet.h> 32 #include <wtf/RefCounted.h>33 #include <wtf/Vector.h>34 31 35 32 namespace WebCore { 36 33 37 class ContainerNode;38 34 class DOMRect; 39 35 class DOMRectList; 40 class Document;41 36 class DocumentFragment; 42 37 class FloatQuad; 43 class Node;44 38 class NodeWithIndex; 45 39 class RenderText; … … 48 42 class VisiblePosition; 49 43 44 struct SimpleRange; 45 46 // FIXME: Rename to LiveRange, while leaving the DOM-exposed name as Range. 50 47 class Range : public RefCounted<Range> { 51 48 public: … … 186 183 WEBCORE_EXPORT bool rangesOverlap(const Range*, const Range*); 187 184 185 WEBCORE_EXPORT Ref<Range> createLiveRange(const SimpleRange&); 186 WEBCORE_EXPORT RefPtr<Range> createLiveRange(const Optional<SimpleRange>&); 187 188 bool documentOrderComparator(const Node*, const Node*); 189 190 WTF::TextStream& operator<<(WTF::TextStream&, const RangeBoundaryPoint&); 191 WTF::TextStream& operator<<(WTF::TextStream&, const Range&); 192 188 193 inline bool documentOrderComparator(const Node* a, const Node* b) 189 194 { 190 195 return Range::compareBoundaryPoints(const_cast<Node*>(a), 0, const_cast<Node*>(b), 0).releaseReturnValue() < 0; 191 196 } 192 193 WTF::TextStream& operator<<(WTF::TextStream&, const RangeBoundaryPoint&); 194 WTF::TextStream& operator<<(WTF::TextStream&, const Range&); 195 196 } // namespace 197 198 } // namespace WebCore 197 199 198 200 #if ENABLE(TREE_DEBUGGING) -
trunk/Source/WebCore/dom/SimpleRange.cpp
r258129 r258525 54 54 } 55 55 56 Ref<Range> createLiveRange(const SimpleRange& range)57 {58 return Range::create(range.start.document(), range.start.container.ptr(), range.start.offset, range.end.container.ptr(), range.end.offset);59 56 } 60 61 RefPtr<Range> createLiveRange(const Optional<SimpleRange>& range)62 {63 if (!range)64 return nullptr;65 return createLiveRange(*range);66 }67 68 } -
trunk/Source/WebCore/dom/SimpleRange.h
r258129 r258525 44 44 45 45 SimpleRange(const BoundaryPoint&, const BoundaryPoint&); 46 SimpleRange(BoundaryPoint&&, BoundaryPoint&&);46 WEBCORE_EXPORT SimpleRange(BoundaryPoint&&, BoundaryPoint&&); 47 47 48 // Convenience overloads to help with transition from using a lot of live ranges. 49 // FIXME: Move to the Range class header as either makeSimpleRange or Range::operator SimpleRange. 48 50 WEBCORE_EXPORT SimpleRange(const Range&); 49 50 // Convenience overloads to help with transition from using a lot of live ranges. Consider removing these eventually.51 SimpleRange(const Range*); // Crashes if passed a nullptr.52 51 SimpleRange(const Ref<Range>&); 53 52 }; 54 53 55 54 bool operator==(const SimpleRange&, const SimpleRange&); 56 57 WEBCORE_EXPORT Ref<Range> createLiveRange(const SimpleRange&);58 WEBCORE_EXPORT RefPtr<Range> createLiveRange(const Optional<SimpleRange>&);59 60 inline SimpleRange::SimpleRange(const Range* range)61 : SimpleRange(*range)62 {63 }64 55 65 56 inline SimpleRange::SimpleRange(const Ref<Range>& range) -
trunk/Source/WebCore/editing/ApplyStyleCommand.cpp
r258522 r258525 1267 1267 { 1268 1268 auto* startNode = start.containerNode(); 1269 int startOffset = start.computeOffsetInContainerNode(); 1270 if (startOffset) 1269 if (start.computeOffsetInContainerNode()) 1271 1270 return false; 1272 1271 … … 1290 1289 mergeIdenticalElements(previousElement, element); 1291 1290 1292 int startOffsetAdjustment = startChild->computeNodeIndex(); 1293 int endOffsetAdjustment = startNode == end.deprecatedNode() ? startOffsetAdjustment : 0; 1294 updateStartEnd({ startNode, startOffsetAdjustment, Position::PositionIsOffsetInAnchor}, 1295 { end.deprecatedNode(), end.deprecatedEditingOffset() + endOffsetAdjustment, Position::PositionIsOffsetInAnchor }); 1291 // FIXME: Inconsistent that we use computeOffsetInContainerNode for start, but deprecatedEditingOffset for end. 1292 unsigned startOffset = startChild->computeNodeIndex(); 1293 unsigned endOffset = end.deprecatedEditingOffset() + (startNode == end.deprecatedNode() ? startOffset : 0); 1294 updateStartEnd({ startNode, startOffset, Position::PositionIsOffsetInAnchor }, 1295 { end.deprecatedNode(), endOffset, Position::PositionIsOffsetInAnchor }); 1296 1296 return true; 1297 1297 } … … 1323 1323 1324 1324 bool shouldUpdateStart = start.containerNode() == endNode; 1325 intendOffset = nextChild ? nextChild->computeNodeIndex() : nextElement.countChildNodes();1325 unsigned endOffset = nextChild ? nextChild->computeNodeIndex() : nextElement.countChildNodes(); 1326 1326 updateStartEnd(shouldUpdateStart ? Position(&nextElement, start.offsetInContainerNode(), Position::PositionIsOffsetInAnchor) : start, 1327 1327 { &nextElement, endOffset, Position::PositionIsOffsetInAnchor }); -
trunk/Source/WebCore/editing/Editing.cpp
r258475 r258525 52 52 #include "RenderTableCell.h" 53 53 #include "ShadowRoot.h" 54 #include "SimpleRange.h"55 54 #include "Text.h" 56 55 #include "TextIterator.h" … … 1309 1308 { 1310 1309 HashSet<RefPtr<HTMLImageElement>> result; 1311 for (TextIterator iterator( &range); !iterator.atEnd(); iterator.advance()) {1310 for (TextIterator iterator(range); !iterator.atEnd(); iterator.advance()) { 1312 1311 if (!is<HTMLImageElement>(iterator.node())) 1313 1312 continue; -
trunk/Source/WebCore/editing/Editing.h
r256563 r258525 38 38 class HTMLSpanElement; 39 39 class HTMLTextFormControlElement; 40 class Range; 40 41 class RenderBlock; 41 42 class VisiblePosition; -
trunk/Source/WebCore/editing/Editor.cpp
r258475 r258525 3314 3314 // We remove '\0' characters because they are not visibly rendered to the user. 3315 3315 auto& selection = m_frame.selection().selection(); 3316 return plainText(selection.start(), selection.end(), behavior).replaceWithLiteral('\0', ""); 3316 auto start = selection.start(); 3317 auto end = selection.end(); 3318 if (start.isNull() || start.isOrphan() || end.isNull() || end.isOrphan()) 3319 return emptyString(); 3320 return plainText(SimpleRange { *makeBoundaryPoint(start), *makeBoundaryPoint(end) }, behavior).replaceWithLiteral('\0', ""); 3317 3321 } 3318 3322 -
trunk/Source/WebCore/editing/HTMLInterchange.cpp
r213355 r258525 28 28 29 29 #include "Editing.h" 30 #include "RenderElement.h"31 30 #include "RenderText.h" 32 31 #include "Text.h" 33 #include "TextIterator.h"34 32 #include <wtf/text/StringBuilder.h> 35 33 #include <wtf/unicode/CharacterNames.h> … … 63 61 switch (add) { 64 62 case 0: 65 s.appendLiteral(convertedSpaceString); 66 s.append(' '); 67 s.appendLiteral(convertedSpaceString); 63 s.append(convertedSpaceString, ' ', convertedSpaceString); 68 64 add = 3; 69 65 break; … … 77 73 if (i == 0) { 78 74 // at start of string 79 s.appendLiteral(convertedSpaceString); 80 s.append(' '); 75 s.append(convertedSpaceString, ' '); 81 76 } else if (i + 2 == in.length()) { 82 77 // at end of string 83 s.appendLiteral(convertedSpaceString); 84 s.appendLiteral(convertedSpaceString); 78 s.append(convertedSpaceString, convertedSpaceString); 85 79 } else { 86 s.appendLiteral(convertedSpaceString); 87 s.append(' '); 80 s.append(convertedSpaceString, ' '); 88 81 } 89 82 break; -
trunk/Source/WebCore/editing/TextIterator.cpp
r258475 r258525 330 330 // -------- 331 331 332 333 TextIterator::TextIterator(Position start, Position end, TextIteratorBehavior behavior) 332 static Node* firstNode(const BoundaryPoint& point) 333 { 334 if (point.container->isCharacterDataNode()) 335 return point.container.ptr(); 336 if (Node* child = point.container->traverseToChildAt(point.offset)) 337 return child; 338 if (!point.offset) 339 return point.container.ptr(); 340 return NodeTraversal::nextSkippingChildren(point.container); 341 } 342 343 TextIterator::TextIterator(const SimpleRange& range, TextIteratorBehavior behavior) 334 344 : m_behavior(behavior) 335 345 { 336 if (start.isNull() || end.isNull()) 337 return; 338 ASSERT(comparePositions(start, end) <= 0); 339 340 RELEASE_ASSERT(behavior & TextIteratorTraversesFlatTree || start.treeScope() == end.treeScope()); 341 342 start.document()->updateLayoutIgnorePendingStylesheets(); 343 344 // FIXME: Use Position / PositionIterator instead to avoid offset computation. 345 m_startContainer = start.containerNode(); 346 m_startOffset = start.computeOffsetInContainerNode(); 347 348 m_endContainer = end.containerNode(); 349 m_endOffset = end.computeOffsetInContainerNode(); 350 351 m_node = start.firstNode().get(); 352 if (!m_node) 353 return; 354 355 init(); 356 } 357 358 TextIterator::TextIterator(const Range* range, TextIteratorBehavior behavior) 359 : m_behavior(behavior) 360 { 361 if (!range) 362 return; 363 364 range->ownerDocument().updateLayoutIgnorePendingStylesheets(); 365 366 m_startContainer = &range->startContainer(); 367 368 // Callers should be handing us well-formed ranges. If we discover that this isn't 369 // the case, we could consider changing this assertion to an early return. 370 ASSERT(range->boundaryPointsValid()); 371 372 m_startOffset = range->startOffset(); 373 m_endContainer = &range->endContainer(); 374 m_endOffset = range->endOffset(); 375 376 m_node = range->firstNode(); 346 range.start.document().updateLayoutIgnorePendingStylesheets(); 347 348 m_startContainer = range.start.container.ptr(); 349 m_startOffset = range.start.offset; 350 m_endContainer = range.end.container.ptr(); 351 m_endOffset = range.end.offset; 352 353 m_node = firstNode(range.start); 377 354 if (!m_node) 378 355 return; … … 1141 1118 // -------- 1142 1119 1143 SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator(const Range& range)1144 { 1145 range. ownerDocument().updateLayoutIgnorePendingStylesheets();1146 1147 Node* startNode = &range.startContainer();1148 Node* endNode = &range.endContainer();1149 int startOffset = range.startOffset();1150 int endOffset = range.endOffset();1120 SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator(const SimpleRange& range) 1121 { 1122 range.start.document().updateLayoutIgnorePendingStylesheets(); 1123 1124 Node* startNode = range.start.container.ptr(); 1125 Node* endNode = range.end.container.ptr(); 1126 unsigned startOffset = range.start.offset; 1127 unsigned endOffset = range.end.offset; 1151 1128 1152 1129 if (!startNode->isCharacterDataNode()) { 1153 if (startOffset >= 0 && startOffset < static_cast<int>(startNode->countChildNodes())) {1130 if (startOffset < startNode->countChildNodes()) { 1154 1131 startNode = startNode->traverseToChildAt(startOffset); 1155 1132 startOffset = 0; … … 1157 1134 } 1158 1135 if (!endNode->isCharacterDataNode()) { 1159 if (endOffset > 0 && endOffset <= static_cast<int>(endNode->countChildNodes())) {1136 if (endOffset > 0 && endOffset <= endNode->countChildNodes()) { 1160 1137 endNode = endNode->traverseToChildAt(endOffset - 1); 1161 1138 endOffset = lastOffsetInNode(endNode); … … 1392 1369 // -------- 1393 1370 1394 CharacterIterator::CharacterIterator(const Range& range, TextIteratorBehavior behavior) 1395 : m_underlyingIterator(&range, behavior) 1396 { 1397 while (!atEnd() && !m_underlyingIterator.text().length()) 1398 m_underlyingIterator.advance(); 1399 } 1400 1401 CharacterIterator::CharacterIterator(Position start, Position end, TextIteratorBehavior behavior) 1402 : m_underlyingIterator(start, end, behavior) 1371 CharacterIterator::CharacterIterator(const SimpleRange& range, TextIteratorBehavior behavior) 1372 : m_underlyingIterator(range, behavior) 1403 1373 { 1404 1374 while (!atEnd() && !m_underlyingIterator.text().length()) … … 1484 1454 } 1485 1455 1486 BackwardsCharacterIterator::BackwardsCharacterIterator(const Range& range)1456 BackwardsCharacterIterator::BackwardsCharacterIterator(const SimpleRange& range) 1487 1457 : m_underlyingIterator(range) 1488 1458 { … … 1547 1517 // -------- 1548 1518 1549 WordAwareIterator::WordAwareIterator(const Range& range)1550 : m_underlyingIterator( &range)1519 WordAwareIterator::WordAwareIterator(const SimpleRange& range) 1520 : m_underlyingIterator(range) 1551 1521 { 1552 1522 advance(); // get in position over the first chunk of text … … 2376 2346 int TextIterator::rangeLength(const Range* range, bool forSelectionPreservation) 2377 2347 { 2348 if (!range) 2349 return 0; 2378 2350 unsigned length = 0; 2379 for (TextIterator it( range, forSelectionPreservation ? TextIteratorEmitsCharactersBetweenAllVisiblePositions : TextIteratorDefaultBehavior); !it.atEnd(); it.advance())2351 for (TextIterator it(*range, forSelectionPreservation ? TextIteratorEmitsCharactersBetweenAllVisiblePositions : TextIteratorDefaultBehavior); !it.atEnd(); it.advance()) 2380 2352 length += it.text().length(); 2381 2353 return length; … … 2406 2378 Ref<Range> textRunRange = rangeOfContents(*scope); 2407 2379 2408 TextIterator it(textRunRange .ptr(), forSelectionPreservation ? TextIteratorEmitsCharactersBetweenAllVisiblePositions : TextIteratorDefaultBehavior);2380 TextIterator it(textRunRange, forSelectionPreservation ? TextIteratorEmitsCharactersBetweenAllVisiblePositions : TextIteratorDefaultBehavior); 2409 2381 2410 2382 // FIXME: the atEnd() check shouldn't be necessary, workaround for <http://bugs.webkit.org/show_bug.cgi?id=6289>. … … 2507 2479 bool hasAnyPlainText(const SimpleRange& range, TextIteratorBehavior behavior) 2508 2480 { 2509 for (TextIterator iterator { createLiveRange(range).ptr(), behavior }; !iterator.atEnd(); iterator.advance()) {2481 for (TextIterator iterator { range, behavior }; !iterator.atEnd(); iterator.advance()) { 2510 2482 if (!iterator.text().isEmpty()) 2511 2483 return true; … … 2514 2486 } 2515 2487 2516 String plainText( Position start, Position end, TextIteratorBehavior defaultBehavior, bool isDisplayString)2488 String plainText(const SimpleRange& range, TextIteratorBehavior defaultBehavior, bool isDisplayString) 2517 2489 { 2518 2490 // The initial buffer size can be critical for performance: https://bugs.webkit.org/show_bug.cgi?id=81192 2519 2491 static const unsigned initialCapacity = 1 << 15; 2520 2492 2521 if (!start.document()) 2522 return { }; 2523 auto document = makeRef(*start.document()); 2493 auto document = makeRef(range.start.document()); 2524 2494 2525 2495 unsigned bufferLength = 0; … … 2530 2500 behavior = static_cast<TextIteratorBehavior>(behavior | TextIteratorEmitsTextsWithoutTranscoding); 2531 2501 2532 for (TextIterator it( start, end, behavior); !it.atEnd(); it.advance()) {2502 for (TextIterator it(range, behavior); !it.atEnd(); it.advance()) { 2533 2503 it.appendTextToStringBuilder(builder); 2534 2504 bufferLength += it.text().length(); … … 2546 2516 } 2547 2517 2548 String plainTextReplacingNoBreakSpace(Position start, Position end, TextIteratorBehavior defaultBehavior, bool isDisplayString)2549 {2550 return plainText(start, end, defaultBehavior, isDisplayString).replace(noBreakSpace, ' ');2551 }2552 2553 2518 String plainText(const Range* range, TextIteratorBehavior defaultBehavior, bool isDisplayString) 2554 2519 { 2555 2520 if (!range) 2556 2521 return emptyString(); 2557 return plainText( range->startPosition(), range->endPosition(), defaultBehavior, isDisplayString);2522 return plainText(*range, defaultBehavior, isDisplayString); 2558 2523 } 2559 2524 … … 2566 2531 } 2567 2532 2568 String plainTextReplacingNoBreakSpace(const Range*range, TextIteratorBehavior defaultBehavior, bool isDisplayString)2533 String plainTextReplacingNoBreakSpace(const SimpleRange& range, TextIteratorBehavior defaultBehavior, bool isDisplayString) 2569 2534 { 2570 2535 return plainText(range, defaultBehavior, isDisplayString).replace(noBreakSpace, ' '); -
trunk/Source/WebCore/editing/TextIterator.h
r258475 r258525 31 31 #include "TextIteratorBehavior.h" 32 32 #include <wtf/Vector.h> 33 #include <wtf/text/StringView.h>34 33 35 34 namespace WebCore { 36 35 37 36 class Range; 38 class RenderText;39 37 class RenderTextFragment; 40 38 41 WEBCORE_EXPORT String plainText(Position start, Position end, TextIteratorBehavior = TextIteratorDefaultBehavior, bool isDisplayString = false);42 WEBCORE_EXPORT String plainTextReplacingNoBreakSpace(Position start, Position end, TextIteratorBehavior = TextIteratorDefaultBehavior, bool isDisplayString = false);43 44 39 WEBCORE_EXPORT String plainText(const Range*, TextIteratorBehavior = TextIteratorDefaultBehavior, bool isDisplayString = false); 45 WEBCORE_EXPORT String plainTextReplacingNoBreakSpace(const Range*, TextIteratorBehavior = TextIteratorDefaultBehavior, bool isDisplayString = false); 40 WEBCORE_EXPORT String plainText(const SimpleRange&, TextIteratorBehavior = TextIteratorDefaultBehavior, bool isDisplayString = false); 41 WEBCORE_EXPORT String plainTextReplacingNoBreakSpace(const SimpleRange&, TextIteratorBehavior = TextIteratorDefaultBehavior, bool isDisplayString = false); 46 42 WEBCORE_EXPORT String plainTextUsingBackwardsTextIteratorForTesting(const SimpleRange&); 47 43 … … 92 88 WTF_MAKE_FAST_ALLOCATED; 93 89 public: 94 WEBCORE_EXPORT TextIterator(Position start, Position end, TextIteratorBehavior = TextIteratorDefaultBehavior); 95 WEBCORE_EXPORT explicit TextIterator(const Range*, TextIteratorBehavior = TextIteratorDefaultBehavior); 90 WEBCORE_EXPORT explicit TextIterator(const SimpleRange&, TextIteratorBehavior = TextIteratorDefaultBehavior); 96 91 WEBCORE_EXPORT ~TextIterator(); 97 92 … … 178 173 class SimplifiedBackwardsTextIterator { 179 174 public: 180 explicit SimplifiedBackwardsTextIterator(const Range&);175 explicit SimplifiedBackwardsTextIterator(const SimpleRange&); 181 176 182 177 bool atEnd() const { return !m_positionNode; } … … 233 228 class CharacterIterator { 234 229 public: 235 WEBCORE_EXPORT explicit CharacterIterator(const Range&, TextIteratorBehavior = TextIteratorDefaultBehavior); 236 WEBCORE_EXPORT explicit CharacterIterator(Position start, Position end, TextIteratorBehavior = TextIteratorDefaultBehavior); 230 WEBCORE_EXPORT explicit CharacterIterator(const SimpleRange&, TextIteratorBehavior = TextIteratorDefaultBehavior); 237 231 238 232 bool atEnd() const { return m_underlyingIterator.atEnd(); } … … 255 249 class BackwardsCharacterIterator { 256 250 public: 257 explicit BackwardsCharacterIterator(const Range&);251 explicit BackwardsCharacterIterator(const SimpleRange&); 258 252 259 253 bool atEnd() const { return m_underlyingIterator.atEnd(); } … … 274 268 class WordAwareIterator { 275 269 public: 276 explicit WordAwareIterator(const Range&);270 explicit WordAwareIterator(const SimpleRange&); 277 271 278 272 bool atEnd() const { return !m_didLookAhead && m_underlyingIterator.atEnd(); } -
trunk/Source/WebCore/editing/TextManipulationController.cpp
r258475 r258525 142 142 public: 143 143 ParagraphContentIterator(const Position& start, const Position& end) 144 : m_iterator( start, end)144 : m_iterator({ *makeBoundaryPoint(start), *makeBoundaryPoint(end) }) 145 145 , m_iteratorNode(m_iterator.atEnd() ? nullptr : createLiveRange(m_iterator.range())->firstNode()) 146 146 , m_currentNodeForFindingInvisibleContent(start.firstNode()) … … 463 463 HashMap<TokenIdentifier, TokenExchangeData> tokenExchangeMap; 464 464 465 if (item.start.isNull() &&item.end.isNull()) {465 if (item.start.isNull() || item.end.isNull()) { 466 466 RELEASE_ASSERT(item.tokens.size() == 1); 467 467 auto element = makeRefPtr(item.element.get()); -
trunk/Source/WebCore/editing/VisibleSelection.cpp
r258475 r258525 34 34 #include "Settings.h" 35 35 #include "ShadowRoot.h" 36 #include "SimpleRange.h"37 36 #include "TextIterator.h" 38 37 #include "VisibleUnits.h" -
trunk/Source/WebCore/editing/VisibleUnits.cpp
r258475 r258525 490 490 { 491 491 unsigned suffixLength = 0; 492 TextIterator forwardsIterator( &forwardsScanRange);492 TextIterator forwardsIterator(forwardsScanRange); 493 493 while (!forwardsIterator.atEnd()) { 494 494 StringView text = forwardsIterator.text(); … … 610 610 if (result.hasException()) 611 611 return { }; 612 for (TextIterator forwardsIterator(forwardsScanRange .ptr()); !forwardsIterator.atEnd(); forwardsIterator.advance())612 for (TextIterator forwardsIterator(forwardsScanRange); !forwardsIterator.atEnd(); forwardsIterator.advance()) 613 613 append(string, forwardsIterator.text()); 614 614 suffixLength = string.size(); … … 675 675 if (start.deprecatedNode()) 676 676 searchRange->setStart(*start.deprecatedNode(), start.deprecatedEditingOffset()); 677 TextIterator it(searchRange .ptr(), TextIteratorEmitsCharactersBetweenAllVisiblePositions);677 TextIterator it(searchRange, TextIteratorEmitsCharactersBetweenAllVisiblePositions); 678 678 unsigned next = forwardSearchForBoundaryWithTextIterator(it, string, prefixLength, searchFunction); 679 679 -
trunk/Source/WebCore/editing/cocoa/DataDetection.mm
r258250 r258525 44 44 #import "Range.h" 45 45 #import "RenderObject.h" 46 #import "SimpleRange.h"47 46 #import "StyleProperties.h" 48 47 #import "Text.h" … … 163 162 return detectItemAtPositionWithRange(position, contextRange, detectedDataBoundingBox, detectedDataRange); 164 163 } 164 165 165 #endif // PLATFORM(MAC) 166 166 … … 346 346 } 347 347 348 static void buildQuery(DDScanQueryRef scanQuery, Range*contextRange)348 static void buildQuery(DDScanQueryRef scanQuery, const SimpleRange& contextRange) 349 349 { 350 350 // Once we're over this number of fragments, stop at the first hard break. … … 445 445 NSArray *DataDetection::detectContentInRange(RefPtr<Range>& contextRange, DataDetectorTypes types, NSDictionary *context) 446 446 { 447 if (!contextRange) 448 return nil; 449 447 450 RetainPtr<DDScannerRef> scanner = adoptCF(softLink_DataDetectorsCore_DDScannerCreate(DDScannerTypeStandard, 0, nullptr)); 448 451 RetainPtr<DDScanQueryRef> scanQuery = adoptCF(softLink_DataDetectorsCore_DDScanQueryCreate(NULL)); 449 buildQuery(scanQuery.get(), contextRange.get());452 buildQuery(scanQuery.get(), *contextRange); 450 453 451 454 if (types & DataDetectorTypeLookupSuggestion) … … 488 491 489 492 Vector<Vector<RefPtr<Range>>> allResultRanges; 490 TextIterator iterator( contextRange.get());493 TextIterator iterator(*contextRange); 491 494 CFIndex iteratorCount = 0; 492 495 -
trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm
r252729 r258525 338 338 339 339 fullCharacterRange = makeRange(paragraphStart, paragraphEnd); 340 340 if (!fullCharacterRange) 341 return { nullptr, nil }; 342 341 343 selectionRange = NSMakeRange(TextIterator::rangeLength(rangeToSelectionStart.get()), TextIterator::rangeLength(makeRange(selectionStart, selectionEnd).get())); 342 344 … … 358 360 NSRange selectedRange = [getRVSelectionClass() revealRangeAtIndex:hitIndex selectedRanges:@[[NSValue valueWithRange:selectionRange]] shouldUpdateSelection:nil]; 359 361 360 String itemString = plainText( fullCharacterRange.get());362 String itemString = plainText(*fullCharacterRange); 361 363 RetainPtr<RVItem> item = adoptNS([allocRVItemInstance() initWithText:itemString selectedRange:selectedRange]); 362 364 NSRange highlightRange = item.get().highlightRange; -
trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm
r258250 r258525 62 62 #import "RenderImage.h" 63 63 #import "RenderText.h" 64 #import "SimpleRange.h"65 64 #import "StyleProperties.h" 66 65 #import "StyledElement.h" … … 2397 2396 RetainPtr<NSMutableDictionary> attrs = adoptNS([[NSMutableDictionary alloc] init]); 2398 2397 2399 for (TextIterator it( &range); !it.atEnd(); it.advance()) {2398 for (TextIterator it(range); !it.atEnd(); it.advance()) { 2400 2399 SimpleRange currentTextRange = it.range(); 2401 2400 Node& startContainer = currentTextRange.start.container; -
trunk/Source/WebCore/page/TextIndicator.cpp
r258129 r258525 44 44 #include "RenderObject.h" 45 45 #include "RenderText.h" 46 #include "SimpleRange.h"47 46 #include "TextIterator.h" 48 47 #include "TextPaintStyle.h" … … 214 213 { 215 214 HashSet<Color> colors; 216 for (TextIterator iterator( &range); !iterator.atEnd(); iterator.advance()) {215 for (TextIterator iterator(range); !iterator.atEnd(); iterator.advance()) { 217 216 auto* node = iterator.node(); 218 217 if (!is<Text>(node) || !is<RenderText>(node->renderer())) … … 300 299 return false; 301 300 } 302 return plainTextReplacingNoBreakSpace( &range).stripWhiteSpace().isEmpty();301 return plainTextReplacingNoBreakSpace(range).stripWhiteSpace().isEmpty(); 303 302 } 304 303 -
trunk/Source/WebCore/page/ios/FrameIOS.mm
r257592 r258525 761 761 762 762 auto rangeForMarker = Range::create(*document(), createLegacyEditingPosition(node, marker->startOffset()), createLegacyEditingPosition(node, marker->endOffset())); 763 String visibleTextForMarker = plainText(rangeForMarker .ptr());763 String visibleTextForMarker = plainText(rangeForMarker); 764 764 size_t interpretationsCountForCurrentMarker = marker->alternatives().size() + 1; 765 765 for (size_t i = 0; i < interpretationsCount; ++i) { … … 782 782 // Finally, add any text after the last marker. 783 783 auto afterLastMarkerRange = Range::create(*document(), precedingTextStartPosition, createLegacyEditingPosition(root, rootChildCount)); 784 String textAfterLastMarker = plainText(afterLastMarkerRange .ptr());784 String textAfterLastMarker = plainText(afterLastMarkerRange); 785 785 if (!textAfterLastMarker.isEmpty()) { 786 786 for (auto& interpretation : interpretations) -
trunk/Source/WebCore/rendering/HitTestResult.cpp
r258468 r258525 203 203 return emptyString(); 204 204 205 auto range = frame->selection().toNormalizedRange(); 206 if (!range) 207 return emptyString(); 208 205 209 // Look for a character that's not just a separator. 206 for (TextIterator it( frame->selection().toNormalizedRange().get()); !it.atEnd(); it.advance()) {210 for (TextIterator it(*range); !it.atEnd(); it.advance()) { 207 211 int length = it.text().length(); 208 212 for (int i = 0; i < length; ++i) { -
trunk/Source/WebCore/rendering/line/LineLayoutTraversal.h
r255143 r258525 30 30 #include "LineLayoutTraversalDisplayRunPath.h" 31 31 #include "LineLayoutTraversalSimplePath.h" 32 #include "RenderText.h"33 #include <wtf/HashMap.h>34 #include <wtf/IteratorRange.h>35 32 #include <wtf/Variant.h> 36 #include <wtf/text/StringView.h>37 33 38 34 namespace WebCore { 39 35 40 36 class RenderLineBreak; 37 class RenderText; 41 38 42 39 namespace LineLayoutTraversal { -
trunk/Source/WebCore/testing/Internals.cpp
r258475 r258525 175 175 #include "Settings.h" 176 176 #include "ShadowRoot.h" 177 #include "SimpleRange.h"178 177 #include "SourceBuffer.h" 179 178 #include "SpellChecker.h" -
trunk/Source/WebKit/ChangeLog
r258521 r258525 1 2020-03-15 Darin Adler <darin@apple.com> 2 3 Move most of TextIterator off of live ranges 4 https://bugs.webkit.org/show_bug.cgi?id=209129 5 6 Reviewed by Antti Koivisto. 7 8 * WebProcess/InjectedBundle/API/mac/WKDOMTextIterator.mm: 9 (-[WKDOMTextIterator initWithRange:]): Leave _textIterator as a nullptr 10 if the passed-in range is nil since we no longer offer a way to create 11 an empty TextIterator; other clients don't seem to need one. 12 (-[WKDOMTextIterator advance]): Add a null check. 13 (-[WKDOMTextIterator atEnd]): Ditto. 14 (-[WKDOMTextIterator currentRange]): Ditto. 15 (-[WKDOMTextIterator currentTextPointer]): Ditto. 16 (-[WKDOMTextIterator currentTextLength]): Ditto. 17 18 * WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm: Removed include. 19 20 * WebProcess/WebPage/ViewGestureGeometryCollector.cpp: 21 (WebKit::ViewGestureGeometryCollector::computeTextLegibilityScales): Pass 22 a reference to a range known not to be null. 23 24 * WebProcess/WebPage/WebPage.cpp: Removed an include. 25 26 * WebProcess/WebPage/ios/WebPageIOS.mm: Removed a "using naemsapce WebCore". 27 Added two local functions 28 (WebKit::plainTextForContext): Added. Helper for just this file where calling 29 plainTextReplacingNoBreakSpace on a possibly null Range is common. 30 (WebKit::plainTextForDisplay): Ditto. This one passes true for isDisplayString. 31 Not entirely clear how carefully we chose which of the two to call, or if there 32 is sufficient test coverage. 33 (WebKit::WebPage::platformEditorState const): Use plainTextForContext 34 and plainTextForDisplay. 35 (WebKit::WebPage::getSelectionContext): Ditto. 36 (WebKit::WebPage::getRectsAtSelectionOffsetWithText): Use plainTextForDisplay. 37 (WebKit::WebPage::requestDictationContext): Use plainTextForContext. 38 (WebKit::WebPage::replaceSelectedText): Ditto. 39 (WebKit::WebPage::replaceDictatedText): Ditto. 40 (WebKit::WebPage::requestAutocorrectionData): Ditto. 41 (WebKit::WebPage::applyAutocorrectionInternal): Ditto. 42 (WebKit::WebPage::autocorrectionContext): Ditto. 43 (WebKit::dataDetectorLinkPositionInformation): Use plainTextForDisplay. 44 (WebKit::WebPage::requestDocumentEditingContext): Use RetainPtr instead of 45 autorelease. Use makeBoundaryPoint to convert Position objects to SimpleRange. 46 1 47 2020-03-16 Chris Dumez <cdumez@apple.com> 2 48 … … 125 171 * WebProcess/cocoa/UserMediaCaptureManager.cpp: 126 172 (WebKit::UserMediaCaptureManager::Source::setShouldApplyRotation): 173 174 * WebProcess/WebPage/mac/WebPageMac.mm: Removed an include. 127 175 128 176 2020-03-13 Sergio Villar Senin <svillar@igalia.com> -
trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKDOMTextIterator.mm
r258250 r258525 29 29 #import "WKDOMInternals.h" 30 30 #import "WKDOMRange.h" 31 #import <WebCore/SimpleRange.h>32 31 #import <WebCore/TextIterator.h> 33 32 … … 47 46 return nil; 48 47 49 _textIterator = makeUnique<WebCore::TextIterator>(WebKit::toWebCoreRange(range)); 48 if (!range) 49 return self; 50 51 _textIterator = makeUnique<WebCore::TextIterator>(*WebKit::toWebCoreRange(range)); 50 52 return self; 51 53 } … … 53 55 - (void)advance 54 56 { 55 _textIterator->advance(); 57 if (_textIterator) 58 _textIterator->advance(); 56 59 _upconvertedText.shrink(0); 57 60 } … … 59 62 - (BOOL)atEnd 60 63 { 61 return _textIterator ->atEnd();64 return _textIterator && _textIterator->atEnd(); 62 65 } 63 66 64 67 - (WKDOMRange *)currentRange 65 68 { 66 return WebKit::toWKDOMRange(createLiveRange(_textIterator->range()).ptr());69 return _textIterator ? WebKit::toWKDOMRange(createLiveRange(_textIterator->range()).ptr()) : nil; 67 70 } 68 71 … … 70 73 - (const unichar*)currentTextPointer 71 74 { 75 if (!_textIterator) 76 return nullptr; 72 77 StringView text = _textIterator->text(); 73 78 unsigned length = text.length(); … … 84 89 - (NSUInteger)currentTextLength 85 90 { 86 return _textIterator ->text().length();91 return _textIterator ? _textIterator->text().length() : 0; 87 92 } 88 93 -
trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm
r258280 r258525 41 41 #import <WebCore/RenderObject.h> 42 42 #import <WebCore/RenderedDocumentMarker.h> 43 #import <WebCore/SimpleRange.h>44 43 #import <WebCore/TextIterator.h> 45 44 #import <WebCore/VisibleUnits.h> -
trunk/Source/WebKit/WebProcess/WebPage/ViewGestureGeometryCollector.cpp
r249435 r258525 162 162 unsigned totalSampledTextLength = 0; 163 163 164 for (TextIterator documentTextIterator { documentRange. ptr(), TextIteratorEntersTextControls }; !documentTextIterator.atEnd(); documentTextIterator.advance()) {164 for (TextIterator documentTextIterator { documentRange.get(), TextIteratorEntersTextControls }; !documentTextIterator.atEnd(); documentTextIterator.advance()) { 165 165 if (++numberOfIterations >= maximumNumberOfTextRunsToConsider) 166 166 break; -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r258421 r258525 227 227 #include <WebCore/ShadowRoot.h> 228 228 #include <WebCore/SharedBuffer.h> 229 #include <WebCore/SimpleRange.h>230 229 #include <WebCore/StyleProperties.h> 231 230 #include <WebCore/SubframeLoader.h> -
trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
r258475 r258525 125 125 #import <WebCore/ShadowRoot.h> 126 126 #import <WebCore/SharedBuffer.h> 127 #import <WebCore/SimpleRange.h>128 127 #import <WebCore/StyleProperties.h> 129 128 #import <WebCore/TextIndicator.h> … … 144 143 145 144 namespace WebKit { 146 using namespace WebCore; 145 146 // FIXME: Unclear if callers in this file are correctly choosing which of these two functions to use. 147 148 static String plainTextForContext(const Range* range) 149 { 150 if (!range) 151 return emptyString(); 152 return WebCore::plainTextReplacingNoBreakSpace(*range); 153 } 154 155 static String plainTextForDisplay(const Range* range) 156 { 157 if (!range) 158 return emptyString(); 159 return WebCore::plainTextReplacingNoBreakSpace(*range, TextIteratorDefaultBehavior, true); 160 } 147 161 148 162 void WebPage::platformInitialize() … … 229 243 else 230 244 result.lastMarkedRect = result.firstMarkedRect; 231 result.markedText = plainText ReplacingNoBreakSpace(compositionRange.get());245 result.markedText = plainTextForContext(compositionRange.get()); 232 246 } 233 247 } … … 259 273 // FIXME: The following check should take into account writing direction. 260 274 postLayoutData.isReplaceAllowed = result.isContentEditable && atBoundaryOfGranularity(selection.start(), WordGranularity, DirectionForward); 261 postLayoutData.wordAtSelection = plainText ReplacingNoBreakSpace(wordRangeFromPosition(selection.start()).get());275 postLayoutData.wordAtSelection = plainTextForContext(wordRangeFromPosition(selection.start()).get()); 262 276 if (selection.isContentEditable()) 263 277 charactersAroundPosition(selection.start(), postLayoutData.characterAfterSelection, postLayoutData.characterBeforeSelection, postLayoutData.twoCharacterBeforeSelection); … … 270 284 selectedRange->collectSelectionRects(postLayoutData.selectionRects); 271 285 convertSelectionRectsToRootView(view, postLayoutData.selectionRects); 272 selectedText = plainText ReplacingNoBreakSpace(selectedRange.get(), TextIteratorDefaultBehavior, true);286 selectedText = plainTextForDisplay(selectedRange.get()); 273 287 postLayoutData.selectedTextLength = selectedText.length(); 274 288 const int maxSelectedTextLength = 200; … … 503 517 const int selectionExtendedContextLength = 350; 504 518 505 String selectedText = plainText ReplacingNoBreakSpace(frame.selection().selection().toNormalizedRange().get());506 String textBefore = plainText ReplacingNoBreakSpace(rangeExpandedByCharactersInDirectionAtWordBoundary(frame.selection().selection().start(), selectionExtendedContextLength, DirectionBackward).get(), TextIteratorDefaultBehavior, true);507 String textAfter = plainText ReplacingNoBreakSpace(rangeExpandedByCharactersInDirectionAtWordBoundary(frame.selection().selection().end(), selectionExtendedContextLength, DirectionForward).get(), TextIteratorDefaultBehavior, true);519 String selectedText = plainTextForContext(frame.selection().selection().toNormalizedRange().get()); 520 String textBefore = plainTextForDisplay(rangeExpandedByCharactersInDirectionAtWordBoundary(frame.selection().selection().start(), selectionExtendedContextLength, DirectionBackward).get()); 521 String textAfter = plainTextForDisplay(rangeExpandedByCharactersInDirectionAtWordBoundary(frame.selection().selection().end(), selectionExtendedContextLength, DirectionForward).get()); 508 522 509 523 send(Messages::WebPageProxy::SelectionContextCallback(selectedText, textBefore, textAfter, callbackID)); … … 2007 2021 } 2008 2022 2009 if (plainText ReplacingNoBreakSpace(range.ptr(), TextIteratorDefaultBehavior, true) != text) {2023 if (plainTextForDisplay(range.ptr()) != text) { 2010 2024 // Try to search for a range which is the closest to the position within the selection range that matches the passed in text. 2011 2025 if (auto wordRange = rangeNearPositionMatchesText(startPosition, text, selection.toNormalizedRange())) { … … 2227 2241 String selectedText; 2228 2242 if (frame.selection().isRange()) 2229 selectedText = plainText ReplacingNoBreakSpace(frame.selection().selection().toNormalizedRange().get());2243 selectedText = plainTextForContext(frame.selection().selection().toNormalizedRange().get()); 2230 2244 2231 2245 String contextBefore; … … 2240 2254 } 2241 2255 if (lastPosition.isNotNull() && lastPosition != startPosition) 2242 contextBefore = plainText ReplacingNoBreakSpace(Range::create(*frame.document(), lastPosition, startPosition).ptr());2256 contextBefore = plainTextForContext(Range::create(*frame.document(), lastPosition, startPosition).ptr()); 2243 2257 } 2244 2258 … … 2254 2268 } 2255 2269 if (lastPosition.isNotNull() && lastPosition != endPosition) 2256 contextAfter = plainText ReplacingNoBreakSpace(Range::create(*frame.document(), endPosition, lastPosition).ptr());2270 contextAfter = plainTextForContext(Range::create(*frame.document(), endPosition, lastPosition).ptr()); 2257 2271 } 2258 2272 … … 2264 2278 Frame& frame = m_page->focusController().focusedOrMainFrame(); 2265 2279 RefPtr<Range> wordRange = frame.selection().isCaret() ? wordRangeFromPosition(frame.selection().selection().start()) : frame.selection().toNormalizedRange(); 2266 if (plainText ReplacingNoBreakSpace(wordRange.get()) != oldText)2280 if (plainTextForContext(wordRange.get()) != oldText) 2267 2281 return; 2268 2282 … … 2290 2304 auto range = Range::create(*frame.document(), position, frame.selection().selection().start()); 2291 2305 2292 if (plainText ReplacingNoBreakSpace(range.ptr()) != oldText)2306 if (plainTextForContext(range.ptr()) != oldText) 2293 2307 return; 2294 2308 … … 2315 2329 } 2316 2330 2317 auto textForRange = plainText ReplacingNoBreakSpace(range.get());2331 auto textForRange = plainTextForContext(range.get()); 2318 2332 const unsigned maxSearchAttempts = 5; 2319 2333 for (size_t i = 0; i < maxSearchAttempts && textForRange != textForAutocorrection; ++i) … … 2323 2337 break; 2324 2338 range = Range::create(*frame.document(), wordRangeFromPosition(position)->startPosition(), range->endPosition()); 2325 textForRange = plainText ReplacingNoBreakSpace(range.get());2339 textForRange = plainTextForContext(range.get()); 2326 2340 } 2327 2341 … … 2386 2400 VisiblePosition position = frame.selection().selection().start(); 2387 2401 range = wordRangeFromPosition(position); 2388 textForRange = plainText ReplacingNoBreakSpace(range.get());2402 textForRange = plainTextForContext(range.get()); 2389 2403 2390 2404 // If 'originalText' is not the same as 'textForRange' we need to move 'range' … … 2397 2411 position = startOfDocument(static_cast<Node*>(frame.document()->documentElement())); 2398 2412 range = Range::create(*frame.document(), position, frame.selection().selection().start()); 2399 textForRange = plainText ReplacingNoBreakSpace(range.get());2413 textForRange = plainTextForContext(range.get()); 2400 2414 unsigned loopCount = 0; 2401 2415 const unsigned maxPositionsAttempts = 10; … … 2406 2420 else 2407 2421 range = Range::create(*frame.document(), position, frame.selection().selection().start()); 2408 textForRange = plainText ReplacingNoBreakSpace(range.get());2422 textForRange = plainTextForContext(range.get()); 2409 2423 loopCount++; 2410 2424 } … … 2422 2436 return false; 2423 2437 2424 textForRange = plainText ReplacingNoBreakSpace(range.get());2438 textForRange = plainTextForContext(range.get()); 2425 2439 } 2426 2440 … … 2458 2472 2459 2473 if (frame.selection().isRange()) 2460 selectedText = plainText ReplacingNoBreakSpace(frame.selection().selection().toNormalizedRange().get());2474 selectedText = plainTextForContext(frame.selection().selection().toNormalizedRange().get()); 2461 2475 2462 2476 if (auto compositionRange = frame.editor().compositionRange()) { … … 2464 2478 String markedTextBefore; 2465 2479 if (range) 2466 markedTextBefore = plainText ReplacingNoBreakSpace(range.get());2480 markedTextBefore = plainTextForContext(range.get()); 2467 2481 range = Range::create(*frame.document(), endPosition, compositionRange->endPosition()); 2468 2482 String markedTextAfter; 2469 2483 if (range) 2470 markedTextAfter = plainText ReplacingNoBreakSpace(range.get());2484 markedTextAfter = plainTextForContext(range.get()); 2471 2485 markedText = markedTextBefore + selectedText + markedTextAfter; 2472 2486 if (!markedText.isEmpty()) { … … 2485 2499 if (previousPosition.isNull()) 2486 2500 break; 2487 String currentWord = plainText ReplacingNoBreakSpace(Range::create(*frame.document(), previousPosition, currentPosition).ptr());2501 String currentWord = plainTextForContext(Range::create(*frame.document(), previousPosition, currentPosition).ptr()); 2488 2502 totalContextLength += currentWord.length(); 2489 2503 if (totalContextLength >= maxContextLength) … … 2492 2506 } 2493 2507 if (currentPosition.isNotNull() && currentPosition != startPosition) { 2494 contextBefore = plainText ReplacingNoBreakSpace(Range::create(*frame.document(), currentPosition, startPosition).ptr());2508 contextBefore = plainTextForContext(Range::create(*frame.document(), currentPosition, startPosition).ptr()); 2495 2509 if (atBoundaryOfGranularity(currentPosition, ParagraphGranularity, DirectionBackward)) 2496 2510 contextBefore = makeString("\n "_s, contextBefore); … … 2503 2517 nextPosition = positionOfNextBoundaryOfGranularity(endPosition, WordGranularity, DirectionForward); 2504 2518 if (nextPosition.isNotNull()) 2505 contextAfter = plainText ReplacingNoBreakSpace(Range::create(*frame.document(), endPosition, nextPosition).ptr());2519 contextAfter = plainTextForContext(Range::create(*frame.document(), endPosition, nextPosition).ptr()); 2506 2520 } 2507 2521 } … … 2632 2646 auto linkRange = Range::create(element.document()); 2633 2647 linkRange->selectNodeContents(element); 2634 info.textBefore = plainText ReplacingNoBreakSpace(rangeExpandedByCharactersInDirectionAtWordBoundary(linkRange->startPosition(),2635 dataDetectionExtendedContextLength, DirectionBackward).get() , TextIteratorDefaultBehavior, true);2636 info.textAfter = plainText ReplacingNoBreakSpace(rangeExpandedByCharactersInDirectionAtWordBoundary(linkRange->endPosition(),2637 dataDetectionExtendedContextLength, DirectionForward).get() , TextIteratorDefaultBehavior, true);2648 info.textBefore = plainTextForDisplay(rangeExpandedByCharactersInDirectionAtWordBoundary(linkRange->startPosition(), 2649 dataDetectionExtendedContextLength, DirectionBackward).get()); 2650 info.textAfter = plainTextForDisplay(rangeExpandedByCharactersInDirectionAtWordBoundary(linkRange->endPosition(), 2651 dataDetectionExtendedContextLength, DirectionForward).get()); 2638 2652 } 2639 2653 #endif … … 4187 4201 } 4188 4202 4189 auto makeString = [&](VisiblePosition& start, VisiblePosition& end) -> NSAttributedString * { 4190 if (start.isNull() || end.isNull() || start == end) 4203 auto makeString = [] (const VisiblePosition& start, const VisiblePosition& end) -> RetainPtr<NSAttributedString> { 4204 auto startBoundary = makeBoundaryPoint(start.deepEquivalent()); 4205 auto endBoundary = makeBoundaryPoint(end.deepEquivalent()); 4206 if (!startBoundary || !endBoundary || *startBoundary == *endBoundary) 4191 4207 return nil; 4192 4208 // FIXME: This should return editing-offset-compatible attributed strings if that option is requested. 4193 return adoptNS([[NSAttributedString alloc] initWithString: plainTextReplacingNoBreakSpace(start.deepEquivalent(), end.deepEquivalent())]).autorelease();4209 return adoptNS([[NSAttributedString alloc] initWithString:WebCore::plainTextReplacingNoBreakSpace({ WTFMove(*startBoundary), WTFMove(*endBoundary) })]); 4194 4210 }; 4195 4211 4196 context.contextBefore = makeString(contextBeforeStart, startOfRangeOfInterestInSelection) ;4197 context.selectedText = makeString(startOfRangeOfInterestInSelection, endOfRangeOfInterestInSelection) ;4198 context.contextAfter = makeString(endOfRangeOfInterestInSelection, contextAfterEnd) ;4212 context.contextBefore = makeString(contextBeforeStart, startOfRangeOfInterestInSelection).get(); 4213 context.selectedText = makeString(startOfRangeOfInterestInSelection, endOfRangeOfInterestInSelection).get(); 4214 context.contextAfter = makeString(endOfRangeOfInterestInSelection, contextAfterEnd).get(); 4199 4215 if (compositionRange && rangesOverlap(rangeOfInterest.get(), compositionRange.get())) { 4200 4216 VisiblePosition compositionStart(compositionRange->startPosition()); 4201 4217 VisiblePosition compositionEnd(compositionRange->endPosition()); 4202 context.markedText = makeString(compositionStart, compositionEnd) ;4218 context.markedText = makeString(compositionStart, compositionEnd).get(); 4203 4219 context.selectedRangeInMarkedText.location = distanceBetweenPositions(startOfRangeOfInterestInSelection, compositionStart); 4204 4220 context.selectedRangeInMarkedText.length = [context.selectedText.string length]; … … 4227 4243 context.textRects = characterRectsForRange(*contextRange, 0); 4228 4244 } else if (wantsMarkedTextRects && compositionRange) { 4229 auto compositionStartOffset = plainTextReplacingNoBreakSpace(contextBeforeStart.deepEquivalent(), compositionRange->startPosition()).length(); 4245 auto start = makeBoundaryPoint(contextBeforeStart.deepEquivalent()); 4246 auto end = makeBoundaryPoint(compositionRange->startPosition()); 4247 unsigned compositionStartOffset = 0; 4248 if (start && end) 4249 compositionStartOffset = WebCore::plainText(SimpleRange { WTFMove(*start), WTFMove(*end) }).length(); 4230 4250 context.textRects = characterRectsForRange(*compositionRange, compositionStartOffset); 4231 4251 } -
trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm
r258129 r258525 87 87 #import <WebCore/RuntimeApplicationChecks.h> 88 88 #import <WebCore/ScrollView.h> 89 #import <WebCore/SimpleRange.h>90 89 #import <WebCore/StyleInheritedData.h> 91 90 #import <WebCore/TextIterator.h> -
trunk/Source/WebKitLegacy/mac/ChangeLog
r258519 r258525 1 2020-03-15 Darin Adler <darin@apple.com> 2 3 Move most of TextIterator off of live ranges 4 https://bugs.webkit.org/show_bug.cgi?id=209129 5 6 Reviewed by Antti Koivisto. 7 8 * WebView/WebFrame.mm: Removed an include. 9 10 * WebView/WebHTMLView.mm: 11 (-[WebHTMLView _legacyAttributedStringFrom:offset:to:offset:]): 12 Add casts to unsigned. 13 14 * WebView/WebTextIterator.mm: 15 (-[WebTextIterator initWithRange:]): Leave _private->_textIterator 16 as a nullptr if the passed-in range is nil since we no longer offer 17 a way to create an empty TextIterator; other clients don't seem to 18 need one. 19 (-[WebTextIterator advance]): Check _private->_textIterator for null. 20 (-[WebTextIterator atEnd]): Ditto. 21 (-[WebTextIterator currentRange]): Ditto. 22 (-[WebTextIterator currentTextPointer]): Ditto. 23 (-[WebTextIterator currentTextLength]): Ditto. 24 (-[WebTextIterator currentNode]): Ditto. 25 (-[WebTextIterator currentText]): Ditto. 26 1 27 2020-03-16 Timothy Horton <timothy_horton@apple.com> 2 28 -
trunk/Source/WebKitLegacy/mac/WebView/WebFrame.mm
r258339 r258525 101 101 #import <WebCore/ScriptController.h> 102 102 #import <WebCore/SecurityOrigin.h> 103 #import <WebCore/SimpleRange.h>104 103 #import <WebCore/SmartReplace.h> 105 104 #import <WebCore/StyleProperties.h> -
trunk/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm
r257592 r258525 7024 7024 { 7025 7025 return attributedStringBetweenStartAndEnd( 7026 WebCore::Position { core(startContainer), sta rtOffset, WebCore::Position::PositionIsOffsetInAnchor },7027 WebCore::Position { core(endContainer), endOffset, WebCore::Position::PositionIsOffsetInAnchor });7026 WebCore::Position { core(startContainer), static_cast<unsigned>(startOffset), WebCore::Position::PositionIsOffsetInAnchor }, 7027 WebCore::Position { core(endContainer), static_cast<unsigned>(endOffset), WebCore::Position::PositionIsOffsetInAnchor }); 7028 7028 } 7029 7029 -
trunk/Source/WebKitLegacy/mac/WebView/WebTextIterator.mm
r258250 r258525 31 31 #import <JavaScriptCore/InitializeThreading.h> 32 32 #import <WebCore/Range.h> 33 #import <WebCore/SimpleRange.h>34 33 #import <WebCore/TextIterator.h> 35 34 #import <wtf/MainThread.h> … … 71 70 72 71 _private = [[WebTextIteratorPrivate alloc] init]; 73 _private->_textIterator = makeUnique<WebCore::TextIterator>(core(range)); 72 if (!range) 73 return self; 74 75 _private->_textIterator = makeUnique<WebCore::TextIterator>(*core(range)); 74 76 return self; 75 77 } … … 77 79 - (void)advance 78 80 { 79 _private->_textIterator->advance(); 81 if (_private->_textIterator) 82 _private->_textIterator->advance(); 80 83 _private->_upconvertedText.shrink(0); 81 84 } … … 83 86 - (BOOL)atEnd 84 87 { 85 return _private->_textIterator ->atEnd();88 return _private->_textIterator && _private->_textIterator->atEnd(); 86 89 } 87 90 88 91 - (DOMRange *)currentRange 89 92 { 93 if (!_private->_textIterator) 94 return nil; 90 95 auto& textIterator = *_private->_textIterator; 91 96 if (textIterator.atEnd()) 92 return n ullptr;97 return nil; 93 98 return kit(createLiveRange(textIterator.range()).ptr()); 94 99 } … … 97 102 - (const unichar*)currentTextPointer 98 103 { 104 if (!_private->_textIterator) 105 return nullptr; 99 106 StringView text = _private->_textIterator->text(); 100 107 unsigned length = text.length(); … … 111 118 - (NSUInteger)currentTextLength 112 119 { 113 return _private->_textIterator ->text().length();120 return _private->_textIterator ? _private->_textIterator->text().length() : 0; 114 121 } 115 122 … … 120 127 - (DOMNode *)currentNode 121 128 { 122 return kit(_private->_textIterator->node());129 return _private->_textIterator ? kit(_private->_textIterator->node()) : nil; 123 130 } 124 131 125 132 - (NSString *)currentText 126 133 { 127 return [[_private->_textIterator->text().createNSString().get() retain] autorelease];134 return _private->_textIterator ? _private->_textIterator->text().createNSString().autorelease() : @""; 128 135 } 129 136
Note:
See TracChangeset
for help on using the changeset viewer.