1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10:17:35 +00:00

LibWeb: Rename "for_each_in_subtree(_of_type)" to "for_each_in_inclusive_subtree(_of_type)"

This is because it includes the initial node that the function was
called on, which makes it "inclusive" as according to the spec.

This is important as there are non-inclusive variants, particularly
used in the node mutation algorithms.
This commit is contained in:
Luke 2021-04-06 18:38:10 +01:00 committed by Andreas Kling
parent f482628fe5
commit ca71ac484b
12 changed files with 29 additions and 29 deletions

View file

@ -114,7 +114,7 @@ void Document::removed_last_ref()
// Gather up all the descendants of this document and prune them from the tree.
// FIXME: This could definitely be more elegant.
NonnullRefPtrVector<Node> descendants;
for_each_in_subtree([&](auto& node) {
for_each_in_inclusive_subtree([&](auto& node) {
if (&node != this)
descendants.append(node);
return IterationDecision::Continue;
@ -316,7 +316,7 @@ void Document::tear_down_layout_tree()
NonnullRefPtrVector<Layout::Node> layout_nodes;
m_layout_root->for_each_in_subtree([&](auto& layout_node) {
m_layout_root->for_each_in_inclusive_subtree([&](auto& layout_node) {
layout_nodes.append(layout_node);
return IterationDecision::Continue;
});
@ -505,7 +505,7 @@ void Document::set_hovered_node(Node* node)
NonnullRefPtrVector<Element> Document::get_elements_by_name(const String& name) const
{
NonnullRefPtrVector<Element> elements;
for_each_in_subtree_of_type<Element>([&](auto& element) {
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
if (element.attribute(HTML::AttributeNames::name) == name)
elements.append(element);
return IterationDecision::Continue;
@ -518,7 +518,7 @@ NonnullRefPtrVector<Element> Document::get_elements_by_tag_name(const FlyString&
// FIXME: Support "*" for tag_name
// https://dom.spec.whatwg.org/#concept-getelementsbytagname
NonnullRefPtrVector<Element> elements;
for_each_in_subtree_of_type<Element>([&](auto& element) {
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
if (element.namespace_() == Namespace::HTML
? element.local_name().to_lowercase() == tag_name.to_lowercase()
: element.local_name() == tag_name) {
@ -532,7 +532,7 @@ NonnullRefPtrVector<Element> Document::get_elements_by_tag_name(const FlyString&
NonnullRefPtrVector<Element> Document::get_elements_by_class_name(const FlyString& class_name) const
{
NonnullRefPtrVector<Element> elements;
for_each_in_subtree_of_type<Element>([&](auto& element) {
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
if (element.has_class(class_name, in_quirks_mode() ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive))
elements.append(element);
return IterationDecision::Continue;
@ -661,7 +661,7 @@ NonnullRefPtrVector<HTML::HTMLScriptElement> Document::take_scripts_to_execute_a
void Document::adopt_node(Node& subtree_root)
{
subtree_root.for_each_in_subtree([&](auto& node) {
subtree_root.for_each_in_inclusive_subtree([&](auto& node) {
node.set_document({}, *this);
return IterationDecision::Continue;
});

View file

@ -350,7 +350,7 @@ NonnullRefPtrVector<Element> Element::get_elements_by_tag_name(const FlyString&
// FIXME: Support "*" for tag_name
// https://dom.spec.whatwg.org/#concept-getelementsbytagname
NonnullRefPtrVector<Element> elements;
for_each_in_subtree_of_type<Element>([&](auto& element) {
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
if (element.namespace_() == Namespace::HTML
? element.local_name().to_lowercase() == tag_name.to_lowercase()
: element.local_name() == tag_name) {
@ -364,7 +364,7 @@ NonnullRefPtrVector<Element> Element::get_elements_by_tag_name(const FlyString&
NonnullRefPtrVector<Element> Element::get_elements_by_class_name(const FlyString& class_name) const
{
NonnullRefPtrVector<Element> elements;
for_each_in_subtree_of_type<Element>([&](auto& element) {
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
if (element.has_class(class_name, m_document->in_quirks_mode() ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive))
elements.append(element);
return IterationDecision::Continue;

View file

@ -114,7 +114,7 @@ RefPtr<Layout::Node> Node::create_layout_node()
void Node::invalidate_style()
{
for_each_in_subtree_of_type<Element>([&](auto& element) {
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
element.set_needs_style_update(true);
return IterationDecision::Continue;
});

View file

@ -39,7 +39,7 @@ public:
RefPtr<Element> get_element_by_id(const FlyString& id) const
{
RefPtr<Element> found_element;
static_cast<const NodeType*>(this)->template for_each_in_subtree_of_type<Element>([&](auto& element) {
static_cast<const NodeType*>(this)->template for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
if (element.attribute(HTML::AttributeNames::id) == id) {
found_element = &element;
return IterationDecision::Break;

View file

@ -40,7 +40,7 @@ RefPtr<Element> ParentNode::query_selector(const StringView& selector_text)
dump_selector(selector.value());
RefPtr<Element> result;
for_each_in_subtree_of_type<Element>([&](auto& element) {
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
if (SelectorEngine::matches(selector.value(), element)) {
result = element;
return IterationDecision::Break;
@ -60,7 +60,7 @@ NonnullRefPtrVector<Element> ParentNode::query_selector_all(const StringView& se
dump_selector(selector.value());
NonnullRefPtrVector<Element> elements;
for_each_in_subtree_of_type<Element>([&](auto& element) {
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
if (SelectorEngine::matches(selector.value(), element)) {
elements.append(element);
}