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