LibWeb: Make normalize_sublists_in_node() take a Node instead of Element

This prevents some unnecessary casting to DOM::Element.
This commit is contained in:
Jelle Raaijmakers 2025-01-10 00:17:13 +01:00 committed by Andreas Kling
commit 83f48a07d4
Notes: github-actions[bot] 2025-01-10 22:39:00 +00:00
3 changed files with 7 additions and 7 deletions

View file

@ -153,16 +153,16 @@ bool command_delete_action(DOM::Document& document, String const&)
if (offset == 0 && node->index() == 0
&& node_element.local_name().is_one_of(HTML::TagNames::li, HTML::TagNames::dt, HTML::TagNames::dd)) {
// 1. Let items be a list of all lis that are ancestors of node.
Vector<GC::Ref<DOM::Element>> items;
Vector<GC::Ref<DOM::Node>> items;
node->for_each_ancestor([&items](GC::Ref<DOM::Node> ancestor) {
if (is<HTML::HTMLLIElement>(*ancestor))
items.append(static_cast<DOM::Element&>(*ancestor));
items.append(ancestor);
return IterationDecision::Continue;
});
// 2. Normalize sublists of each item in items.
for (auto item : items)
normalize_sublists_in_node(*item);
normalize_sublists_in_node(item);
// 3. Record the values of the one-node list consisting of node, and let values be the
// result.

View file

@ -1964,15 +1964,15 @@ Optional<DOM::BoundaryPoint> next_equivalent_point(DOM::BoundaryPoint boundary_p
}
// https://w3c.github.io/editing/docs/execCommand/#normalize-sublists
void normalize_sublists_in_node(GC::Ref<DOM::Element> item)
void normalize_sublists_in_node(GC::Ref<DOM::Node> item)
{
// 1. If item is not an li or it is not editable or its parent is not editable, abort these
// steps.
if (item->local_name() != HTML::TagNames::li || !item->is_editable() || !item->parent()->is_editable())
if (!is<HTML::HTMLLIElement>(*item) || !item->is_editable() || !item->parent()->is_editable())
return;
// 2. Let new item be null.
GC::Ptr<DOM::Element> new_item;
GC::Ptr<DOM::Node> new_item;
// 3. While item has an ol or ul child:
while (item->has_child_of_type<HTML::HTMLOListElement>() || item->has_child_of_type<HTML::HTMLUListElement>()) {

View file

@ -67,7 +67,7 @@ bool is_whitespace_node(GC::Ref<DOM::Node>);
DOM::BoundaryPoint last_equivalent_point(DOM::BoundaryPoint);
void move_node_preserving_ranges(GC::Ref<DOM::Node>, GC::Ref<DOM::Node> new_parent, u32 new_index);
Optional<DOM::BoundaryPoint> next_equivalent_point(DOM::BoundaryPoint);
void normalize_sublists_in_node(GC::Ref<DOM::Element>);
void normalize_sublists_in_node(GC::Ref<DOM::Node>);
bool precedes_a_line_break(GC::Ref<DOM::Node>);
Optional<DOM::BoundaryPoint> previous_equivalent_point(DOM::BoundaryPoint);
Vector<RecordedOverride> record_current_states_and_values(GC::Ref<DOM::Range>);