Parcourir la source

LibWeb: Move has_a_rendering_opportunity() to Navigable

Andreas Kling il y a 1 an
Parent
commit
93e4a0de16

+ 0 - 10
Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp

@@ -466,16 +466,6 @@ bool BrowsingContext::decrement_cursor_position_offset()
     return true;
 }
 
-// https://html.spec.whatwg.org/#rendering-opportunity
-bool BrowsingContext::has_a_rendering_opportunity() const
-{
-    // A browsing context has a rendering opportunity if the user agent is currently able to present the contents of the browsing context to the user,
-    // accounting for hardware refresh rate constraints and user agent throttling for performance reasons, but considering content presentable even if it's outside the viewport.
-
-    // FIXME: We should at the very least say `false` here if we're an inactive browser tab.
-    return true;
-}
-
 // https://html.spec.whatwg.org/multipage/interaction.html#currently-focused-area-of-a-top-level-browsing-context
 JS::GCPtr<DOM::Node> BrowsingContext::currently_focused_area()
 {

+ 0 - 2
Userland/Libraries/LibWeb/HTML/BrowsingContext.h

@@ -170,8 +170,6 @@ public:
 
     void did_edit(Badge<EditEventHandler>);
 
-    bool has_a_rendering_opportunity() const;
-
     JS::GCPtr<DOM::Node> currently_focused_area();
 
     Vector<JS::NonnullGCPtr<SessionHistoryEntry>>& session_history() { return m_session_history; }

+ 2 - 2
Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp

@@ -145,9 +145,9 @@ void EventLoop::process()
         }
     };
 
-    // 2. Rendering opportunities: Remove from docs all Document objects whose browsing context do not have a rendering opportunity.
+    // 2. Rendering opportunities: Remove from docs all Document objects whose node navigables do not have a rendering opportunity.
     docs.remove_all_matching([&](auto& document) {
-        return document->browsing_context() && !document->browsing_context()->has_a_rendering_opportunity();
+        return document->navigable() && !document->navigable()->has_a_rendering_opportunity();
     });
 
     // 3. If docs is not empty, then set hasARenderingOpportunity to true

+ 19 - 0
Userland/Libraries/LibWeb/HTML/Navigable.cpp

@@ -1652,4 +1652,23 @@ void Navigable::set_needs_display(CSSPixelRect const& rect)
         container()->layout_node()->set_needs_display();
 }
 
+// https://html.spec.whatwg.org/#rendering-opportunity
+bool Navigable::has_a_rendering_opportunity() const
+{
+    // A navigable has a rendering opportunity if the user agent is currently able to present
+    // the contents of the navigable to the user,
+    // accounting for hardware refresh rate constraints and user agent throttling for performance reasons,
+    // but considering content presentable even if it's outside the viewport.
+
+    // A navigable has no rendering opportunities if its active document is render-blocked
+    // or if it is suppressed for view transitions;
+    // otherwise, rendering opportunities are determined based on hardware constraints
+    // such as display refresh rates and other factors such as page performance
+    // or whether the document's visibility state is "visible".
+    // Rendering opportunities typically occur at regular intervals.
+
+    // FIXME: We should at the very least say `false` here if we're an inactive browser tab.
+    return true;
+}
+
 }

+ 3 - 0
Userland/Libraries/LibWeb/HTML/Navigable.h

@@ -151,6 +151,9 @@ public:
 
     void set_is_popup(TokenizedFeature::Popup is_popup) { m_is_popup = is_popup; }
 
+    // https://html.spec.whatwg.org/#rendering-opportunity
+    [[nodiscard]] bool has_a_rendering_opportunity() const;
+
 protected:
     Navigable();