scoop:scoop.ui:0.1.0
src/accessibility/text_children.scoop
Selected production source · src/accessibility/text_children.scoop
1
package scoop.ui3
import scoop.collections.HashMap4
import scoop.window.Utf8Range5
import scoop.window.accessibility.*7
internal class SemanticTextChildBinding(8
val parent: SemanticsHandle,9
val text: String,10
val range: Utf8Range11
)13
internal fun refreshSemanticTextChildren(handles: Array<SemanticsHandle>) {14
val entries = HashMap<SemanticNodeId, ArrayList<SemanticTextChild>>()15
for (handle in handles) {16
if (!handle.active)17
continue18
val binding = handle.textChild ?: continue19
val parent = binding.parent20
if (21
!parent.active ||22
parent.properties.protectedText ||23
parent.properties.value !=24
Some(binding.text)25
)26
continue27
var ancestor = handle.parent28
var descendant = false29
while (true) {30
val current = ancestor ?: break31
if (current === parent) {32
descendant = true;33
break34
}35
ancestor = current.parent36
}37
if (!descendant)38
continue39
val children = entries[parent.id] ?: ArrayList<SemanticTextChild>()40
children.add(SemanticTextChild(handle.id, binding.range))41
entries[parent.id] = children42
}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() ?: []49
}