Bug 1452131, properly end the drag session when the drag is aborted, for example if the mouse is released before the child process starts the drag, r=nika a=lizzard
authorNeil Deakin <neil@mozilla.com>
Thu, 02 Aug 2018 09:50:20 -0400
changeset 478480 13ded90ac6289617c00ca79e1fc7fd62e3865cf4
parent 478479 d810601eca84f079b8159a5fe55d467ca6566ffd
child 478481 cfe8e60f9e0a1a9987c085f513ae409d5399a99a
push id9685
push userrgurzau@mozilla.com
push dateSun, 19 Aug 2018 07:13:08 +0000
treeherdermozilla-beta@37110fa0b0b1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnika, lizzard
bugs1452131
milestone62.0
Bug 1452131, properly end the drag session when the drag is aborted, for example if the mouse is released before the child process starts the drag, r=nika a=lizzard
widget/nsBaseDragService.cpp
--- a/widget/nsBaseDragService.cpp
+++ b/widget/nsBaseDragService.cpp
@@ -255,19 +255,20 @@ nsBaseDragService::InvokeDragSession(nsI
   // feedback for things like trees because the event coordinates
   // are in the wrong coord system, so turn off mouse capture.
   nsIPresShell::ClearMouseCapture(nullptr);
 
   nsresult rv = InvokeDragSessionImpl(aTransferableArray,
                                       aDragRgn, aActionType);
 
   if (NS_FAILED(rv)) {
-    mSourceNode = nullptr;
-    mTriggeringPrincipalURISpec.Truncate(0);
-    mSourceDocument = nullptr;
+    // Set mDoingDrag so that EndDragSession cleans up and sends the dragend event
+    // after the aborted drag.
+    mDoingDrag = true;
+    EndDragSession(true, 0);
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsBaseDragService::InvokeDragSessionWithImage(nsINode* aDOMNode,
                                               const nsACString& aPrincipalURISpec,
@@ -289,28 +290,20 @@ nsBaseDragService::InvokeDragSessionWith
   mDragPopup = nullptr;
   mImage = aImage;
   mImageOffset = CSSIntPoint(aImageX, aImageY);
 
   mScreenPosition.x = aDragEvent->ScreenX(CallerType::System);
   mScreenPosition.y = aDragEvent->ScreenY(CallerType::System);
   mInputSource = aDragEvent->MozInputSource();
 
-  nsresult rv = InvokeDragSession(aDOMNode, aPrincipalURISpec,
-                                  aTransferableArray,
-                                  aRegion, aActionType,
-                                  nsIContentPolicy::TYPE_INTERNAL_IMAGE);
-
-  if (NS_FAILED(rv)) {
-    mImage = nullptr;
-    mHasImage = false;
-    mDataTransfer = nullptr;
-  }
-
-  return rv;
+  return InvokeDragSession(aDOMNode, aPrincipalURISpec,
+                           aTransferableArray,
+                           aRegion, aActionType,
+                           nsIContentPolicy::TYPE_INTERNAL_IMAGE);
 }
 
 NS_IMETHODIMP
 nsBaseDragService::InvokeDragSessionWithSelection(Selection* aSelection,
                                                   const nsACString& aPrincipalURISpec,
                                                   nsIArray* aTransferableArray,
                                                   uint32_t aActionType,
                                                   DragEvent* aDragEvent,
@@ -331,28 +324,20 @@ nsBaseDragService::InvokeDragSessionWith
   mScreenPosition.y = aDragEvent->ScreenY(CallerType::System);
   mInputSource = aDragEvent->MozInputSource();
 
   // just get the focused node from the selection
   // XXXndeakin this should actually be the deepest node that contains both
   // endpoints of the selection
   nsCOMPtr<nsINode> node = aSelection->GetFocusNode();
 
-  nsresult rv = InvokeDragSession(node, aPrincipalURISpec,
-                                  aTransferableArray,
-                                  nullptr, aActionType,
-                                  nsIContentPolicy::TYPE_OTHER);
-
-  if (NS_FAILED(rv)) {
-    mHasImage = false;
-    mSelection = nullptr;
-    mDataTransfer = nullptr;
-  }
-
-  return rv;
+  return InvokeDragSession(node, aPrincipalURISpec,
+                           aTransferableArray,
+                           nullptr, aActionType,
+                           nsIContentPolicy::TYPE_OTHER);
 }
 
 //-------------------------------------------------------------------------
 NS_IMETHODIMP
 nsBaseDragService::GetCurrentSession(nsIDragSession ** aSession)
 {
   if (!aSession)
     return NS_ERROR_INVALID_ARG;