Title: [291618] trunk
Revision
291618
Author
wenson_hs...@apple.com
Date
2022-03-22 08:24:09 -0700 (Tue, 22 Mar 2022)

Log Message

-[WKWebView _spellCheckerDocumentTag] is inconsistent with the document tag passed into NSSpellChecker
https://bugs.webkit.org/show_bug.cgi?id=238186
rdar://90591883

Reviewed by Tim Horton.

Source/WebKit:

Currently, WebViewImpl and WebPageProxy both maintain separate spellchecking document tag values, both of which
are derived from `-[NSSpellChecker uniqueSpellDocumentTag]`. While the former is used for autocorrection as well
as the WKWebView SPI `-_spellCheckerDocumentTag`, the latter is passed into NSSpellChecker API when performing
spellchecking.

For various reasons, Mail compose (using WebKit2) requires `-_spellCheckerDocumentTag` to be consistent with the
value of the spell checker document tag passed into `-checkString:range:…:inSpellDocumentWithTag:orthography:`.
Address this by simply having WebViewImpl call through into WebPageProxy's `spellDocumentTag`, such that the two
now share the same value.

Test: SpellCheckerDocumentTag.SpellCheckerDocumentTagWhenCheckingString

* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::spellCheckerDocumentTag):

Tools:

Add a test to verify that the spell checking document tag passed into NSSpellChecker API is consistent with the
document tag reported by WKWebView.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/mac/SpellCheckerDocumentTag.mm: Added.
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (291617 => 291618)


--- trunk/Source/WebKit/ChangeLog	2022-03-22 14:48:44 UTC (rev 291617)
+++ trunk/Source/WebKit/ChangeLog	2022-03-22 15:24:09 UTC (rev 291618)
@@ -1,3 +1,27 @@
+2022-03-22  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        -[WKWebView _spellCheckerDocumentTag] is inconsistent with the document tag passed into NSSpellChecker
+        https://bugs.webkit.org/show_bug.cgi?id=238186
+        rdar://90591883
+
+        Reviewed by Tim Horton.
+
+        Currently, WebViewImpl and WebPageProxy both maintain separate spellchecking document tag values, both of which
+        are derived from `-[NSSpellChecker uniqueSpellDocumentTag]`. While the former is used for autocorrection as well
+        as the WKWebView SPI `-_spellCheckerDocumentTag`, the latter is passed into NSSpellChecker API when performing
+        spellchecking.
+
+        For various reasons, Mail compose (using WebKit2) requires `-_spellCheckerDocumentTag` to be consistent with the
+        value of the spell checker document tag passed into `-checkString:range:…:inSpellDocumentWithTag:orthography:`.
+        Address this by simply having WebViewImpl call through into WebPageProxy's `spellDocumentTag`, such that the two
+        now share the same value.
+
+        Test: SpellCheckerDocumentTag.SpellCheckerDocumentTagWhenCheckingString
+
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::spellCheckerDocumentTag):
+
 2022-03-22  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [GTK][WPE] Remove the ATK implementation

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h (291617 => 291618)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h	2022-03-22 14:48:44 UTC (rev 291617)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h	2022-03-22 15:24:09 UTC (rev 291618)
@@ -846,8 +846,6 @@
     String m_promisedFilename;
     String m_promisedURL;
 
-    std::optional<NSInteger> m_spellCheckerDocumentTag;
-
     CGFloat m_totalHeightOfBanners { 0 };
 
     RetainPtr<NSView> m_inspectorAttachmentView;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (291617 => 291618)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2022-03-22 14:48:44 UTC (rev 291617)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2022-03-22 15:24:09 UTC (rev 291618)
@@ -2828,9 +2828,7 @@
 
 NSInteger WebViewImpl::spellCheckerDocumentTag()
 {
-    if (!m_spellCheckerDocumentTag)
-        m_spellCheckerDocumentTag = [NSSpellChecker uniqueSpellDocumentTag];
-    return m_spellCheckerDocumentTag.value();
+    return m_page->spellDocumentTag();
 }
 
 void WebViewImpl::pressureChangeWithEvent(NSEvent *event)

Modified: trunk/Tools/ChangeLog (291617 => 291618)


--- trunk/Tools/ChangeLog	2022-03-22 14:48:44 UTC (rev 291617)
+++ trunk/Tools/ChangeLog	2022-03-22 15:24:09 UTC (rev 291618)
@@ -1,3 +1,18 @@
+2022-03-22  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        -[WKWebView _spellCheckerDocumentTag] is inconsistent with the document tag passed into NSSpellChecker
+        https://bugs.webkit.org/show_bug.cgi?id=238186
+        rdar://90591883
+
+        Reviewed by Tim Horton.
+
+        Add a test to verify that the spell checking document tag passed into NSSpellChecker API is consistent with the
+        document tag reported by WKWebView.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/mac/SpellCheckerDocumentTag.mm: Added.
+        (TestWebKitAPI::TEST):
+
 2022-03-22  Jonathan Bedard  <jbed...@apple.com>
 
         [git-webkit] Make radar conditional on authentication (Follow-up fix)

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (291617 => 291618)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2022-03-22 14:48:44 UTC (rev 291617)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2022-03-22 15:24:09 UTC (rev 291618)
@@ -1116,6 +1116,7 @@
 		F4C2AB221DD6D95E00E06D5B /* enormous-video-with-sound.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */; };
 		F4C8797F2059D8D3009CD00B /* ScrollViewInsetTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4C8797E2059D8D3009CD00B /* ScrollViewInsetTests.mm */; };
 		F4CD74C620FDACFA00DE3794 /* text-with-async-script.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4CD74C520FDACF500DE3794 /* text-with-async-script.html */; };
+		F4CDF3D227E97C7E00191928 /* SpellCheckerDocumentTag.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4CDF3D127E97C7E00191928 /* SpellCheckerDocumentTag.mm */; };
 		F4CF32802366552200D3AD07 /* EnterKeyHintTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4CF327F2366552200D3AD07 /* EnterKeyHintTests.mm */; };
 		F4CFCDDA249FC9E400527482 /* SpaceOnly.otf in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4CFCDD8249FC9D900527482 /* SpaceOnly.otf */; };
 		F4D060082734A1AB008FA67A /* simple-editor.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4D060072734A08C008FA67A /* simple-editor.html */; };
@@ -2058,7 +2059,6 @@
 		4995A6EF25E876A300E5F0A9 /* csp-document-uri-report.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "csp-document-uri-report.html"; sourceTree = "<group>"; };
 		49AEEF682407276F00C87E4C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 		49AEEF6B2407358600C87E4C /* InAppBrowserPrivacy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InAppBrowserPrivacy.mm; sourceTree = "<group>"; };
-		49CB61AF27E17E4D0017078E /* WKPrinting.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKPrinting.mm; sourceTree = "<group>"; };
 		49D2E5C12731E37400BCCAED /* file-with-iframe.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "file-with-iframe.html"; sourceTree = "<group>"; };
 		49D7FBA7241FDDDA00AB67FA /* in-app-browser-privacy-local-file.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "in-app-browser-privacy-local-file.html"; sourceTree = "<group>"; };
 		49EF6AD42677C0BE007967DC /* AppPrivacyReport.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AppPrivacyReport.mm; sourceTree = "<group>"; };
@@ -3146,6 +3146,7 @@
 		F4CD74C720FDB49600DE3794 /* TestURLSchemeHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestURLSchemeHandler.h; sourceTree = "<group>"; };
 		F4CD74C820FDB49600DE3794 /* TestURLSchemeHandler.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TestURLSchemeHandler.mm; sourceTree = "<group>"; };
 		F4CDAB3322489FE10057A2D9 /* UserInterfaceSwizzler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UserInterfaceSwizzler.h; sourceTree = "<group>"; };
+		F4CDF3D127E97C7E00191928 /* SpellCheckerDocumentTag.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SpellCheckerDocumentTag.mm; sourceTree = "<group>"; };
 		F4CF327F2366552200D3AD07 /* EnterKeyHintTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = EnterKeyHintTests.mm; sourceTree = "<group>"; };
 		F4CFCDD8249FC9D900527482 /* SpaceOnly.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = SpaceOnly.otf; sourceTree = "<group>"; };
 		F4CFCDD9249FC9D900527482 /* Ahem.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Ahem.ttf; sourceTree = "<group>"; };
@@ -3722,7 +3723,6 @@
 				375E0E151D66674400EFEC2C /* WKNSNumber.mm */,
 				37B47E2E1D64E7CA005F4EFF /* WKObject.mm */,
 				2D00065D1C1F58940088E6A7 /* WKPDFView.mm */,
-				49CB61AC27E145B40017078E /* WKPrinting.mm */,
 				3781746C2198AE2400062C26 /* WKProcessPoolConfiguration.mm */,
 				44817A2E1F0486BF00003810 /* WKRequestActivatedElementInfo.mm */,
 				5E4B1D2C1D404C6100053621 /* WKScrollViewDelegate.mm */,
@@ -4941,6 +4941,7 @@
 				261516D515B0E60500A2C201 /* SetAndUpdateCacheModel.mm */,
 				52B8CF9515868CF000281053 /* SetDocumentURI.mm */,
 				C540F775152E4DA000A40C8C /* SimplifyMarkup.mm */,
+				F4CDF3D127E97C7E00191928 /* SpellCheckerDocumentTag.mm */,
 				57F4AA9F208FA83D00A68E9E /* SSLKeyGenerator.mm */,
 				83BC5ABF20E6C0D300F5879F /* StartLoadInDidFailProvisionalLoad.mm */,
 				291861FD17BD4DC700D4E41E /* StopLoadingFromDidFinishLoading.mm */,
@@ -5812,6 +5813,7 @@
 				7CCE7F151A411AE600447C4C /* SpacebarScrolling.cpp in Sources */,
 				BC3FEB61267FCDB00054006A /* SpanCF.cpp in Sources */,
 				BC3FEB64267FCF740054006A /* SpanCocoa.mm in Sources */,
+				F4CDF3D227E97C7E00191928 /* SpellCheckerDocumentTag.mm in Sources */,
 				57F4AAA0208FAEF000A68E9E /* SSLKeyGenerator.mm in Sources */,
 				83BC5AC020E6C0DF00F5879F /* StartLoadInDidFailProvisionalLoad.mm in Sources */,
 				51EB126524CA6B66000CB030 /* SteelSeriesNimbus.mm in Sources */,
@@ -5963,9 +5965,9 @@
 				1CACADA1230620AE0007D54C /* WKWebViewOpaque.mm in Sources */,
 				CD27A1C123C661ED006E11DD /* WKWebViewPausePlayingAudioTests.mm in Sources */,
 				E520A36B25AFB76C00526CB9 /* WKWebViewTitlebarSeparatorTests.mm in Sources */,
+				3545E58927E2AD1300F1910E /* WritingModeTests.cpp in Sources */,
 				7C74C8FA22DFBA9600DA2DAB /* WTFStringUtilities.cpp in Sources */,
 				C14D304624B4C3BA00480387 /* XPCEndpoint.mm in Sources */,
-				3545E58927E2AD1300F1910E /* WritingModeTests.cpp in Sources */,
 				5C581D3227C8A01C006B3BC4 /* YouTubePluginReplacement.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;

Added: trunk/Tools/TestWebKitAPI/Tests/mac/SpellCheckerDocumentTag.mm (0 => 291618)


--- trunk/Tools/TestWebKitAPI/Tests/mac/SpellCheckerDocumentTag.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/SpellCheckerDocumentTag.mm	2022-03-22 15:24:09 UTC (rev 291618)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if PLATFORM(MAC)
+
+#import "InstanceMethodSwizzler.h"
+#import "TestWKWebView.h"
+#import "Utilities.h"
+#import <WebKit/WKWebViewPrivate.h>
+
+namespace TestWebKitAPI {
+
+static NSInteger lastDocumentSpellCheckingTag = 0;
+static bool handledCheckStringRequest = false;
+static NSArray<NSTextCheckingResult *> *swizzledCheckString(id, SEL, NSString *, NSRange, NSTextCheckingTypes, NSDictionary<NSTextCheckingOptionKey, id> *, NSInteger tag, NSOrthography **, NSInteger *)
+{
+    lastDocumentSpellCheckingTag = tag;
+    handledCheckStringRequest = true;
+    return @[ ];
+}
+
+TEST(SpellCheckerDocumentTag, SpellCheckerDocumentTagWhenCheckingString)
+{
+    InstanceMethodSwizzler spellCheckingSwizzler {
+        NSSpellChecker.sharedSpellChecker.class,
+        @selector(checkString:range:types:options:inSpellDocumentWithTag:orthography:wordCount:),
+        reinterpret_cast<IMP>(swizzledCheckString)
+    };
+
+    auto webView = adoptNS([[TestWKWebView<NSTextInputClient> alloc] initWithFrame:CGRectMake(0, 0, 400, 400)]);
+    [webView synchronouslyLoadHTMLString:@"<body contenteditable>"];
+    [webView objectByEvaluatingJavaScript:@"getSelection().setPosition(document.body)"];
+    [webView insertText:@"Testing.\n" replacementRange:NSMakeRange(0, 0)];
+    Util::run(&handledCheckStringRequest);
+
+    EXPECT_GT(lastDocumentSpellCheckingTag, 0);
+    EXPECT_GT([webView _spellCheckerDocumentTag], 0);
+    EXPECT_EQ(lastDocumentSpellCheckingTag, [webView _spellCheckerDocumentTag]);
+}
+
+} // namespace TestWebKitAPI
+
+#endif // PLATFORM(MAC)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to