mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
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:
parent
3afd88330b
commit
d4966bc2d8
Notes:
github-actions[bot]
2024-11-06 09:55:25 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/d4966bc2d8f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2183
4 changed files with 27 additions and 1 deletions
|
@ -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())
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue