mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 04:27:49 +00:00
Merge branch 'red/rf-button' into area/ribbon-fw
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -455,4 +455,23 @@ impl AccessTree {
|
||||
pub fn children_of(&self, key: NodeKey) -> Vec<NodeKey> {
|
||||
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<NodeKey> {
|
||||
let mut seen = Vec::new();
|
||||
let mut pending: Vec<NodeKey> = 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,16 +315,14 @@ 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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user