1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +00:00

LibWeb: Port HTMLFormElement interface from DeprecatedString to String

Leaving a FIXME for HTMLFormElement::method as it looks like this could
be Reflect in the IDL.
This commit is contained in:
Shannon Booth 2023-09-03 15:44:24 +12:00 committed by Tim Flynn
parent 63aa93aaf4
commit 2a732e6ddd
3 changed files with 16 additions and 16 deletions

View file

@ -465,9 +465,10 @@ ErrorOr<void> HTMLFormElement::populate_vector_with_submittable_elements_in_tree
} }
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-method // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-method
DeprecatedString HTMLFormElement::method() const StringView HTMLFormElement::method() const
{ {
// The method and enctype IDL attributes must reflect the respective content attributes of the same name, limited to only known values. // The method and enctype IDL attributes must reflect the respective content attributes of the same name, limited to only known values.
// FIXME: This should probably be `Reflect` in the IDL.
auto method_state = method_state_from_form_element(*this); auto method_state = method_state_from_form_element(*this);
switch (method_state) { switch (method_state) {
case MethodAttributeState::GET: case MethodAttributeState::GET:
@ -476,36 +477,35 @@ DeprecatedString HTMLFormElement::method() const
return "post"sv; return "post"sv;
case MethodAttributeState::Dialog: case MethodAttributeState::Dialog:
return "dialog"sv; return "dialog"sv;
default:
VERIFY_NOT_REACHED();
} }
VERIFY_NOT_REACHED();
} }
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-method // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-method
WebIDL::ExceptionOr<void> HTMLFormElement::set_method(DeprecatedString const& method) WebIDL::ExceptionOr<void> HTMLFormElement::set_method(String const& method)
{ {
// The method and enctype IDL attributes must reflect the respective content attributes of the same name, limited to only known values. // The method and enctype IDL attributes must reflect the respective content attributes of the same name, limited to only known values.
return set_attribute(AttributeNames::method, method); return set_attribute(AttributeNames::method, method);
} }
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-action // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-action
DeprecatedString HTMLFormElement::action() const String HTMLFormElement::action() const
{ {
// The action IDL attribute must reflect the content attribute of the same name, except that on getting, when the // The action IDL attribute must reflect the content attribute of the same name, except that on getting, when the
// content attribute is missing or its value is the empty string, the element's node document's URL must be returned // content attribute is missing or its value is the empty string, the element's node document's URL must be returned
// instead. // instead.
if (!has_attribute(AttributeNames::action)) if (!has_attribute(AttributeNames::action))
return document().url_string(); return MUST(document().url().to_string());
auto action_attribute = deprecated_attribute(AttributeNames::action); auto action_attribute = attribute(AttributeNames::action);
if (action_attribute.is_empty()) if (!action_attribute.has_value() || action_attribute->is_empty())
return document().url_string(); return MUST(document().url().to_string());
return action_attribute; return action_attribute.value();
} }
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-action // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-action
WebIDL::ExceptionOr<void> HTMLFormElement::set_action(DeprecatedString const& value) WebIDL::ExceptionOr<void> HTMLFormElement::set_action(String const& value)
{ {
return set_attribute(AttributeNames::action, value); return set_attribute(AttributeNames::action, value);
} }

View file

@ -80,11 +80,11 @@ public:
bool constructing_entry_list() const { return m_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; } void set_constructing_entry_list(bool value) { m_constructing_entry_list = value; }
DeprecatedString method() const; StringView method() const;
WebIDL::ExceptionOr<void> set_method(DeprecatedString const&); WebIDL::ExceptionOr<void> set_method(String const&);
DeprecatedString action() const; String action() const;
WebIDL::ExceptionOr<void> set_action(DeprecatedString const&); WebIDL::ExceptionOr<void> set_action(String const&);
private: private:
HTMLFormElement(DOM::Document&, DOM::QualifiedName); HTMLFormElement(DOM::Document&, DOM::QualifiedName);

View file

@ -2,7 +2,7 @@
#import <HTML/HTMLElement.idl> #import <HTML/HTMLElement.idl>
// https://html.spec.whatwg.org/multipage/semantics.html#htmlformelement // https://html.spec.whatwg.org/multipage/semantics.html#htmlformelement
[Exposed=Window, UseDeprecatedAKString] [Exposed=Window]
interface HTMLFormElement : HTMLElement { interface HTMLFormElement : HTMLElement {
[HTMLConstructor] constructor(); [HTMLConstructor] constructor();