scoop:scoop.ui:0.1.0
src/accessibility/reference.scoop
Selected production source · src/accessibility/reference.scoop
1
package scoop.ui3
import scoop.platform.concurrent.currentThreadId4
import scoop.window.accessibility.SemanticNodeId6
/** A render-observable reference to one actual mounted semantic node. */7
public class SemanticsReference public constructor(): Equals<SemanticsReference> {8
private val thread = currentThreadId()9
private val current = state<SemanticNodeId?>(None)10
private var owner: SemanticsHandle? = None11
public val id: SemanticNodeId? get() {12
checkThread()13
return current.value14
}15
public override operator fun equals(other: SemanticsReference): Boolean = this === other16
private fun checkThread() {17
if (currentThreadId() != thread)18
throw IllegalStateException(Some("semantic reference used from another thread"))19
}20
internal fun checkTarget(handle: SemanticsHandle) {21
checkThread()22
when (owner) {23
case Some(val previous) -> requireUi(24
previous === handle || previous.isClosed,25
"semantic reference already has an active target"26
)27
case None -> {}28
}29
}30
internal fun attach(handle: SemanticsHandle) {31
checkTarget(handle)32
when (owner) {33
case Some(val previous) -> if (previous === handle)34
return35
case None -> {}36
}37
owner = Some(handle)38
current.value = Some(handle.id)39
}40
internal fun detach(handle: SemanticsHandle) {41
checkThread()42
when (owner) {43
case Some(val previous) -> if (previous === handle) {44
owner = None45
current.value = None46
}47
case None -> {}48
}49
}50
}