Bug 707623 - gtk_grab_add(mShell) instead of (mContainer) to avoid double key event dispatch r=roc, feedback=mconley.
authorKarl Tomlinson <karlt@mozbugz.karlt.net>
Tue, 30 Oct 2012 11:49:10 -0400
changeset 111911 33df4d95396a669565f7e9bc2543cf69bc9892a8
parent 111910 e0cf397089ec879a15c170cbf1a100892d5727d6
child 111912 72003517a631a301a57a60f22ae356490d781c4b
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersroc
bugs707623
milestone19.0a1
Bug 707623 - gtk_grab_add(mShell) instead of (mContainer) to avoid double key event dispatch r=roc, feedback=mconley.
widget/gtk2/nsWindow.cpp
--- a/widget/gtk2/nsWindow.cpp
+++ b/widget/gtk2/nsWindow.cpp
@@ -1809,61 +1809,64 @@ nsWindow::EnableDragDrop(bool aEnable)
 NS_IMETHODIMP
 nsWindow::CaptureMouse(bool aCapture)
 {
     LOG(("CaptureMouse %p\n", (void *)this));
 
     if (!mGdkWindow)
         return NS_OK;
 
-    GtkWidget *widget = GetMozContainerWidget();
-    if (!widget)
+    if (!mShell)
         return NS_ERROR_FAILURE;
 
     if (aCapture) {
-        gtk_grab_add(widget);
+        gtk_grab_add(mShell);
         GrabPointer(GetLastUserInputTime());
     }
     else {
         ReleaseGrabs();
-        gtk_grab_remove(widget);
+        gtk_grab_remove(mShell);
     }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindow::CaptureRollupEvents(nsIRollupListener *aListener,
                               bool               aDoCapture)
 {
     if (!mGdkWindow)
         return NS_OK;
 
-    GtkWidget *widget = GetMozContainerWidget();
-    if (!widget)
+    if (!mShell)
         return NS_ERROR_FAILURE;
 
     LOG(("CaptureRollupEvents %p\n", (void *)this));
 
     if (aDoCapture) {
         gRollupListener = aListener;
         // real grab is only done when there is no dragging
         if (!nsWindow::DragInProgress()) {
-            gtk_grab_add(widget);
+            // This widget grab ensures that a Gecko GtkWidget receives mouse
+            // events even when embedded in non-Gecko-owned GtkWidgets.
+            // The grab is placed on the toplevel GtkWindow instead of the
+            // MozContainer to avoid double dispatch of keyboard events
+            // (bug 707623).
+            gtk_grab_add(mShell);
             GrabPointer(GetLastUserInputTime());
         }
     }
     else {
         if (!nsWindow::DragInProgress()) {
             ReleaseGrabs();
         }
         // There may not have been a drag in process when aDoCapture was set,
         // so make sure to remove any added grab.  This is a no-op if the grab
         // was not added to this widget.
-        gtk_grab_remove(widget);
+        gtk_grab_remove(mShell);
         gRollupListener = nullptr;
     }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindow::GetAttention(int32_t aCycleCount)