2020-08-01 03:04:26 +01:00
|
|
|
/*
|
2021-04-28 22:46:44 +02:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2020-08-01 03:04:26 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-01 03:04:26 +01:00
|
|
|
*/
|
|
|
|
|
2022-09-30 17:16:16 -06:00
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2023-06-02 21:44:03 +02:00
|
|
|
#include <LibWeb/DOM/Event.h>
|
2020-08-01 03:04:26 +01:00
|
|
|
#include <LibWeb/HTML/HTMLDetailsElement.h>
|
2023-06-02 21:44:03 +02:00
|
|
|
#include <LibWeb/HTML/HTMLSummaryElement.h>
|
2020-08-01 03:04:26 +01:00
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2022-02-18 21:00:52 +01:00
|
|
|
HTMLDetailsElement::HTMLDetailsElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
2021-02-07 11:20:15 +01:00
|
|
|
: HTMLElement(document, move(qualified_name))
|
2020-08-01 03:04:26 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-14 13:21:51 -06:00
|
|
|
HTMLDetailsElement::~HTMLDetailsElement() = default;
|
2023-01-10 06:28:20 -05:00
|
|
|
|
2023-06-02 21:44:03 +02:00
|
|
|
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.
|
2023-08-13 13:05:26 +02:00
|
|
|
dispatch_event(Web::DOM::Event::create(realm(), HTML::EventNames::toggle));
|
2023-06-02 21:44:03 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
void HTMLDetailsElement::initialize(JS::Realm& realm)
|
2023-01-10 06:28:20 -05:00
|
|
|
{
|
2023-08-07 08:41:28 +02:00
|
|
|
Base::initialize(realm);
|
2023-01-10 06:28:20 -05:00
|
|
|
set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLDetailsElementPrototype>(realm, "HTMLDetailsElement"));
|
|
|
|
}
|
|
|
|
|
2020-08-01 03:04:26 +01:00
|
|
|
}
|