LibWeb: Add a document observer for pageHide/pageShow events

WebDriver will need to "block" until a pageShow event occurs in some
cases.
This commit is contained in:
Timothy Flynn 2024-11-05 13:12:58 -05:00 committed by Andreas Kling
parent 3afd88330b
commit d4966bc2d8
Notes: github-actions[bot] 2024-11-06 09:55:25 +00:00
4 changed files with 27 additions and 1 deletions

View file

@ -3045,6 +3045,19 @@ bool Document::anything_is_delaying_the_load_event() const
return false;
}
void Document::set_page_showing(bool page_showing)
{
if (m_page_showing == page_showing)
return;
m_page_showing = page_showing;
for (auto document_observer : m_document_observers) {
if (document_observer->document_page_showing_observer())
document_observer->document_page_showing_observer()->function()(m_page_showing);
}
}
void Document::invalidate_stacking_context_tree()
{
if (auto* paintable_box = this->paintable_box())

View file

@ -426,7 +426,7 @@ public:
void decrement_number_of_things_delaying_the_load_event(Badge<DocumentLoadEventDelayer>);
bool page_showing() const { return m_page_showing; }
void set_page_showing(bool value) { m_page_showing = value; }
void set_page_showing(bool);
bool hidden() const;
StringView visibility_state() const;

View file

@ -27,6 +27,7 @@ void DocumentObserver::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_document_completely_loaded);
visitor.visit(m_document_readiness_observer);
visitor.visit(m_document_visibility_state_observer);
visitor.visit(m_document_page_showing_observer);
}
void DocumentObserver::finalize()
@ -67,4 +68,12 @@ void DocumentObserver::set_document_visibility_state_observer(Function<void(HTML
m_document_visibility_state_observer = nullptr;
}
void DocumentObserver::set_document_page_showing_observer(Function<void(bool)> callback)
{
if (callback)
m_document_page_showing_observer = JS::create_heap_function(vm().heap(), move(callback));
else
m_document_page_showing_observer = nullptr;
}
}

View file

@ -32,6 +32,9 @@ public:
[[nodiscard]] JS::GCPtr<JS::HeapFunction<void(HTML::VisibilityState)>> document_visibility_state_observer() const { return m_document_visibility_state_observer; }
void set_document_visibility_state_observer(Function<void(HTML::VisibilityState)>);
[[nodiscard]] JS::GCPtr<JS::HeapFunction<void(bool)>> document_page_showing_observer() const { return m_document_page_showing_observer; }
void set_document_page_showing_observer(Function<void(bool)>);
private:
explicit DocumentObserver(JS::Realm&, DOM::Document&);
@ -43,6 +46,7 @@ private:
JS::GCPtr<JS::HeapFunction<void()>> m_document_completely_loaded;
JS::GCPtr<JS::HeapFunction<void(HTML::DocumentReadyState)>> m_document_readiness_observer;
JS::GCPtr<JS::HeapFunction<void(HTML::VisibilityState)>> m_document_visibility_state_observer;
JS::GCPtr<JS::HeapFunction<void(bool)>> m_document_page_showing_observer;
};
}