Closed Bug 1957955 Opened 7 months ago Closed 7 months ago

Add a "widget" event synthesization API for wheel events

Categories

(Core :: Panning and Zooming, enhancement, P2)

enhancement
Points:
3

Tracking

()

RESOLVED FIXED
139 Branch
Tracking Status
firefox139 --- fixed

People

(Reporter: whimboo, Assigned: whimboo)

References

(Blocks 1 open bug)

Details

(Whiteboard: [webdriver:m16])

Attachments

(2 files, 1 obsolete file)

This bug tracks introducing an nsIDOMWindowUtils API for synthesizing "widget" wheel events which will be sent to the parent process and go through APZ processing there, but unlike "native" wheel events will not be injected into the operating system's native event queue.

We need this API for bug 1848957 to send widget events via WebDriver.

Priority: -- → P2
Attachment #9477770 - Flags: approval-mozilla-beta?
Attachment #9477770 - Flags: approval-mozilla-beta?

With the changes for DOMWindowUtils and EventUtils (as attached as patch) I tried to update the following test as proposed by Hiro to switch from native events to widget events but I can see different issues with missing events:

  1. Compared to sending a native event the expected events are not always emitted, especially not when we already are at scrollTop == 0
  2. When a scroll is performed (modifying scrollTop before) it doesn't matter if I enable async events or not, scroll and scrollend are always emitted. What would need to change to only emit them with widget events? I thought it's the overscroll, but maybe there is another factor?

Feel free to attach the patch from Phabricator, apply the following changes as well, and run the command:

mach mochitest gfx/layers/apz/test/mochitest/test_group_overscroll_handoff.html

to reproduce.

diff --git a/gfx/layers/apz/test/mochitest/helper_wheelevents_handoff_on_iframe.html b/gfx/layers/apz/test/mochitest/helper_wheelevents_handoff_on_iframe.html
index 79101b2ca5b71..fdeda1178bcd3 100644
--- a/gfx/layers/apz/test/mochitest/helper_wheelevents_handoff_on_iframe.html
+++ b/gfx/layers/apz/test/mochitest/helper_wheelevents_handoff_on_iframe.html
@@ -1,48 +1,81 @@
 <head>
   <meta name="viewport" content="width=device-width; initial-scale=1.0">
   <title>Test that wheel events on an unscrollable OOP iframe are handoff-ed</title>
   <script src="apz_test_native_event_utils.js"></script>
   <script src="apz_test_utils.js"></script>
+  <script src="/tests/SimpleTest/EventUtils.js"></script>
   <script src="/tests/SimpleTest/paint_listener.js"></script>
   <style>
   iframe {
     height: 201px;
     border: none;
   }
   </style>
 </head>
 <body>
   <div id="iframe-container" style="overflow-y: scroll; height: 200px;">
     <iframe src="https://example.com/tests/gfx/layers/apz/test/mochitest/helper_wheelevents_handoff_on_iframe_child.html"></iframe>
   </div>
   <div style="height: 200vh;"></div>
   <script type="application/javascript">
 async function test() {
+  function waitForEvent(target, type) {
+    return new Promise(resolve => {
+      target.addEventListener(type, e => {
+        info(`Received "${e.type}" event for ${e.target}`);
+        resolve();
+      }, { once: true });
+    });
+  }
+
   const scrollContainer = document.querySelector("#iframe-container");
-  let scrollEventPromise = waitForScrollEvent(scrollContainer);
+
+  // Issue: Without setting the scroll position first, negative scrolling starting
+  // with scrollTop == 0 doesn't emit any events.
+  scrollContainer.scrollTop = 10;
+
+  let scrollEventPromise = waitForEvent(scrollContainer, "scroll");
+  let scrollendEventPromise = waitForEvent(scrollContainer, "scrollend");
+  let wheelEventPromise = waitForEvent(scrollContainer, "wheel");
 
   // Send a wheel event on the iframe.
   const iframe = document.querySelector("iframe");
-  await synthesizeNativeWheel(iframe, 50, 50, 0, -50);
+
+  const event = {
+    deltaY: -50,
+    asyncEnabled: true,
+  };
+  synthesizeWheel(iframe, 50, 50, event);
+  // await synthesizeNativeWheel(iframe, 50, 50, 0, -50);
+
   await scrollEventPromise;
+  await scrollendEventPromise;
+  await wheelEventPromise; // not emitted
 
   // The wheel event should be handoff-ed to the parent scroll container.
   is(scrollContainer.scrollTop, scrollContainer.scrollTopMax,
      "The scroll position in the parent scroll container should be at the bottom");
 
   // Make sure the wheel event wasn't handoff-ed to the root scroller.
   is(window.scrollY, 0, "The root scroll position should be 0");
 
   await promiseFrame();
   scrollEventPromise = waitForScrollEvent(window);
+
   // Send a wheel event on the iframe again.
-  await synthesizeNativeWheel(iframe, 50, 50, 0, -50);
+  synthesizeWheel(iframe, 50, 50, event);
+  // await synthesizeNativeWheel(iframe, 50, 50, 0, -50);
+
+  // None of the following events are emitted because we are already scrolled
+  // to the top.
   await scrollEventPromise;
+  await scrollendEventPromise;
+  await wheelEventPromise;
 
   // Now it should be handoff-ed to the root scroller.
   ok(window.scrollY > 0,
      "The wheel event should have been handoff-ed to the root scroller");
 }
 
 waitUntilApzStable()
 .then(test)
Attachment #9477770 - Attachment is obsolete: true

There's a confusing difference between synthesizeNativeWheel and synthesizeWheel. The delta direction is opposite direction.

I tried the modified test locally with setting "test.events.async.enabled=true" and with changing the deltaY to 50, the test works.

(In reply to Henrik Skupin [:whimboo][⌚️UTC+2] from comment #2)

With the changes for DOMWindowUtils and EventUtils (as attached as patch) I tried to update the following test as proposed by Hiro to switch from native events to widget events but I can see different issues with missing events:

  1. Compared to sending a native event the expected events are not always emitted, especially not when we already are at scrollTop == 0

You don't need this change with the positive deltaY.

Attachment #9477953 - Attachment description: Bug 1957955 - [apz] Use widget events instead of native events for wheel event handoff mochitests. → Bug 1957955 - [apz] Use widget events instead of native events for helper_wheelevents_handoff_on_iframe.html.
Points: --- → 3
Whiteboard: [webdriver:m16]
Pushed by hskupin@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/4be24e8d9463 [dom] Add support for widget-level wheel (scroll) events to WindowUtils. r=hiro https://hg.mozilla.org/integration/autoland/rev/408e73e86a0d [apz] Use widget events instead of native events for helper_wheelevents_handoff_on_iframe.html. r=hiro
Status: ASSIGNED → RESOLVED
Closed: 7 months ago
Resolution: --- → FIXED
Target Milestone: --- → 139 Branch
QA Whiteboard: [qa-triage-done-c140/b139]
See Also: → 1968855
See Also: → 1957531
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: