Title: [239750] trunk
Revision
239750
Author
[email protected]
Date
2019-01-08 16:10:24 -0800 (Tue, 08 Jan 2019)

Log Message

[iOS] Dispatch a synthetic mousedown event prior to starting drags
https://bugs.webkit.org/show_bug.cgi?id=193229
<rdar://problem/46717097>

Reviewed by Tim Horton.

Source/WebCore:

Tweaks some drag initiation logic on iOS to actually send a "mousedown" event to the page prior to drag start.
This improves drag and drop compatibility with web pages that expect a mousedown to always precede dragging.
Additionally, ensure that preventing the "mousedown" event also prevents "dragstart", which matches macOS
behavior.

Test: DragAndDropTests.PreventingMouseDownShouldPreventDragStart

* page/EventHandler.cpp:

Make the text drag delay 0 on iOS. This was introduced on iOS when originally bringing up drag and drop, and was
made to simply match macOS. However, it doesn't make sense to respect the delay here, since the purpose of this
delay is to disambiguate between making a text selection and starting a drag when pressing on text that is
already selected; on iOS (including iOSMac), this gesture conflict is already resolved by platform gesture
recognizers in the client layer, so there is always no delay between mouse down and drag here.

* page/ios/EventHandlerIOS.mm:

Dispatch a mousedown and inspect the value of `m_mouseDownMayStartDrag` when starting a drag on iOS. This brings
our behavior closer in line with macOS.

(WebCore::EventHandler::tryToBeginDataInteractionAtPoint):

Tools:

Add a cross-platform drag and drop test to verify that calling `preventDefault()` on the mousedown event
prevents a drag from starting.

* TestWebKitAPI/Tests/WebKitCocoa/DragAndDropTests.mm:
* TestWebKitAPI/Tests/WebKitCocoa/link-and-target-div.html:

Tweak this test to make it robust when dragging the link to the target element multiple times in a single test.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (239749 => 239750)


--- trunk/Source/WebCore/ChangeLog	2019-01-08 23:06:12 UTC (rev 239749)
+++ trunk/Source/WebCore/ChangeLog	2019-01-09 00:10:24 UTC (rev 239750)
@@ -1,3 +1,33 @@
+2019-01-08  Wenson Hsieh  <[email protected]>
+
+        [iOS] Dispatch a synthetic mousedown event prior to starting drags
+        https://bugs.webkit.org/show_bug.cgi?id=193229
+        <rdar://problem/46717097>
+
+        Reviewed by Tim Horton.
+
+        Tweaks some drag initiation logic on iOS to actually send a "mousedown" event to the page prior to drag start.
+        This improves drag and drop compatibility with web pages that expect a mousedown to always precede dragging.
+        Additionally, ensure that preventing the "mousedown" event also prevents "dragstart", which matches macOS
+        behavior.
+
+        Test: DragAndDropTests.PreventingMouseDownShouldPreventDragStart
+
+        * page/EventHandler.cpp:
+
+        Make the text drag delay 0 on iOS. This was introduced on iOS when originally bringing up drag and drop, and was
+        made to simply match macOS. However, it doesn't make sense to respect the delay here, since the purpose of this
+        delay is to disambiguate between making a text selection and starting a drag when pressing on text that is
+        already selected; on iOS (including iOSMac), this gesture conflict is already resolved by platform gesture
+        recognizers in the client layer, so there is always no delay between mouse down and drag here.
+
+        * page/ios/EventHandlerIOS.mm:
+
+        Dispatch a mousedown and inspect the value of `m_mouseDownMayStartDrag` when starting a drag on iOS. This brings
+        our behavior closer in line with macOS.
+
+        (WebCore::EventHandler::tryToBeginDataInteractionAtPoint):
+
 2019-01-08  Youenn Fablet  <[email protected]>
 
         service worker fetch handler results in bad referrer

Modified: trunk/Source/WebCore/page/EventHandler.cpp (239749 => 239750)


--- trunk/Source/WebCore/page/EventHandler.cpp	2019-01-08 23:06:12 UTC (rev 239749)
+++ trunk/Source/WebCore/page/EventHandler.cpp	2019-01-09 00:10:24 UTC (rev 239750)
@@ -138,7 +138,7 @@
 const int TextDragHysteresis = 3;
 const int ColorDragHystersis = 3;
 const int GeneralDragHysteresis = 3;
-#if PLATFORM(COCOA)
+#if PLATFORM(MAC)
 const Seconds EventHandler::TextDragDelay { 150_ms };
 #else
 const Seconds EventHandler::TextDragDelay { 0_s };

Modified: trunk/Source/WebCore/page/ios/EventHandlerIOS.mm (239749 => 239750)


--- trunk/Source/WebCore/page/ios/EventHandlerIOS.mm	2019-01-08 23:06:12 UTC (rev 239749)
+++ trunk/Source/WebCore/page/ios/EventHandlerIOS.mm	2019-01-09 00:10:24 UTC (rev 239750)
@@ -676,17 +676,14 @@
     if (subframe && subframe->eventHandler().tryToBeginDataInteractionAtPoint(adjustedClientPosition, adjustedGlobalPosition))
         return true;
 
-    // FIXME: This needs to be refactored, along with handleMousePressEvent and handleMouseMoveEvent, so that state associated only with dragging
-    // lives solely in the DragController, and so that we don't need to pretend that a mouse press and mouse move have already occurred here.
-    m_mouseDownMayStartDrag = eventMayStartDrag(syntheticMousePressEvent);
-    if (!m_mouseDownMayStartDrag)
+    if (!eventMayStartDrag(syntheticMousePressEvent))
         return false;
 
-    SetForScope<bool> mousePressed(m_mousePressed, true);
-    dragState().source = nullptr;
-    m_mouseDownPos = protectedFrame->view()->windowToContents(syntheticMouseMoveEvent.position());
-
-    return handleMouseDraggedEvent(hitTestedMouseEvent, DontCheckDragHysteresis);
+    handleMousePressEvent(syntheticMousePressEvent);
+    bool handledDrag = m_mouseDownMayStartDrag && handleMouseDraggedEvent(hitTestedMouseEvent, DontCheckDragHysteresis);
+    // Reset this bit to prevent autoscrolling from updating the selection with the last mouse location.
+    m_mouseDownMayStartSelect = false;
+    return handledDrag;
 }
 
 #endif

Modified: trunk/Tools/ChangeLog (239749 => 239750)


--- trunk/Tools/ChangeLog	2019-01-08 23:06:12 UTC (rev 239749)
+++ trunk/Tools/ChangeLog	2019-01-09 00:10:24 UTC (rev 239750)
@@ -1,3 +1,19 @@
+2019-01-08  Wenson Hsieh  <[email protected]>
+
+        [iOS] Dispatch a synthetic mousedown event prior to starting drags
+        https://bugs.webkit.org/show_bug.cgi?id=193229
+        <rdar://problem/46717097>
+
+        Reviewed by Tim Horton.
+
+        Add a cross-platform drag and drop test to verify that calling `preventDefault()` on the mousedown event
+        prevents a drag from starting.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/DragAndDropTests.mm:
+        * TestWebKitAPI/Tests/WebKitCocoa/link-and-target-div.html:
+
+        Tweak this test to make it robust when dragging the link to the target element multiple times in a single test.
+
 2019-01-08  Zhifei Fang  <[email protected]>
   
         Layout test will generate a perf metric file to results dir.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DragAndDropTests.mm (239749 => 239750)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DragAndDropTests.mm	2019-01-08 23:06:12 UTC (rev 239749)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DragAndDropTests.mm	2019-01-09 00:10:24 UTC (rev 239750)
@@ -116,6 +116,25 @@
     EXPECT_WK_STREQ("https://webkit.org/\nhttps://apple.com/", [webView stringByEvaluatingJavaScript:@"urlData.textContent"]);
 }
 
+TEST(DragAndDropTests, PreventingMouseDownShouldPreventDragStart)
+{
+    auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebViewFrame:CGRectMake(0, 0, 320, 500)]);
+    auto webView = [simulator webView];
+    WKPreferencesSetCustomPasteboardDataEnabled((__bridge WKPreferencesRef)[webView configuration].preferences, true);
+    [webView synchronouslyLoadTestPageNamed:@"link-and-target-div"];
+    [simulator runFrom:CGPointMake(160, 100) to:CGPointMake(160, 300)];
+    EXPECT_WK_STREQ("PASS", [webView stringByEvaluatingJavaScript:@"target.textContent"]);
+    EXPECT_WK_STREQ("dragstart dragend", [webView stringByEvaluatingJavaScript:@"output.textContent"]);
+
+    // Now verify that preventing default on the 'mousedown' event cancels the drag altogether.
+    [webView evaluateJavaScript:@"target.textContent = output.textContent = ''" completionHandler:nil];
+    [webView evaluateJavaScript:@"source.addEventListener('mousedown', event => { event.preventDefault(); window.observedMousedown = true; })" completionHandler:nil];
+    [simulator runFrom:CGPointMake(160, 100) to:CGPointMake(160, 300)];
+    EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"target.textContent"]);
+    EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"output.textContent"]);
+    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"observedMousedown"].boolValue);
+}
+
 #if ENABLE(INPUT_TYPE_COLOR)
 
 TEST(DragAndDropTests, ColorInputToColorInput)
@@ -188,6 +207,6 @@
     TestWebKitAPI::Util::run(&changeEventFired);
 }
 
-#endif
+#endif // ENABLE(INPUT_TYPE_COLOR)
 
 #endif // WK_API_ENABLED && ENABLE(DRAG_SUPPORT)

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/link-and-target-div.html (239749 => 239750)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/link-and-target-div.html	2019-01-08 23:06:12 UTC (rev 239749)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/link-and-target-div.html	2019-01-09 00:10:24 UTC (rev 239750)
@@ -4,6 +4,7 @@
     width: 100%;
     height: 100%;
     margin: 0;
+    overflow: hidden;
 }
 
 a, #target {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to