Skip to content

Commit

Permalink
Word completion suggestion interferes with website's suggestion results
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=271197
rdar://124727588

Reviewed by Aditya Keerthi and Abrar Rahman Protyasha.

If the value of `writingsuggestions` isn't explicitly specified, have the default value for it be
`false` instead of `true` if the element has disabled `autocomplete`.

* Source/WebCore/dom/Element.cpp:
(WebCore::Element::isWritingSuggestionsEnabled const):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WritingSuggestions.mm:
(TEST):

Canonical link: https://commits.webkit.org/276344@main
  • Loading branch information
rr-codes committed Mar 19, 2024
1 parent 79b1286 commit ab8b39b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Source/WebCore/dom/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4784,7 +4784,7 @@ bool Element::isWritingSuggestionsEnabled() const
// not in the `default` state and the nearest such ancestor's `writingsuggestions` content attribute
// is in the `false` state, then return `false`.

for (auto* ancestor = this; ancestor; ancestor = ancestor->parentElementInComposedTree()) {
for (RefPtr ancestor = this; ancestor; ancestor = ancestor->parentElementInComposedTree()) {
auto& value = ancestor->attributeWithoutSynchronization(HTMLNames::writingsuggestionsAttr);

if (value.isNull())
Expand All @@ -4795,6 +4795,12 @@ bool Element::isWritingSuggestionsEnabled() const
return false;
}

// This is not yet part of the spec, but it improves web-compatibility; if autocomplete
// is intentionally off, the site author probably wants writingsuggestions off too.
auto autocompleteValue = attributeWithoutSynchronization(HTMLNames::autocompleteAttr);
if (equalLettersIgnoringASCIICase(autocompleteValue, "off"_s))
return false;

if (protectedDocument()->quirks().shouldDisableWritingSuggestionsByDefaultQuirk())
return false;

Expand Down
8 changes: 8 additions & 0 deletions Tools/TestWebKitAPI/Tests/WebKitCocoa/WritingSuggestions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,12 @@ - (void)focusElementAndEnsureEditorStateUpdate:(NSString *)element
EXPECT_EQ(UITextInlinePredictionTypeNo, [webView effectiveTextInputTraits].inlinePredictionType);
}

TEST(WritingSuggestionsWebAPI, DefaultStateWithDisabledAutocomplete)
{
auto webView = adoptNS([[WritingSuggestionsWebAPIWKWebView alloc] initWithHTMLString:@"<body><input id='input' type='text' autocomplete='off'></input></body>"]);
[webView focusElementAndEnsureEditorStateUpdate:@"document.getElementById('input')"];

EXPECT_EQ(UITextInlinePredictionTypeNo, [webView effectiveTextInputTraits].inlinePredictionType);
}

#endif

0 comments on commit ab8b39b

Please sign in to comment.