HTMLDetailsElement.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/Intrinsics.h>
  7. #include <LibWeb/DOM/Event.h>
  8. #include <LibWeb/HTML/HTMLDetailsElement.h>
  9. #include <LibWeb/HTML/HTMLSummaryElement.h>
  10. namespace Web::HTML {
  11. HTMLDetailsElement::HTMLDetailsElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  12. : HTMLElement(document, move(qualified_name))
  13. {
  14. }
  15. HTMLDetailsElement::~HTMLDetailsElement() = default;
  16. WebIDL::ExceptionOr<void> HTMLDetailsElement::set_attribute(DeprecatedFlyString const& name, DeprecatedString const& value)
  17. {
  18. auto result = HTMLElement::set_attribute(name, value);
  19. if (result.is_exception())
  20. return result.exception();
  21. if (name == HTML::AttributeNames::open)
  22. run_details_notification_task_steps();
  23. return result;
  24. }
  25. void HTMLDetailsElement::remove_attribute(DeprecatedFlyString const& name)
  26. {
  27. HTMLElement::remove_attribute(name);
  28. if (name == HTML::AttributeNames::open)
  29. run_details_notification_task_steps();
  30. }
  31. // https://html.spec.whatwg.org/multipage/interactive-elements.html#the-details-element:details-notification-task-steps
  32. void HTMLDetailsElement::run_details_notification_task_steps()
  33. {
  34. // Whenever the open attribute is added to or removed from a details element,
  35. // the user agent must queue an element task on the DOM manipulation task source given then details element that runs the following steps,
  36. // which are known as the details notification task steps, for this details element:
  37. queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] {
  38. // 1. FIXME: If another task has been queued to run the details notification task steps for this details element, then return.
  39. // 2. Fire an event named toggle at the details element.
  40. dispatch_event(Web::DOM::Event::create(realm(), HTML::EventNames::toggle));
  41. });
  42. }
  43. void HTMLDetailsElement::initialize(JS::Realm& realm)
  44. {
  45. Base::initialize(realm);
  46. set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLDetailsElementPrototype>(realm, "HTMLDetailsElement"));
  47. }
  48. }