Bug 894876 - part 1 - Add support for GDK_BUTTON_RELEASE in nsWindow::SynthesizeNativeMouseEvent(); r=karlt
authorTim Taubert <ttaubert@mozilla.com>
Wed, 24 Jul 2013 09:58:50 +0200
changeset 152061 105fa6fdce3054aa951b3774f7f175654707e298
parent 152060 0a2cc86d61b79c3d7f1708600165d85f0c9b1fdf
child 152062 c089c7694bb4c6d4eb5c5ebc019407d04747e4b2
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs894876
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 894876 - part 1 - Add support for GDK_BUTTON_RELEASE in nsWindow::SynthesizeNativeMouseEvent(); r=karlt
widget/gtk2/nsWindow.cpp
--- a/widget/gtk2/nsWindow.cpp
+++ b/widget/gtk2/nsWindow.cpp
@@ -6214,13 +6214,39 @@ nsWindow::SynthesizeNativeMouseEvent(nsI
                                      uint32_t aNativeMessage,
                                      uint32_t aModifierFlags)
 {
   if (!mGdkWindow) {
     return NS_OK;
   }
 
   GdkDisplay* display = gdk_window_get_display(mGdkWindow);
-  GdkScreen* screen = gdk_window_get_screen(mGdkWindow);
-  gdk_display_warp_pointer(display, screen, aPoint.x, aPoint.y);
+
+  // When a button-release event is requested, create it here and put it in the
+  // event queue. This will not emit a motion event - this needs to be done
+  // explicitly *before* requesting a button-release. You will also need to wait
+  // for the motion event to be dispatched before requesting a button-release
+  // event to maintain the desired event order.
+  if (aNativeMessage == GDK_BUTTON_RELEASE) {
+    GdkEvent event;
+    memset(&event, 0, sizeof(GdkEvent));
+    event.type = (GdkEventType)aNativeMessage;
+    event.button.button = 1;
+    event.button.window = mGdkWindow;
+    event.button.time = GDK_CURRENT_TIME;
+
+#if (MOZ_WIDGET_GTK == 3)
+    // Get device for event source
+    GdkDeviceManager *device_manager = gdk_display_get_device_manager(display);
+    event.button.device = gdk_device_manager_get_client_pointer(device_manager);
+#endif
+
+    gdk_event_put(&event);
+  } else {
+    // We don't support specific events other than button-release. In case
+    // aNativeMessage != GDK_BUTTON_RELEASE we'll synthesize a motion event
+    // that will be emitted by gdk_display_warp_pointer().
+    GdkScreen* screen = gdk_window_get_screen(mGdkWindow);
+    gdk_display_warp_pointer(display, screen, aPoint.x, aPoint.y);
+  }
 
   return NS_OK;
 }