Browse Source

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.
Luke 4 years ago
parent
commit
ca71ac484b

+ 2 - 2
Userland/Libraries/LibWeb/CSS/StyleInvalidator.cpp

@@ -37,7 +37,7 @@ StyleInvalidator::StyleInvalidator(DOM::Document& document)
     if (!m_document.should_invalidate_styles_on_attribute_changes())
         return;
     auto& style_resolver = m_document.style_resolver();
-    m_document.for_each_in_subtree_of_type<DOM::Element>([&](auto& element) {
+    m_document.for_each_in_inclusive_subtree_of_type<DOM::Element>([&](auto& element) {
         m_elements_and_matching_rules_before.set(&element, style_resolver.collect_matching_rules(element));
         return IterationDecision::Continue;
     });
@@ -48,7 +48,7 @@ StyleInvalidator::~StyleInvalidator()
     if (!m_document.should_invalidate_styles_on_attribute_changes())
         return;
     auto& style_resolver = m_document.style_resolver();
-    m_document.for_each_in_subtree_of_type<DOM::Element>([&](auto& element) {
+    m_document.for_each_in_inclusive_subtree_of_type<DOM::Element>([&](auto& element) {
         auto maybe_matching_rules_before = m_elements_and_matching_rules_before.get(&element);
         if (!maybe_matching_rules_before.has_value()) {
             element.set_needs_style_update(true);

+ 6 - 6
Userland/Libraries/LibWeb/DOM/Document.cpp

@@ -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;
     });

+ 2 - 2
Userland/Libraries/LibWeb/DOM/Element.cpp

@@ -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;

+ 1 - 1
Userland/Libraries/LibWeb/DOM/Node.cpp

@@ -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;
     });

+ 1 - 1
Userland/Libraries/LibWeb/DOM/NonElementParentNode.h

@@ -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;

+ 2 - 2
Userland/Libraries/LibWeb/DOM/ParentNode.cpp

@@ -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);
         }

+ 1 - 1
Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp

@@ -117,7 +117,7 @@ void HTMLFormElement::submit_form(RefPtr<HTMLElement> submitter, bool from_submi
 
     Vector<URLQueryParam> parameters;
 
-    for_each_in_subtree_of_type<HTMLInputElement>([&](auto& node) {
+    for_each_in_inclusive_subtree_of_type<HTMLInputElement>([&](auto& node) {
         auto& input = downcast<HTMLInputElement>(node);
         if (!input.name().is_null() && (input.type() != "submit" || &input == submitter))
             parameters.append({ input.name(), input.value() });

+ 2 - 2
Userland/Libraries/LibWeb/Layout/InitialContainingBlockBox.cpp

@@ -48,7 +48,7 @@ void InitialContainingBlockBox::build_stacking_context_tree()
 
     set_stacking_context(make<StackingContext>(*this, nullptr));
 
-    for_each_in_subtree_of_type<Box>([&](Box& box) {
+    for_each_in_inclusive_subtree_of_type<Box>([&](Box& box) {
         if (&box == this)
             return IterationDecision::Continue;
         if (!box.establishes_stacking_context()) {
@@ -101,7 +101,7 @@ void InitialContainingBlockBox::recompute_selection_states()
 
     auto selection = this->selection().normalized();
 
-    for_each_in_subtree([&](auto& layout_node) {
+    for_each_in_inclusive_subtree([&](auto& layout_node) {
         if (!selection.is_valid()) {
             // Everything gets SelectionState::None.
         } else if (&layout_node == selection.start().layout_node && &layout_node == selection.end().layout_node) {

+ 2 - 2
Userland/Libraries/LibWeb/Layout/Label.cpp

@@ -120,7 +120,7 @@ Label* Label::label_for_control_node(LabelableNode& control)
     if (id.is_empty())
         return label;
 
-    control.document().layout_node()->for_each_in_subtree_of_type<Label>([&](auto& node) {
+    control.document().layout_node()->for_each_in_inclusive_subtree_of_type<Label>([&](auto& node) {
         if (node.dom_node().for_() == id) {
             label = &node;
             return IterationDecision::Break;
@@ -144,7 +144,7 @@ LabelableNode* Label::control_node()
     if (for_.is_empty())
         return control;
 
-    document().layout_node()->for_each_in_subtree_of_type<LabelableNode>([&](auto& node) {
+    document().layout_node()->for_each_in_inclusive_subtree_of_type<LabelableNode>([&](auto& node) {
         if (node.dom_node().attribute(HTML::AttributeNames::id) == for_) {
             control = &node;
             return IterationDecision::Break;

+ 1 - 1
Userland/Libraries/LibWeb/Layout/RadioButton.cpp

@@ -139,7 +139,7 @@ void RadioButton::set_checked_within_group()
     dom_node().set_checked(true);
     String name = dom_node().name();
 
-    document().for_each_in_subtree_of_type<HTML::HTMLInputElement>([&](auto& element) {
+    document().for_each_in_inclusive_subtree_of_type<HTML::HTMLInputElement>([&](auto& element) {
         if (element.checked() && (element.layout_node() != this) && (element.name() == name))
             element.set_checked(false);
         return IterationDecision::Continue;

+ 1 - 1
Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp

@@ -155,7 +155,7 @@ RefPtr<Node> TreeBuilder::build(DOM::Node& dom_node)
 template<CSS::Display display, typename Callback>
 void TreeBuilder::for_each_in_tree_with_display(NodeWithStyle& root, Callback callback)
 {
-    root.for_each_in_subtree_of_type<Box>([&](auto& box) {
+    root.for_each_in_inclusive_subtree_of_type<Box>([&](auto& box) {
         if (box.computed_values().display() == display)
             callback(box);
         return IterationDecision::Continue;

+ 8 - 8
Userland/Libraries/LibWeb/TreeNode.h

@@ -140,52 +140,52 @@ public:
     }
 
     template<typename Callback>
-    IterationDecision for_each_in_subtree(Callback callback) const
+    IterationDecision for_each_in_inclusive_subtree(Callback callback) const
     {
         if (callback(static_cast<const T&>(*this)) == IterationDecision::Break)
             return IterationDecision::Break;
         for (auto* child = first_child(); child; child = child->next_sibling()) {
-            if (child->for_each_in_subtree(callback) == IterationDecision::Break)
+            if (child->for_each_in_inclusive_subtree(callback) == IterationDecision::Break)
                 return IterationDecision::Break;
         }
         return IterationDecision::Continue;
     }
 
     template<typename Callback>
-    IterationDecision for_each_in_subtree(Callback callback)
+    IterationDecision for_each_in_inclusive_subtree(Callback callback)
     {
         if (callback(static_cast<T&>(*this)) == IterationDecision::Break)
             return IterationDecision::Break;
         for (auto* child = first_child(); child; child = child->next_sibling()) {
-            if (child->for_each_in_subtree(callback) == IterationDecision::Break)
+            if (child->for_each_in_inclusive_subtree(callback) == IterationDecision::Break)
                 return IterationDecision::Break;
         }
         return IterationDecision::Continue;
     }
 
     template<typename U, typename Callback>
-    IterationDecision for_each_in_subtree_of_type(Callback callback)
+    IterationDecision for_each_in_inclusive_subtree_of_type(Callback callback)
     {
         if (is<U>(static_cast<const T&>(*this))) {
             if (callback(static_cast<U&>(*this)) == IterationDecision::Break)
                 return IterationDecision::Break;
         }
         for (auto* child = first_child(); child; child = child->next_sibling()) {
-            if (child->template for_each_in_subtree_of_type<U>(callback) == IterationDecision::Break)
+            if (child->template for_each_in_inclusive_subtree_of_type<U>(callback) == IterationDecision::Break)
                 return IterationDecision::Break;
         }
         return IterationDecision::Continue;
     }
 
     template<typename U, typename Callback>
-    IterationDecision for_each_in_subtree_of_type(Callback callback) const
+    IterationDecision for_each_in_inclusive_subtree_of_type(Callback callback) const
     {
         if (is<U>(static_cast<const T&>(*this))) {
             if (callback(static_cast<const U&>(*this)) == IterationDecision::Break)
                 return IterationDecision::Break;
         }
         for (auto* child = first_child(); child; child = child->next_sibling()) {
-            if (child->template for_each_in_subtree_of_type<U>(callback) == IterationDecision::Break)
+            if (child->template for_each_in_inclusive_subtree_of_type<U>(callback) == IterationDecision::Break)
                 return IterationDecision::Break;
         }
         return IterationDecision::Continue;