HTMLOptionElement.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibWeb/HTML/HTMLOptionElement.h>
  8. namespace Web::HTML {
  9. HTMLOptionElement::HTMLOptionElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  10. : HTMLElement(document, move(qualified_name))
  11. {
  12. }
  13. HTMLOptionElement::~HTMLOptionElement() = default;
  14. void HTMLOptionElement::parse_attribute(FlyString const& name, String const& value)
  15. {
  16. HTMLElement::parse_attribute(name, value);
  17. if (name == HTML::AttributeNames::selected) {
  18. // Except where otherwise specified, when the element is created, its selectedness must be set to true
  19. // if the element has a selected attribute. Whenever an option element's selected attribute is added,
  20. // if its dirtiness is false, its selectedness must be set to true.
  21. if (!m_dirty)
  22. m_selected = true;
  23. }
  24. }
  25. void HTMLOptionElement::did_remove_attribute(FlyString const& name)
  26. {
  27. HTMLElement::did_remove_attribute(name);
  28. if (name == HTML::AttributeNames::selected) {
  29. // Whenever an option element's selected attribute is removed, if its dirtiness is false, its selectedness must be set to false.
  30. if (!m_dirty)
  31. m_selected = false;
  32. }
  33. }
  34. // https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-selected
  35. void HTMLOptionElement::set_selected(bool selected)
  36. {
  37. // On setting, it must set the element's selectedness to the new value, set its dirtiness to true, and then cause the element to ask for a reset.
  38. m_selected = selected;
  39. m_dirty = true;
  40. ask_for_a_reset();
  41. }
  42. // https://html.spec.whatwg.org/multipage/form-elements.html#ask-for-a-reset
  43. void HTMLOptionElement::ask_for_a_reset()
  44. {
  45. // FIXME: Implement this operation.
  46. }
  47. }