Bug 1399956 - Support synthesized scroll events. r=jrmuizel
authorBrendan Dahl <brendan.dahl@gmail.com>
Thu, 21 Sep 2017 14:56:40 -0700
changeset 386574 d3484a545375ad44317e2d5afa6e757898328d68
parent 386573 d41de10195a075ee501738cb09246438b0bfaea9
child 386575 a031371ca87e0f4e04159f173bb2baecd60226c9
push id32695
push userarchaeopteryx@coole-files.de
push dateTue, 17 Oct 2017 09:45:44 +0000
treeherdermozilla-central@0d9c6250f99d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1399956, 1151667
milestone58.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 1399956 - Support synthesized scroll events. r=jrmuizel Fixes test_bug1151667.html MozReview-Commit-ID: 8lCHNTA8zIL
widget/headless/HeadlessWidget.cpp
widget/headless/HeadlessWidget.h
--- a/widget/headless/HeadlessWidget.cpp
+++ b/widget/headless/HeadlessWidget.cpp
@@ -472,10 +472,35 @@ HeadlessWidget::SynthesizeNativeMouseEve
   if (msg == eMouseDown) {
     event.mClickCount = 1;
   }
   event.AssignEventTime(WidgetEventTime());
   DispatchInputEvent(&event);
   return NS_OK;
 }
 
+nsresult
+HeadlessWidget::SynthesizeNativeMouseScrollEvent(mozilla::LayoutDeviceIntPoint aPoint,
+                                                 uint32_t aNativeMessage,
+                                                 double aDeltaX,
+                                                 double aDeltaY,
+                                                 double aDeltaZ,
+                                                 uint32_t aModifierFlags,
+                                                 uint32_t aAdditionalFlags,
+                                                 nsIObserver* aObserver)
+{
+  AutoObserverNotifier notifier(aObserver, "mousescrollevent");
+  // The various platforms seem to handle scrolling deltas differently,
+  // but the following seems to emulate it well enough.
+  WidgetWheelEvent event(true, eWheel, this);
+  event.mDeltaMode = nsIDOMWheelEvent::DOM_DELTA_LINE;
+  event.mIsNoLineOrPageDelta = true;
+  event.mDeltaX = -aDeltaX * MOZ_HEADLESS_SCROLL_MULTIPLIER;
+  event.mDeltaY = -aDeltaY * MOZ_HEADLESS_SCROLL_MULTIPLIER;
+  event.mDeltaZ = -aDeltaZ * MOZ_HEADLESS_SCROLL_MULTIPLIER;
+  event.mRefPoint = aPoint - WidgetToScreenOffset();
+  event.AssignEventTime(WidgetEventTime());
+  DispatchInputEvent(&event);
+  return NS_OK;
+}
+
 } // namespace widget
 } // namespace mozilla
--- a/widget/headless/HeadlessWidget.h
+++ b/widget/headless/HeadlessWidget.h
@@ -12,32 +12,37 @@
 #include "CompositorWidget.h"
 
 // The various synthesized event values are hardcoded to avoid pulling
 // in the platform specific widget code.
 #if defined(MOZ_WIDGET_GTK)
 #define MOZ_HEADLESS_MOUSE_MOVE 3 // GDK_MOTION_NOTIFY
 #define MOZ_HEADLESS_MOUSE_DOWN 4 // GDK_BUTTON_PRESS
 #define MOZ_HEADLESS_MOUSE_UP   7 // GDK_BUTTON_RELEASE
+#define MOZ_HEADLESS_SCROLL_MULTIPLIER 3
 #elif defined(XP_WIN)
 #define MOZ_HEADLESS_MOUSE_MOVE 1 // MOUSEEVENTF_MOVE
 #define MOZ_HEADLESS_MOUSE_DOWN 2 // MOUSEEVENTF_LEFTDOWN
 #define MOZ_HEADLESS_MOUSE_UP   4 // MOUSEEVENTF_LEFTUP
+#define MOZ_HEADLESS_SCROLL_MULTIPLIER 1
 #elif defined(XP_MACOSX)
 #define MOZ_HEADLESS_MOUSE_MOVE 5 // NSMouseMoved
 #define MOZ_HEADLESS_MOUSE_DOWN 1 // NSLeftMouseDown
 #define MOZ_HEADLESS_MOUSE_UP   2 // NSLeftMouseUp
+#define MOZ_HEADLESS_SCROLL_MULTIPLIER 1
 #elif defined(ANDROID)
 #define MOZ_HEADLESS_MOUSE_MOVE 7 // ACTION_HOVER_MOVE
 #define MOZ_HEADLESS_MOUSE_DOWN 5 // ACTION_POINTER_DOWN
 #define MOZ_HEADLESS_MOUSE_UP   6 // ACTION_POINTER_UP
+#define MOZ_HEADLESS_SCROLL_MULTIPLIER 1
 #else
 #define MOZ_HEADLESS_MOUSE_MOVE -1
 #define MOZ_HEADLESS_MOUSE_DOWN -1
 #define MOZ_HEADLESS_MOUSE_UP   -1
+#define MOZ_HEADLESS_SCROLL_MULTIPLIER = -1
 #endif
 
 namespace mozilla {
 namespace widget {
 
 class HeadlessWidget : public nsBaseWidget
 {
 public:
@@ -119,16 +124,25 @@ public:
   virtual nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
                                               uint32_t aNativeMessage,
                                               uint32_t aModifierFlags,
                                               nsIObserver* aObserver) override;
   virtual nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
                                              nsIObserver* aObserver) override
                    { return SynthesizeNativeMouseEvent(aPoint, MOZ_HEADLESS_MOUSE_MOVE, 0, aObserver); };
 
+  virtual nsresult SynthesizeNativeMouseScrollEvent(LayoutDeviceIntPoint aPoint,
+                                                    uint32_t aNativeMessage,
+                                                    double aDeltaX,
+                                                    double aDeltaY,
+                                                    double aDeltaZ,
+                                                    uint32_t aModifierFlags,
+                                                    uint32_t aAdditionalFlags,
+                                                    nsIObserver* aObserver) override;
+
 private:
   ~HeadlessWidget();
   bool mEnabled;
   bool mVisible;
   bool mDestroyed;
   nsIWidget* mTopLevel;
   HeadlessCompositorWidget* mCompositorWidget;
   // The size mode before entering fullscreen mode.