Diff
Modified: trunk/LayoutTests/ChangeLog (217586 => 217587)
--- trunk/LayoutTests/ChangeLog 2017-05-30 23:55:51 UTC (rev 217586)
+++ trunk/LayoutTests/ChangeLog 2017-05-31 00:44:02 UTC (rev 217587)
@@ -1,3 +1,15 @@
+2017-05-30 Tim Horton <[email protected]>
+
+ Keyboard autocorrections do not apply with an active selection (but keyboard acts like they did)
+ https://bugs.webkit.org/show_bug.cgi?id=172735
+ <rdar://problem/32015977>
+
+ Reviewed by Enrica Casucci.
+
+ * fast/events/ios/autocorrect-with-range-selection-expected.txt: Added.
+ * fast/events/ios/autocorrect-with-range-selection.html: Added.
+ Add a test that ensures that autocorrection with a selection succeeds.
+
2017-05-30 Sam Weinig <[email protected]>
[WebIDL] Generate named property deleters
Added: trunk/LayoutTests/fast/events/ios/autocorrect-with-range-selection-expected.txt (0 => 217587)
--- trunk/LayoutTests/fast/events/ios/autocorrect-with-range-selection-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/events/ios/autocorrect-with-range-selection-expected.txt 2017-05-31 00:44:02 UTC (rev 217587)
@@ -0,0 +1,4 @@
+To
+To manually test, type 'Ti' into the contenteditable, select it, then tap the autocorrection in the keyboard. The 'Ti' should be autocorrected.
+
+
Added: trunk/LayoutTests/fast/events/ios/autocorrect-with-range-selection.html (0 => 217587)
--- trunk/LayoutTests/fast/events/ios/autocorrect-with-range-selection.html (rev 0)
+++ trunk/LayoutTests/fast/events/ios/autocorrect-with-range-selection.html 2017-05-31 00:44:02 UTC (rev 217587)
@@ -0,0 +1,36 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+<html>
+<head>
+ <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
+ <script>
+ if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+ }
+
+ function runTest()
+ {
+ if (!window.testRunner || !testRunner.runUIScript)
+ return;
+
+ var inputEl = document.getElementById("editable");
+ window.getSelection().setBaseAndExtent(inputEl, 0, inputEl, 2);
+
+ testRunner.runUIScript(`(function() {
+ uiController.applyAutocorrection("To", "Ti", function() {
+ uiController.uiScriptComplete();
+ });
+ })();`, function () {
+ testRunner.notifyDone()
+ });
+ }
+ </script>
+</head>
+
+<body _onload_="runTest()">
+ <div contenteditable id="editable">Ti</div>
+ <p>To manually test, type 'Ti' into the contenteditable, select it, then tap the autocorrection in the keyboard. The 'Ti' should be autocorrected.</p>
+ <code><div id="output"></div></code>
+</body>
+
+</html>
Modified: trunk/Source/WebKit2/ChangeLog (217586 => 217587)
--- trunk/Source/WebKit2/ChangeLog 2017-05-30 23:55:51 UTC (rev 217586)
+++ trunk/Source/WebKit2/ChangeLog 2017-05-31 00:44:02 UTC (rev 217587)
@@ -1,3 +1,21 @@
+2017-05-30 Tim Horton <[email protected]>
+
+ Keyboard autocorrections do not apply with an active selection (but keyboard acts like they did)
+ https://bugs.webkit.org/show_bug.cgi?id=172735
+ <rdar://problem/32015977>
+
+ Reviewed by Enrica Casucci.
+
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView applyAutocorrection:toString:withCompletionHandler:]):
+ * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+ Expose applyAutocorrection on the WKTesting category for use from UIScriptController.
+
+ * WebProcess/WebPage/ios/WebPageIOS.mm:
+ (WebKit::WebPage::syncApplyAutocorrection):
+ If there is a range selection and it precisely matches the autocorrection's "before"
+ string, allow the autocorrection to take place.
+
2017-05-30 Joseph Pecoraro <[email protected]>
Web Inspector: images dragged from Inspector to Desktop are named "Unknown.png"
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (217586 => 217587)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2017-05-30 23:55:51 UTC (rev 217586)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2017-05-31 00:44:02 UTC (rev 217587)
@@ -5270,6 +5270,13 @@
[_contentView accessoryTab:NO];
}
+- (void)applyAutocorrection:(NSString *)newString toString:(NSString *)oldString withCompletionHandler:(void (^)())completionHandler
+{
+ [_contentView applyAutocorrection:newString toString:oldString withCompletionHandler:[capturedCompletionHandler = makeBlockPtr(completionHandler)] (UIWKAutocorrectionRects *rects) {
+ capturedCompletionHandler();
+ }];
+}
+
- (void)dismissFormAccessoryView
{
[_contentView accessoryDone];
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (217586 => 217587)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h 2017-05-30 23:55:51 UTC (rev 217586)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h 2017-05-31 00:44:02 UTC (rev 217587)
@@ -327,6 +327,8 @@
- (void)dismissFormAccessoryView WK_API_AVAILABLE(ios(WK_IOS_TBA));
- (void)selectFormAccessoryPickerRow:(int)rowIndex WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)applyAutocorrection:(NSString *)newString toString:(NSString *)oldString withCompletionHandler:(void (^)())completionHandler;
+
- (void)didStartFormControlInteraction WK_API_AVAILABLE(ios(WK_IOS_TBA));
- (void)didEndFormControlInteraction WK_API_AVAILABLE(ios(WK_IOS_TBA));
Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (217586 => 217587)
--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm 2017-05-30 23:55:51 UTC (rev 217586)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm 2017-05-31 00:44:02 UTC (rev 217587)
@@ -2273,35 +2273,50 @@
void WebPage::syncApplyAutocorrection(const String& correction, const String& originalText, bool& correctionApplied)
{
- RefPtr<Range> range;
correctionApplied = false;
+
Frame& frame = m_page->focusController().focusedOrMainFrame();
- if (!frame.selection().isCaret())
+ if (!frame.selection().isCaretOrRange())
return;
- VisiblePosition position = frame.selection().selection().start();
-
- range = wordRangeFromPosition(position);
- String textForRange = plainTextReplacingNoBreakSpace(range.get());
- if (textForRange != originalText) {
- for (size_t i = 0; i < originalText.length(); ++i)
- position = position.previous();
- if (position.isNull())
- position = startOfDocument(static_cast<Node*>(frame.document()->documentElement()));
- range = Range::create(*frame.document(), position, frame.selection().selection().start());
- if (range)
- textForRange = (range) ? plainTextReplacingNoBreakSpace(range.get()) : emptyString();
- unsigned loopCount = 0;
- const unsigned maxPositionsAttempts = 10;
- while (textForRange.length() && textForRange.length() > originalText.length() && loopCount < maxPositionsAttempts) {
- position = position.next();
- if (position.isNotNull() && position >= frame.selection().selection().start())
- range = nullptr;
- else
- range = Range::create(*frame.document(), position, frame.selection().selection().start());
- textForRange = (range) ? plainTextReplacingNoBreakSpace(range.get()) : emptyString();
- loopCount++;
+
+ RefPtr<Range> range;
+ String textForRange;
+
+ if (frame.selection().isCaret()) {
+ VisiblePosition position = frame.selection().selection().start();
+ range = wordRangeFromPosition(position);
+ textForRange = plainTextReplacingNoBreakSpace(range.get());
+ if (textForRange != originalText) {
+ // Search for the original text before the selection caret.
+ for (size_t i = 0; i < originalText.length(); ++i)
+ position = position.previous();
+ if (position.isNull())
+ position = startOfDocument(static_cast<Node*>(frame.document()->documentElement()));
+ range = Range::create(*frame.document(), position, frame.selection().selection().start());
+ if (range)
+ textForRange = (range) ? plainTextReplacingNoBreakSpace(range.get()) : emptyString();
+ unsigned loopCount = 0;
+ const unsigned maxPositionsAttempts = 10;
+ while (textForRange.length() && textForRange.length() > originalText.length() && loopCount < maxPositionsAttempts) {
+ position = position.next();
+ if (position.isNotNull() && position >= frame.selection().selection().start())
+ range = nullptr;
+ else
+ range = Range::create(*frame.document(), position, frame.selection().selection().start());
+ textForRange = (range) ? plainTextReplacingNoBreakSpace(range.get()) : emptyString();
+ loopCount++;
+ }
}
+ } else {
+ // Range selection.
+ range = frame.selection().toNormalizedRange();
+ if (!range) {
+ correctionApplied = false;
+ return;
+ }
+ textForRange = plainTextReplacingNoBreakSpace(range.get());
}
+
if (textForRange != originalText) {
correctionApplied = false;
return;
Modified: trunk/Tools/ChangeLog (217586 => 217587)
--- trunk/Tools/ChangeLog 2017-05-30 23:55:51 UTC (rev 217586)
+++ trunk/Tools/ChangeLog 2017-05-31 00:44:02 UTC (rev 217587)
@@ -1,3 +1,22 @@
+2017-05-30 Tim Horton <[email protected]>
+
+ Keyboard autocorrections do not apply with an active selection (but keyboard acts like they did)
+ https://bugs.webkit.org/show_bug.cgi?id=172735
+ <rdar://problem/32015977>
+
+ Reviewed by Enrica Casucci.
+
+ * DumpRenderTree/ios/UIScriptControllerIOS.mm:
+ (WTR::UIScriptController::applyAutocorrection):
+ * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
+ * TestRunnerShared/UIScriptContext/UIScriptController.cpp:
+ (WTR::UIScriptController::applyAutocorrection):
+ * TestRunnerShared/UIScriptContext/UIScriptController.h:
+ * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
+ (WTR::UIScriptController::applyAutocorrection):
+ Expose applyAutocorrection to UIScriptController. Use a WKTesting method
+ because I don't know how to tap the button in the autocorrection bar from a test.
+
2017-05-30 Daniel Bates <[email protected]>
Add unit test for WebKit2 C SPI runBeforeUnloadConfirmPanel()
Modified: trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm (217586 => 217587)
--- trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm 2017-05-30 23:55:51 UTC (rev 217586)
+++ trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm 2017-05-31 00:44:02 UTC (rev 217587)
@@ -203,6 +203,10 @@
{
}
+void UIScriptController::applyAutocorrection(JSStringRef, JSStringRef, JSValueRef)
+{
+}
+
double UIScriptController::minimumZoomScale() const
{
return gWebScrollView.minimumZoomScale;
Modified: trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl (217586 => 217587)
--- trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl 2017-05-30 23:55:51 UTC (rev 217586)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl 2017-05-31 00:44:02 UTC (rev 217587)
@@ -191,6 +191,8 @@
void keyboardAccessoryBarNext();
void keyboardAccessoryBarPrevious();
+ void applyAutocorrection(DOMString newString, DOMString oldString, object callback);
+
// Returned object is a dictionary with the passed in string as a key for returned object
object contentsOfUserInterfaceItem(DOMString interfaceItem);
Modified: trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp (217586 => 217587)
--- trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp 2017-05-30 23:55:51 UTC (rev 217586)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp 2017-05-31 00:44:02 UTC (rev 217587)
@@ -318,6 +318,10 @@
{
}
+void UIScriptController::applyAutocorrection(JSStringRef, JSStringRef, JSValueRef)
+{
+}
+
double UIScriptController::zoomScale() const
{
return 1;
Modified: trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h (217586 => 217587)
--- trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h 2017-05-30 23:55:51 UTC (rev 217586)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h 2017-05-31 00:44:02 UTC (rev 217587)
@@ -92,6 +92,8 @@
void keyboardAccessoryBarNext();
void keyboardAccessoryBarPrevious();
+
+ void applyAutocorrection(JSStringRef newString, JSStringRef oldString, JSValueRef callback);
void dismissFormAccessoryView();
void selectFormAccessoryPickerRow(long);
Modified: trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm (217586 => 217587)
--- trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm 2017-05-30 23:55:51 UTC (rev 217586)
+++ trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm 2017-05-31 00:44:02 UTC (rev 217587)
@@ -477,6 +477,18 @@
[webView keyboardAccessoryBarPrevious];
}
+void UIScriptController::applyAutocorrection(JSStringRef newString, JSStringRef oldString, JSValueRef callback)
+{
+ unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
+
+ TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
+ [webView applyAutocorrection:toWTFString(toWK(newString)) toString:toWTFString(toWK(oldString)) withCompletionHandler:^ {
+ if (!m_context)
+ return;
+ m_context->asyncTaskComplete(callbackID);
+ }];
+}
+
double UIScriptController::minimumZoomScale() const
{
TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();