HTMLFormElement.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2023, Kenneth Myhra <kennethmyhra@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibWeb/ARIA/Roles.h>
  9. #include <LibWeb/HTML/HTMLElement.h>
  10. #include <LibWeb/HTML/HTMLInputElement.h>
  11. namespace Web::HTML {
  12. class HTMLFormElement final : public HTMLElement {
  13. WEB_PLATFORM_OBJECT(HTMLFormElement, HTMLElement);
  14. public:
  15. virtual ~HTMLFormElement() override;
  16. DeprecatedString action() const;
  17. DeprecatedString method() const { return attribute(HTML::AttributeNames::method); }
  18. ErrorOr<void> submit_form(JS::GCPtr<HTMLElement> submitter, bool from_submit_binding = false);
  19. void reset_form();
  20. // NOTE: This is for the JS bindings. Use submit_form instead.
  21. WebIDL::ExceptionOr<void> submit();
  22. // NOTE: This is for the JS bindings. Use submit_form instead.
  23. void reset();
  24. void add_associated_element(Badge<FormAssociatedElement>, HTMLElement&);
  25. void remove_associated_element(Badge<FormAssociatedElement>, HTMLElement&);
  26. ErrorOr<Vector<JS::NonnullGCPtr<DOM::Element>>> get_submittable_elements();
  27. JS::NonnullGCPtr<DOM::HTMLCollection> elements() const;
  28. unsigned length() const;
  29. WebIDL::ExceptionOr<bool> check_validity();
  30. WebIDL::ExceptionOr<bool> report_validity();
  31. // https://www.w3.org/TR/html-aria/#el-form
  32. virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::form; }
  33. // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-entry-list
  34. bool constructing_entry_list() const { return m_constructing_entry_list; }
  35. void set_constructing_entry_list(bool value) { m_constructing_entry_list = value; }
  36. private:
  37. HTMLFormElement(DOM::Document&, DOM::QualifiedName);
  38. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  39. virtual void visit_edges(Cell::Visitor&) override;
  40. ErrorOr<void> populate_vector_with_submittable_elements_in_tree_order(JS::NonnullGCPtr<DOM::Element> element, Vector<JS::NonnullGCPtr<DOM::Element>>& elements);
  41. bool m_firing_submission_events { false };
  42. // https://html.spec.whatwg.org/multipage/forms.html#locked-for-reset
  43. bool m_locked_for_reset { false };
  44. Vector<JS::GCPtr<HTMLElement>> m_associated_elements;
  45. JS::GCPtr<DOM::HTMLCollection> mutable m_elements;
  46. bool m_constructing_entry_list { false };
  47. };
  48. }