HTMLOptGroupElement.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/HTMLOptGroupElementPrototype.h>
  7. #include <LibWeb/Bindings/Intrinsics.h>
  8. #include <LibWeb/HTML/HTMLOptGroupElement.h>
  9. #include <LibWeb/HTML/HTMLSelectElement.h>
  10. namespace Web::HTML {
  11. GC_DEFINE_ALLOCATOR(HTMLOptGroupElement);
  12. HTMLOptGroupElement::HTMLOptGroupElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  13. : HTMLElement(document, move(qualified_name))
  14. {
  15. }
  16. HTMLOptGroupElement::~HTMLOptGroupElement() = default;
  17. void HTMLOptGroupElement::initialize(JS::Realm& realm)
  18. {
  19. Base::initialize(realm);
  20. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLOptGroupElement);
  21. }
  22. void HTMLOptGroupElement::inserted()
  23. {
  24. Base::inserted();
  25. // AD-HOC: We update the selectedness of our <select> parent here,
  26. // to ensure that the correct <option> is selected after an <optgroup> is dynamically inserted.
  27. if (is<HTMLSelectElement>(*parent()) && first_child_of_type<HTMLOptionElement>())
  28. static_cast<HTMLSelectElement&>(*parent()).update_selectedness();
  29. }
  30. }