iced_winit/
a11y.rs

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
use crate::futures::futures::channel::mpsc;
use crate::program::Control;

use iced_accessibility::accesskit::{
    ActivationHandler, NodeBuilder, NodeId, Role, Tree, TreeUpdate,
};
use iced_accessibility::accesskit_winit::Adapter;
use iced_runtime::core;

pub struct WinitActivationHandler {
    pub proxy: mpsc::UnboundedSender<Control>,
    pub title: String,
}

impl ActivationHandler for WinitActivationHandler {
    fn request_initial_tree(
        &mut self,
    ) -> Option<iced_accessibility::accesskit::TreeUpdate> {
        let node_id = core::id::window_node_id();

        let _ = self
            .proxy
            .unbounded_send(Control::AccessibilityEnabled(true));
        let mut node = NodeBuilder::new(Role::Window);
        node.set_name(self.title.clone());
        let node = node.build();
        let root = NodeId(node_id);
        Some(TreeUpdate {
            nodes: vec![(root, node)],
            tree: Some(Tree::new(root)),
            focus: root,
        })
    }
}

pub struct WinitActionHandler {
    pub id: core::window::Id,
    pub proxy: mpsc::UnboundedSender<Control>,
}

impl iced_accessibility::accesskit::ActionHandler for WinitActionHandler {
    fn do_action(
        &mut self,
        request: iced_accessibility::accesskit::ActionRequest,
    ) {
        let _ = self
            .proxy
            .unbounded_send(Control::Accessibility(self.id, request));
    }
}

pub struct WinitDeactivationHandler {
    pub proxy: mpsc::UnboundedSender<Control>,
}

impl iced_accessibility::accesskit::DeactivationHandler
    for WinitDeactivationHandler
{
    fn deactivate_accessibility(&mut self) {
        let _ = self
            .proxy
            .unbounded_send(Control::AccessibilityEnabled(false));
    }
}