From 8addfc14af8129664ba6ef11913b8a8d8cc4711f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 23 Feb 2024 20:50:19 +0100 Subject: [PATCH] LibWeb: Implement IntersectionObserver "intersection roots" per spec In particular, get the implicit root correctly for intersection observers that don't have an explicit root specified. This makes it possible to load the Terminal app on https://puter.com/ --- ...r-originating-iframe-is-removed-from-dom.txt | 1 + ...-originating-iframe-is-removed-from-dom.html | 17 +++++++++++++++++ .../IntersectionObserver.cpp | 12 +++++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/IntersectionObserver/implicit-root-after-originating-iframe-is-removed-from-dom.txt create mode 100644 Tests/LibWeb/Text/input/IntersectionObserver/implicit-root-after-originating-iframe-is-removed-from-dom.html diff --git a/Tests/LibWeb/Text/expected/IntersectionObserver/implicit-root-after-originating-iframe-is-removed-from-dom.txt b/Tests/LibWeb/Text/expected/IntersectionObserver/implicit-root-after-originating-iframe-is-removed-from-dom.txt new file mode 100644 index 0000000000..af663e86b6 --- /dev/null +++ b/Tests/LibWeb/Text/expected/IntersectionObserver/implicit-root-after-originating-iframe-is-removed-from-dom.txt @@ -0,0 +1 @@ + PASS if we didn't crash! diff --git a/Tests/LibWeb/Text/input/IntersectionObserver/implicit-root-after-originating-iframe-is-removed-from-dom.html b/Tests/LibWeb/Text/input/IntersectionObserver/implicit-root-after-originating-iframe-is-removed-from-dom.html new file mode 100644 index 0000000000..417a1d3136 --- /dev/null +++ b/Tests/LibWeb/Text/input/IntersectionObserver/implicit-root-after-originating-iframe-is-removed-from-dom.html @@ -0,0 +1,17 @@ + + + + + diff --git a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp index 29d29c6f0d..28e4c73367 100644 --- a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp +++ b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace Web::IntersectionObserver { @@ -156,11 +157,16 @@ Variant, JS::Handle, Empty> Intersection return m_root.value(); } +// https://www.w3.org/TR/intersection-observer/#intersectionobserver-intersection-root Variant, JS::Handle> IntersectionObserver::intersection_root() const { - if (!m_root.has_value()) - return JS::make_handle(global_object().navigable()->traversable_navigable()->active_document()); - return m_root.value(); + // The intersection root for an IntersectionObserver is the value of its root attribute + // if the attribute is non-null; + if (m_root.has_value()) + return m_root.value(); + + // otherwise, it is the top-level browsing context’s document node, referred to as the implicit root. + return JS::make_handle(global_object().page().top_level_browsing_context().active_document()); } // https://www.w3.org/TR/intersection-observer/#intersectionobserver-root-intersection-rectangle