[Extra zoom mode] Clearing text fields should dispatch input events of type "deleteCo...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 May 2018 18:23:45 +0000 (18:23 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 May 2018 18:23:45 +0000 (18:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185769
<rdar://problem/40368261>

Reviewed by Tim Horton.

Source/WebKit:

When setting the text of the currently focused element to the empty string, just delete the text instead of
pretending to insert an empty string. This mimics deleting content using the delete key on macOS, and fires an
input event with inputType "deleteContent" instead of "insertText".

Test: fast/forms/extrazoom/delete-content-in-text-field.html

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::setTextAsync):

LayoutTests:

Adds a new test to inspect the input events dispatched as a result of inserting and deleting text in a form
control. The inputTypes should be "insertText" and "deleteContent", respectively; the data values should be the
inserted string and null, respectively.

* fast/forms/extrazoom/delete-content-in-text-field-expected.txt: Added.
* fast/forms/extrazoom/delete-content-in-text-field.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@231967 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/forms/extrazoom/delete-content-in-text-field-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/extrazoom/delete-content-in-text-field.html [new file with mode: 0644]
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebPage/WebPage.cpp

index c68a4e7..f79f27f 100644 (file)
@@ -1,3 +1,18 @@
+2018-05-18  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Extra zoom mode] Clearing text fields should dispatch input events of type "deleteContent"
+        https://bugs.webkit.org/show_bug.cgi?id=185769
+        <rdar://problem/40368261>
+
+        Reviewed by Tim Horton.
+
+        Adds a new test to inspect the input events dispatched as a result of inserting and deleting text in a form
+        control. The inputTypes should be "insertText" and "deleteContent", respectively; the data values should be the
+        inserted string and null, respectively.
+
+        * fast/forms/extrazoom/delete-content-in-text-field-expected.txt: Added.
+        * fast/forms/extrazoom/delete-content-in-text-field.html: Added.
+
 2018-05-18  Youenn Fablet  <youenn@apple.com>
 
         Layout Test http/wpt/service-workers/header-filtering.https.html is a flaky failure
diff --git a/LayoutTests/fast/forms/extrazoom/delete-content-in-text-field-expected.txt b/LayoutTests/fast/forms/extrazoom/delete-content-in-text-field-expected.txt
new file mode 100644 (file)
index 0000000..81740e4
--- /dev/null
@@ -0,0 +1,12 @@
+PASS inputEventAfterInsertingText.type is 'input'
+PASS inputEventAfterInsertingText.inputType is 'insertText'
+PASS inputEventAfterInsertingText.data is 'testing'
+PASS valueAfterInsertingText is 'testing'
+PASS inputEventAfterDeletingText.type is 'input'
+PASS inputEventAfterDeletingText.inputType is 'deleteContent'
+PASS inputEventAfterDeletingText.data is null
+PASS valueAfterDeletingText is ''
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/extrazoom/delete-content-in-text-field.html b/LayoutTests/fast/forms/extrazoom/delete-content-in-text-field.html
new file mode 100644 (file)
index 0000000..a00a9c0
--- /dev/null
@@ -0,0 +1,60 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+<html>
+<meta name="viewport" content="width=device-width">
+<head>
+<script src="../../../resources/js-test.js"></script>
+<script src="../../../resources/ui-helper.js"></script>
+<script>
+doneCount = 0;
+lastInputEvent = null;
+jsTestIsAsync = true;
+
+function enterTextAndWaitForKeyboardToHide(text) {
+    return new Promise(async resolve => {
+        await UIHelper.activateAndWaitForInputSessionAt(100, 100);
+        UIHelper.waitForKeyboardToHide().then(resolve);
+        UIHelper.enterText(text);
+    });
+}
+
+async function runTest() {
+    if (!window.testRunner) {
+        description(`This test requires WebKitTestRunner.`);
+        return;
+    }
+
+    await enterTextAndWaitForKeyboardToHide("testing");
+    inputEventAfterInsertingText = lastInputEvent;
+    valueAfterInsertingText = field.value;
+
+    await enterTextAndWaitForKeyboardToHide("");
+    inputEventAfterDeletingText = lastInputEvent;
+    valueAfterDeletingText = field.value;
+
+    shouldBe("inputEventAfterInsertingText.type", "'input'");
+    shouldBe("inputEventAfterInsertingText.inputType", "'insertText'");
+    shouldBe("inputEventAfterInsertingText.data", "'testing'");
+    shouldBe("valueAfterInsertingText", "'testing'");
+
+    shouldBe("inputEventAfterDeletingText.type", "'input'");
+    shouldBe("inputEventAfterDeletingText.inputType", "'deleteContent'");
+    shouldBe("inputEventAfterDeletingText.data", "null");
+    shouldBe("valueAfterDeletingText", "''");
+
+    checkDone();
+}
+
+function handleInput(event) {
+    lastInputEvent = event;
+}
+
+function checkDone() {
+    if (++doneCount === 3)
+        finishJSTest();
+}
+</script>
+</head>
+<body onload="runTest()">
+<input id="field" style="width: 320px; height: 568px;" oninput="handleInput(event)" onblur="checkDone()"></input>
+</body>
+</html>
index d1c46b9..c970812 100644 (file)
@@ -1,3 +1,20 @@
+2018-05-18  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Extra zoom mode] Clearing text fields should dispatch input events of type "deleteContent"
+        https://bugs.webkit.org/show_bug.cgi?id=185769
+        <rdar://problem/40368261>
+
+        Reviewed by Tim Horton.
+
+        When setting the text of the currently focused element to the empty string, just delete the text instead of
+        pretending to insert an empty string. This mimics deleting content using the delete key on macOS, and fires an
+        input event with inputType "deleteContent" instead of "insertText".
+
+        Test: fast/forms/extrazoom/delete-content-in-text-field.html
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::setTextAsync):
+
 2018-05-18  Keith Rollin  <krollin@apple.com>
 
         Renamed "trackNetworkActivity" to "tracksResourceLoadMilestones"
index 45a2356..84a43c9 100644 (file)
@@ -4619,7 +4619,10 @@ void WebPage::setTextAsync(const String& text)
     if (frame->selection().selection().isContentEditable()) {
         UserTypingGestureIndicator indicator(frame.get());
         frame->selection().selectAll();
-        frame->editor().insertText(text, nullptr, TextEventInputKeyboard);
+        if (text.isEmpty())
+            frame->editor().deleteSelectionWithSmartDelete(false);
+        else
+            frame->editor().insertText(text, nullptr, TextEventInputKeyboard);
         return;
     }