Title: [271262] trunk
Revision
271262
Author
[email protected]
Date
2021-01-07 15:09:29 -0800 (Thu, 07 Jan 2021)

Log Message

Text fields should not be translated while typing
https://bugs.webkit.org/show_bug.cgi?id=220431
<rdar://problem/71724918>

Reviewed by Tim Horton.

Source/WebCore:

Don't vend text nodes or newly created elements inside input elements for translation (i.e. text manipulation)
if the input element was modified by the user. Note that this check is right before the call to
`observeParagraphs` as opposed to when we schedule the observation update, since edit commands may create
renderers for text nodes and other elements before the `m_lastChangeWasUserEdit` flag has been set.

Test: TextManipulation.StartTextManipulationDoesNotExtractUserModifiedText

* editing/TextManipulationController.cpp:
(WebCore::TextManipulationController::scheduleObservationUpdate):

Tools:

Add an API test that modifies text in two input fields (by executing an edit command, and then by
programmatically setting the value attribute). The test verifies that only the latter (programmatic) value
change propagates a text manipulation update to the client layer.

* TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (271261 => 271262)


--- trunk/Source/WebCore/ChangeLog	2021-01-07 22:40:14 UTC (rev 271261)
+++ trunk/Source/WebCore/ChangeLog	2021-01-07 23:09:29 UTC (rev 271262)
@@ -1,3 +1,21 @@
+2021-01-07  Wenson Hsieh  <[email protected]>
+
+        Text fields should not be translated while typing
+        https://bugs.webkit.org/show_bug.cgi?id=220431
+        <rdar://problem/71724918>
+
+        Reviewed by Tim Horton.
+
+        Don't vend text nodes or newly created elements inside input elements for translation (i.e. text manipulation)
+        if the input element was modified by the user. Note that this check is right before the call to
+        `observeParagraphs` as opposed to when we schedule the observation update, since edit commands may create
+        renderers for text nodes and other elements before the `m_lastChangeWasUserEdit` flag has been set.
+
+        Test: TextManipulation.StartTextManipulationDoesNotExtractUserModifiedText
+
+        * editing/TextManipulationController.cpp:
+        (WebCore::TextManipulationController::scheduleObservationUpdate):
+
 2021-01-07  Eric Carlson  <[email protected]>
 
         [MSE] Fix potential crash in SourceBufferPrivateAVFObjC::destroyParser

Modified: trunk/Source/WebCore/editing/TextManipulationController.cpp (271261 => 271262)


--- trunk/Source/WebCore/editing/TextManipulationController.cpp	2021-01-07 22:40:14 UTC (rev 271261)
+++ trunk/Source/WebCore/editing/TextManipulationController.cpp	2021-01-07 23:09:29 UTC (rev 271262)
@@ -605,6 +605,10 @@
         for (auto& node : nodesToObserve) {
             if (!node->isConnected())
                 continue;
+
+            if (auto host = makeRefPtr(node->shadowHost()); is<HTMLInputElement>(host.get()) && downcast<HTMLInputElement>(*host).lastChangeWasUserEdit())
+                continue;
+
             if (!commonAncestor)
                 commonAncestor = is<ContainerNode>(node.get()) ? node.ptr() : node->parentNode();
             else if (!node->isDescendantOf(commonAncestor.get()))

Modified: trunk/Tools/ChangeLog (271261 => 271262)


--- trunk/Tools/ChangeLog	2021-01-07 22:40:14 UTC (rev 271261)
+++ trunk/Tools/ChangeLog	2021-01-07 23:09:29 UTC (rev 271262)
@@ -1,3 +1,18 @@
+2021-01-07  Wenson Hsieh  <[email protected]>
+
+        Text fields should not be translated while typing
+        https://bugs.webkit.org/show_bug.cgi?id=220431
+        <rdar://problem/71724918>
+
+        Reviewed by Tim Horton.
+
+        Add an API test that modifies text in two input fields (by executing an edit command, and then by
+        programmatically setting the value attribute). The test verifies that only the latter (programmatic) value
+        change propagates a text manipulation update to the client layer.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
+        (TestWebKitAPI::TEST):
+
 2021-01-07  Jonathan Bedard  <[email protected]>
 
         [webkitscmpy] Use .git/config to verify if repository is git-svn

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm (271261 => 271262)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm	2021-01-07 22:40:14 UTC (rev 271261)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm	2021-01-07 23:09:29 UTC (rev 271262)
@@ -924,6 +924,41 @@
     EXPECT_WK_STREQ("Two", items[1].tokens[0].content);
 }
 
+TEST(TextManipulation, StartTextManipulationDoesNotExtractUserModifiedText)
+{
+    auto delegate = adoptNS([[TextManipulationDelegate alloc] init]);
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
+    [webView _setTextManipulationDelegate:delegate.get()];
+    [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html><body><input id='one'><input id='two'></body>"];
+
+    done = false;
+    [webView _startTextManipulationsWithConfiguration:nil completion:^{
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+
+    EXPECT_EQ([delegate items].count, 0UL);
+
+    Vector<RetainPtr<_WKTextManipulationItem>> items;
+    done = false;
+    [delegate setItemCallback:[&] (_WKTextManipulationItem *item) {
+        items.append(retainPtr(item));
+        done = true;
+    }];
+
+    [webView stringByEvaluatingJavaScript:@"document.getElementById('one').focus();"
+        "document.execCommand('InsertText', true, 'foo');"
+        "document.getElementById('two').value = 'bar';"];
+
+    Util::run(&done);
+
+    EXPECT_EQ(items.size(), 1U);
+
+    auto tokens = [items[0] tokens];
+    EXPECT_EQ(tokens.count, 1UL);
+    EXPECT_WK_STREQ("bar", tokens.firstObject.content);
+}
+
 TEST(TextManipulation, StartTextManipulationExtractsVisibleLineBreaksInTextAsExcludedTokens)
 {
     auto delegate = adoptNS([[TextManipulationDelegate alloc] init]);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to