b=497498 use a helper method for dispatching destination drag events r=roc
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 17 Apr 2012 13:00:25 +1200
changeset 91817 93a7a0655014286756c8691e6a3cbe4882b33534
parent 91816 8bea9978c445a4a6dac7f2d05796e113746ce863
child 91818 7f5e0ef6ad589a7adf8ca866246f4e1ab3a8f060
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersroc
bugs497498
milestone14.0a1
b=497498 use a helper method for dispatching destination drag events r=roc
widget/gtk2/nsWindow.cpp
widget/gtk2/nsWindow.h
--- a/widget/gtk2/nsWindow.cpp
+++ b/widget/gtk2/nsWindow.cpp
@@ -3318,16 +3318,33 @@ nsWindow::CheckNeedDragLeave(nsWindow* a
 
     // update our drag status
     UpdateDragStatus(aDragContext, aDragService);
 
     // set the last window to the innerMostWidget
     sLastDragMotionWindow = aInnerMostWidget;
 }
 
+void
+nsWindow::DispatchDragEvent(PRUint32 aMsg, const nsIntPoint& aRefPoint,
+                            guint aTime)
+{
+    nsDragEvent event(true, aMsg, this);
+
+    if (aMsg == NS_DRAGDROP_OVER) {
+        InitDragEvent(event);
+    }
+
+    event.refPoint = aRefPoint;
+    event.time = aTime;
+
+    nsEventStatus status;
+    DispatchEvent(&event, status);
+}
+
 gboolean
 nsWindow::OnDragMotionEvent(GtkWidget *aWidget,
                             GdkDragContext *aDragContext,
                             gint aX,
                             gint aY,
                             guint aTime,
                             gpointer aData)
 {
@@ -3380,26 +3397,18 @@ nsWindow::OnDragMotionEvent(GtkWidget *a
 
     // update the drag context
     dragServiceGTK->TargetSetLastContext(aWidget, aDragContext, aTime);
 
     dragServiceGTK->SetCanDrop(false);
 
     dragService->FireDragEventAtSource(NS_DRAGDROP_DRAG);
 
-    nsDragEvent event(true, NS_DRAGDROP_OVER, innerMostWidget);
-
-    InitDragEvent(event);
-
-    event.refPoint.x = retx;
-    event.refPoint.y = rety;
-    event.time = aTime;
-
-    nsEventStatus status;
-    innerMostWidget->DispatchEvent(&event, status);
+    innerMostWidget->
+        DispatchDragEvent(NS_DRAGDROP_OVER, nsIntPoint(retx, rety), aTime);
 
     // Reply to tell the source whether we can drop and what action would be
     // taken.
     dragServiceGTK->TargetEndDragMotion(aWidget, aDragContext, aTime);
 
     // and unset our context
     dragServiceGTK->TargetSetLastContext(0, 0, 0);
 
@@ -3492,42 +3501,30 @@ nsWindow::OnDragDropEvent(GtkWidget *aWi
     // contain a position.  However, we can't assume the same when the Motif
     // protocol is used.
 
     dragServiceGTK->TargetSetLastContext(aWidget, aDragContext, aTime);
     dragServiceGTK->SetCanDrop(false);
 
     dragService->FireDragEventAtSource(NS_DRAGDROP_DRAG);
 
-    nsDragEvent event(true, NS_DRAGDROP_OVER, innerMostWidget);
-
-    InitDragEvent(event);
-
-    event.refPoint.x = retx;
-    event.refPoint.y = rety;
-    event.time = aTime;
-
-    nsEventStatus status;
-    innerMostWidget->DispatchEvent(&event, status);
+    innerMostWidget->
+        DispatchDragEvent(NS_DRAGDROP_OVER, nsIntPoint(retx, rety), aTime);
 
     gboolean success = FALSE;
 
     // We need to check innerMostWidget->mIsDestroyed here because the nsRefPtr
     // only protects innerMostWidget from being deleted, it does NOT protect
     // against nsView::~nsView() calling Destroy() on it, bug 378670.
     if (!innerMostWidget->mIsDestroyed) {
         bool canDrop;
         dragServiceGTK->GetCanDrop(&canDrop);
         PRUint32 msg = canDrop ? NS_DRAGDROP_DROP : NS_DRAGDROP_EXIT;
-        nsDragEvent event(true, msg, innerMostWidget);
-        event.refPoint.x = retx;
-        event.refPoint.y = rety;
-
-        nsEventStatus status = nsEventStatus_eIgnore;
-        innerMostWidget->DispatchEvent(&event, status);
+
+        innerMostWidget->DispatchDragEvent(msg, nsIntPoint(retx, rety), aTime);
 
         success = canDrop;
     }
 
     // before we unset the context we need to do a drop_finish
 
     gdk_drop_finish(aDragContext, success, aTime);
 
@@ -3567,20 +3564,17 @@ nsWindow::OnDragDataReceivedEvent(GtkWid
                                        aSelectionData, aInfo, aTime);
 }
 
 void
 nsWindow::OnDragLeave(void)
 {
     LOGDRAG(("nsWindow::OnDragLeave(%p)\n", (void*)this));
 
-    nsDragEvent event(true, NS_DRAGDROP_EXIT, this);
-
-    nsEventStatus status;
-    DispatchEvent(&event, status);
+    DispatchDragEvent(NS_DRAGDROP_EXIT, nsIntPoint(0, 0), 0);
 
     nsCOMPtr<nsIDragService> dragService = do_GetService(kCDragServiceCID);
 
     if (dragService) {
         nsCOMPtr<nsIDragSession> currentDragSession;
         dragService->GetCurrentSession(getter_AddRefs(currentDragSession));
 
         if (currentDragSession) {
--- a/widget/gtk2/nsWindow.h
+++ b/widget/gtk2/nsWindow.h
@@ -310,16 +310,19 @@ public:
 
     NS_IMETHOD         BeginResizeDrag(nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVertical);
     NS_IMETHOD         BeginMoveDrag(nsMouseEvent* aEvent);
 
     MozContainer*      GetMozContainer() { return mContainer; }
     GdkWindow*         GetGdkWindow() { return mGdkWindow; }
     bool               IsDestroyed() { return mIsDestroyed; }
 
+    void               DispatchDragEvent(PRUint32 aMsg,
+                                         const nsIntPoint& aRefPoint,
+                                         guint aTime);
     // If this dispatched the keydown event actually, this returns TRUE,
     // otherwise, FALSE.
     bool               DispatchKeyDownEvent(GdkEventKey *aEvent,
                                             bool *aIsCancelled);
 
     NS_IMETHOD ResetInputState();
     NS_IMETHOD_(void) SetInputContext(const InputContext& aContext,
                                       const InputContextAction& aAction);