<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[211356] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/211356">211356</a></dd>
<dt>Author</dt> <dd>n_wang@apple.com</dd>
<dt>Date</dt> <dd>2017-01-29 21:03:11 -0800 (Sun, 29 Jan 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>AX: WKContentView needs to implement UITextInput methods to make speak 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.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomRangecpp">trunk/Source/WebCore/dom/Range.cpp</a></li>
<li><a href="#trunkSourceWebCoredomRangeh">trunk/Source/WebCore/dom/Range.h</a></li>
<li><a href="#trunkSourceWebCoreeditingTextIteratorcpp">trunk/Source/WebCore/editing/TextIterator.cpp</a></li>
<li><a href="#trunkSourceWebCoreeditingTextIteratorh">trunk/Source/WebCore/editing/TextIterator.h</a></li>
<li><a href="#trunkSourceWebCoreeditinghtmleditingh">trunk/Source/WebCore/editing/htmlediting.h</a></li>
<li><a href="#trunkSourceWebCoretestingInternalscpp">trunk/Source/WebCore/testing/Internals.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingInternalsh">trunk/Source/WebCore/testing/Internals.h</a></li>
<li><a href="#trunkSourceWebCoretestingInternalsidl">trunk/Source/WebCore/testing/Internals.idl</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2Scriptswebkitmessagespy">trunk/Source/WebKit2/Scripts/webkit/messages.py</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxyh">trunk/Source/WebKit2/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxymessagesin">trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKContentViewInteractionh">trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKContentViewInteractionmm">trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWebPageProxyIOSmm">trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPageh">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagemessagesin">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm">trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestseditingtextiteratorrangeofstringclosesttopositionexpectedtxt">trunk/LayoutTests/editing/text-iterator/range-of-string-closest-to-position-expected.txt</a></li>
<li><a href="#trunkLayoutTestseditingtextiteratorrangeofstringclosesttopositionhtml">trunk/LayoutTests/editing/text-iterator/range-of-string-closest-to-position.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/LayoutTests/ChangeLog        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2017-01-29 Nan Wang <n_wang@apple.com>
+
+ AX: WKContentView needs to implement UITextInput methods to make speak selection highlighting work
+ https://bugs.webkit.org/show_bug.cgi?id=166955
+
+ Reviewed by Ryosuke Niwa.
+
+ * editing/text-iterator/range-of-string-closest-to-position-expected.txt: Added.
+ * editing/text-iterator/range-of-string-closest-to-position.html: Added.
+
</ins><span class="cx"> 2017-01-29 Yoav Weiss <yoav@yoav.ws>
</span><span class="cx">
</span><span class="cx"> Add invalid value tests to Link header handling.
</span></span></pre></div>
<a id="trunkLayoutTestseditingtextiteratorrangeofstringclosesttopositionexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/text-iterator/range-of-string-closest-to-position-expected.txt (0 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/text-iterator/range-of-string-closest-to-position-expected.txt         (rev 0)
+++ trunk/LayoutTests/editing/text-iterator/range-of-string-closest-to-position-expected.txt        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+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
+
</ins></span></pre></div>
<a id="trunkLayoutTestseditingtextiteratorrangeofstringclosesttopositionhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/text-iterator/range-of-string-closest-to-position.html (0 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/text-iterator/range-of-string-closest-to-position.html         (rev 0)
+++ trunk/LayoutTests/editing/text-iterator/range-of-string-closest-to-position.html        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -0,0 +1,75 @@
</span><ins>+<!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>
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebCore/ChangeLog        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2017-01-29 Nan Wang <n_wang@apple.com>
+
+ AX: WKContentView needs to implement UITextInput methods to make speak selection highlighting work
+ https://bugs.webkit.org/show_bug.cgi?id=166955
+
+ Reviewed by Ryosuke Niwa.
+
+ 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:
+
</ins><span class="cx"> 2017-01-29 Andy Estes <aestes@apple.com>
</span><span class="cx">
</span><span class="cx"> [QuickLook] Add a WebPreference to enable saving QuickLook documents in WebKitLegacy
</span></span></pre></div>
<a id="trunkSourceWebCoredomRangecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Range.cpp (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Range.cpp        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebCore/dom/Range.cpp        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -1266,7 +1266,7 @@
</span><span class="cx">
</span><span class="cx"> // This function is similar in spirit to addLineBoxRects, but annotates the returned rectangles
</span><span class="cx"> // with additional state which helps iOS draw selections in its unique way.
</span><del>-void Range::collectSelectionRects(Vector<SelectionRect>& rects)
</del><ins>+int Range::collectSelectionRectsWithoutUnionInteriorLines(Vector<SelectionRect>& rects)
</ins><span class="cx"> {
</span><span class="cx"> auto& startContainer = this->startContainer();
</span><span class="cx"> auto& endContainer = this->endContainer();
</span><span class="lines">@@ -1325,7 +1325,7 @@
</span><span class="cx"> VisiblePosition endPosition(createLegacyEditingPosition(&endContainer, endOffset), VP_DEFAULT_AFFINITY);
</span><span class="cx"> VisiblePosition brPosition(createLegacyEditingPosition(stopNode, 0), VP_DEFAULT_AFFINITY);
</span><span class="cx"> if (endPosition == brPosition)
</span><del>- rects.last().setIsLineBreak(true);
</del><ins>+ rects.last().setIsLineBreak(true);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> int lineTop = std::numeric_limits<int>::max();
</span><span class="lines">@@ -1422,7 +1422,15 @@
</span><span class="cx"> } else if (selectionRect.direction() == LTR && selectionRect.isLastOnLine())
</span><span class="cx"> selectionRect.setLogicalWidth(selectionRect.maxX() - selectionRect.logicalLeft());
</span><span class="cx"> }
</span><ins>+
+ return maxLineNumber;
+}
</ins><span class="cx">
</span><ins>+void Range::collectSelectionRects(Vector<SelectionRect>& rects)
+{
+ int maxLineNumber = collectSelectionRectsWithoutUnionInteriorLines(rects);
+ const size_t numberOfRects = rects.size();
+
</ins><span class="cx"> // Union all the rectangles on interior lines (i.e. not first or last).
</span><span class="cx"> // On first and last lines, just avoid having overlaps by merging intersecting rectangles.
</span><span class="cx"> Vector<SelectionRect> unionedRects;
</span></span></pre></div>
<a id="trunkSourceWebCoredomRangeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Range.h (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Range.h        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebCore/dom/Range.h        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -125,6 +125,7 @@
</span><span class="cx"> WEBCORE_EXPORT FloatRect absoluteBoundingRect() const;
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> WEBCORE_EXPORT void collectSelectionRects(Vector<SelectionRect>&);
</span><ins>+ WEBCORE_EXPORT int collectSelectionRectsWithoutUnionInteriorLines(Vector<SelectionRect>&);
</ins><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> void nodeChildrenChanged(ContainerNode&);
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingTextIteratorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/TextIterator.cpp (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/TextIterator.cpp        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebCore/editing/TextIterator.cpp        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -2656,10 +2656,28 @@
</span><span class="cx"> return result;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static std::optional<std::pair<size_t, size_t>> findPlainTextOffset(SearchBuffer& buffer, CharacterIterator& findIterator, bool searchForward)
</del><ins>+static TextIteratorBehavior findIteratorOptions(FindOptions options)
</ins><span class="cx"> {
</span><del>- size_t matchStart = 0;
- size_t matchLength = 0;
</del><ins>+ TextIteratorBehavior iteratorOptions = TextIteratorEntersTextControls | TextIteratorClipsToFrameAncestors;
+ if (!(options & DoNotTraverseFlatTree))
+ iteratorOptions |= TextIteratorTraversesFlatTree;
+ return iteratorOptions;
+}
+
+static void findPlainTextMatches(const Range& range, const String& target, FindOptions options, const std::function<bool(size_t, size_t)>& match)
+{
+ SearchBuffer buffer(target, options);
+ if (buffer.needsMoreContext()) {
+ Ref<Range> beforeStartRange = range.ownerDocument().createRange();
+ beforeStartRange->setEnd(range.startContainer(), range.startOffset());
+ for (SimplifiedBackwardsTextIterator backwardsIterator(beforeStartRange.get()); !backwardsIterator.atEnd(); backwardsIterator.advance()) {
+ buffer.prependContext(backwardsIterator.text());
+ if (!buffer.needsMoreContext())
+ break;
+ }
+ }
+
+ CharacterIterator findIterator(range, findIteratorOptions(options));
</ins><span class="cx"> while (!findIterator.atEnd()) {
</span><span class="cx"> findIterator.advance(buffer.append(findIterator.text()));
</span><span class="cx"> while (1) {
</span><span class="lines">@@ -2674,45 +2692,53 @@
</span><span class="cx"> }
</span><span class="cx"> size_t lastCharacterInBufferOffset = findIterator.characterOffset();
</span><span class="cx"> ASSERT(lastCharacterInBufferOffset >= matchStartOffset);
</span><del>- matchStart = lastCharacterInBufferOffset - matchStartOffset;
- matchLength = newMatchLength;
- if (searchForward) // Look for the last match when searching backwards instead.
- return std::pair<size_t, size_t> { matchStart, matchLength };
</del><ins>+ if (match(lastCharacterInBufferOffset - matchStartOffset, newMatchLength))
+ return;
</ins><span class="cx"> }
</span><span class="cx"> }
</span><ins>+}
</ins><span class="cx">
</span><ins>+static Ref<Range> rangeForMatch(const Range& range, FindOptions options, size_t matchStart, size_t matchLength, bool searchForward)
+{
</ins><span class="cx"> if (!matchLength)
</span><del>- return std::nullopt;
</del><ins>+ return collapsedToBoundary(range, searchForward);
+ CharacterIterator rangeComputeIterator(range, findIteratorOptions(options));
+ return characterSubrange(range.ownerDocument(), rangeComputeIterator, matchStart, matchLength);
+}
</ins><span class="cx">
</span><del>- return std::pair<size_t, size_t> { matchStart, matchLength };
</del><ins>+Ref<Range> findClosestPlainText(const Range& range, const String& target, FindOptions options, unsigned targetOffset)
+{
+ size_t matchStart = 0;
+ size_t matchLength = 0;
+ size_t distance = std::numeric_limits<size_t>::max();
+ auto match = [targetOffset, &distance, &matchStart, &matchLength] (size_t start, size_t length) {
+ size_t newDistance = std::min(abs(static_cast<signed>(start - targetOffset)), abs(static_cast<signed>(start + length - targetOffset)));
+ if (newDistance < distance) {
+ matchStart = start;
+ matchLength = length;
+ distance = newDistance;
+ }
+ return false;
+ };
+
+ findPlainTextMatches(range, target, options, match);
+ return rangeForMatch(range, options, matchStart, matchLength, !(options & Backwards));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> Ref<Range> findPlainText(const Range& range, const String& target, FindOptions options)
</span><span class="cx"> {
</span><del>- SearchBuffer buffer(target, options);
-
- if (buffer.needsMoreContext()) {
- Ref<Range> beforeStartRange = range.ownerDocument().createRange();
- beforeStartRange->setEnd(range.startContainer(), range.startOffset());
- for (SimplifiedBackwardsTextIterator backwardsIterator(beforeStartRange.get()); !backwardsIterator.atEnd(); backwardsIterator.advance()) {
- buffer.prependContext(backwardsIterator.text());
- if (!buffer.needsMoreContext())
- break;
- }
- }
-
</del><span class="cx"> bool searchForward = !(options & Backwards);
</span><del>- TextIteratorBehavior iteratorOptions = TextIteratorEntersTextControls | TextIteratorClipsToFrameAncestors;
- if (!(options & DoNotTraverseFlatTree))
- iteratorOptions |= TextIteratorTraversesFlatTree;
</del><ins>+ size_t matchStart = 0;
+ size_t matchLength = 0;
+ auto match = [searchForward, &matchStart, &matchLength] (size_t start, size_t length) {
+ matchStart = start;
+ matchLength = length;
+ // Look for the last match when searching backwards instead.
+ return searchForward;
+ };
</ins><span class="cx">
</span><del>- CharacterIterator findIterator(range, iteratorOptions);
- auto result = findPlainTextOffset(buffer, findIterator, searchForward);
- if (!result)
- return collapsedToBoundary(range, searchForward);
-
- CharacterIterator rangeComputeIterator(range, iteratorOptions);
- return characterSubrange(range.ownerDocument(), rangeComputeIterator, result->first, result->second);
</del><ins>+ findPlainTextMatches(range, target, options, match);
+ return rangeForMatch(range, options, matchStart, matchLength, searchForward);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingTextIteratorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/TextIterator.h (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/TextIterator.h        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebCore/editing/TextIterator.h        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -45,6 +45,7 @@
</span><span class="cx"> WEBCORE_EXPORT String plainText(const Range*, TextIteratorBehavior = TextIteratorDefaultBehavior, bool isDisplayString = false);
</span><span class="cx"> WEBCORE_EXPORT String plainTextReplacingNoBreakSpace(const Range*, TextIteratorBehavior = TextIteratorDefaultBehavior, bool isDisplayString = false);
</span><span class="cx"> Ref<Range> findPlainText(const Range&, const String&, FindOptions);
</span><ins>+WEBCORE_EXPORT Ref<Range> findClosestPlainText(const Range&, const String&, FindOptions, unsigned);
</ins><span class="cx">
</span><span class="cx"> // FIXME: Move this somewhere else in the editing directory. It doesn't belong here.
</span><span class="cx"> bool isRendererReplacedElement(RenderObject*);
</span></span></pre></div>
<a id="trunkSourceWebCoreeditinghtmleditingh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/htmlediting.h (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/htmlediting.h        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebCore/editing/htmlediting.h        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -144,9 +144,9 @@
</span><span class="cx">
</span><span class="cx"> int comparePositions(const VisiblePosition&, const VisiblePosition&);
</span><span class="cx">
</span><del>-int indexForVisiblePosition(const VisiblePosition&, RefPtr<ContainerNode>& scope);
</del><ins>+WEBCORE_EXPORT int indexForVisiblePosition(const VisiblePosition&, RefPtr<ContainerNode>& scope);
</ins><span class="cx"> int indexForVisiblePosition(Node&, const VisiblePosition&, bool forSelectionPreservation);
</span><del>-VisiblePosition visiblePositionForIndex(int index, ContainerNode* scope);
</del><ins>+WEBCORE_EXPORT VisiblePosition visiblePositionForIndex(int index, ContainerNode* scope);
</ins><span class="cx"> VisiblePosition visiblePositionForIndexUsingCharacterIterator(Node&, int index); // FIXME: Why do we need this version?
</span><span class="cx">
</span><span class="cx"> // -------------------------------------------------------------------------
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.cpp (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.cpp        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebCore/testing/Internals.cpp        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -1456,6 +1456,11 @@
</span><span class="cx"> return TextIterator::subrange(&range, rangeLocation, rangeLength);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+RefPtr<Range> Internals::rangeOfStringNearLocation(const Range& searchRange, const String& text, unsigned targetOffset)
+{
+ return findClosestPlainText(searchRange, text, 0, targetOffset);
+}
+
</ins><span class="cx"> ExceptionOr<RefPtr<Range>> Internals::rangeForDictionaryLookupAtLocation(int x, int y)
</span><span class="cx"> {
</span><span class="cx"> #if PLATFORM(MAC)
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.h (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.h        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebCore/testing/Internals.h        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -201,6 +201,7 @@
</span><span class="cx"> String rangeAsText(const Range&);
</span><span class="cx"> Ref<Range> subrange(Range&, int rangeLocation, int rangeLength);
</span><span class="cx"> ExceptionOr<RefPtr<Range>> rangeForDictionaryLookupAtLocation(int x, int y);
</span><ins>+ RefPtr<Range> rangeOfStringNearLocation(const Range&, const String&, unsigned);
</ins><span class="cx">
</span><span class="cx"> ExceptionOr<void> setDelegatesScrolling(bool enabled);
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.idl (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.idl        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebCore/testing/Internals.idl        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -195,6 +195,7 @@
</span><span class="cx"> DOMString rangeAsText(Range range);
</span><span class="cx"> Range subrange(Range range, long rangeLocation, long rangeLength);
</span><span class="cx"> [MayThrowException] Range? rangeForDictionaryLookupAtLocation(long x, long y);
</span><ins>+ Range? rangeOfStringNearLocation(Range range, DOMString text, long targetOffset);
</ins><span class="cx">
</span><span class="cx"> [MayThrowException] void setDelegatesScrolling(boolean enabled);
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebKit2/ChangeLog        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2017-01-29 Nan Wang <n_wang@apple.com>
+
+ AX: WKContentView needs to implement UITextInput methods to make speak selection highlighting work
+ https://bugs.webkit.org/show_bug.cgi?id=166955
+
+ Reviewed by Ryosuke Niwa.
+
+ 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):
+
</ins><span class="cx"> 2017-01-29 Dan Bernstein <mitz@apple.com>
</span><span class="cx">
</span><span class="cx"> [iOS] Expose WebCore::DataDetection::detectContentInRange WKWebProcessPlugInRangeHandle
</span></span></pre></div>
<a id="trunkSourceWebKit2Scriptswebkitmessagespy"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Scripts/webkit/messages.py (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Scripts/webkit/messages.py        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebKit2/Scripts/webkit/messages.py        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -365,6 +365,7 @@
</span><span class="cx"> 'WebCore::TextIndicatorData': ['<WebCore/TextIndicator.h>'],
</span><span class="cx"> 'WebCore::TextureMapperAnimations': ['<WebCore/TextureMapperAnimation.h>'],
</span><span class="cx"> 'WebCore::ViewportAttributes': ['<WebCore/ViewportArguments.h>'],
</span><ins>+ 'WebCore::SelectionRect': ['"EditorState.h"'],
</ins><span class="cx"> 'WebKit::BackForwardListItemState': ['"SessionState.h"'],
</span><span class="cx"> 'WebKit::LayerHostingMode': ['"LayerTreeContext.h"'],
</span><span class="cx"> 'WebKit::PageState': ['"SessionState.h"'],
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -256,6 +256,7 @@
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> typedef GenericCallback<const WebCore::IntPoint&, uint32_t, uint32_t, uint32_t> GestureCallback;
</span><span class="cx"> typedef GenericCallback<const WebCore::IntPoint&, uint32_t, uint32_t> TouchesCallback;
</span><ins>+typedef GenericCallback<const Vector<WebCore::SelectionRect>&> SelectionRectsCallback;
</ins><span class="cx"> struct NodeAssistanceArguments {
</span><span class="cx"> AssistedNodeInformation m_nodeInformation;
</span><span class="cx"> bool m_userIsInteracting;
</span><span class="lines">@@ -545,6 +546,8 @@
</span><span class="cx"> void handleTwoFingerTapAtPoint(const WebCore::IntPoint&, uint64_t requestID);
</span><span class="cx"> void setForceAlwaysUserScalable(bool);
</span><span class="cx"> void setIsScrollingOrZooming(bool);
</span><ins>+ void requestRectsForGranularityWithSelectionOffset(WebCore::TextGranularity, uint32_t offset, std::function<void(const Vector<WebCore::SelectionRect>&, CallbackBase::Error)>);
+ void requestRectsAtSelectionOffsetWithText(int32_t offset, const String&, std::function<void(const Vector<WebCore::SelectionRect>&, CallbackBase::Error)>);
</ins><span class="cx"> #if ENABLE(DATA_INTERACTION)
</span><span class="cx"> void didPerformDataInteractionControllerOperation();
</span><span class="cx"> void requestStartDataInteraction(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition);
</span><span class="lines">@@ -1477,6 +1480,7 @@
</span><span class="cx"> void selectionContextCallback(const String&, const String&, const String&, uint64_t);
</span><span class="cx"> void interpretKeyEvent(const EditorState&, bool isCharEvent, bool& handled);
</span><span class="cx"> void showPlaybackTargetPicker(bool hasVideo, const WebCore::IntRect& elementRect);
</span><ins>+ void selectionRectsCallback(const Vector<WebCore::SelectionRect>&, uint64_t);
</ins><span class="cx"> #endif
</span><span class="cx"> #if PLATFORM(GTK)
</span><span class="cx"> void printFinishedCallback(const WebCore::ResourceError&, uint64_t);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -195,6 +195,7 @@
</span><span class="cx"> DidNotHandleTapAsClick(WebCore::IntPoint point)
</span><span class="cx"> DisableDoubleTapGesturesDuringTapIfNecessary(uint64_t requestID)
</span><span class="cx"> DrawToPDFCallback(IPC::DataReference pdfData, uint64_t callbackID)
</span><ins>+ SelectionRectsCallback(Vector<WebCore::SelectionRect> selectionRects, uint64_t callbackID);
</ins><span class="cx"> #endif
</span><span class="cx"> #if ENABLE(DATA_DETECTION)
</span><span class="cx"> SetDataDetectionResult(struct WebKit::DataDetectionResult dataDetectionResult)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKContentViewInteractionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -247,6 +247,8 @@
</span><span class="cx"> - (NSArray *)_dataDetectionResults;
</span><span class="cx"> - (NSArray<NSValue *> *)_uiTextSelectionRects;
</span><span class="cx"> - (void)accessibilityRetrieveSpeakSelectionContent;
</span><ins>+- (void)_accessibilityRetrieveRectsEnclosingSelectionOffset:(NSInteger)offset withGranularity:(UITextGranularity)granularity;
+- (void)_accessibilityRetrieveRectsAtSelectionOffset:(NSInteger)offset withText:(NSString *)text;
</ins><span class="cx">
</span><span class="cx"> #if ENABLE(DATA_INTERACTION)
</span><span class="cx"> - (void)_didPerformDataInteractionControllerOperation;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKContentViewInteractionmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -495,6 +495,8 @@
</span><span class="cx">
</span><span class="cx"> @interface WKContentView (WKInteractionPrivate)
</span><span class="cx"> - (void)accessibilitySpeakSelectionSetContent:(NSString *)string;
</span><ins>+- (NSArray *)webSelectionRectsForSelectionRects:(const Vector<WebCore::SelectionRect>&)selectionRects;
+- (void)_accessibilityDidGetSelectionRects:(NSArray *)selectionRects withGranularity:(UITextGranularity)granularity atOffset:(NSInteger)offset;
</ins><span class="cx"> @end
</span><span class="cx">
</span><span class="cx"> @implementation WKContentView (WKInteraction)
</span><span class="lines">@@ -1496,11 +1498,8 @@
</span><span class="cx"> return _positionInformation.nodeAtPositionIsAssistedNode;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-- (NSArray *)webSelectionRects
</del><ins>+- (NSArray *)webSelectionRectsForSelectionRects:(const Vector<WebCore::SelectionRect>&)selectionRects
</ins><span class="cx"> {
</span><del>- if (_page->editorState().selectionIsNone)
- return nil;
- const auto& selectionRects = _page->editorState().postLayoutData().selectionRects;
</del><span class="cx"> unsigned size = selectionRects.size();
</span><span class="cx"> if (!size)
</span><span class="cx"> return nil;
</span><span class="lines">@@ -1524,6 +1523,14 @@
</span><span class="cx"> return webRects;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+- (NSArray *)webSelectionRects
+{
+ if (_page->editorState().selectionIsNone)
+ return nil;
+ const auto& selectionRects = _page->editorState().postLayoutData().selectionRects;
+ return [self webSelectionRectsForSelectionRects:selectionRects];
+}
+
</ins><span class="cx"> - (void)_highlightLongPressRecognized:(UILongPressGestureRecognizer *)gestureRecognizer
</span><span class="cx"> {
</span><span class="cx"> ASSERT(gestureRecognizer == _highlightLongPressGestureRecognizer);
</span><span class="lines">@@ -2197,6 +2204,28 @@
</span><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+- (void)_accessibilityRetrieveRectsEnclosingSelectionOffset:(NSInteger)offset withGranularity:(UITextGranularity)granularity
+{
+ RetainPtr<WKContentView> view = self;
+ _page->requestRectsForGranularityWithSelectionOffset(toWKTextGranularity(granularity), offset , [view, offset, granularity](const Vector<WebCore::SelectionRect>& selectionRects, CallbackBase::Error error) {
+ if (error != WebKit::CallbackBase::Error::None)
+ return;
+ if ([view respondsToSelector:@selector(_accessibilityDidGetSelectionRects:withGranularity:atOffset:)])
+ [view _accessibilityDidGetSelectionRects:[view webSelectionRectsForSelectionRects:selectionRects] withGranularity:granularity atOffset:offset];
+ });
+}
+
+- (void)_accessibilityRetrieveRectsAtSelectionOffset:(NSInteger)offset withText:(NSString *)text
+{
+ RetainPtr<WKContentView> view = self;
+ _page->requestRectsAtSelectionOffsetWithText(offset, text, [view, offset](const Vector<WebCore::SelectionRect>& selectionRects, CallbackBase::Error error) {
+ if (error != WebKit::CallbackBase::Error::None)
+ return;
+ if ([view respondsToSelector:@selector(_accessibilityDidGetSelectionRects:withGranularity:atOffset:)])
+ [view _accessibilityDidGetSelectionRects:[view webSelectionRectsForSelectionRects:selectionRects] withGranularity:UITextGranularityWord atOffset:offset];
+ });
+}
+
</ins><span class="cx"> // UIWKInteractionViewProtocol
</span><span class="cx">
</span><span class="cx"> static inline GestureType toGestureType(UIWKGestureType gestureType)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWebPageProxyIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -186,6 +186,17 @@
</span><span class="cx"> callback->performCallbackWithReturnValue(beforeText, markedText, selectedText, afterText, location, length);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void WebPageProxy::selectionRectsCallback(const Vector<WebCore::SelectionRect>& selectionRects, uint64_t callbackID)
+{
+ auto callback = m_callbacks.take<SelectionRectsCallback>(callbackID);
+ if (!callback) {
+ ASSERT_NOT_REACHED();
+ return;
+ }
+
+ callback->performCallbackWithReturnValue(selectionRects);
+}
+
</ins><span class="cx"> void WebPageProxy::updateVisibleContentRects(const VisibleContentRectUpdateInfo& visibleContentRectUpdate)
</span><span class="cx"> {
</span><span class="cx"> if (!isValid())
</span><span class="lines">@@ -722,6 +733,28 @@
</span><span class="cx"> m_process->send(Messages::WebPage::SelectWordBackward(), m_pageID);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void WebPageProxy::requestRectsForGranularityWithSelectionOffset(WebCore::TextGranularity granularity, uint32_t offset, std::function<void(const Vector<WebCore::SelectionRect>&, CallbackBase::Error)> callbackFunction)
+{
+ if (!isValid()) {
+ callbackFunction(Vector<WebCore::SelectionRect>(), CallbackBase::Error::Unknown);
+ return;
+ }
+
+ uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+ m_process->send(Messages::WebPage::GetRectsForGranularityWithSelectionOffset(static_cast<uint32_t>(granularity), offset, callbackID), m_pageID);
+}
+
+void WebPageProxy::requestRectsAtSelectionOffsetWithText(int32_t offset, const String& text, std::function<void(const Vector<WebCore::SelectionRect>&, CallbackBase::Error)> callbackFunction)
+{
+ if (!isValid()) {
+ callbackFunction(Vector<WebCore::SelectionRect>(), CallbackBase::Error::Unknown);
+ return;
+ }
+
+ uint64_t callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+ m_process->send(Messages::WebPage::GetRectsAtSelectionOffsetWithText(offset, text, callbackID), m_pageID);
+}
+
</ins><span class="cx"> void WebPageProxy::moveSelectionByOffset(int32_t offset, std::function<void (CallbackBase::Error)> callbackFunction)
</span><span class="cx"> {
</span><span class="cx"> if (!isValid()) {
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -577,6 +577,8 @@
</span><span class="cx"> void updateSelectionAppearance();
</span><span class="cx"> void getSelectionContext(uint64_t callbackID);
</span><span class="cx"> void handleTwoFingerTapAtPoint(const WebCore::IntPoint&, uint64_t requestID);
</span><ins>+ void getRectsForGranularityWithSelectionOffset(uint32_t, int32_t, uint64_t callbackID);
+ void getRectsAtSelectionOffsetWithText(int32_t, const String&, uint64_t callbackID);
</ins><span class="cx"> #if ENABLE(IOS_TOUCH_EVENTS)
</span><span class="cx"> void dispatchAsynchronousTouchEvents(const Vector<WebTouchEvent, 1>& queue);
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagemessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -96,6 +96,8 @@
</span><span class="cx"> SetAllowsMediaDocumentInlinePlayback(bool allows)
</span><span class="cx"> HandleTwoFingerTapAtPoint(WebCore::IntPoint point, uint64_t requestID)
</span><span class="cx"> SetForceAlwaysUserScalable(bool userScalable)
</span><ins>+ GetRectsForGranularityWithSelectionOffset(uint32_t granularity, int32_t offset, uint64_t callbackID);
+ GetRectsAtSelectionOffsetWithText(int32_t offset, String text, uint64_t callbackID);
</ins><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> SetControlledByAutomation(bool controlled)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (211355 => 211356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2017-01-30 01:40:29 UTC (rev 211355)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2017-01-30 05:03:11 UTC (rev 211356)
</span><span class="lines">@@ -105,6 +105,7 @@
</span><span class="cx"> #import <WebCore/VisibleUnits.h>
</span><span class="cx"> #import <WebCore/WKContentObservation.h>
</span><span class="cx"> #import <WebCore/WebEvent.h>
</span><ins>+#import <WebCore/htmlediting.h>
</ins><span class="cx"> #import <wtf/MathExtras.h>
</span><span class="cx"> #import <wtf/SetForScope.h>
</span><span class="cx">
</span><span class="lines">@@ -1819,6 +1820,84 @@
</span><span class="cx"> send(Messages::WebPageProxy::VoidCallback(callbackID));
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static VisiblePosition visiblePositionForPositionWithOffset(const VisiblePosition& position, int32_t offset)
+{
+ RefPtr<ContainerNode> root;
+ unsigned startIndex = indexForVisiblePosition(position, root);
+ return visiblePositionForIndex(startIndex + offset, root.get());
+}
+
+void WebPage::getRectsForGranularityWithSelectionOffset(uint32_t granularity, int32_t offset, uint64_t callbackID)
+{
+ Frame& frame = m_page->focusController().focusedOrMainFrame();
+ VisibleSelection selection = frame.selection().selection();
+ VisiblePosition selectionStart = selection.visibleStart();
+
+ if (selectionStart.isNull()) {
+ send(Messages::WebPageProxy::SelectionRectsCallback({ }, callbackID));
+ return;
+ }
+
+ auto position = visiblePositionForPositionWithOffset(selectionStart, offset);
+ SelectionDirection direction = offset < 0 ? DirectionBackward : DirectionForward;
+
+ auto range = enclosingTextUnitOfGranularity(position, static_cast<WebCore::TextGranularity>(granularity), direction);
+ if (!range || range->collapsed()) {
+ send(Messages::WebPageProxy::SelectionRectsCallback({ }, callbackID));
+ return;
+ }
+
+ Vector<WebCore::SelectionRect> selectionRects;
+ range->collectSelectionRectsWithoutUnionInteriorLines(selectionRects);
+ convertSelectionRectsToRootView(frame.view(), selectionRects);
+ send(Messages::WebPageProxy::SelectionRectsCallback(selectionRects, callbackID));
+}
+
+static RefPtr<Range> rangeNearPositionMatchesText(const VisiblePosition& position, RefPtr<Range> originalRange, const String& matchText, RefPtr<Range> selectionRange)
+{
+ auto range = Range::create(selectionRange->ownerDocument(), selectionRange->startPosition(), position.deepEquivalent().parentAnchoredEquivalent());
+ unsigned targetOffset = TextIterator::rangeLength(range.ptr(), true);
+ return findClosestPlainText(*selectionRange.get(), matchText, 0, targetOffset);
+}
+
+void WebPage::getRectsAtSelectionOffsetWithText(int32_t offset, const String& text, uint64_t callbackID)
+{
+ Frame& frame = m_page->focusController().focusedOrMainFrame();
+ uint32_t length = text.length();
+ VisibleSelection selection = frame.selection().selection();
+ VisiblePosition selectionStart = selection.visibleStart();
+ VisiblePosition selectionEnd = selection.visibleEnd();
+
+ if (selectionStart.isNull() || selectionEnd.isNull()) {
+ send(Messages::WebPageProxy::SelectionRectsCallback({ }, callbackID));
+ return;
+ }
+
+ auto startPosition = visiblePositionForPositionWithOffset(selectionStart, offset);
+ auto endPosition = visiblePositionForPositionWithOffset(startPosition, length);
+ auto range = Range::create(*frame.document(), startPosition, endPosition);
+
+ if (range->collapsed()) {
+ send(Messages::WebPageProxy::SelectionRectsCallback({ }, callbackID));
+ return;
+ }
+
+ String rangeText = plainTextReplacingNoBreakSpace(range.ptr(), TextIteratorDefaultBehavior, true);
+ if (rangeText != text) {
+ auto selectionRange = selection.toNormalizedRange();
+ // Try to search for a range which is the closest to the position within the selection range that matches the passed in text.
+ if (auto wordRange = rangeNearPositionMatchesText(startPosition, range.ptr(), text, selectionRange)) {
+ if (!wordRange->collapsed())
+ range = *wordRange;
+ }
+ }
+
+ Vector<WebCore::SelectionRect> selectionRects;
+ range->collectSelectionRectsWithoutUnionInteriorLines(selectionRects);
+ convertSelectionRectsToRootView(frame.view(), selectionRects);
+ send(Messages::WebPageProxy::SelectionRectsCallback(selectionRects, callbackID));
+}
+
</ins><span class="cx"> VisiblePosition WebPage::visiblePositionInFocusedNodeForPoint(const Frame& frame, const IntPoint& point, bool isInteractingWithAssistedNode)
</span><span class="cx"> {
</span><span class="cx"> IntPoint adjustedPoint(frame.view()->rootViewToContents(point));
</span></span></pre>
</div>
</div>
</body>
</html>