Skip to content

Truly independent web browser

LibWeb: Update layout before the DevTools picker’s hit test

sideshowbarker0ccf83121e45
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h
index bbb27674262..be1fc905627 100644
--- a/Libraries/LibWeb/DOM/Document.h
+++ b/Libraries/LibWeb/DOM/Document.h
@@ -191,6 +191,7 @@ enum class InvalidateLayoutTreeReason {
X(EventHandlerPointerCaptureEvents, false) \
X(EventHandlerRunActivationBehavior, false) \
X(EventHandlerShowContextMenu, false) \
+ X(EventHandlerTargetNodeAtPosition, false) \
X(FontFaceSetReady, false) \
X(HTMLElementGetTheTextSteps, false) \
X(HTMLElementOffsetHeight, true) \
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp
index d64ac6b6ae2..2a5940a53d0 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -3496,6 +3496,14 @@ Optional<EventHandler::Target> EventHandler::target_for_mouse_position(CSSPixelP
GC::Ptr<DOM::Node> EventHandler::target_node_for_mouse_position(CSSPixelPoint position)
{
+ // NB: A hit test records the document again where its display list isn't current, and recording reads layout, so
+ // bring layout up to date first, as the mouse handlers do.
+ if (auto document = m_navigable->active_document()) {
+ document->update_layout(DOM::UpdateLayoutReason::EventHandlerTargetNodeAtPosition);
+ if (!has_committed_root_box())
+ return {};
+ }
+
auto target = target_for_mouse_position(position);
if (!target.has_value())
return {};