Skip to content

Commit

Permalink
Set a transform on the root AccessKit node (#764)
Browse files Browse the repository at this point in the history
This is better than having to apply the scale factor to the bounding
rectangles of all nodes, especially when we take externally generated
AccessKit nodes, such as those generated by Parley, into account.
  • Loading branch information
mwcampbell authored Nov 28, 2024
1 parent d981f0d commit 3b18fc3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
2 changes: 0 additions & 2 deletions masonry/src/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ pub struct AccessCtx<'a> {
pub(crate) widget_children: ArenaMutChildren<'a, Box<dyn Widget>>,
pub(crate) tree_update: &'a mut TreeUpdate,
pub(crate) rebuild_all: bool,
pub(crate) scale_factor: f64,
}

// --- MARK: GETTERS ---
Expand Down Expand Up @@ -1265,7 +1264,6 @@ impl<'s> AccessCtx<'s> {
global_state: self.global_state,
tree_update: self.tree_update,
rebuild_all: self.rebuild_all,
scale_factor: self.scale_factor,
};
RawWrapper {
ctx: child_ctx,
Expand Down
20 changes: 9 additions & 11 deletions masonry/src/passes/accessibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn build_accessibility_tree(
mut widget: ArenaMut<'_, Box<dyn Widget>>,
mut state: ArenaMut<'_, WidgetState>,
rebuild_all: bool,
scale_factor: f64,
scale_factor: Option<f64>,
) {
let _span = enter_span_if(
global_state.trace.access,
Expand Down Expand Up @@ -49,10 +49,12 @@ fn build_accessibility_tree(
widget_children: widget.children.reborrow_mut(),
tree_update,
rebuild_all,
scale_factor,
};
let mut node = build_access_node(widget.item, &mut ctx);
widget.item.accessibility(&mut ctx, &mut node);
if let Some(scale_factor) = scale_factor {
node.set_transform(accesskit::Affine::scale(scale_factor));
}

let id: NodeId = ctx.widget_state.id.into();
if ctx.global_state.trace.access {
Expand All @@ -79,7 +81,7 @@ fn build_accessibility_tree(
widget,
state.reborrow_mut(),
rebuild_all,
scale_factor,
None,
);
parent_state.merge_up(state.item);
},
Expand All @@ -89,10 +91,7 @@ fn build_accessibility_tree(
// --- MARK: BUILD NODE ---
fn build_access_node(widget: &mut dyn Widget, ctx: &mut AccessCtx) -> Node {
let mut node = Node::new(widget.accessibility_role());
node.set_bounds(to_accesskit_rect(
ctx.widget_state.window_layout_rect(),
ctx.scale_factor,
));
node.set_bounds(to_accesskit_rect(ctx.widget_state.window_layout_rect()));

node.set_children(
widget
Expand Down Expand Up @@ -124,9 +123,8 @@ fn build_access_node(widget: &mut dyn Widget, ctx: &mut AccessCtx) -> Node {
node
}

fn to_accesskit_rect(r: Rect, scale_factor: f64) -> accesskit::Rect {
let sr = r.scale_from_origin(scale_factor);
accesskit::Rect::new(sr.x0, sr.y0, sr.x1, sr.y1)
fn to_accesskit_rect(r: Rect) -> accesskit::Rect {
accesskit::Rect::new(r.x0, r.y0, r.x1, r.y1)
}

// --- MARK: ROOT ---
Expand Down Expand Up @@ -172,7 +170,7 @@ pub(crate) fn run_accessibility_pass(root: &mut RenderRoot, scale_factor: f64) -
root_widget,
root_state,
root.rebuild_access_tree,
scale_factor,
Some(scale_factor),
);
root.rebuild_access_tree = false;

Expand Down

0 comments on commit 3b18fc3

Please sign in to comment.