Title: [255303] branches/safari-610.1.1-branch/Source/WebCore
Revision
255303
Author
[email protected]
Date
2020-01-28 13:49:57 -0800 (Tue, 28 Jan 2020)

Log Message

Cherry-pick r255128. rdar://problem/58837212

    Tighten up some of the drag state machine logic
    https://bugs.webkit.org/show_bug.cgi?id=206798

    Reviewed by Wenson Hsieh.

    * page/EventHandler.h: Added shouldDispatchEventsToDragSourceElement function and renamed
    the existing dispatchDragSrcEvent function to dispatchEventToDragSourceElement.

    * page/EventHandler.cpp:
    (WebCore::EventHandler::updateDragAndDrop): Call the renamed dispatchEventToDragSourceElement
    unconditionally, since it now has the smarts to only dispatch an event when we are supposed to.
    (WebCore::EventHandler::cancelDragAndDrop): Ditto.
    (WebCore::EventHandler::dragSourceEndedAt): Call the new shouldDispatchEventsToDragSourceElement
    function because of the null check it does for dataTransfer, before calling setDestinationOperation
    on the dataTransfer, since there isn't an obvious ironclad guarantee we might be here without an
    actual drag fully in process and a dataTransfer object allocated. Also call the renamed
    dispatchEventToDragSourceElement by its new name.
    (WebCore::EventHandler::shouldDispatchDragSourceEvents): Added. Checks thre three conditions that
    affect whether we should dispatch events to the drag source. First that there is a drag source.
    Second that there is a dataTransfer object, indicating that we got far enough in the logic to
    actually start a drag. Third that shouldDispatchEvents is true, indicating this is the type of
    drag that should be visible to the website content and so events should be dispatched.
    (WebCore::EventHandler::dispatchEventToDragSourceElement): Call shouldDispatchDragSourceEvents
    before dispatching the event, so that callers don't all have to do that check.

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

Modified Paths

Diff

Modified: branches/safari-610.1.1-branch/Source/WebCore/ChangeLog (255302 => 255303)


--- branches/safari-610.1.1-branch/Source/WebCore/ChangeLog	2020-01-28 21:49:54 UTC (rev 255302)
+++ branches/safari-610.1.1-branch/Source/WebCore/ChangeLog	2020-01-28 21:49:57 UTC (rev 255303)
@@ -1,5 +1,63 @@
 2020-01-28  Russell Epstein  <[email protected]>
 
+        Cherry-pick r255128. rdar://problem/58837212
+
+    Tighten up some of the drag state machine logic
+    https://bugs.webkit.org/show_bug.cgi?id=206798
+    
+    Reviewed by Wenson Hsieh.
+    
+    * page/EventHandler.h: Added shouldDispatchEventsToDragSourceElement function and renamed
+    the existing dispatchDragSrcEvent function to dispatchEventToDragSourceElement.
+    
+    * page/EventHandler.cpp:
+    (WebCore::EventHandler::updateDragAndDrop): Call the renamed dispatchEventToDragSourceElement
+    unconditionally, since it now has the smarts to only dispatch an event when we are supposed to.
+    (WebCore::EventHandler::cancelDragAndDrop): Ditto.
+    (WebCore::EventHandler::dragSourceEndedAt): Call the new shouldDispatchEventsToDragSourceElement
+    function because of the null check it does for dataTransfer, before calling setDestinationOperation
+    on the dataTransfer, since there isn't an obvious ironclad guarantee we might be here without an
+    actual drag fully in process and a dataTransfer object allocated. Also call the renamed
+    dispatchEventToDragSourceElement by its new name.
+    (WebCore::EventHandler::shouldDispatchDragSourceEvents): Added. Checks thre three conditions that
+    affect whether we should dispatch events to the drag source. First that there is a drag source.
+    Second that there is a dataTransfer object, indicating that we got far enough in the logic to
+    actually start a drag. Third that shouldDispatchEvents is true, indicating this is the type of
+    drag that should be visible to the website content and so events should be dispatched.
+    (WebCore::EventHandler::dispatchEventToDragSourceElement): Call shouldDispatchDragSourceEvents
+    before dispatching the event, so that callers don't all have to do that check.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@255128 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-01-25  Darin Adler  <[email protected]>
+
+            Tighten up some of the drag state machine logic
+            https://bugs.webkit.org/show_bug.cgi?id=206798
+
+            Reviewed by Wenson Hsieh.
+
+            * page/EventHandler.h: Added shouldDispatchEventsToDragSourceElement function and renamed
+            the existing dispatchDragSrcEvent function to dispatchEventToDragSourceElement.
+
+            * page/EventHandler.cpp:
+            (WebCore::EventHandler::updateDragAndDrop): Call the renamed dispatchEventToDragSourceElement
+            unconditionally, since it now has the smarts to only dispatch an event when we are supposed to.
+            (WebCore::EventHandler::cancelDragAndDrop): Ditto.
+            (WebCore::EventHandler::dragSourceEndedAt): Call the new shouldDispatchEventsToDragSourceElement
+            function because of the null check it does for dataTransfer, before calling setDestinationOperation
+            on the dataTransfer, since there isn't an obvious ironclad guarantee we might be here without an
+            actual drag fully in process and a dataTransfer object allocated. Also call the renamed
+            dispatchEventToDragSourceElement by its new name.
+            (WebCore::EventHandler::shouldDispatchDragSourceEvents): Added. Checks thre three conditions that
+            affect whether we should dispatch events to the drag source. First that there is a drag source.
+            Second that there is a dataTransfer object, indicating that we got far enough in the logic to
+            actually start a drag. Third that shouldDispatchEvents is true, indicating this is the type of
+            drag that should be visible to the website content and so events should be dispatched.
+            (WebCore::EventHandler::dispatchEventToDragSourceElement): Call shouldDispatchDragSourceEvents
+            before dispatching the event, so that callers don't all have to do that check.
+
+2020-01-28  Russell Epstein  <[email protected]>
+
         Cherry-pick r255116. rdar://problem/58800787
 
     HTMLMediaElement should not remove the media session at DOM suspension time

Modified: branches/safari-610.1.1-branch/Source/WebCore/page/EventHandler.cpp (255302 => 255303)


--- branches/safari-610.1.1-branch/Source/WebCore/page/EventHandler.cpp	2020-01-28 21:49:54 UTC (rev 255302)
+++ branches/safari-610.1.1-branch/Source/WebCore/page/EventHandler.cpp	2020-01-28 21:49:57 UTC (rev 255303)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2020 Apple Inc. All rights reserved.
  * Copyright (C) 2006 Alexey Proskuryakov ([email protected])
  * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
  *
@@ -2383,8 +2383,7 @@
                 response = targetFrame->eventHandler().updateDragAndDrop(event, makePasteboard, sourceOperation, draggingFiles);
         } else if (newTarget) {
             // As per section 7.9.4 of the HTML 5 spec., we must always fire a drag event before firing a dragenter, dragleave, or dragover event.
-            if (dragState().source && dragState().shouldDispatchEvents)
-                dispatchDragSrcEvent(eventNames().dragEvent, event);
+            dispatchEventToDragSourceElement(eventNames().dragEvent, event);
             response = dispatchDragEnterOrDragOverEvent(eventNames().dragenterEvent, *newTarget, event, makePasteboard(), sourceOperation, draggingFiles);
         }
 
@@ -2410,8 +2409,8 @@
                 response = targetFrame->eventHandler().updateDragAndDrop(event, makePasteboard, sourceOperation, draggingFiles);
         } else if (newTarget) {
             // Note, when dealing with sub-frames, we may need to fire only a dragover event as a drag event may have been fired earlier.
-            if (!m_shouldOnlyFireDragOverEvent && dragState().source && dragState().shouldDispatchEvents)
-                dispatchDragSrcEvent(eventNames().dragEvent, event);
+            if (!m_shouldOnlyFireDragOverEvent)
+                dispatchEventToDragSourceElement(eventNames().dragEvent, event);
             response = dispatchDragEnterOrDragOverEvent(eventNames().dragoverEvent, *newTarget, event, makePasteboard(), sourceOperation, draggingFiles);
             m_shouldOnlyFireDragOverEvent = false;
         }
@@ -2429,8 +2428,7 @@
         if (targetFrame)
             targetFrame->eventHandler().cancelDragAndDrop(event, WTFMove(pasteboard), sourceOperation, draggingFiles);
     } else if (m_dragTarget) {
-        if (dragState().source && dragState().shouldDispatchEvents)
-            dispatchDragSrcEvent(eventNames().dragEvent, event);
+        dispatchEventToDragSourceElement(eventNames().dragEvent, event);
 
         auto dataTransfer = DataTransfer::createForUpdatingDropTarget(m_dragTarget->document(), WTFMove(pasteboard), sourceOperation, draggingFiles);
         dispatchDragEvent(eventNames().dragleaveEvent, *m_dragTarget, event, dataTransfer.get());
@@ -3651,9 +3649,9 @@
     HitTestRequest request(HitTestRequest::Release | HitTestRequest::DisallowUserAgentShadowContent);
     prepareMouseEvent(request, event);
 
-    if (dragState().source && dragState().shouldDispatchEvents) {
+    if (shouldDispatchEventsToDragSourceElement()) {
         dragState().dataTransfer->setDestinationOperation(operation);
-        dispatchDragSrcEvent(eventNames().dragendEvent, event);
+        dispatchEventToDragSourceElement(eventNames().dragendEvent, event);
     }
     invalidateDataTransfer();
 
@@ -3675,12 +3673,17 @@
         dragState().source = &rootEditableElement;
 }
 
-void EventHandler::dispatchDragSrcEvent(const AtomString& eventType, const PlatformMouseEvent& event)
+bool EventHandler::shouldDispatchEventsToDragSourceElement()
 {
-    ASSERT(dragState().dataTransfer);
-    dispatchDragEvent(eventType, *dragState().source, event, *dragState().dataTransfer);
+    return dragState().source && dragState().dataTransfer && dragState().shouldDispatchEvents;
 }
 
+void EventHandler::dispatchEventToDragSourceElement(const AtomString& eventType, const PlatformMouseEvent& event)
+{
+    if (shouldDispatchEventsToDragSourceElement())
+        dispatchDragEvent(eventType, *dragState().source, event, *dragState().dataTransfer);
+}
+
 bool EventHandler::dispatchDragStartEventOnSourceElement(DataTransfer& dataTransfer)
 {
     return !dispatchDragEvent(eventNames().dragstartEvent, *dragState().source, m_mouseDown, dataTransfer) && !m_frame.selection().selection().isInPasswordField();
@@ -3780,6 +3783,7 @@
     DragOperation srcOp = DragOperationNone;      
     
     // This does work only if we missed a dragEnd. Do it anyway, just to make sure the old dataTransfer gets numbed.
+    // FIXME: Consider doing this earlier in this function as the earliest point we're sure it would be safe to drop an old drag.
     invalidateDataTransfer();
 
     dragState().dataTransfer = DataTransfer::createForDrag();
@@ -3799,7 +3803,7 @@
                 auto delta = m_mouseDownPos - roundedIntPoint(absolutePosition);
                 dragState().dataTransfer->setDragImage(dragState().source.get(), delta.width(), delta.height());
             } else {
-                dispatchDragSrcEvent(eventNames().dragendEvent, event.event());
+                dispatchEventToDragSourceElement(eventNames().dragendEvent, event.event());
                 m_mouseDownMayStartDrag = false;
                 invalidateDataTransfer();
                 dragState().source = nullptr;
@@ -3829,12 +3833,12 @@
             m_mouseDownMayStartDrag = false;
             return true;
         }
-        if (dragState().source && dragState().shouldDispatchEvents) {
+        if (shouldDispatchEventsToDragSourceElement()) {
             // Drag was canned at the last minute. We owe dragSource a dragend event.
-            dispatchDragSrcEvent(eventNames().dragendEvent, event.event());
+            dispatchEventToDragSourceElement(eventNames().dragendEvent, event.event());
             m_mouseDownMayStartDrag = false;
         }
-    } 
+    }
 
     if (!m_mouseDownMayStartDrag) {
         // Something failed to start the drag, clean up.

Modified: branches/safari-610.1.1-branch/Source/WebCore/page/EventHandler.h (255302 => 255303)


--- branches/safari-610.1.1-branch/Source/WebCore/page/EventHandler.h	2020-01-28 21:49:54 UTC (rev 255302)
+++ branches/safari-610.1.1-branch/Source/WebCore/page/EventHandler.h	2020-01-28 21:49:57 UTC (rev 255303)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006-2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -424,7 +424,8 @@
 #if ENABLE(DRAG_SUPPORT)
     void clearDragState();
 
-    void dispatchDragSrcEvent(const AtomString& eventType, const PlatformMouseEvent&);
+    static bool shouldDispatchEventsToDragSourceElement();
+    void dispatchEventToDragSourceElement(const AtomString& eventType, const PlatformMouseEvent&);
     bool dispatchDragStartEventOnSourceElement(DataTransfer&);
 
     bool dragHysteresisExceeded(const FloatPoint&) const;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to