HTMLDataListElement.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/HTMLDataListElementPrototype.h>
  7. #include <LibWeb/Bindings/Intrinsics.h>
  8. #include <LibWeb/HTML/HTMLDataListElement.h>
  9. #include <LibWeb/HTML/HTMLOptionElement.h>
  10. namespace Web::HTML {
  11. GC_DEFINE_ALLOCATOR(HTMLDataListElement);
  12. HTMLDataListElement::HTMLDataListElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  13. : HTMLElement(document, move(qualified_name))
  14. {
  15. }
  16. HTMLDataListElement::~HTMLDataListElement() = default;
  17. void HTMLDataListElement::initialize(JS::Realm& realm)
  18. {
  19. Base::initialize(realm);
  20. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLDataListElement);
  21. }
  22. void HTMLDataListElement::visit_edges(Cell::Visitor& visitor)
  23. {
  24. Base::visit_edges(visitor);
  25. visitor.visit(m_options);
  26. }
  27. // https://html.spec.whatwg.org/multipage/form-elements.html#dom-datalist-options
  28. GC::Ref<DOM::HTMLCollection> HTMLDataListElement::options()
  29. {
  30. // The options IDL attribute must return an HTMLCollection rooted at the datalist node, whose filter matches option elements.
  31. if (!m_options) {
  32. m_options = DOM::HTMLCollection::create(*this, DOM::HTMLCollection::Scope::Descendants, [](Element const& element) {
  33. return is<HTML::HTMLOptionElement>(element);
  34. });
  35. }
  36. return *m_options;
  37. }
  38. }