fix(ui-contract): a memoized view kept with AccessKit off runs once AccessKit is on

Whether the pass builds AccessKit nodes is part of a run's place: a run kept
while AccessKit was off holds no nodes, and replaying it after AccessKit turns
on (a screen reader starts, automation reads the tree) left the view out of the
access tree.
This commit is contained in:
aiongg committed 2026-11-27 03:12:40 +00:00
1 parent 14317bbe78
commit cc9612fa22
4 files changed
+43 -4

No files matched your search

+1
View File
@@ -141,6 +141,7 @@ impl Lazy {
layout,
pixels_per_point: ctx.pixels_per_point(),
atlas: ctx.fonts(|fonts| fonts.atlas_generation()),
access: crate::runtime::egui::access::builds_nodes(&ctx),
opacity: ui.opacity(),
env: env.key,
flow: env.flow(),
@@ -140,6 +140,11 @@ pub(crate) fn create_node(ctx: &Context, id: Id) -> bool {
ctx.accesskit_node_builder(id, |_| ()).is_some()
}
/// Whether this pass builds AccessKit nodes: AccessKit was on when the pass began. Reads only, unlike `create_node`.
pub(crate) fn builds_nodes(ctx: &Context) -> bool {
ctx.with_accesskit_parents(|_| ()).is_some()
}
/// Whether AccessKit is running and the widget `id` is visible: nodes are built only then. Creates the node of `id`.
pub(crate) fn enabled(ctx: &Context, id: Id) -> bool {
create_node(ctx, id)
+10 -4
View File
@@ -174,8 +174,8 @@ pub(crate) struct Measured {
pub(crate) fills: Option<craft_behavior::Axis>,
}
/// Where a memoized view ran: it replays only at a place of the same size, layer, layout, opacity, flow and environment,
/// and its record moves with the room's position (`Place::shift_to`).
/// Where a memoized view ran: it replays only at a place of the same size, layer, layout, AccessKit state, opacity, flow
/// and environment, and its record moves with the room's position (`Place::shift_to`).
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct Place {
/// The region its parent offered it.
@@ -187,6 +187,9 @@ pub(crate) struct Place {
/// The font atlas the run's text points into (`Fonts::atlas_generation`): egui clears the atlas when it fills up
/// and rebuilds it for new text options, and a kept galley's glyphs then name other glyphs.
pub(crate) atlas: u64,
/// Whether the pass built AccessKit nodes (`access::builds_nodes`): a run with AccessKit off keeps no nodes, which a
/// pass with it on must show, and AccessKit turns on mid-session (a screen reader starts, automation reads the tree).
pub(crate) access: bool,
/// The opacity everything painted in the room is faded to (`Ui::opacity`, a layer fading in or out): the run's
/// colours hold it.
pub(crate) opacity: f32,
@@ -214,7 +217,8 @@ struct Moved {
impl Place {
/// How a run at this place that took `rect` replays at `now`, or `None` when it cannot. The room may have moved;
/// its size, the layer, layout, scale, font atlas, opacity, flow and environment are the ones the run had. A record
/// its size, the layer, layout, scale, font atlas, AccessKit state, opacity, flow and environment are the ones the run
/// had. A record
/// that shows an overlay replays only at the room and clip of its run (`Record::pinned`). Any other record moves by
/// the room's move when that keeps where a run places content (`keeps_placement`, so a moved record is what a run
/// there gives) and, for a move, the record holds nothing a move cannot place (`Record::movable`: no paint
@@ -233,6 +237,7 @@ impl Place {
&& now.layout == self.layout
&& now.pixels_per_point == self.pixels_per_point
&& now.atlas == self.atlas
&& now.access == self.access
&& now.opacity == self.opacity
&& now.env == self.env
&& now.flow == self.flow;
@@ -513,7 +518,8 @@ pub(crate) fn replay(ctx: &Context, id: Id) {
/// - no value it read (a bound value, an inspection record, a command's state) changed this frame (`note_edit`), or,
/// replaying a run of this frame, after that run started;
/// - the call's key is the one of its last run (its props key after that run), and its environment (theme, density,
/// scale, language, window active) and the flow of the body around it (`Flow`) the ones it ran in;
/// scale, language, window active), the flow of the body around it (`Flow`) and whether the pass builds AccessKit
/// nodes the ones it ran in;
/// - the run did nothing a replay cannot repeat (`runtime::replay`) and asked for no discard pass: what it added is
/// what the pass was thrown away for;
/// - the shown life of no component it showed ended (`memory::ended_since`): a replay would show memory state that is
@@ -268,6 +268,33 @@ fn a_settled_view_runs_after_the_font_atlas_is_rebuilt() {
assert_eq!(frame(&mut frames), 0, "then it replays again");
}
/// A run kept while AccessKit was off holds no nodes. When AccessKit turns on (a screen reader starts, automation reads
/// the tree), a settled view runs in place of replaying, so its nodes are in the tree, then settles again. The replay
/// audit is on throughout: every replay is compared with a real run.
#[trial]
fn a_settled_view_runs_when_access_kit_turns_on() {
let mut frames = Frames::new();
craft_ui::testing::audit_replays(&frames.ctx, true);
frames.ctx.disable_accesskit();
let frame = |frames: &mut Frames| {
frames.frame(vec![], |ui| {
in_region(ui, region(0), |ui| MemoView::new("title", Title { title: "Access".to_owned() }, title).show(ui));
});
(title_runs(), !frames.tree().with_role(Role::BUTTON).is_empty())
};
for _ in 0..WARM {
frame(&mut frames);
}
assert_eq!(frame(&mut frames), (0, false), "a settled view replays, with no nodes while AccessKit is off");
frames.ctx.enable_accesskit();
let (runs, button) = frame(&mut frames);
assert!(runs > 0 && button, "the view runs in the first frame with AccessKit on and reports its button");
for _ in 0..WARM {
frame(&mut frames);
}
assert_eq!(frame(&mut frames), (0, true), "then it replays again, its button still in the tree");
}
/// A view that writes its own `&mut Tracked` runs twice for the change that asked for the write, the writing run and
/// one that reads the written value, then replays.
#[trial]