From cb405c773bb6e87f7f6207af527957f11eb94434 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Wed, 5 Feb 2025 23:37:21 +0000 Subject: [PATCH] LibWeb: Ensure inert elements are not visible for hit testing --- Libraries/LibWeb/Painting/Paintable.cpp | 11 +++++ Libraries/LibWeb/Painting/Paintable.h | 2 +- .../wpt-import/inert/inert-computed-style.txt | 6 +++ .../inert/inert-computed-style.html | 49 +++++++++++++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/inert/inert-computed-style.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/inert/inert-computed-style.html diff --git a/Libraries/LibWeb/Painting/Paintable.cpp b/Libraries/LibWeb/Painting/Paintable.cpp index b2ccfae76a7..53100a3abe5 100644 --- a/Libraries/LibWeb/Painting/Paintable.cpp +++ b/Libraries/LibWeb/Painting/Paintable.cpp @@ -83,6 +83,17 @@ CSS::ImmutableComputedValues const& Paintable::computed_values() const return m_layout_node->computed_values(); } +bool Paintable::visible_for_hit_testing() const +{ + // https://html.spec.whatwg.org/multipage/interaction.html#inert-subtrees + // When a node is inert: + // - Hit-testing must act as if the 'pointer-events' CSS property were set to 'none'. + if (auto dom_node = this->dom_node(); dom_node && dom_node->is_inert()) + return false; + + return computed_values().pointer_events() != CSS::PointerEvents::None; +} + void Paintable::set_dom_node(GC::Ptr dom_node) { m_dom_node = dom_node; diff --git a/Libraries/LibWeb/Painting/Paintable.h b/Libraries/LibWeb/Painting/Paintable.h index b7387d837c3..33af6bcda0f 100644 --- a/Libraries/LibWeb/Painting/Paintable.h +++ b/Libraries/LibWeb/Painting/Paintable.h @@ -109,7 +109,7 @@ public: CSS::ImmutableComputedValues const& computed_values() const; - bool visible_for_hit_testing() const { return computed_values().pointer_events() != CSS::PointerEvents::None; } + bool visible_for_hit_testing() const; GC::Ptr navigable() const; diff --git a/Tests/LibWeb/Text/expected/wpt-import/inert/inert-computed-style.txt b/Tests/LibWeb/Text/expected/wpt-import/inert/inert-computed-style.txt new file mode 100644 index 00000000000..8b2576b9c8e --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/inert/inert-computed-style.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass inert isn't hit-testable, but that isn't expose in the computed style \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/inert/inert-computed-style.html b/Tests/LibWeb/Text/input/wpt-import/inert/inert-computed-style.html new file mode 100644 index 00000000000..018e16812c7 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/inert/inert-computed-style.html @@ -0,0 +1,49 @@ + + +inert isn't hit-testable, but that isn't expose in the computed style + + + + + +
+
+