Title: [265188] trunk
Revision
265188
Author
[email protected]
Date
2020-08-02 13:49:26 -0700 (Sun, 02 Aug 2020)

Log Message

Table data is incorrectly translated in some articles on en.wikipedia.org
https://bugs.webkit.org/show_bug.cgi?id=215071
<rdar://problem/66354013>

Reviewed by Darin Adler.

Source/WebCore:

Text in table cells sometimes end up in adjacent cells after translation, since adjacent cells are currently
extracted as different tokens in a single item; mitigate this by splitting text in table cells into different
text manipulation items instead.

Test: TextManipulation.StartTextManipulationExtractsTableCellsAsSeparateItems

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

Tools:

Add a new API test to exercise the change.

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (265187 => 265188)


--- trunk/Source/WebCore/ChangeLog	2020-08-02 15:12:40 UTC (rev 265187)
+++ trunk/Source/WebCore/ChangeLog	2020-08-02 20:49:26 UTC (rev 265188)
@@ -1,3 +1,20 @@
+2020-08-02  Wenson Hsieh  <[email protected]>
+
+        Table data is incorrectly translated in some articles on en.wikipedia.org
+        https://bugs.webkit.org/show_bug.cgi?id=215071
+        <rdar://problem/66354013>
+
+        Reviewed by Darin Adler.
+
+        Text in table cells sometimes end up in adjacent cells after translation, since adjacent cells are currently
+        extracted as different tokens in a single item; mitigate this by splitting text in table cells into different
+        text manipulation items instead.
+
+        Test: TextManipulation.StartTextManipulationExtractsTableCellsAsSeparateItems
+
+        * editing/TextManipulationController.cpp:
+        (WebCore::isEnclosingItemBoundaryElement):
+
 2020-08-01  Rob Buis  <[email protected]>
 
         Remove superfluous ResourceTiming constructor overload

Modified: trunk/Source/WebCore/editing/TextManipulationController.cpp (265187 => 265188)


--- trunk/Source/WebCore/editing/TextManipulationController.cpp	2020-08-02 15:12:40 UTC (rev 265187)
+++ trunk/Source/WebCore/editing/TextManipulationController.cpp	2020-08-02 20:49:26 UTC (rev 265188)
@@ -320,6 +320,9 @@
         }
     }
 
+    if (element.hasTagName(HTMLNames::tdTag) && displayType == DisplayType::TableCell)
+        return true;
+
     if (element.hasTagName(HTMLNames::spanTag) && displayType == DisplayType::InlineBlock)
         return true;
 

Modified: trunk/Tools/ChangeLog (265187 => 265188)


--- trunk/Tools/ChangeLog	2020-08-02 15:12:40 UTC (rev 265187)
+++ trunk/Tools/ChangeLog	2020-08-02 20:49:26 UTC (rev 265188)
@@ -1,3 +1,16 @@
+2020-08-02  Wenson Hsieh  <[email protected]>
+
+        Table data is incorrectly translated in some articles on en.wikipedia.org
+        https://bugs.webkit.org/show_bug.cgi?id=215071
+        <rdar://problem/66354013>
+
+        Reviewed by Darin Adler.
+
+        Add a new API test to exercise the change.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
+        (TestWebKitAPI::TEST):
+
 2020-08-02  Darin Adler  <[email protected]>
 
         Write a script to find duplicate files and delete some duplicate tests in LayoutTests

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm (265187 => 265188)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm	2020-08-02 15:12:40 UTC (rev 265187)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm	2020-08-02 20:49:26 UTC (rev 265188)
@@ -1146,6 +1146,47 @@
     EXPECT_WK_STREQ("World", items[1].tokens[0].content);
 }
 
+TEST(TextManipulation, StartTextManipulationExtractsTableCellsAsSeparateItems)
+{
+    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>"
+        "<html>"
+        "<head>"
+        "  <style>"
+        "    td { border: solid 1px tomato; }"
+        "  </style>"
+        "</head>"
+        "<body>"
+        "  <table>"
+        "    <tbody>"
+        "      <tr>"
+        "        <td>Foo</td>"
+        "        <td>Bar</td>"
+        "        <td>Baz</td>"
+        "      </tr>"
+        "    </tbody>"
+        "  </table>"
+        "</body>"];
+
+    done = false;
+    [webView _startTextManipulationsWithConfiguration:nil completion:^{
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+
+    auto items = [delegate items];
+    EXPECT_EQ(items.count, 3UL);
+    EXPECT_EQ(items[0].tokens.count, 1UL);
+    EXPECT_WK_STREQ("Foo", items[0].tokens[0].content);
+    EXPECT_EQ(items[1].tokens.count, 1UL);
+    EXPECT_WK_STREQ("Bar", items[1].tokens[0].content);
+    EXPECT_EQ(items[2].tokens.count, 1UL);
+    EXPECT_WK_STREQ("Baz", items[2].tokens[0].content);
+}
+
 struct Token {
     NSString *identifier;
     NSString *content;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to