- Revision
- 250476
- Author
- [email protected]
- Date
- 2019-09-27 18:20:54 -0700 (Fri, 27 Sep 2019)
Log Message
Cherry-pick r250432. rdar://problem/55801091
[iOS]: When inserting a photo and then inserting auto-corrected text, the photo is removed
https://bugs.webkit.org/show_bug.cgi?id=202294
Patch by Said Abou-Hallawa <[email protected]> on 2019-09-27
Reviewed by Wenson Hsieh.
Source/WebKit:
WebPage::applyAutocorrectionInternal() calls wordRangeFromPosition() to
calculate the range of the word to be replaced with the auto-corrected
word. But if the text of the range does not match the original text,
applyAutocorrectionInternal() tries to correct the range by moving it
forward such that the length of the text range matches the length of the
original text.
Another case, which should correct the range also, is: the range does not
have a text but it is not collapsed. In this case, we should set the range
back to the selection range so non-text nodes is removed.
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::applyAutocorrectionInternal):
LayoutTests:
* fast/events/ios/autocorrect-after-image-expected.txt: Added.
* fast/events/ios/autocorrect-after-image.html: Added.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250432 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Modified Paths
Added Paths
Diff
Modified: branches/safari-608-branch/LayoutTests/ChangeLog (250475 => 250476)
--- branches/safari-608-branch/LayoutTests/ChangeLog 2019-09-28 01:00:08 UTC (rev 250475)
+++ branches/safari-608-branch/LayoutTests/ChangeLog 2019-09-28 01:20:54 UTC (rev 250476)
@@ -1,5 +1,48 @@
2019-09-27 Alan Coon <[email protected]>
+ Cherry-pick r250432. rdar://problem/55801091
+
+ [iOS]: When inserting a photo and then inserting auto-corrected text, the photo is removed
+ https://bugs.webkit.org/show_bug.cgi?id=202294
+
+ Patch by Said Abou-Hallawa <[email protected]> on 2019-09-27
+ Reviewed by Wenson Hsieh.
+
+ Source/WebKit:
+
+ WebPage::applyAutocorrectionInternal() calls wordRangeFromPosition() to
+ calculate the range of the word to be replaced with the auto-corrected
+ word. But if the text of the range does not match the original text,
+ applyAutocorrectionInternal() tries to correct the range by moving it
+ forward such that the length of the text range matches the length of the
+ original text.
+
+ Another case, which should correct the range also, is: the range does not
+ have a text but it is not collapsed. In this case, we should set the range
+ back to the selection range so non-text nodes is removed.
+
+ * WebProcess/WebPage/ios/WebPageIOS.mm:
+ (WebKit::WebPage::applyAutocorrectionInternal):
+
+ LayoutTests:
+
+ * fast/events/ios/autocorrect-after-image-expected.txt: Added.
+ * fast/events/ios/autocorrect-after-image.html: Added.
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250432 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2019-09-27 Said Abou-Hallawa <[email protected]>
+
+ [iOS]: When inserting a photo and then inserting auto-corrected text, the photo is removed
+ https://bugs.webkit.org/show_bug.cgi?id=202294
+
+ Reviewed by Wenson Hsieh.
+
+ * fast/events/ios/autocorrect-after-image-expected.txt: Added.
+ * fast/events/ios/autocorrect-after-image.html: Added.
+
+2019-09-27 Alan Coon <[email protected]>
+
Cherry-pick r250392. rdar://problem/55770703
[iOS 13] Tapping on a non-editable text selection should toggle callout bar visibility instead of clearing selection
Added: branches/safari-608-branch/LayoutTests/fast/events/ios/autocorrect-after-image-expected.txt (0 => 250476)
--- branches/safari-608-branch/LayoutTests/fast/events/ios/autocorrect-after-image-expected.txt (rev 0)
+++ branches/safari-608-branch/LayoutTests/fast/events/ios/autocorrect-after-image-expected.txt 2019-09-28 01:20:54 UTC (rev 250476)
@@ -0,0 +1,13 @@
+The
+This test verifies that inserting an auto-corrected text after an image does not remove the image.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS Observed input event of inputType insertText
+PASS document.activeElement is editor
+PASS editor.children.length is 1
+PASS editor.children[0] instanceof HTMLImageElement is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: branches/safari-608-branch/LayoutTests/fast/events/ios/autocorrect-after-image.html (0 => 250476)
--- branches/safari-608-branch/LayoutTests/fast/events/ios/autocorrect-after-image.html (rev 0)
+++ branches/safari-608-branch/LayoutTests/fast/events/ios/autocorrect-after-image.html 2019-09-28 01:20:54 UTC (rev 250476)
@@ -0,0 +1,44 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+<html>
+<head>
+ <meta charset="utf8">
+ <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
+ <script src=""
+ <script src=""
+ <style>
+ #editor {
+ max-width: 200px;
+ }
+ </style>
+ <script>
+ jsTestIsAsync = true;
+
+ addEventListener("load", async () => {
+ description(`This test verifies that inserting an auto-corrected text after an image does not remove the image.`);
+
+ addEventListener("input", event => testPassed(`Observed input event of inputType ${event.inputType}`));
+
+ if (!window.testRunner || !testRunner.runUIScript)
+ return;
+
+ editor = document.getElementById("editor");
+ await UIHelper.activateElementAndWaitForInputSession(editor);
+ await UIHelper.applyAutocorrection("The", "");
+ shouldBe("document.activeElement", "editor");
+ shouldBe("editor.children.length", "1");
+ shouldBeTrue("editor.children[0] instanceof HTMLImageElement");
+ editor.blur();
+ await UIHelper.waitForKeyboardToHide();
+ finishJSTest();
+ });
+ </script>
+</head>
+<body>
+ <div contenteditable id="editor">
+ <img src=""
+ </div>
+ <div id="description"></div>
+ <div id="console"></div>
+</body>
+
+</html>
Modified: branches/safari-608-branch/Source/WebKit/ChangeLog (250475 => 250476)
--- branches/safari-608-branch/Source/WebKit/ChangeLog 2019-09-28 01:00:08 UTC (rev 250475)
+++ branches/safari-608-branch/Source/WebKit/ChangeLog 2019-09-28 01:20:54 UTC (rev 250476)
@@ -1,5 +1,59 @@
2019-09-27 Alan Coon <[email protected]>
+ Cherry-pick r250432. rdar://problem/55801091
+
+ [iOS]: When inserting a photo and then inserting auto-corrected text, the photo is removed
+ https://bugs.webkit.org/show_bug.cgi?id=202294
+
+ Patch by Said Abou-Hallawa <[email protected]> on 2019-09-27
+ Reviewed by Wenson Hsieh.
+
+ Source/WebKit:
+
+ WebPage::applyAutocorrectionInternal() calls wordRangeFromPosition() to
+ calculate the range of the word to be replaced with the auto-corrected
+ word. But if the text of the range does not match the original text,
+ applyAutocorrectionInternal() tries to correct the range by moving it
+ forward such that the length of the text range matches the length of the
+ original text.
+
+ Another case, which should correct the range also, is: the range does not
+ have a text but it is not collapsed. In this case, we should set the range
+ back to the selection range so non-text nodes is removed.
+
+ * WebProcess/WebPage/ios/WebPageIOS.mm:
+ (WebKit::WebPage::applyAutocorrectionInternal):
+
+ LayoutTests:
+
+ * fast/events/ios/autocorrect-after-image-expected.txt: Added.
+ * fast/events/ios/autocorrect-after-image.html: Added.
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250432 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2019-09-27 Said Abou-Hallawa <[email protected]>
+
+ [iOS]: When inserting a photo and then inserting auto-corrected text, the photo is removed
+ https://bugs.webkit.org/show_bug.cgi?id=202294
+
+ Reviewed by Wenson Hsieh.
+
+ WebPage::applyAutocorrectionInternal() calls wordRangeFromPosition() to
+ calculate the range of the word to be replaced with the auto-corrected
+ word. But if the text of the range does not match the original text,
+ applyAutocorrectionInternal() tries to correct the range by moving it
+ forward such that the length of the text range matches the length of the
+ original text.
+
+ Another case, which should correct the range also, is: the range does not
+ have a text but it is not collapsed. In this case, we should set the range
+ back to the selection range so non-text nodes is removed.
+
+ * WebProcess/WebPage/ios/WebPageIOS.mm:
+ (WebKit::WebPage::applyAutocorrectionInternal):
+
+2019-09-27 Alan Coon <[email protected]>
+
Cherry-pick r250401. rdar://problem/55770702
ContextMenu on a link in an email no longer shows web preview
Modified: branches/safari-608-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (250475 => 250476)
--- branches/safari-608-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2019-09-28 01:00:08 UTC (rev 250475)
+++ branches/safari-608-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2019-09-28 01:20:54 UTC (rev 250476)
@@ -2412,6 +2412,9 @@
VisiblePosition position = frame.selection().selection().start();
range = wordRangeFromPosition(position);
textForRange = plainTextReplacingNoBreakSpace(range.get());
+
+ // If 'originalText' is not the same as 'textForRange' we need to move 'range'
+ // forward such that it matches the original selection as much as possible.
if (foldQuoteMarks(textForRange) != originalTextWithFoldedQuoteMarks) {
// Search for the original text before the selection caret.
for (size_t i = 0; i < originalText.length(); ++i)
@@ -2419,8 +2422,7 @@
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();
+ textForRange = plainTextReplacingNoBreakSpace(range.get());
unsigned loopCount = 0;
const unsigned maxPositionsAttempts = 10;
while (textForRange.length() && textForRange.length() > originalText.length() && loopCount < maxPositionsAttempts) {
@@ -2429,9 +2431,15 @@
range = nullptr;
else
range = Range::create(*frame.document(), position, frame.selection().selection().start());
- textForRange = (range) ? plainTextReplacingNoBreakSpace(range.get()) : emptyString();
+ textForRange = plainTextReplacingNoBreakSpace(range.get());
loopCount++;
}
+ } else if (textForRange.isEmpty() && range && !range->collapsed()) {
+ // If 'range' does not include any text but it is not collapsed, we need to set
+ // 'range' to match the selection. Otherwise non-text nodes will be removed.
+ range = Range::create(*frame.document(), position, position);
+ if (!range)
+ return false;
}
} else {
// Range selection.