Scoop API

scoop:scoop.ui:0.1.0

src/accessibility/tree.scoop

Selected production source · src/accessibility/tree.scoop

1package scoop.ui
3import scoop.window.accessibility.*
5/** Only an actual structural change walks the mounted tree, in declaration order. */
6internal class SemanticOrder {
7 private var next = 0L
8 val handles = ArrayList<SemanticsHandle>()
9 fun apply(node: MountedNode, inherited: SemanticsHandle?) {
10 if (!node.active)
11 return
12 val ancestor =
13 when (node.body) {
14 case Portal(_) -> None
15 else -> inherited
16 }
17 for (handle in node.semanticHandles) {
18 if (!handle.active)
19 continue
20 val parent = semanticParent(handle.explicitParent, ancestor)
21 handle.resource.reparent(parent?.resource, next)
22 handle.parent = parent
23 handles.add(handle)
24 next += 1L
25 }
26 val route = semanticParent(node.semanticRoute, ancestor)
27 for (child in node.children)
28 apply(child, route)
29 }
32internal fun semanticParent(
33 local: SemanticsHandle?,
34 inherited: SemanticsHandle?
35): SemanticsHandle? =
36 when (local) {
37 case Some(val value) -> Some(value)
38 case None -> inherited
39 }
41internal fun inheritedSemantics(node: MountedNode): SemanticsHandle? {
42 var ancestor = node.parent
43 while (true) {
44 val current = ancestor ?: return None
45 when (current.body) {
46 case Portal(_) -> return None
47 else -> {}
48 }
49 when (val route = current.semanticRoute) {
50 case Some(val handle) -> if (handle.active)
51 return Some(handle)
52 case None -> {}
53 }
54 ancestor = current.parent
55 }
58internal fun checkSemanticParent(node: MountedNode, parent: SemanticsHandle?) {
59 when (parent) {
60 case Some(val handle) -> checkSemanticOwner(node, handle)
61 case None -> {}
62 }
65internal fun checkSemanticOwner(node: MountedNode, handle: SemanticsHandle) {
66 handle.checkOpen()
67 var ancestor: MountedNode? = Some(node)
68 while (true) {
69 val current = ancestor ?: break
70 if (current === handle.owner)
71 return
72 ancestor = current.parent
73 }
74 throw IllegalArgumentException(
75 Some("semantic resource must belong to this mount or an ancestor")
76 )