/* * Copyright (c) 2018-2021, Andreas Kling * Copyright (c) 2023, Kenneth Myhra * Copyright (c) 2023, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace Web::HTML { // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fs-method #define ENUMERATE_FORM_METHOD_ATTRIBUTES \ __ENUMERATE_FORM_METHOD_ATTRIBUTE(get, GET) \ __ENUMERATE_FORM_METHOD_ATTRIBUTE(post, POST) \ __ENUMERATE_FORM_METHOD_ATTRIBUTE(dialog, Dialog) // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fs-enctype #define ENUMERATE_FORM_METHOD_ENCODING_TYPES \ __ENUMERATE_FORM_METHOD_ENCODING_TYPE("application/x-www-form-urlencoded", FormUrlEncoded) \ __ENUMERATE_FORM_METHOD_ENCODING_TYPE("multipart/form-data", FormData) \ __ENUMERATE_FORM_METHOD_ENCODING_TYPE("text/plain", PlainText) class HTMLFormElement final : public HTMLElement { WEB_PLATFORM_OBJECT(HTMLFormElement, HTMLElement); JS_DECLARE_ALLOCATOR(HTMLFormElement); public: virtual ~HTMLFormElement() override; String action_from_form_element(JS::NonnullGCPtr element) const; enum class MethodAttributeState { #define __ENUMERATE_FORM_METHOD_ATTRIBUTE(_, state) state, ENUMERATE_FORM_METHOD_ATTRIBUTES #undef __ENUMERATE_FORM_METHOD_ATTRIBUTE }; MethodAttributeState method_state_from_form_element(JS::NonnullGCPtr element) const; enum class EncodingTypeAttributeState { #define __ENUMERATE_FORM_METHOD_ENCODING_TYPE(_, state) state, ENUMERATE_FORM_METHOD_ENCODING_TYPES #undef __ENUMERATE_FORM_METHOD_ENCODING_TYPE }; EncodingTypeAttributeState encoding_type_state_from_form_element(JS::NonnullGCPtr element) const; struct SubmitFormOptions { bool from_submit_binding = { false }; UserNavigationInvolvement user_involvement = { UserNavigationInvolvement::None }; }; WebIDL::ExceptionOr submit_form(JS::NonnullGCPtr submitter, SubmitFormOptions); WebIDL::ExceptionOr implicitly_submit_form(); void reset_form(); // NOTE: This is for the JS bindings. Use submit_form instead. WebIDL::ExceptionOr submit(); // NOTE: This is for the JS bindings. Use submit_form instead. WebIDL::ExceptionOr request_submit(JS::GCPtr submitter); // NOTE: This is for the JS bindings. Use submit_form instead. void reset(); void add_associated_element(Badge, HTMLElement&); void remove_associated_element(Badge, HTMLElement&); Vector> get_submittable_elements(); JS::NonnullGCPtr elements() const; unsigned length() const; WebIDL::ExceptionOr check_validity(); WebIDL::ExceptionOr report_validity(); // https://www.w3.org/TR/html-aria/#el-form virtual Optional default_role() const override { return ARIA::Role::form; } // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-entry-list bool constructing_entry_list() const { return m_constructing_entry_list; } void set_constructing_entry_list(bool value) { m_constructing_entry_list = value; } StringView method() const; WebIDL::ExceptionOr set_method(String const&); String action() const; WebIDL::ExceptionOr set_action(String const&); private: HTMLFormElement(DOM::Document&, DOM::QualifiedName); virtual bool is_html_form_element() const override { return true; } virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; // ^PlatformObject virtual WebIDL::ExceptionOr item_value(size_t index) const override; virtual WebIDL::ExceptionOr named_item_value(FlyString const& name) const override; virtual Vector supported_property_names() const override; virtual bool is_supported_property_index(u32) const override; ErrorOr pick_an_encoding() const; ErrorOr mutate_action_url(URL::URL parsed_action, Vector entry_list, String encoding, JS::NonnullGCPtr target_navigable, Bindings::NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement); ErrorOr submit_as_entity_body(URL::URL parsed_action, Vector entry_list, EncodingTypeAttributeState encoding_type, String encoding, JS::NonnullGCPtr target_navigable, Bindings::NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement); void get_action_url(URL::URL parsed_action, JS::NonnullGCPtr target_navigable, Bindings::NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement); ErrorOr mail_with_headers(URL::URL parsed_action, Vector entry_list, String encoding, JS::NonnullGCPtr target_navigable, Bindings::NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement); ErrorOr mail_as_body(URL::URL parsed_action, Vector entry_list, EncodingTypeAttributeState encoding_type, String encoding, JS::NonnullGCPtr target_navigable, Bindings::NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement); void plan_to_navigate_to(URL::URL url, Variant post_resource, JS::NonnullGCPtr target_navigable, Bindings::NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement); FormAssociatedElement* default_button(); size_t number_of_fields_blocking_implicit_submission() const; bool m_firing_submission_events { false }; // https://html.spec.whatwg.org/multipage/forms.html#locked-for-reset bool m_locked_for_reset { false }; Vector> m_associated_elements; // https://html.spec.whatwg.org/multipage/forms.html#past-names-map struct PastNameEntry { JS::GCPtr node; MonotonicTime insertion_time; }; HashMap mutable m_past_names_map; JS::GCPtr mutable m_elements; bool m_constructing_entry_list { false }; // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#planned-navigation // Each form element has a planned navigation, which is either null or a task; when the form is first created, // its planned navigation must be set to null. Task const* m_planned_navigation { nullptr }; }; } namespace Web::DOM { template<> inline bool Node::fast_is() const { return is_html_form_element(); } }