Bläddra i källkod

LibWeb: Implement the "top-level traversable" of a browsing context

Andreas Kling 2 år sedan
förälder
incheckning
6871fbce9f

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

@@ -21,6 +21,7 @@
 #include <LibWeb/HTML/RemoteBrowsingContext.h>
 #include <LibWeb/HTML/RemoteBrowsingContext.h>
 #include <LibWeb/HTML/SandboxingFlagSet.h>
 #include <LibWeb/HTML/SandboxingFlagSet.h>
 #include <LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h>
 #include <LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h>
+#include <LibWeb/HTML/TraversableNavigable.h>
 #include <LibWeb/HTML/Window.h>
 #include <LibWeb/HTML/Window.h>
 #include <LibWeb/HTML/WindowProxy.h>
 #include <LibWeb/HTML/WindowProxy.h>
 #include <LibWeb/HighResolutionTime/TimeOrigin.h>
 #include <LibWeb/HighResolutionTime/TimeOrigin.h>
@@ -290,6 +291,16 @@ void BrowsingContext::visit_edges(Cell::Visitor& visitor)
     visitor.visit(m_previous_sibling);
     visitor.visit(m_previous_sibling);
 }
 }
 
 
+// https://html.spec.whatwg.org/multipage/document-sequences.html#bc-traversable
+JS::NonnullGCPtr<HTML::TraversableNavigable> BrowsingContext::top_level_traversable() const
+{
+    // A browsing context's top-level traversable is its active document's node navigable's top-level traversable.
+    auto traversable = active_document()->navigable()->top_level_traversable();
+    VERIFY(traversable);
+    VERIFY(traversable->is_top_level_traversable());
+    return *traversable;
+}
+
 void BrowsingContext::did_edit(Badge<EditEventHandler>)
 void BrowsingContext::did_edit(Badge<EditEventHandler>)
 {
 {
     reset_cursor_blink_cycle();
     reset_cursor_blink_cycle();

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

@@ -42,6 +42,8 @@ public:
 
 
     virtual ~BrowsingContext() override;
     virtual ~BrowsingContext() override;
 
 
+    JS::NonnullGCPtr<HTML::TraversableNavigable> top_level_traversable() const;
+
     JS::GCPtr<BrowsingContext> parent() const { return m_parent; }
     JS::GCPtr<BrowsingContext> parent() const { return m_parent; }
     void append_child(JS::NonnullGCPtr<BrowsingContext>);
     void append_child(JS::NonnullGCPtr<BrowsingContext>);
     void remove_child(JS::NonnullGCPtr<BrowsingContext>);
     void remove_child(JS::NonnullGCPtr<BrowsingContext>);