Scoop API

scoop:scoop.window:0.1.0

src/accessibility/text_children.scoop

Selected production source · src/accessibility/text_children.scoop

1package scoop.window.accessibility
3import scoop.collections.HashSet
4import scoop.window.*
6public struct SemanticTextChild(val node: SemanticNodeId, val range: Utf8Range)
8internal fun sameSemanticTextChildren(
9 a: Array<SemanticTextChild>,
10 b: Array<SemanticTextChild>
11): Boolean {
12 if (a.size != b.size)
13 return false
14 for (index in 0L ..< a.size)
15 if (a[index] != b[index])
16 return false
17 return true
20internal fun checkSemanticTextChildren(
21 source: AccessibilityNode,
22 children: Array<SemanticTextChild>
23) {
24 if (children.size == 0L)
25 return
26 requireWindow(
27 !source.properties.protectedText &&
28 source.properties.value !=
29 None &&
30 (source.role == SemanticRole.Text || source.role == SemanticRole.TextField),
31 "text children require public text"
32 )
33 val bytes = source.properties.value!!.toByteArray()
34 val ids = HashSet<SemanticNodeId>()
35 for (child in children) {
36 requireWindow(ids.add(child.node), "duplicate text child")
37 checkSemanticTargets(source, [child.node])
38 checkTextRange(bytes, child.range)
39 var ancestor = source.provider.lookup(child.node)!!.parentNode
40 var descendant = false
41 while (true) {
42 val node = ancestor ?: break
43 if (node === source) {
44 descendant = true;
45 break
46 }
47 ancestor = node.parentNode
48 }
49 requireWindow(descendant, "text child must be a semantic descendant")
50 }
53internal fun withoutSemanticTextChild(
54 children: Array<SemanticTextChild>,
55 id: SemanticNodeId
56): Array<SemanticTextChild> {
57 val result = ArrayList<SemanticTextChild>()
58 for (child in children)
59 if (child.node != id)
60 result.add(child)
61 return result.toArray()