diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 8f00c5388b3..e0c6c64c905 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -448,6 +448,7 @@ set(SOURCES HTML/WorkerGlobalScope.cpp HTML/WorkerLocation.cpp HTML/WorkerNavigator.cpp + HTML/ValidityState.cpp HighResolutionTime/Performance.cpp HighResolutionTime/TimeOrigin.cpp Infra/Base64.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index ef86b907313..00e30ccd6db 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -467,6 +467,7 @@ class TrackEvent; struct TransferDataHolder; class TraversableNavigable; class UserActivation; +class ValidityState; class VideoTrack; class VideoTrackList; class Window; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 760ef991695..88ba3acc5ea 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -82,6 +83,17 @@ void HTMLInputElement::visit_edges(Cell::Visitor& visitor) visitor.visit(m_image_request); } +// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-validity +JS::NonnullGCPtr HTMLInputElement::validity() const +{ + auto& vm = this->vm(); + auto& realm = this->realm(); + + dbgln("FIXME: Implement validity attribute getter"); + + return vm.heap().allocate(realm, realm); +} + JS::GCPtr HTMLInputElement::create_layout_node(NonnullRefPtr style) { if (type_state() == TypeAttributeState::Hidden) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h index a9dca6c56c3..96bd516ca04 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h @@ -174,6 +174,8 @@ public: virtual void form_associated_element_was_removed(DOM::Node*) override; virtual void form_associated_element_attribute_changed(FlyString const&, Optional const&) override; + JS::NonnullGCPtr validity() const; + // ^HTMLElement // https://html.spec.whatwg.org/multipage/forms.html#category-label virtual bool is_labelable() const override { return type_state() != TypeAttributeState::Hidden; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.idl index 654c218cd56..f50216a72f7 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.idl @@ -1,5 +1,6 @@ #import #import +#import #import // https://html.spec.whatwg.org/multipage/input.html#htmlinputelement @@ -48,7 +49,7 @@ interface HTMLInputElement : HTMLElement { undefined stepDown(optional long n = 1); [FIXME] readonly attribute boolean willValidate; - [FIXME] readonly attribute ValidityState validity; + readonly attribute ValidityState validity; [FIXME] readonly attribute DOMString validationMessage; boolean checkValidity(); boolean reportValidity(); diff --git a/Userland/Libraries/LibWeb/HTML/ValidityState.cpp b/Userland/Libraries/LibWeb/HTML/ValidityState.cpp new file mode 100644 index 00000000000..1d41fa4801a --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/ValidityState.cpp @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024, Shannon Booth +* +* SPDX-License-Identifier: BSD-2-Clause +*/ + +#include +#include +#include + +namespace Web::HTML { + +JS_DEFINE_ALLOCATOR(ValidityState); + +ValidityState::ValidityState(JS::Realm& realm) + : PlatformObject(realm) +{ +} + +void ValidityState::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(ValidityState); +} + +} diff --git a/Userland/Libraries/LibWeb/HTML/ValidityState.h b/Userland/Libraries/LibWeb/HTML/ValidityState.h new file mode 100644 index 00000000000..ed21409b3f5 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/ValidityState.h @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024, Shannon Booth +* +* SPDX-License-Identifier: BSD-2-Clause +*/ + +#pragma once + +#include + +namespace Web::HTML { + +// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#validitystate +class ValidityState final : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(ValidityState, Bindings::PlatformObject); + JS_DECLARE_ALLOCATOR(ValidityState); + +public: + virtual ~ValidityState() override = default; + +private: + ValidityState(JS::Realm&); + + virtual void initialize(JS::Realm&) override; +}; + +} diff --git a/Userland/Libraries/LibWeb/HTML/ValidityState.idl b/Userland/Libraries/LibWeb/HTML/ValidityState.idl new file mode 100644 index 00000000000..24e15368c61 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/ValidityState.idl @@ -0,0 +1,15 @@ +// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#validitystate +[Exposed=Window] +interface ValidityState { + [FIXME] readonly attribute boolean valueMissing; + [FIXME] readonly attribute boolean typeMismatch; + [FIXME] readonly attribute boolean patternMismatch; + [FIXME] readonly attribute boolean tooLong; + [FIXME] readonly attribute boolean tooShort; + [FIXME] readonly attribute boolean rangeUnderflow; + [FIXME] readonly attribute boolean rangeOverflow; + [FIXME] readonly attribute boolean stepMismatch; + [FIXME] readonly attribute boolean badInput; + [FIXME] readonly attribute boolean customError; + [FIXME] readonly attribute boolean valid; +}; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index f88ba77e9b4..21b205765e8 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -210,6 +210,7 @@ libweb_js_bindings(HTML/TimeRanges) libweb_js_bindings(HTML/ToggleEvent) libweb_js_bindings(HTML/TrackEvent) libweb_js_bindings(HTML/UserActivation) +libweb_js_bindings(HTML/ValidityState) libweb_js_bindings(HTML/VideoTrack) libweb_js_bindings(HTML/VideoTrackList) libweb_js_bindings(HTML/Window GLOBAL)