From aa3ba629bad705b4b6616d94e60106fe05800b59 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 9 Sep 2021 00:59:09 +0200 Subject: [PATCH] LibWeb: Add DOM::Element::queue_an_element_task(source, steps) This roughly models the "queue an element task" algorithm from the spec. For safety, this captures a strong reference to the element, and then bundles that with a callback into a HTML::Task (that we then queue up.) --- Userland/Libraries/LibWeb/DOM/Element.cpp | 10 ++++++++++ Userland/Libraries/LibWeb/DOM/Element.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 526850040c..7929ecd183 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -377,4 +378,13 @@ void Element::make_html_uppercased_qualified_name() m_html_uppercased_qualified_name = qualified_name(); } +// https://html.spec.whatwg.org/multipage/webappapis.html#queue-an-element-task +void Element::queue_an_element_task(HTML::Task::Source source, Function steps) +{ + auto task = HTML::Task::create(source, &document(), [strong_this = NonnullRefPtr(*this), steps = move(steps)] { + steps(); + }); + HTML::main_thread_event_loop().task_queue().add(move(task)); +} + } diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index 3878cc433d..c6bc944399 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -104,6 +105,8 @@ public: m_custom_properties.set(custom_property_name, style_property); } + void queue_an_element_task(HTML::Task::Source, Function); + protected: RefPtr create_layout_node() override;