Skip to content

Truly independent web browser

LibWeb: Don’t hold hovers back for a scroll of a replaced document

sideshowbarker6ecdb35ef4f8
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index c713ac849bc..76bbf116af3 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -6268,9 +6268,25 @@ void LocalNavigable::schedule_hover_update_after_async_scroll()
m_async_scroll_hover_update_timer->restart(AK::Duration::from_milliseconds(hover_update_after_async_scroll_delay_ms));
}
+static bool async_scroll_node_is_in_document(DOM::Document& document, Web::AsyncScrollNodeStableID const& stable_id)
+{
+ if (stable_id.kind == Web::AsyncScrollNodeKind::Viewport || stable_id.kind == Web::AsyncScrollNodeKind::VisualViewport)
+ return stable_id.node_id == document.unique_id();
+ return element_for_async_scroll_node_stable_id(document, stable_id) != nullptr;
+}
+
bool LocalNavigable::leave_hover_update_to_end_of_user_scroll()
{
- if (!any_of(m_pending_async_scroll_operations, [](auto const& pending) { return pending.trigger == ScrollTrigger::UserInput; }))
+ // A user's scroll of a document this navigable no longer shows may never be reported as ended, since its scroll
+ // node is gone: It holds back no hover of the active document.
+ auto document = active_document();
+ if (!document)
+ return false;
+ if (!any_of(m_pending_async_scroll_operations, [&](auto const& pending) {
+ if (pending.trigger != ScrollTrigger::UserInput)
+ return false;
+ return !pending.stable_node_id.has_value() || async_scroll_node_is_in_document(*document, *pending.stable_node_id);
+ }))
return false;
schedule_hover_update_after_async_scroll();
return true;
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-follows-a-document-that-replaced-one-mid-scroll.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-follows-a-document-that-replaced-one-mid-scroll.txt
new file mode 100644
index 00000000000..2c78f7a6203
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-follows-a-document-that-replaced-one-mid-scroll.txt
@@ -0,0 +1,2 @@
+at rest: Arrow
+the target transformed under the pointer: Hand
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-follows-a-document-that-replaced-one-mid-scroll.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-follows-a-document-that-replaced-one-mid-scroll.html
new file mode 100644
index 00000000000..55393da93a5
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-follows-a-document-that-replaced-one-mid-scroll.html
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<style>
+ body { margin: 0; }
+ iframe { display: block; width: 300px; height: 200px; border: 0; }
+</style>
+<iframe id="frame"></iframe>
+<script>
+ // A wheel gesture over the frame ends with a snap the compositor scrolls, and the frame's document is replaced before
+ // the snap reports its end. The snap's scroll node went with that document, so the user's scroll holds back no hover
+ // of the document that replaced it: The cursor follows a box moved under the pointer at rest.
+ asyncTest(async done => {
+ const snapping = "<style>html { scroll-snap-type: y mandatory; } body { margin: 0; } div { height: 300px; scroll-snap-align: start; }</style><div></div><div></div><div></div><div></div>";
+ const hovering = "<style>body { margin: 0; } #target { cursor: pointer; position: absolute; left: 150px; top: 0; width: 100px; height: 100px; }</style><div id=target></div>";
+ let loaded = new Promise(resolve => frame.addEventListener("load", resolve, { once: true }));
+ frame.srcdoc = snapping;
+ await loaded;
+ await animationFrame();
+ await animationFrame();
+ await internals.wheelThroughUIProcess(50, 50, 0, 0, true, "ongoing");
+ for (let step = 0; step < 3; step++)
+ await internals.wheelThroughUIProcess(50, 50, 0, 50, true, "ongoing");
+ await internals.wheelThroughUIProcess(50, 50, 0, 0, true, "ended");
+ loaded = new Promise(resolve => frame.addEventListener("load", resolve, { once: true }));
+ frame.srcdoc = hovering;
+ await loaded;
+ const target = frame.contentDocument.getElementById("target");
+ await whileLaneHovers(async frameTime => {
+ internals.mouseMove(50, 50);
+ let time = frameTime;
+ const lines = [];
+ const step = async change => {
+ change();
+ time += 16;
+ internals.injectRenderingOpportunity(time);
+ await untilLaneSettled();
+ await nextTask();
+ };
+ lines.push(`at rest: ${internals.currentCursor()}`);
+ await step(() => target.style.transform = "translateX(-150px)");
+ lines.push(`the target transformed under the pointer: ${internals.currentCursor()}`);
+ println(lines.join("\n"));
+ }, [document, frame.contentDocument]);
+ done();
+ });
+</script>