Skip to content

Truly independent web browser

LibWeb: Record hit-test display lists with the frames' paint config

Aliaksandr Kalenike1e18e1f1986
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index a0cea17a132..96a59b0f116 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -10559,10 +10559,14 @@ Optional<Painting::HitTestQuery> Document::prepare_hit_test_query(Layout::BegunR
// A hit test only reads a recording of the document as it is now: it presents nothing, so the compositor never
// shows a frame a hit test made in place of one the render clock sampled later. The next frame records again.
+ // It copies from the published recording only where it records with the paint config the frames record with.
auto rebuild_hit_test_display_list = [&] {
set_needs_to_record_display_list();
+ HTML::PaintConfig paint_config { .paint_overlay = true };
+ if (auto navigable = this->navigable())
+ paint_config = navigable->stamp_paint_config(paint_config);
Compositing::DisplayListResourceStorage throwaway_resource_storage_for_hit_test_only_recording;
- (void)record_display_list(read, HTML::PaintConfig { .paint_overlay = true }, throwaway_resource_storage_for_hit_test_only_recording, Painting::PaintCommandCacheMode::ReadOnly);
+ (void)record_display_list(read, paint_config, throwaway_resource_storage_for_hit_test_only_recording, Painting::PaintCommandCacheMode::ReadOnly);
};
// The paint properties were prepared above, and a query reads them as they were left there: preparing them again
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.h
index 8c3886bf598..d91c68d3525 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.h
+++ b/Libraries/LibWeb/HTML/LocalNavigable.h
@@ -367,6 +367,7 @@ public:
bool active_document_opts_out_of_force_dark() const;
bool force_dark_applies_to_active_document() const;
bool force_dark_enabled() const { return m_force_dark_enabled; }
+ PaintConfig stamp_paint_config(PaintConfig) const;
void set_should_show_caret_hit_test_debug_overlay(bool);
bool should_show_caret_hit_test_debug_overlay() const { return m_should_show_caret_hit_test_debug_overlay; }
@@ -446,7 +447,6 @@ private:
// A rendering update's recording that flies beside the event loop, with what its frame is finished with.
struct RecordingInFlight;
- PaintConfig stamp_paint_config(PaintConfig) const;
Compositor::FlightPresentation take_presentation(Compositor::SealedPresentation);
void commit_unrecorded_frame(Layout::BegunRead const&, DOM::Document&, Compositor::SealedPresentation);
Compositor::SealedPresentation seal_presentation(DOM::Document&, PaintConfig const&, bool records_display_list);
diff --git a/Tests/LibWeb/Text/expected/display_list/hit-test-recording-with-force-dark-copies-from-published-recording.txt b/Tests/LibWeb/Text/expected/display_list/hit-test-recording-with-force-dark-copies-from-published-recording.txt
new file mode 100644
index 00000000000..44f6b2e5396
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/display_list/hit-test-recording-with-force-dark-copies-from-published-recording.txt
@@ -0,0 +1,2 @@
+hit target: box
+hit-test recording: @viewport ASSEMBLE
diff --git a/Tests/LibWeb/Text/input/display_list/hit-test-recording-with-force-dark-copies-from-published-recording.html b/Tests/LibWeb/Text/input/display_list/hit-test-recording-with-force-dark-copies-from-published-recording.html
new file mode 100644
index 00000000000..8ee9b97193b
--- /dev/null
+++ b/Tests/LibWeb/Text/input/display_list/hit-test-recording-with-force-dark-copies-from-published-recording.html
@@ -0,0 +1,26 @@
+<!doctype html>
+<script src="../include.js"></script>
+<style>
+ body { margin: 0; }
+ #box { position: absolute; left: 10px; top: 60px; width: 50px; height: 50px; background: green; }
+</style>
+<div id="box"></div>
+<script>
+// The frames record with the navigable's paint config, which has force dark on here. A hit test records with the same
+// config, so it still copies from the frame published last instead of recording the whole page.
+promiseTest(async () => {
+ const nextFrame = () => new Promise(resolve => requestAnimationFrame(resolve));
+ internals.setForceDarkEnabled(true);
+ await nextFrame();
+ await nextFrame();
+
+ box.style.left = "100px";
+ internals.beginDisplayListTrace();
+ const target = document.elementFromPoint(120, 80);
+ const viewportWork = internals.takeDisplayListTrace().split("\n").find(line => line.startsWith("@viewport "));
+ internals.setForceDarkEnabled(false);
+
+ println(`hit target: ${target.id}`);
+ println(`hit-test recording: ${viewportWork}`);
+});
+</script>