scoop:scoop.window:0.1.0
src/accessibility/text_children.scoop
Selected production source · src/accessibility/text_children.scoop
1
package scoop.window.accessibility3
import scoop.collections.HashSet4
import scoop.window.*6
public struct SemanticTextChild(val node: SemanticNodeId, val range: Utf8Range)8
internal fun sameSemanticTextChildren(9
a: Array<SemanticTextChild>,10
b: Array<SemanticTextChild>11
): Boolean {12
if (a.size != b.size)13
return false14
for (index in 0L ..< a.size)15
if (a[index] != b[index])16
return false17
return true18
}20
internal fun checkSemanticTextChildren(21
source: AccessibilityNode,22
children: Array<SemanticTextChild>23
) {24
if (children.size == 0L)25
return26
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)!!.parentNode40
var descendant = false41
while (true) {42
val node = ancestor ?: break43
if (node === source) {44
descendant = true;45
break46
}47
ancestor = node.parentNode48
}49
requireWindow(descendant, "text child must be a semantic descendant")50
}51
}53
internal fun withoutSemanticTextChild(54
children: Array<SemanticTextChild>,55
id: SemanticNodeId56
): 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()62
}