Changeset 254557 in webkit
- Timestamp:
- Jan 14, 2020, 9:57:39 PM (7 years ago)
- Location:
- trunk/Source
- Files:
-
- 18 edited
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/accessibility/AXObjectCache.cpp (modified) (1 diff)
-
WebCore/accessibility/AccessibilityRenderObject.cpp (modified) (1 diff)
-
WebCore/accessibility/atk/WebKitAccessibleHyperlink.cpp (modified) (1 diff)
-
WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp (modified) (1 diff)
-
WebCore/accessibility/atk/WebKitAccessibleUtil.cpp (modified) (1 diff)
-
WebCore/editing/ApplyStyleCommand.cpp (modified) (2 diffs)
-
WebCore/editing/CompositeEditCommand.cpp (modified) (4 diffs)
-
WebCore/editing/Editing.cpp (modified) (2 diffs)
-
WebCore/editing/Editing.h (modified) (2 diffs)
-
WebCore/editing/TextIterator.cpp (modified) (3 diffs)
-
WebCore/editing/TextIterator.h (modified) (2 diffs)
-
WebCore/editing/TextIteratorBehavior.h (modified) (1 diff)
-
WebCore/editing/ios/DictationCommandIOS.cpp (modified) (1 diff)
-
WebCore/html/HTMLTextFormControlElement.cpp (modified) (1 diff)
-
WebCore/page/EventHandler.cpp (modified) (1 diff)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r254556 r254557 1 2020-01-14 Ryosuke Niwa <rniwa@webkit.org> 2 3 Enable the offset assertion in HTMLTextFormControlElement::indexForPosition 4 https://bugs.webkit.org/show_bug.cgi?id=205706 5 6 Reviewed by Darin Adler. 7 8 This patch fixes the erroneously disabled debug assertion in HTMLTextFormControlElement::indexForPosition. 9 10 It also fixes the bug that it was asserting even when VisiblePosition was null, and computed a wrong offset 11 when the entire input element is not visible (e.g. becaue height is 0px). 12 13 TextIterator::rangeLength and TextIterator::rangeFromLocationAndLength now takes an OptionSet of 14 newly added enum class TextIteratorLengthOption instead of a boolean indicating whether a space should be 15 generated for a replaced element. Most code changes are due to this refactoring. 16 17 No new tests since existing tests exercise this code. 18 19 * accessibility/AXObjectCache.cpp: 20 (WebCore::AXObjectCache::rangeMatchesTextNearRange): 21 * accessibility/AccessibilityRenderObject.cpp: 22 (WebCore::AccessibilityRenderObject::indexForVisiblePosition const): 23 * accessibility/atk/WebKitAccessibleInterfaceText.cpp: 24 (getSelectionOffsetsForObject): 25 * accessibility/atk/WebKitAccessibleUtil.cpp: 26 (objectFocusedAndCaretOffsetUnignored): 27 * editing/ApplyStyleCommand.cpp: 28 (WebCore::ApplyStyleCommand::applyBlockStyle): 29 * editing/CompositeEditCommand.cpp: 30 (WebCore::CompositeEditCommand::moveParagraphs): 31 * editing/Editing.cpp: 32 (WebCore::indexForVisiblePosition): 33 (WebCore::visiblePositionForIndex): 34 * editing/Editing.h: 35 (WebCore::indexForVisiblePosition): 36 * editing/TextIterator.cpp: 37 (WebCore::behaviorFromLegnthOptions): Added. 38 (WebCore::TextIterator::rangeLength): 39 (WebCore::TextIterator::rangeFromLocationAndLength): 40 * editing/TextIterator.h: 41 (WebCore::TextIterator::rangeLength): 42 (WebCore::TextIterator::rangeFromLocationAndLength): 43 * editing/TextIteratorBehavior.h: 44 * editing/ios/DictationCommandIOS.cpp: 45 (WebCore::DictationCommandIOS::doApply): 46 * html/HTMLTextFormControlElement.cpp: 47 (WebCore::HTMLTextFormControlElement::indexForPosition const): Enabled the assertion when VisiblePosition 48 is not null, and fixed the bug that the offset computed from VisiblePosition were always 0 when the input 49 element is not visible (e.g. has 0px size or has visibility: hidden). 50 * page/EventHandler.cpp: 51 (WebCore::textDistance): 52 1 53 2020-01-14 Chris Dumez <cdumez@apple.com> 2 54 -
trunk/Source/WebCore/accessibility/AXObjectCache.cpp
r254320 r254557 1934 1934 1935 1935 auto range = Range::create(m_document, startPosition, originalRange->startPosition()); 1936 unsigned targetOffset = TextIterator::rangeLength(range.ptr(), true);1936 unsigned targetOffset = TextIterator::rangeLength(range.ptr(), { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 1937 1937 return findClosestPlainText(searchRange.get(), matchText, { }, targetOffset); 1938 1938 } -
trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp
r253565 r254557 2033 2033 // We need to consider replaced elements for GTK, as they will be 2034 2034 // presented with the 'object replacement character' (0xFFFC). 2035 bool forSelectionPreservation = true;2035 return WebCore::indexForVisiblePosition(*node, position, { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 2036 2036 #else 2037 bool forSelectionPreservation = false;2037 return WebCore::indexForVisiblePosition(*node, position); 2038 2038 #endif 2039 2040 return WebCore::indexForVisiblePosition(*node, position, forSelectionPreservation);2041 2039 } 2042 2040 -
trunk/Source/WebCore/accessibility/atk/WebKitAccessibleHyperlink.cpp
r253261 r254557 155 155 { 156 156 // This is going to be the actual length in most of the cases 157 int baseLength = TextIterator::rangeLength(range, true);157 int baseLength = TextIterator::rangeLength(range, { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 158 158 159 159 // Check whether the current hyperlink belongs to a list item. -
trunk/Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp
r251798 r254557 411 411 // Set values for start offsets and calculate initial range length. 412 412 // These values might be adjusted later to cover special cases. 413 startOffset = webCoreOffsetToAtkOffset(coreObject, TextIterator::rangeLength(rangeInParent.ptr(), true));413 startOffset = webCoreOffsetToAtkOffset(coreObject, TextIterator::rangeLength(rangeInParent.ptr(), { TextIteratorLengthOption::GenerateSpacesForReplacedElements })); 414 414 auto nodeRange = Range::create(node->document(), nodeRangeStart, nodeRangeEnd); 415 int rangeLength = TextIterator::rangeLength(nodeRange.ptr(), true);415 int rangeLength = TextIterator::rangeLength(nodeRange.ptr(), { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 416 416 417 417 // Special cases that are only relevant when working with *_END boundaries. -
trunk/Source/WebCore/accessibility/atk/WebKitAccessibleUtil.cpp
r251798 r254557 248 248 else if (!isStartOfLine(endPosition)) { 249 249 RefPtr<Range> range = makeRange(startPosition, endPosition.previous()); 250 offset = TextIterator::rangeLength(range.get(), true) + 1;250 offset = TextIterator::rangeLength(range.get(), { TextIteratorLengthOption::GenerateSpacesForReplacedElements }) + 1; 251 251 } else { 252 252 RefPtr<Range> range = makeRange(startPosition, endPosition); 253 offset = TextIterator::rangeLength(range.get(), true);253 offset = TextIterator::rangeLength(range.get(), { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 254 254 } 255 255 -
trunk/Source/WebCore/editing/ApplyStyleCommand.cpp
r252392 r254557 253 253 auto startRange = Range::create(document(), firstPositionInNode(scope), visibleStart.deepEquivalent().parentAnchoredEquivalent()); 254 254 auto endRange = Range::create(document(), firstPositionInNode(scope), visibleEnd.deepEquivalent().parentAnchoredEquivalent()); 255 int startIndex = TextIterator::rangeLength(startRange.ptr(), true);256 int endIndex = TextIterator::rangeLength(endRange.ptr(), true);255 int startIndex = TextIterator::rangeLength(startRange.ptr(), { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 256 int endIndex = TextIterator::rangeLength(endRange.ptr(), { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 257 257 258 258 VisiblePosition paragraphStart(startOfParagraph(visibleStart)); … … 286 286 287 287 { 288 auto startRange = TextIterator::rangeFromLocationAndLength(scope, startIndex, 0, true);289 auto endRange = TextIterator::rangeFromLocationAndLength(scope, endIndex, 0, true);288 auto startRange = TextIterator::rangeFromLocationAndLength(scope, startIndex, 0, { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 289 auto endRange = TextIterator::rangeFromLocationAndLength(scope, endIndex, 0, { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 290 290 if (startRange && endRange) 291 291 updateStartEnd(startRange->startPosition(), endRange->startPosition()); -
trunk/Source/WebCore/editing/CompositeEditCommand.cpp
r253750 r254557 1434 1434 if (startInParagraph) { 1435 1435 auto startRange = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleStart.deepEquivalent().parentAnchoredEquivalent()); 1436 startIndex = TextIterator::rangeLength(startRange.ptr(), true);1436 startIndex = TextIterator::rangeLength(startRange.ptr(), { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 1437 1437 } 1438 1438 … … 1440 1440 if (endInParagraph) { 1441 1441 auto endRange = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleEnd.deepEquivalent().parentAnchoredEquivalent()); 1442 endIndex = TextIterator::rangeLength(endRange.ptr(), true);1442 endIndex = TextIterator::rangeLength(endRange.ptr(), { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 1443 1443 } 1444 1444 } … … 1511 1511 1512 1512 auto startToDestinationRange = Range::create(document(), firstPositionInNode(editableRoot.get()), destination.deepEquivalent().parentAnchoredEquivalent()); 1513 destinationIndex = TextIterator::rangeLength(startToDestinationRange.ptr(), true);1513 destinationIndex = TextIterator::rangeLength(startToDestinationRange.ptr(), { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 1514 1514 1515 1515 setEndingSelection(VisibleSelection(destination, originalIsDirectional)); … … 1533 1533 // in a call to rangeFromLocationAndLength with a location past the end 1534 1534 // of the document (which will return null). 1535 RefPtr<Range> start = TextIterator::rangeFromLocationAndLength(editableRoot.get(), destinationIndex + startIndex, 0, true); 1536 RefPtr<Range> end = TextIterator::rangeFromLocationAndLength(editableRoot.get(), destinationIndex + endIndex, 0, true); 1535 RefPtr<Range> start = TextIterator::rangeFromLocationAndLength(editableRoot.get(), destinationIndex + startIndex, 0, 1536 { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 1537 RefPtr<Range> end = TextIterator::rangeFromLocationAndLength(editableRoot.get(), destinationIndex + endIndex, 0, 1538 { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 1537 1539 if (start && end) 1538 1540 setEndingSelection(VisibleSelection(start->startPosition(), end->startPosition(), DOWNSTREAM, originalIsDirectional)); -
trunk/Source/WebCore/editing/Editing.cpp
r249605 r254557 1085 1085 1086 1086 auto range = Range::create(document, firstPositionInNode(scope.get()), position.parentAnchoredEquivalent()); 1087 return TextIterator::rangeLength(range.ptr(), true);1087 return TextIterator::rangeLength(range.ptr(), { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 1088 1088 } 1089 1089 1090 1090 // FIXME: Merge this function with the one above. 1091 int indexForVisiblePosition(Node& node, const VisiblePosition& visiblePosition, bool forSelectionPreservation)1091 int indexForVisiblePosition(Node& node, const VisiblePosition& visiblePosition, OptionSet<TextIteratorLengthOption> options) 1092 1092 { 1093 1093 auto range = Range::create(node.document(), firstPositionInNode(&node), visiblePosition.deepEquivalent().parentAnchoredEquivalent()); 1094 return TextIterator::rangeLength(range.ptr(), forSelectionPreservation);1094 return TextIterator::rangeLength(range.ptr(), options); 1095 1095 } 1096 1096 … … 1107 1107 VisiblePosition visiblePositionForIndex(int index, ContainerNode* scope) 1108 1108 { 1109 auto range = TextIterator::rangeFromLocationAndLength(scope, index, 0, true);1109 auto range = TextIterator::rangeFromLocationAndLength(scope, index, 0, { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 1110 1110 // Check for an invalid index. Certain editing operations invalidate indices because 1111 1111 // of problems with TextIteratorEmitsCharactersBetweenAllVisiblePositions. -
trunk/Source/WebCore/editing/Editing.h
r249605 r254557 27 27 28 28 #include "Position.h" 29 #include "TextIteratorBehavior.h" 29 30 #include <wtf/Forward.h> 30 31 #include <wtf/HashSet.h> 32 #include <wtf/OptionSet.h> 31 33 #include <wtf/unicode/CharacterNames.h> 32 34 … … 150 152 151 153 WEBCORE_EXPORT int indexForVisiblePosition(const VisiblePosition&, RefPtr<ContainerNode>& scope); 152 int indexForVisiblePosition(Node&, const VisiblePosition&, bool forSelectionPreservation);154 int indexForVisiblePosition(Node&, const VisiblePosition&, OptionSet<TextIteratorLengthOption> = { }); 153 155 WEBCORE_EXPORT VisiblePosition visiblePositionForPositionWithOffset(const VisiblePosition&, int offset); 154 156 WEBCORE_EXPORT VisiblePosition visiblePositionForIndex(int index, ContainerNode* scope); -
trunk/Source/WebCore/editing/TextIterator.cpp
r250343 r254557 2397 2397 // -------- 2398 2398 2399 int TextIterator::rangeLength(const Range* range, bool forSelectionPreservation) 2399 static TextIteratorBehavior behaviorFromLegnthOptions(OptionSet<TextIteratorLengthOption> options) 2400 { 2401 TextIteratorBehavior behavior = TextIteratorDefaultBehavior; 2402 if (options.contains(TextIteratorLengthOption::GenerateSpacesForReplacedElements)) 2403 behavior |= TextIteratorEmitsCharactersBetweenAllVisiblePositions; 2404 if (options.contains(TextIteratorLengthOption::IgnoreVisibility)) 2405 behavior |= TextIteratorIgnoresStyleVisibility; 2406 return behavior; 2407 } 2408 2409 int TextIterator::rangeLength(const Range* range, OptionSet<TextIteratorLengthOption> options) 2400 2410 { 2401 2411 unsigned length = 0; 2402 for (TextIterator it(range, forSelectionPreservation ? TextIteratorEmitsCharactersBetweenAllVisiblePositions : TextIteratorDefaultBehavior); !it.atEnd(); it.advance())2412 for (TextIterator it(range, behaviorFromLegnthOptions(options)); !it.atEnd(); it.advance()) 2403 2413 length += it.text().length(); 2404 2414 return length; … … 2419 2429 } 2420 2430 2421 RefPtr<Range> TextIterator::rangeFromLocationAndLength(ContainerNode* scope, int rangeLocation, int rangeLength, bool forSelectionPreservation)2431 RefPtr<Range> TextIterator::rangeFromLocationAndLength(ContainerNode* scope, int rangeLocation, int rangeLength, OptionSet<TextIteratorLengthOption> options) 2422 2432 { 2423 2433 Ref<Range> resultRange = scope->document().createRange(); … … 2429 2439 Ref<Range> textRunRange = rangeOfContents(*scope); 2430 2440 2431 TextIterator it(textRunRange.ptr(), forSelectionPreservation ? TextIteratorEmitsCharactersBetweenAllVisiblePositions : TextIteratorDefaultBehavior);2441 TextIterator it(textRunRange.ptr(), behaviorFromLegnthOptions(options)); 2432 2442 2433 2443 // FIXME: the atEnd() check shouldn't be necessary, workaround for <http://bugs.webkit.org/show_bug.cgi?id=6289>. -
trunk/Source/WebCore/editing/TextIterator.h
r252528 r254557 32 32 #include "Range.h" 33 33 #include "TextIteratorBehavior.h" 34 #include <wtf/OptionSet.h> 34 35 #include <wtf/Vector.h> 35 36 #include <wtf/text/StringView.h> … … 122 123 void appendTextToStringBuilder(StringBuilder& builder) const { copyableText().appendToStringBuilder(builder); } 123 124 124 WEBCORE_EXPORT static int rangeLength(const Range*, bool spacesForReplacedElements = false);125 WEBCORE_EXPORT static RefPtr<Range> rangeFromLocationAndLength(ContainerNode* scope, int rangeLocation, int rangeLength, bool spacesForReplacedElements = false);125 WEBCORE_EXPORT static int rangeLength(const Range*, OptionSet<TextIteratorLengthOption> = { }); 126 WEBCORE_EXPORT static RefPtr<Range> rangeFromLocationAndLength(ContainerNode* scope, int rangeLocation, int rangeLength, OptionSet<TextIteratorLengthOption> = { }); 126 127 WEBCORE_EXPORT static bool getLocationAndLengthFromRange(Node* scope, const Range*, size_t& location, size_t& length); 127 128 WEBCORE_EXPORT static Ref<Range> subrange(Range& entireRange, int characterOffset, int characterCount); -
trunk/Source/WebCore/editing/TextIteratorBehavior.h
r210432 r254557 64 64 typedef unsigned short TextIteratorBehavior; 65 65 66 enum class TextIteratorLengthOption : uint8_t { 67 GenerateSpacesForReplacedElements = 1 << 0, 68 IgnoreVisibility = 1 << 1, 69 }; 70 66 71 } // namespace WebCore -
trunk/Source/WebCore/editing/ios/DictationCommandIOS.cpp
r240237 r254557 69 69 // FIXME: Add the result marker using a Position cached before results are inserted, instead of relying on TextIterators. 70 70 auto rangeToEnd = Range::create(document(), createLegacyEditingPosition((Node *)root, 0), afterResults.deepEquivalent()); 71 int endIndex = TextIterator::rangeLength(rangeToEnd.ptr(), true);71 int endIndex = TextIterator::rangeLength(rangeToEnd.ptr(), { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 72 72 int startIndex = endIndex - resultLength; 73 73 74 74 if (startIndex >= 0) { 75 RefPtr<Range> resultRange = TextIterator::rangeFromLocationAndLength(document().documentElement(), startIndex, endIndex, true); 75 RefPtr<Range> resultRange = TextIterator::rangeFromLocationAndLength(document().documentElement(), startIndex, endIndex, 76 { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 76 77 ASSERT(resultRange); // FIXME: What guarantees this? 77 78 document().markers().addDictationResultMarker(*resultRange, m_metadata); -
trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp
r254087 r254557 644 644 unsigned length = innerTextValue().length(); 645 645 index = std::min(index, length); // FIXME: We shouldn't have to call innerTextValue() just to ignore the last LF. See finishText. 646 #if 0647 // FIXME: This assertion code was never built, has bit rotted, and needs to be fixed before it can be enabled:648 // https://bugs.webkit.org/show_bug.cgi?id=205706.649 646 #if ASSERT_ENABLED 650 647 VisiblePosition visiblePosition = passedPosition; 651 unsigned indexComputedByVisiblePosition = 0;652 if (visiblePosition.isNotNull())653 indexComputedByVisiblePosition = WebCore::indexForVisiblePosition(innerText, visiblePosition, false /* forSelectionPreservation */);654 ASSERT(index == indexComputedByVisiblePosition);655 #endif 648 if (visiblePosition.isNotNull()) { 649 unsigned indexComputedByVisiblePosition = WebCore::indexForVisiblePosition(*innerText, visiblePosition, 650 { TextIteratorLengthOption::GenerateSpacesForReplacedElements, TextIteratorLengthOption::IgnoreVisibility }); 651 ASSERT(index == indexComputedByVisiblePosition); 652 } 656 653 #endif 657 654 return index; -
trunk/Source/WebCore/page/EventHandler.cpp
r254029 r254557 658 658 { 659 659 auto range = Range::create(start.anchorNode()->document(), start, end); 660 return TextIterator::rangeLength(range.ptr(), true);660 return TextIterator::rangeLength(range.ptr(), { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 661 661 } 662 662 -
trunk/Source/WebKit/ChangeLog
r254556 r254557 1 2020-01-14 Ryosuke Niwa <rniwa@webkit.org> 2 3 Enable the offset assertion in HTMLTextFormControlElement::indexForPosition 4 https://bugs.webkit.org/show_bug.cgi?id=205706 5 6 Reviewed by Darin Adler. 7 8 * WebProcess/WebPage/ios/WebPageIOS.mm: 9 (WebKit::rangeNearPositionMatchesText): 10 1 11 2020-01-14 Chris Dumez <cdumez@apple.com> 2 12 -
trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
r254387 r254557 1958 1958 { 1959 1959 auto range = Range::create(selectionRange->ownerDocument(), selectionRange->startPosition(), position.deepEquivalent().parentAnchoredEquivalent()); 1960 unsigned targetOffset = TextIterator::rangeLength(range.ptr(), true);1960 unsigned targetOffset = TextIterator::rangeLength(range.ptr(), { TextIteratorLengthOption::GenerateSpacesForReplacedElements }); 1961 1961 return findClosestPlainText(*selectionRange.get(), matchText, { }, targetOffset); 1962 1962 }
Note:
See TracChangeset
for help on using the changeset viewer.