-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AccessKit integration #78
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
d611f85
Connect the hot-reloading crate
matthunz e710cdc
Apply template updates from the hot-reload CLI
matthunz 860e80d
Run cargo fmt
matthunz 46a48b4
Make hot-reload a non-default feature
matthunz 21e11b6
Merge with main
matthunz b09b2f9
Fix panic on root node and clean up
matthunz 9228169
Merge with main
matthunz b270203
Import accesskit
matthunz e108b15
Merge branch 'hot-reload' of https://github.com/matthunz/blitz into a…
matthunz a6c643c
Pipe accesskit events to View
matthunz f4d03f7
Build example accesskit tree
matthunz dde3fcb
Add Document::visit method and build initial accesskit tree from View
matthunz dcbfb91
Create mapping from accesskit id to node id
matthunz 5b4e544
Send basic tree updates on dom change
matthunz f2be9f3
Clean up and map ids to node ids
matthunz a419383
Rebuild tree until observability is figured out
matthunz d407e0b
Clean up
matthunz 05b04a2
Fix tree hierarchy
matthunz 3d3e67d
Create AccessibilityState struct and refactor
matthunz 6a009f5
Handle more accesskit roles
matthunz 7f7e91b
Move accessibility to new module
matthunz 0ce74dd
Rename accesskit feature flag to accessibility
matthunz 709d505
Merge branch 'main' of https://github.com/matthunz/blitz into accesskit
matthunz f657a96
Merge with main
matthunz c2f984b
Fix merge
matthunz 9ae0fb7
Set element node name instead of html tag
matthunz a882185
Add labelled_by relationship for text nodes and elements
matthunz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use dioxus::prelude::*; | ||
|
||
fn main() { | ||
dioxus_blitz::launch(app); | ||
} | ||
|
||
fn app() -> Element { | ||
rsx! { | ||
body { | ||
App {} | ||
} | ||
} | ||
} | ||
|
||
#[component] | ||
fn App() -> Element { | ||
rsx! { | ||
div { "Dioxus for all" } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
use crate::waker::UserEvent; | ||
use accesskit::{NodeBuilder, NodeId, Role, Tree, TreeUpdate}; | ||
use blitz_dom::{local_name, Document, Node}; | ||
use winit::{event_loop::EventLoopProxy, window::Window}; | ||
|
||
/// State of the accessibility node tree and platform adapter. | ||
pub struct AccessibilityState { | ||
/// Adapter to connect to the [`EventLoop`](`winit::event_loop::EventLoop`). | ||
adapter: accesskit_winit::Adapter, | ||
|
||
/// Next ID to assign an an [`accesskit::Node`]. | ||
next_id: u64, | ||
} | ||
|
||
impl AccessibilityState { | ||
pub fn new(window: &Window, proxy: EventLoopProxy<UserEvent>) -> Self { | ||
Self { | ||
adapter: accesskit_winit::Adapter::with_event_loop_proxy(window, proxy.clone()), | ||
next_id: 1, | ||
} | ||
} | ||
pub fn build_tree(&mut self, doc: &Document) { | ||
let mut nodes = std::collections::HashMap::new(); | ||
let mut window = NodeBuilder::new(Role::Window); | ||
|
||
doc.visit(|node_id, node| { | ||
let parent = node | ||
.parent | ||
.and_then(|parent_id| nodes.get_mut(&parent_id)) | ||
.map(|(_, parent)| parent) | ||
.unwrap_or(&mut window); | ||
let (id, node_builder) = self.build_node(node, parent); | ||
|
||
nodes.insert(node_id, (id, node_builder)); | ||
}); | ||
|
||
let mut nodes: Vec<_> = nodes | ||
.into_iter() | ||
.map(|(_, (id, node))| (id, node.build())) | ||
.collect(); | ||
nodes.push((NodeId(0), window.build())); | ||
|
||
let tree = Tree::new(NodeId(0)); | ||
let tree_update = TreeUpdate { | ||
nodes, | ||
tree: Some(tree), | ||
focus: NodeId(0), | ||
}; | ||
|
||
self.adapter.update_if_active(|| tree_update) | ||
} | ||
|
||
fn build_node(&mut self, node: &Node, parent: &mut NodeBuilder) -> (NodeId, NodeBuilder) { | ||
let mut node_builder = NodeBuilder::default(); | ||
|
||
let id = NodeId(self.next_id); | ||
self.next_id += 1; | ||
|
||
if let Some(element_data) = node.element_data() { | ||
let name = element_data.name.local.to_string(); | ||
|
||
// TODO match more roles | ||
let role = match &*name { | ||
"button" => Role::Button, | ||
"div" => Role::GenericContainer, | ||
"header" => Role::Header, | ||
"h1" | "h2" | "h3" | "h4" | "h5" | "h6" => Role::Heading, | ||
"p" => Role::Paragraph, | ||
"section" => Role::Section, | ||
"input" => { | ||
let ty = element_data.attr(local_name!("type")).unwrap_or("text"); | ||
match ty { | ||
"number" => Role::NumberInput, | ||
_ => Role::TextInput, | ||
} | ||
} | ||
_ => Role::Unknown, | ||
}; | ||
|
||
node_builder.set_role(role); | ||
node_builder.set_html_tag(name); | ||
} else if node.is_text_node() { | ||
node_builder.set_role(Role::StaticText); | ||
node_builder.set_name(node.text_content()); | ||
parent.push_labelled_by(id) | ||
} | ||
|
||
parent.push_child(id); | ||
|
||
(id, node_builder) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might it be worth at least implementing "click" here (which of course is the only event we support generally. I think the code could just be copied from the regular click handler (skipping the bit which determines which node to generate the event for as we should be given a node id directly)