<!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>[200106] trunk/Source</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/200106">200106</a></dd>
<dt>Author</dt> <dd>bdakin@apple.com</dd>
<dt>Date</dt> <dd>2016-04-26 13:09:32 -0700 (Tue, 26 Apr 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Check to make sure shouldRequestCandidates() before requesting candidates
https://bugs.webkit.org/show_bug.cgi?id=157038
-and corresponding-
rdar://problem/25910418

Reviewed by Tim Horton.

This patch limits requesting and showing candidates to cases where 
shouldRequestCandidates() is true. This patch also caches the sequence number 
returned by [NSSpellChecker requestCandidatesForSelectedRange:] to make sure 
it is equal to the sequence number sent to the callback handler so that we do 
not show candidates for old requests.

Source/WebKit/mac:

* WebCoreSupport/WebEditorClient.h:
* WebCoreSupport/WebEditorClient.mm:
(WebEditorClient::requestCandidatesForSelection):
(WebEditorClient::handleRequestedCandidates):
* WebView/WebView.mm:
(-[WebView showCandidates:forString:inRect:forSelectedRange:view:completionHandler:]):
(-[WebView shouldRequestCandidates]):
* WebView/WebViewInternal.h:

Source/WebKit2:

* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::updateWebViewImplAdditions):
(WebKit::WebViewImpl::shouldRequestCandidates):
(WebKit::WebViewImpl::showCandidates):
(WebKit::WebViewImpl::requestCandidatesForSelectionIfNeeded):
(WebKit::WebViewImpl::handleRequestedCandidates):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitmacChangeLog">trunk/Source/WebKit/mac/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitmacWebCoreSupportWebEditorClienth">trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.h</a></li>
<li><a href="#trunkSourceWebKitmacWebCoreSupportWebEditorClientmm">trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm</a></li>
<li><a href="#trunkSourceWebKitmacWebViewWebViewmm">trunk/Source/WebKit/mac/WebView/WebView.mm</a></li>
<li><a href="#trunkSourceWebKitmacWebViewWebViewInternalh">trunk/Source/WebKit/mac/WebView/WebViewInternal.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCocoaWebViewImplh">trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCocoaWebViewImplmm">trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitmacChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/ChangeLog (200105 => 200106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/ChangeLog        2016-04-26 20:01:13 UTC (rev 200105)
+++ trunk/Source/WebKit/mac/ChangeLog        2016-04-26 20:09:32 UTC (rev 200106)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2016-04-26  Beth Dakin  &lt;bdakin@apple.com&gt;
+
+        Check to make sure shouldRequestCandidates() before requesting candidates
+        https://bugs.webkit.org/show_bug.cgi?id=157038
+        -and corresponding-
+        rdar://problem/25910418
+
+        Reviewed by Tim Horton.
+
+        This patch limits requesting and showing candidates to cases where 
+        shouldRequestCandidates() is true. This patch also caches the sequence number 
+        returned by [NSSpellChecker requestCandidatesForSelectedRange:] to make sure 
+        it is equal to the sequence number sent to the callback handler so that we do 
+        not show candidates for old requests.
+
+        * WebCoreSupport/WebEditorClient.h:
+        * WebCoreSupport/WebEditorClient.mm:
+        (WebEditorClient::requestCandidatesForSelection):
+        (WebEditorClient::handleRequestedCandidates):
+        * WebView/WebView.mm:
+        (-[WebView showCandidates:forString:inRect:forSelectedRange:view:completionHandler:]):
+        (-[WebView shouldRequestCandidates]):
+        * WebView/WebViewInternal.h:
+
</ins><span class="cx"> 2016-04-25  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove the build flag for template elements
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebCoreSupportWebEditorClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.h (200105 => 200106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.h        2016-04-26 20:01:13 UTC (rev 200105)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.h        2016-04-26 20:09:32 UTC (rev 200106)
</span><span class="lines">@@ -190,6 +190,7 @@
</span><span class="cx"> #if PLATFORM(MAC) &amp;&amp; __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 101200
</span><span class="cx">     RetainPtr&lt;NSString&gt; m_paragraphContextForCandidateRequest;
</span><span class="cx">     NSRange m_rangeForCandidates;
</span><ins>+    NSInteger m_lastCandidateRequestSequenceNumber;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     WeakPtrFactory&lt;WebEditorClient&gt; m_weakPtrFactory;
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebCoreSupportWebEditorClientmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm (200105 => 200106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm        2016-04-26 20:01:13 UTC (rev 200105)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm        2016-04-26 20:09:32 UTC (rev 200106)
</span><span class="lines">@@ -1139,6 +1139,9 @@
</span><span class="cx"> #if PLATFORM(MAC) &amp;&amp; __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 101200
</span><span class="cx"> void WebEditorClient::requestCandidatesForSelection(const VisibleSelection&amp; selection)
</span><span class="cx"> {
</span><ins>+    if (![m_webView shouldRequestCandidates])
+        return;
+
</ins><span class="cx">     RefPtr&lt;Range&gt; selectedRange = selection.toNormalizedRange();
</span><span class="cx">     if (!selectedRange)
</span><span class="cx">         return;
</span><span class="lines">@@ -1158,7 +1161,7 @@
</span><span class="cx"> 
</span><span class="cx">     NSTextCheckingTypes checkingTypes = NSTextCheckingTypeSpelling | NSTextCheckingTypeReplacement | NSTextCheckingTypeCorrection;
</span><span class="cx">     auto weakEditor = m_weakPtrFactory.createWeakPtr();
</span><del>-    [[NSSpellChecker sharedSpellChecker] requestCandidatesForSelectedRange:m_rangeForCandidates inString:m_paragraphContextForCandidateRequest.get() types:checkingTypes options:nil inSpellDocumentWithTag:spellCheckerDocumentTag() completionHandler:[weakEditor](NSInteger sequenceNumber, NSArray&lt;NSTextCheckingResult *&gt; *candidates) {
</del><ins>+    m_lastCandidateRequestSequenceNumber = [[NSSpellChecker sharedSpellChecker] requestCandidatesForSelectedRange:m_rangeForCandidates inString:m_paragraphContextForCandidateRequest.get() types:checkingTypes options:nil inSpellDocumentWithTag:spellCheckerDocumentTag() completionHandler:[weakEditor](NSInteger sequenceNumber, NSArray&lt;NSTextCheckingResult *&gt; *candidates) {
</ins><span class="cx">         dispatch_async(dispatch_get_main_queue(), ^{
</span><span class="cx">             if (!weakEditor)
</span><span class="cx">                 return;
</span><span class="lines">@@ -1170,6 +1173,12 @@
</span><span class="cx"> 
</span><span class="cx"> void WebEditorClient::handleRequestedCandidates(NSInteger sequenceNumber, NSArray&lt;NSTextCheckingResult *&gt; *candidates)
</span><span class="cx"> {
</span><ins>+    if (![m_webView shouldRequestCandidates])
+        return;
+
+    if (m_lastCandidateRequestSequenceNumber != sequenceNumber)
+        return;
+
</ins><span class="cx">     Frame* frame = core([m_webView _selectedOrMainFrame]);
</span><span class="cx">     if (!frame)
</span><span class="cx">         return;
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebViewWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (200105 => 200106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebView/WebView.mm        2016-04-26 20:01:13 UTC (rev 200105)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm        2016-04-26 20:09:32 UTC (rev 200106)
</span><span class="lines">@@ -6679,6 +6679,11 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (BOOL)shouldRequestCandidates
+{
+    return NO;
+}
+
</ins><span class="cx"> @end
</span><span class="cx"> #endif // PLATFORM(MAC) &amp;&amp; __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 101200 &amp;&amp; USE(APPLE_INTERNAL_SDK)
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebViewWebViewInternalh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebView/WebViewInternal.h (200105 => 200106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebView/WebViewInternal.h        2016-04-26 20:01:13 UTC (rev 200105)
+++ trunk/Source/WebKit/mac/WebView/WebViewInternal.h        2016-04-26 20:09:32 UTC (rev 200106)
</span><span class="lines">@@ -298,4 +298,5 @@
</span><span class="cx"> @interface WebView (WebUpdateWebViewAdditions)
</span><span class="cx"> - (void)updateWebViewAdditions;
</span><span class="cx"> - (void)showCandidates:(NSArray *)candidates forString:(NSString *)string inRect:(NSRect)rectOfTypedString forSelectedRange:(NSRange)range view:(NSView *)view completionHandler:(void (^)(NSTextCheckingResult *acceptedCandidate))completionBlock;
</span><ins>+- (BOOL)shouldRequestCandidates;
</ins><span class="cx"> @end
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (200105 => 200106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-04-26 20:01:13 UTC (rev 200105)
+++ trunk/Source/WebKit2/ChangeLog        2016-04-26 20:09:32 UTC (rev 200106)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2016-04-26  Beth Dakin  &lt;bdakin@apple.com&gt;
+
+        Check to make sure shouldRequestCandidates() before requesting candidates
+        https://bugs.webkit.org/show_bug.cgi?id=157038
+        -and corresponding-
+        rdar://problem/25910418
+
+        Reviewed by Tim Horton.
+
+        This patch limits requesting and showing candidates to cases where 
+        shouldRequestCandidates() is true. This patch also caches the sequence number 
+        returned by [NSSpellChecker requestCandidatesForSelectedRange:] to make sure 
+        it is equal to the sequence number sent to the callback handler so that we do 
+        not show candidates for old requests.
+
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::updateWebViewImplAdditions):
+        (WebKit::WebViewImpl::shouldRequestCandidates):
+        (WebKit::WebViewImpl::showCandidates):
+        (WebKit::WebViewImpl::requestCandidatesForSelectionIfNeeded):
+        (WebKit::WebViewImpl::handleRequestedCandidates):
+
</ins><span class="cx"> 2016-04-26  Gyuyoung Kim  &lt;gyuyoung.kim@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         [EFL] Update expectation result in ewk_context_preferred_languages API test
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaWebViewImplh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h (200105 => 200106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h        2016-04-26 20:01:13 UTC (rev 200105)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h        2016-04-26 20:09:32 UTC (rev 200106)
</span><span class="lines">@@ -472,6 +472,7 @@
</span><span class="cx">     void rightMouseUp(NSEvent *);
</span><span class="cx"> 
</span><span class="cx">     void updateWebViewImplAdditions();
</span><ins>+    bool shouldRequestCandidates() const;
</ins><span class="cx">     void showCandidates(NSArray *candidates, NSString *, NSRect rectOfTypedString, NSRange selectedRange, NSView *, void (^completionHandler)(NSTextCheckingResult *acceptedCandidate));
</span><span class="cx">     void webViewImplAdditionsWillDestroyView();
</span><span class="cx"> 
</span><span class="lines">@@ -628,6 +629,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 101200
</span><span class="cx">     String m_lastStringForCandidateRequest;
</span><ins>+    NSInteger m_lastCandidateRequestSequenceNumber;
</ins><span class="cx"> #endif
</span><span class="cx">     NSRange m_softSpaceRange { NSNotFound, 0 };
</span><span class="cx">     bool m_isHandlingAcceptedCandidate { false };
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaWebViewImplmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm (200105 => 200106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm        2016-04-26 20:01:13 UTC (rev 200105)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm        2016-04-26 20:09:32 UTC (rev 200106)
</span><span class="lines">@@ -439,6 +439,11 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool WebViewImpl::shouldRequestCandidates() const
+{
+    return false;
+}
+
</ins><span class="cx"> void WebViewImpl::showCandidates(NSArray *candidates, NSString *string, NSRect rectOfTypedString, NSRange selectedRange, NSView *view, void (^completionHandler)(NSTextCheckingResult *acceptedCandidate))
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="lines">@@ -2147,6 +2152,9 @@
</span><span class="cx"> #if __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 101200
</span><span class="cx"> void WebViewImpl::requestCandidatesForSelectionIfNeeded()
</span><span class="cx"> {
</span><ins>+    if (!shouldRequestCandidates())
+        return;
+
</ins><span class="cx">     const EditorState&amp; editorState = m_page-&gt;editorState();
</span><span class="cx">     if (!editorState.isContentEditable)
</span><span class="cx">         return;
</span><span class="lines">@@ -2161,7 +2169,7 @@
</span><span class="cx">     NSRange selectedRange = NSMakeRange(postLayoutData.candidateRequestStartPosition, postLayoutData.selectedTextLength);
</span><span class="cx">     NSTextCheckingTypes checkingTypes = NSTextCheckingTypeSpelling | NSTextCheckingTypeReplacement | NSTextCheckingTypeCorrection;
</span><span class="cx">     auto weakThis = createWeakPtr();
</span><del>-    [[NSSpellChecker sharedSpellChecker] requestCandidatesForSelectedRange:selectedRange inString:postLayoutData.paragraphContextForCandidateRequest types:checkingTypes options:nil inSpellDocumentWithTag:spellCheckerDocumentTag() completionHandler:[weakThis](NSInteger sequenceNumber, NSArray&lt;NSTextCheckingResult *&gt; *candidates) {
</del><ins>+    m_lastCandidateRequestSequenceNumber = [[NSSpellChecker sharedSpellChecker] requestCandidatesForSelectedRange:selectedRange inString:postLayoutData.paragraphContextForCandidateRequest types:checkingTypes options:nil inSpellDocumentWithTag:spellCheckerDocumentTag() completionHandler:[weakThis](NSInteger sequenceNumber, NSArray&lt;NSTextCheckingResult *&gt; *candidates) {
</ins><span class="cx">         dispatch_async(dispatch_get_main_queue(), ^{
</span><span class="cx">             if (!weakThis)
</span><span class="cx">                 return;
</span><span class="lines">@@ -2173,6 +2181,12 @@
</span><span class="cx"> 
</span><span class="cx"> void WebViewImpl::handleRequestedCandidates(NSInteger sequenceNumber, NSArray&lt;NSTextCheckingResult *&gt; *candidates)
</span><span class="cx"> {
</span><ins>+    if (!shouldRequestCandidates())
+        return;
+
+    if (m_lastCandidateRequestSequenceNumber != sequenceNumber)
+        return;
+
</ins><span class="cx">     const EditorState&amp; editorState = m_page-&gt;editorState();
</span><span class="cx">     if (!editorState.isContentEditable)
</span><span class="cx">         return;
</span></span></pre>
</div>
</div>

</body>
</html>