Title: [264947] trunk
Revision
264947
Author
commit-qu...@webkit.org
Date
2020-07-27 15:02:03 -0700 (Mon, 27 Jul 2020)

Log Message

Text manipulation should not extract non-breaking spaces
https://bugs.webkit.org/show_bug.cgi?id=214839
<rdar://problem/64113531>

Patch by Sihui Liu <sihui_...@appe.com> on 2020-07-27
Reviewed by Wenson Hsieh.

Source/WebCore:

Spaces are very likely to be dropped during translation. And non-breaking space, if dropped, is likely to affect
layout of web page.

API test: TextManipulation.StartTextManipulationIgnoresSpaces

* editing/TextManipulationController.cpp:
(WebCore::isNotSpace):
(WebCore::TextManipulationController::parse):

Tools:

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (264946 => 264947)


--- trunk/Source/WebCore/ChangeLog	2020-07-27 21:59:55 UTC (rev 264946)
+++ trunk/Source/WebCore/ChangeLog	2020-07-27 22:02:03 UTC (rev 264947)
@@ -1,3 +1,20 @@
+2020-07-27  Sihui Liu  <sihui_...@appe.com>
+
+        Text manipulation should not extract non-breaking spaces
+        https://bugs.webkit.org/show_bug.cgi?id=214839
+        <rdar://problem/64113531>
+
+        Reviewed by Wenson Hsieh.
+
+        Spaces are very likely to be dropped during translation. And non-breaking space, if dropped, is likely to affect
+        layout of web page.
+
+        API test: TextManipulation.StartTextManipulationIgnoresSpaces
+
+        * editing/TextManipulationController.cpp:
+        (WebCore::isNotSpace):
+        (WebCore::TextManipulationController::parse):
+
 2020-07-27  Chris Dumez  <cdu...@apple.com>
 
         ASSERT([filteredCookies.get() count] <= 1) on  imported/w3c/web-platform-tests/websockets/cookies/third-party-cookie-accepted.https.html

Modified: trunk/Source/WebCore/editing/TextManipulationController.cpp (264946 => 264947)


--- trunk/Source/WebCore/editing/TextManipulationController.cpp	2020-07-27 21:59:55 UTC (rev 264946)
+++ trunk/Source/WebCore/editing/TextManipulationController.cpp	2020-07-27 22:02:03 UTC (rev 264947)
@@ -143,6 +143,14 @@
     return isHTMLLineBreak(character) || isInPrivateUseArea(character);
 }
 
+static bool isNotSpace(UChar character)
+{
+    if (character == noBreakSpace)
+        return false;
+
+    return isNotHTMLSpace(character);
+}
+
 class ParagraphContentIterator {
 public:
     ParagraphContentIterator(const Position& start, const Position& end)
@@ -388,7 +396,7 @@
             unit.tokens.append(ManipulationToken { m_tokenIdentifier.generate(), stringForToken, tokenInfo(&textNode), true });
             startPositionOfCurrentToken = index + 1;
             unit.lastTokenContainsDelimiter = true;
-        } else if (isNotHTMLSpace(character)) {
+        } else if (isNotSpace(character)) {
             if (!isNodeExcluded)
                 unit.areAllTokensExcluded = false;
             positionOfLastNonHTMLSpace = index;

Modified: trunk/Tools/ChangeLog (264946 => 264947)


--- trunk/Tools/ChangeLog	2020-07-27 21:59:55 UTC (rev 264946)
+++ trunk/Tools/ChangeLog	2020-07-27 22:02:03 UTC (rev 264947)
@@ -1,3 +1,14 @@
+2020-07-27  Sihui Liu  <sihui_...@appe.com>
+
+        Text manipulation should not extract non-breaking spaces
+        https://bugs.webkit.org/show_bug.cgi?id=214839
+        <rdar://problem/64113531>
+
+        Reviewed by Wenson Hsieh.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
+        (TestWebKitAPI::TEST):
+
 2020-07-27  Aakash Jain  <aakash_j...@apple.com>
 
         ews email notification should include bot name and link to results database

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm (264946 => 264947)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm	2020-07-27 21:59:55 UTC (rev 264946)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm	2020-07-27 22:02:03 UTC (rev 264947)
@@ -1121,6 +1121,31 @@
     EXPECT_WK_STREQ("This is a heading", items[1].tokens[0].content);
 }
 
+TEST(TextManipulation, StartTextManipulationIgnoresSpaces)
+{
+    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>"
+        "Hello"
+        "<div style='background-color: lightblue;'>&nbsp;</div>"
+        "World"];
+
+    done = false;
+    [webView _startTextManipulationsWithConfiguration:nil completion:^{
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+
+    auto items = [delegate items];
+    EXPECT_EQ(items.count, 2UL);
+    EXPECT_EQ(items[0].tokens.count, 1UL);
+    EXPECT_WK_STREQ("Hello", items[0].tokens[0].content);
+    EXPECT_EQ(items[1].tokens.count, 1UL);
+    EXPECT_WK_STREQ("World", items[1].tokens[0].content);
+}
+
 struct Token {
     NSString *identifier;
     NSString *content;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to