Changeset 271262 in webkit


Ignore:
Timestamp:
Jan 7, 2021 3:09:29 PM (19 months ago)
Author:
Wenson Hsieh
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):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r271261 r271262  
     12021-01-07  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Text fields should not be translated while typing
     4        https://bugs.webkit.org/show_bug.cgi?id=220431
     5        <rdar://problem/71724918>
     6
     7        Reviewed by Tim Horton.
     8
     9        Don't vend text nodes or newly created elements inside input elements for translation (i.e. text manipulation)
     10        if the input element was modified by the user. Note that this check is right before the call to
     11        `observeParagraphs` as opposed to when we schedule the observation update, since edit commands may create
     12        renderers for text nodes and other elements before the `m_lastChangeWasUserEdit` flag has been set.
     13
     14        Test: TextManipulation.StartTextManipulationDoesNotExtractUserModifiedText
     15
     16        * editing/TextManipulationController.cpp:
     17        (WebCore::TextManipulationController::scheduleObservationUpdate):
     18
    1192021-01-07  Eric Carlson  <eric.carlson@apple.com>
    220
  • trunk/Source/WebCore/editing/TextManipulationController.cpp

    r270561 r271262  
    606606            if (!node->isConnected())
    607607                continue;
     608
     609            if (auto host = makeRefPtr(node->shadowHost()); is<HTMLInputElement>(host.get()) && downcast<HTMLInputElement>(*host).lastChangeWasUserEdit())
     610                continue;
     611
    608612            if (!commonAncestor)
    609613                commonAncestor = is<ContainerNode>(node.get()) ? node.ptr() : node->parentNode();
  • trunk/Tools/ChangeLog

    r271258 r271262  
     12021-01-07  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Text fields should not be translated while typing
     4        https://bugs.webkit.org/show_bug.cgi?id=220431
     5        <rdar://problem/71724918>
     6
     7        Reviewed by Tim Horton.
     8
     9        Add an API test that modifies text in two input fields (by executing an edit command, and then by
     10        programmatically setting the value attribute). The test verifies that only the latter (programmatic) value
     11        change propagates a text manipulation update to the client layer.
     12
     13        * TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
     14        (TestWebKitAPI::TEST):
     15
    1162021-01-07  Jonathan Bedard  <JonWBedard@gmail.com>
    217
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm

    r270561 r271262  
    925925}
    926926
     927TEST(TextManipulation, StartTextManipulationDoesNotExtractUserModifiedText)
     928{
     929    auto delegate = adoptNS([[TextManipulationDelegate alloc] init]);
     930    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
     931    [webView _setTextManipulationDelegate:delegate.get()];
     932    [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html><body><input id='one'><input id='two'></body>"];
     933
     934    done = false;
     935    [webView _startTextManipulationsWithConfiguration:nil completion:^{
     936        done = true;
     937    }];
     938    TestWebKitAPI::Util::run(&done);
     939
     940    EXPECT_EQ([delegate items].count, 0UL);
     941
     942    Vector<RetainPtr<_WKTextManipulationItem>> items;
     943    done = false;
     944    [delegate setItemCallback:[&] (_WKTextManipulationItem *item) {
     945        items.append(retainPtr(item));
     946        done = true;
     947    }];
     948
     949    [webView stringByEvaluatingJavaScript:@"document.getElementById('one').focus();"
     950        "document.execCommand('InsertText', true, 'foo');"
     951        "document.getElementById('two').value = 'bar';"];
     952
     953    Util::run(&done);
     954
     955    EXPECT_EQ(items.size(), 1U);
     956
     957    auto tokens = [items[0] tokens];
     958    EXPECT_EQ(tokens.count, 1UL);
     959    EXPECT_WK_STREQ("bar", tokens.firstObject.content);
     960}
     961
    927962TEST(TextManipulation, StartTextManipulationExtractsVisibleLineBreaksInTextAsExcludedTokens)
    928963{
Note: See TracChangeset for help on using the changeset viewer.