Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Jun 21, 2024
1 parent a419383 commit d407e0b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 56 deletions.
9 changes: 8 additions & 1 deletion examples/accessibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ fn main() {
fn app() -> Element {
rsx! {
body {
"Dioxus 4 all"
App {}
}
}
}

#[component]
fn App() -> Element {
rsx! {
div { "Dioxus for all" }
}
}
91 changes: 36 additions & 55 deletions packages/dioxus-blitz/src/window.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::waker::UserEvent;
use blitz::{RenderState, Renderer, Viewport};
use blitz_dom::{Document, DocumentLike, Node};
use blitz_dom::{DocumentLike, Node};
use winit::keyboard::PhysicalKey;

#[allow(unused)]
Expand Down Expand Up @@ -98,34 +98,10 @@ impl<'a, Doc: DocumentLike> View<'a, Doc> {
Some(waker) => {
let cx = std::task::Context::from_waker(waker);
if self.renderer.poll(cx) {
let Some(ref mut state) = self.state else {
return true;
};

// TODO send fine grained accessibility tree updates.
let changed = mem::take(&mut self.renderer.dom.as_mut().changed);
if !changed.is_empty() {
let doc = self.renderer.dom.as_ref();

let mut nodes = Vec::new();
doc.visit(|node_id, node| {
let (id, node_builder) = state.build_node(node_id, node);
nodes.push((id, node_builder.build()));
});

let mut window = accesskit::NodeBuilder::new(accesskit::Role::Window);
for (id, _) in &nodes {
window.push_child(*id);
}
nodes.push((accesskit::NodeId(0), window.build()));

let tree = accesskit::Tree::new(accesskit::NodeId(0));
let tree_update = accesskit::TreeUpdate {
nodes,
tree: Some(tree),
focus: accesskit::NodeId(0),
};

state.adapter.update_if_active(|| tree_update)
self.build_accessibility_tree()
}

true
Expand Down Expand Up @@ -356,35 +332,8 @@ impl<'a, Doc: DocumentLike> View<'a, Doc> {

#[cfg(feature = "accesskit")]
pub fn handle_accessibility_event(&mut self, event: &accesskit_winit::WindowEvent) {
let Some(ref mut state) = self.state else {
return;
};

match event {
accesskit_winit::WindowEvent::InitialTreeRequested => {
let doc = self.renderer.dom.as_ref();

let mut nodes = Vec::new();
doc.visit(|node_id, node| {
let (id, node_builder) = state.build_node(node_id, node);
nodes.push((id, node_builder.build()));
});

let mut window = accesskit::NodeBuilder::new(accesskit::Role::Window);
for (id, _) in &nodes {
window.push_child(*id);
}
nodes.push((accesskit::NodeId(0), window.build()));

let tree = accesskit::Tree::new(accesskit::NodeId(0));
let tree_update = accesskit::TreeUpdate {
nodes,
tree: Some(tree),
focus: accesskit::NodeId(0),
};

state.adapter.update_if_active(|| tree_update)
}
accesskit_winit::WindowEvent::InitialTreeRequested => self.build_accessibility_tree(),
accesskit_winit::WindowEvent::AccessibilityDeactivated => {
// TODO
}
Expand Down Expand Up @@ -446,6 +395,38 @@ impl<'a, Doc: DocumentLike> View<'a, Doc> {
self.waker = None;
self.renderer.suspend();
}

fn build_accessibility_tree(&mut self) {
let Some(ref mut state) = self.state else {
return;
};

let changed = mem::take(&mut self.renderer.dom.as_mut().changed);
if !changed.is_empty() {
let doc = self.renderer.dom.as_ref();

let mut nodes = Vec::new();
doc.visit(|node_id, node| {
let (id, node_builder) = state.build_node(node_id, node);
nodes.push((id, node_builder.build()));
});

let mut window = accesskit::NodeBuilder::new(accesskit::Role::Window);
for (id, _) in &nodes {
window.push_child(*id);
}
nodes.push((accesskit::NodeId(0), window.build()));

let tree = accesskit::Tree::new(accesskit::NodeId(0));
let tree_update = accesskit::TreeUpdate {
nodes,
tree: Some(tree),
focus: accesskit::NodeId(0),
};

state.adapter.update_if_active(|| tree_update)
}
}
}

/// Initialize the default menu bar.
Expand Down

0 comments on commit d407e0b

Please sign in to comment.