Skip to content
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
1 change: 1 addition & 0 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions changelog.d/claude-project-thread-0t1td0-content-roles.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
that carries only a name (image, heading, text-level roles), keeps its own role and gains
their names (ADR-0332). A button over a labelled image is announced "Add, button" and found
by that name, where it was a nameless button with an image beneath it. A meter or a progress
bar inside a control stays a node. Content that must stay a stop of its own, or be found by
its `identifier`, is wrapped in `Semantics::container(true)`: an identifier on absorbed
content is not published.
bar inside a control stays a node. Content that must stay a stop of its own is wrapped in
`Semantics::container(true)`; an identifier on absorbed content names the control's node when
the control has none, and content named otherwise than its control stays a node of its own
(ADR-0407).

### Removed

Expand Down
17 changes: 17 additions & 0 deletions changelog.d/claude-project-thread-f2wym8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### Changed

- `Semantics::label` around a control names that control's own node, whatever the control: a
`Switch`, `Checkbox`, `Radio`, `CupertinoButton` or `ListTile` joins the annotation, as in
Flutter 3.50.1, and a button, a chip or a `FloatingActionButton` takes a `Semantics` that holds
nothing else, where Flutter would publish the label as a second node with no action above the
button. The label reads before the control's own text ("Send Go"). A `Semantics` over a control
and other content stays a node above them, and a button or chip stays apart from the content
beside it (ADR-0407).
- A disabled control no longer joins a node that offers a user action of its own: in a tappable
row it keeps its own disabled node, and the row keeps its tap (ADR-0407).
- A semantics configuration absorbed into another node gives that node its identifier when the
node has none of its own, so a control's `identifier` survives joining the `Semantics` that
names it. Outside a `MergeSemantics`, a configuration whose identifier differs from the node
above it forms a node of its own and keeps it. A control that joins its row now names the row,
so a row template that repeats the control's identifier in every row reports a sibling clash:
name each row instead (ADR-0407).
7 changes: 4 additions & 3 deletions changelog.d/semantics-identifier.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
`flui-cupertino`, ADR-0240): `SemanticsConfiguration::set_identifier`/`identifier` give a node a
stable id for tests and automation. It is published as AccessKit `author_id` (UI Automation's
`AutomationId`, macOS `AXIdentifier`, AT-SPI's accessible id) and as the wire `Node.identifier`
of an agent read, and it is never announced. It names only the node its own configuration
forms: it makes no boundary and annotates nothing, and a parent or `MergeSemantics` that absorbs
the configuration does not take it.
of an agent read, and it is never announced. It makes no boundary and annotates nothing; absorbed
into a parent or merged by `MergeSemantics`, it names that node when the node has none of its
own, and outside a merge a configuration named otherwise than the node above it forms a node of
its own (ADR-0407).
- `Semantics::identifier`, `MergeSemantics::identifier` (with `RenderMergeSemantics::set_identifier`)
and an `identifier` builder on `RawButton`, `Disclosure`, `EditableText` and
`RawTextField`; in `flui-material` on `ElevatedButton`, `FilledButton`, `OutlinedButton`,
Expand Down
3 changes: 2 additions & 1 deletion crates/flui-objects/src/proxy/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,8 @@ impl RenderMergeSemantics {
/// Names the merged node for tests and automation (ADR-0240). The merge is
/// the boundary that forms the node, so the identifier of a control
/// assembled from merged parts belongs here: a descendant's own identifier
/// is not carried into the merged node.
/// names the merged node only when this is unset, the first one merged
/// winning (ADR-0407).
pub fn set_identifier(
&mut self,
identifier: Option<std::sync::Arc<str>>,
Expand Down
56 changes: 56 additions & 0 deletions crates/flui-rendering/src/pipeline/owner/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,25 @@ fn build_semantics_fragments_impl<'f>(
});
}

if let Some(mut control) =
sole_control_it_names(&config, &decisions, clipped.hidden, &mut child_fragments)
{
// The annotation was the item's root: the position stamped on it is
// the control's now.
apply_lazy_child_semantic_index(
node,
tree.parent(id),
&mut control.config,
&control.children,
);
let mut nodes = Vec::with_capacity_in(1, arena);
nodes.push(SemanticsFragment::Formed(control));
return Some(SemanticsFragments {
nodes,
blocks_previous_siblings,
});
}

let (children, absorbed_inside) = merge_child_fragments(
&mut config,
&rect,
Expand Down Expand Up @@ -934,6 +953,43 @@ fn build_semantics_fragments_impl<'f>(
})
}

/// The control node an annotation names when the control is all it holds: a
/// `Semantics` around a button, a chip or a FAB names the control's own node
/// instead of forming one above it, as one around a switch does by joining it
/// (ADR-0407 §2). Flutter forms the node above, so a screen reader stops
/// twice, once on a name with no action and once on the nameless button.
///
/// The annotation is none of a boundary, a merge or a part of one, its only
/// child fragment is a formed node whose role its content names, and the two
/// can share a node (`can_absorb`). Anything else is assembled as before.
fn sole_control_it_names<'f>(
config: &SemanticsConfiguration,
decisions: &NodeAssemblyDecisions,
hidden_by_clip: bool,
fragments: &mut FrameVec<'f, SemanticsFragment<'f>>,
) -> Option<BuiltSemanticsNode<'f>> {
let annotation = config.has_been_annotated()
&& !config.is_semantics_boundary()
&& !config.is_merge_boundary()
&& !config.explicit_child_nodes()
&& !decisions.children_merge_into_ancestor
&& !hidden_by_clip;
if !annotation {
return None;
}
let [SemanticsFragment::Formed(control)] = fragments.as_mut_slice() else {
return None;
};
if !control.config.names_a_control(true, false) || !config.can_absorb(&control.config, true) {
return None;
}
control.config.absorb_enclosing(config);
match fragments.pop() {
Some(SemanticsFragment::Formed(control)) => Some(control),
_ => None,
}
}

/// Checks that the regions holding a text's runs (ADR-0214 §2 as amended)
/// hold each of its runs once, in run order: their ranges, in region order,
/// are consecutive and cover every run. Regions hold runs only of the text
Expand Down
3 changes: 2 additions & 1 deletion crates/flui-rendering/tests/contract_matrices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ fn lifecycle_matrix() {
fn semantics_assembly_matrix() {
let cases: &[(&str, fn())] = &[
("semantics_assembly::a_semantics_clip_drops_a_child_that_falls_entirely_outside_it", crate::semantics_assembly::a_semantics_clip_drops_a_child_that_falls_entirely_outside_it),
("semantics_assembly::an_identifier_names_only_the_node_its_configuration_forms", crate::semantics_assembly::an_identifier_names_only_the_node_its_configuration_forms),
("semantics_assembly::an_identifier_names_the_node_its_configuration_forms_or_joins", crate::semantics_assembly::an_identifier_names_the_node_its_configuration_forms_or_joins),
("semantics_assembly::an_annotation_around_a_control_alone_names_the_controls_node", crate::semantics_assembly::an_annotation_around_a_control_alone_names_the_controls_node),
("semantics_assembly::a_table_shape_the_role_drops_bounds_no_cell", crate::semantics_assembly::a_table_shape_the_role_drops_bounds_no_cell),
("semantics_assembly::nonfinite_reading_order_is_refused_before_publication", crate::semantics_assembly::nonfinite_reading_order_is_refused_before_publication),
("semantics_assembly::re_assembling_marked_subtrees_refuses_like_the_whole_tree", crate::semantics_assembly::re_assembling_marked_subtrees_refuses_like_the_whole_tree),
Expand Down
102 changes: 92 additions & 10 deletions crates/flui-rendering/tests/semantics_assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,12 @@ fn identified(identifier: &str, label: Option<&str>) -> SemanticsConfiguration {
}
config
}
/// An identifier names only the node its own configuration forms
/// (ADR-0240): a boundary keeps it, a contributor absorbed into its
/// ancestor and a boundary under a merge lose it, and an identifier alone
/// forms no node.
pub(crate) fn an_identifier_names_only_the_node_its_configuration_forms() {
/// An identifier names the node its configuration forms or joins
/// (ADR-0407): a boundary keeps its own, a contributor absorbed into its
/// ancestor names that ancestor when it has none, a merged parent keeps its
/// own over its merged child's, and an identifier alone forms and joins no
/// node.
pub(crate) fn an_identifier_names_the_node_its_configuration_forms_or_joins() {
// The walk root's own children always form nodes, so the cases sit under
// a plain boundary, where contributors are absorbed.
let run = RenderTester::mount(
Expand All @@ -776,12 +777,13 @@ pub(crate) fn an_identifier_names_only_the_node_its_configuration_forms() {
})
.label("save"),
)
// Before the note, so a bare identifier that joined would win.
.child(box_node(SemanticsLeaf {
configuration: Some(identified("note-id", Some("Note"))),
configuration: Some(identified("bare-id", None)),
..SemanticsLeaf::new(20.0)
}))
.child(box_node(SemanticsLeaf {
configuration: Some(identified("bare-id", None)),
configuration: Some(identified("note-id", Some("Note"))),
..SemanticsLeaf::new(20.0)
}))
.child(
Expand Down Expand Up @@ -822,13 +824,14 @@ pub(crate) fn an_identifier_names_only_the_node_its_configuration_forms() {
assert_eq!(node_of(save).config().identifier(), Some("save-id"));
assert_eq!(
node_of(group).config().identifier(),
None,
"an absorbed contributor's identifier does not cross into its ancestor"
Some("note-id"),
"an absorbed contributor names the ancestor that has no identifier; \
the bare identifier beside it is absorbed by nobody"
);
assert_eq!(
node_of(group).label(),
Some("Note"),
"the absorbed label arrives without its identifier"
"the absorbed label arrives without its identifier as text"
);
assert_eq!(
node_of(card).config().identifier(),
Expand Down Expand Up @@ -1322,3 +1325,82 @@ pub(crate) fn a_handler_that_panics_in_a_graft_leaves_containment_to_a_rebuild()
"every child of the holder is contained now, so it clips them"
);
}

/// A configuration with `label` and nothing else.
fn labelled(label: &str) -> SemanticsConfiguration {
let mut config = SemanticsConfiguration::new();
config.set_label(label);
config
}

/// An annotation whose only content is a control's node names that node
/// (ADR-0407 §2): the control's node takes the annotation's label before its
/// own, and no node forms above it. An annotation over the control and other
/// content still forms the node above both.
pub(crate) fn an_annotation_around_a_control_alone_names_the_controls_node() {
let run = RenderTester::mount(
box_node(SemanticsContainer::default()).label("root").child(
box_node(SemanticsContainer::default().with_boundary())
.label("group")
.child(
box_node(SemanticsContainer::default().with_configuration(labelled("Send")))
.label("label")
.child(
box_node(SemanticsLeaf {
configuration: Some(labelled("Go")),
..SemanticsLeaf::new(20.0).with_boundary().with_button()
})
.label("button"),
),
)
.child(
box_node(SemanticsContainer::default().with_configuration(labelled("Row")))
.label("row")
.child(box_node(SemanticsLeaf {
configuration: Some(labelled("Draft")),
..SemanticsLeaf::new(20.0)
}))
.child(
box_node(SemanticsLeaf {
configuration: Some(labelled("Open")),
..SemanticsLeaf::new(20.0).with_boundary().with_button()
})
.label("open"),
),
),
),
)
.with_constraints(constraints())
.with_semantics_enabled()
.run_frame();

let root = accessibility_id(run.id("root"));
let group = accessibility_id(run.id("group"));
let button = accessibility_id(run.id("button"));
let open = accessibility_id(run.id("open"));
assert_snapshot_preorder(&snapshot(&run), &[root, group, button, open]);

let owner = run
.owner()
.semantics_owner()
.expect("semantics must remain enabled");
let node_of = |id: AccessibilityNodeId| {
owner
.tree()
.iter()
.find(|(_, node)| node.accessibility_id() == Some(id))
.map(|(_, node)| node)
.expect("every expected accessibility identity resolves")
};
assert_eq!(
node_of(button).label(),
Some("Send Go"),
"the annotation's label reads first, on the control's node"
);
assert_eq!(
node_of(group).label(),
Some("Row Draft"),
"an annotation over more than the control is absorbed above it"
);
assert_eq!(node_of(open).label(), Some("Open"));
}
32 changes: 21 additions & 11 deletions crates/flui-semantics/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -851,17 +851,26 @@ cross-thread handoff is the AccessKit `TreeUpdate`. `SemanticsAttributes` is the
consumers read and write a node through `SemanticsConfiguration`'s accessors. A selection-only annotation still reaches the
platform (`a_selection_only_annotation_reaches_the_platform`).

### The identifier names only the node its own configuration forms
### The identifier names the node its configuration forms or joins

**Rule.** [ADR-0240](../../docs/adr/ADR-0240-semantics-identifier.md)'s identifier is published as
AccessKit `author_id` and as the wire `Node.identifier`, and never as text. Setting it neither marks
the configuration annotated nor makes it a boundary, and `absorb` never takes it: a configuration
with only an identifier contributes nothing, and one absorbed into an ancestor or a
`MergeSemantics` loses it while the receiver keeps its own. A widget names its node where the node
is formed: a container `Semantics`, `MergeSemantics::identifier`, or a control whose own
configuration is the outermost of its parts. A node AccessKit's filter lifts into its parent (no
role, label or text, or the `Generic` or `Presentation` role) takes its identifier with it, so no
agent or OS automation locator selects it (the web mirror still writes `data-flui-id`).
the configuration annotated nor makes it a boundary, so a configuration with only an identifier
contributes nothing and names no node. `absorb` carries it, first wins
([ADR-0407](../../docs/adr/ADR-0407-an-annotation-names-the-control-it-holds.md)): a
configuration absorbed into an ancestor or a `MergeSemantics` names that node when the node has no
identifier of its own, and the receiver keeps its own when it has one. So a control that joins the
`Semantics` above it keeps its identifier on the node it joined, as Flutter's
`SemanticsConfiguration.absorb` does (flutter/flutter@3.50.1
`packages/flutter/lib/src/semantics/semantics.dart:6954`). A node publishes one identifier, so
outside a merge two different ones are two nodes: `can_absorb` and `can_join` refuse a
configuration whose identifier differs from the node's or a sibling's, and it forms a node of its
own that keeps its id (Flutter keeps the first and drops the other). A `MergeSemantics` takes
everything, its own identifier or the first merged one. A control's node that takes the `Semantics`
holding only it (`absorb_enclosing`) reads that annotation first, so its identifier wins there as
its label reads first. A node AccessKit's filter lifts into its
parent (no role, label or text, or the `Generic` or `Presentation` role) takes its identifier with
it, so no agent or OS automation locator selects it (the web mirror still writes `data-flui-id`).
`read_wire` lists a `TreeDiagnostic::UnpublishedIdentifier` for each identifier and node it is
lifted into, at most 4 nodes per identifier (a row template names its first rows) and 256 in all,
and the deprecated `flui_testing::tester::TestError::UnpublishedIdentifier` (the scenario
Expand All @@ -872,10 +881,11 @@ a failure, so `to_be_gone` still passes on a lifted identifier. Past the cap a
lookup falls back to `NotFound`.

**Why.** An identifier that annotated or split nodes would change the tree, and so what a screen
reader says, by adding a test id; one carried upward would name a node with another node's id, and
a merged parent would collect its children's.
reader says, by adding a test id. One dropped on absorb would lose a control's id whenever the
control joins the annotation that names it; first wins keeps a node that names itself from taking
a descendant's id, and keeps a merged parent to one id.

**Test.** `the_identifier_is_exported_unannounced_unmerged_and_no_boundary` in
**Test.** `the_identifier_is_exported_unannounced_no_boundary_and_joins_first_wins` in
`tests/identifier.rs`, `an_identifier_on_a_node_that_publishes_nothing_else_is_reported` and
`unpublished_identifiers_are_reported_once_per_parent_and_bounded`,
`an_identifier_lifted_under_many_parents_leaves_room_for_the_rest` there; the `identifier` row of
Expand Down
Loading
Loading