mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-04 16:11:54 +00:00
LibWeb: Implement validity IDL attribute
This commit is contained in:
parent
184ae687c5
commit
83c4e22247
Notes:
github-actions[bot]
2025-02-18 06:38:10 +00:00
Author: https://github.com/Psychpsyo
Commit: 83c4e22247
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3583
Reviewed-by: https://github.com/shannonbooth
Reviewed-by: https://github.com/tcl3 ✅
33 changed files with 2007 additions and 31 deletions
|
@ -6,14 +6,21 @@
|
|||
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/Bindings/ValidityStatePrototype.h>
|
||||
#include <LibWeb/HTML/HTMLElement.h>
|
||||
#include <LibWeb/HTML/ValidityState.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(ValidityState);
|
||||
|
||||
ValidityState::ValidityState(JS::Realm& realm)
|
||||
GC::Ref<ValidityState> ValidityState::create(JS::Realm& realm, FormAssociatedElement const& control)
|
||||
{
|
||||
return realm.create<ValidityState>(realm, control);
|
||||
}
|
||||
|
||||
ValidityState::ValidityState(JS::Realm& realm, FormAssociatedElement const& control)
|
||||
: PlatformObject(realm)
|
||||
, m_control(control)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -23,4 +30,86 @@ void ValidityState::initialize(JS::Realm& realm)
|
|||
WEB_SET_PROTOTYPE_FOR_INTERFACE(ValidityState);
|
||||
}
|
||||
|
||||
void ValidityState::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_control.form_associated_element_to_html_element());
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-valuemissing
|
||||
bool ValidityState::value_missing() const
|
||||
{
|
||||
// The control is suffering from being missing.
|
||||
return m_control.suffering_from_being_missing();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-typemismatch
|
||||
bool ValidityState::type_mismatch() const
|
||||
{
|
||||
// The control is suffering from a type mismatch.
|
||||
return m_control.suffering_from_a_type_mismatch();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-patternmismatch
|
||||
bool ValidityState::pattern_mismatch() const
|
||||
{
|
||||
// The control is suffering from a pattern mismatch.
|
||||
return m_control.suffering_from_a_pattern_mismatch();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-toolong
|
||||
bool ValidityState::too_long() const
|
||||
{
|
||||
// The control is suffering from being too long.
|
||||
return m_control.suffering_from_being_too_long();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-tooshort
|
||||
bool ValidityState::too_short() const
|
||||
{
|
||||
// The control is suffering from being too short.
|
||||
return m_control.suffering_from_being_too_short();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-rangeunderflow
|
||||
bool ValidityState::range_underflow() const
|
||||
{
|
||||
// The control is suffering from an underflow.
|
||||
return m_control.suffering_from_an_underflow();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-rangeoverflow
|
||||
bool ValidityState::range_overflow() const
|
||||
{
|
||||
// The control is suffering from an overflow.
|
||||
return m_control.suffering_from_an_overflow();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-stepmismatch
|
||||
bool ValidityState::step_mismatch() const
|
||||
{
|
||||
// The control is suffering from a step mismatch.
|
||||
return m_control.suffering_from_a_step_mismatch();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-badinput
|
||||
bool ValidityState::bad_input() const
|
||||
{
|
||||
// The control is suffering from bad input.
|
||||
return m_control.suffering_from_bad_input();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-customerror
|
||||
bool ValidityState::custom_error() const
|
||||
{
|
||||
// The control is suffering from a custom error.
|
||||
return m_control.suffering_from_a_custom_error();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-valid
|
||||
bool ValidityState::valid() const
|
||||
{
|
||||
return !(value_missing() || type_mismatch() || pattern_mismatch() || too_long() || too_short() || range_underflow() || range_overflow() || step_mismatch() || bad_input() || custom_error() || valid());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue