Skip to content

layout: Accessibility code cleanups - #46691

Merged
mukilan merged 2 commits into
servo:mainfrom
alice:accessibility-node-methods
Jul 23, 2026
Merged

layout: Accessibility code cleanups#46691
mukilan merged 2 commits into
servo:mainfrom
alice:accessibility-node-methods

Conversation

@alice

@alice alice commented Jul 21, 2026

Copy link
Copy Markdown
Contributor
  • Move resolve_local_damage_for_node_and_subtree() and update_node_and_descendants_from_dom_node() on to AccessibilityNode;
  • Rename update_node_from_dom_node() to update_properties_from_dom_node();
  • Rename update_node_and_descendants_from_dom_node() to update_node_and_populate_new_descendants_from_dom_node();
  • Rename update_descendants_from_dom_node() to update_children_and_populate_new_descendants_from_dom_node(), and change the weak_self argument to be an ArcRefCell, only downgrading if necessary;
  • Add an ancestors() iterator on AccessibilityNode;
  • Make AccessibilityNode::children() return an Iterator;
  • Make test_accessibility_partial_subtree_move_and_delete() less confusing by using more different types of elements;
  • Rename the counters in UpdateCounters to match their corresponding values in ReflowStatistics and ServoTestUtils.

Testing: No behaviour changes.
Fixes: part of #4344

@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jul 21, 2026
@alice
alice requested a review from mukilan July 21, 2026 14:16

@simonwuelker simonwuelker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Jul 21, 2026

@mukilan mukilan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are few minor issues in the doc comments, but looks good to me!

Comment thread components/layout/accessibility_tree.rs Outdated
update.unresolved_local_damage.remove(&self.id);
}

/// Update the given AccessibilityNode from its corresponding DOM node and

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Update the given AccessibilityNode from its corresponding DOM node and
/// Update the given [`AccessibilityNode`] from its corresponding DOM node and

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread components/layout/accessibility_tree.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not changed in this PR, but the comment is outdated.

Suggested change
/// [`LocalAccessibilityDamage::SubtreeChanged`].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread components/layout/accessibility_tree.rs Outdated
}

/// Update the given AccessibilityNode from its corresponding DOM node and
/// ['AccessibilityDamage'].

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently not a valid link since we are not using backticks.

Suggested change
/// ['AccessibilityDamage'].
/// [`AccessibilityDamage`].

Comment thread components/layout/accessibility_tree.rs Outdated

// Update self.child_nodes in place.
self.child_nodes.push(new_child.clone());
self.child_nodes.push(strong_child.clone());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clone is not necessary as this is the last use of strong_child.

Suggested change
self.child_nodes.push(strong_child.clone());
self.child_nodes.push(strong_child);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this call earlier, so it still needs a .clone(), but I removed an extra clone() by not making a copy of new_child.

Comment thread components/layout/accessibility_tree.rs Outdated
// same position as previously.
let weak_self = ref_self.downgrade();
for dom_child in remaining_dom_children {
let (new_id, new_child) = tree.get_or_create_node(&dom_child, update);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not something related to this PR. I am wondering if it makes sense to pass the parent handle to get_or_create_node here, rather than set it at the end of the loop. get_or_create_node already borrows the node to set the tag name, so potentially we could avoid an additional borrow if the node is not new.

@alice alice Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea, but I think we need to give it some more thought since we also call update_node_from_dom_node() on the new child, and it might be a bit odd to move that into get_or_create_node() since it's potentially recursive.

That also makes me reconsider my renaming of that method here!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I meant we can move only the new_child.parent_node = Some(weak_self.clone()) part, which is currently at the end of the loop, into get_or_create_node. I agree that moving update_node_from_dom_node might not be a good idea.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would that avoid a borrow? We need to set the parent on the new child whether it's newly-created or not, so we need to borrow it somewhere either way. We need to borrow the newly-created child to call update_node_and_populate_new_descendants_from_dom_node() here, so we can't only borrow it in get_or_create_node() unless we also move that call in there as well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to the additional borrow in the case of an existing node, not the newly-created node. For the former, if we set the parent in get_or_create_node, then we don't need to borrow again in this method.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like in the recent push get_or_create_node we only borrow the node for newly-created case, so I guess that now addresses the extra borrow for existing nodes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh now I finally get what you were suggesting 🤦 sorry for being obtuse!

alice added 2 commits July 22, 2026 09:34
- Move `resolve_local_damage_for_node_and_subtree()` and `update_node_and_descendants_from_dom_node()` on to `AccessibilityNode`;
- Rename `update_node_from_dom_node()` to `update_properties_from_dom_node()`;
- Rename `update_node_and_descendants_from_dom_node()` to `update_node_from_dom_node()`;
- Rename `update_descendants_from_dom_node()` to `update_children_from_dom_node()`, and change the `weak_self` argument to be an `ArcRefCell`, only downgrading if necessary;
- Add an `ancestors()` iterator on `AccessibilityNode`;
- Make `AccessibilityNode::children()` return an Iterator;
- Make `test_accessibility_partial_subtree_move_and_delete()` less confusing by using more different types of elements.

Signed-off-by: Alice Boxhall <alice@igalia.com>
Review comments:
- Fix out-of-date references to `LocalDamage`;
- Fix broken doc comment references.

Extra changes:
- Rename counter names to match the names in `ReflowStatistics` and `ServoTestUtils`;
- Rename `update_node_from_dom_node()` to `update_node_and_populate_new_descendants_from_dom_node()`;
- Rename `update_children_from_dom_node()` to `update_children_and_populate_new_descendants_from_dom_node()`.

Signed-off-by: Alice Boxhall <alice@igalia.com>
@alice
alice force-pushed the accessibility-node-methods branch from 19410ce to c57150c Compare July 22, 2026 08:30
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jul 22, 2026
@mukilan
mukilan added this pull request to the merge queue Jul 22, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jul 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 22, 2026
@servo-highfive servo-highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Jul 22, 2026
@mukilan
mukilan added this pull request to the merge queue Jul 23, 2026
@servo-highfive servo-highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Jul 23, 2026
Merged via the queue into servo:main with commit 8cec62a Jul 23, 2026
42 checks passed
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-review There is new code that needs to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants