Skip to content
This repository was archived by the owner on Nov 12, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions apps/leaf-dioxus/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions apps/leaf-dioxus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ blitz-traits = "=0.3.0-beta.4"
# `View::accessibility_action_events` through the app's own window events:
# the version blitz-shell's `accessibility` uses.
accesskit_xplat = "0.2"
# The tree itself, where the editor's text goes in (`access.rs`).
accesskit = "0.25"
# Export as PDF and Print (`pdf.rs`): Blitz's paint recorded, and drawn again
# as PDF pages by krilla, glyphs' characters read back from their fonts.
anyrender = "0.14"
Expand Down
31 changes: 26 additions & 5 deletions apps/leaf-dioxus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,25 @@ app carries out through its own handling of window events. The tree is rebuilt a
rebuilds it only on a poll that finds changes, which the app's own resolves
have usually taken first. The iOS side is the fork's `examples/ios-a11y`.

The document is a text area (`AXTextArea`), not static text. Each tree
built passes through a hook (`access.rs`, blitz-shell's
`View::set_accessibility_tree_hook`) that hands the editor's element to the
editor (`Editor::describe`, the widget's `access.rs`): its value is the
whole text, and its children are text runs, one per visual line, with each
character's length, position and width, where its words start, and the
selection. In the rendered view the text is the text as shown; in the
source view it is the Markdown. So assistive tech reads AXValue,
AXNumberOfCharacters, AXSelectedText and AXSelectedTextRange, AXInsertionPointLineNumber,
AXRangeForLine, AXLineForIndex, AXStringForRange and AXBoundsForRange, and
VoiceOver reads by line and word. Setting AXValue or AXSelectedTextRange
comes back as AccessKit's `SetValue` or `SetTextSelection`, which the
editor carries out through the document as typing does
(`Editor::accessibility_action`): a new value replaces only the stretch
that differs, typed over. The text and its runs are kept while the
document, the caret and the rows' layouts are unchanged, so a frame that
changes neither costs about a millisecond (120,000 characters, debug
build).

**winit is patched.** Its macOS backend is kept, patched, in the Blitz
fork's `patches/winit-appkit` (`PATCH.md` there says what and why;
`upstream/` is the change prepared for winit), and the app takes it by git
Expand Down Expand Up @@ -446,13 +465,15 @@ An agent can test the app without taking the screen from whoever is using it
`open`, which brings the app forward; `additional_arguments` passes it
arguments.
- **Reading it.** `get_window_state` captures one window even when it is
covered or minimized. The tree holds only the window's own buttons and the
menu bar: the page is drawn by Blitz and has no accessibility elements.
Read frames with `list_windows` or `System Events` (`position`, `size`).
covered or minimized. The document is an `AXTextArea` whose value is its
text (see "Accessibility" above), and the toolbar's controls are buttons
and checkboxes. Read frames with `list_windows` or `System Events`
(`position`, `size`).
- **Acting on it.** Menu items through `invoke_menu`, which does not
activate the app; window buttons by their element tokens; text with
`type_text` and a point in the page, which reaches the editor in a covered
window. A pixel click in the background does not move the caret, and keys
`set_value` on the text area's element token, read back from its value
(checked on 2026-10-22, in a covered window), or `type_text` and a point in
the page. A pixel click in the background does not move the caret, and keys
to a minimized window are refused. `delivery_mode: "foreground"` brings the
app forward and moves the real pointer: not for a screen someone is using.
`set_window_frame` moves and sizes a window, between displays too.
Expand Down
82 changes: 82 additions & 0 deletions apps/leaf-dioxus/src/access.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//! The document's text in each window's accessibility tree.
//!
//! Blitz builds the tree from the page, where the editor's rows are divs of
//! static text. Each tree built passes through the hook installed here,
//! which hands the editor's element ([`leaf_dioxus::TEXT_ID`]) to the
//! editor to make a text area of — its value, text runs and selection — in
//! place of the nodes under it. What assistive tech asks of that text area
//! comes back through [`action`].

use std::collections::HashSet;

use accesskit::{ActionRequest, NodeId, TreeUpdate};
use blitz_dom::BaseDocument;
use blitz_shell::View;
use dioxus_native::winit::window::WindowId;
use leaf_dioxus::{TEXT_ID, is_text_run};

use crate::app::page;
use crate::renderer::Renderer;

/// What AccessKit calls the window: the root Blitz gives the tree.
const WINDOW: NodeId = NodeId(u64::MAX);

/// Pass every tree built for window `id` through [`describe`].
pub fn install(view: &mut View<Renderer>, id: WindowId) {
view.set_accessibility_tree_hook(move |doc, tree| describe(id, doc, tree));
}

/// Make the editor's element in `tree` the document's text area, if the
/// window has an editor.
fn describe(id: WindowId, doc: &BaseDocument, tree: &mut TreeUpdate) {
let Some(ed) = page(id).and_then(|p| p.editor()) else {
return;
};
let Some(text) = doc.get_element_by_id(TEXT_ID) else {
return;
};
let text_id = NodeId(text.as_u64());
let Some(at) = tree.nodes.iter().position(|(n, _)| *n == text_id) else {
return;
};
let Some(runs) = ed.describe(&mut tree.nodes[at].1) else {
return;
};
// The rows' nodes go: the runs stand for them.
let mut under = HashSet::new();
let mut stack: Vec<_> = doc
.get_node(text)
.map_or(Vec::new(), |n| n.children.to_vec());
while let Some(n) = stack.pop() {
under.insert(n.as_u64());
if let Some(node) = doc.get_node(n) {
stack.extend(node.children.iter().copied());
}
}
tree.nodes.retain(|(n, _)| !under.contains(&n.0));
tree.nodes.extend(runs);
// The editor has the keys unless one of the page's controls has them,
// so it has the focus too: the caret VoiceOver follows is its.
let focus = tree.focus;
let root = NodeId(doc.root_node().id.as_u64());
if focus == WINDOW
|| focus == root
|| under.contains(&focus.0)
|| !tree.nodes.iter().any(|(n, _)| *n == focus)
{
tree.focus = text_id;
}
}

/// Carry out what assistive tech asks of the editor's text area or one of
/// its runs, in window `id`: whether it was the editor's to do.
pub fn action(view: &View<Renderer>, id: WindowId, request: &ActionRequest) -> bool {
let text = view.doc.inner().get_element_by_id(TEXT_ID);
let target = request.target_node;
if !is_text_run(target) && text.map(|t| NodeId(t.as_u64())) != Some(target) {
return false;
}
page(id)
.and_then(|p| p.with_editor(|ed, _| ed.accessibility_action(request)))
.unwrap_or(false)
}
10 changes: 10 additions & 0 deletions apps/leaf-dioxus/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ impl App {
});
doc.initial_build();
}
crate::access::install(&mut view, window.id());
view.resume();
view.request_redraw();
self.blitz.windows.insert(window.id(), view);
Expand Down Expand Up @@ -587,9 +588,18 @@ impl ApplicationHandler for App {
// A press assistive tech asks for is carried out as a click,
// through this app's own handling of window events, so the page
// and the editor see it as they see a hand's.
// What it asks of the document's text is the editor's.
if let BlitzShellEvent::Accessibility { window_id, data } = &event
&& let accesskit_xplat::WindowEvent::ActionRequested(request) = &**data
{
let edited = self
.blitz
.windows
.get(window_id)
.is_some_and(|view| crate::access::action(view, *window_id, request));
if edited {
continue;
}
let events = self
.blitz
.windows
Expand Down
1 change: 1 addition & 0 deletions apps/leaf-dioxus/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
//! `LEAF_TRACE=1` logs keys, pointer events and repaint timings to stderr;
//! `LEAF_OUTLINE=1` outlines every visual line and run.

mod access;
mod app;
mod commands;
mod context;
Expand Down
1 change: 1 addition & 0 deletions crates/leaf-dioxus/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/leaf-dioxus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ parley = "=0.12.0"
unicode-width = "0.2"
# Grapheme clusters, the unit a column advances by, as core walks them.
unicode-segmentation = "1.13"
# The document as assistive tech reads and edits it (`access.rs`): the
# AccessKit Blitz's accessibility tree is made of, at the version it uses.
accesskit = "0.25"

# Block pictures (`media.rs`): a picture's size off its header, an SVG's off
# its canvas, so the block's height is known before Blitz has decoded it. Both
Expand Down
8 changes: 8 additions & 0 deletions crates/leaf-dioxus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ is the Swift editor's defaults.
follow. It does not clip to the box: Blitz will not repaint a clip that
changes, so the stylesheet still clips at `body`, and the host covers what
lies outside the box with its own chrome, in a stacking layer above it.
- **Assistive tech** reads the document as text when the host hands the
editor its element's node. Blitz's tree has the page's rows as static
text; a host with blitz-shell's `View::set_accessibility_tree_hook` finds
the element by its id, `TEXT_ID`, gives its node to `Editor::describe`,
which makes it a text area and answers its text runs, and puts the runs in
the tree in place of the nodes under it. The requests that come back for
that node or a run (`is_text_run`) go to `Editor::accessibility_action`.
`apps/leaf-dioxus/src/access.rs` does all three.
- **Under a finger** (iOS), a tap places the caret and raises the keyboard,
a drag scrolls, and a sideways drag, where `Editor::set_turns` allows it,
slides the page and is `Host::turn` when let go far enough. The keyboard is
Expand Down
Loading
Loading