Skip to content

Truly independent web browser

LibWeb: Invalidate wheel listener state only for the listening document

Aliaksandr Kalenik11c4b8e95c3d
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h
index a861dfcb0eb..e524b6b26e5 100644
--- a/Libraries/LibWeb/DOM/Document.h
+++ b/Libraries/LibWeb/DOM/Document.h
@@ -1369,6 +1369,9 @@ public:
// state has to be derived when they move.
void set_may_have_blocking_wheel_event_listener() { m_may_have_blocking_wheel_event_listener = true; }
[[nodiscard]] bool may_have_blocking_wheel_event_listener() const { return m_may_have_blocking_wheel_event_listener; }
+ // The page's wheel event listener state generation at the newest change to this document's blocking listeners.
+ u64 wheel_event_listener_state_generation() const { return m_wheel_event_listener_state_generation; }
+ void set_wheel_event_listener_state_generation(u64 generation) { m_wheel_event_listener_state_generation = generation; }
// Whether a node in this document has ever published a paint fact. It never goes back to false:
// a node that lost its last fact still has to publish that it did.
@@ -2225,6 +2228,7 @@ private:
bool m_requested_wanted_font_faces { false };
bool m_may_have_scroll_snap_areas { false };
bool m_may_have_blocking_wheel_event_listener { false };
+ u64 m_wheel_event_listener_state_generation { 0 };
bool m_may_have_dom_paint_facts { false };
HashTable<GC::Ref<Element>> m_list_owners_pending_item_renumber;
diff --git a/Libraries/LibWeb/DOM/EventTarget.cpp b/Libraries/LibWeb/DOM/EventTarget.cpp
index c22b08932e2..5d5ac566923 100644
--- a/Libraries/LibWeb/DOM/EventTarget.cpp
+++ b/Libraries/LibWeb/DOM/EventTarget.cpp
@@ -301,7 +301,7 @@ static void invalidate_compositor_wheel_event_listener_state(EventTarget& event_
if (auto* window = as_if<HTML::Window>(event_target)) {
auto& document = window->associated_document();
document.set_needs_to_record_display_list();
- document.page().invalidate_compositor_wheel_event_listener_state();
+ document.page().invalidate_compositor_wheel_event_listener_state(document);
return;
}
@@ -311,7 +311,7 @@ static void invalidate_compositor_wheel_event_listener_state(EventTarget& event_
node->document().set_may_have_blocking_wheel_event_listener();
node->update_inside_blocking_wheel_event_handler_state_for_subtree();
node->set_needs_repaint();
- node->document().page().invalidate_compositor_wheel_event_listener_state();
+ node->document().page().invalidate_compositor_wheel_event_listener_state(node->document());
}
}
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index b340df63352..b8baa4ad097 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -1448,7 +1448,7 @@ static Optional<RecordedScrollTree> recorded_scroll_tree_of(DOM::Document& docum
.admission = {},
};
auto async_scrolling_state = Compositing::async_scrolling_state_from_display_list(*display_list);
- recorded.admission = Compositing::wheel_routing_admission_for(async_scrolling_state, document.page().wheel_event_listener_state_generation());
+ recorded.admission = Compositing::wheel_routing_admission_for(async_scrolling_state, document.wheel_event_listener_state_generation());
recorded.scroll_tree.set_state(move(async_scrolling_state));
recorded.scroll_tree.rebuild_wheel_hit_test_targets(display_list, &recorded.visual_context_tree, document.scroll_state_snapshot());
return recorded;
diff --git a/Libraries/LibWeb/Page/Page.cpp b/Libraries/LibWeb/Page/Page.cpp
index 2ae355c3d94..e91f1be78b1 100644
--- a/Libraries/LibWeb/Page/Page.cpp
+++ b/Libraries/LibWeb/Page/Page.cpp
@@ -661,14 +661,15 @@ Compositing::KeyboardScrollState Page::take_keyboard_scroll_state_for_compositor
return state;
}
-void Page::invalidate_compositor_wheel_event_listener_state()
+// A document's listeners only see the wheel events over that document, so they only hold back the wheel steps of its own
+// navigable's context.
+void Page::invalidate_compositor_wheel_event_listener_state(DOM::Document& document)
{
++m_wheel_event_listener_state_generation;
+ document.set_wheel_event_listener_state_generation(m_wheel_event_listener_state_generation);
- for (auto const& navigable : hosted_navigables()) {
- if (navigable->has_compositor_context())
- navigable->compositor_context().invalidate_wheel_event_listener_state(m_wheel_event_listener_state_generation);
- }
+ if (auto navigable = document.navigable(); navigable && navigable->has_compositor_context())
+ navigable->compositor_context().invalidate_wheel_event_listener_state(m_wheel_event_listener_state_generation);
}
void Page::update_needs_beforeunload_check()
diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h
index 5bf1a864864..91847b3a022 100644
--- a/Libraries/LibWeb/Page/Page.h
+++ b/Libraries/LibWeb/Page/Page.h
@@ -242,7 +242,7 @@ public:
u64 wheel_event_listener_state_generation() const { return m_wheel_event_listener_state_generation; }
u64 keyboard_scroll_state_generation() const { return m_keyboard_scroll_state_generation; }
- void invalidate_compositor_wheel_event_listener_state();
+ void invalidate_compositor_wheel_event_listener_state(DOM::Document&);
void invalidate_compositor_keyboard_scroll_state();
void invalidate_compositor_keyboard_scroll_state_for_document(DOM::Document const&);
void keyboard_scroll_event_path_changed(DOM::EventTarget const&);