mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:28:12 +00:00
LibWeb: Bring form submission more up to spec
The main missing things are: - Dialog submission - Form validation - Encoding URLs in the form element's encoding - Navigables
This commit is contained in:
parent
bd62fe9c33
commit
f04d1d493d
6 changed files with 668 additions and 73 deletions
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2023, Kenneth Myhra <kennethmyhra@serenityos.org>
|
||||
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -8,21 +9,50 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibWeb/ARIA/Roles.h>
|
||||
#include <LibWeb/HTML/AbstractBrowsingContext.h>
|
||||
#include <LibWeb/HTML/HTMLElement.h>
|
||||
#include <LibWeb/HTML/HTMLInputElement.h>
|
||||
#include <LibWeb/HTML/HistoryHandlingBehavior.h>
|
||||
|
||||
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);
|
||||
|
||||
public:
|
||||
virtual ~HTMLFormElement() override;
|
||||
|
||||
DeprecatedString action() const;
|
||||
DeprecatedString method() const { return attribute(HTML::AttributeNames::method); }
|
||||
DeprecatedString action_from_form_element(JS::NonnullGCPtr<HTMLElement> element) const;
|
||||
|
||||
ErrorOr<void> submit_form(JS::GCPtr<HTMLElement> submitter, bool from_submit_binding = false);
|
||||
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<HTMLElement const> 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<HTMLElement> element) const;
|
||||
|
||||
WebIDL::ExceptionOr<void> submit_form(JS::NonnullGCPtr<HTMLElement> submitter, bool from_submit_binding = false);
|
||||
|
||||
void reset_form();
|
||||
|
||||
|
@ -50,6 +80,12 @@ public:
|
|||
bool constructing_entry_list() const { return m_constructing_entry_list; }
|
||||
void set_constructing_entry_list(bool value) { m_constructing_entry_list = value; }
|
||||
|
||||
DeprecatedString method() const;
|
||||
WebIDL::ExceptionOr<void> set_method(DeprecatedString const&);
|
||||
|
||||
DeprecatedString action() const;
|
||||
WebIDL::ExceptionOr<void> set_action(DeprecatedString const&);
|
||||
|
||||
private:
|
||||
HTMLFormElement(DOM::Document&, DOM::QualifiedName);
|
||||
|
||||
|
@ -58,6 +94,15 @@ private:
|
|||
|
||||
ErrorOr<void> populate_vector_with_submittable_elements_in_tree_order(JS::NonnullGCPtr<DOM::Element> element, Vector<JS::NonnullGCPtr<DOM::Element>>& elements);
|
||||
|
||||
ErrorOr<String> pick_an_encoding() const;
|
||||
|
||||
ErrorOr<void> mutate_action_url(AK::URL parsed_action, Vector<XHR::FormDataEntry> entry_list, JS::NonnullGCPtr<AbstractBrowsingContext> target_navigable, HistoryHandlingBehavior history_handling);
|
||||
ErrorOr<void> submit_as_entity_body(AK::URL parsed_action, Vector<XHR::FormDataEntry> entry_list, EncodingTypeAttributeState encoding_type, String encoding, JS::NonnullGCPtr<AbstractBrowsingContext> target_navigable, HistoryHandlingBehavior history_handling);
|
||||
void get_action_url(AK::URL parsed_action, JS::NonnullGCPtr<AbstractBrowsingContext> target_navigable, HistoryHandlingBehavior history_handling);
|
||||
ErrorOr<void> mail_with_headers(AK::URL parsed_action, Vector<XHR::FormDataEntry> entry_list, String encoding, JS::NonnullGCPtr<AbstractBrowsingContext> target_navigable, HistoryHandlingBehavior history_handling);
|
||||
ErrorOr<void> mail_as_body(AK::URL parsed_action, Vector<XHR::FormDataEntry> entry_list, EncodingTypeAttributeState encoding_type, String encoding, JS::NonnullGCPtr<AbstractBrowsingContext> target_navigable, HistoryHandlingBehavior history_handling);
|
||||
void plan_to_navigate_to(Variant<AK::URL, JS::NonnullGCPtr<Fetch::Infrastructure::Request>> resource, JS::NonnullGCPtr<AbstractBrowsingContext> target_navigable, HistoryHandlingBehavior history_handling);
|
||||
|
||||
bool m_firing_submission_events { false };
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#locked-for-reset
|
||||
|
@ -68,6 +113,11 @@ private:
|
|||
JS::GCPtr<DOM::HTMLCollection> 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 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue