Skip to content

Truly independent web browser

LibWeb: Root the nodes editing commands collect

Shannon Booth2dcd09ac839f
diff --git a/Libraries/LibWeb/Editing/Commands.cpp b/Libraries/LibWeb/Editing/Commands.cpp
index e450a8f3226..7d513a86cb0 100644
--- a/Libraries/LibWeb/Editing/Commands.cpp
+++ b/Libraries/LibWeb/Editing/Commands.cpp
@@ -100,7 +100,7 @@ bool command_create_link_action(DOM::Document& document, Utf16View value)
// 2. For each editable a element that has an href attribute and is an ancestor of some node effectively contained
// in the active range, set that a element's href attribute to value.
- HashTable<DOM::Node*> visited_ancestors;
+ GC::RootHashTable<DOM::Node*> visited_ancestors;
auto set_value_for_ancestor_anchors = [&](GC::Ref<DOM::Node> node) {
node->for_each_ancestor([&](GC::Ref<DOM::Node> ancestor) {
if (visited_ancestors.contains(ancestor.ptr()))
@@ -260,7 +260,7 @@ bool command_delete_action(DOM::Document& document, Utf16View)
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::Node>> items;
+ GC::RootVector<GC::Ref<DOM::Node>> items;
node->for_each_ancestor([&items](GC::Ref<DOM::Node> ancestor) {
if (is<HTML::HTMLLIElement>(*ancestor))
items.append(ancestor);
@@ -355,7 +355,7 @@ bool command_delete_action(DOM::Document& document, Utf16View)
auto new_range = block_extend_a_range(DOM::Range::create(*node, 0, *node, 0));
// 2. Let node list be a list of nodes, initially empty.
- Vector<GC::Ref<DOM::Node>> node_list;
+ GC::RootVector<GC::Ref<DOM::Node>> node_list;
// 3. For each node current node contained in new range, append current node to node list if
// the last member of node list (if any) is not an ancestor of current node, and current
@@ -699,7 +699,7 @@ bool command_format_block_action(DOM::Document& document, Utf16View value)
auto new_range = block_extend_a_range(*active_range(document));
// 5. Let node list be an empty list of nodes.
- Vector<GC::Ref<DOM::Node>> node_list;
+ GC::RootVector<GC::Ref<DOM::Node>> node_list;
// 6. For each node node contained in new range, append node to node list if it is editable, the last member of
// original node list (if any) is not an ancestor of node, node is either a non-list single-line container or an
@@ -756,7 +756,7 @@ bool command_format_block_action(DOM::Document& document, Utf16View value)
// 10. While node list is not empty:
while (!node_list.is_empty()) {
- Vector<GC::Ref<DOM::Node>> sublist;
+ GC::RootVector<GC::Ref<DOM::Node>> sublist;
// 1. If the first member of node list is a single-line container:
if (is_single_line_container(node_list.first())) {
@@ -835,7 +835,7 @@ bool command_format_block_indeterminate(DOM::Document const& document)
auto new_range = block_extend_a_range(*range);
// 3. Let node list be all visible editable nodes that are contained in new range and have no children.
- Vector<GC::Ref<DOM::Node>> node_list;
+ GC::RootVector<GC::Ref<DOM::Node>> node_list;
new_range->for_each_contained([&](GC::Ref<DOM::Node> node) {
if (is_visible_node(node) && node->is_editable() && !node->has_children())
node_list.append(node);
@@ -1132,7 +1132,7 @@ bool command_forward_delete_action(DOM::Document& document, Utf16View)
bool command_indent_action(DOM::Document& document, Utf16View)
{
// 1. Let items be a list of all lis that are inclusive ancestors of the active range's start and/or end node.
- Vector<GC::Ref<DOM::Node>> items;
+ GC::RootVector<GC::Ref<DOM::Node>> items;
auto add_all_lis = [&items](GC::Ref<DOM::Node> node) {
node->for_each_inclusive_ancestor([&items](GC::Ref<DOM::Node> ancestor) {
if (is<HTML::HTMLLIElement>(*ancestor) && !items.contains_slow(ancestor))
@@ -1152,7 +1152,7 @@ bool command_indent_action(DOM::Document& document, Utf16View)
auto new_range = block_extend_a_range(*active_range(document));
// 4. Let node list be a list of nodes, initially empty.
- Vector<GC::Ref<DOM::Node>> node_list;
+ GC::RootVector<GC::Ref<DOM::Node>> node_list;
// 5. For each node node contained in new range, if node is editable and is an allowed child of "div" or "ol" and if
// the last member of node list (if any) is not an ancestor of node, append node to node list.
@@ -1185,7 +1185,7 @@ bool command_indent_action(DOM::Document& document, Utf16View)
// 7. While node list is not empty:
while (!node_list.is_empty()) {
// 1. Let sublist be a list of nodes, initially empty.
- Vector<GC::Ref<DOM::Node>> sublist;
+ GC::RootVector<GC::Ref<DOM::Node>> sublist;
// 2. Remove the first member of node list and append it to sublist.
sublist.append(node_list.take_first());
@@ -1594,7 +1594,7 @@ bool command_insert_paragraph_action(DOM::Document& document, Utf16View)
auto new_range = block_extend_a_range(active_range);
// 3. Let node list be a list of nodes, initially empty.
- Vector<GC::Ref<DOM::Node>> node_list;
+ GC::RootVector<GC::Ref<DOM::Node>> node_list;
// 4. Append to node list the first node in tree order that is contained in new range and is an allowed child of
// "p", if any.
@@ -1816,7 +1816,7 @@ bool command_insert_paragraph_action(DOM::Document& document, Utf16View)
clone_element->remove_attribute(HTML::AttributeNames::id);
}
insert_node_before(clone, parent, start_node->next_sibling());
- Vector<GC::Ref<DOM::Node>> children_to_move;
+ GC::RootVector<GC::Ref<DOM::Node>> children_to_move;
for (auto* child = start_node->child_at_index(start_offset); child; child = child->next_sibling())
children_to_move.append(*child);
for (auto child_to_move : children_to_move)
@@ -1825,7 +1825,7 @@ bool command_insert_paragraph_action(DOM::Document& document, Utf16View)
start_offset = index + 1;
start_node = parent;
}
- Vector<GC::Ref<DOM::Node>> nodes_to_move;
+ GC::RootVector<GC::Ref<DOM::Node>> nodes_to_move;
for (auto* child = container->child_at_index(start_offset); child; child = child->next_sibling())
nodes_to_move.append(*child);
for (auto node_to_move : nodes_to_move)
@@ -2121,7 +2121,7 @@ static bool justify_indeterminate(DOM::Document const& document, JustifyAlignmen
// Return true if among visible editable nodes that are contained in the result and have no children, at least one
// has alignment value "[alignment]" and at least one does not. Otherwise return false.
- Vector<GC::Ref<DOM::Node>> matching_nodes;
+ GC::RootVector<GC::Ref<DOM::Node>> matching_nodes;
range->for_each_contained([&matching_nodes](GC::Ref<DOM::Node> node) {
if (is_visible_node(node) && node->is_editable() && !node->has_children())
matching_nodes.append(node);
@@ -2147,7 +2147,7 @@ static bool justify_state(DOM::Document const& document, JustifyAlignment alignm
// Return true if there is at least one visible editable node that is contained in the result and has no children,
// and all such nodes have alignment value "[alignment]". Otherwise return false.
- Vector<GC::Ref<DOM::Node>> matching_nodes;
+ GC::RootVector<GC::Ref<DOM::Node>> matching_nodes;
range->for_each_contained([&matching_nodes](GC::Ref<DOM::Node> node) {
if (is_visible_node(node) && node->is_editable() && !node->has_children())
matching_nodes.append(node);
@@ -2294,7 +2294,7 @@ Utf16String command_justify_right_value(DOM::Document const& document)
bool command_outdent_action(DOM::Document& document, Utf16View)
{
// 1. Let items be a list of all lis that are inclusive ancestors of the active range's start and/or end node.
- Vector<GC::Ref<DOM::Node>> items;
+ GC::RootVector<GC::Ref<DOM::Node>> items;
auto add_all_lis = [&items](GC::Ref<DOM::Node> node) {
node->for_each_inclusive_ancestor([&items](GC::Ref<DOM::Node> ancestor) {
if (is<HTML::HTMLLIElement>(*ancestor) && !items.contains_slow(ancestor))
@@ -2314,7 +2314,7 @@ bool command_outdent_action(DOM::Document& document, Utf16View)
auto new_range = block_extend_a_range(*active_range(document));
// 4. Let node list be a list of nodes, initially empty.
- Vector<GC::Ref<DOM::Node>> node_list;
+ GC::RootVector<GC::Ref<DOM::Node>> node_list;
// 5. For each node node contained in new range, append node to node list if the last member of node list (if any)
// is not an ancestor of node; node is editable; and either node has no editable descendants, or is an ol or ul,
@@ -2353,7 +2353,7 @@ bool command_outdent_action(DOM::Document& document, Utf16View)
break;
// 3. Let sublist be a list of nodes, initially empty.
- Vector<GC::Ref<DOM::Node>> sublist;
+ GC::RootVector<GC::Ref<DOM::Node>> sublist;
// 4. Remove the first member of node list and append it to sublist.
sublist.append(node_list.take_first());
@@ -2397,7 +2397,7 @@ bool command_redo_action(DOM::Document& document, Utf16View)
bool command_remove_format_action(DOM::Document& document, Utf16View)
{
// 1. Let elements to remove be a list of every removeFormat candidate effectively contained in the active range.
- Vector<GC::Ref<DOM::Element>> elements_to_remove;
+ GC::RootVector<GC::Ref<DOM::Element>> elements_to_remove;
for_each_node_effectively_contained_in_range(active_range(document), [&](GC::Ref<DOM::Node> descendant) {
if (is_remove_format_candidate(descendant))
elements_to_remove.append(static_cast<DOM::Element&>(*descendant));
@@ -2433,7 +2433,7 @@ bool command_remove_format_action(DOM::Document& document, Utf16View)
MUST(split_text(static_cast<DOM::Text&>(*end.node), end.offset));
// 5. Let node list consist of all editable nodes effectively contained in the active range.
- Vector<GC::Ref<DOM::Node>> node_list;
+ GC::RootVector<GC::Ref<DOM::Node>> node_list;
for_each_node_effectively_contained_in_range(active_range(document), [&](GC::Ref<DOM::Node> descendant) {
if (descendant->is_editable())
node_list.append(descendant);
@@ -2678,7 +2678,7 @@ bool command_unlink_action(DOM::Document& document, Utf16View)
{
// 1. Let hyperlinks be a list of every a element that has an href attribute and is contained in the active range or
// is an ancestor of one of its boundary points.
- Vector<GC::Ref<DOM::Element>> hyperlinks;
+ GC::RootVector<GC::Ref<DOM::Element>> hyperlinks;
if (auto range = active_range(document)) {
auto node_matches = [](GC::Ref<DOM::Node> node) {
return is<HTML::HTMLAnchorElement>(*node)