Parcourir la source

LibWeb: Move system visibility state to TraversableNavigable

This no longer belongs in BrowsingContext.
Andreas Kling il y a 1 an
Parent
commit
38cb15ff49

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

@@ -776,35 +776,6 @@ bool BrowsingContext::document_family_contains(DOM::Document const& document) co
     return document_family().first_matching([&](auto& entry) { return entry.ptr() == &document; }).has_value();
 }
 
-VisibilityState BrowsingContext::system_visibility_state() const
-{
-    return m_system_visibility_state;
-}
-
-// https://html.spec.whatwg.org/multipage/interaction.html#system-visibility-state
-void BrowsingContext::set_system_visibility_state(VisibilityState visibility_state)
-{
-    if (m_system_visibility_state == visibility_state)
-        return;
-    m_system_visibility_state = visibility_state;
-
-    // When a user-agent determines that the system visibility state for top-level browsing context context
-    // has changed to newState, it must queue a task on the user interaction task source to update
-    // the visibility state of all the Document objects in the top-level browsing context's document family with newState.
-    auto document_family = top_level_browsing_context()->document_family();
-
-    // From the new navigable version, where it tells us what global object to use here:
-    // 1. Let document be navigable's active document.
-    // 2. Queue a global task on the user interaction task source given document's relevant global object to update the visibility state of document with newState.
-    // FIXME: Update this function to fully match the navigable version.
-    VERIFY(active_document());
-    queue_global_task(Task::Source::UserInteraction, relevant_global_object(*active_document()), [visibility_state, document_family = move(document_family)] {
-        for (auto& document : document_family) {
-            document->update_the_visibility_state(visibility_state);
-        }
-    });
-}
-
 void BrowsingContext::append_child(JS::NonnullGCPtr<BrowsingContext> child)
 {
     VERIFY(!child->m_parent);

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

@@ -194,9 +194,6 @@ public:
     Vector<JS::Handle<DOM::Document>> document_family() const;
     bool document_family_contains(DOM::Document const&) const;
 
-    VisibilityState system_visibility_state() const;
-    void set_system_visibility_state(VisibilityState);
-
     bool has_been_discarded() const { return m_has_been_discarded; }
 
     Optional<AK::URL> const& creator_url() const { return m_creator_url; }
@@ -253,9 +250,6 @@ private:
     // https://html.spec.whatwg.org/multipage/browsers.html#tlbc-group
     JS::GCPtr<BrowsingContextGroup> m_group;
 
-    // https://html.spec.whatwg.org/multipage/interaction.html#system-visibility-state
-    VisibilityState m_system_visibility_state { VisibilityState::Hidden };
-
     JS::GCPtr<BrowsingContext> m_parent;
     JS::GCPtr<BrowsingContext> m_first_child;
     JS::GCPtr<BrowsingContext> m_last_child;

+ 3 - 2
Userland/Libraries/LibWeb/HTML/Focus.cpp

@@ -13,6 +13,7 @@
 #include <LibWeb/DOM/Element.h>
 #include <LibWeb/DOM/ShadowRoot.h>
 #include <LibWeb/HTML/Focus.h>
+#include <LibWeb/HTML/TraversableNavigable.h>
 #include <LibWeb/UIEvents/FocusEvent.h>
 
 namespace Web::HTML {
@@ -257,8 +258,8 @@ void run_unfocusing_steps(DOM::Node* old_focus_target)
     // 7. Let topDocument be old chain's last entry.
     auto* top_document = verify_cast<DOM::Document>(old_chain.last().ptr());
 
-    // 8. If topDocument's browsing context has system focus, then run the focusing steps for topDocument's viewport.
-    if (top_document->browsing_context()->system_visibility_state() == HTML::VisibilityState::Visible) {
+    // 8. If topDocument's node navigable has system focus, then run the focusing steps for topDocument's viewport.
+    if (top_document->navigable()->traversable_navigable()->system_visibility_state() == HTML::VisibilityState::Visible) {
         // FIXME: run the focusing steps for topDocument's viewport (??)
     } else {
         // FIXME: Otherwise, apply any relevant platform-specific conventions for removing system focus from

+ 29 - 0
Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp

@@ -635,4 +635,33 @@ void finalize_a_same_document_navigation(JS::NonnullGCPtr<TraversableNavigable>
     traversable->apply_the_push_or_replace_history_step(*target_step);
 }
 
+// https://html.spec.whatwg.org/multipage/interaction.html#system-visibility-state
+void TraversableNavigable::set_system_visibility_state(VisibilityState visibility_state)
+{
+    if (m_system_visibility_state == visibility_state)
+        return;
+    m_system_visibility_state = visibility_state;
+
+    // When a user-agent determines that the system visibility state for
+    // traversable navigable traversable has changed to newState, it must run the following steps:
+
+    // 1. Let navigables be the inclusive descendant navigables of traversable.
+    // FIXME: Spec bug: https://github.com/whatwg/html/issues/9758
+    VERIFY(active_document());
+    auto navigables = active_document()->inclusive_descendant_navigables();
+
+    // 2. For each navigable of navigables:
+    for (auto& navigable : navigables) {
+        // 1. Let document be navigable's active document.
+        auto document = navigable->active_document();
+        VERIFY(document);
+
+        // 2. Queue a global task on the user interaction task source given document's relevant global object
+        //    to update the visibility state of document with newState.
+        queue_global_task(Task::Source::UserInteraction, relevant_global_object(*document), [visibility_state, document] {
+            document->update_the_visibility_state(visibility_state);
+        });
+    }
+}
+
 }

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

@@ -29,7 +29,9 @@ public:
     Vector<JS::NonnullGCPtr<SessionHistoryEntry>>& session_history_entries() { return m_session_history_entries; }
     Vector<JS::NonnullGCPtr<SessionHistoryEntry>> const& session_history_entries() const { return m_session_history_entries; }
     bool running_nested_apply_history_step() const { return m_running_nested_apply_history_step; }
+
     VisibilityState system_visibility_state() const { return m_system_visibility_state; }
+    void set_system_visibility_state(VisibilityState);
 
     struct HistoryObjectLengthAndIndex {
         size_t script_history_length;

+ 1 - 1
Userland/Services/WebContent/ConnectionFromClient.cpp

@@ -871,7 +871,7 @@ void ConnectionFromClient::request_file(Web::FileRequest file_request)
 
 void ConnectionFromClient::set_system_visibility_state(bool visible)
 {
-    m_page_host->page().top_level_browsing_context().set_system_visibility_state(
+    m_page_host->page().top_level_traversable()->set_system_visibility_state(
         visible
             ? Web::HTML::VisibilityState::Visible
             : Web::HTML::VisibilityState::Hidden);

+ 2 - 2
Userland/Services/WebContent/WebDriverConnection.cpp

@@ -1948,7 +1948,7 @@ void WebDriverConnection::restore_the_window()
     // Do not return from this operation until the visibility state of the top-level browsing context’s active document has reached the visible state, or until the operation times out.
     // FIXME: Implement timeouts.
     Web::Platform::EventLoopPlugin::the().spin_until([this]() {
-        auto state = m_page_client.page().top_level_browsing_context().system_visibility_state();
+        auto state = m_page_client.page().top_level_traversable()->system_visibility_state();
         return state == Web::HTML::VisibilityState::Visible;
     });
 }
@@ -1972,7 +1972,7 @@ Gfx::IntRect WebDriverConnection::iconify_the_window()
     // Do not return from this operation until the visibility state of the top-level browsing context’s active document has reached the hidden state, or until the operation times out.
     // FIXME: Implement timeouts.
     Web::Platform::EventLoopPlugin::the().spin_until([this]() {
-        auto state = m_page_client.page().top_level_browsing_context().system_visibility_state();
+        auto state = m_page_client.page().top_level_traversable()->system_visibility_state();
         return state == Web::HTML::VisibilityState::Hidden;
     });