From 97616fa108cd9246657eb200ac836d2fa319f71e Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 7 Jan 2025 15:16:07 +0000 Subject: [PATCH] LibWeb/DOM: Move "stop intersection observing..." code into a method We'll need to call it from elsewhere. Also add a missing step 5 from where we previously called it. --- Libraries/LibWeb/DOM/Document.cpp | 24 ++++++++++++++++-------- Libraries/LibWeb/DOM/Document.h | 1 + 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index b6a2d1fff4c..feaf8926109 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -4542,15 +4542,10 @@ void Document::start_intersection_observing_a_lazy_loading_element(Element& elem } // 4. Stop intersection-observing a lazy loading element for entry.target. - // https://html.spec.whatwg.org/multipage/urls-and-fetching.html#stop-intersection-observing-a-lazy-loading-element - // 1. Let doc be element's node document. - // NOTE: It's `this`. + stop_intersection_observing_a_lazy_loading_element(entry.target()); - // 2. Assert: doc's lazy load intersection observer is not null. - VERIFY(m_lazy_load_intersection_observer); - - // 3. Call doc's lazy load intersection observer unobserve method with element as the argument. - m_lazy_load_intersection_observer->unobserve(entry.target()); + // 5. Set entry.target's lazy load resumption steps to null. + entry.target()->take_lazy_load_resumption_steps({}); // 6. Invoke resumptionSteps. resumption_steps->function()(); @@ -4572,6 +4567,19 @@ void Document::start_intersection_observing_a_lazy_loading_element(Element& elem m_lazy_load_intersection_observer->observe(element); } +// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#stop-intersection-observing-a-lazy-loading-element +void Document::stop_intersection_observing_a_lazy_loading_element(Element& element) +{ + // 1. Let doc be element's node document. + // NOTE: It's `this`. + + // 2. Assert: doc's lazy load intersection observer is not null. + VERIFY(m_lazy_load_intersection_observer); + + // 3. Call doc's lazy load intersection observer unobserve method with element as the argument. + m_lazy_load_intersection_observer->unobserve(element); +} + // https://html.spec.whatwg.org/multipage/semantics.html#shared-declarative-refresh-steps void Document::shared_declarative_refresh_steps(StringView input, GC::Ptr meta_element) { diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index 7fa45d62ef1..9d08415c4f8 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -613,6 +613,7 @@ public: void run_the_update_intersection_observations_steps(HighResolutionTime::DOMHighResTimeStamp time); void start_intersection_observing_a_lazy_loading_element(Element&); + void stop_intersection_observing_a_lazy_loading_element(Element&); void shared_declarative_refresh_steps(StringView input, GC::Ptr meta_element = nullptr);