From 779da2993ed63c6e8353def6acc18522b3017d0f Mon Sep 17 00:00:00 2001 From: Karl Tomlinson Date: Tue, 17 Apr 2012 13:00:26 +1200 Subject: [PATCH] b=497498 split drag event dispatch code from GTK signal handling methods r=roc --HG-- extra : rebase_source : f8d7a93c9ca2f11fdc46587585aec6fb0bcfd091 --- widget/gtk2/nsWindow.cpp | 58 ++++++++++++++++++++++++---------------- widget/gtk2/nsWindow.h | 7 +++++ 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/widget/gtk2/nsWindow.cpp b/widget/gtk2/nsWindow.cpp index bac7729c839..f54bc193770 100644 --- a/widget/gtk2/nsWindow.cpp +++ b/widget/gtk2/nsWindow.cpp @@ -3323,6 +3323,37 @@ nsWindow::CheckNeedDragLeave(nsWindow* aInnerMostWidget, sLastDragMotionWindow = aInnerMostWidget; } +void +nsWindow::DispatchDragMotionEvents(nsDragService *aDragService, + const nsIntPoint& aWindowPoint, guint aTime) +{ + aDragService->SetCanDrop(false); + + aDragService->FireDragEventAtSource(NS_DRAGDROP_DRAG); + + DispatchDragEvent(NS_DRAGDROP_OVER, aWindowPoint, aTime); +} + +// Returns true if the drop was successful +gboolean +nsWindow::DispatchDragDropEvent(nsDragService *aDragService, + const nsIntPoint& aWindowPoint, guint aTime) +{ + // We need to check mIsDestroyed here because the nsRefPtr + // only protects this from being deleted, it does NOT protect + // against nsView::~nsView() calling Destroy() on it, bug 378670. + if (mIsDestroyed) + return FALSE; + + bool canDrop; + aDragService->GetCanDrop(&canDrop); + PRUint32 msg = canDrop ? NS_DRAGDROP_DROP : NS_DRAGDROP_EXIT; + + DispatchDragEvent(msg, aWindowPoint, aTime); + + return canDrop; +} + void nsWindow::DispatchDragEvent(PRUint32 aMsg, const nsIntPoint& aRefPoint, guint aTime) @@ -3398,12 +3429,8 @@ nsWindow::OnDragMotionEvent(GtkWidget *aWidget, // update the drag context dragServiceGTK->TargetSetLastContext(aWidget, aDragContext, aTime); - dragServiceGTK->SetCanDrop(false); - - dragService->FireDragEventAtSource(NS_DRAGDROP_DRAG); - innerMostWidget-> - DispatchDragEvent(NS_DRAGDROP_OVER, nsIntPoint(retx, rety), aTime); + DispatchDragMotionEvents(dragServiceGTK, nsIntPoint(retx, rety), aTime); // Reply to tell the source whether we can drop and what action would be // taken. @@ -3502,27 +3529,12 @@ nsWindow::OnDragDropEvent(GtkWidget *aWidget, // protocol is used. dragServiceGTK->TargetSetLastContext(aWidget, aDragContext, aTime); - dragServiceGTK->SetCanDrop(false); - - dragService->FireDragEventAtSource(NS_DRAGDROP_DRAG); innerMostWidget-> - DispatchDragEvent(NS_DRAGDROP_OVER, nsIntPoint(retx, rety), aTime); + DispatchDragMotionEvents(dragServiceGTK, 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; - - innerMostWidget->DispatchDragEvent(msg, nsIntPoint(retx, rety), aTime); - - success = canDrop; - } + gboolean success = innerMostWidget-> + DispatchDragDropEvent(dragServiceGTK, nsIntPoint(retx, rety), aTime); // before we unset the context we need to do a drop_finish diff --git a/widget/gtk2/nsWindow.h b/widget/gtk2/nsWindow.h index abea8fdaa58..2be47bcffa8 100644 --- a/widget/gtk2/nsWindow.h +++ b/widget/gtk2/nsWindow.h @@ -95,6 +95,7 @@ extern PRLogModuleInfo *gWidgetDrawLog; #endif /* MOZ_LOGGING */ +class nsDragService; #if defined(MOZ_X11) && defined(MOZ_HAVE_SHAREDMEMORYSYSV) # define MOZ_HAVE_SHMIMAGE @@ -318,6 +319,12 @@ public: void DispatchDragEvent(PRUint32 aMsg, const nsIntPoint& aRefPoint, guint aTime); + void DispatchDragMotionEvents(nsDragService *aDragService, + const nsIntPoint& aPoint, + guint aTime); + gboolean DispatchDragDropEvent(nsDragService *aDragService, + const nsIntPoint& aWindowPoint, + guint aTime); // If this dispatched the keydown event actually, this returns TRUE, // otherwise, FALSE. bool DispatchKeyDownEvent(GdkEventKey *aEvent,