Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
AX: WKContentView needs to implement UITextInput methods to make spea…
…k selection highlighting work https://bugs.webkit.org/show_bug.cgi?id=166955 Reviewed by Ryosuke Niwa. Source/WebCore: Created a new version of Range::collectSelectionRect() that returns rects for each line, so that Speak Selection doesn't need to handle searching for soft line breaks. Also added a variant of findPlainText to search for the closest matched range to the given position. Test: editing/text-iterator/range-of-string-closest-to-position.html * dom/Range.cpp: (WebCore::Range::collectSelectionRectsWithoutUnionInteriorLines): (WebCore::Range::collectSelectionRects): * dom/Range.h: * editing/TextIterator.cpp: (WebCore::findPlainTextMatches): (WebCore::updateSearchBuffer): (WebCore::findIteratorOptions): (WebCore::rangeMatches): (WebCore::findClosestPlainText): (WebCore::findPlainText): (WebCore::findPlainTextOffset): Deleted. * editing/TextIterator.h: * editing/htmlediting.h: * testing/Internals.cpp: (WebCore::Internals::rangeOfStringNearLocation): * testing/Internals.h: * testing/Internals.idl: Source/WebKit2: Implemented methods that Speak Selection can use to retrieve the word/sentence highlighting rects. * Scripts/webkit/messages.py: (headers_for_type): * UIProcess/WebPageProxy.h: * UIProcess/WebPageProxy.messages.in: * UIProcess/ios/WKContentViewInteraction.h: * UIProcess/ios/WKContentViewInteraction.mm: (-[WKContentView webSelectionRectsForSelectionRects:]): (-[WKContentView webSelectionRects]): (-[WKContentView _accessibilityRetrieveRectsEnclosingSelectionOffset:withGranularity:]): (-[WKContentView _accessibilityRetrieveRectsAtSelectionOffset:withText:]): * UIProcess/ios/WebPageProxyIOS.mm: (WebKit::WebPageProxy::selectionRectsCallback): (WebKit::WebPageProxy::requestRectsForGranularityWithSelectionOffset): (WebKit::WebPageProxy::requestRectsAtSelectionOffsetWithText): * WebProcess/WebPage/WebPage.h: * WebProcess/WebPage/WebPage.messages.in: * WebProcess/WebPage/ios/WebPageIOS.mm: (WebKit::visiblePositionForPositionWithOffset): (WebKit::WebPage::getRectsForGranularityWithSelectionOffset): (WebKit::rangeNearPositionMatchesText): (WebKit::WebPage::getRectsAtSelectionOffsetWithText): LayoutTests: * editing/text-iterator/range-of-string-closest-to-position-expected.txt: Added. * editing/text-iterator/range-of-string-closest-to-position.html: Added. Canonical link: https://commits.webkit.org/184600@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@211356 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
with
394 additions
and 39 deletions.
- +10 −0 LayoutTests/ChangeLog
- +11 −0 LayoutTests/editing/text-iterator/range-of-string-closest-to-position-expected.txt
- +75 −0 LayoutTests/editing/text-iterator/range-of-string-closest-to-position.html
- +32 −0 Source/WebCore/ChangeLog
- +10 −2 Source/WebCore/dom/Range.cpp
- +1 −0 Source/WebCore/dom/Range.h
- +57 −31 Source/WebCore/editing/TextIterator.cpp
- +1 −0 Source/WebCore/editing/TextIterator.h
- +2 −2 Source/WebCore/editing/htmlediting.h
- +5 −0 Source/WebCore/testing/Internals.cpp
- +1 −0 Source/WebCore/testing/Internals.h
- +1 −0 Source/WebCore/testing/Internals.idl
- +31 −0 Source/WebKit2/ChangeLog
- +1 −0 Source/WebKit2/Scripts/webkit/messages.py
- +4 −0 Source/WebKit2/UIProcess/WebPageProxy.h
- +1 −0 Source/WebKit2/UIProcess/WebPageProxy.messages.in
- +2 −0 Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h
- +33 −4 Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm
- +33 −0 Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm
- +2 −0 Source/WebKit2/WebProcess/WebPage/WebPage.h
- +2 −0 Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
- +79 −0 Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,11 @@ | ||
PASS internals.rangeOfStringNearLocation(rangeOfNodeContent(p1), 'the', 11).toArray() is secondThe | ||
PASS internals.rangeOfStringNearLocation(rangeOfNodeContent(p1), 'the', 9).toArray() is secondThe | ||
PASS internals.rangeOfStringNearLocation(rangeOfNodeContent(p1), 'the', 6).toArray() is firstThe | ||
PASS internals.rangeOfStringNearLocation(rangeOfNodeContent(p1), 'the', 16).toArray() is secondThe | ||
PASS internals.rangeOfStringNearLocation(rangeOfNodeContent(p1), 'The', 11).toArray() is upperThe | ||
PASS internals.rangeOfStringNearLocation(rangeOfNodeContent(p2), '中文', 5).toArray() is chineseMatch | ||
PASS internals.rangeOfStringNearLocation(rangeOfNodeContent(p3), 'the', 5).toArray() is rtlMatch | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,75 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<script src="../../resources/js-test-pre.js"></script> | ||
</head> | ||
<body> | ||
<div id="test" contenteditable> | ||
<p id="p1">the car is the good the The world.</p> | ||
<p id="p2">中文字是中文字</p> | ||
<bdo dir="rtl" id="p3">the best</bdo> | ||
</div> | ||
<div id="console"></div> | ||
<script> | ||
|
||
if (!window.internals) | ||
testFailed('This test requires internals object'); | ||
else { | ||
var container = document.getElementById('test'); | ||
|
||
function range(startContainer, startOffset, endContainer, endOffset) { | ||
var range = document.createRange(); | ||
range.setStart(startContainer, startOffset); | ||
range.setEnd(endContainer, endOffset); | ||
return range; | ||
} | ||
|
||
function rangeOfNodeContent(referenceNode) { | ||
var range = document.createRange(); | ||
range.selectNodeContents(referenceNode); | ||
return range; | ||
} | ||
|
||
Range.prototype.toArray = function () { | ||
return [this.startContainer, this.startOffset, this.endContainer, this.endOffset]; | ||
} | ||
|
||
var p1 = document.getElementById("p1"); | ||
var p2 = document.getElementById("p2"); | ||
var p3 = document.getElementById("p3"); | ||
|
||
var firstThe = [p1.firstChild, 0, p1.firstChild, 3]; | ||
var secondThe = [p1.firstChild, 11, p1.firstChild, 14]; | ||
var upperThe = [p1.firstChild, 24, p1.firstChild, 27]; | ||
var chineseMatch = [p2.firstChild, 4, p2.firstChild, 6]; | ||
var germanMatch = [p3.firstChild, 5, p3.firstChild, 6]; | ||
var rtlMatch = [p3.firstChild, 0, p3.firstChild, 3]; | ||
|
||
// When the target position is correct, at the beginning of the matched range. | ||
shouldBe('internals.rangeOfStringNearLocation(rangeOfNodeContent(p1), \'the\', 11).toArray()', 'secondThe'); | ||
|
||
// Cases that the matched range is on either side of the target position. | ||
shouldBe('internals.rangeOfStringNearLocation(rangeOfNodeContent(p1), \'the\', 9).toArray()', 'secondThe'); | ||
shouldBe('internals.rangeOfStringNearLocation(rangeOfNodeContent(p1), \'the\', 6).toArray()', 'firstThe'); | ||
|
||
// In this case, target position is at the beginning of "oog", make sure it's picking the | ||
// left side "the" as the closest match. | ||
shouldBe('internals.rangeOfStringNearLocation(rangeOfNodeContent(p1), \'the\', 16).toArray()', 'secondThe'); | ||
|
||
// Upper case. | ||
shouldBe('internals.rangeOfStringNearLocation(rangeOfNodeContent(p1), \'The\', 11).toArray()', 'upperThe'); | ||
|
||
// CJK | ||
shouldBe('internals.rangeOfStringNearLocation(rangeOfNodeContent(p2), \'中文\', 5).toArray()', 'chineseMatch'); | ||
|
||
// RtL | ||
shouldBe('internals.rangeOfStringNearLocation(rangeOfNodeContent(p3), \'the\', 5).toArray()', 'rtlMatch'); | ||
|
||
container.style.display = 'none'; | ||
} | ||
|
||
</script> | ||
<script src="../../resources/js-test-post.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.