1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:08:10 +00:00

LibWeb: Use the element factory in clone_node

It was directly creating a new Element object instead of creating the
appropriate element.

For example, document.body.cloneNode(true) would return an Element
instead of an HTMLBodyElement.
This commit is contained in:
Luke 2021-07-05 05:28:29 +01:00 committed by Andreas Kling
parent 5430bc8963
commit e4ae1cdd1f

View file

@ -15,6 +15,7 @@
#include <LibWeb/DOM/Comment.h>
#include <LibWeb/DOM/DocumentType.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/ElementFactory.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/EventDispatcher.h>
#include <LibWeb/DOM/EventListener.h>
@ -412,8 +413,7 @@ NonnullRefPtr<Node> Node::clone_node(Document* document, bool clone_children) co
RefPtr<Node> copy;
if (is<Element>(this)) {
auto& element = *verify_cast<Element>(this);
auto qualified_name = QualifiedName(element.local_name(), element.prefix(), element.namespace_());
auto element_copy = adopt_ref(*new Element(*document, move(qualified_name)));
auto element_copy = DOM::create_element(*document, element.local_name(), element.namespace_() /* FIXME: nodes namespace prefix, and nodes is value, with the synchronous custom elements flag unset */);
element.for_each_attribute([&](auto& name, auto& value) {
element_copy->set_attribute(name, value);
});