mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-06 16:19:23 +00:00
LibWeb: Move get_elements_by_name implementation to ParentNode
Previously, we had two implementations of the same function in `Document` and `Element`, which had inadvertantly diverged.
This commit is contained in:
parent
f666d967d6
commit
faf64bfb41
Notes:
github-actions[bot]
2024-07-23 06:59:24 +00:00
Author: https://github.com/tcl3
Commit: faf64bfb41
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/773
6 changed files with 18 additions and 33 deletions
|
@ -1401,21 +1401,6 @@ JS::NonnullGCPtr<HTMLCollection> Document::get_elements_by_name(FlyString const&
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::NonnullGCPtr<HTMLCollection> Document::get_elements_by_class_name(StringView class_names)
|
|
||||||
{
|
|
||||||
Vector<FlyString> list_of_class_names;
|
|
||||||
for (auto& name : class_names.split_view(' ')) {
|
|
||||||
list_of_class_names.append(FlyString::from_utf8(name).release_value_but_fixme_should_propagate_errors());
|
|
||||||
}
|
|
||||||
return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [list_of_class_names = move(list_of_class_names), quirks_mode = document().in_quirks_mode()](Element const& element) {
|
|
||||||
for (auto& name : list_of_class_names) {
|
|
||||||
if (!element.has_class(name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-applets
|
// https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-applets
|
||||||
JS::NonnullGCPtr<HTMLCollection> Document::applets()
|
JS::NonnullGCPtr<HTMLCollection> Document::applets()
|
||||||
{
|
{
|
||||||
|
|
|
@ -249,7 +249,6 @@ public:
|
||||||
void schedule_layout_update();
|
void schedule_layout_update();
|
||||||
|
|
||||||
JS::NonnullGCPtr<HTMLCollection> get_elements_by_name(FlyString const&);
|
JS::NonnullGCPtr<HTMLCollection> get_elements_by_name(FlyString const&);
|
||||||
JS::NonnullGCPtr<HTMLCollection> get_elements_by_class_name(StringView);
|
|
||||||
|
|
||||||
JS::NonnullGCPtr<HTMLCollection> applets();
|
JS::NonnullGCPtr<HTMLCollection> applets();
|
||||||
JS::NonnullGCPtr<HTMLCollection> anchors();
|
JS::NonnullGCPtr<HTMLCollection> anchors();
|
||||||
|
|
|
@ -814,21 +814,6 @@ bool Element::is_document_element() const
|
||||||
return parent() == &document();
|
return parent() == &document();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::NonnullGCPtr<HTMLCollection> Element::get_elements_by_class_name(StringView class_names)
|
|
||||||
{
|
|
||||||
Vector<FlyString> list_of_class_names;
|
|
||||||
for (auto& name : class_names.split_view_if(Infra::is_ascii_whitespace)) {
|
|
||||||
list_of_class_names.append(FlyString::from_utf8(name).release_value_but_fixme_should_propagate_errors());
|
|
||||||
}
|
|
||||||
return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [list_of_class_names = move(list_of_class_names), quirks_mode = document().in_quirks_mode()](Element const& element) {
|
|
||||||
for (auto& name : list_of_class_names) {
|
|
||||||
if (!element.has_class(name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#element-shadow-host
|
// https://dom.spec.whatwg.org/#element-shadow-host
|
||||||
bool Element::is_shadow_host() const
|
bool Element::is_shadow_host() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -212,8 +212,6 @@ public:
|
||||||
bool is_target() const;
|
bool is_target() const;
|
||||||
bool is_document_element() const;
|
bool is_document_element() const;
|
||||||
|
|
||||||
JS::NonnullGCPtr<HTMLCollection> get_elements_by_class_name(StringView);
|
|
||||||
|
|
||||||
bool is_shadow_host() const;
|
bool is_shadow_host() const;
|
||||||
JS::GCPtr<ShadowRoot> shadow_root() { return m_shadow_root; }
|
JS::GCPtr<ShadowRoot> shadow_root() { return m_shadow_root; }
|
||||||
JS::GCPtr<ShadowRoot const> shadow_root() const { return m_shadow_root; }
|
JS::GCPtr<ShadowRoot const> shadow_root() const { return m_shadow_root; }
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <LibWeb/DOM/ParentNode.h>
|
#include <LibWeb/DOM/ParentNode.h>
|
||||||
#include <LibWeb/DOM/StaticNodeList.h>
|
#include <LibWeb/DOM/StaticNodeList.h>
|
||||||
#include <LibWeb/Dump.h>
|
#include <LibWeb/Dump.h>
|
||||||
|
#include <LibWeb/Infra/CharacterTypes.h>
|
||||||
#include <LibWeb/Infra/Strings.h>
|
#include <LibWeb/Infra/Strings.h>
|
||||||
#include <LibWeb/Namespace.h>
|
#include <LibWeb/Namespace.h>
|
||||||
|
|
||||||
|
@ -225,4 +226,19 @@ WebIDL::ExceptionOr<void> ParentNode::replace_children(Vector<Variant<JS::Handle
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JS::NonnullGCPtr<HTMLCollection> ParentNode::get_elements_by_class_name(StringView class_names)
|
||||||
|
{
|
||||||
|
Vector<FlyString> list_of_class_names;
|
||||||
|
for (auto& name : class_names.split_view_if(Infra::is_ascii_whitespace)) {
|
||||||
|
list_of_class_names.append(FlyString::from_utf8(name).release_value_but_fixme_should_propagate_errors());
|
||||||
|
}
|
||||||
|
return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [list_of_class_names = move(list_of_class_names), quirks_mode = document().in_quirks_mode()](Element const& element) {
|
||||||
|
for (auto& name : list_of_class_names) {
|
||||||
|
if (!element.has_class(name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,8 @@ public:
|
||||||
WebIDL::ExceptionOr<void> append(Vector<Variant<JS::Handle<Node>, String>> const& nodes);
|
WebIDL::ExceptionOr<void> append(Vector<Variant<JS::Handle<Node>, String>> const& nodes);
|
||||||
WebIDL::ExceptionOr<void> replace_children(Vector<Variant<JS::Handle<Node>, String>> const& nodes);
|
WebIDL::ExceptionOr<void> replace_children(Vector<Variant<JS::Handle<Node>, String>> const& nodes);
|
||||||
|
|
||||||
|
JS::NonnullGCPtr<HTMLCollection> get_elements_by_class_name(StringView);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ParentNode(JS::Realm& realm, Document& document, NodeType type)
|
ParentNode(JS::Realm& realm, Document& document, NodeType type)
|
||||||
: Node(realm, document, type)
|
: Node(realm, document, type)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue