Scoop API

scoop:scoop.ui:0.1.0

src/accessibility/text_children.scoop

Selected production source · src/accessibility/text_children.scoop

1package scoop.ui
3import scoop.collections.HashMap
4import scoop.window.Utf8Range
5import scoop.window.accessibility.*
7internal class SemanticTextChildBinding(
8 val parent: SemanticsHandle,
9 val text: String,
10 val range: Utf8Range
13internal fun refreshSemanticTextChildren(handles: Array<SemanticsHandle>) {
14 val entries = HashMap<SemanticNodeId, ArrayList<SemanticTextChild>>()
15 for (handle in handles) {
16 if (!handle.active)
17 continue
18 val binding = handle.textChild ?: continue
19 val parent = binding.parent
20 if (
21 !parent.active ||
22 parent.properties.protectedText ||
23 parent.properties.value !=
24 Some(binding.text)
25 )
26 continue
27 var ancestor = handle.parent
28 var descendant = false
29 while (true) {
30 val current = ancestor ?: break
31 if (current === parent) {
32 descendant = true;
33 break
34 }
35 ancestor = current.parent
36 }
37 if (!descendant)
38 continue
39 val children = entries[parent.id] ?: ArrayList<SemanticTextChild>()
40 children.add(SemanticTextChild(handle.id, binding.range))
41 entries[parent.id] = children
42 }
43 for (handle in handles)
44 if (
45 handle.active &&
46 (handle.role == SemanticRole.Text || handle.role == SemanticRole.TextField)
47 )
48 handle.resource.textChildren = entries[handle.id]?.toArray() ?: []