1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 20:47:45 +00:00

LibWeb: Support getElementsByTagName() properly in non-HTML documents

This commit is contained in:
Andreas Kling 2022-09-18 00:39:42 +02:00
parent bd0648a492
commit 6b3293a74b

View file

@ -1,11 +1,13 @@
/* /*
* Copyright (c) 2020, Luke Wilde <lukew@serenityos.org> * Copyright (c) 2020, Luke Wilde <lukew@serenityos.org>
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <LibWeb/CSS/Parser/Parser.h> #include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/SelectorEngine.h> #include <LibWeb/CSS/SelectorEngine.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/HTMLCollection.h> #include <LibWeb/DOM/HTMLCollection.h>
#include <LibWeb/DOM/NodeOperations.h> #include <LibWeb/DOM/NodeOperations.h>
#include <LibWeb/DOM/ParentNode.h> #include <LibWeb/DOM/ParentNode.h>
@ -104,8 +106,8 @@ JS::NonnullGCPtr<HTMLCollection> ParentNode::get_elements_by_tag_name(FlyString
}); });
} }
// FIXME: 2. Otherwise, if roots node document is an HTML document, return a HTMLCollection rooted at root, whose filter matches the following descendant elements: // 2. Otherwise, if roots node document is an HTML document, return a HTMLCollection rooted at root, whose filter matches the following descendant elements:
// (It is currently always a HTML document) if (root().document().document_type() == Document::Type::HTML) {
return HTMLCollection::create(*this, [qualified_name](Element const& element) { return HTMLCollection::create(*this, [qualified_name](Element const& element) {
// - Whose namespace is the HTML namespace and whose qualified name is qualifiedName, in ASCII lowercase. // - Whose namespace is the HTML namespace and whose qualified name is qualifiedName, in ASCII lowercase.
if (element.namespace_() == Namespace::HTML) if (element.namespace_() == Namespace::HTML)
@ -114,8 +116,12 @@ JS::NonnullGCPtr<HTMLCollection> ParentNode::get_elements_by_tag_name(FlyString
// - Whose namespace is not the HTML namespace and whose qualified name is qualifiedName. // - Whose namespace is not the HTML namespace and whose qualified name is qualifiedName.
return element.qualified_name() == qualified_name; return element.qualified_name() == qualified_name;
}); });
}
// FIXME: 3. Otherwise, return a HTMLCollection rooted at root, whose filter matches descendant elements whose qualified name is qualifiedName. // 3. Otherwise, return a HTMLCollection rooted at root, whose filter matches descendant elements whose qualified name is qualifiedName.
return HTMLCollection::create(*this, [qualified_name](Element const& element) {
return element.qualified_name() == qualified_name;
});
} }
// https://dom.spec.whatwg.org/#concept-getelementsbytagnamens // https://dom.spec.whatwg.org/#concept-getelementsbytagnamens