[WK2] Tapping away to dismiss the selection does not update the selected DOM range...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 31 Mar 2017 22:36:00 +0000 (22:36 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 31 Mar 2017 22:36:00 +0000 (22:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=170328
<rdar://problem/30904558>

Reviewed by Tim Horton.

Source/WebKit2:

When UIKit clears the selection while in text interaction mode, it notifies its document view (i.e., the
WKContentView) by setting its selected text range to nil. When character granularity selection is enabled, use
this as a cue to notify the web process that the selection is being cleared out.

-setSelectedTextRange: is a noop in the general case because the web process acts as the source of truth for what
the selection currently consists of, and notifies the UI process and UIKit via WKTextPosition and WKTextRange.
However, in the case of character granularity selections, tapping away to clear the selection is handled by
UIKit's text gesture recognizer cluster, which then informs the document (via -setSelectedTextRange:) that the
selection should be cleared out.

Adds a new Layout test: editing/selection/character-granularity-selected-range-after-dismissing-selection.html.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView setSelectedTextRange:]):

LayoutTests:

Adds a new layout test verifying that when a user taps away to clear the current selection in character
granularity selection mode, the selected DOM range in the web process does not fall out of sync with UIKit's
selection views, which are dismissed.

* editing/selection/character-granularity-selected-range-after-dismissing-selection-expected.txt: Added.
* editing/selection/character-granularity-selected-range-after-dismissing-selection.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/editing/selection/character-granularity-selected-range-after-dismissing-selection-expected.txt [new file with mode: 0644]
LayoutTests/editing/selection/character-granularity-selected-range-after-dismissing-selection.html [new file with mode: 0644]
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm

index 3ac1fe9..9d5a6b3 100644 (file)
@@ -1,3 +1,18 @@
+2017-03-31  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [WK2] Tapping away to dismiss the selection does not update the selected DOM range using character granularity
+        https://bugs.webkit.org/show_bug.cgi?id=170328
+        <rdar://problem/30904558>
+
+        Reviewed by Tim Horton.
+
+        Adds a new layout test verifying that when a user taps away to clear the current selection in character
+        granularity selection mode, the selected DOM range in the web process does not fall out of sync with UIKit's
+        selection views, which are dismissed.
+
+        * editing/selection/character-granularity-selected-range-after-dismissing-selection-expected.txt: Added.
+        * editing/selection/character-granularity-selected-range-after-dismissing-selection.html: Added.
+
 2017-03-31  Youenn Fablet  <youenn@apple.com>
 
         Add a test to ensure webrtc generated certificates and names are ephemeral
index c9f5d1c..db9bebd 100644 (file)
@@ -79,6 +79,7 @@ fast/attachment/attachment-subtitle-resize.html
 
 # This test only makes sense on iOS
 fast/attachment/attachment-wrapping-action.html
+editing/selection/character-granularity-selected-range-after-dismissing-selection.html [ Skip ]
 editing/selection/caret-after-tap-in-editable-selection.html [ Skip ]
 
 # Only iOS has selection UI drawn by UIKit
diff --git a/LayoutTests/editing/selection/character-granularity-selected-range-after-dismissing-selection-expected.txt b/LayoutTests/editing/selection/character-granularity-selected-range-after-dismissing-selection-expected.txt
new file mode 100644 (file)
index 0000000..e485a58
--- /dev/null
@@ -0,0 +1,5 @@
+WEB
+KIT
+The selected content is now: "WEB"
+The selected content is now: ""
+
diff --git a/LayoutTests/editing/selection/character-granularity-selected-range-after-dismissing-selection.html b/LayoutTests/editing/selection/character-granularity-selected-range-after-dismissing-selection.html
new file mode 100644 (file)
index 0000000..6a95227
--- /dev/null
@@ -0,0 +1,58 @@
+<!-- webkit-test-runner [ useFlexibleViewport=true, useCharacterSelectionGranularity=true ] -->
+<meta name=viewport content="width=device-width, initial-scale=1">
+<div style="font-size: 125px;">WEB<br>KIT</div>
+<div id="output" style="color: green; margin-top: 1em;"></div>
+<script>
+    function selectUpperTextScript()
+    {
+        return `
+        (() => {
+            uiController.longPressAtPoint(100, 100, () => {
+                uiController.uiScriptComplete();
+            });
+        })();`
+    }
+
+    function tapLowerTextScript()
+    {
+        return `
+        (() => {
+            uiController.singleTapAtPoint(100, 225, () => {
+                uiController.uiScriptComplete();
+            });
+        })();`
+    }
+
+    function appendOutput(message)
+    {
+        let code = document.createElement("code");
+        code.appendChild(document.createTextNode(message));
+        output.appendChild(code);
+        output.appendChild(document.createElement("br"));
+    }
+
+    (() => {
+        if (!window.testRunner) {
+            appendOutput(`This test cannot be run manually; character granularity selections must be enabled.`);
+            return;
+        }
+
+        let selectedString = "";
+        document.addEventListener("selectionchange", () => {
+            let currentSelectedString = getSelection().toString();
+            if (selectedString === currentSelectedString)
+                return;
+
+            selectedString = currentSelectedString;
+            appendOutput(`The selected content is now: "${selectedString}"`);
+            if (selectedString === "")
+                testRunner.notifyDone();
+        });
+    })();
+
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+    testRunner.runUIScript(selectUpperTextScript(), () => {
+        testRunner.runUIScript(tapLowerTextScript(), () => { });
+    });
+</script>
index ea10946..1c5e99b 100644 (file)
@@ -1,5 +1,28 @@
 2017-03-31  Wenson Hsieh  <wenson_hsieh@apple.com>
 
+        [WK2] Tapping away to dismiss the selection does not update the selected DOM range using character granularity
+        https://bugs.webkit.org/show_bug.cgi?id=170328
+        <rdar://problem/30904558>
+
+        Reviewed by Tim Horton.
+
+        When UIKit clears the selection while in text interaction mode, it notifies its document view (i.e., the
+        WKContentView) by setting its selected text range to nil. When character granularity selection is enabled, use
+        this as a cue to notify the web process that the selection is being cleared out.
+
+        -setSelectedTextRange: is a noop in the general case because the web process acts as the source of truth for what
+        the selection currently consists of, and notifies the UI process and UIKit via WKTextPosition and WKTextRange.
+        However, in the case of character granularity selections, tapping away to clear the selection is handled by
+        UIKit's text gesture recognizer cluster, which then informs the document (via -setSelectedTextRange:) that the
+        selection should be cleared out.
+
+        Adds a new Layout test: editing/selection/character-granularity-selected-range-after-dismissing-selection.html.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView setSelectedTextRange:]):
+
+2017-03-31  Wenson Hsieh  <wenson_hsieh@apple.com>
+
         [WK2] Tapping editable text inside of a range selection no longer changes the selection to a caret
         https://bugs.webkit.org/show_bug.cgi?id=170327
         <rdar://problem/31363816>
index 252af4d..1727fae 100644 (file)
@@ -2977,6 +2977,11 @@ static void selectionChangedWithTouch(WKContentView *view, const WebCore::IntPoi
 
 - (void)setSelectedTextRange:(UITextRange *)range
 {
+    if (_webView.configuration.selectionGranularity != WKSelectionGranularityCharacter)
+        return;
+
+    if (!range)
+        [self clearSelection];
 }
 
 - (BOOL)hasMarkedText