LibWeb: Add 'Run the fullscreen steps'

Future commits will populate the pending list with events.
This commit is contained in:
Simon Farre 2025-03-20 15:38:20 +01:00 committed by Luke Wilde
parent 79de597f8a
commit f5ac0ccf6c
4 changed files with 58 additions and 1 deletions

View file

@ -648,6 +648,10 @@ void Document::visit_edges(Cell::Visitor& visitor)
visitor.visit(event.target);
}
for (auto& event : m_pending_fullscreen_events) {
visitor.visit(event.element);
}
visitor.visit(m_adopted_style_sheets);
visitor.visit(m_script_blocking_style_sheet_set);
@ -6756,6 +6760,40 @@ void Document::remove_render_blocking_element(GC::Ref<Element> element)
m_render_blocking_elements.remove(element);
}
// https://fullscreen.spec.whatwg.org/#run-the-fullscreen-steps
void Document::run_fullscreen_steps()
{
// 1. Let pendingEvents be documents list of pending fullscreen events.
auto pending_events = GC::ConservativeVector<PendingFullscreenEvent> { vm().heap() };
pending_events.extend(m_pending_fullscreen_events);
// 2. Empty documents list of pending fullscreen events.
m_pending_fullscreen_events.clear();
// 3. For each (type, element) in pendingEvents:
for (auto const& [type, element] : pending_events) {
// 1. Let target be element if element is connected and its node document is document, and otherwise let target be document.
GC::Ref<Node> target { *this };
if (element->is_connected() && &element->document() == this)
target = element;
// 2. Fire an event named type, with its bubbles and composed attributes set to true, at target.
switch (type) {
case PendingFullscreenEvent::Type::Change:
target->dispatch_event(Event::create(realm(), HTML::EventNames::fullscreenchange, EventInit { .bubbles = true, .composed = true }));
break;
case PendingFullscreenEvent::Type::Error:
target->dispatch_event(Event::create(realm(), HTML::EventNames::fullscreenerror, EventInit { .bubbles = true, .composed = true }));
break;
}
}
}
void Document::append_pending_fullscreen_change(PendingFullscreenEvent::Type type, GC::Ref<Element> element)
{
m_pending_fullscreen_events.append(PendingFullscreenEvent { type, element });
}
// https://dom.spec.whatwg.org/#document-allow-declarative-shadow-roots
void Document::set_allow_declarative_shadow_roots(bool allow)
{

View file

@ -164,6 +164,14 @@ enum class PolicyControlledFeature : u8 {
WindowManagement,
};
struct PendingFullscreenEvent {
enum class Type {
Change,
Error,
} type;
GC::Ref<Element> element;
};
class WEB_API Document
: public ParentNode
, public HTML::GlobalEventHandlers {
@ -957,6 +965,9 @@ public:
void remove_render_blocking_element(GC::Ref<Element>);
ElementByIdMap& element_by_id() const;
// https://fullscreen.spec.whatwg.org/#run-the-fullscreen-steps
void run_fullscreen_steps();
void append_pending_fullscreen_change(PendingFullscreenEvent::Type type, GC::Ref<Element> element);
auto& script_blocking_style_sheet_set() { return m_script_blocking_style_sheet_set; }
auto const& script_blocking_style_sheet_set() const { return m_script_blocking_style_sheet_set; }
@ -1401,6 +1412,9 @@ private:
// https://drafts.csswg.org/css-values-5/#random-caching
HashMap<CSS::RandomCachingKey, double> m_element_shared_css_random_base_value_cache;
// https://fullscreen.spec.whatwg.org/#list-of-pending-fullscreen-events
Vector<PendingFullscreenEvent> m_pending_fullscreen_events;
};
template<>

View file

@ -423,7 +423,10 @@ void EventLoop::update_the_rendering()
document->update_animations_and_send_events(HighResolutionTime::relative_high_resolution_time(frame_timestamp, relevant_global_object(*document)));
};
// FIXME: 12. For each doc of docs, run the fullscreen steps for doc. [FULLSCREEN]
// 12. For each doc of docs, run the fullscreen steps for doc. [FULLSCREEN]
for (auto& document : docs) {
document->run_fullscreen_steps();
}
// FIXME: 13. For each doc of docs, if the user agent detects that the backing storage associated with a CanvasRenderingContext2D or an OffscreenCanvasRenderingContext2D, context, has been lost, then it must run the context lost steps for each such context:

View file

@ -69,6 +69,8 @@ namespace Web::HTML::EventNames {
__ENUMERATE_HTML_EVENT(focusin) \
__ENUMERATE_HTML_EVENT(focusout) \
__ENUMERATE_HTML_EVENT(formdata) \
__ENUMERATE_HTML_EVENT(fullscreenchange) \
__ENUMERATE_HTML_EVENT(fullscreenerror) \
__ENUMERATE_HTML_EVENT(hashchange) \
__ENUMERATE_HTML_EVENT(input) \
__ENUMERATE_HTML_EVENT(invalid) \