1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:37:34 +00:00

LibWeb+WebContent+Browser: Plumb visibility state from GUI to web pages

OOPWV now reacts to show/hide events and informs LibWeb about the state
change. This makes visibilitychange events fire when switching tabs. :^)
This commit is contained in:
Andreas Kling 2022-09-19 20:50:33 +02:00
parent 5908873b45
commit d4acdac317
14 changed files with 150 additions and 11 deletions

View file

@ -647,6 +647,8 @@ void Document::set_title(String const& title)
void Document::attach_to_browsing_context(Badge<HTML::BrowsingContext>, HTML::BrowsingContext& browsing_context)
{
m_browsing_context = browsing_context;
update_the_visibility_state(browsing_context.system_visibility_state());
}
void Document::detach_from_browsing_context(Badge<HTML::BrowsingContext>, HTML::BrowsingContext& browsing_context)
@ -1587,11 +1589,17 @@ bool Document::hidden() const
// https://html.spec.whatwg.org/multipage/interaction.html#dom-document-visibilitystate
String Document::visibility_state() const
{
return m_visibility_state;
switch (m_visibility_state) {
case HTML::VisibilityState::Hidden:
return "hidden"sv;
case HTML::VisibilityState::Visible:
return "visible"sv;
}
VERIFY_NOT_REACHED();
}
// https://html.spec.whatwg.org/multipage/interaction.html#update-the-visibility-state
void Document::update_the_visibility_state(String visibility_state)
void Document::update_the_visibility_state(HTML::VisibilityState visibility_state)
{
// 1. If document's visibility state equals visibilityState, then return.
if (m_visibility_state == visibility_state)
@ -1985,4 +1993,25 @@ HTML::PolicyContainer Document::policy_container() const
return m_policy_container;
}
// https://html.spec.whatwg.org/multipage/browsers.html#list-of-the-descendant-browsing-contexts
Vector<NonnullRefPtr<HTML::BrowsingContext>> Document::list_of_descendant_browsing_contexts() const
{
// 1. Let list be an empty list.
Vector<NonnullRefPtr<HTML::BrowsingContext>> list;
// 2. For each browsing context container container,
// whose nested browsing context is non-null and whose shadow-including root is d, in shadow-including tree order:
// NOTE: We already store our browsing contexts in a tree structure, so we can simply collect all the descendants
// of this document's browsing context.
if (browsing_context()) {
browsing_context()->for_each_in_subtree([&](auto& context) {
list.append(context);
return IterationDecision::Continue;
});
}
return list;
}
}

View file

@ -31,6 +31,7 @@
#include <LibWeb/HTML/Origin.h>
#include <LibWeb/HTML/SandboxingFlagSet.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/VisibilityState.h>
#include <LibWeb/HTML/Window.h>
namespace Web::DOM {
@ -319,7 +320,7 @@ public:
String visibility_state() const;
// https://html.spec.whatwg.org/multipage/interaction.html#update-the-visibility-state
void update_the_visibility_state(String visibility_state);
void update_the_visibility_state(HTML::VisibilityState);
void run_the_resize_steps();
void run_the_scroll_steps();
@ -382,6 +383,9 @@ public:
// https://html.spec.whatwg.org/multipage/dom.html#concept-document-policy-container
HTML::PolicyContainer policy_container() const;
// https://html.spec.whatwg.org/multipage/browsers.html#list-of-the-descendant-browsing-contexts
Vector<NonnullRefPtr<HTML::BrowsingContext>> list_of_descendant_browsing_contexts() const;
protected:
virtual void visit_edges(Cell::Visitor&) override;
@ -527,7 +531,7 @@ private:
HTML::PolicyContainer m_policy_container;
// https://html.spec.whatwg.org/multipage/interaction.html#visibility-state
String m_visibility_state { "hidden" };
HTML::VisibilityState m_visibility_state { HTML::VisibilityState::Hidden };
};
}