Skip to content

Truly independent web browser

LibWeb: Keep dispatching latched wheel events that started over text

Aliaksandr Kalenik351421f1b6f2
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp
index 8e155831052..1626b396681 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -2926,6 +2926,9 @@ Layout::Node* EventHandler::validated_wheel_scroll_latch_target_layout_node(Layo
else if (auto* element = as_if<DOM::Element>(*target))
layout_node = element->pseudo_element_layout_node(read, *pseudo_element);
}
+ // A hit on text is a hit on the text's parent, which has the paintable row that events are dispatched from.
+ if (layout_node && layout_node->is_text_node())
+ layout_node = layout_node->parent();
if (!layout_node)
m_wheel_scroll_latch.clear();
return layout_node;
diff --git a/Tests/LibWeb/Text/expected/wheel-latch-over-text-keeps-dispatching-and-scrolling.txt b/Tests/LibWeb/Text/expected/wheel-latch-over-text-keeps-dispatching-and-scrolling.txt
new file mode 100644
index 00000000000..722d035290e
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wheel-latch-over-text-keeps-dispatching-and-scrolling.txt
@@ -0,0 +1,2 @@
+wheel event targets: SPAN,SPAN,SPAN,SPAN
+scroller.scrollTop: 30
diff --git a/Tests/LibWeb/Text/input/wheel-latch-over-text-keeps-dispatching-and-scrolling.html b/Tests/LibWeb/Text/input/wheel-latch-over-text-keeps-dispatching-and-scrolling.html
new file mode 100644
index 00000000000..32f19a8bd76
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wheel-latch-over-text-keeps-dispatching-and-scrolling.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<style>
+ body {
+ margin: 0;
+ }
+ #scroller {
+ width: 300px;
+ height: 200px;
+ overflow: auto;
+ font: 20px/30px sans-serif;
+ }
+</style>
+<div id="scroller"></div>
+<script>
+ for (let i = 0; i < 60; i++) {
+ const line = document.createElement("div");
+ line.innerHTML = `<span>Line ${i}</span>`;
+ scroller.appendChild(line);
+ }
+
+ promiseTest(async () => {
+ const targets = [];
+ // A blocking wheel event listener keeps the scrolling of these gestures on the main thread.
+ scroller.addEventListener("wheel", event => targets.push(event.target.tagName), { passive: false });
+ await animationFrame();
+ await animationFrame();
+
+ // Every step of a gesture that starts over text goes to the element around the text and scrolls the scroller.
+ for (let step = 0; step < 3; step++)
+ await internals.wheel(15, 15, 0, 10, true, "ongoing");
+ await internals.wheel(15, 15, 0, 0, true, "ended");
+
+ println(`wheel event targets: ${targets.join(",")}`);
+ println(`scroller.scrollTop: ${scroller.scrollTop}`);
+ });
+</script>