1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: 2026 FernTech
//! A node's description, computed from the nodes it is `described_by`.
//!
//! ## Why the framework computes it
//!
//! A `described_by` relation reaches no screen reader through AccessKit 0.25.
//! `accesskit_consumer-0.39.0` gives a node a description from its own
//! `description` property and nothing else (`node.rs:796-800`), unlike its name,
//! which it does assemble from `labelled_by` (`node.rs:774-793`). And no adapter
//! exports the relation: the AT-SPI relation set holds `ControllerFor` alone
//! (`accesskit_atspi_common-0.20.0/src/node.rs:960-977`), UIA answers
//! `ControllerFor` and never `DescribedBy` (`accesskit_windows-0.35.0/src/node.rs:
//! 1044`), and macOS links only `controls` (`accesskit_macos-0.27.0/src/node.rs:
//! 1161-1176`). So a field that points at its validation message is read as if it
//! pointed at nothing. This pass does what a browser's accessible-description
//! computation does with `aria-describedby`: it writes the text of every target
//! onto the node's `description`, after the node's own. That property is what
//! each platform reads: AT-SPI `Description` (`accesskit_atspi_common` `node.rs:
//! 46-48, 835-840`), UIA `FullDescription` (`accesskit_windows` `node.rs:415-421,
//! 1311`), macOS `accessibilityHelp` (`accesskit_macos` `node.rs:543-550`).
//!
//! The relation is kept beside it. Orca, the one reader that follows it, reads
//! the relation's targets only when the description is empty (Orca 46.1,
//! `orca/generator.py:463-464`: `get_description(obj) or
//! displayedDescription(obj)`), so a node carrying both is read once.
//!
//! ## What the readers do with a description
//!
//! - **Orca 46.1** reads it as focus arrives: a node newly focused is spoken
//! in the `unfocused` format (`orca/generator.py:227-231`), whose suffix
//! includes `description` (`orca/formatting.py:129`), with
//! `speakDescription` on by default (`orca/settings.py:243`).
//! It also **speaks a change to it** on the focused node, with no check that
//! the text is new: `onDescriptionChanged` compares against
//! `pointOfReference['description']`, a key nothing writes (the focus handler
//! stores `'descriptions'`), and presents any non-empty text
//! (`orca/scripts/default.py:1316-1335`). Changes on other nodes are ignored.
//! - **NVDA** (source at nvaccess/nvda `f56b2e0d`) takes a UIA element's
//! description from `FullDescription`, falling back to `HelpText`
//! (`NVDAObjects/UIA/__init__.py` `_get_description`), and reports it on focus
//! (`presentation.reportObjectDescriptions`, default on). It maps no event to a
//! `FullDescription` change (`UIAHandler/__init__.py`
//! `UIAPropertyIdsToNVDAEventNames` lists `HelpText` only), so a change is not
//! spoken.
//! - **VoiceOver** is closed source. It reads `AXHelp` as a hint, after a pause
//! or on VO-Shift-H; that is documented behaviour, not verified here.
//! `accesskit_macos` posts no notification when a description changes
//! (`event.rs` `node_updated` posts title, value and selected-text changes).
//!
//! ## The order an update arrives in
//!
//! Every adapter hears an update through `accesskit_consumer`, which reports
//! the nodes added and changed first and the focus move after them
//! (`tree.rs:640-673`). So an announcement, and a description change on the
//! node focus is leaving, both reach a reader before it learns where focus
//! went. What the readers then do with them differs:
//!
//! - **Orca 46.1** stops speaking before it reads the new focus:
//! `locusOfFocusChanged` calls `presentationInterrupt`
//! (`orca/scripts/default.py:698-705`), which is `speech.stop()` and so a
//! speech-dispatcher cancel (`orca/scripts/default.py:2674-2682`,
//! `orca/speech.py:309-311`, `orca/speechdispatcherfactory.py:358-359`),
//! whenever `shouldInterruptForLocusOfFocusChange` says so, and for a focus
//! event it does unless one node is the other's named ancestor or controls
//! it (`orca/script_utilities.py:4125-4171`). An announcement made in the
//! update focus moves in is cut before it is heard. Orca still holds the
//! node focus is leaving as its focus while it handles that node's changes,
//! so it speaks a description change there (the check in
//! `orca/scripts/default.py:1316-1335` is against the focus it has, not the
//! one the update carries), and cuts that too. Read from the source, not
//! heard from a running Orca.
//! - **NVDA** does not stop: `event_gainFocus` reads the node with
//! `speakObject` and cancels nothing (`NVDAObjects/__init__.py:1204-1206,
//! 1365-1372`; `eventHandler.py` `doPreGainFocus` drops only speech queued
//! for an earlier focus), and a live region is a `ui.message`
//! (`NVDAObjects/__init__.py:1238-1253`). Both are heard, in order.
//!
//! ## Why a description does not always take the text at once
//!
//! A description is for arriving; a change is for a live region. Written
//! naively, the text reaches a reader twice, or not at all, in the moments that
//! matter most:
//!
//! - a field validates while the user is still in it (Enter, or an app setting
//! the error), its `ValidationStrip` announces the message, and the focused
//! field's description changes to the same message, which Orca speaks again;
//! - the user leaves that field, the message the description held back joins
//! it in the update focus moves in, and Orca starts saying it once more as
//! it leaves, only to cut it for the next field;
//! - focus is sent to the field at fault in the same update the message is
//! announced (the WCAG pattern of focusing the first error). NVDA says the
//! announcement and then the field, so a description holding the message too
//! says it twice; Orca cuts the announcement, so a description without the
//! message leaves nothing that says it.
//!
//! So:
//!
//! 1. **Only where the reader keeps an announcement through a focus move**, a
//! text some live region is announcing in this very update (a live node the
//! adapters see newly, re-worded or with a new politeness, the framework's
//! announcer included) is left out of the node focus is on and every node
//! it is inside. That is Windows, where NVDA keeps it. On AT-SPI Orca cuts
//! it, so the arrival is the one voice left and keeps the text. VoiceOver
//! is unverified and is treated as Orca is: a text left out of the arrival
//! and cut from the announcement is not heard at all, while one kept is at
//! worst heard twice, the second time as a hint after a pause. The
//! framework's announcer does not speak in an update that moves focus: it
//! holds its message for the next (see [`crate::announcer`]), where every
//! reader hears it after the arrival, so its text is left out of the
//! arrival on every platform.
//! 2. **A node focus was on or inside in the last delivered update** gains no
//! text in this one: not while focus stays, where Orca speaks the change,
//! and not as focus leaves it, where Orca starts to. It may lose one: a
//! message that has gone away is dropped, never read out as stale. A node
//! focus has left takes what it held back in the next update, which the
//! tree asks for itself; by then Orca's focus is elsewhere.
//!
//! A left-out text arrives the next time focus does. Rule 1 defers to a voice
//! saying the text at that moment, where that voice is known to be heard.
//! Rule 2 costs only a change Orca alone would have spoken, so on every
//! platform a message that must be heard as it appears needs a live region,
//! and one without it is heard on the next arrival.
//!
//! ## A node's keyboard shortcut
//!
//! An interim, until AccessKit's adapters export it. A node's own
//! `keyboard_shortcut` (a menu row's chord, a command palette row's, a control
//! given `access_shortcut_id` or `access_shortcut_literal`) reaches no screen
//! reader in the pinned versions: `accesskit_windows-0.35.2` sets no UIA
//! `AcceleratorKey`, `accesskit_atspi_common-0.21.1` answers an empty key
//! binding for every action (`node.rs:1112-1113`), and `accesskit_macos-0.27.2`
//! has nothing for it (AccessKit #668 is open for AT-SPI). So this pass also
//! writes the chord at the end of the node's description, which every reader
//! reports, behind the one switch [`CHORD_IN_DESCRIPTION`]: turn it off once
//! the adapters export the shortcut, or readers say it twice.
//!
//! - The chord follows what the description already says after `", "`, which
//! is punctuation (a pause in speech, a break in braille), not a
//! translatable string; alone, it is the whole description. It is the
//! string the node carries, with no prefix.
//! - It is left out when it is empty, when it is the node's own text, or when
//! the description already holds it as a whole token (bounded by the start
//! or end of the text or by a character that is neither alphanumeric nor
//! `+`), so a description such as "Saves the file (Ctrl+S)" is not doubled
//! and a bare-key chord "S" is not taken to be in "Saves". The comparison is
//! literal: `access_shortcut_id` writes `KeyStroke`'s `Display` form
//! ("Ctrl+S", "Cmd+S"), while a widget's own text may hold the localized
//! `format_keystroke` form ("Strg+S", "⌘S"), and the two count as
//! different, so such a control hears its chord twice.
//! - It is the node's own text, a property its widget sets on every walk like
//! its own description, not text drawn from a relation, so rules 1 and 2 do
//! not apply to it: it is written as soon as it is there, a focused node
//! included. It is not part of what [`DescriptionMemory`] remembers, so the
//! rules judge relation text against the same history with the switch on or
//! off.
use ;
use ;
use WidgetTree;
/// Whether a node's `keyboard_shortcut` is also written at the end of its
/// description (see the module docs, "A node's keyboard shortcut").
///
/// On because no adapter in the pinned AccessKit versions exports the
/// shortcut: UIA has no `AcceleratorKey`, the AT-SPI adapter answers an empty
/// key binding (`accesskit_atspi_common-0.21.1` `node.rs:1113`, AccessKit
/// #668), macOS has nothing. Turn it off once they export it as UIA
/// `AcceleratorKey`, the AT-SPI key binding and the macOS equivalent;
/// otherwise readers say the chord twice.
pub const CHORD_IN_DESCRIPTION: bool = true;
/// The separator written before a chord that follows other text. Not
/// translated: teksilo-core has no translations, so an Arabic or a CJK
/// description shows an ASCII comma here.
const CHORD_SEPARATOR: &str = ", ";
/// The node's chord, trimmed, when [`CHORD_IN_DESCRIPTION`] is on and it has
/// one that is not empty.
/// The chord to append to `assembled`, the description built so far: none
/// when the node's own text (its name) or `assembled` already holds it as a
/// whole token, so "Save (Ctrl+S)" is not followed by "Ctrl+S" again.
/// Whether `text` holds `token` bounded on each side by its start or end or
/// by a character that is neither alphanumeric nor part of a chord (`+`, and
/// the macOS modifier glyphs, which join a chord with no `+`: "⌘S").
/// What a platform's screen reader does with an announcement made in the
/// update focus moves in, which decides rule 1 (see the module docs).
pub
/// What the last delivered update said, as far as this pass needs to know.
///
/// Kept by [`WidgetTree::sync_accessibility`], which is the only caller whose
/// update reaches a screen reader; a snapshot reads it and never writes it.
pub
/// The name every adapter announces for a live node: the value of a
/// `Role::Label` and the label of anything else, and neither in place of the
/// other (`accesskit_consumer` `node.rs:744-746`; see
/// [`crate::accessibility::announced_text`]). A name drawn through
/// `labelled_by` is not followed here, so a live region named that way is not
/// taken to be speaking, and rule 1 leaves its text in the arrival.
/// The text a node carries, for a description to quote: its name, or for a
/// node named from its value (a `Role::Label`, per `accesskit_consumer`
/// `node.rs:744-746`) its value, and failing that the other of the two. This
/// is what a target shows, not what an adapter would announce for it, which
/// is [`spoken_name`].
/// The text a relation target contributes: its own, or failing that the text
/// of what it contains, in reading order.
///
/// As in the accessible-name computation a browser runs for
/// `aria-describedby`, a target counts even when it is hidden, since pointing
/// at hidden text is how a description is kept off the reading path; what a
/// target contains counts only when it is not hidden. Text runs are skipped.
/// A node with text of its own stops the walk before its runs are reached, so
/// the runs met here belong to a node that carries its text in runs alone,
/// which is a document surface (the code editor, the log): its whole visible
/// text read out on every arrival is not a description, and a target meant to
/// be read says what it means as a name or a value.