From 13b7355ec10c21be90df997c66022e246c57656d Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 2 Nov 2024 09:22:13 -0400 Subject: [PATCH] LibWeb: Move some classes from the DOM namespace to the HTML namespace The following classes are in the HTML spec and thus belong in the HTML namespace: * BeforeUnloadEvent * HTMLFormControlsCollection * RadioNodeList --- .../Userland/Libraries/LibWeb/DOM/BUILD.gn | 3 -- .../Userland/Libraries/LibWeb/HTML/BUILD.gn | 3 ++ .../Userland/Libraries/LibWeb/idl_files.gni | 6 ++-- .../expected/{DOM => HTML}/beforeunload.txt | 0 .../input/{DOM => HTML}/beforeunload.html | 0 Userland/Libraries/LibWeb/CMakeLists.txt | 6 ++-- Userland/Libraries/LibWeb/DOM/Document.cpp | 6 ++-- Userland/Libraries/LibWeb/DOM/EventTarget.cpp | 6 ++-- Userland/Libraries/LibWeb/Forward.h | 6 ++-- .../{DOM => HTML}/BeforeUnloadEvent.cpp | 4 +-- .../LibWeb/{DOM => HTML}/BeforeUnloadEvent.h | 2 +- .../{DOM => HTML}/BeforeUnloadEvent.idl | 0 .../HTMLFormControlsCollection.cpp | 21 ++++++------ .../HTMLFormControlsCollection.h | 13 ++++---- .../HTMLFormControlsCollection.idl | 2 +- .../Libraries/LibWeb/HTML/HTMLFormElement.cpp | 11 ++++--- .../Libraries/LibWeb/HTML/HTMLFormElement.h | 4 +-- .../Libraries/LibWeb/HTML/HTMLFormElement.idl | 2 +- .../LibWeb/{DOM => HTML}/RadioNodeList.cpp | 32 +++++++++---------- .../LibWeb/{DOM => HTML}/RadioNodeList.h | 10 +++--- .../LibWeb/{DOM => HTML}/RadioNodeList.idl | 0 Userland/Libraries/LibWeb/idl_files.cmake | 6 ++-- 22 files changed, 72 insertions(+), 71 deletions(-) rename Tests/LibWeb/Text/expected/{DOM => HTML}/beforeunload.txt (100%) rename Tests/LibWeb/Text/input/{DOM => HTML}/beforeunload.html (100%) rename Userland/Libraries/LibWeb/{DOM => HTML}/BeforeUnloadEvent.cpp (93%) rename Userland/Libraries/LibWeb/{DOM => HTML}/BeforeUnloadEvent.h (97%) rename Userland/Libraries/LibWeb/{DOM => HTML}/BeforeUnloadEvent.idl (100%) rename Userland/Libraries/LibWeb/{DOM => HTML}/HTMLFormControlsCollection.cpp (78%) rename Userland/Libraries/LibWeb/{DOM => HTML}/HTMLFormControlsCollection.h (50%) rename Userland/Libraries/LibWeb/{DOM => HTML}/HTMLFormControlsCollection.idl (91%) rename Userland/Libraries/LibWeb/{DOM => HTML}/RadioNodeList.cpp (70%) rename Userland/Libraries/LibWeb/{DOM => HTML}/RadioNodeList.h (59%) rename Userland/Libraries/LibWeb/{DOM => HTML}/RadioNodeList.idl (100%) diff --git a/Meta/gn/secondary/Userland/Libraries/LibWeb/DOM/BUILD.gn b/Meta/gn/secondary/Userland/Libraries/LibWeb/DOM/BUILD.gn index 3df8c4c7f11..06202f52c45 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibWeb/DOM/BUILD.gn +++ b/Meta/gn/secondary/Userland/Libraries/LibWeb/DOM/BUILD.gn @@ -8,7 +8,6 @@ source_set("DOM") { "AccessibilityTreeNode.cpp", "AdoptedStyleSheets.cpp", "Attr.cpp", - "BeforeUnloadEvent.cpp", "CDATASection.cpp", "CharacterData.cpp", "Comment.cpp", @@ -28,7 +27,6 @@ source_set("DOM") { "EventDispatcher.cpp", "EventTarget.cpp", "HTMLCollection.cpp", - "HTMLFormControlsCollection.cpp", "IDLEventListener.cpp", "LiveNodeList.cpp", "MutationObserver.cpp", @@ -44,7 +42,6 @@ source_set("DOM") { "Position.cpp", "ProcessingInstruction.cpp", "QualifiedName.cpp", - "RadioNodeList.cpp", "Range.cpp", "ShadowRoot.cpp", "Slot.cpp", diff --git a/Meta/gn/secondary/Userland/Libraries/LibWeb/HTML/BUILD.gn b/Meta/gn/secondary/Userland/Libraries/LibWeb/HTML/BUILD.gn index b8d0f7c28a3..12d37d983fb 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibWeb/HTML/BUILD.gn +++ b/Meta/gn/secondary/Userland/Libraries/LibWeb/HTML/BUILD.gn @@ -18,6 +18,7 @@ source_set("HTML") { "AttributeNames.cpp", "AudioTrack.cpp", "AudioTrackList.cpp", + "BeforeUnloadEvent.cpp", "BroadcastChannel.cpp", "BrowsingContext.cpp", "BrowsingContextGroup.cpp", @@ -73,6 +74,7 @@ source_set("HTML") { "HTMLEmbedElement.cpp", "HTMLFieldSetElement.cpp", "HTMLFontElement.cpp", + "HTMLFormControlsCollection.cpp", "HTMLFormElement.cpp", "HTMLFrameElement.cpp", "HTMLFrameSetElement.cpp", @@ -163,6 +165,7 @@ source_set("HTML") { "PopStateEvent.cpp", "PotentialCORSRequest.cpp", "PromiseRejectionEvent.cpp", + "RadioNodeList.cpp", "SelectItem.cpp", "SelectedFile.cpp", "ServiceWorker.cpp", diff --git a/Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni b/Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni index b31a37f117d..afd0cc05892 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni +++ b/Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni @@ -67,7 +67,6 @@ standard_idl_files = [ "//Userland/Libraries/LibWeb/DOM/AbortSignal.idl", "//Userland/Libraries/LibWeb/DOM/AbstractRange.idl", "//Userland/Libraries/LibWeb/DOM/Attr.idl", - "//Userland/Libraries/LibWeb/DOM/BeforeUnloadEvent.idl", "//Userland/Libraries/LibWeb/DOM/CDATASection.idl", "//Userland/Libraries/LibWeb/DOM/CharacterData.idl", "//Userland/Libraries/LibWeb/DOM/Comment.idl", @@ -81,7 +80,6 @@ standard_idl_files = [ "//Userland/Libraries/LibWeb/DOM/Event.idl", "//Userland/Libraries/LibWeb/DOM/EventTarget.idl", "//Userland/Libraries/LibWeb/DOM/HTMLCollection.idl", - "//Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.idl", "//Userland/Libraries/LibWeb/DOM/MutationObserver.idl", "//Userland/Libraries/LibWeb/DOM/MutationRecord.idl", "//Userland/Libraries/LibWeb/DOM/NamedNodeMap.idl", @@ -90,7 +88,6 @@ standard_idl_files = [ "//Userland/Libraries/LibWeb/DOM/NodeIterator.idl", "//Userland/Libraries/LibWeb/DOM/NodeList.idl", "//Userland/Libraries/LibWeb/DOM/ProcessingInstruction.idl", - "//Userland/Libraries/LibWeb/DOM/RadioNodeList.idl", "//Userland/Libraries/LibWeb/DOM/Range.idl", "//Userland/Libraries/LibWeb/DOM/ShadowRoot.idl", "//Userland/Libraries/LibWeb/DOM/StaticRange.idl", @@ -120,6 +117,7 @@ standard_idl_files = [ "//Userland/Libraries/LibWeb/HighResolutionTime/Performance.idl", "//Userland/Libraries/LibWeb/HTML/AudioTrack.idl", "//Userland/Libraries/LibWeb/HTML/AudioTrackList.idl", + "//Userland/Libraries/LibWeb/HTML/BeforeUnloadEvent.idl", "//Userland/Libraries/LibWeb/HTML/BroadcastChannel.idl", "//Userland/Libraries/LibWeb/HTML/CanvasGradient.idl", "//Userland/Libraries/LibWeb/HTML/CanvasPattern.idl", @@ -161,6 +159,7 @@ standard_idl_files = [ "//Userland/Libraries/LibWeb/HTML/HTMLEmbedElement.idl", "//Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.idl", "//Userland/Libraries/LibWeb/HTML/HTMLFontElement.idl", + "//Userland/Libraries/LibWeb/HTML/HTMLFormControlsCollection.idl", "//Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl", "//Userland/Libraries/LibWeb/HTML/HTMLFrameElement.idl", "//Userland/Libraries/LibWeb/HTML/HTMLFrameSetElement.idl", @@ -237,6 +236,7 @@ standard_idl_files = [ "//Userland/Libraries/LibWeb/HTML/PluginArray.idl", "//Userland/Libraries/LibWeb/HTML/PopStateEvent.idl", "//Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.idl", + "//Userland/Libraries/LibWeb/HTML/RadioNodeList.idl", "//Userland/Libraries/LibWeb/HTML/ServiceWorker.idl", "//Userland/Libraries/LibWeb/HTML/ServiceWorkerContainer.idl", "//Userland/Libraries/LibWeb/HTML/ServiceWorkerRegistration.idl", diff --git a/Tests/LibWeb/Text/expected/DOM/beforeunload.txt b/Tests/LibWeb/Text/expected/HTML/beforeunload.txt similarity index 100% rename from Tests/LibWeb/Text/expected/DOM/beforeunload.txt rename to Tests/LibWeb/Text/expected/HTML/beforeunload.txt diff --git a/Tests/LibWeb/Text/input/DOM/beforeunload.html b/Tests/LibWeb/Text/input/HTML/beforeunload.html similarity index 100% rename from Tests/LibWeb/Text/input/DOM/beforeunload.html rename to Tests/LibWeb/Text/input/HTML/beforeunload.html diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 334529e70d4..c611511db59 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -164,7 +164,6 @@ set(SOURCES DOM/AccessibilityTreeNode.cpp DOM/AdoptedStyleSheets.cpp DOM/Attr.cpp - DOM/BeforeUnloadEvent.cpp DOM/CDATASection.cpp DOM/CharacterData.cpp DOM/Comment.cpp @@ -185,7 +184,6 @@ set(SOURCES DOM/EventDispatcher.cpp DOM/EventTarget.cpp DOM/HTMLCollection.cpp - DOM/HTMLFormControlsCollection.cpp DOM/IDLEventListener.cpp DOM/LiveNodeList.cpp DOM/MutationObserver.cpp @@ -201,7 +199,6 @@ set(SOURCES DOM/Position.cpp DOM/ProcessingInstruction.cpp DOM/QualifiedName.cpp - DOM/RadioNodeList.cpp DOM/Range.cpp DOM/ShadowRoot.cpp DOM/Slot.cpp @@ -274,6 +271,7 @@ set(SOURCES HTML/AttributeNames.cpp HTML/AudioTrack.cpp HTML/AudioTrackList.cpp + HTML/BeforeUnloadEvent.cpp HTML/BroadcastChannel.cpp HTML/BrowsingContext.cpp HTML/BrowsingContextGroup.cpp @@ -343,6 +341,7 @@ set(SOURCES HTML/HTMLEmbedElement.cpp HTML/HTMLFieldSetElement.cpp HTML/HTMLFontElement.cpp + HTML/HTMLFormControlsCollection.cpp HTML/HTMLFormElement.cpp HTML/HTMLFrameElement.cpp HTML/HTMLFrameSetElement.cpp @@ -439,6 +438,7 @@ set(SOURCES HTML/PluginArray.cpp HTML/PotentialCORSRequest.cpp HTML/PromiseRejectionEvent.cpp + HTML/RadioNodeList.cpp HTML/Scripting/ClassicScript.cpp HTML/Scripting/Environments.cpp HTML/Scripting/EnvironmentSettingsSnapshot.cpp diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 4e568e1f7ca..f1b61e2d776 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -40,7 +40,6 @@ #include #include #include -#include #include #include #include @@ -69,6 +68,7 @@ #include #include #include +#include #include #include #include @@ -1763,7 +1763,7 @@ WebIDL::ExceptionOr> Document::create_event(StringView i // 2. If interface is an ASCII case-insensitive match for any of the strings in the first column in the following table, // then set constructor to the interface in the second column on the same row as the matching string: if (Infra::is_ascii_case_insensitive_match(interface, "beforeunloadevent"sv)) { - event = BeforeUnloadEvent::create(realm, FlyString {}); + event = HTML::BeforeUnloadEvent::create(realm, FlyString {}); } else if (Infra::is_ascii_case_insensitive_match(interface, "compositionevent"sv)) { event = UIEvents::CompositionEvent::create(realm, String {}); } else if (Infra::is_ascii_case_insensitive_match(interface, "customevent"sv)) { @@ -5697,7 +5697,7 @@ Document::StepsToFireBeforeunloadResult Document::steps_to_fire_beforeunload(boo // using BeforeUnloadEvent, with the cancelable attribute initialized to true. auto& global_object = HTML::relevant_global_object(*this); auto& window = verify_cast(global_object); - auto beforeunload_event = BeforeUnloadEvent::create(realm(), HTML::EventNames::beforeunload); + auto beforeunload_event = HTML::BeforeUnloadEvent::create(realm(), HTML::EventNames::beforeunload); beforeunload_event->set_cancelable(true); auto event_firing_result = window.dispatch_event(*beforeunload_event); diff --git a/Userland/Libraries/LibWeb/DOM/EventTarget.cpp b/Userland/Libraries/LibWeb/DOM/EventTarget.cpp index c7f4c0e5f59..00180f63ad9 100644 --- a/Userland/Libraries/LibWeb/DOM/EventTarget.cpp +++ b/Userland/Libraries/LibWeb/DOM/EventTarget.cpp @@ -16,13 +16,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include #include #include @@ -691,7 +691,7 @@ JS::ThrowCompletionOr EventTarget::process_event_handler_for_event(FlyStri auto return_value = *return_value_or_error.value(); // 5. Process return value as follows: - if (is(event) && event.type() == "beforeunload") { + if (is(event) && event.type() == "beforeunload") { // -> If event is a BeforeUnloadEvent object and event's type is "beforeunload" // If return value is not null, then: if (!return_value.is_nullish()) { @@ -699,7 +699,7 @@ JS::ThrowCompletionOr EventTarget::process_event_handler_for_event(FlyStri event.set_cancelled(true); // 2. If event's returnValue attribute's value is the empty string, then set event's returnValue attribute's value to return value. - auto& before_unload_event = static_cast(event); + auto& before_unload_event = static_cast(event); if (before_unload_event.return_value().is_empty()) before_unload_event.set_return_value(TRY(return_value.to_string(vm()))); } diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 2eb6b4422a7..b6c3f7fca37 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -254,7 +254,6 @@ class AbortSignal; class AbstractRange; class AccessibilityTreeNode; class Attr; -class BeforeUnloadEvent; class CDATASection; class CharacterData; class Comment; @@ -273,7 +272,6 @@ class Event; class EventHandler; class EventTarget; class HTMLCollection; -class HTMLFormControlsCollection; class IDLEventListener; class LiveNodeList; class MutationObserver; @@ -286,7 +284,6 @@ class NodeList; class ParentNode; class Position; class ProcessingInstruction; -class RadioNodeList; class Range; class RegisteredObserver; class ShadowRoot; @@ -378,6 +375,7 @@ namespace Web::HTML { class AnimationFrameCallbackDriver; class AudioTrack; class AudioTrackList; +class BeforeUnloadEvent; class BroadcastChannel; class BrowsingContext; class BrowsingContextGroup; @@ -426,6 +424,7 @@ class HTMLElement; class HTMLEmbedElement; class HTMLFieldSetElement; class HTMLFontElement; +class HTMLFormControlsCollection; class HTMLFormElement; class HTMLFrameElement; class HTMLFrameSetElement; @@ -507,6 +506,7 @@ class Path2D; class Plugin; class PluginArray; class PromiseRejectionEvent; +class RadioNodeList; class SelectedFile; class ServiceWorkerContainer; class ServiceWorkerRegistration; diff --git a/Userland/Libraries/LibWeb/DOM/BeforeUnloadEvent.cpp b/Userland/Libraries/LibWeb/HTML/BeforeUnloadEvent.cpp similarity index 93% rename from Userland/Libraries/LibWeb/DOM/BeforeUnloadEvent.cpp rename to Userland/Libraries/LibWeb/HTML/BeforeUnloadEvent.cpp index 998f256d11f..72616bd0629 100644 --- a/Userland/Libraries/LibWeb/DOM/BeforeUnloadEvent.cpp +++ b/Userland/Libraries/LibWeb/HTML/BeforeUnloadEvent.cpp @@ -6,9 +6,9 @@ #include #include -#include +#include -namespace Web::DOM { +namespace Web::HTML { JS_DEFINE_ALLOCATOR(BeforeUnloadEvent); diff --git a/Userland/Libraries/LibWeb/DOM/BeforeUnloadEvent.h b/Userland/Libraries/LibWeb/HTML/BeforeUnloadEvent.h similarity index 97% rename from Userland/Libraries/LibWeb/DOM/BeforeUnloadEvent.h rename to Userland/Libraries/LibWeb/HTML/BeforeUnloadEvent.h index 7dc554cf7e8..93c520d5ad3 100644 --- a/Userland/Libraries/LibWeb/DOM/BeforeUnloadEvent.h +++ b/Userland/Libraries/LibWeb/HTML/BeforeUnloadEvent.h @@ -9,7 +9,7 @@ #include #include -namespace Web::DOM { +namespace Web::HTML { class BeforeUnloadEvent final : public DOM::Event { WEB_PLATFORM_OBJECT(BeforeUnloadEvent, DOM::Event); diff --git a/Userland/Libraries/LibWeb/DOM/BeforeUnloadEvent.idl b/Userland/Libraries/LibWeb/HTML/BeforeUnloadEvent.idl similarity index 100% rename from Userland/Libraries/LibWeb/DOM/BeforeUnloadEvent.idl rename to Userland/Libraries/LibWeb/HTML/BeforeUnloadEvent.idl diff --git a/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormControlsCollection.cpp similarity index 78% rename from Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.cpp rename to Userland/Libraries/LibWeb/HTML/HTMLFormControlsCollection.cpp index 7a8234029a0..60e121bc852 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormControlsCollection.cpp @@ -8,20 +8,21 @@ #include #include #include -#include #include +#include +#include -namespace Web::DOM { +namespace Web::HTML { JS_DEFINE_ALLOCATOR(HTMLFormControlsCollection); -JS::NonnullGCPtr HTMLFormControlsCollection::create(ParentNode& root, Scope scope, Function filter) +JS::NonnullGCPtr HTMLFormControlsCollection::create(DOM::ParentNode& root, Scope scope, Function filter) { return root.heap().allocate(root.realm(), root, scope, move(filter)); } -HTMLFormControlsCollection::HTMLFormControlsCollection(ParentNode& root, Scope scope, Function filter) - : HTMLCollection(root, scope, move(filter)) +HTMLFormControlsCollection::HTMLFormControlsCollection(DOM::ParentNode& root, Scope scope, Function filter) + : DOM::HTMLCollection(root, scope, move(filter)) { } @@ -34,7 +35,7 @@ void HTMLFormControlsCollection::initialize(JS::Realm& realm) } // https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#dom-htmlformcontrolscollection-nameditem -Variant> HTMLFormControlsCollection::named_item_or_radio_node_list(FlyString const& name) const +Variant> HTMLFormControlsCollection::named_item_or_radio_node_list(FlyString const& name) const { // 1. If name is the empty string, return null and stop the algorithm. if (name.is_empty()) @@ -42,7 +43,7 @@ Variant> HTMLFormControlsCollection:: // 2. If, at the time the method is called, there is exactly one node in the collection that has either an id attribute or a name attribute equal to name, then return that node and stop the algorithm. // 3. Otherwise, if there are no nodes in the collection that have either an id attribute or a name attribute equal to name, then return null and stop the algorithm. - Element* matching_element = nullptr; + DOM::Element* matching_element = nullptr; bool multiple_matching = false; auto collection = collect_matching_elements(); @@ -67,11 +68,11 @@ Variant> HTMLFormControlsCollection:: // 4. Otherwise, create a new RadioNodeList object representing a live view of the HTMLFormControlsCollection object, further filtered so that the only nodes in the // RadioNodeList object are those that have either an id attribute or a name attribute equal to name. The nodes in the RadioNodeList object must be sorted in tree // order. Return that RadioNodeList object. - return JS::make_handle(RadioNodeList::create(realm(), root(), LiveNodeList::Scope::Descendants, [name](Node const& node) { - if (!is(node)) + return JS::make_handle(RadioNodeList::create(realm(), root(), DOM::LiveNodeList::Scope::Descendants, [name](auto const& node) { + if (!is(node)) return false; - auto const& element = verify_cast(node); + auto const& element = verify_cast(node); return element.id() == name || element.name() == name; })); } diff --git a/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.h b/Userland/Libraries/LibWeb/HTML/HTMLFormControlsCollection.h similarity index 50% rename from Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.h rename to Userland/Libraries/LibWeb/HTML/HTMLFormControlsCollection.h index 3c77c620d43..32fdb536815 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormControlsCollection.h @@ -7,20 +7,19 @@ #pragma once #include -#include -namespace Web::DOM { +namespace Web::HTML { -class HTMLFormControlsCollection : public HTMLCollection { - WEB_PLATFORM_OBJECT(HTMLFormControlsCollection, HTMLCollection); +class HTMLFormControlsCollection : public DOM::HTMLCollection { + WEB_PLATFORM_OBJECT(HTMLFormControlsCollection, DOM::HTMLCollection); JS_DECLARE_ALLOCATOR(HTMLFormControlsCollection); public: - [[nodiscard]] static JS::NonnullGCPtr create(ParentNode& root, Scope, ESCAPING Function filter); + [[nodiscard]] static JS::NonnullGCPtr create(DOM::ParentNode& root, Scope, ESCAPING Function filter); virtual ~HTMLFormControlsCollection() override; - Variant> named_item_or_radio_node_list(FlyString const& name) const; + Variant> named_item_or_radio_node_list(FlyString const& name) const; protected: virtual void initialize(JS::Realm&) override; @@ -28,7 +27,7 @@ protected: virtual JS::Value named_item_value(FlyString const& name) const final; private: - HTMLFormControlsCollection(ParentNode& root, Scope, ESCAPING Function filter); + HTMLFormControlsCollection(DOM::ParentNode& root, Scope, ESCAPING Function filter); }; } diff --git a/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.idl b/Userland/Libraries/LibWeb/HTML/HTMLFormControlsCollection.idl similarity index 91% rename from Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.idl rename to Userland/Libraries/LibWeb/HTML/HTMLFormControlsCollection.idl index 0821a53b9e9..f3cde859539 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormControlsCollection.idl @@ -1,5 +1,5 @@ #import -#import +#import // https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#htmlformcontrolscollection [Exposed=Window] diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp index 660bef79642..71c7d7e4747 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -22,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -516,11 +517,11 @@ static bool is_form_control(DOM::Element const& element, HTMLFormElement const& } // https://html.spec.whatwg.org/multipage/forms.html#dom-form-elements -JS::NonnullGCPtr HTMLFormElement::elements() const +JS::NonnullGCPtr HTMLFormElement::elements() const { if (!m_elements) { auto& root = verify_cast(const_cast(this)->root()); - m_elements = DOM::HTMLFormControlsCollection::create(root, DOM::HTMLCollection::Scope::Descendants, [this](Element const& element) { + m_elements = HTMLFormControlsCollection::create(root, DOM::HTMLCollection::Scope::Descendants, [this](Element const& element) { return is_form_control(element, *this); }); } @@ -1021,7 +1022,7 @@ JS::Value HTMLFormElement::named_item_value(FlyString const& name) const // 1. Let candidates be a live RadioNodeList object containing all the listed elements, whose form owner is the form // element, that have either an id attribute or a name attribute equal to name, with the exception of input // elements whose type attribute is in the Image Button state, in tree order. - auto candidates = DOM::RadioNodeList::create(realm, root, DOM::LiveNodeList::Scope::Descendants, [this, name](auto& node) -> bool { + auto candidates = RadioNodeList::create(realm, root, DOM::LiveNodeList::Scope::Descendants, [this, name](auto& node) -> bool { if (!is(node)) return false; auto const& element = static_cast(node); @@ -1038,7 +1039,7 @@ JS::Value HTMLFormElement::named_item_value(FlyString const& name) const // whose form owner is the form element, that have either an id attribute or a name attribute equal to name, // in tree order. if (candidates->length() == 0) { - candidates = DOM::RadioNodeList::create(realm, root, DOM::LiveNodeList::Scope::Descendants, [this, name](auto& node) -> bool { + candidates = RadioNodeList::create(realm, root, DOM::LiveNodeList::Scope::Descendants, [this, name](auto& node) -> bool { if (!is(node)) return false; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h index bb016bccb2b..098f852884e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h @@ -75,7 +75,7 @@ public: Vector> get_submittable_elements(); - JS::NonnullGCPtr elements() const; + JS::NonnullGCPtr elements() const; unsigned length() const; WebIDL::ExceptionOr check_validity(); @@ -136,7 +136,7 @@ private: }; HashMap mutable m_past_names_map; - JS::GCPtr mutable m_elements; + JS::GCPtr mutable m_elements; bool m_constructing_entry_list { false }; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl index 1d4e6a1737c..74e2a5b8c44 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl @@ -1,5 +1,5 @@ -#import #import +#import // https://html.spec.whatwg.org/multipage/forms.html#attr-form-autocomplete [MissingValueDefault=on, InvalidValueDefault=on] diff --git a/Userland/Libraries/LibWeb/DOM/RadioNodeList.cpp b/Userland/Libraries/LibWeb/HTML/RadioNodeList.cpp similarity index 70% rename from Userland/Libraries/LibWeb/DOM/RadioNodeList.cpp rename to Userland/Libraries/LibWeb/HTML/RadioNodeList.cpp index 03a09d16157..22bb7722a65 100644 --- a/Userland/Libraries/LibWeb/DOM/RadioNodeList.cpp +++ b/Userland/Libraries/LibWeb/HTML/RadioNodeList.cpp @@ -7,20 +7,20 @@ #include #include #include -#include #include +#include -namespace Web::DOM { +namespace Web::HTML { JS_DEFINE_ALLOCATOR(RadioNodeList); -JS::NonnullGCPtr RadioNodeList::create(JS::Realm& realm, Node const& root, Scope scope, Function filter) +JS::NonnullGCPtr RadioNodeList::create(JS::Realm& realm, DOM::Node const& root, Scope scope, Function filter) { return realm.heap().allocate(realm, realm, root, scope, move(filter)); } -RadioNodeList::RadioNodeList(JS::Realm& realm, Node const& root, Scope scope, Function filter) - : LiveNodeList(realm, root, scope, move(filter)) +RadioNodeList::RadioNodeList(JS::Realm& realm, DOM::Node const& root, Scope scope, Function filter) + : DOM::LiveNodeList(realm, root, scope, move(filter)) { } @@ -32,13 +32,13 @@ void RadioNodeList::initialize(JS::Realm& realm) WEB_SET_PROTOTYPE_FOR_INTERFACE(RadioNodeList); } -static HTML::HTMLInputElement const* radio_button(Node const& node) +static HTMLInputElement const* radio_button(DOM::Node const& node) { - if (!is(node)) + if (!is(node)) return nullptr; - auto const& input_element = verify_cast(node); - if (input_element.type_state() != HTML::HTMLInputElement::TypeAttributeState::RadioButton) + auto const& input_element = verify_cast(node); + if (input_element.type_state() != HTMLInputElement::TypeAttributeState::RadioButton) return nullptr; return &input_element; @@ -49,7 +49,7 @@ FlyString RadioNodeList::value() const { // 1. Let element be the first element in tree order represented by the RadioNodeList object that is an input element whose type // attribute is in the Radio Button state and whose checkedness is true. Otherwise, let it be null. - auto* element = verify_cast(first_matching([](Node const& node) -> bool { + auto* element = verify_cast(first_matching([](DOM::Node const& node) -> bool { auto const* button = radio_button(node); if (!button) return false; @@ -63,23 +63,23 @@ FlyString RadioNodeList::value() const // 3. If element is an element with no value attribute, return the string "on". // 4. Otherwise, return the value of element's value attribute. - return element->get_attribute(HTML::AttributeNames::value).value_or("on"_string); + return element->get_attribute(AttributeNames::value).value_or("on"_string); } void RadioNodeList::set_value(FlyString const& value) { - HTML::HTMLInputElement* element = nullptr; + HTMLInputElement* element = nullptr; // 1. If the new value is the string "on": let element be the first element in tree order represented by the RadioNodeList object // that is an input element whose type attribute is in the Radio Button state and whose value content attribute is either absent, // or present and equal to the new value, if any. If no such element exists, then instead let element be null. if (value == "on"sv) { - element = verify_cast(first_matching([&value](auto const& node) { + element = verify_cast(first_matching([&value](auto const& node) { auto const* button = radio_button(node); if (!button) return false; - auto const maybe_value = button->get_attribute(HTML::AttributeNames::value); + auto const maybe_value = button->get_attribute(AttributeNames::value); return !maybe_value.has_value() || maybe_value.value() == value; })); } @@ -87,12 +87,12 @@ void RadioNodeList::set_value(FlyString const& value) // type attribute is in the Radio Button state and whose value content attribute is present and equal to the new value, if any. If // no such element exists, then instead let element be null. else { - element = verify_cast(first_matching([&value](auto const& node) { + element = verify_cast(first_matching([&value](auto const& node) { auto const* button = radio_button(node); if (!button) return false; - auto const maybe_value = button->get_attribute(HTML::AttributeNames::value); + auto const maybe_value = button->get_attribute(AttributeNames::value); return maybe_value.has_value() && maybe_value.value() == value; })); } diff --git a/Userland/Libraries/LibWeb/DOM/RadioNodeList.h b/Userland/Libraries/LibWeb/HTML/RadioNodeList.h similarity index 59% rename from Userland/Libraries/LibWeb/DOM/RadioNodeList.h rename to Userland/Libraries/LibWeb/HTML/RadioNodeList.h index 0e5c52909e0..c8e61ad8df9 100644 --- a/Userland/Libraries/LibWeb/DOM/RadioNodeList.h +++ b/Userland/Libraries/LibWeb/HTML/RadioNodeList.h @@ -8,15 +8,15 @@ #include -namespace Web::DOM { +namespace Web::HTML { // https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#radionodelist -class RadioNodeList : public LiveNodeList { - WEB_PLATFORM_OBJECT(RadioNodeList, LiveNodeList); +class RadioNodeList : public DOM::LiveNodeList { + WEB_PLATFORM_OBJECT(RadioNodeList, DOM::LiveNodeList); JS_DECLARE_ALLOCATOR(RadioNodeList); public: - [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm& realm, Node const& root, Scope scope, ESCAPING Function filter); + [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm& realm, DOM::Node const& root, Scope scope, ESCAPING Function filter); virtual ~RadioNodeList() override; @@ -27,7 +27,7 @@ protected: virtual void initialize(JS::Realm&) override; private: - explicit RadioNodeList(JS::Realm& realm, Node const& root, Scope scope, ESCAPING Function filter); + explicit RadioNodeList(JS::Realm& realm, DOM::Node const& root, Scope scope, ESCAPING Function filter); }; } diff --git a/Userland/Libraries/LibWeb/DOM/RadioNodeList.idl b/Userland/Libraries/LibWeb/HTML/RadioNodeList.idl similarity index 100% rename from Userland/Libraries/LibWeb/DOM/RadioNodeList.idl rename to Userland/Libraries/LibWeb/HTML/RadioNodeList.idl diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 1d0e6201b42..3b5eb8cc689 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -48,7 +48,6 @@ libweb_js_bindings(DOM/AbstractRange) libweb_js_bindings(DOM/Attr) libweb_js_bindings(DOM/AbortController) libweb_js_bindings(DOM/AbortSignal) -libweb_js_bindings(DOM/BeforeUnloadEvent) libweb_js_bindings(DOM/CDATASection) libweb_js_bindings(DOM/CharacterData) libweb_js_bindings(DOM/Comment) @@ -62,7 +61,6 @@ libweb_js_bindings(DOM/Element) libweb_js_bindings(DOM/Event) libweb_js_bindings(DOM/EventTarget) libweb_js_bindings(DOM/HTMLCollection) -libweb_js_bindings(DOM/HTMLFormControlsCollection) libweb_js_bindings(DOM/MutationObserver) libweb_js_bindings(DOM/MutationRecord) libweb_js_bindings(DOM/NamedNodeMap) @@ -71,7 +69,6 @@ libweb_js_bindings(DOM/NodeFilter) libweb_js_bindings(DOM/NodeIterator) libweb_js_bindings(DOM/NodeList) libweb_js_bindings(DOM/ProcessingInstruction) -libweb_js_bindings(DOM/RadioNodeList) libweb_js_bindings(DOM/Range) libweb_js_bindings(DOM/ShadowRoot) libweb_js_bindings(DOM/StaticRange) @@ -102,6 +99,7 @@ libweb_js_bindings(Geometry/DOMRectList) libweb_js_bindings(Geometry/DOMRectReadOnly) libweb_js_bindings(HTML/AudioTrack) libweb_js_bindings(HTML/AudioTrackList) +libweb_js_bindings(HTML/BeforeUnloadEvent) libweb_js_bindings(HTML/BroadcastChannel) libweb_js_bindings(HTML/CanvasGradient) libweb_js_bindings(HTML/CanvasPattern) @@ -144,6 +142,7 @@ libweb_js_bindings(HTML/HTMLElement) libweb_js_bindings(HTML/HTMLEmbedElement) libweb_js_bindings(HTML/HTMLFieldSetElement) libweb_js_bindings(HTML/HTMLFontElement) +libweb_js_bindings(HTML/HTMLFormControlsCollection) libweb_js_bindings(HTML/HTMLFormElement) libweb_js_bindings(HTML/HTMLFrameElement) libweb_js_bindings(HTML/HTMLFrameSetElement) @@ -219,6 +218,7 @@ libweb_js_bindings(HTML/Plugin) libweb_js_bindings(HTML/PluginArray) libweb_js_bindings(HTML/PopStateEvent) libweb_js_bindings(HTML/PromiseRejectionEvent) +libweb_js_bindings(HTML/RadioNodeList) libweb_js_bindings(HTML/ServiceWorker) libweb_js_bindings(HTML/ServiceWorkerContainer) libweb_js_bindings(HTML/ServiceWorkerRegistration)