diff options
author | Andreas Kling <kling@serenityos.org> | 2022-03-09 14:34:32 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-09 16:43:00 +0100 |
commit | fabcee016f42f7d56d76496b2a86d7e28ba5b385 (patch) | |
tree | fd3c850d8539b8c899e8a1ac7189709be6e015b3 /Meta/Lagom | |
parent | ba87f23f22b274232d83e9c8ce3b537a7e486f32 (diff) | |
download | serenity-fabcee016f42f7d56d76496b2a86d7e28ba5b385.zip |
LibWeb: Add basic support for DOM's NodeIterator and NodeFilter
This patch adds NodeIterator (created via Document.createNodeIterator())
which allows you to iterate through all the nodes in a subtree while
filtering with a provided NodeFilter callback along the way.
This first cut implements the full API, but does not yet handle nodes
being removed from the document while referenced by the iterator. That
will be done in a subsequent patch.
Diffstat (limited to 'Meta/Lagom')
-rw-r--r-- | Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp index 2d979e28c6..f5372124bb 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp @@ -320,18 +320,23 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter )~~~"); } } - } else if (parameter.type->name == "EventListener") { + } else if (parameter.type->name.is_one_of("EventListener", "NodeFilter")) { // FIXME: Replace this with support for callback interfaces. https://heycam.github.io/webidl/#idl-callback-interface + if (parameter.type->name == "EventListener") + scoped_generator.set("cpp_type", "IDLEventListener"); + else + scoped_generator.set("cpp_type", parameter.type->name); + if (parameter.type->nullable) { scoped_generator.append(R"~~~( - RefPtr<IDLEventListener> @cpp_name@; + RefPtr<@cpp_type@> @cpp_name@; if (!@js_name@@js_suffix@.is_nullish()) { if (!@js_name@@js_suffix@.is_object()) return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObject, @js_name@@js_suffix@.to_string_without_side_effects()); CallbackType callback_type(JS::make_handle(&@js_name@@js_suffix@.as_object()), HTML::incumbent_settings_object()); - @cpp_name@ = adopt_ref(*new IDLEventListener(move(callback_type))); + @cpp_name@ = adopt_ref(*new @cpp_type@(move(callback_type))); } )~~~"); } else { @@ -340,7 +345,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObject, @js_name@@js_suffix@.to_string_without_side_effects()); CallbackType callback_type(JS::make_handle(&@js_name@@js_suffix@.as_object()), HTML::incumbent_settings_object()); - auto @cpp_name@ = adopt_ref(*new IDLEventListener(move(callback_type))); + auto @cpp_name@ = adopt_ref(*new @cpp_type@(move(callback_type))); )~~~"); } } else if (IDL::is_wrappable_type(*parameter.type)) { @@ -2803,6 +2808,7 @@ void generate_prototype_implementation(IDL::Interface const& interface) #include <LibWeb/DOM/Element.h> #include <LibWeb/DOM/Event.h> #include <LibWeb/DOM/IDLEventListener.h> +#include <LibWeb/DOM/NodeFilter.h> #include <LibWeb/DOM/Range.h> #include <LibWeb/HTML/Scripting/Environments.h> #include <LibWeb/HTML/Window.h> |