From fd8809073dfba97f974535fff53021d3ca08c745 Mon Sep 17 00:00:00 2001 From: "blizzard%redhat.com" Date: Wed, 7 Feb 2001 04:16:20 +0000 Subject: [PATCH] Fix bug #16766. This should fix the requirement to release the mouse before context menus work. r=pavlov, sr=blizzard. Patch from Kevin Buhr . Thanks. --- widget/src/gtk/nsWidget.cpp | 25 +++---------------------- widget/src/gtk/nsWidget.h | 4 +++- widget/src/gtk/nsWindow.cpp | 11 ++++++++++- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/widget/src/gtk/nsWidget.cpp b/widget/src/gtk/nsWidget.cpp index 1485734da30f..5db9c10bd1ac 100644 --- a/widget/src/gtk/nsWidget.cpp +++ b/widget/src/gtk/nsWidget.cpp @@ -118,18 +118,6 @@ void nsWidget::GetLastEventTime(guint32 *aTime) *aTime = sLastEventTime; } -void nsWidget::DragStarted(void) -{ - if (sButtonMotionTarget) - { - sButtonMotionTarget = nsnull; - sButtonMotionRootX = -1; - sButtonMotionRootY = -1; - sButtonMotionWidgetX = -1; - sButtonMotionWidgetY = -1; - } -} - #ifdef USE_XIM nsresult nsWidget::KillICSpotTimer () { @@ -409,7 +397,7 @@ NS_IMETHODIMP nsWidget::Destroy(void) // we don't want people sending us events if we are the button motion target if (sButtonMotionTarget == this) - sButtonMotionTarget = nsnull; + DropMotionTarget(); // ok, set our state mIsDestroying = PR_TRUE; @@ -1757,7 +1745,7 @@ nsWidget::OnEnterNotifySignal(GdkEventCrossing * aGdkCrossingEvent) // // XXX ramiro - Same as above. // - if (sButtonMotionTarget) + if (nsnull != sButtonMotionTarget) { return; } @@ -2051,14 +2039,7 @@ nsWidget::OnButtonReleaseSignal(GdkEventButton * aGdkButtonEvent) theWidget->DispatchMouseEvent(event); NS_IF_RELEASE(theWidget); - - if (sButtonMotionTarget) - { - sButtonMotionTarget = nsnull; - - sButtonMotionRootX = -1; - sButtonMotionRootY = -1; - } + DropMotionTarget(); } ////////////////////////////////////////////////////////////////////// /* virtual */ void diff --git a/widget/src/gtk/nsWidget.h b/widget/src/gtk/nsWidget.h index 76862325a0c5..22bbf794eb15 100644 --- a/widget/src/gtk/nsWidget.h +++ b/widget/src/gtk/nsWidget.h @@ -206,9 +206,11 @@ public: static void SetLastEventTime(guint32 aTime); static void GetLastEventTime(guint32 *aTime); + static void DropMotionTarget(void) { sButtonMotionTarget = nsnull; }; + // inform the widget code that we are about to do a drag - it must // release the sButtonMotionTarget if it is set. - static void DragStarted(void); + static void DragStarted(void) { DropMotionTarget(); }; protected: diff --git a/widget/src/gtk/nsWindow.cpp b/widget/src/gtk/nsWindow.cpp index 4bf8c09565ff..a352bb9a95e3 100644 --- a/widget/src/gtk/nsWindow.cpp +++ b/widget/src/gtk/nsWindow.cpp @@ -821,6 +821,7 @@ void nsWindow::NativeGrab(PRBool aGrab) if (aGrab) { GdkCursor *cursor = gdk_cursor_new (GDK_ARROW); + DropMotionTarget(); gint retval; retval = gdk_pointer_grab (GDK_SUPERWIN(mSuperWin)->bin_window, PR_TRUE,(GdkEventMask) (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | @@ -853,6 +854,7 @@ void nsWindow::NativeGrab(PRBool aGrab) printf("nsWindow::NativeGrab %p ungrab\n", this); #endif gdk_keyboard_ungrab(GDK_CURRENT_TIME); + DropMotionTarget(); gdk_pointer_ungrab(GDK_CURRENT_TIME); } } @@ -2421,7 +2423,13 @@ NS_IMETHODIMP nsWindow::CaptureMouse(PRBool aCapture) if (aCapture) { + if (!grabWidget) { + g_print("nsWindow::CaptureMouse on NULL grabWidget\n"); + return NS_ERROR_FAILURE; + } + GdkCursor *cursor = gdk_cursor_new (GDK_ARROW); + DropMotionTarget(); gdk_pointer_grab (GTK_WIDGET(grabWidget)->window, PR_TRUE,(GdkEventMask) (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | @@ -2432,8 +2440,9 @@ NS_IMETHODIMP nsWindow::CaptureMouse(PRBool aCapture) } else { + DropMotionTarget(); gdk_pointer_ungrab(GDK_CURRENT_TIME); - gtk_grab_remove(grabWidget); + if (grabWidget) gtk_grab_remove(grabWidget); } return NS_OK;