1use super::*;
4
5impl AppRuntime {
6 pub fn extract_text_content(bp: &NodeBlueprint) -> String {
8 match bp {
9 NodeBlueprint::Text(s) => s.clone(),
10 NodeBlueprint::DynamicText(f) => f(),
11 NodeBlueprint::Element { children, .. } | NodeBlueprint::Fragment(children) => children
12 .iter()
13 .map(Self::extract_text_content)
14 .filter(|s| !s.is_empty())
15 .collect::<Vec<_>>()
16 .join(" "),
17 NodeBlueprint::Empty => String::new(),
18 }
19 }
20
21 pub fn update_accessibility_tree(&mut self) -> strata_a11y::A11yTreeUpdate {
23 let focused_id = self
24 .active_focus
25 .as_ref()
26 .map(|f| strata_a11y::A11yNodeId(f.input_index as u64 + 1));
27 let new_tree = strata_a11y::build_a11y_tree_with_layout(
28 &self.root_blueprint,
29 &self.layout_root,
30 focused_id,
31 );
32
33 let update = self.a11y_bridge.update(new_tree.clone());
34 self.a11y_tree = Some(new_tree);
35 self.a11y_updates_count += 1;
36 update
37 }
38
39 pub fn full_accessibility_update(&self) -> strata_a11y::A11yTreeUpdate {
41 if let Some(ref tree) = self.a11y_tree {
42 strata_a11y::A11yTreeUpdate::diff(None, tree)
43 } else {
44 strata_a11y::A11yTreeUpdate::empty()
45 }
46 }
47
48 pub fn dispatch_accessibility_action(
50 &mut self,
51 target_node: strata_a11y::A11yNodeId,
52 action: strata_a11y::A11yAction,
53 ) -> bool {
54 if let Some(ref tree) = self.a11y_tree {
55 if let Some(node) = tree.get_node(target_node) {
56 match &action {
57 strata_a11y::A11yAction::Click => {
58 if let Some(bounds) = node.bounds {
59 let cx = bounds.x + bounds.width * 0.5;
60 let cy = bounds.y + bounds.height * 0.5;
61 self.dispatch_click(cx, cy);
62 self.a11y_bridge.dispatch_action(target_node, action);
63 return true;
64 }
65 }
66 strata_a11y::A11yAction::Focus => {
67 if let Some(bounds) = node.bounds {
68 let cx = bounds.x + bounds.width * 0.5;
69 let cy = bounds.y + bounds.height * 0.5;
70 self.dispatch_pointer_down(cx, cy);
71 self.a11y_bridge.dispatch_action(target_node, action);
72 return true;
73 }
74 }
75 strata_a11y::A11yAction::SetValue(val) => {
76 if let Some(ref focus) = self.active_focus {
77 focus.state.text.set(val.clone());
78 if let Some(ref on_input) = focus.on_input {
79 on_input(strata_dom::Event {
80 value: val.clone(),
81 ..Default::default()
82 });
83 }
84 self.a11y_bridge.dispatch_action(target_node, action);
85 return true;
86 }
87 }
88 _ => {
89 self.a11y_bridge.dispatch_action(target_node, action);
90 return true;
91 }
92 }
93 }
94 }
95 self.a11y_bridge.dispatch_action(target_node, action);
96 false
97 }
98}