mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 18:02:45 +00:00
Merge pull request #2328 from aiongg/space-and-uia-fixes
access: no dangling AccessKit controls id (Windows menu crash, from #2239)
This commit is contained in:
@@ -10,9 +10,7 @@ mod text;
|
||||
mod tree;
|
||||
|
||||
use crate::runtime::pass_state;
|
||||
#[cfg(feature = "testing")]
|
||||
use egui::FullOutput;
|
||||
use egui::{Context, Id, IdMap, IdSet, ViewportId};
|
||||
use egui::{Context, FullOutput, Id, IdMap, IdSet, ViewportId};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use super::pass;
|
||||
@@ -200,3 +198,28 @@ fn hide_behind_modal(ctx: &Context, viewport: ViewportId, written: &IdSet) {
|
||||
pub(crate) fn tree_of(output: &mut FullOutput) -> Option<AccessTree> {
|
||||
output.platform_output.accesskit_update.take().map(AccessTree::new)
|
||||
}
|
||||
|
||||
/// Drops relations that name a node this update does not carry.
|
||||
///
|
||||
/// A menu reports its popup open on a frame where the popup's own node is not emitted (the ordering
|
||||
/// differs per menu), and `runtime::access::emit` puts that id in `controls`. A host's UIA adapter
|
||||
/// unwraps every `controls` lookup (`accesskit_consumer`'s `Node::controls`), so one id with no node
|
||||
/// in the same update aborts the app: photocraft#15597, where clicking Image, Edit or Layer — and on
|
||||
/// one machine Filter — closed PhotoCraft on the click that opened the menu.
|
||||
pub(crate) fn drop_dangling_relations(output: &mut FullOutput) {
|
||||
let Some(update) = output.platform_output.accesskit_update.as_mut() else { return };
|
||||
prune_controls(update);
|
||||
}
|
||||
|
||||
/// The step itself: every `controls` id of `update` that names no node of `update` is dropped. Other
|
||||
/// relations keep their ids: they are built from nodes this pass wrote.
|
||||
pub fn prune_controls(update: &mut egui::accesskit::TreeUpdate) {
|
||||
let ids: std::collections::HashSet<egui::accesskit::NodeId> = update.nodes.iter().map(|(id, _)| *id).collect();
|
||||
for (_, node) in update.nodes.iter_mut() {
|
||||
if node.controls().iter().all(|id| ids.contains(id)) {
|
||||
continue;
|
||||
}
|
||||
let kept: Vec<egui::accesskit::NodeId> = node.controls().iter().copied().filter(|id| ids.contains(id)).collect();
|
||||
node.set_controls(kept);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! The plugin impl, its registration and hook order, and the plugin lock.
|
||||
|
||||
use crate::runtime::frame;
|
||||
use egui::{Context, Plugin, RawInput, Ui};
|
||||
use egui::{Context, FullOutput, Plugin, RawInput, Ui};
|
||||
|
||||
/// The runtime's plugin. egui holds a plugin's mutex while it calls a hook, so the struct holds no state:
|
||||
/// every record lives in context data behind its own lock.
|
||||
@@ -17,6 +17,10 @@ impl Plugin for RuntimePlugin {
|
||||
frame::input_hook(ctx, input);
|
||||
}
|
||||
|
||||
fn output_hook(&mut self, ctx: &Context, output: &mut FullOutput) {
|
||||
let _ = ctx;
|
||||
crate::runtime::egui::access::drop_dangling_relations(output);
|
||||
}
|
||||
fn on_begin_pass(&mut self, ui: &mut Ui) {
|
||||
frame::begin_pass(ui);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use crate::runtime::access::{FieldLabel, scope};
|
||||
use egui::{Context, Id};
|
||||
|
||||
pub use crate::runtime::egui::access::{AccessTree, Declared, NodeKey};
|
||||
pub use crate::runtime::egui::access::{AccessTree, Declared, NodeKey, prune_controls};
|
||||
|
||||
/// The AccessKit tree a finished pass of a viewport produced, taken out of its output; empty when it made none.
|
||||
pub fn tree_of(output: &mut crate::runtime::egui::fixture::FullOutput) -> AccessTree {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
//! Relations that name a node the update does not carry.
|
||||
|
||||
use craft_ui::testing::access::prune_controls;
|
||||
use craft_ui::testing::trial;
|
||||
use egui::accesskit::{Node, NodeId, Role, TreeId, TreeUpdate};
|
||||
|
||||
fn update(controls: Vec<NodeId>, carried: Vec<NodeId>) -> TreeUpdate {
|
||||
let mut node = Node::new(Role::Button);
|
||||
node.set_controls(controls);
|
||||
TreeUpdate {
|
||||
nodes: carried.into_iter().map(|id| (id, Node::new(Role::Button))).chain(std::iter::once((NodeId(1), node))).collect(),
|
||||
tree: None,
|
||||
tree_id: TreeId::ROOT,
|
||||
focus: NodeId(1),
|
||||
}
|
||||
}
|
||||
|
||||
fn controls_of_first(tree: &TreeUpdate) -> Vec<NodeId> {
|
||||
tree.nodes.iter().find(|(id, _)| *id == NodeId(1)).map(|(_, node)| node.controls().to_vec()).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// A popup that reports itself open on a frame where its node is not emitted leaves its id in
|
||||
/// `controls`; the host's UIA adapter unwraps that lookup and aborts (photocraft#15597). The id
|
||||
/// that has a node stays.
|
||||
#[trial]
|
||||
fn controls_keep_the_ids_the_update_carries_and_drop_the_rest() {
|
||||
let mut tree = update(vec![NodeId(2), NodeId(9)], vec![NodeId(2)]);
|
||||
prune_controls(&mut tree);
|
||||
assert_eq!(controls_of_first(&tree), vec![NodeId(2)], "the id without a node is gone, the one with a node stays");
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn controls_with_every_node_carried_are_left_alone() {
|
||||
let mut tree = update(vec![NodeId(2)], vec![NodeId(2)]);
|
||||
prune_controls(&mut tree);
|
||||
assert_eq!(controls_of_first(&tree), vec![NodeId(2)]);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
//! The accessibility emitter: the label scope and merge rule, announcements, modal inertness, viewports.
|
||||
|
||||
mod bounds;
|
||||
mod controls;
|
||||
mod face_record;
|
||||
mod face_state;
|
||||
mod nodes;
|
||||
|
||||
Reference in New Issue
Block a user