From 38cb15ff498b319052cde81af9647e6c43d6c0b8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 19 Sep 2023 20:24:18 +0200 Subject: [PATCH] LibWeb: Move system visibility state to TraversableNavigable This no longer belongs in BrowsingContext. --- .../Libraries/LibWeb/HTML/BrowsingContext.cpp | 29 ------------------- .../Libraries/LibWeb/HTML/BrowsingContext.h | 6 ---- Userland/Libraries/LibWeb/HTML/Focus.cpp | 5 ++-- .../LibWeb/HTML/TraversableNavigable.cpp | 29 +++++++++++++++++++ .../LibWeb/HTML/TraversableNavigable.h | 2 ++ .../WebContent/ConnectionFromClient.cpp | 2 +- .../WebContent/WebDriverConnection.cpp | 4 +-- 7 files changed, 37 insertions(+), 40 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp index 91930b4c9d9..72240e73c61 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp +++ b/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 child) { VERIFY(!child->m_parent); diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.h b/Userland/Libraries/LibWeb/HTML/BrowsingContext.h index 67852bff8eb..cbba1d40159 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.h +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.h @@ -194,9 +194,6 @@ public: Vector> 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 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 m_group; - // https://html.spec.whatwg.org/multipage/interaction.html#system-visibility-state - VisibilityState m_system_visibility_state { VisibilityState::Hidden }; - JS::GCPtr m_parent; JS::GCPtr m_first_child; JS::GCPtr m_last_child; diff --git a/Userland/Libraries/LibWeb/HTML/Focus.cpp b/Userland/Libraries/LibWeb/HTML/Focus.cpp index 58b24ac5643..439bee40a08 100644 --- a/Userland/Libraries/LibWeb/HTML/Focus.cpp +++ b/Userland/Libraries/LibWeb/HTML/Focus.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include 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(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 diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp index d33b61888e4..24b5e64d8de 100644 --- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp @@ -635,4 +635,33 @@ void finalize_a_same_document_navigation(JS::NonnullGCPtr 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); + }); + } +} + } diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h index 4efd9d44655..7a442cece83 100644 --- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h +++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h @@ -29,7 +29,9 @@ public: Vector>& session_history_entries() { return m_session_history_entries; } Vector> 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; diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index 7fa41163940..b19c0bd7ed0 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/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); diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index 6bb62fef3a2..7b2dd1e38cb 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/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; });