HTMLOptionElement.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. * Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibWeb/HTML/HTMLElement.h>
  9. namespace Web::HTML {
  10. class HTMLOptionElement final : public HTMLElement {
  11. WEB_PLATFORM_OBJECT(HTMLOptionElement, HTMLElement);
  12. GC_DECLARE_ALLOCATOR(HTMLOptionElement);
  13. public:
  14. virtual ~HTMLOptionElement() override;
  15. bool selected() const { return m_selected; }
  16. void set_selected(bool);
  17. void set_selected_internal(bool);
  18. [[nodiscard]] u64 selectedness_update_index() const { return m_selectedness_update_index; }
  19. String value() const;
  20. WebIDL::ExceptionOr<void> set_value(String const&);
  21. String text() const;
  22. void set_text(String const&);
  23. [[nodiscard]] String label() const;
  24. void set_label(String const&);
  25. int index() const;
  26. bool disabled() const;
  27. GC::Ptr<HTML::HTMLFormElement> form() const;
  28. virtual Optional<ARIA::Role> default_role() const override;
  29. private:
  30. friend class Bindings::OptionConstructor;
  31. friend class HTMLSelectElement;
  32. HTMLOptionElement(DOM::Document&, DOM::QualifiedName);
  33. virtual void initialize(JS::Realm&) override;
  34. virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
  35. virtual void inserted() override;
  36. virtual void removed_from(Node*) override;
  37. void ask_for_a_reset();
  38. // https://html.spec.whatwg.org/multipage/form-elements.html#concept-option-selectedness
  39. bool m_selected { false };
  40. // https://html.spec.whatwg.org/multipage/form-elements.html#concept-option-dirtiness
  41. bool m_dirty { false };
  42. u64 m_selectedness_update_index { 0 };
  43. };
  44. }