mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:07:34 +00:00
LibWeb: Flesh out "document visibility" state a bit more
We can now "update the visibility state", which also causes `visibilitychange` events to fire on the document. This still needs GUI integration work at the BrowsingContext level.
This commit is contained in:
parent
5a500827b8
commit
42b8656db3
3 changed files with 28 additions and 3 deletions
|
@ -1578,13 +1578,31 @@ Bindings::LocationObject* Document::location()
|
||||||
// https://html.spec.whatwg.org/multipage/interaction.html#dom-document-hidden
|
// https://html.spec.whatwg.org/multipage/interaction.html#dom-document-hidden
|
||||||
bool Document::hidden() const
|
bool Document::hidden() const
|
||||||
{
|
{
|
||||||
return false;
|
return visibility_state() == "hidden";
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/interaction.html#dom-document-visibilitystate
|
// https://html.spec.whatwg.org/multipage/interaction.html#dom-document-visibilitystate
|
||||||
String Document::visibility_state() const
|
String Document::visibility_state() const
|
||||||
{
|
{
|
||||||
return hidden() ? "hidden" : "visible";
|
return m_visibility_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/interaction.html#update-the-visibility-state
|
||||||
|
void Document::update_the_visibility_state(String visibility_state)
|
||||||
|
{
|
||||||
|
// 1. If document's visibility state equals visibilityState, then return.
|
||||||
|
if (m_visibility_state == visibility_state)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 2. Set document's visibility state to visibilityState.
|
||||||
|
m_visibility_state = visibility_state;
|
||||||
|
|
||||||
|
// FIXME: 3. Run any page visibility change steps which may be defined in other specifications, with visibility state and document.
|
||||||
|
|
||||||
|
// 4. Fire an event named visibilitychange at document, with its bubbles attribute initialized to true.
|
||||||
|
auto event = DOM::Event::create(window(), HTML::EventNames::visibilitychange);
|
||||||
|
event->set_bubbles(true);
|
||||||
|
dispatch_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom-view/#run-the-resize-steps
|
// https://drafts.csswg.org/cssom-view/#run-the-resize-steps
|
||||||
|
|
|
@ -317,6 +317,9 @@ public:
|
||||||
bool hidden() const;
|
bool hidden() const;
|
||||||
String visibility_state() const;
|
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 run_the_resize_steps();
|
void run_the_resize_steps();
|
||||||
void run_the_scroll_steps();
|
void run_the_scroll_steps();
|
||||||
|
|
||||||
|
@ -502,6 +505,9 @@ private:
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/#completely-loaded-time
|
// https://html.spec.whatwg.org/#completely-loaded-time
|
||||||
Optional<AK::Time> m_completely_loaded_time;
|
Optional<AK::Time> m_completely_loaded_time;
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/interaction.html#visibility-state
|
||||||
|
String m_visibility_state { "hidden" };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,8 @@ namespace Web::HTML::EventNames {
|
||||||
__ENUMERATE_HTML_EVENT(submit) \
|
__ENUMERATE_HTML_EVENT(submit) \
|
||||||
__ENUMERATE_HTML_EVENT(toggle) \
|
__ENUMERATE_HTML_EVENT(toggle) \
|
||||||
__ENUMERATE_HTML_EVENT(unhandledrejection) \
|
__ENUMERATE_HTML_EVENT(unhandledrejection) \
|
||||||
__ENUMERATE_HTML_EVENT(unload)
|
__ENUMERATE_HTML_EVENT(unload) \
|
||||||
|
__ENUMERATE_HTML_EVENT(visibilitychange)
|
||||||
|
|
||||||
#define __ENUMERATE_HTML_EVENT(name) extern FlyString name;
|
#define __ENUMERATE_HTML_EVENT(name) extern FlyString name;
|
||||||
ENUMERATE_HTML_EVENTS
|
ENUMERATE_HTML_EVENTS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue