From 398bf10b92b4496239f94d6548190bf280843cc7 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sat, 4 May 2024 14:47:04 +0100 Subject: [PATCH] LibWeb: Use `TraversalDecision` for multi level Node traversal methods This adds the `SkipChildrenAndContinue` option, where traversal continues but child nodes are not included. --- .../LibWeb/Animations/KeyframeEffect.cpp | 4 +- Userland/Libraries/LibWeb/DOM/Document.cpp | 32 +++---- Userland/Libraries/LibWeb/DOM/Element.cpp | 8 +- .../Libraries/LibWeb/DOM/HTMLCollection.cpp | 2 +- .../Libraries/LibWeb/DOM/LiveNodeList.cpp | 6 +- Userland/Libraries/LibWeb/DOM/Node.cpp | 10 +-- Userland/Libraries/LibWeb/DOM/Node.h | 85 ++++++++++--------- .../LibWeb/DOM/NonElementParentNode.h | 8 +- Userland/Libraries/LibWeb/DOM/ParentNode.cpp | 6 +- Userland/Libraries/LibWeb/DOM/Range.cpp | 2 +- Userland/Libraries/LibWeb/DOM/ShadowRoot.h | 28 +++--- Userland/Libraries/LibWeb/DOM/Slottable.cpp | 10 +-- Userland/Libraries/LibWeb/Forward.h | 1 + .../Libraries/LibWeb/HTML/BrowsingContext.h | 40 ++++----- .../CustomElements/CustomElementRegistry.cpp | 8 +- .../LibWeb/HTML/FormAssociatedElement.cpp | 4 +- .../LibWeb/HTML/HTMLAllCollection.cpp | 2 +- .../LibWeb/HTML/HTMLDetailsElement.cpp | 6 +- .../Libraries/LibWeb/HTML/HTMLFormElement.cpp | 8 +- .../LibWeb/HTML/HTMLInputElement.cpp | 6 +- .../LibWeb/HTML/HTMLLabelElement.cpp | 8 +- Userland/Libraries/LibWeb/HTML/Window.cpp | 14 +-- .../LibWeb/Layout/FormattingContext.cpp | 12 +-- Userland/Libraries/LibWeb/Layout/Label.cpp | 4 +- .../Libraries/LibWeb/Layout/LayoutState.cpp | 4 +- .../Libraries/LibWeb/Layout/TableGrid.cpp | 2 +- .../Libraries/LibWeb/Layout/TreeBuilder.cpp | 12 +-- .../Libraries/LibWeb/Painting/Paintable.h | 6 -- .../LibWeb/Painting/PaintableBox.cpp | 4 +- Userland/Libraries/LibWeb/SVG/SVGElement.cpp | 4 +- Userland/Libraries/LibWeb/TraversalDecision.h | 17 ++++ Userland/Libraries/LibWeb/TreeNode.h | 79 ++++++++--------- .../WebContent/ConnectionFromClient.cpp | 2 +- 33 files changed, 229 insertions(+), 215 deletions(-) create mode 100644 Userland/Libraries/LibWeb/TraversalDecision.h diff --git a/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp b/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp index 101bf8a1d43..9708a42bab5 100644 --- a/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp +++ b/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp @@ -923,7 +923,7 @@ void KeyframeEffect::update_style_properties() target->for_each_in_subtree_of_type([&](auto& element) { auto* element_style = element.computed_css_values(); if (!element_style || !element.layout_node()) - return IterationDecision::Continue; + return TraversalDecision::Continue; for (auto i = to_underlying(CSS::first_property_id); i <= to_underlying(CSS::last_property_id); ++i) { if (element_style->is_property_inherited(static_cast(i))) { @@ -933,7 +933,7 @@ void KeyframeEffect::update_style_properties() } element.layout_node()->apply_style(*element_style); - return IterationDecision::Continue; + return TraversalDecision::Continue; }); auto invalidation = compute_required_invalidation(animated_properties_before_update, style->animated_property_values()); diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 16bd829ffda..72e22d44a51 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -751,7 +751,7 @@ JS::GCPtr Document::title_element() for_each_in_subtree_of_type([&](auto& title_element_in_tree) { title_element = title_element_in_tree; - return IterationDecision::Break; + return TraversalDecision::Break; }); return title_element; @@ -931,10 +931,10 @@ void Document::update_base_element(Badge) for_each_in_subtree_of_type([&base_element](HTML::HTMLBaseElement const& base_element_in_tree) { if (base_element_in_tree.has_attribute(HTML::AttributeNames::href)) { base_element = &base_element_in_tree; - return IterationDecision::Break; + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); m_first_base_element_with_href_in_tree_order = base_element; @@ -1757,7 +1757,7 @@ void Document::adopt_node(Node& node) // FIXME: 2. If inclusiveDescendant is an element, then set the node document of each attribute in inclusiveDescendant’s // attribute list to document. - return IterationDecision::Continue; + return TraversalDecision::Continue; }); // 2. For each inclusiveDescendant in node’s shadow-including inclusive descendants that is custom, @@ -1765,7 +1765,7 @@ void Document::adopt_node(Node& node) // and an argument list containing oldDocument and document. node.for_each_shadow_including_inclusive_descendant([&](DOM::Node& inclusive_descendant) { if (!is(inclusive_descendant)) - return IterationDecision::Continue; + return TraversalDecision::Continue; auto& element = static_cast(inclusive_descendant); if (element.is_custom()) { @@ -1778,14 +1778,14 @@ void Document::adopt_node(Node& node) element.enqueue_a_custom_element_callback_reaction(HTML::CustomElementReactionNames::adoptedCallback, move(arguments)); } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); // 3. For each inclusiveDescendant in node’s shadow-including inclusive descendants, in shadow-including tree order, // run the adopting steps with inclusiveDescendant and oldDocument. node.for_each_shadow_including_inclusive_descendant([&](auto& inclusive_descendant) { inclusive_descendant.adopted_from(old_document); - return IterationDecision::Continue; + return TraversalDecision::Continue; }); // Transfer NodeIterators rooted at `node` from old_document to this document. @@ -1951,9 +1951,9 @@ Element* Document::find_a_potential_indicated_element(FlyString const& fragment) root().for_each_in_subtree_of_type([&](Element const& element) { if (element.name() == fragment) { element_with_name = const_cast(&element); - return IterationDecision::Break; + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); if (element_with_name) return element_with_name; @@ -2959,12 +2959,12 @@ Vector> Document::descendant_navigables() auto& navigable_container = static_cast(node); // 1. If navigableContainer's content navigable is null, then continue. if (!navigable_container.content_navigable()) - return IterationDecision::Continue; + return TraversalDecision::Continue; // 2. Extend navigables with navigableContainer's content navigable's active document's inclusive descendant navigables. navigables.extend(navigable_container.content_navigable()->active_document()->inclusive_descendant_navigables()); } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); // 4. Return navigables. @@ -3041,10 +3041,10 @@ Vector> Document::document_tree_child_navigables() for_each_in_subtree_of_type([&](HTML::NavigableContainer& navigable_container) { // 1. If navigableContainer's content navigable is null, then continue. if (!navigable_container.content_navigable()) - return IterationDecision::Continue; + return TraversalDecision::Continue; // 2. Append navigableContainer's content navigable to navigables. navigables.append(*navigable_container.content_navigable()); - return IterationDecision::Continue; + return TraversalDecision::Continue; }); // 5. Return navigables. @@ -4509,9 +4509,9 @@ Element const* Document::element_from_point(double x, double y) auto* dom_node = result.dom_node(); if (dom_node && dom_node->is_element()) { hit_test_result = result; - return Painting::TraversalDecision::Break; + return TraversalDecision::Break; } - return Painting::TraversalDecision::Continue; + return TraversalDecision::Continue; }); } if (hit_test_result.has_value()) @@ -4551,7 +4551,7 @@ Vector> Document::elements_from_point(double x, double auto* dom_node = result.dom_node(); if (dom_node && dom_node->is_element()) sequence.append(*static_cast(dom_node)); - return Painting::TraversalDecision::Continue; + return TraversalDecision::Continue; }); } diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 8e5455b1bf4..038e379ec61 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -2290,11 +2290,11 @@ Element::Directionality Element::directionality() const // Discard not-allowed ancestors for (auto* ancestor = text_node.parent(); ancestor && ancestor != this; ancestor = ancestor->parent()) { if (is(*ancestor) || is(*ancestor) || is(*ancestor)) - return IterationDecision::Continue; + return TraversalDecision::Continue; if (ancestor->is_element()) { auto ancestor_element = static_cast(ancestor); if (ancestor_element->dir().has_value()) - return IterationDecision::Continue; + return TraversalDecision::Continue; } } @@ -2304,11 +2304,11 @@ Element::Directionality Element::directionality() const if (first_is_one_of(bidi_class, bidirectional_class_L, bidirectional_class_AL, bidirectional_class_R)) { found_character = code_point; found_character_bidi_class = bidi_class; - return IterationDecision::Break; + return TraversalDecision::Break; } } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); // If such a character is found and it is of bidirectional character type AL or R, diff --git a/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp b/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp index 0c045247d27..2286f91d124 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp +++ b/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp @@ -61,7 +61,7 @@ void HTMLCollection::update_cache_if_needed() const m_root->for_each_in_subtree_of_type([&](auto& element) { if (m_filter(element)) m_cached_elements.append(element); - return IterationDecision::Continue; + return TraversalDecision::Continue; }); } else { m_root->for_each_child_of_type([&](auto& element) { diff --git a/Userland/Libraries/LibWeb/DOM/LiveNodeList.cpp b/Userland/Libraries/LibWeb/DOM/LiveNodeList.cpp index c03ba4ec183..417a9de1c84 100644 --- a/Userland/Libraries/LibWeb/DOM/LiveNodeList.cpp +++ b/Userland/Libraries/LibWeb/DOM/LiveNodeList.cpp @@ -42,7 +42,7 @@ JS::MarkedVector LiveNodeList::collection() const m_root->for_each_in_subtree([&](auto& node) { if (m_filter(node)) nodes.append(const_cast(&node)); - return IterationDecision::Continue; + return TraversalDecision::Continue; }); } else { m_root->for_each_child([&](auto& node) { @@ -61,9 +61,9 @@ Node* LiveNodeList::first_matching(Function const& filter) co m_root->for_each_in_subtree([&](auto& node) { if (m_filter(node) && filter(node)) { matched_node = const_cast(&node); - return IterationDecision::Break; + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); } else { m_root->for_each_child([&](auto& node) { diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 48a733d56e7..94e05acb360 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -149,7 +149,7 @@ String Node::descendant_text_content() const StringBuilder builder; for_each_in_subtree_of_type([&](auto& text_node) { builder.append(text_node.data()); - return IterationDecision::Continue; + return TraversalDecision::Continue; }); return builder.to_string_without_validation(); } @@ -281,7 +281,7 @@ void Node::invalidate_style() if (shadow_root->has_children()) shadow_root->m_child_needs_style_update = true; } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); for (auto* ancestor = parent_or_shadow_host(); ancestor; ancestor = ancestor->parent_or_shadow_host()) ancestor->m_child_needs_style_update = true; @@ -507,7 +507,7 @@ void Node::insert_before(JS::NonnullGCPtr node, JS::GCPtr child, boo } } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); } @@ -646,7 +646,7 @@ void Node::remove(bool suppress_observers) for_each_in_inclusive_subtree_of_type([&](auto const&) { has_descendent_slot = true; - return IterationDecision::Break; + return TraversalDecision::Break; }); if (has_descendent_slot) { @@ -692,7 +692,7 @@ void Node::remove(bool suppress_observers) } } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); // 19. For each inclusive ancestor inclusiveAncestor of parent, and then for each registered of inclusiveAncestor’s registered observer list, diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h index 10f0aff3051..8342e933d8e 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.h +++ b/Userland/Libraries/LibWeb/DOM/Node.h @@ -16,6 +16,7 @@ #include #include #include +#include #include namespace Web::DOM { @@ -274,11 +275,11 @@ public: // https://dom.spec.whatwg.org/#concept-shadow-including-inclusive-descendant template - IterationDecision for_each_shadow_including_inclusive_descendant(Callback); + TraversalDecision for_each_shadow_including_inclusive_descendant(Callback); // https://dom.spec.whatwg.org/#concept-shadow-including-descendant template - IterationDecision for_each_shadow_including_descendant(Callback); + TraversalDecision for_each_shadow_including_descendant(Callback); Slottable as_slottable(); @@ -460,95 +461,95 @@ public: } template - IterationDecision for_each_in_inclusive_subtree(Callback callback) const + TraversalDecision for_each_in_inclusive_subtree(Callback callback) const { - if (callback(static_cast(*this)) == IterationDecision::Break) - return IterationDecision::Break; + if (auto decision = callback(static_cast(*this)); decision != TraversalDecision::Continue) + return decision; for (auto* child = first_child(); child; child = child->next_sibling()) { - if (child->for_each_in_inclusive_subtree(callback) == IterationDecision::Break) - return IterationDecision::Break; + if (child->for_each_in_inclusive_subtree(callback) == TraversalDecision::Break) + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; } template - IterationDecision for_each_in_inclusive_subtree(Callback callback) + TraversalDecision for_each_in_inclusive_subtree(Callback callback) { - if (callback(static_cast(*this)) == IterationDecision::Break) - return IterationDecision::Break; + if (auto decision = callback(static_cast(*this)); decision != TraversalDecision::Continue) + return decision; for (auto* child = first_child(); child; child = child->next_sibling()) { - if (child->for_each_in_inclusive_subtree(callback) == IterationDecision::Break) - return IterationDecision::Break; + if (child->for_each_in_inclusive_subtree(callback) == TraversalDecision::Break) + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; } template - IterationDecision for_each_in_inclusive_subtree_of_type(Callback callback) + TraversalDecision for_each_in_inclusive_subtree_of_type(Callback callback) { if (is(static_cast(*this))) { - if (callback(static_cast(*this)) == IterationDecision::Break) - return IterationDecision::Break; + if (auto decision = callback(static_cast(*this)); decision != TraversalDecision::Continue) + return decision; } for (auto* child = first_child(); child; child = child->next_sibling()) { - if (child->template for_each_in_inclusive_subtree_of_type(callback) == IterationDecision::Break) - return IterationDecision::Break; + if (child->template for_each_in_inclusive_subtree_of_type(callback) == TraversalDecision::Break) + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; } template - IterationDecision for_each_in_inclusive_subtree_of_type(Callback callback) const + TraversalDecision for_each_in_inclusive_subtree_of_type(Callback callback) const { if (is(static_cast(*this))) { - if (callback(static_cast(*this)) == IterationDecision::Break) - return IterationDecision::Break; + if (auto decision = callback(static_cast(*this)); decision != TraversalDecision::Continue) + return decision; } for (auto* child = first_child(); child; child = child->next_sibling()) { - if (child->template for_each_in_inclusive_subtree_of_type(callback) == IterationDecision::Break) - return IterationDecision::Break; + if (child->template for_each_in_inclusive_subtree_of_type(callback) == TraversalDecision::Break) + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; } template - IterationDecision for_each_in_subtree(Callback callback) const + TraversalDecision for_each_in_subtree(Callback callback) const { for (auto* child = first_child(); child; child = child->next_sibling()) { - if (child->for_each_in_inclusive_subtree(callback) == IterationDecision::Break) - return IterationDecision::Break; + if (child->for_each_in_inclusive_subtree(callback) == TraversalDecision::Break) + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; } template - IterationDecision for_each_in_subtree(Callback callback) + TraversalDecision for_each_in_subtree(Callback callback) { for (auto* child = first_child(); child; child = child->next_sibling()) { - if (child->for_each_in_inclusive_subtree(callback) == IterationDecision::Break) - return IterationDecision::Break; + if (child->for_each_in_inclusive_subtree(callback) == TraversalDecision::Break) + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; } template - IterationDecision for_each_in_subtree_of_type(Callback callback) + TraversalDecision for_each_in_subtree_of_type(Callback callback) { for (auto* child = first_child(); child; child = child->next_sibling()) { - if (child->template for_each_in_inclusive_subtree_of_type(callback) == IterationDecision::Break) - return IterationDecision::Break; + if (child->template for_each_in_inclusive_subtree_of_type(callback) == TraversalDecision::Break) + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; } template - IterationDecision for_each_in_subtree_of_type(Callback callback) const + TraversalDecision for_each_in_subtree_of_type(Callback callback) const { for (auto* child = first_child(); child; child = child->next_sibling()) { - if (child->template for_each_in_inclusive_subtree_of_type(callback) == IterationDecision::Break) - return IterationDecision::Break; + if (child->template for_each_in_inclusive_subtree_of_type(callback) == TraversalDecision::Break) + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; } template diff --git a/Userland/Libraries/LibWeb/DOM/NonElementParentNode.h b/Userland/Libraries/LibWeb/DOM/NonElementParentNode.h index f58e6dfc579..4c834250bf1 100644 --- a/Userland/Libraries/LibWeb/DOM/NonElementParentNode.h +++ b/Userland/Libraries/LibWeb/DOM/NonElementParentNode.h @@ -24,9 +24,9 @@ public: static_cast(this)->template for_each_in_inclusive_subtree_of_type([&](auto& element) { if (element.id() == id) { found_element = &element; - return IterationDecision::Break; + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); return found_element; } @@ -37,9 +37,9 @@ public: static_cast(this)->template for_each_in_inclusive_subtree_of_type([&](auto& element) { if (element.id() == id) { found_element = &element; - return IterationDecision::Break; + return TraversalDecision::Continue; } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); return found_element; } diff --git a/Userland/Libraries/LibWeb/DOM/ParentNode.cpp b/Userland/Libraries/LibWeb/DOM/ParentNode.cpp index a009ffe56dd..59c5a85dfdd 100644 --- a/Userland/Libraries/LibWeb/DOM/ParentNode.cpp +++ b/Userland/Libraries/LibWeb/DOM/ParentNode.cpp @@ -45,10 +45,10 @@ WebIDL::ExceptionOr> ParentNode::query_selector(StringView se for (auto& selector : selectors) { if (SelectorEngine::matches(selector, {}, element, {}, this)) { result = &element; - return IterationDecision::Break; + return TraversalDecision::Break; } } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); return result; @@ -79,7 +79,7 @@ WebIDL::ExceptionOr> ParentNode::query_selector_all(S elements.append(&element); } } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); return StaticNodeList::create(realm(), move(elements)); diff --git a/Userland/Libraries/LibWeb/DOM/Range.cpp b/Userland/Libraries/LibWeb/DOM/Range.cpp index 3dd83aabac7..9b48ec688f0 100644 --- a/Userland/Libraries/LibWeb/DOM/Range.cpp +++ b/Userland/Libraries/LibWeb/DOM/Range.cpp @@ -1225,7 +1225,7 @@ WebIDL::ExceptionOr> Range::create_contextual fragment_node->for_each_in_subtree_of_type([&](HTML::HTMLScriptElement& script_element) { script_element.unmark_as_already_started({}); script_element.unmark_as_parser_inserted({}); - return IterationDecision::Continue; + return TraversalDecision::Continue; }); // 5. Return the value of fragment node. diff --git a/Userland/Libraries/LibWeb/DOM/ShadowRoot.h b/Userland/Libraries/LibWeb/DOM/ShadowRoot.h index f1d2c01149d..e2902960b45 100644 --- a/Userland/Libraries/LibWeb/DOM/ShadowRoot.h +++ b/Userland/Libraries/LibWeb/DOM/ShadowRoot.h @@ -71,37 +71,37 @@ template<> inline bool Node::fast_is() const { return node_type() == to_underlying(NodeType::DOCUMENT_FRAGMENT_NODE) && is_shadow_root(); } template -inline IterationDecision Node::for_each_shadow_including_inclusive_descendant(Callback callback) +inline TraversalDecision Node::for_each_shadow_including_inclusive_descendant(Callback callback) { - if (callback(*this) == IterationDecision::Break) - return IterationDecision::Break; + if (callback(*this) == TraversalDecision::Break) + return TraversalDecision::Break; for (auto* child = first_child(); child; child = child->next_sibling()) { if (child->is_element()) { if (JS::GCPtr shadow_root = static_cast(child)->shadow_root_internal()) { - if (shadow_root->for_each_shadow_including_inclusive_descendant(callback) == IterationDecision::Break) - return IterationDecision::Break; + if (shadow_root->for_each_shadow_including_inclusive_descendant(callback) == TraversalDecision::Break) + return TraversalDecision::Break; } } - if (child->for_each_shadow_including_inclusive_descendant(callback) == IterationDecision::Break) - return IterationDecision::Break; + if (child->for_each_shadow_including_inclusive_descendant(callback) == TraversalDecision::Break) + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; } template -inline IterationDecision Node::for_each_shadow_including_descendant(Callback callback) +inline TraversalDecision Node::for_each_shadow_including_descendant(Callback callback) { for (auto* child = first_child(); child; child = child->next_sibling()) { if (child->is_element()) { if (JS::GCPtr shadow_root = static_cast(child)->shadow_root()) { - if (shadow_root->for_each_shadow_including_inclusive_descendant(callback) == IterationDecision::Break) - return IterationDecision::Break; + if (shadow_root->for_each_shadow_including_inclusive_descendant(callback) == TraversalDecision::Break) + return TraversalDecision::Break; } } - if (child->for_each_shadow_including_inclusive_descendant(callback) == IterationDecision::Break) - return IterationDecision::Break; + if (child->for_each_shadow_including_inclusive_descendant(callback) == TraversalDecision::Break) + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; } } diff --git a/Userland/Libraries/LibWeb/DOM/Slottable.cpp b/Userland/Libraries/LibWeb/DOM/Slottable.cpp index b48a268d59c..fb4e93e3b15 100644 --- a/Userland/Libraries/LibWeb/DOM/Slottable.cpp +++ b/Userland/Libraries/LibWeb/DOM/Slottable.cpp @@ -78,10 +78,10 @@ JS::GCPtr find_a_slot(Slottable const& slottable, OpenFla shadow->for_each_in_subtree_of_type([&](auto& child) { if (!child.manually_assigned_nodes().contains_slow(slottable)) - return IterationDecision::Continue; + return TraversalDecision::Continue; slot = child; - return IterationDecision::Break; + return TraversalDecision::Break; }); return slot; @@ -93,10 +93,10 @@ JS::GCPtr find_a_slot(Slottable const& slottable, OpenFla shadow->for_each_in_subtree_of_type([&](auto& child) { if (child.slot_name() != slottable_name) - return IterationDecision::Continue; + return TraversalDecision::Continue; slot = child; - return IterationDecision::Break; + return TraversalDecision::Break; }); return slot; @@ -188,7 +188,7 @@ void assign_slottables_for_a_tree(JS::NonnullGCPtr root) // descendants, in tree order. root->for_each_in_inclusive_subtree_of_type([](auto& slot) { assign_slottables(slot); - return IterationDecision::Continue; + return TraversalDecision::Continue; }); } diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 6d88ee1b15a..0bfadeb8aaa 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -18,6 +18,7 @@ class PageClient; class PaintContext; class Resource; class ResourceLoader; +enum class TraversalDecision; class XMLDocumentBuilder; } diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.h b/Userland/Libraries/LibWeb/HTML/BrowsingContext.h index 6f83bf91121..7171c39ceb9 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.h +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.h @@ -53,47 +53,47 @@ public: bool is_familiar_with(BrowsingContext const&) const; template - IterationDecision for_each_in_inclusive_subtree(Callback callback) const + TraversalDecision for_each_in_inclusive_subtree(Callback callback) const { - if (callback(*this) == IterationDecision::Break) - return IterationDecision::Break; + if (callback(*this) == TraversalDecision::Break) + return TraversalDecision::Break; for (auto child = first_child(); child; child = child->next_sibling()) { - if (child->for_each_in_inclusive_subtree(callback) == IterationDecision::Break) - return IterationDecision::Break; + if (child->for_each_in_inclusive_subtree(callback) == TraversalDecision::Break) + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; } template - IterationDecision for_each_in_inclusive_subtree(Callback callback) + TraversalDecision for_each_in_inclusive_subtree(Callback callback) { - if (callback(*this) == IterationDecision::Break) - return IterationDecision::Break; + if (callback(*this) == TraversalDecision::Break) + return TraversalDecision::Break; for (auto child = first_child(); child; child = child->next_sibling()) { - if (child->for_each_in_inclusive_subtree(callback) == IterationDecision::Break) - return IterationDecision::Break; + if (child->for_each_in_inclusive_subtree(callback) == TraversalDecision::Break) + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; } template - IterationDecision for_each_in_subtree(Callback callback) const + TraversalDecision for_each_in_subtree(Callback callback) const { for (auto child = first_child(); child; child = child->next_sibling()) { - if (child->for_each_in_inclusive_subtree(callback) == IterationDecision::Break) - return IterationDecision::Break; + if (child->for_each_in_inclusive_subtree(callback) == TraversalDecision::Break) + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; } template - IterationDecision for_each_in_subtree(Callback callback) + TraversalDecision for_each_in_subtree(Callback callback) { for (auto child = first_child(); child; child = child->next_sibling()) { - if (child->for_each_in_inclusive_subtree(callback) == IterationDecision::Break) - return IterationDecision::Break; + if (child->for_each_in_inclusive_subtree(callback) == TraversalDecision::Break) + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; } bool is_top_level() const; diff --git a/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.cpp b/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.cpp index fcb2b28f45a..92ac445ba64 100644 --- a/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.cpp +++ b/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.cpp @@ -292,14 +292,14 @@ JS::ThrowCompletionOr CustomElementRegistry::define(String const& name, We document.for_each_shadow_including_descendant([&](DOM::Node& inclusive_descendant) { if (!is(inclusive_descendant)) - return IterationDecision::Continue; + return TraversalDecision::Continue; auto& inclusive_descendant_element = static_cast(inclusive_descendant); if (inclusive_descendant_element.namespace_uri() == Namespace::HTML && inclusive_descendant_element.local_name() == local_name && (!extends.has_value() || inclusive_descendant_element.is_value() == name)) upgrade_candidates.append(JS::make_handle(inclusive_descendant_element)); - return IterationDecision::Continue; + return TraversalDecision::Continue; }); // 19. For each element element in upgrade candidates, enqueue a custom element upgrade reaction given element and definition. @@ -388,12 +388,12 @@ void CustomElementRegistry::upgrade(JS::NonnullGCPtr root) const root->for_each_shadow_including_inclusive_descendant([&](DOM::Node& inclusive_descendant) { if (!is(inclusive_descendant)) - return IterationDecision::Continue; + return TraversalDecision::Continue; auto& inclusive_descendant_element = static_cast(inclusive_descendant); candidates.append(JS::make_handle(inclusive_descendant_element)); - return IterationDecision::Continue; + return TraversalDecision::Continue; }); // 2. For each candidate of candidates, try to upgrade candidate. diff --git a/Userland/Libraries/LibWeb/HTML/FormAssociatedElement.cpp b/Userland/Libraries/LibWeb/HTML/FormAssociatedElement.cpp index 7f375ba35b8..d13df20e6d4 100644 --- a/Userland/Libraries/LibWeb/HTML/FormAssociatedElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/FormAssociatedElement.cpp @@ -137,10 +137,10 @@ void FormAssociatedElement::reset_form_owner() html_element.root().for_each_in_inclusive_subtree_of_type([this, &form_value](HTMLFormElement& form_element) { if (form_element.id() == form_value) { set_form(&form_element); - return IterationDecision::Break; + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAllCollection.cpp b/Userland/Libraries/LibWeb/HTML/HTMLAllCollection.cpp index d2f4bae527b..482343bd069 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLAllCollection.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLAllCollection.cpp @@ -91,7 +91,7 @@ JS::MarkedVector> HTMLAllCollection::collect_matc m_root->for_each_in_subtree_of_type([&](auto& element) { if (m_filter(element)) elements.append(element); - return IterationDecision::Continue; + return TraversalDecision::Continue; }); } else { m_root->for_each_child_of_type([&](auto& element) { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp index 33859f9ed44..fd2c45f35af 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp @@ -157,15 +157,15 @@ void HTMLDetailsElement::update_shadow_tree_slots() for_each_in_subtree([&](auto& child) { if (&child == summary) - return IterationDecision::Continue; + return TraversalDecision::Continue; if (!child.is_slottable()) - return IterationDecision::Continue; + return TraversalDecision::Continue; child.as_slottable().visit([&](auto& node) { descendants_assignment.append(JS::make_handle(node)); }); - return IterationDecision::Continue; + return TraversalDecision::Continue; }); m_summary_slot->assign(move(summary_assignment)); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp index aad6886b019..ef8303fd821 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp @@ -561,7 +561,7 @@ Vector> HTMLFormElement::get_submittable_elements submittable_elements.append(form_associated_element->form_associated_element_to_html_element()); } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); return submittable_elements; @@ -1086,14 +1086,14 @@ FormAssociatedElement* HTMLFormElement::default_button() root().for_each_in_subtree([&](auto& node) { auto* form_associated_element = dynamic_cast(&node); if (!form_associated_element) - return IterationDecision::Continue; + return TraversalDecision::Continue; if (form_associated_element->form() == this && form_associated_element->is_submit_button()) { default_button = form_associated_element; - return IterationDecision::Break; + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); return default_button; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 5155c1da098..a2378476d0a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -1398,7 +1398,7 @@ void HTMLInputElement::set_checked_within_group() document().for_each_in_inclusive_subtree_of_type([&](auto& element) { if (element.checked() && &element != this && is_in_same_radio_button_group(*this, element)) element.set_checked(false, ChangeSource::User); - return IterationDecision::Continue; + return TraversalDecision::Continue; }); } @@ -1425,9 +1425,9 @@ void HTMLInputElement::legacy_pre_activation_behavior() document().for_each_in_inclusive_subtree_of_type([&](auto& element) { if (element.checked() && is_in_same_radio_button_group(*this, element)) { m_legacy_pre_activation_behavior_checked_element_in_group = &element; - return IterationDecision::Break; + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); set_checked_within_group(); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLabelElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLLabelElement.cpp index 210822bb1a6..20cf7e02dfd 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLabelElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLLabelElement.cpp @@ -46,9 +46,9 @@ JS::GCPtr HTMLLabelElement::control() const for_each_in_inclusive_subtree_of_type([&](auto& element) { if (element.id() == *for_() && element.is_labelable()) { control = &const_cast(element); - return IterationDecision::Break; + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); return control; } @@ -58,9 +58,9 @@ JS::GCPtr HTMLLabelElement::control() const for_each_in_subtree_of_type([&](auto& element) { if (element.is_labelable()) { control = &const_cast(element); - return IterationDecision::Break; + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); return control; diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index 5f364815a81..89b059d6b7b 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -1698,14 +1698,14 @@ Vector Window::supported_property_names() const // that have a non-empty name content attribute and are in a document tree with window's associated Document as their root; and // - the value of the id content attribute for all HTML elements that have a non-empty id content attribute // and are in a document tree with window's associated Document as their root. - associated_document().for_each_in_subtree_of_type([&property_names](auto& element) -> IterationDecision { + associated_document().for_each_in_subtree_of_type([&property_names](auto& element) -> TraversalDecision { if (is(element) || is(element) || is(element) || is(element)) { if (element.name().has_value()) property_names.set(element.name().value(), AK::HashSetExistingEntryBehavior::Keep); } if (auto const& name = element.id(); name.has_value()) property_names.set(name.value().to_string(), AK::HashSetExistingEntryBehavior::Keep); - return IterationDecision::Continue; + return TraversalDecision::Continue; }); return property_names.values(); @@ -1729,12 +1729,12 @@ WebIDL::ExceptionOr Window::named_item_value(FlyString const& name) c JS::GCPtr container = nullptr; mutable_this.associated_document().for_each_in_subtree_of_type([&](HTML::NavigableContainer& navigable_container) { if (!navigable_container.content_navigable()) - return IterationDecision::Continue; + return TraversalDecision::Continue; if (objects.navigables.contains_slow(JS::NonnullGCPtr { *navigable_container.content_navigable() })) { container = navigable_container; - return IterationDecision::Break; + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); // 2. Return container's content navigable's active WindowProxy. VERIFY(container); @@ -1775,13 +1775,13 @@ Window::NamedObjects Window::named_objects(StringView name) // embed, form, img, or object elements that have a name content attribute whose value is name // and are in a document tree with window's associated Document as their root; and // HTML elements that have an id content attribute whose value is name and are in a document tree with window's associated Document as their root. - associated_document().for_each_in_subtree_of_type([&objects, &name](auto& element) -> IterationDecision { + associated_document().for_each_in_subtree_of_type([&objects, &name](auto& element) -> TraversalDecision { if ((is(element) || is(element) || is(element) || is(element)) && (element.name() == name)) objects.elements.append(element); else if (element.id() == name) objects.elements.append(element); - return IterationDecision::Continue; + return TraversalDecision::Continue; }); return objects; diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index bc8d76fdc8d..8bf36f8be56 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -410,9 +410,9 @@ CSSPixels FormattingContext::compute_table_box_width_inside_table_wrapper(Box co box.for_each_in_subtree_of_type([&](Box const& child_box) { if (child_box.display().is_table_inside()) { table_box = child_box; - return IterationDecision::Break; + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); VERIFY(table_box.has_value()); @@ -464,9 +464,9 @@ CSSPixels FormattingContext::compute_table_box_height_inside_table_wrapper(Box c box.for_each_in_subtree_of_type([&](Box const& child_box) { if (child_box.display().is_table_inside()) { table_box = child_box; - return IterationDecision::Break; + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); VERIFY(table_box.has_value()); @@ -1808,9 +1808,9 @@ bool FormattingContext::can_skip_is_anonymous_text_run(Box& box) box.for_each_in_subtree([&](auto const& node) { if (!is(node) || !static_cast(node).dom_node().data().bytes_as_string_view().is_whitespace()) { contains_only_white_space = false; - return IterationDecision::Break; + return TraversalDecision::Break; } - return IterationDecision::Continue; + return TraversalDecision::Continue; }); if (contains_only_white_space) return true; diff --git a/Userland/Libraries/LibWeb/Layout/Label.cpp b/Userland/Libraries/LibWeb/Layout/Label.cpp index 533506a9804..a82488840d5 100644 --- a/Userland/Libraries/LibWeb/Layout/Label.cpp +++ b/Userland/Libraries/LibWeb/Layout/Label.cpp @@ -104,9 +104,9 @@ Label const* Label::label_for_control_node(LabelableNode const& control) control.document().layout_node()->for_each_in_inclusive_subtree_of_type