mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-04 08:36:12 +00:00
LibWeb: Use IterationDecision
in single level Node iteration methods
`Node::for_each_child()` and `Node::for_each_child_of_type()` callbacks now return an `IterationDecision`, which allows us to break early if required.
This commit is contained in:
parent
b5bed37074
commit
c57d395a48
Notes:
sideshowbarker
2024-07-17 02:35:27 +09:00
Author: https://github.com/tcl3
Commit: c57d395a48
Pull-request: https://github.com/SerenityOS/serenity/pull/24207
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/shannonbooth ✅
25 changed files with 81 additions and 27 deletions
|
@ -864,6 +864,7 @@ static void update_the_source_set(DOM::Element& element)
|
|||
elements.clear();
|
||||
element.parent()->for_each_child_of_type<DOM::Element>([&](auto& child) {
|
||||
elements.append(&child);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -135,6 +135,7 @@ void HTMLInputElement::set_checked(bool checked, ChangeSource change_source)
|
|||
if (parent()) {
|
||||
parent()->for_each_child([&](auto& child) {
|
||||
child.invalidate_style();
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,6 +85,7 @@ static void concatenate_descendants_text_content(DOM::Node const* node, StringBu
|
|||
builder.append(verify_cast<DOM::Text>(node)->data());
|
||||
node->for_each_child([&](auto const& node) {
|
||||
concatenate_descendants_text_content(&node, builder);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -98,6 +99,7 @@ String HTMLOptionElement::text() const
|
|||
// script or SVG script elements.
|
||||
for_each_child([&](auto const& node) {
|
||||
concatenate_descendants_text_content(&node, builder);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
||||
// Return the result of stripping and collapsing ASCII whitespace from the above concatenation.
|
||||
|
|
|
@ -174,12 +174,15 @@ Vector<JS::Handle<HTMLOptionElement>> HTMLSelectElement::list_of_options() const
|
|||
|
||||
for_each_child_of_type<HTMLOptionElement>([&](HTMLOptionElement& option_element) {
|
||||
list.append(JS::make_handle(option_element));
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
||||
for_each_child_of_type<HTMLOptGroupElement>([&](HTMLOptGroupElement const& optgroup_element) {
|
||||
optgroup_element.for_each_child_of_type<HTMLOptionElement>([&](HTMLOptionElement& option_element) {
|
||||
list.append(JS::make_handle(option_element));
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
||||
return list;
|
||||
|
|
|
@ -58,6 +58,8 @@ void HTMLTemplateElement::cloned(Node& copy, bool clone_children)
|
|||
|
||||
// FIXME: Should this use TreeNode::append_child instead?
|
||||
MUST(template_clone.content()->append_child(cloned_child));
|
||||
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -4418,7 +4418,8 @@ String HTMLParser::serialize_html_fragment(DOM::Node const& node, DOM::FragmentS
|
|||
if (is<DOM::Element>(current_node)) {
|
||||
// -> If current node is an Element
|
||||
auto& element = verify_cast<DOM::Element>(current_node);
|
||||
return serialize_element(element);
|
||||
serialize_element(element);
|
||||
return IterationDecision::Continue;
|
||||
}
|
||||
|
||||
if (is<DOM::Text>(current_node)) {
|
||||
|
@ -4440,7 +4441,6 @@ String HTMLParser::serialize_html_fragment(DOM::Node const& node, DOM::FragmentS
|
|||
|
||||
// 2. Otherwise, append the value of current node's data IDL attribute, escaped as described below.
|
||||
builder.append(escape_string(text_node.data(), AttributeMode::No));
|
||||
return IterationDecision::Continue;
|
||||
}
|
||||
|
||||
if (is<DOM::Comment>(current_node)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue