diff options
author | stelar7 <dudedbz@gmail.com> | 2023-06-02 21:44:03 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-06-03 05:56:00 +0200 |
commit | fd360ba1715692ce44c49c680ab67bf2a1d2fcc4 (patch) | |
tree | 76cf1a37c15916f074cc29d10e4d615c862eb0f3 /Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp | |
parent | 8773122f6b55044a738dcc22e4342d3de4c4c25d (diff) | |
download | serenity-fd360ba1715692ce44c49c680ab67bf2a1d2fcc4.zip |
LibWeb: Implement `details_notification_task_steps` for <details>
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp index fceef86285..609f70d833 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp @@ -5,7 +5,9 @@ */ #include <LibWeb/Bindings/Intrinsics.h> +#include <LibWeb/DOM/Event.h> #include <LibWeb/HTML/HTMLDetailsElement.h> +#include <LibWeb/HTML/HTMLSummaryElement.h> namespace Web::HTML { @@ -16,6 +18,40 @@ HTMLDetailsElement::HTMLDetailsElement(DOM::Document& document, DOM::QualifiedNa HTMLDetailsElement::~HTMLDetailsElement() = default; +WebIDL::ExceptionOr<void> HTMLDetailsElement::set_attribute(DeprecatedFlyString const& name, DeprecatedString const& value) +{ + auto result = HTMLElement::set_attribute(name, value); + if (result.is_exception()) + return result.exception(); + + if (name == HTML::AttributeNames::open) + run_details_notification_task_steps(); + + return result; +} + +void HTMLDetailsElement::remove_attribute(DeprecatedFlyString const& name) +{ + HTMLElement::remove_attribute(name); + + if (name == HTML::AttributeNames::open) + run_details_notification_task_steps(); +} + +// https://html.spec.whatwg.org/multipage/interactive-elements.html#the-details-element:details-notification-task-steps +void HTMLDetailsElement::run_details_notification_task_steps() +{ + // Whenever the open attribute is added to or removed from a details element, + // the user agent must queue an element task on the DOM manipulation task source given then details element that runs the following steps, + // which are known as the details notification task steps, for this details element: + queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] { + // 1. FIXME: If another task has been queued to run the details notification task steps for this details element, then return. + + // 2. Fire an event named toggle at the details element. + dispatch_event(Web::DOM::Event::create(realm(), HTML::EventNames::toggle).release_value_but_fixme_should_propagate_errors()); + }); +} + JS::ThrowCompletionOr<void> HTMLDetailsElement::initialize(JS::Realm& realm) { MUST_OR_THROW_OOM(Base::initialize(realm)); |