summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.cpp22
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.h6
-rw-r--r--Userland/Libraries/LibWeb/HTML/EventNames.h3
3 files changed, 28 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp
index 64fbe989af..3ae99605a0 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Document.cpp
@@ -1578,13 +1578,31 @@ Bindings::LocationObject* Document::location()
// https://html.spec.whatwg.org/multipage/interaction.html#dom-document-hidden
bool Document::hidden() const
{
- return false;
+ return visibility_state() == "hidden";
}
// https://html.spec.whatwg.org/multipage/interaction.html#dom-document-visibilitystate
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
diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h
index b75c00a624..7b280fb2e2 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.h
+++ b/Userland/Libraries/LibWeb/DOM/Document.h
@@ -317,6 +317,9 @@ public:
bool hidden() 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_scroll_steps();
@@ -502,6 +505,9 @@ private:
// https://html.spec.whatwg.org/#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" };
};
}
diff --git a/Userland/Libraries/LibWeb/HTML/EventNames.h b/Userland/Libraries/LibWeb/HTML/EventNames.h
index 1aaa6eb91d..05fb2bf4d5 100644
--- a/Userland/Libraries/LibWeb/HTML/EventNames.h
+++ b/Userland/Libraries/LibWeb/HTML/EventNames.h
@@ -57,7 +57,8 @@ namespace Web::HTML::EventNames {
__ENUMERATE_HTML_EVENT(submit) \
__ENUMERATE_HTML_EVENT(toggle) \
__ENUMERATE_HTML_EVENT(unhandledrejection) \
- __ENUMERATE_HTML_EVENT(unload)
+ __ENUMERATE_HTML_EVENT(unload) \
+ __ENUMERATE_HTML_EVENT(visibilitychange)
#define __ENUMERATE_HTML_EVENT(name) extern FlyString name;
ENUMERATE_HTML_EVENTS