use accesskit::Role;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum SurfaceId {
Omnibar,
CommandPalette,
NodeFinder,
ContextMenu,
ConfirmDialog,
NodeCreate,
FrameRename,
StatusBar,
TreeSpine,
NavigatorHost,
TilePane,
CanvasPane,
BaseLayer,
RosterPane,
InspectorPane,
StewardPane,
GlossPane,
ApparatusPane,
CommsPane,
WorkbenchPane,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AccessibilityDescriptor {
pub role: Role,
pub label: &'static str,
pub description: Option<&'static str>,
pub keyboard_shortcut: Option<&'static str>,
}
impl AccessibilityDescriptor {
pub fn apply(&self, node: &mut accesskit::Node) {
node.set_role(self.role);
node.set_label(self.label);
if let Some(desc) = self.description {
node.set_description(desc);
}
if let Some(ks) = self.keyboard_shortcut {
node.set_keyboard_shortcut(ks);
}
}
}
pub fn descriptor_for(surface: SurfaceId) -> AccessibilityDescriptor {
match surface {
SurfaceId::Omnibar => AccessibilityDescriptor {
role: Role::TextInput,
label: "Address bar",
description: Some(
"URL entry and breadcrumb display. Type a URL and \
press Enter to open it as a node.",
),
keyboard_shortcut: Some("Ctrl+L"),
},
SurfaceId::CommandPalette => AccessibilityDescriptor {
role: Role::Dialog,
label: "Command palette",
description: Some(
"Search and run any registered Graphshell action. \
Type to filter; arrow keys to navigate; Enter to run.",
),
keyboard_shortcut: Some("Ctrl+Shift+P"),
},
SurfaceId::NodeFinder => AccessibilityDescriptor {
role: Role::Dialog,
label: "Node finder",
description: Some(
"Search graph nodes by title, tag, URL, or content. \
Type to filter; arrow keys to navigate; Enter to open.",
),
keyboard_shortcut: Some("Ctrl+P"),
},
SurfaceId::ContextMenu => AccessibilityDescriptor {
role: Role::Menu,
label: "Context menu",
description: Some("Actions available for the right-clicked target."),
keyboard_shortcut: None,
},
SurfaceId::ConfirmDialog => AccessibilityDescriptor {
role: Role::AlertDialog,
label: "Confirm destructive action",
description: Some(
"Press Confirm to proceed with the destructive action, \
or Cancel / Escape to abandon it.",
),
keyboard_shortcut: None,
},
SurfaceId::NodeCreate => AccessibilityDescriptor {
role: Role::Dialog,
label: "Create node",
description: Some(
"Enter a URL or address. Press Enter to create the \
node, or Cancel / Escape to abandon.",
),
keyboard_shortcut: None,
},
SurfaceId::FrameRename => AccessibilityDescriptor {
role: Role::Dialog,
label: "Rename frame",
description: Some(
"Enter a new label for the active Frame. Press Enter \
to apply, or Cancel / Escape to abandon.",
),
keyboard_shortcut: None,
},
SurfaceId::StatusBar => AccessibilityDescriptor {
role: Role::ContentInfo,
label: "Status bar",
description: Some(
"Ambient runtime indicators: ready state, dispatched \
actions, pending intent queue depth, focused node.",
),
keyboard_shortcut: None,
},
SurfaceId::TreeSpine => AccessibilityDescriptor {
role: Role::Tree,
label: "Tree spine",
description: Some("Structural list of nodes in the current workbench."),
keyboard_shortcut: None,
},
SurfaceId::NavigatorHost => AccessibilityDescriptor {
role: Role::Navigation,
label: "Navigator host",
description: Some(
"Sidebar or toolbar host containing the Tree Spine, \
Swatches, and Activity Log buckets.",
),
keyboard_shortcut: None,
},
SurfaceId::TilePane => AccessibilityDescriptor {
role: Role::TabPanel,
label: "Tile pane",
description: Some(
"Pane showing the active tiles of a graphlet. \
Right-click for tile actions.",
),
keyboard_shortcut: None,
},
SurfaceId::CanvasPane => AccessibilityDescriptor {
role: Role::Canvas,
label: "Graph canvas pane",
description: Some(
"Force-directed canvas of graph nodes. Left-drag to \
pan, scroll to zoom, right-click on a node for \
actions.",
),
keyboard_shortcut: None,
},
SurfaceId::BaseLayer => AccessibilityDescriptor {
role: Role::Canvas,
label: "Graph canvas",
description: Some(
"Default home view of the current graph. Right-click \
for graph-level actions.",
),
keyboard_shortcut: None,
},
SurfaceId::RosterPane => AccessibilityDescriptor {
role: Role::List,
label: "Roster pane",
description: Some("List of graph nodes with their current content state."),
keyboard_shortcut: Some("Ctrl+R"),
},
SurfaceId::InspectorPane => AccessibilityDescriptor {
role: Role::Complementary,
label: "Inspector pane",
description: Some(
"Selected object details: provenance, trust, parse diagnostics, document structure, cache state, and lineage.",
),
keyboard_shortcut: None,
},
SurfaceId::StewardPane => AccessibilityDescriptor {
role: Role::Complementary,
label: "Steward pane",
description: Some(
"Live async operations and actionable actor state: fetches, sync, retries, background work, and jobs.",
),
keyboard_shortcut: None,
},
SurfaceId::GlossPane => AccessibilityDescriptor {
role: Role::Navigation,
label: "Gloss pane",
description: Some("Navigator surface for outlines, swatches, and graphlets."),
keyboard_shortcut: Some("Ctrl+G"),
},
SurfaceId::ApparatusPane => AccessibilityDescriptor {
role: Role::Complementary,
label: "Apparatus pane",
description: Some("System diagnostics, probes, accessibility status, and settings."),
keyboard_shortcut: Some("Ctrl+,"),
},
SurfaceId::CommsPane => AccessibilityDescriptor {
role: Role::Complementary,
label: "Comms pane",
description: Some("Mail and cabal conversation surface."),
keyboard_shortcut: None,
},
SurfaceId::WorkbenchPane => AccessibilityDescriptor {
role: Role::TabPanel,
label: "Workbench pane",
description: Some("Tiled live node workbench."),
keyboard_shortcut: Some("Ctrl+T"),
},
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_surface_has_a_non_empty_label() {
for surface in [
SurfaceId::Omnibar,
SurfaceId::CommandPalette,
SurfaceId::NodeFinder,
SurfaceId::ContextMenu,
SurfaceId::ConfirmDialog,
SurfaceId::NodeCreate,
SurfaceId::FrameRename,
SurfaceId::StatusBar,
SurfaceId::TreeSpine,
SurfaceId::NavigatorHost,
SurfaceId::TilePane,
SurfaceId::CanvasPane,
SurfaceId::BaseLayer,
SurfaceId::RosterPane,
SurfaceId::InspectorPane,
SurfaceId::StewardPane,
SurfaceId::GlossPane,
SurfaceId::ApparatusPane,
SurfaceId::CommsPane,
SurfaceId::WorkbenchPane,
] {
let d = descriptor_for(surface);
assert!(
!d.label.is_empty(),
"{surface:?} ships with an empty a11y label",
);
}
}
#[test]
fn keyboard_shortcuts_include_modifier_keys() {
for surface in [
SurfaceId::Omnibar,
SurfaceId::CommandPalette,
SurfaceId::NodeFinder,
] {
let d = descriptor_for(surface);
let ks = d
.keyboard_shortcut
.expect("this surface should ship with a shortcut hint");
assert!(
ks.contains("Ctrl") || ks.contains("Cmd") || ks.contains("Alt"),
"{surface:?} shortcut hint missing modifier: {ks}",
);
}
}
#[test]
fn apply_writes_role_and_label_to_accesskit_node() {
let d = descriptor_for(SurfaceId::ConfirmDialog);
let mut node = accesskit::Node::new(d.role);
d.apply(&mut node);
let _ = node;
}
}