Title: [221234] trunk
Revision
221234
Author
wenson_hs...@apple.com
Date
2017-08-27 22:12:56 -0700 (Sun, 27 Aug 2017)

Log Message

Picking an emoji via the emoji dialog (Ctrl+Cmd+Space) fires inconsistent beforeinput events.
https://bugs.webkit.org/show_bug.cgi?id=170955
<rdar://problem/31697653>

Reviewed by Ryosuke Niwa.

Source/WebKit:

Currently, we insert text with TextEventInputAutocompletion as the text event input type if any text range to
replace was specified by the platform. Instead, limit this only to when the text replacement range is not empty.
This more closely matches the intention of the spec, which states that the "insertReplacementText" inputType
should be used when "[replacing] existing text by means of a spell checker, auto-correct or similar".

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

Source/WebKitLegacy/mac:

Tweak -insertText: to pass TextEventInputAutocompletion to Editor::insertText when inserting text, if existing
text is being replaced.

* WebView/WebHTMLView.mm:
(-[WebHTMLView insertText:]):

Tools:

Replace UIScriptController.insertText with UIScriptController.replaceTextAtRange, and implement
replaceTextAtRange in WebKit1. See corresponding layout tests (input-event-insert-replacement.html and
before-input-prevent-insert-replacement.html) for more detail.

* DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
* DumpRenderTree/mac/AppKitTestSPI.h: Added.

Introduce an SPI header for private AppKit headers needed to support DumpRenderTree.

* DumpRenderTree/mac/UIScriptControllerMac.mm:
(WTR::UIScriptController::replaceTextAtRange):
(WTR::UIScriptController::insertText): Deleted.
* TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
* TestRunnerShared/UIScriptContext/UIScriptController.cpp:
(WTR::UIScriptController::replaceTextAtRange):
(WTR::UIScriptController::insertText): Deleted.
* TestRunnerShared/UIScriptContext/UIScriptController.h:
* WebKitTestRunner/mac/UIScriptControllerMac.mm:
(WTR::UIScriptController::replaceTextAtRange):
(WTR::UIScriptController::insertText): Deleted.

Replace UIScriptController.insertText with UIScriptController.replaceTextAtRange, which better describes the
behavior of this function.

LayoutTests:

Augments two existing layout tests to check for additional cases of inserting text with replacement ranges.
Also enables this test for WebKit1 on Mac. Both these tests are currently enabled only for WebKit2, and also only
check the case where we're replacing an existing non-empty range of text.

* fast/events/before-input-prevent-insert-replacement-expected.txt:
* fast/events/before-input-prevent-insert-replacement.html:
* fast/events/input-event-insert-replacement-expected.txt:
* fast/events/input-event-insert-replacement.html:

Tests for cases of replacing existing text ranges, and inserting text at a position.

* platform/mac-wk1/TestExpectations:
* resources/ui-helper.js:

Add a new UIHelper function to insert text at a given replacement range. This codepath is taken when selecting
an emoji using the emoji picker menu on Mac, and also when selecting a dead key option after holding down on a
vowel key.

(window.UIHelper.replaceTextAtRange):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (221233 => 221234)


--- trunk/LayoutTests/ChangeLog	2017-08-28 01:22:55 UTC (rev 221233)
+++ trunk/LayoutTests/ChangeLog	2017-08-28 05:12:56 UTC (rev 221234)
@@ -1,3 +1,31 @@
+2017-08-27  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Picking an emoji via the emoji dialog (Ctrl+Cmd+Space) fires inconsistent beforeinput events.
+        https://bugs.webkit.org/show_bug.cgi?id=170955
+        <rdar://problem/31697653>
+
+        Reviewed by Ryosuke Niwa.
+
+        Augments two existing layout tests to check for additional cases of inserting text with replacement ranges.
+        Also enables this test for WebKit1 on Mac. Both these tests are currently enabled only for WebKit2, and also only
+        check the case where we're replacing an existing non-empty range of text.
+
+        * fast/events/before-input-prevent-insert-replacement-expected.txt:
+        * fast/events/before-input-prevent-insert-replacement.html:
+        * fast/events/input-event-insert-replacement-expected.txt:
+        * fast/events/input-event-insert-replacement.html:
+
+        Tests for cases of replacing existing text ranges, and inserting text at a position.
+
+        * platform/mac-wk1/TestExpectations:
+        * resources/ui-helper.js:
+
+        Add a new UIHelper function to insert text at a given replacement range. This codepath is taken when selecting
+        an emoji using the emoji picker menu on Mac, and also when selecting a dead key option after holding down on a
+        vowel key.
+
+        (window.UIHelper.replaceTextAtRange):
+
 2017-08-27  Devin Rousso  <web...@devinrousso.com>
 
         Web Inspector: Record actions performed on WebGLRenderingContext

Modified: trunk/LayoutTests/fast/events/before-input-prevent-insert-replacement-expected.txt (221233 => 221234)


--- trunk/LayoutTests/fast/events/before-input-prevent-insert-replacement-expected.txt	2017-08-28 01:22:55 UTC (rev 221233)
+++ trunk/LayoutTests/fast/events/before-input-prevent-insert-replacement-expected.txt	2017-08-28 05:12:56 UTC (rev 221234)
@@ -1,7 +1,20 @@
-a
-Typing 'a'...
-(editable): type=beforeinput, inputType=insertText, data="" dataTransfer=`null`
-(editable): type=input, inputType=insertText, data="" dataTransfer=`null`
-Attempting to replace 'a' with 'b'...
-(editable): type=beforeinput, inputType=insertReplacementText, data="" dataTransfer=`plain:"b", html:"b"`
+To manually test, press and hold down 'a' and select one of the accented characters.
+You should observe that the replacement accented character does not replace 'a'.
+Then insert an emoji using the emoji picker. This should insert something into the editor.
+Finally, select all the content and attempt to replace it with an emoji. This should do nothing.
+ac
+(1) Typing 'a'...
+(editable): type=beforeinput, inputType=insertText, data="" dataTransfer=(null)
+(editable): type=input, inputType=insertText, data="" dataTransfer=(null)
+The editor now has text content: a
+(2) Preventing default when replacing 'a' with 'b'...
+(editable): type=beforeinput, inputType=insertReplacementText, data="" dataTransfer=plain:"b", html:"b"
+The editor now has text content: a
+(3) Inserting 'c' after 'a'...
+(editable): type=beforeinput, inputType=insertText, data="" dataTransfer=(null)
+(editable): type=input, inputType=insertText, data="" dataTransfer=(null)
+The editor now has text content: ac
+(4) Selecting all and preventing replacement with 'd'...
+(editable): type=beforeinput, inputType=insertReplacementText, data="" dataTransfer=plain:"d", html:"d"
+The editor now has text content: ac
 

Modified: trunk/LayoutTests/fast/events/before-input-prevent-insert-replacement.html (221233 => 221234)


--- trunk/LayoutTests/fast/events/before-input-prevent-insert-replacement.html	2017-08-28 01:22:55 UTC (rev 221233)
+++ trunk/LayoutTests/fast/events/before-input-prevent-insert-replacement.html	2017-08-28 05:12:56 UTC (rev 221234)
@@ -1,60 +1,52 @@
 <!DOCTYPE html>
 <html>
-<body>
-    <div id="editable" _onbeforeinput_=handleInputEvent(event) _oninput_=handleInputEvent(event) contenteditable></div>
-    <div id="output"></div>
-    <script type="text/_javascript_">
-        let write = s => output.innerHTML += s + "<br>";
-        var progress = 0;
-        editable.focus();
+<head>
+<script src=""
+</head>
 
-        if (window.internals && window.testRunner) {
-            internals.settings.setInputEventsEnabled(true);
-            testRunner.dumpAsText();
-            testRunner.waitUntilDone();
-            if (window.eventSender && testRunner.runUIScript) {
-                write("Typing 'a'...");
-                eventSender.keyDown("a");
-                write("Attempting to replace 'a' with 'b'...");
-                testRunner.runUIScript(getUIScript(), (result) => incrementProgress());
-            }
-        } else {
-            write("To manually test, press and hold down 'a' and select one of the accented characters.");
-            write("You should observe that the replacement accented character does not replace 'a'.");
-        }
+<div>To manually test, press and hold down 'a' and select one of the accented characters.</div>
+<div>You should observe that the replacement accented character does not replace 'a'.</div>
+<div>Then insert an emoji using the emoji picker. This should insert something into the editor.</div>
+<div>Finally, select all the content and attempt to replace it with an emoji. This should do nothing.</div>
+<div id="editable" _onbeforeinput_=handleInputEvent(event) _oninput_=handleInputEvent(event) contenteditable></div>
+<div id="output"></div>
 
-        function incrementProgress()
-        {
-            progress++;
-            if (progress == 2)
-                testRunner.notifyDone();
-        }
+<script type="text/_javascript_">
+    let write = s => output.innerHTML += s + "<br>";
+    editable.focus();
 
-        function handleInputEvent(event)
-        {
-            write(`(${event.target.id}): type=${event.type}, inputType=${event.inputType}, data="" dataTransfer=\`${dataTransferAsString(event.dataTransfer)}\``);
-            if (event.inputType === "insertReplacementText") {
-                event.preventDefault();
-                incrementProgress();
-            }
-        }
+    if (window.testRunner && window.eventSender && testRunner.runUIScript) {
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+        runTest();
+    }
 
-        function dataTransferAsString(dataTransfer)
-        {
-            if (!dataTransfer)
-                return "null";
+    async function runTest() {
+        write("(1) Typing 'a'...");
+        eventSender.keyDown("a");
+        write(`The editor now has text content: ${editable.textContent}`);
+        write("(2) Preventing default when replacing 'a' with 'b'...");
+        await UIHelper.replaceTextAtRange("b", 0, 1)
+        write(`The editor now has text content: ${editable.textContent}`);
+        write("(3) Inserting 'c' after 'a'...");
+        await UIHelper.replaceTextAtRange("c", 1, 0);
+        write(`The editor now has text content: ${editable.textContent}`);
+        write("(4) Selecting all and preventing replacement with 'd'...");
+        document.execCommand("SelectAll")
+        await UIHelper.replaceTextAtRange("d", 0, 2);
+        write(`The editor now has text content: ${editable.textContent}`);
 
-            return `plain:"${dataTransfer.getData('text/plain')}", html:"${dataTransfer.getData('text/html')}"`;
-        }
+        testRunner.notifyDone();
+    }
 
-        function getUIScript()
-        {
-            return `
-            (function() {
-                uiController.insertText("b", 0, 1);
-                uiController.uiScriptComplete();
-            })();`
-        }
-    </script>
+    function handleInputEvent(event)
+    {
+        let dataTransferString = event.dataTransfer ? `plain:"${event.dataTransfer.getData('text/plain')}", html:"${event.dataTransfer.getData('text/html')}"` : "(null)";
+        write(`(${event.target.id}): type=${event.type}, inputType=${event.inputType}, data="" dataTransfer=${dataTransferString}`);
+
+        if (event.type === "beforeinput" && event.inputType === "insertReplacementText")
+            event.preventDefault();
+    }
+</script>
 </body>
-</html>
\ No newline at end of file
+</html>

Modified: trunk/LayoutTests/fast/events/input-event-insert-replacement-expected.txt (221233 => 221234)


--- trunk/LayoutTests/fast/events/input-event-insert-replacement-expected.txt	2017-08-28 01:22:55 UTC (rev 221233)
+++ trunk/LayoutTests/fast/events/input-event-insert-replacement-expected.txt	2017-08-28 05:12:56 UTC (rev 221234)
@@ -1,11 +1,23 @@
+To manually test, press and hold down 'a' and select one of the accented characters."
+You should observe a pair of beforeinput/input events for both 'a' and the replacement accented character."
+Importantly, the inputType of these four events should be 'insertReplacementText'."
+Then insert a single emoji character. You should observe beforeinput/input events for the inserted emoji."
+Importantly, the inputType of these two events should be 'insertText'."
 
-Typing 'a'...
-(editable): type=beforeinput, inputType=insertText, data="" dataTransfer=`null`
-(editable): type=input, inputType=insertText, data="" dataTransfer=`null`
+(1) Typing 'a'...
+(editable): type=beforeinput, inputType=insertText, data="" dataTransfer=null
+(editable): type=input, inputType=insertText, data="" dataTransfer=null
 The value of the input is now: a
-
-Replacing 'a' with 'b'...
-(editable): type=beforeinput, inputType=insertReplacementText, data="" dataTransfer=`null`
-(editable): type=input, inputType=insertReplacementText, data="" dataTransfer=`null`
+(2) Replacing 'a' with 'b'...
+(editable): type=beforeinput, inputType=insertReplacementText, data="" dataTransfer=null
+(editable): type=input, inputType=insertReplacementText, data="" dataTransfer=null
 The value of the input is now: b
+(3) Inserting 'c' after 'b'...
+(editable): type=beforeinput, inputType=insertText, data="" dataTransfer=null
+(editable): type=input, inputType=insertText, data="" dataTransfer=null
+The value of the input is now: bc
+(4) Selecting all and replacing with 'd'...
+(editable): type=beforeinput, inputType=insertReplacementText, data="" dataTransfer=null
+(editable): type=input, inputType=insertReplacementText, data="" dataTransfer=null
+The value of the input is now: d
 

Modified: trunk/LayoutTests/fast/events/input-event-insert-replacement.html (221233 => 221234)


--- trunk/LayoutTests/fast/events/input-event-insert-replacement.html	2017-08-28 01:22:55 UTC (rev 221233)
+++ trunk/LayoutTests/fast/events/input-event-insert-replacement.html	2017-08-28 05:12:56 UTC (rev 221234)
@@ -1,55 +1,47 @@
 <!DOCTYPE html>
 <html>
-<body>
-    <input id="editable" _onbeforeinput_=logInputEvent(event) _oninput_=logInputEvent(event)></input>
-    <div id="output"></div>
-    <script type="text/_javascript_">
-        let write = s => output.innerHTML += s + "<br>";
-        var progress = 0;
-        editable.focus();
+<head>
+<script src=""
+</head>
 
-        if (window.internals && window.testRunner) {
-            internals.settings.setInputEventsEnabled(true);
-            testRunner.dumpAsText();
-            testRunner.waitUntilDone();
-            if (window.eventSender && testRunner.runUIScript) {
-                write("Typing 'a'...");
-                eventSender.keyDown("a");
-                write(`The value of the input is now: ${editable.value}`);
-                write("");
-                write("Replacing 'a' with 'b'...");
-                testRunner.runUIScript(getUIScript(), (result) => incrementProgress());
-            }
-        } else {
-            write("To manually test, press and hold down 'a' and select one of the accented characters.");
-            write("You should observe a pair of beforeinput/input events for both 'a' and the replacement accented character.");
-            write("Importantly, the inputType of the last two events should be 'insertReplacementText'.");
-        }
+<div>To manually test, press and hold down 'a' and select one of the accented characters."</div>
+<div>You should observe a pair of beforeinput/input events for both 'a' and the replacement accented character."</div>
+<div>Importantly, the inputType of these four events should be 'insertReplacementText'."</div>
+<div>Then insert a single emoji character. You should observe beforeinput/input events for the inserted emoji."</div>
+<div>Importantly, the inputType of these two events should be 'insertText'."</div>
 
-        function incrementProgress()
-        {
-            progress++;
-            if (progress != 5)
-                return;
+<input id="editable" _onbeforeinput_=logInputEvent(event) _oninput_=logInputEvent(event)></input>
+<div id="output"></div>
+<script type="text/_javascript_">
+    let write = s => output.innerHTML += s + "<br>";
+    editable.focus();
+    if (window.testRunner && window.eventSender && testRunner.runUIScript) {
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+        runTest();
+    }
 
-            write(`The value of the input is now: ${editable.value}`);
-            testRunner.notifyDone();
-        }
+    function logInputEvent(event)
+    {
+        write(`(${event.target.id}): type=${event.type}, inputType=${event.inputType}, data="" dataTransfer=${event.dataTransfer}`);
+    }
 
-        function logInputEvent(event)
-        {
-            write(`(${event.target.id}): type=${event.type}, inputType=${event.inputType}, data="" dataTransfer=\`${event.dataTransfer}\``);
-            incrementProgress();
-        }
+    async function runTest() {
+        write("(1) Typing 'a'...");
+        eventSender.keyDown("a");
+        write(`The value of the input is now: ${editable.value}`);
+        write("(2) Replacing 'a' with 'b'...");
+        await UIHelper.replaceTextAtRange("b", 0, 1);
+        write(`The value of the input is now: ${editable.value}`);
+        write("(3) Inserting 'c' after 'b'...");
+        await UIHelper.replaceTextAtRange("c", 1, 0);
+        write(`The value of the input is now: ${editable.value}`);
+        write("(4) Selecting all and replacing with 'd'...");
+        document.execCommand("SelectAll")
+        await UIHelper.replaceTextAtRange("d", 0, 2);
+        write(`The value of the input is now: ${editable.value}`);
 
-        function getUIScript()
-        {
-            return `
-            (function() {
-                uiController.insertText("b", 0, 1);
-                uiController.uiScriptComplete();
-            })();`
-        }
-    </script>
-</body>
-</html>
\ No newline at end of file
+        testRunner.notifyDone();
+    }
+</script>
+</html>

Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (221233 => 221234)


--- trunk/LayoutTests/platform/mac-wk1/TestExpectations	2017-08-28 01:22:55 UTC (rev 221233)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations	2017-08-28 05:12:56 UTC (rev 221234)
@@ -85,10 +85,6 @@
 # WK1 and WK2 mousemove events are subtly different in ways that break this test on WK1.
 fast/events/ghostly-mousemoves-in-subframe.html [ Skip ]
 
-# Test support for inserting special characters is not yet implemented on WK1.
-fast/events/before-input-prevent-insert-replacement.html [ Skip ]
-fast/events/input-event-insert-replacement.html [ Skip ]
-
 # Media Stream API testing is not supported for WK1 yet.
 fast/mediastream
 http/tests/media/media-stream

Modified: trunk/LayoutTests/resources/ui-helper.js (221233 => 221234)


--- trunk/LayoutTests/resources/ui-helper.js	2017-08-28 01:22:55 UTC (rev 221233)
+++ trunk/LayoutTests/resources/ui-helper.js	2017-08-28 05:12:56 UTC (rev 221234)
@@ -110,6 +110,15 @@
         });
     }
 
+    static replaceTextAtRange(text, location, length) {
+        return new Promise(resolve => {
+            testRunner.runUIScript(`(() => {
+                uiController.replaceTextAtRange("${text}", ${location}, ${length});
+                uiController.uiScriptComplete('Done');
+            })()`, resolve);
+        });
+    }
+
     static wait(promise)
     {
         testRunner.waitUntilDone();

Modified: trunk/Source/WebKit/ChangeLog (221233 => 221234)


--- trunk/Source/WebKit/ChangeLog	2017-08-28 01:22:55 UTC (rev 221233)
+++ trunk/Source/WebKit/ChangeLog	2017-08-28 05:12:56 UTC (rev 221234)
@@ -1,5 +1,21 @@
 2017-08-27  Wenson Hsieh  <wenson_hs...@apple.com>
 
+        Picking an emoji via the emoji dialog (Ctrl+Cmd+Space) fires inconsistent beforeinput events.
+        https://bugs.webkit.org/show_bug.cgi?id=170955
+        <rdar://problem/31697653>
+
+        Reviewed by Ryosuke Niwa.
+
+        Currently, we insert text with TextEventInputAutocompletion as the text event input type if any text range to
+        replace was specified by the platform. Instead, limit this only to when the text replacement range is not empty.
+        This more closely matches the intention of the spec, which states that the "insertReplacementText" inputType
+        should be used when "[replacing] existing text by means of a spell checker, auto-correct or similar".
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::insertTextAsync):
+
+2017-08-27  Wenson Hsieh  <wenson_hs...@apple.com>
+
         [iOS WK2] Web process crashes after changing selection to the end of the document when speaking a selection
         https://bugs.webkit.org/show_bug.cgi?id=176011
         <rdar://problem/32614095>

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (221233 => 221234)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2017-08-28 01:22:55 UTC (rev 221233)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2017-08-28 05:12:56 UTC (rev 221234)
@@ -4843,11 +4843,10 @@
 
     bool replacesText = false;
     if (replacementEditingRange.location != notFound) {
-        RefPtr<Range> replacementRange = rangeFromEditingRange(frame, replacementEditingRange, static_cast<EditingRangeIsRelativeTo>(editingRangeIsRelativeTo));
-        if (replacementRange) {
+        if (auto replacementRange = rangeFromEditingRange(frame, replacementEditingRange, static_cast<EditingRangeIsRelativeTo>(editingRangeIsRelativeTo))) {
             SetForScope<bool> isSelectingTextWhileInsertingAsynchronously(m_isSelectingTextWhileInsertingAsynchronously, suppressSelectionUpdate);
             frame.selection().setSelection(VisibleSelection(*replacementRange, SEL_DEFAULT_AFFINITY));
-            replacesText = true;
+            replacesText = replacementEditingRange.length;
         }
     }
     

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (221233 => 221234)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2017-08-28 01:22:55 UTC (rev 221233)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2017-08-28 05:12:56 UTC (rev 221234)
@@ -1,3 +1,17 @@
+2017-08-27  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Picking an emoji via the emoji dialog (Ctrl+Cmd+Space) fires inconsistent beforeinput events.
+        https://bugs.webkit.org/show_bug.cgi?id=170955
+        <rdar://problem/31697653>
+
+        Reviewed by Ryosuke Niwa.
+
+        Tweak -insertText: to pass TextEventInputAutocompletion to Editor::insertText when inserting text, if existing
+        text is being replaced.
+
+        * WebView/WebHTMLView.mm:
+        (-[WebHTMLView insertText:]):
+
 2017-08-24  Chris Dumez  <cdu...@apple.com>
 
         [Directory Upload] Add basic support for input.webkitdirectory

Modified: trunk/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm (221233 => 221234)


--- trunk/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm	2017-08-28 01:22:55 UTC (rev 221233)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm	2017-08-28 05:12:56 UTC (rev 221234)
@@ -7154,11 +7154,13 @@
     _private->softSpaceRange = NSMakeRange(NSNotFound, 0);
 #endif
 
+    bool replacesText = false;
     if (replacementRange.location != NSNotFound) {
         WebRangeIsRelativeTo rangeIsRelativeTo = needToRemoveSoftSpace ? WebRangeIsRelativeTo::Paragraph : WebRangeIsRelativeTo::EditableRoot;
-        RefPtr<Range> domRange = [[self _frame] _convertToDOMRange:replacementRange rangeIsRelativeTo:rangeIsRelativeTo];
-        if (domRange)
+        if (auto domRange = [[self _frame] _convertToDOMRange:replacementRange rangeIsRelativeTo:rangeIsRelativeTo]) {
             coreFrame->selection().setSelection(VisibleSelection(*domRange, SEL_DEFAULT_AFFINITY));
+            replacesText = replacementRange.length;
+        }
     }
 
     bool eventHandled = false;
@@ -7171,7 +7173,7 @@
         if (!dictationAlternativeLocations.isEmpty())
             eventHandled = coreFrame->editor().insertDictatedText(eventText, dictationAlternativeLocations, event);
         else
-            eventHandled = coreFrame->editor().insertText(eventText, event);
+            eventHandled = coreFrame->editor().insertText(eventText, event, replacesText ? TextEventInputAutocompletion : TextEventInputKeyboard);
         
 #if USE(INSERTION_UNDO_GROUPING)
         if (registerUndoGroup)

Modified: trunk/Tools/ChangeLog (221233 => 221234)


--- trunk/Tools/ChangeLog	2017-08-28 01:22:55 UTC (rev 221233)
+++ trunk/Tools/ChangeLog	2017-08-28 05:12:56 UTC (rev 221234)
@@ -1,5 +1,37 @@
 2017-08-27  Wenson Hsieh  <wenson_hs...@apple.com>
 
+        Picking an emoji via the emoji dialog (Ctrl+Cmd+Space) fires inconsistent beforeinput events.
+        https://bugs.webkit.org/show_bug.cgi?id=170955
+        <rdar://problem/31697653>
+
+        Reviewed by Ryosuke Niwa.
+
+        Replace UIScriptController.insertText with UIScriptController.replaceTextAtRange, and implement
+        replaceTextAtRange in WebKit1. See corresponding layout tests (input-event-insert-replacement.html and
+        before-input-prevent-insert-replacement.html) for more detail.
+
+        * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
+        * DumpRenderTree/mac/AppKitTestSPI.h: Added.
+
+        Introduce an SPI header for private AppKit headers needed to support DumpRenderTree.
+
+        * DumpRenderTree/mac/UIScriptControllerMac.mm:
+        (WTR::UIScriptController::replaceTextAtRange):
+        (WTR::UIScriptController::insertText): Deleted.
+        * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
+        * TestRunnerShared/UIScriptContext/UIScriptController.cpp:
+        (WTR::UIScriptController::replaceTextAtRange):
+        (WTR::UIScriptController::insertText): Deleted.
+        * TestRunnerShared/UIScriptContext/UIScriptController.h:
+        * WebKitTestRunner/mac/UIScriptControllerMac.mm:
+        (WTR::UIScriptController::replaceTextAtRange):
+        (WTR::UIScriptController::insertText): Deleted.
+
+        Replace UIScriptController.insertText with UIScriptController.replaceTextAtRange, which better describes the
+        behavior of this function.
+
+2017-08-27  Wenson Hsieh  <wenson_hs...@apple.com>
+
         [iOS WK2] Web process crashes after changing selection to the end of the document when speaking a selection
         https://bugs.webkit.org/show_bug.cgi?id=176011
         <rdar://problem/32614095>

Modified: trunk/Tools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj (221233 => 221234)


--- trunk/Tools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj	2017-08-28 01:22:55 UTC (rev 221233)
+++ trunk/Tools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj	2017-08-28 05:12:56 UTC (rev 221234)
@@ -284,6 +284,7 @@
 		2D403F19150871F9005358D2 /* LayoutTestHelper */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = LayoutTestHelper; sourceTree = BUILT_PRODUCTS_DIR; };
 		2DA2E3A31E1BA54100A3BBD0 /* DumpRenderTreeSpellChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DumpRenderTreeSpellChecker.h; path = mac/DumpRenderTreeSpellChecker.h; sourceTree = "<group>"; };
 		2DA2E3A41E1BA54100A3BBD0 /* DumpRenderTreeSpellChecker.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = DumpRenderTreeSpellChecker.mm; path = mac/DumpRenderTreeSpellChecker.mm; sourceTree = "<group>"; };
+		2EDE0DAA1F5131DE00D5F8DF /* AppKitTestSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = AppKitTestSPI.h; path = mac/AppKitTestSPI.h; sourceTree = "<group>"; };
 		31117B3A15D9A56A00163BC8 /* MockWebNotificationProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MockWebNotificationProvider.h; path = mac/MockWebNotificationProvider.h; sourceTree = "<group>"; };
 		31117B3B15D9A56A00163BC8 /* MockWebNotificationProvider.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MockWebNotificationProvider.mm; path = mac/MockWebNotificationProvider.mm; sourceTree = "<group>"; };
 		31268EBA1EF06A95001963E2 /* UIKitTestSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UIKitTestSPI.h; path = ../TestRunnerShared/spi/UIKitTestSPI.h; sourceTree = "<group>"; };
@@ -545,6 +546,7 @@
 		0F6A0E001D6E0F8A00F1C9A8 /* mac */ = {
 			isa = PBXGroup;
 			children = (
+				2EDE0DAA1F5131DE00D5F8DF /* AppKitTestSPI.h */,
 				0F18E70E1D6BACB60027E547 /* UIScriptControllerMac.mm */,
 			);
 			name = mac;
@@ -603,10 +605,10 @@
 				BCA18B6E0C9B08DB00114369 /* NavigationController.m */,
 				BCA18B2F0C9B01B400114369 /* ObjCController.h */,
 				BCA18B300C9B01B400114369 /* ObjCController.m */,
-				F4D423601DD5046900678290 /* TextInputController.h */,
 				BC0131D80C9772010087317D /* TestRunner.cpp */,
 				BC0131D90C9772010087317D /* TestRunner.h */,
 				BCA18B220C9B014B00114369 /* TestRunnerMac.mm */,
+				F4D423601DD5046900678290 /* TextInputController.h */,
 			);
 			name = Controllers;
 			sourceTree = "<group>";
@@ -1061,7 +1063,6 @@
 			files = (
 				A134E53618905EFF00901D06 /* AccessibilityCommonMac.mm in Sources */,
 				BCD08B3A0E1057EF00A7D0C1 /* AccessibilityController.cpp in Sources */,
-				2DA2E3A51E1BA54100A3BBD0 /* DumpRenderTreeSpellChecker.mm in Sources */,
 				AA5A15EF16E15CD000F7C561 /* AccessibilityControllerIOS.mm in Sources */,
 				BCD08B710E1059D200A7D0C1 /* AccessibilityControllerMac.mm in Sources */,
 				80045AEE147718E7008290A8 /* AccessibilityNotificationHandler.mm in Sources */,
@@ -1080,6 +1081,7 @@
 				BCA18B7B0C9B08F100114369 /* DumpRenderTreeDraggingInfo.mm in Sources */,
 				A8D79CEB0FC28B2C004AC8FE /* DumpRenderTreeFileDraggingSource.m in Sources */,
 				A8B91ADA0CF3B32F008F91FF /* DumpRenderTreePasteboard.mm in Sources */,
+				2DA2E3A51E1BA54100A3BBD0 /* DumpRenderTreeSpellChecker.mm in Sources */,
 				A8B91ADC0CF3B32F008F91FF /* DumpRenderTreeWindow.mm in Sources */,
 				BCA18B620C9B08C200114369 /* EditingDelegate.mm in Sources */,
 				BCA18B700C9B08DB00114369 /* EventSendingController.mm in Sources */,
@@ -1087,6 +1089,7 @@
 				BCF6C6500C98E9C000AC063E /* GCController.cpp in Sources */,
 				BCA18B230C9B014B00114369 /* GCControllerMac.mm in Sources */,
 				5185F6B210714E07007AA393 /* HistoryDelegate.mm in Sources */,
+				312943F91E71F2B4001EE2CC /* IOSLayoutTestCommunication.cpp in Sources */,
 				2CE88FA217124D8C00734FC0 /* _javascript_Threading.cpp in Sources */,
 				0F18E7061D6BA0230027E547 /* JSUIScriptController.cpp in Sources */,
 				0F18E7131D6BC43A0027E547 /* JSWrapper.cpp in Sources */,
@@ -1098,22 +1101,21 @@
 				BCA18B800C9B08F100114369 /* ObjCPluginFunction.m in Sources */,
 				8465E2C70FFA8DF2003B8342 /* PixelDumpSupport.cpp in Sources */,
 				BCB284CD0CFA83C8007E533E /* PixelDumpSupportCG.cpp in Sources */,
-				F4D423611DD5048200678290 /* TextInputControllerIOS.m in Sources */,
 				A1158D59189274360088C17B /* PixelDumpSupportIOS.mm in Sources */,
 				BCB284D60CFA83D1007E533E /* PixelDumpSupportMac.mm in Sources */,
 				BCA18B660C9B08C200114369 /* PolicyDelegate.mm in Sources */,
 				BCA18B680C9B08C200114369 /* ResourceLoadDelegate.mm in Sources */,
+				7CBBC3231DDFCF9A00786B9D /* TestOptions.mm in Sources */,
 				BC0131DA0C9772010087317D /* TestRunner.cpp in Sources */,
 				BCA18B240C9B014B00114369 /* TestRunnerMac.mm in Sources */,
+				F4D423611DD5048200678290 /* TextInputControllerIOS.m in Sources */,
 				BCA18B490C9B02C400114369 /* TextInputControllerMac.m in Sources */,
 				BCA18B6A0C9B08C200114369 /* UIDelegate.mm in Sources */,
 				0F18E6EC1D6B9C070027E547 /* UIScriptContext.cpp in Sources */,
 				0F18E6ED1D6B9C070027E547 /* UIScriptController.cpp in Sources */,
 				0F18E70D1D6BAC8C0027E547 /* UIScriptControllerIOS.mm in Sources */,
-				7CBBC3231DDFCF9A00786B9D /* TestOptions.mm in Sources */,
 				0F18E70F1D6BACB60027E547 /* UIScriptControllerMac.mm in Sources */,
 				BC9D90240C97472E0099A4A3 /* WorkQueue.cpp in Sources */,
-				312943F91E71F2B4001EE2CC /* IOSLayoutTestCommunication.cpp in Sources */,
 				BCA18B260C9B015C00114369 /* WorkQueueItemMac.mm in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;

Added: trunk/Tools/DumpRenderTree/mac/AppKitTestSPI.h (0 => 221234)


--- trunk/Tools/DumpRenderTree/mac/AppKitTestSPI.h	                        (rev 0)
+++ trunk/Tools/DumpRenderTree/mac/AppKitTestSPI.h	2017-08-28 05:12:56 UTC (rev 221234)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if PLATFORM(MAC)
+
+#if USE(APPLE_INTERNAL_SDK)
+
+#import <AppKit/NSTextInputContext_Private.h>
+
+#else
+
+extern "C" {
+extern NSString *NSTextInputReplacementRangeAttributeName;
+}
+
+#endif
+
+#endif // PLATFORM(MAC)
+

Modified: trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm (221233 => 221234)


--- trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm	2017-08-28 01:22:55 UTC (rev 221233)
+++ trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm	2017-08-28 05:12:56 UTC (rev 221234)
@@ -36,6 +36,8 @@
 
 #if PLATFORM(MAC)
 
+#import "AppKitTestSPI.h"
+
 namespace WTR {
 
 void UIScriptController::doAsyncTask(JSValueRef callback)
@@ -64,8 +66,13 @@
     doAsyncTask(callback);
 }
 
-void UIScriptController::insertText(JSStringRef, int, int)
+void UIScriptController::replaceTextAtRange(JSStringRef text, int location, int length)
 {
+    auto textToInsert = adoptCF(JSStringCopyCFString(kCFAllocatorDefault, text));
+    auto rangeAttribute = adoptNS([[NSDictionary alloc] initWithObjectsAndKeys:NSStringFromRange(NSMakeRange(location == -1 ? NSNotFound : location, length)), NSTextInputReplacementRangeAttributeName, nil]);
+    auto textAndRange = adoptNS([[NSAttributedString alloc] initWithString:(NSString *)textToInsert.get() attributes:rangeAttribute.get()]);
+
+    [mainFrame.webView insertText:textAndRange.get()];
 }
 
 void UIScriptController::zoomToScale(double scale, JSValueRef callback)

Modified: trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl (221233 => 221234)


--- trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl	2017-08-28 01:22:55 UTC (rev 221233)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl	2017-08-28 05:12:56 UTC (rev 221234)
@@ -226,7 +226,7 @@
     readonly attribute object textSelectionCaretRect; // An object with 'left', 'top', 'width', 'height' properties.
     readonly attribute object inputViewBounds;
 
-    void insertText(DOMString text, long location, long length);
+    void replaceTextAtRange(DOMString text, long location, long length);
     void removeAllDynamicDictionaries();
 
     readonly attribute DOMString scrollingTreeAsText;

Modified: trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp (221233 => 221234)


--- trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp	2017-08-28 01:22:55 UTC (rev 221233)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp	2017-08-28 05:12:56 UTC (rev 221234)
@@ -461,7 +461,7 @@
 {
 }
 
-void UIScriptController::insertText(JSStringRef, int, int)
+void UIScriptController::replaceTextAtRange(JSStringRef, int, int)
 {
 }
 

Modified: trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h (221233 => 221234)


--- trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h	2017-08-28 01:22:55 UTC (rev 221233)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h	2017-08-28 05:12:56 UTC (rev 221234)
@@ -151,7 +151,7 @@
     JSObjectRef textSelectionCaretRect() const;
     JSObjectRef inputViewBounds() const;
 
-    void insertText(JSStringRef, int location, int length);
+    void replaceTextAtRange(JSStringRef, int location, int length);
     void removeAllDynamicDictionaries();
     
     JSRetainPtr<JSStringRef> scrollingTreeAsText() const;

Modified: trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm (221233 => 221234)


--- trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm	2017-08-28 01:22:55 UTC (rev 221233)
+++ trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm	2017-08-28 05:12:56 UTC (rev 221234)
@@ -75,7 +75,7 @@
     doAsyncTask(callback);
 }
 
-void UIScriptController::insertText(JSStringRef text, int location, int length)
+void UIScriptController::replaceTextAtRange(JSStringRef text, int location, int length)
 {
 #if WK_API_ENABLED
     if (location == -1)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to