<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[245067] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/245067">245067</a></dd>
<dt>Author</dt> <dd>timothy_horton@apple.com</dd>
<dt>Date</dt> <dd>2019-05-08 13:50:22 -0700 (Wed, 08 May 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>iOS: Selection is dismissed even if click is preventDefault()'d
https://bugs.webkit.org/show_bug.cgi?id=197686
<rdar://problem/49398824>

Reviewed by Wenson Hsieh.

Source/WebKit:

We currently unconditionally dismiss the selection on any tap; however
if a site preventDefault()s on click, we shouldn't perform the default
action of dismissing the selection.

Instead of clearing the selection in the UI process, clear it in the
Web content process if we don't dispatch a synthetic click; the normal
WebCore machinery will handle it in the case that we do.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _singleTapRecognized:]):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::commitPotentialTapFailed):
(WebKit::WebPage::selectWithGesture):
(WebKit::WebPage::clearSelection):
(WebKit::WebPage::selectTextWithGranularityAtPoint):

LayoutTests:

* editing/selection/ios/clear-selection-after-tapping-on-element-with-no-click-handler-expected.txt: Added.
* editing/selection/ios/clear-selection-after-tapping-on-element-with-no-click-handler.html: Added.
* editing/selection/ios/persist-selection-after-tapping-on-element-with-click-handler-expected.txt: Added.
* editing/selection/ios/persist-selection-after-tapping-on-element-with-click-handler.html: Added.
New tests.

* platform/ios/editing/deleting/smart-delete-paragraph-003-expected.txt:
* platform/ios/editing/pasteboard/smart-paste-paragraph-003-expected.txt:
Rebaseline since we changed the timing of editing callbacks by changing where the selection happens.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformioseditingdeletingsmartdeleteparagraph003expectedtxt">trunk/LayoutTests/platform/ios/editing/deleting/smart-delete-paragraph-003-expected.txt</a></li>
<li><a href="#trunkLayoutTestsplatformioseditingpasteboardsmartpasteparagraph003expectedtxt">trunk/LayoutTests/platform/ios/editing/pasteboard/smart-paste-paragraph-003-expected.txt</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitUIProcessiosWKContentViewInteractionmm">trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageWebPageh">trunk/Source/WebKit/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageiosWebPageIOSmm">trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestseditingselectioniosclearselectionaftertappingonelementwithnoclickhandlerexpectedtxt">trunk/LayoutTests/editing/selection/ios/clear-selection-after-tapping-on-element-with-no-click-handler-expected.txt</a></li>
<li><a href="#trunkLayoutTestseditingselectioniosclearselectionaftertappingonelementwithnoclickhandlerhtml">trunk/LayoutTests/editing/selection/ios/clear-selection-after-tapping-on-element-with-no-click-handler.html</a></li>
<li><a href="#trunkLayoutTestseditingselectioniospersistselectionaftertappingonelementwithclickhandlerexpectedtxt">trunk/LayoutTests/editing/selection/ios/persist-selection-after-tapping-on-element-with-click-handler-expected.txt</a></li>
<li><a href="#trunkLayoutTestseditingselectioniospersistselectionaftertappingonelementwithclickhandlerhtml">trunk/LayoutTests/editing/selection/ios/persist-selection-after-tapping-on-element-with-click-handler.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (245066 => 245067)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2019-05-08 20:32:24 UTC (rev 245066)
+++ trunk/LayoutTests/ChangeLog 2019-05-08 20:50:22 UTC (rev 245067)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2019-05-08  Tim Horton  <timothy_horton@apple.com>
+
+        iOS: Selection is dismissed even if click is preventDefault()'d
+        https://bugs.webkit.org/show_bug.cgi?id=197686
+        <rdar://problem/49398824>
+
+        Reviewed by Wenson Hsieh.
+
+        * editing/selection/ios/clear-selection-after-tapping-on-element-with-no-click-handler-expected.txt: Added.
+        * editing/selection/ios/clear-selection-after-tapping-on-element-with-no-click-handler.html: Added.
+        * editing/selection/ios/persist-selection-after-tapping-on-element-with-click-handler-expected.txt: Added.
+        * editing/selection/ios/persist-selection-after-tapping-on-element-with-click-handler.html: Added.
+        New tests.
+
+        * platform/ios/editing/deleting/smart-delete-paragraph-003-expected.txt:
+        * platform/ios/editing/pasteboard/smart-paste-paragraph-003-expected.txt:
+        Rebaseline since we changed the timing of editing callbacks by changing where the selection happens.
+
</ins><span class="cx"> 2019-05-08  Wenson Hsieh  <wenson_hsieh@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [iOS] Add a quirk to synthesize mouse events when modifying the selection
</span></span></pre></div>
<a id="trunkLayoutTestseditingselectioniosclearselectionaftertappingonelementwithnoclickhandlerexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/selection/ios/clear-selection-after-tapping-on-element-with-no-click-handler-expected.txt (0 => 245067)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/selection/ios/clear-selection-after-tapping-on-element-with-no-click-handler-expected.txt                              (rev 0)
+++ trunk/LayoutTests/editing/selection/ios/clear-selection-after-tapping-on-element-with-no-click-handler-expected.txt 2019-05-08 20:50:22 UTC (rev 245067)
</span><span class="lines">@@ -0,0 +1,3 @@
</span><ins>+WebKit
+The selected text is: ""
+This test verifies that the DOM selection is dismissed when tapping on an element that does not listen to click events.
</ins></span></pre></div>
<a id="trunkLayoutTestseditingselectioniosclearselectionaftertappingonelementwithnoclickhandlerhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/selection/ios/clear-selection-after-tapping-on-element-with-no-click-handler.html (0 => 245067)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/selection/ios/clear-selection-after-tapping-on-element-with-no-click-handler.html                              (rev 0)
+++ trunk/LayoutTests/editing/selection/ios/clear-selection-after-tapping-on-element-with-no-click-handler.html 2019-05-08 20:50:22 UTC (rev 245067)
</span><span class="lines">@@ -0,0 +1,63 @@
</span><ins>+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+<html>
+<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
+<head>
+    <script src="../../../resources/basic-gestures.js"></script>
+    <script src="../../../resources/ui-helper.js"></script>
+    <style>
+    body {
+        margin: 0;
+    }
+
+    #target {
+        font-size: 100px;
+    }
+
+    #clickTarget {
+        width: 100px;
+        height: 100px;
+    }
+    </style>
+    <script>
+    if (window.testRunner) {
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+    }
+
+    async function run()
+    {
+        if (!window.testRunner)
+            return;
+
+        function didChangeSelection()
+        {
+            result.textContent = window.getSelection().toString()
+        }
+
+        document.addEventListener("selectionchange", didChangeSelection);
+
+        var clickTarget = document.getElementById("clickTarget");
+
+        var target = document.getElementById("target");        
+        window.getSelection().setBaseAndExtent(target, 0, target, 6);
+
+        await UIHelper.activateElement(clickTarget);
+
+        setTimeout(async function () {
+            // The test is done, but we need to tap again to ensure we don't
+            // hang the next test with a double tap.
+            document.removeEventListener("selectionchange", didChangeSelection);
+            await UIHelper.tapAt(10, 500);
+
+            testRunner.notifyDone();
+        }, 0);
+    }
+    </script>
+</head>
+<body onload="run()">
+    <div id="target">WebKit</div>
+    <div id="clickTarget"></div>
+    <pre>The selected text is: "<span id="result"></span>"</pre>
+    <p>This test verifies that the DOM selection is dismissed when tapping on an element that does not listen to click events.</p>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestseditingselectioniospersistselectionaftertappingonelementwithclickhandlerexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/selection/ios/persist-selection-after-tapping-on-element-with-click-handler-expected.txt (0 => 245067)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/selection/ios/persist-selection-after-tapping-on-element-with-click-handler-expected.txt                               (rev 0)
+++ trunk/LayoutTests/editing/selection/ios/persist-selection-after-tapping-on-element-with-click-handler-expected.txt  2019-05-08 20:50:22 UTC (rev 245067)
</span><span class="lines">@@ -0,0 +1,3 @@
</span><ins>+WebKit
+The selected text is: "WebKit"
+This test verifies that the DOM selection is not dismissed when tapping on an element that preventDefault()s the click event.
</ins></span></pre></div>
<a id="trunkLayoutTestseditingselectioniospersistselectionaftertappingonelementwithclickhandlerhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/selection/ios/persist-selection-after-tapping-on-element-with-click-handler.html (0 => 245067)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/selection/ios/persist-selection-after-tapping-on-element-with-click-handler.html                               (rev 0)
+++ trunk/LayoutTests/editing/selection/ios/persist-selection-after-tapping-on-element-with-click-handler.html  2019-05-08 20:50:22 UTC (rev 245067)
</span><span class="lines">@@ -0,0 +1,68 @@
</span><ins>+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+<html>
+<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
+<head>
+    <script src="../../../resources/basic-gestures.js"></script>
+    <script src="../../../resources/ui-helper.js"></script>
+    <style>
+    body {
+        margin: 0;
+    }
+
+    #target {
+        font-size: 100px;
+    }
+
+    #clickTarget {
+        width: 100px;
+        height: 100px;
+        background-color: green;
+    }
+    </style>
+    <script>
+    if (window.testRunner) {
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+    }
+
+    async function run()
+    {
+        if (!window.testRunner)
+            return;
+
+        function didChangeSelection()
+        {
+            result.textContent = window.getSelection().toString()
+        }
+
+        document.addEventListener("selectionchange", didChangeSelection);
+
+        var clickTarget = document.getElementById("clickTarget");
+
+        clickTarget.addEventListener("click", event => {
+            event.preventDefault();
+
+            setTimeout(async function () {
+                // The test is done, but we need to tap again to ensure we don't
+                // hang the next test with a double tap.
+                document.removeEventListener("selectionchange", didChangeSelection);
+                await UIHelper.tapAt(10, 500);
+
+                testRunner.notifyDone();
+            }, 0);
+        });
+
+        var target = document.getElementById("target");        
+        window.getSelection().setBaseAndExtent(target, 0, target, 6);
+
+        await UIHelper.activateElement(clickTarget);
+    }
+    </script>
+</head>
+<body onload="run()">
+    <div id="target">WebKit</div>
+    <div id="clickTarget"></div>
+    <pre>The selected text is: "<span id="result"></span>"</pre>
+    <p>This test verifies that the DOM selection is not dismissed when tapping on an element that preventDefault()s the click event.</p>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformioseditingdeletingsmartdeleteparagraph003expectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/ios/editing/deleting/smart-delete-paragraph-003-expected.txt (245066 => 245067)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/ios/editing/deleting/smart-delete-paragraph-003-expected.txt  2019-05-08 20:32:24 UTC (rev 245066)
+++ trunk/LayoutTests/platform/ios/editing/deleting/smart-delete-paragraph-003-expected.txt     2019-05-08 20:50:22 UTC (rev 245067)
</span><span class="lines">@@ -1,11 +1,8 @@
</span><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><ins>+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 3 of BODY > HTML > #document to 3 of BODY > HTML > #document toDOMRange:range from 0 of DIV > #document-fragment to 0 of DIV > #document-fragment affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</ins><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><del>-EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of DIV > #document-fragment to 0 of DIV > #document-fragment affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
-EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</del><span class="cx"> EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > #document-fragment to 0 of DIV > #document-fragment toDOMRange:range from 0 of DIV > #document-fragment to 0 of DIV > #document-fragment affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</span><del>-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > #document-fragment to 0 of DIV > #document-fragment toDOMRange:range from 0 of #text > DIV > #document-fragment to 4 of #text > DIV > #document-fragment affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</del><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><del>-EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</del><span class="cx"> EDITING DELEGATE: shouldDeleteDOMRange:range from 0 of #text > DIV > #document-fragment to 15 of #text > DIV > #document-fragment
</span><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><span class="cx"> EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > #document-fragment to 0 of DIV > #document-fragment toDOMRange:range from 0 of DIV > #document-fragment to 0 of DIV > #document-fragment affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</span></span></pre></div>
<a id="trunkLayoutTestsplatformioseditingpasteboardsmartpasteparagraph003expectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/ios/editing/pasteboard/smart-paste-paragraph-003-expected.txt (245066 => 245067)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/ios/editing/pasteboard/smart-paste-paragraph-003-expected.txt 2019-05-08 20:32:24 UTC (rev 245066)
+++ trunk/LayoutTests/platform/ios/editing/pasteboard/smart-paste-paragraph-003-expected.txt    2019-05-08 20:50:22 UTC (rev 245067)
</span><span class="lines">@@ -1,13 +1,10 @@
</span><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><ins>+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 3 of BODY > HTML > #document to 3 of BODY > HTML > #document toDOMRange:range from 0 of DIV > #document-fragment to 0 of DIV > #document-fragment affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</ins><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><del>-EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of DIV > #document-fragment to 0 of DIV > #document-fragment affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
-EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</del><span class="cx"> EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > #document-fragment to 0 of DIV > #document-fragment toDOMRange:range from 0 of DIV > #document-fragment to 0 of DIV > #document-fragment affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</span><del>-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > #document-fragment to 0 of DIV > #document-fragment toDOMRange:range from 0 of #text > DIV > #document-fragment to 4 of #text > DIV > #document-fragment affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</del><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><del>-EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</del><span class="cx"> EDITING DELEGATE: shouldInsertText:Test paragraph. replacingDOMRange:range from 16 of #text > DIV > #document-fragment to 16 of #text > DIV > #document-fragment givenAction:WebViewInsertActionPasted
</span><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><span class="cx"> EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 32 of #text > DIV > #document-fragment to 32 of #text > DIV > #document-fragment toDOMRange:range from 1 of #text > DIV > #document-fragment to 1 of #text > DIV > #document-fragment affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (245066 => 245067)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2019-05-08 20:32:24 UTC (rev 245066)
+++ trunk/Source/WebKit/ChangeLog       2019-05-08 20:50:22 UTC (rev 245067)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2019-05-08  Tim Horton  <timothy_horton@apple.com>
+
+        iOS: Selection is dismissed even if click is preventDefault()'d
+        https://bugs.webkit.org/show_bug.cgi?id=197686
+        <rdar://problem/49398824>
+
+        Reviewed by Wenson Hsieh.
+
+        We currently unconditionally dismiss the selection on any tap; however
+        if a site preventDefault()s on click, we shouldn't perform the default
+        action of dismissing the selection.
+
+        Instead of clearing the selection in the UI process, clear it in the
+        Web content process if we don't dispatch a synthetic click; the normal
+        WebCore machinery will handle it in the case that we do.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _singleTapRecognized:]):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::commitPotentialTapFailed):
+        (WebKit::WebPage::selectWithGesture):
+        (WebKit::WebPage::clearSelection):
+        (WebKit::WebPage::selectTextWithGranularityAtPoint):
+
</ins><span class="cx"> 2019-05-08  Alexander Mikhaylenko  <exalm7659@gmail.com>
</span><span class="cx"> 
</span><span class="cx">         [GTK] Support navigation gesture on touchscreens
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessiosWKContentViewInteractionmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (245066 => 245067)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm    2019-05-08 20:32:24 UTC (rev 245066)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm       2019-05-08 20:50:22 UTC (rev 245067)
</span><span class="lines">@@ -2348,12 +2348,6 @@
</span><span class="cx"> 
</span><span class="cx">     ASSERT(_potentialTapInProgress);
</span><span class="cx"> 
</span><del>-    // We don't want to clear the selection if it is in editable content.
-    // The selection could have been set by autofocusing on page load and not
-    // reflected in the UI process since the user was not interacting with the page.
-    if (!_page->editorState().isContentEditable)
-        _page->clearSelection();
-
</del><span class="cx">     _lastInteractionLocation = gestureRecognizer.location;
</span><span class="cx"> 
</span><span class="cx">     [self _endPotentialTapAndEnableDoubleTapGesturesIfNecessary];
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (245066 => 245067)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2019-05-08 20:32:24 UTC (rev 245066)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h    2019-05-08 20:50:22 UTC (rev 245067)
</span><span class="lines">@@ -1818,7 +1818,6 @@
</span><span class="cx">     WebCore::FloatSize m_screenSize;
</span><span class="cx">     WebCore::FloatSize m_availableScreenSize;
</span><span class="cx">     WebCore::FloatSize m_overrideScreenSize;
</span><del>-    RefPtr<WebCore::Range> m_currentBlockSelection;
</del><span class="cx">     WebCore::IntRect m_blockRectForTextSelection;
</span><span class="cx"> 
</span><span class="cx">     RefPtr<WebCore::Range> m_initialSelection;
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageiosWebPageIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (245066 => 245067)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2019-05-08 20:32:24 UTC (rev 245066)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm    2019-05-08 20:50:22 UTC (rev 245067)
</span><span class="lines">@@ -947,6 +947,9 @@
</span><span class="cx"> 
</span><span class="cx"> void WebPage::commitPotentialTapFailed()
</span><span class="cx"> {
</span><ins>+    if (!m_page->focusController().focusedOrMainFrame().selection().selection().isContentEditable())
+        clearSelection();
+
</ins><span class="cx">     send(Messages::WebPageProxy::CommitPotentialTapFailed());
</span><span class="cx">     send(Messages::WebPageProxy::DidNotHandleTapAsClick(roundedIntPoint(m_potentialTapLocation)));
</span><span class="cx"> }
</span><span class="lines">@@ -1367,7 +1370,6 @@
</span><span class="cx">         if (wkGestureState == GestureRecognizerState::Began) {
</span><span class="cx">             m_blockSelectionDesiredSize.setWidth(blockSelectionStartWidth);
</span><span class="cx">             m_blockSelectionDesiredSize.setHeight(blockSelectionStartHeight);
</span><del>-            m_currentBlockSelection = nullptr;
</del><span class="cx">         }
</span><span class="cx">         range = rangeForWebSelectionAtPosition(point, position, flags);
</span><span class="cx">         break;
</span><span class="lines">@@ -1499,7 +1501,6 @@
</span><span class="cx"> void WebPage::clearSelection()
</span><span class="cx"> {
</span><span class="cx">     m_startingGestureRange = nullptr;
</span><del>-    m_currentBlockSelection = nullptr;
</del><span class="cx">     m_page->focusController().focusedOrMainFrame().selection().clear();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1958,7 +1959,6 @@
</span><span class="cx">     if (!isInteractingWithFocusedElement) {
</span><span class="cx">         m_blockSelectionDesiredSize.setWidth(blockSelectionStartWidth);
</span><span class="cx">         m_blockSelectionDesiredSize.setHeight(blockSelectionStartHeight);
</span><del>-        m_currentBlockSelection = nullptr;
</del><span class="cx">         auto* renderer = range ? range->startContainer().renderer() : nullptr;
</span><span class="cx">         if (renderer && renderer->style().preserveNewline())
</span><span class="cx">             m_blockRectForTextSelection = renderer->absoluteBoundingBoxRect(true);
</span></span></pre>
</div>
</div>

</body>
</html>