From b55d049aca131d2b4025c5214200f7213d32399b Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Thu, 19 Nov 2026 13:27:01 +0000 Subject: [PATCH] rf-button: a component that reports no node of its own leaves a pass-through node, not one of unknown role; the button picture trial asserts what a screen reader sees --- .../ui-contract/src/contract/steps/report.rs | 7 ++++++- crates/ui-contract/src/runtime/access.rs | 6 ++++++ crates/ui-contract/src/runtime/egui/access.rs | 10 ++++++++++ .../src/runtime/egui/access/tree.rs | 19 +++++++++++++++++++ crates/ui-widgets/tests/it/buttons.rs | 16 +++++++--------- 5 files changed, 48 insertions(+), 10 deletions(-) diff --git a/crates/ui-contract/src/contract/steps/report.rs b/crates/ui-contract/src/contract/steps/report.rs index eee088166..c003f0f23 100644 --- a/crates/ui-contract/src/contract/steps/report.rs +++ b/crates/ui-contract/src/contract/steps/report.rs @@ -129,8 +129,13 @@ fn report_access(p: &dyn ErasedPass<'_>, facts: &TypeFacts, input: &ReportIn<'_> } scope::finish(ctx, id, None); let carried = scope::carried_name(ctx, id); - // Step 8 created the node by the type's role; the role this pass reports may be none (`Access::role`). + // Step 8 created the node by the type's role; the role this pass reports may be none (`Access::role`). The node + // then stays only as the place of the children shown inside it, which assistive technology passes over: left + // unwritten it would be reported as a node of unknown role. let Role::Node(role) = role else { + if input.node { + access::pass_through(ctx, id); + } scope::leave(ctx, id); return; }; diff --git a/crates/ui-contract/src/runtime/access.rs b/crates/ui-contract/src/runtime/access.rs index 215c61308..9957ba63d 100644 --- a/crates/ui-contract/src/runtime/access.rs +++ b/crates/ui-contract/src/runtime/access.rs @@ -52,6 +52,12 @@ pub(crate) fn hide(ctx: &egui::Context, id: Id) { adapter::hide(ctx, id); } +/// Takes the node of `id` out of what assistive technology reports and keeps its children in their place: a +/// component whose type has a node and that reports none this pass (`Access::role`), with children that have theirs. +pub(crate) fn pass_through(ctx: &egui::Context, id: Id) { + adapter::pass_through(ctx, id); +} + /// Reports `id` as the focused node of this pass. pub(crate) fn set_focus(ctx: &egui::Context, id: Id) { adapter::set_focus(ctx, id); diff --git a/crates/ui-contract/src/runtime/egui/access.rs b/crates/ui-contract/src/runtime/egui/access.rs index 13e579eab..790284cd3 100644 --- a/crates/ui-contract/src/runtime/egui/access.rs +++ b/crates/ui-contract/src/runtime/egui/access.rs @@ -158,6 +158,16 @@ pub(crate) fn hide(ctx: &Context, id: Id) { }); } +/// Makes the node of `id` a generic container without actions: assistive technology passes over it and reports its +/// children in its place, as it does for a `Ui`'s node. +pub(crate) fn pass_through(ctx: &Context, id: Id) { + crate::runtime::egui::widgets::note_node(ctx, id); + ctx.accesskit_node_builder(id, |node| { + node.set_role(accesskit::Role::GenericContainer); + node.clear_actions(); + }); +} + /// Reports `id` as the focused node of this pass. pub(crate) fn set_focus(ctx: &Context, id: Id) { with_emitted(ctx, |emitted| emitted.focus_set = true); diff --git a/crates/ui-contract/src/runtime/egui/access/tree.rs b/crates/ui-contract/src/runtime/egui/access/tree.rs index 06efe74be..86ffedf8a 100644 --- a/crates/ui-contract/src/runtime/egui/access/tree.rs +++ b/crates/ui-contract/src/runtime/egui/access/tree.rs @@ -455,4 +455,23 @@ impl AccessTree { pub fn children_of(&self, key: NodeKey) -> Vec { self.lookup(NodeId(key.0)).map_or_else(Vec::new, |node| node.children().iter().map(|child| NodeKey(child.0)).collect()) } + + /// The nodes screen readers report directly under the node of `key`, in order: AccessKit's consumer drops a + /// generic container and reports its children in its place, and drops a hidden node with what lies below it. + pub fn seen_children_of(&self, key: NodeKey) -> Vec { + let mut seen = Vec::new(); + let mut pending: Vec = self.children_of(key).into_iter().rev().collect(); + while let Some(child) = pending.pop() { + let Some(node) = self.lookup(NodeId(child.0)) else { continue }; + if node.is_hidden() { + continue; + } + if node.role() == NodeRole::GenericContainer { + pending.extend(self.children_of(child).into_iter().rev()); + } else { + seen.push(child); + } + } + seen + } } diff --git a/crates/ui-widgets/tests/it/buttons.rs b/crates/ui-widgets/tests/it/buttons.rs index 91eef82e3..b3778bf4e 100644 --- a/crates/ui-widgets/tests/it/buttons.rs +++ b/crates/ui-widgets/tests/it/buttons.rs @@ -313,15 +313,13 @@ fn a_click_on_a_buttons_picture_activates_the_button_which_stays_one_access_node fixture.click_at(picture.center()); assert!(clicks.get() > 0, "a click inside the picture activates the button"); - for child in fixture.tree().children_of(button.node) { - let tree = fixture.tree(); - eprintln!( - "DIAG rf-fu2 button child {child:?}: role {:?} hidden {} images {}", - tree.role_of(child), - tree.is_hidden(child), - fixture.by_role(Role::IMAGE).len() - ); + let tree = fixture.tree(); + let mut pending = vec![(button.node, 0)]; + while let Some((key, depth)) = pending.pop() { + eprintln!("DIAG rf-button depth {depth} {key:?}: role {:?} hidden {}", tree.role_of(key), tree.is_hidden(key)); + pending.extend(tree.children_of(key).into_iter().map(|child| (child, depth + 1))); } - assert!(fixture.tree().children_of(button.node).is_empty(), "the picture adds no node under the button"); + // The child `Ui` the button shows its picture in is a generic container, which screen readers pass over. + assert!(tree.seen_children_of(button.node).is_empty(), "a screen reader finds no node under the button"); assert!(fixture.by_role(Role::IMAGE).is_empty(), "the picture is not a node of its own"); }