Skip to content
Permalink
Browse files
[iOS] Specifying spellcheck="false" on a contentEditable element shou…
…ld suppress platform spellchecking

https://bugs.webkit.org/show_bug.cgi?id=241514
rdar://91123300

Reviewed by Devin Rousso.

Additionally set `-[UITextInputTraits spellCheckingType]` to `UITextSpellCheckingTypeNo` when
focusing editable fields with the DOM attribute `spellcheck="false"`. This provides a hint to UIKit
that system spellchecking should be disabled when editing this field - among other things, this
allows us to avoid showing text candidates in the case where `autocorrect="off"` is additionally
specified.

If either `spellcheck="true"` is set or `spellcheck` is not specified, we fall back to the user's
preference by using `UITextSpellCheckingTypeDefault`.

Test: KeyboardInputTests.DisableSpellChecking

* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _updateTextInputTraits:]):
* Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
(TestWebKitAPI::TEST):

Canonical link: https://commits.webkit.org/251473@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295468 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
whsieh committed Jun 10, 2022
1 parent 6616e77 commit 2d67e9cb94d7b6a8fa75ca87c72ca437752e0199
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
@@ -5897,6 +5897,7 @@ - (void)_updateTextInputTraits:(id <UITextInputTraits>)traits
traits.smartQuotesType = UITextSmartQuotesTypeNo;
if ([traits respondsToSelector:@selector(setSmartDashesType:)])
traits.smartDashesType = UITextSmartDashesTypeNo;
traits.spellCheckingType = UITextSpellCheckingTypeNo;
}

switch (_focusedElementInformation.inputMode) {
@@ -624,7 +624,7 @@ - (NSUndoManager *)undoManager
EXPECT_EQ(inputView.get(), [contentView inputView]);
}

TEST(KeyboardInputTests, DisableSmartQuotesAndDashes)
TEST(KeyboardInputTests, DisableSpellChecking)
{
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
auto inputDelegate = adoptNS([[TestInputDelegate alloc] init]);
@@ -633,27 +633,28 @@ - (NSUndoManager *)undoManager
}];
[webView _setInputDelegate:inputDelegate.get()];

auto checkSmartQuotesAndDashesType = [&] (UITextSmartDashesType dashesType, UITextSmartQuotesType quotesType) {
auto checkSmartQuotesAndDashesType = [&] (UITextSmartDashesType dashesType, UITextSmartQuotesType quotesType, UITextSpellCheckingType spellCheckingType) {
UITextInputTraits *traits = [[webView textInputContentView] textInputTraits];
EXPECT_EQ(dashesType, traits.smartDashesType);
EXPECT_EQ(quotesType, traits.smartQuotesType);
EXPECT_EQ(spellCheckingType, traits.spellCheckingType);
};

[webView synchronouslyLoadHTMLString:@"<div id='foo' contenteditable spellcheck='false'></div><textarea id='bar' spellcheck='false'></textarea><input id='baz' spellcheck='false'>"];
[webView evaluateJavaScriptAndWaitForInputSessionToChange:@"foo.focus()"];
checkSmartQuotesAndDashesType(UITextSmartDashesTypeNo, UITextSmartQuotesTypeNo);
checkSmartQuotesAndDashesType(UITextSmartDashesTypeNo, UITextSmartQuotesTypeNo, UITextSpellCheckingTypeNo);
[webView evaluateJavaScriptAndWaitForInputSessionToChange:@"bar.focus()"];
checkSmartQuotesAndDashesType(UITextSmartDashesTypeNo, UITextSmartQuotesTypeNo);
checkSmartQuotesAndDashesType(UITextSmartDashesTypeNo, UITextSmartQuotesTypeNo, UITextSpellCheckingTypeNo);
[webView evaluateJavaScriptAndWaitForInputSessionToChange:@"baz.focus()"];
checkSmartQuotesAndDashesType(UITextSmartDashesTypeNo, UITextSmartQuotesTypeNo);
checkSmartQuotesAndDashesType(UITextSmartDashesTypeNo, UITextSmartQuotesTypeNo, UITextSpellCheckingTypeNo);

[webView synchronouslyLoadHTMLString:@"<div id='foo' contenteditable></div><textarea id='bar' spellcheck='true'></textarea><input id='baz'>"];
[webView evaluateJavaScriptAndWaitForInputSessionToChange:@"foo.focus()"];
checkSmartQuotesAndDashesType(UITextSmartDashesTypeDefault, UITextSmartQuotesTypeDefault);
checkSmartQuotesAndDashesType(UITextSmartDashesTypeDefault, UITextSmartQuotesTypeDefault, UITextSpellCheckingTypeDefault);
[webView evaluateJavaScriptAndWaitForInputSessionToChange:@"bar.focus()"];
checkSmartQuotesAndDashesType(UITextSmartDashesTypeDefault, UITextSmartQuotesTypeDefault);
checkSmartQuotesAndDashesType(UITextSmartDashesTypeDefault, UITextSmartQuotesTypeDefault, UITextSpellCheckingTypeDefault);
[webView evaluateJavaScriptAndWaitForInputSessionToChange:@"baz.focus()"];
checkSmartQuotesAndDashesType(UITextSmartDashesTypeDefault, UITextSmartQuotesTypeDefault);
checkSmartQuotesAndDashesType(UITextSmartDashesTypeDefault, UITextSmartQuotesTypeDefault, UITextSpellCheckingTypeDefault);
}

TEST(KeyboardInputTests, SelectionClipRectsWhenPresentingInputView)

0 comments on commit 2d67e9c

Please sign in to comment.