LibWeb: Unify will_validate for form associated elements

We had the same implementation in quiet a few places. With this change
we unify them in a single place
This commit is contained in:
Tete17 2025-08-29 17:59:15 +02:00 committed by Tim Ledbetter
commit 8ab568bc76
Notes: github-actions[bot] 2025-08-29 18:28:58 +00:00
16 changed files with 11 additions and 75 deletions

View file

@ -251,6 +251,14 @@ bool FormAssociatedElement::check_validity()
return check_validity_steps();
}
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-willvalidate
bool FormAssociatedElement::will_validate() const
{
// The willValidate attribute's getter must return true, if this element is a candidate for constraint validation,
// and false otherwise (i.e., false if any conditions are barring it from constraint validation).
return is_candidate_for_constraint_validation();
}
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#check-validity-steps
bool FormAssociatedElement::check_validity_steps()
{

View file

@ -146,6 +146,9 @@ public:
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-checkvalidity
bool check_validity();
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-willvalidate
bool will_validate() const;
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-validity
GC::Ref<ValidityState const> validity() const;

View file

@ -273,13 +273,6 @@ void HTMLButtonElement::activation_behavior(DOM::Event const& event)
PopoverInvokerElement::popover_target_activation_behaviour(*this, as<DOM::Node>(*event.target()));
}
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-willvalidate
bool HTMLButtonElement::will_validate()
{
// The willValidate attribute's getter must return true, if this element is a candidate for constraint validation
return is_candidate_for_constraint_validation();
}
bool HTMLButtonElement::is_focusable() const
{
return enabled();

View file

@ -44,8 +44,6 @@ public:
virtual void form_associated_element_attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
bool will_validate();
// ^EventTarget
// https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-button-element
// https://html.spec.whatwg.org/multipage/interaction.html#focusable-area

View file

@ -88,15 +88,4 @@ GC::Ptr<Layout::Node> HTMLFieldSetElement::create_layout_node(GC::Ref<CSS::Compu
return heap().allocate<Layout::FieldSetBox>(document(), *this, style);
}
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-willvalidate
bool HTMLFieldSetElement::will_validate()
{
// The willValidate attribute's getter must return true, if this element is a candidate for constraint validation,
// and false otherwise (i.e., false if any conditions are barring it from constraint validation).
// A submittable element is a candidate for constraint validation
// https://html.spec.whatwg.org/multipage/forms.html#category-submit
// Submittable elements: button, input, select, textarea, form-associated custom elements [but not fieldset]
return false;
}
}

View file

@ -42,8 +42,6 @@ public:
virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::group; }
static bool will_validate();
virtual GC::Ptr<Layout::Node> create_layout_node(GC::Ref<CSS::ComputedProperties>) override;
Layout::FieldSetBox* layout_node();
Layout::FieldSetBox const* layout_node() const;

View file

@ -2913,13 +2913,6 @@ WebIDL::ExceptionOr<void> HTMLInputElement::step_up_or_down(bool is_down, WebIDL
return {};
}
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-willvalidate
bool HTMLInputElement::will_validate()
{
// The willValidate attribute's getter must return true, if this element is a candidate for constraint validation
return is_candidate_for_constraint_validation();
}
Optional<ARIA::Role> HTMLInputElement::default_role() const
{
// http://wpt.live/html-aam/roles-dynamic-switch.tentative.window.html "Disconnected <input type=checkbox switch>"

View file

@ -159,8 +159,6 @@ public:
WebIDL::ExceptionOr<void> step_up(WebIDL::Long n = 1);
WebIDL::ExceptionOr<void> step_down(WebIDL::Long n = 1);
bool will_validate();
WebIDL::ExceptionOr<void> show_picker();
// ^EventTarget

View file

@ -81,17 +81,6 @@ void HTMLObjectElement::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_document_observer);
}
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-willvalidate
bool HTMLObjectElement::will_validate()
{
// The willValidate attribute's getter must return true, if this element is a candidate for constraint validation,
// and false otherwise (i.e., false if any conditions are barring it from constraint validation).
// A submittable element is a candidate for constraint validation
// https://html.spec.whatwg.org/multipage/forms.html#category-submit
// Submittable elements: button, input, select, textarea, form-associated custom elements [but not object]
return false;
}
void HTMLObjectElement::form_associated_element_attribute_changed(FlyString const& name, Optional<String> const&, Optional<String> const&, Optional<FlyString> const&)
{
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-object-element

View file

@ -47,8 +47,6 @@ public:
virtual void visit_edges(Cell::Visitor&) override;
static bool will_validate();
private:
HTMLObjectElement(DOM::Document&, DOM::QualifiedName);

View file

@ -110,15 +110,4 @@ void HTMLOutputElement::clear_algorithm()
string_replace_all({});
}
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-willvalidate
bool HTMLOutputElement::will_validate()
{
// The willValidate attribute's getter must return true, if this element is a candidate for constraint validation,
// and false otherwise (i.e., false if any conditions are barring it from constraint validation).
// A submittable element is a candidate for constraint validation
// https://html.spec.whatwg.org/multipage/forms.html#category-submit
// Submittable elements: button, input, select, textarea, form-associated custom elements [but not output]
return false;
}
}

View file

@ -57,8 +57,6 @@ public:
// https://www.w3.org/TR/html-aria/#el-output
virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::status; }
static bool will_validate();
private:
HTMLOutputElement(DOM::Document&, DOM::QualifiedName);

View file

@ -691,13 +691,6 @@ void HTMLSelectElement::update_selectedness()
update_inner_text_element();
}
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-willvalidate
bool HTMLSelectElement::will_validate()
{
// The willValidate attribute's getter must return true, if this element is a candidate for constraint validation
return is_candidate_for_constraint_validation();
}
bool HTMLSelectElement::is_focusable() const
{
return enabled();

View file

@ -62,8 +62,6 @@ public:
Vector<GC::Root<HTMLOptionElement>> list_of_options() const;
bool will_validate();
// ^EventTarget
// https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-select-element
// https://html.spec.whatwg.org/multipage/interaction.html#focusable-area

View file

@ -232,13 +232,6 @@ u32 HTMLTextAreaElement::text_length() const
return api_value().length_in_code_units();
}
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-willvalidate
bool HTMLTextAreaElement::will_validate()
{
// The willValidate attribute's getter must return true, if this element is a candidate for constraint validation
return is_candidate_for_constraint_validation();
}
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-textarea-maxlength
WebIDL::Long HTMLTextAreaElement::max_length() const
{

View file

@ -98,8 +98,6 @@ public:
u32 text_length() const;
bool will_validate();
WebIDL::Long max_length() const;
WebIDL::ExceptionOr<void> set_max_length(WebIDL::Long);