Title: [200106] trunk/Source
Revision
200106
Author
[email protected]
Date
2016-04-26 13:09:32 -0700 (Tue, 26 Apr 2016)

Log Message

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):

Modified Paths

Diff

Modified: trunk/Source/WebKit/mac/ChangeLog (200105 => 200106)


--- 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)
@@ -1,3 +1,27 @@
+2016-04-26  Beth Dakin  <[email protected]>
+
+        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:
+
 2016-04-25  Ryosuke Niwa  <[email protected]>
 
         Remove the build flag for template elements

Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.h (200105 => 200106)


--- 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)
@@ -190,6 +190,7 @@
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
     RetainPtr<NSString> m_paragraphContextForCandidateRequest;
     NSRange m_rangeForCandidates;
+    NSInteger m_lastCandidateRequestSequenceNumber;
 #endif
 
     WeakPtrFactory<WebEditorClient> m_weakPtrFactory;

Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm (200105 => 200106)


--- 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)
@@ -1139,6 +1139,9 @@
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
 void WebEditorClient::requestCandidatesForSelection(const VisibleSelection& selection)
 {
+    if (![m_webView shouldRequestCandidates])
+        return;
+
     RefPtr<Range> selectedRange = selection.toNormalizedRange();
     if (!selectedRange)
         return;
@@ -1158,7 +1161,7 @@
 
     NSTextCheckingTypes checkingTypes = NSTextCheckingTypeSpelling | NSTextCheckingTypeReplacement | NSTextCheckingTypeCorrection;
     auto weakEditor = m_weakPtrFactory.createWeakPtr();
-    [[NSSpellChecker sharedSpellChecker] requestCandidatesForSelectedRange:m_rangeForCandidates inString:m_paragraphContextForCandidateRequest.get() types:checkingTypes options:nil inSpellDocumentWithTag:spellCheckerDocumentTag() completionHandler:[weakEditor](NSInteger sequenceNumber, NSArray<NSTextCheckingResult *> *candidates) {
+    m_lastCandidateRequestSequenceNumber = [[NSSpellChecker sharedSpellChecker] requestCandidatesForSelectedRange:m_rangeForCandidates inString:m_paragraphContextForCandidateRequest.get() types:checkingTypes options:nil inSpellDocumentWithTag:spellCheckerDocumentTag() completionHandler:[weakEditor](NSInteger sequenceNumber, NSArray<NSTextCheckingResult *> *candidates) {
         dispatch_async(dispatch_get_main_queue(), ^{
             if (!weakEditor)
                 return;
@@ -1170,6 +1173,12 @@
 
 void WebEditorClient::handleRequestedCandidates(NSInteger sequenceNumber, NSArray<NSTextCheckingResult *> *candidates)
 {
+    if (![m_webView shouldRequestCandidates])
+        return;
+
+    if (m_lastCandidateRequestSequenceNumber != sequenceNumber)
+        return;
+
     Frame* frame = core([m_webView _selectedOrMainFrame]);
     if (!frame)
         return;

Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (200105 => 200106)


--- 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)
@@ -6679,6 +6679,11 @@
 {
 }
 
+- (BOOL)shouldRequestCandidates
+{
+    return NO;
+}
+
 @end
 #endif // PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 && USE(APPLE_INTERNAL_SDK)
 

Modified: trunk/Source/WebKit/mac/WebView/WebViewInternal.h (200105 => 200106)


--- 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)
@@ -298,4 +298,5 @@
 @interface WebView (WebUpdateWebViewAdditions)
 - (void)updateWebViewAdditions;
 - (void)showCandidates:(NSArray *)candidates forString:(NSString *)string inRect:(NSRect)rectOfTypedString forSelectedRange:(NSRange)range view:(NSView *)view completionHandler:(void (^)(NSTextCheckingResult *acceptedCandidate))completionBlock;
+- (BOOL)shouldRequestCandidates;
 @end

Modified: trunk/Source/WebKit2/ChangeLog (200105 => 200106)


--- 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)
@@ -1,3 +1,26 @@
+2016-04-26  Beth Dakin  <[email protected]>
+
+        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):
+
 2016-04-26  Gyuyoung Kim  <[email protected]>
 
         [EFL] Update expectation result in ewk_context_preferred_languages API test

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h (200105 => 200106)


--- 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)
@@ -472,6 +472,7 @@
     void rightMouseUp(NSEvent *);
 
     void updateWebViewImplAdditions();
+    bool shouldRequestCandidates() const;
     void showCandidates(NSArray *candidates, NSString *, NSRect rectOfTypedString, NSRange selectedRange, NSView *, void (^completionHandler)(NSTextCheckingResult *acceptedCandidate));
     void webViewImplAdditionsWillDestroyView();
 
@@ -628,6 +629,7 @@
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
     String m_lastStringForCandidateRequest;
+    NSInteger m_lastCandidateRequestSequenceNumber;
 #endif
     NSRange m_softSpaceRange { NSNotFound, 0 };
     bool m_isHandlingAcceptedCandidate { false };

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm (200105 => 200106)


--- 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)
@@ -439,6 +439,11 @@
 {
 }
 
+bool WebViewImpl::shouldRequestCandidates() const
+{
+    return false;
+}
+
 void WebViewImpl::showCandidates(NSArray *candidates, NSString *string, NSRect rectOfTypedString, NSRange selectedRange, NSView *view, void (^completionHandler)(NSTextCheckingResult *acceptedCandidate))
 {
 }
@@ -2147,6 +2152,9 @@
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
 void WebViewImpl::requestCandidatesForSelectionIfNeeded()
 {
+    if (!shouldRequestCandidates())
+        return;
+
     const EditorState& editorState = m_page->editorState();
     if (!editorState.isContentEditable)
         return;
@@ -2161,7 +2169,7 @@
     NSRange selectedRange = NSMakeRange(postLayoutData.candidateRequestStartPosition, postLayoutData.selectedTextLength);
     NSTextCheckingTypes checkingTypes = NSTextCheckingTypeSpelling | NSTextCheckingTypeReplacement | NSTextCheckingTypeCorrection;
     auto weakThis = createWeakPtr();
-    [[NSSpellChecker sharedSpellChecker] requestCandidatesForSelectedRange:selectedRange inString:postLayoutData.paragraphContextForCandidateRequest types:checkingTypes options:nil inSpellDocumentWithTag:spellCheckerDocumentTag() completionHandler:[weakThis](NSInteger sequenceNumber, NSArray<NSTextCheckingResult *> *candidates) {
+    m_lastCandidateRequestSequenceNumber = [[NSSpellChecker sharedSpellChecker] requestCandidatesForSelectedRange:selectedRange inString:postLayoutData.paragraphContextForCandidateRequest types:checkingTypes options:nil inSpellDocumentWithTag:spellCheckerDocumentTag() completionHandler:[weakThis](NSInteger sequenceNumber, NSArray<NSTextCheckingResult *> *candidates) {
         dispatch_async(dispatch_get_main_queue(), ^{
             if (!weakThis)
                 return;
@@ -2173,6 +2181,12 @@
 
 void WebViewImpl::handleRequestedCandidates(NSInteger sequenceNumber, NSArray<NSTextCheckingResult *> *candidates)
 {
+    if (!shouldRequestCandidates())
+        return;
+
+    if (m_lastCandidateRequestSequenceNumber != sequenceNumber)
+        return;
+
     const EditorState& editorState = m_page->editorState();
     if (!editorState.isContentEditable)
         return;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to