HTMLSelectElement.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibWeb/HTML/HTMLFormElement.h>
  8. #include <LibWeb/HTML/HTMLOptionElement.h>
  9. #include <LibWeb/HTML/HTMLSelectElement.h>
  10. namespace Web::HTML {
  11. HTMLSelectElement::HTMLSelectElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  12. : FormAssociatedElement(document, move(qualified_name))
  13. {
  14. }
  15. HTMLSelectElement::~HTMLSelectElement() = default;
  16. // https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-options
  17. RefPtr<HTMLOptionsCollection> const& HTMLSelectElement::options()
  18. {
  19. if (!m_options) {
  20. m_options = HTMLOptionsCollection::create(*this, [](DOM::Element const& element) {
  21. // https://html.spec.whatwg.org/multipage/form-elements.html#concept-select-option-list
  22. // The list of options for a select element consists of all the option element children of
  23. // the select element, and all the option element children of all the optgroup element children
  24. // of the select element, in tree order.
  25. return is<HTMLOptionElement>(element);
  26. });
  27. }
  28. return m_options;
  29. }
  30. }