Title: [208143] trunk
Revision
208143
Author
[email protected]
Date
2016-10-31 08:12:00 -0700 (Mon, 31 Oct 2016)

Log Message

Holding down a key to choose an accented character should fire "insertReplacementText" input events
https://bugs.webkit.org/show_bug.cgi?id=164209
<rdar://problem/29019305>

Reviewed by Darin Adler.

Source/WebCore:

For TypingCommands that correspond to "insertReplacementText" inputTypes, vend dataTransfers for resulting
beforeinput and input events if the edited area is not an input field or textarea. To do this, convert the plain
text representation of the content to be inserted to HTML text using a helper function,
MarkupAccumulator::appendCharactersReplacingEntities, that is used when creating markup for Text nodes.

Tests: fast/events/before-input-prevent-insert-replacement.html
       fast/events/input-event-insert-replacement.html

* editing/TypingCommand.cpp:
(WebCore::TypingCommand::inputEventData):
(WebCore::TypingCommand::inputEventDataTransfer):
* editing/TypingCommand.h:

Source/WebKit2:

When replacing text, call Editor::insertText with the correct TextEventInputType so that WebCore will know to
use EditActionInsertReplacement when creating and applying the corresponding TypingCommand. Additional minor
changes in order to support testing replacement text insertion.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _insertText:replacementRange:]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::insertTextAsync):

Tools:

Adds test support for inserting replacement text on Mac. This is equivalent to holding down a vowel key (e.g.
'a') to bring up the menu containing accented version of the character, then selecting an accented character to
insert in place of the typed character. This is exposed via UIScriptController.insertText, which takes a string
and an insertion range.

* DumpRenderTree/mac/UIScriptControllerMac.mm:
(WTR::UIScriptController::insertText):
* TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:

Note that there is no callback argument to insertText, since UIScriptController::insertText is synchronous in
the UI process. The tests end when corresponding input events fired as a result of insertText have been received
in the web process. Please see the new layout tests for more detail.

* TestRunnerShared/UIScriptContext/UIScriptController.cpp:
(WTR::UIScriptController::insertText):
* TestRunnerShared/UIScriptContext/UIScriptController.h:
* WebKitTestRunner/mac/UIScriptControllerMac.mm:
(WTR::nsStringFromJSString):
(WTR::UIScriptController::insertText):

LayoutTests:

Adds 2 new layout tests to verify that inserting replacement text fires input events of inputType
"insertReplacementText" instead of the generic "insertText", and that calling preventDefault() on the
beforeinput event prevents text from being inserted. Also checks that inserting replacement text in
contenteditable areas causes the dataTransfer attribute to be populated, and that the data attribute is null.

* fast/events/before-input-prevent-insert-replacement-expected.txt: Added.
* fast/events/before-input-prevent-insert-replacement.html: Added.
* fast/events/input-event-insert-replacement-expected.txt: Added.
* fast/events/input-event-insert-replacement.html: Added.
* platform/ios-simulator/TestExpectations:
* platform/mac-wk1/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (208142 => 208143)


--- trunk/LayoutTests/ChangeLog	2016-10-31 15:01:18 UTC (rev 208142)
+++ trunk/LayoutTests/ChangeLog	2016-10-31 15:12:00 UTC (rev 208143)
@@ -1,3 +1,23 @@
+2016-10-31  Wenson Hsieh  <[email protected]>
+
+        Holding down a key to choose an accented character should fire "insertReplacementText" input events
+        https://bugs.webkit.org/show_bug.cgi?id=164209
+        <rdar://problem/29019305>
+
+        Reviewed by Darin Adler.
+
+        Adds 2 new layout tests to verify that inserting replacement text fires input events of inputType
+        "insertReplacementText" instead of the generic "insertText", and that calling preventDefault() on the
+        beforeinput event prevents text from being inserted. Also checks that inserting replacement text in
+        contenteditable areas causes the dataTransfer attribute to be populated, and that the data attribute is null.
+
+        * fast/events/before-input-prevent-insert-replacement-expected.txt: Added.
+        * fast/events/before-input-prevent-insert-replacement.html: Added.
+        * fast/events/input-event-insert-replacement-expected.txt: Added.
+        * fast/events/input-event-insert-replacement.html: Added.
+        * platform/ios-simulator/TestExpectations:
+        * platform/mac-wk1/TestExpectations:
+
 2016-10-30  Gyuyoung Kim  <[email protected]>
 
         [EFL] Skip media tests because timeout happens on many media tests.

Added: trunk/LayoutTests/fast/events/before-input-prevent-insert-replacement-expected.txt (0 => 208143)


--- trunk/LayoutTests/fast/events/before-input-prevent-insert-replacement-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/before-input-prevent-insert-replacement-expected.txt	2016-10-31 15:12:00 UTC (rev 208143)
@@ -0,0 +1,7 @@
+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"`
+

Added: trunk/LayoutTests/fast/events/before-input-prevent-insert-replacement.html (0 => 208143)


--- trunk/LayoutTests/fast/events/before-input-prevent-insert-replacement.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/before-input-prevent-insert-replacement.html	2016-10-31 15:12:00 UTC (rev 208143)
@@ -0,0 +1,60 @@
+<!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();
+
+        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'.");
+        }
+
+        function incrementProgress()
+        {
+            progress++;
+            if (progress == 2)
+                testRunner.notifyDone();
+        }
+
+        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();
+            }
+        }
+
+        function dataTransferAsString(dataTransfer)
+        {
+            if (!dataTransfer)
+                return "null";
+
+            return `plain:"${dataTransfer.getData('text/plain')}", html:"${dataTransfer.getData('text/html')}"`;
+        }
+
+        function getUIScript()
+        {
+            return `
+            (function() {
+                uiController.insertText("b", 0, 1);
+                uiController.uiScriptComplete();
+            })();`
+        }
+    </script>
+</body>
+</html>
\ No newline at end of file

Added: trunk/LayoutTests/fast/events/input-event-insert-replacement-expected.txt (0 => 208143)


--- trunk/LayoutTests/fast/events/input-event-insert-replacement-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/input-event-insert-replacement-expected.txt	2016-10-31 15:12:00 UTC (rev 208143)
@@ -0,0 +1,11 @@
+
+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`
+The value of the input is now: b
+

Added: trunk/LayoutTests/fast/events/input-event-insert-replacement.html (0 => 208143)


--- trunk/LayoutTests/fast/events/input-event-insert-replacement.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/input-event-insert-replacement.html	2016-10-31 15:12:00 UTC (rev 208143)
@@ -0,0 +1,55 @@
+<!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();
+
+        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'.");
+        }
+
+        function incrementProgress()
+        {
+            progress++;
+            if (progress != 5)
+                return;
+
+            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}\``);
+            incrementProgress();
+        }
+
+        function getUIScript()
+        {
+            return `
+            (function() {
+                uiController.insertText("b", 0, 1);
+                uiController.uiScriptComplete();
+            })();`
+        }
+    </script>
+</body>
+</html>
\ No newline at end of file

Modified: trunk/LayoutTests/platform/ios-simulator/TestExpectations (208142 => 208143)


--- trunk/LayoutTests/platform/ios-simulator/TestExpectations	2016-10-31 15:01:18 UTC (rev 208142)
+++ trunk/LayoutTests/platform/ios-simulator/TestExpectations	2016-10-31 15:12:00 UTC (rev 208143)
@@ -1202,6 +1202,7 @@
 fast/events/frame-tab-focus.html [ Failure ]
 fast/events/ime-composition-events-001.html [ Failure ]
 fast/events/inputText-never-fired-on-keydown-cancel.html [ Failure ]
+fast/events/input-event-insert-replacement.html [ Failure ]
 fast/events/input-events-drag-and-drop.html [ Failure ]
 fast/events/input-events-insert-by-drop.html [ Failure ]
 fast/events/input-events-fired-when-typing.html [ Failure ]
@@ -1212,6 +1213,7 @@
 fast/events/input-events-ime-composition.html [ Failure ]
 fast/events/input-events-paste-rich-datatransfer.html [ Failure ]
 fast/events/input-events-spell-checking-datatransfer.html [ Failure ]
+fast/events/before-input-prevent-insert-replacement.html [ Failure ]
 fast/events/before-input-events-prevent-default.html [ Failure ]
 fast/events/before-input-events-prevent-default-in-textfield.html [ Failure ]
 fast/events/before-input-events-different-start-end-elements.html [ Failure ]

Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (208142 => 208143)


--- trunk/LayoutTests/platform/mac-wk1/TestExpectations	2016-10-31 15:01:18 UTC (rev 208142)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations	2016-10-31 15:12:00 UTC (rev 208143)
@@ -84,6 +84,10 @@
 # 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/Source/WebCore/ChangeLog (208142 => 208143)


--- trunk/Source/WebCore/ChangeLog	2016-10-31 15:01:18 UTC (rev 208142)
+++ trunk/Source/WebCore/ChangeLog	2016-10-31 15:12:00 UTC (rev 208143)
@@ -1,3 +1,24 @@
+2016-10-31  Wenson Hsieh  <[email protected]>
+
+        Holding down a key to choose an accented character should fire "insertReplacementText" input events
+        https://bugs.webkit.org/show_bug.cgi?id=164209
+        <rdar://problem/29019305>
+
+        Reviewed by Darin Adler.
+
+        For TypingCommands that correspond to "insertReplacementText" inputTypes, vend dataTransfers for resulting
+        beforeinput and input events if the edited area is not an input field or textarea. To do this, convert the plain
+        text representation of the content to be inserted to HTML text using a helper function,
+        MarkupAccumulator::appendCharactersReplacingEntities, that is used when creating markup for Text nodes.
+
+        Tests: fast/events/before-input-prevent-insert-replacement.html
+               fast/events/input-event-insert-replacement.html
+
+        * editing/TypingCommand.cpp:
+        (WebCore::TypingCommand::inputEventData):
+        (WebCore::TypingCommand::inputEventDataTransfer):
+        * editing/TypingCommand.h:
+
 2016-10-30  Dave Hyatt  <[email protected]>
 
         [CSS Parser] Miscellaneous bug fixes

Modified: trunk/Source/WebCore/editing/TypingCommand.cpp (208142 => 208143)


--- trunk/Source/WebCore/editing/TypingCommand.cpp	2016-10-31 15:01:18 UTC (rev 208142)
+++ trunk/Source/WebCore/editing/TypingCommand.cpp	2016-10-31 15:12:00 UTC (rev 208143)
@@ -28,6 +28,7 @@
 
 #include "AXObjectCache.h"
 #include "BreakBlockquoteCommand.h"
+#include "DataTransfer.h"
 #include "DeleteSelectionCommand.h"
 #include "Document.h"
 #include "Editor.h"
@@ -39,6 +40,7 @@
 #include "InsertParagraphSeparatorCommand.h"
 #include "InsertTextCommand.h"
 #include "Logging.h"
+#include "MarkupAccumulator.h"
 #include "MathMLElement.h"
 #include "RenderElement.h"
 #include "StaticRange.h"
@@ -406,15 +408,26 @@
 {
     switch (m_currentTypingEditAction) {
     case EditActionTypingInsertText:
-    case EditActionInsertReplacement:
     case EditActionTypingInsertPendingComposition:
     case EditActionTypingInsertFinalComposition:
         return m_currentTextToInsert;
+    case EditActionInsertReplacement:
+        return isEditingTextAreaOrTextInput() ? m_currentTextToInsert : String();
     default:
         return CompositeEditCommand::inputEventData();
     }
 }
 
+RefPtr<DataTransfer> TypingCommand::inputEventDataTransfer() const
+{
+    if (m_currentTypingEditAction != EditActionInsertReplacement || isEditingTextAreaOrTextInput())
+        return nullptr;
+
+    StringBuilder htmlText;
+    MarkupAccumulator::appendCharactersReplacingEntities(htmlText, m_currentTextToInsert, 0, m_currentTextToInsert.length(), EntityMaskInHTMLPCDATA);
+    return DataTransfer::createForInputEvent(m_currentTextToInsert, htmlText.toString());
+}
+
 void TypingCommand::didApplyCommand()
 {
     // TypingCommands handle applied editing separately (see TypingCommand::typingAddedToOpenCommand).

Modified: trunk/Source/WebCore/editing/TypingCommand.h (208142 => 208143)


--- trunk/Source/WebCore/editing/TypingCommand.h	2016-10-31 15:01:18 UTC (rev 208142)
+++ trunk/Source/WebCore/editing/TypingCommand.h	2016-10-31 15:12:00 UTC (rev 208143)
@@ -120,6 +120,7 @@
 
     String inputEventTypeName() const final;
     String inputEventData() const final;
+    RefPtr<DataTransfer> inputEventDataTransfer() const final;
     bool isBeforeInputEventCancelable() const final;
 
     static void updateSelectionIfDifferentFromCurrentSelection(TypingCommand*, Frame*);

Modified: trunk/Source/WebKit2/ChangeLog (208142 => 208143)


--- trunk/Source/WebKit2/ChangeLog	2016-10-31 15:01:18 UTC (rev 208142)
+++ trunk/Source/WebKit2/ChangeLog	2016-10-31 15:12:00 UTC (rev 208143)
@@ -1,3 +1,21 @@
+2016-10-31  Wenson Hsieh  <[email protected]>
+
+        Holding down a key to choose an accented character should fire "insertReplacementText" input events
+        https://bugs.webkit.org/show_bug.cgi?id=164209
+        <rdar://problem/29019305>
+
+        Reviewed by Darin Adler.
+
+        When replacing text, call Editor::insertText with the correct TextEventInputType so that WebCore will know to
+        use EditActionInsertReplacement when creating and applying the corresponding TypingCommand. Additional minor
+        changes in order to support testing replacement text insertion.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _insertText:replacementRange:]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::insertTextAsync):
+
 2016-10-30  Darin Adler  <[email protected]>
 
         Move Element, NamedNodeMap, and DOMStringMap from ExceptionCode to Exception

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (208142 => 208143)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2016-10-31 15:01:18 UTC (rev 208142)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2016-10-31 15:12:00 UTC (rev 208143)
@@ -4650,6 +4650,11 @@
 {
     // Overridden by subclasses.
 }
+
+- (void)_insertText:(id)string replacementRange:(NSRange)replacementRange
+{
+    [self insertText:string replacementRange:replacementRange];
+}
 #endif // PLATFORM(MAC)
 
 - (void)_setPageScale:(CGFloat)scale withOrigin:(CGPoint)origin

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (208142 => 208143)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2016-10-31 15:01:18 UTC (rev 208142)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2016-10-31 15:12:00 UTC (rev 208143)
@@ -290,6 +290,8 @@
 @property (nonatomic, readonly) BOOL _shouldRequestCandidates WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 - (void)_requestActiveNowPlayingSessionInfo WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 - (void)_handleActiveNowPlayingSessionInfoResponse:(BOOL)hasActiveSession title:(NSString *)title duration:(double)duration elapsedTime:(double)elapsedTime WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+
+- (void)_insertText:(id)string replacementRange:(NSRange)replacementRange WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 #endif
 
 - (void)_setPageScale:(CGFloat)scale withOrigin:(CGPoint)origin WK_API_AVAILABLE(ios(WK_IOS_TBA));

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (208142 => 208143)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2016-10-31 15:01:18 UTC (rev 208142)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2016-10-31 15:12:00 UTC (rev 208143)
@@ -4625,11 +4625,13 @@
 {
     Frame& frame = m_page->focusController().focusedOrMainFrame();
 
+    bool replacesText = false;
     if (replacementEditingRange.location != notFound) {
         RefPtr<Range> replacementRange = rangeFromEditingRange(frame, replacementEditingRange, static_cast<EditingRangeIsRelativeTo>(editingRangeIsRelativeTo));
         if (replacementRange) {
             TemporaryChange<bool> isSelectingTextWhileInsertingAsynchronously(m_isSelectingTextWhileInsertingAsynchronously, suppressSelectionUpdate);
             frame.selection().setSelection(VisibleSelection(*replacementRange, SEL_DEFAULT_AFFINITY));
+            replacesText = true;
         }
     }
     
@@ -4639,7 +4641,7 @@
     if (!frame.editor().hasComposition()) {
         // An insertText: might be handled by other responders in the chain if we don't handle it.
         // One example is space bar that results in scrolling down the page.
-        frame.editor().insertText(text, nullptr);
+        frame.editor().insertText(text, nullptr, replacesText ? TextEventInputAutocompletion : TextEventInputKeyboard);
     } else
         frame.editor().confirmComposition(text);
 }

Modified: trunk/Tools/ChangeLog (208142 => 208143)


--- trunk/Tools/ChangeLog	2016-10-31 15:01:18 UTC (rev 208142)
+++ trunk/Tools/ChangeLog	2016-10-31 15:12:00 UTC (rev 208143)
@@ -1,3 +1,31 @@
+2016-10-31  Wenson Hsieh  <[email protected]>
+
+        Holding down a key to choose an accented character should fire "insertReplacementText" input events
+        https://bugs.webkit.org/show_bug.cgi?id=164209
+        <rdar://problem/29019305>
+
+        Reviewed by Darin Adler.
+
+        Adds test support for inserting replacement text on Mac. This is equivalent to holding down a vowel key (e.g.
+        'a') to bring up the menu containing accented version of the character, then selecting an accented character to
+        insert in place of the typed character. This is exposed via UIScriptController.insertText, which takes a string
+        and an insertion range.
+
+        * DumpRenderTree/mac/UIScriptControllerMac.mm:
+        (WTR::UIScriptController::insertText):
+        * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
+
+        Note that there is no callback argument to insertText, since UIScriptController::insertText is synchronous in
+        the UI process. The tests end when corresponding input events fired as a result of insertText have been received
+        in the web process. Please see the new layout tests for more detail.
+
+        * TestRunnerShared/UIScriptContext/UIScriptController.cpp:
+        (WTR::UIScriptController::insertText):
+        * TestRunnerShared/UIScriptContext/UIScriptController.h:
+        * WebKitTestRunner/mac/UIScriptControllerMac.mm:
+        (WTR::nsStringFromJSString):
+        (WTR::UIScriptController::insertText):
+
 2016-10-30  Sam Weinig  <[email protected]>
 
         [WebIDL] Restructure IDLParser structs to better match modern WebIDL concepts

Modified: trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm (208142 => 208143)


--- trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm	2016-10-31 15:01:18 UTC (rev 208142)
+++ trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm	2016-10-31 15:12:00 UTC (rev 208143)
@@ -43,6 +43,10 @@
     });
 }
 
+void UIScriptController::insertText(JSStringRef, int, int)
+{
 }
 
+}
+
 #endif // PLATFORM(MAC)

Modified: trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl (208142 => 208143)


--- trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl	2016-10-31 15:01:18 UTC (rev 208142)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl	2016-10-31 15:12:00 UTC (rev 208143)
@@ -156,5 +156,7 @@
 
     readonly attribute object selectionRangeViewRects; // An array of objects with 'left', 'top', 'width', and 'height' properties.
 
+    void insertText(DOMString text, long location, long length);
+
     void uiScriptComplete(DOMString result);
 };

Modified: trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp (208142 => 208143)


--- trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp	2016-10-31 15:01:18 UTC (rev 208142)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp	2016-10-31 15:12:00 UTC (rev 208143)
@@ -317,6 +317,14 @@
 }
 #endif
 
+#if !PLATFORM(MAC)
+
+void UIScriptController::insertText(JSStringRef, int, int)
+{
+}
+
+#endif
+
 void UIScriptController::uiScriptComplete(JSStringRef result)
 {
     m_context->requestUIScriptCompletion(result);

Modified: trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h (208142 => 208143)


--- trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h	2016-10-31 15:01:18 UTC (rev 208142)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h	2016-10-31 15:12:00 UTC (rev 208143)
@@ -117,6 +117,8 @@
     
     JSObjectRef selectionRangeViewRects() const;
 
+    void insertText(JSStringRef, int location, int length);
+
     void uiScriptComplete(JSStringRef result);
 
 private:

Modified: trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm (208142 => 208143)


--- trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm	2016-10-31 15:01:18 UTC (rev 208142)
+++ trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm	2016-10-31 15:12:00 UTC (rev 208143)
@@ -26,10 +26,20 @@
 #import "config.h"
 #import "UIScriptController.h"
 
+#import "PlatformWebView.h"
+#import "TestController.h"
+#import "TestRunnerWKWebView.h"
 #import "UIScriptContext.h"
+#import <_javascript_Core/JSStringRefCF.h>
+#import <WebKit/WKWebViewPrivate.h>
 
 namespace WTR {
 
+NSString *nsString(JSStringRef string)
+{
+    return (NSString *)adoptCF(JSStringCopyCFString(kCFAllocatorDefault, string)).autorelease();
+}
+
 void UIScriptController::doAsyncTask(JSValueRef callback)
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
@@ -41,4 +51,19 @@
     });
 }
 
+void UIScriptController::insertText(JSStringRef text, int location, int length)
+{
+#if WK_API_ENABLED
+    if (location == -1)
+        location = NSNotFound;
+
+    auto* webView = TestController::singleton().mainWebView()->platformView();
+    [webView _insertText:nsString(text) replacementRange:NSMakeRange(location, length)];
+#else
+    UNUSED_PARAM(text);
+    UNUSED_PARAM(location);
+    UNUSED_PARAM(length);
+#endif
 }
+
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to