scoop:scoop.window:0.1.0
src/accessibility/values.scoop
Selected production source · src/accessibility/values.scoop
1
package scoop.window.accessibility3
import scoop.window.*5
/** A small identity owner that does not retain a window or its application. */6
internal class SemanticIdentity {7
var next = 1L8
}10
/** A window-owned identity. Closing a provider never makes it refer to another node. */11
public class SemanticNodeId internal constructor(12
private val identity: SemanticIdentity,13
public val window: WindowId,14
internal val number: Long15
) : Equals<SemanticNodeId>, Hash {16
public override operator fun equals(other: SemanticNodeId): Boolean = identity ===17
other.identity &&18
number ==19
other.number20
public override fun hash(): Long = number.hash()21
}23
/** Roles implemented by the initial native content provider. */24
public enum SemanticRole {25
Group, Text, Button, Checkbox, TextField, ScrollArea, ScrollBar, Switch, ToggleButton, RadioButton, RadioGroup, Image, List,26
Link, Heading, Slider, ProgressBar, Menu, MenuItem, TabGroup, Tab, Dialog, Table, Cell, RowHeader, ColumnHeader, Disclosure, Separator, Row, Tree, TreeItem27
}29
public enum SemanticSelectionMode {30
Single, Multiple31
}33
public enum SemanticChecked {34
Off, On, Mixed35
}37
/** The active text endpoint's side of a shared visual-line boundary. */38
public enum SemanticTextAffinity {39
Upstream, Downstream40
}42
/** Unknown strings differ from known empty strings. Protected text has no public value. */43
public struct SemanticProperties(44
val name: String? = None,45
val description: String? = None,46
val automationId: String? = None,47
val value: String? = None,48
val enabled: Boolean = true,49
val readOnly: Boolean = false,50
val protectedText: Boolean = false,51
val checked: SemanticChecked? = None,52
val hidden: Boolean = false,53
val error: String? = None,54
val ignored: Boolean = false,55
val selection: Utf8Selection? = None,56
val required: Boolean = false,57
val scroll: SemanticScrollRange? = None,58
val cursorAffinity: SemanticTextAffinity = SemanticTextAffinity.Downstream,59
val selected: Boolean? = None,60
val expanded: Boolean? = None,61
val invalid: Boolean = false,62
val busy: Boolean = false,63
val modal: Boolean = false,64
val headingLevel: Int? = None,65
val range: SemanticValueRange? = None,66
val url: String? = None,67
val live: SemanticLive = SemanticLive.Off,68
val table: SemanticTableSize? = None,69
val cell: SemanticTableCell? = None,70
val orientation: SemanticOrientation? = None,71
val selectionMode: SemanticSelectionMode? = None,72
/** Whether this text field accepts multiple logical lines, including while empty. */73
val multiline: Boolean = false74
) {75
internal fun check() {76
requireWindow(!protectedText || value == None, "protected text cannot publish a value")77
scroll?.check()78
range?.check()79
table?.check()80
cell?.check()81
requireWindow(82
range == None || (value == None && scroll == None),83
"numeric ranges cannot publish text or scroll values"84
)85
when (headingLevel) {86
case Some(val level) -> requireWindow(level >= 1 && level <= 6, "invalid heading level")87
case None -> {}88
}89
requireWindow(scroll == None || value == None, "scroll ranges cannot publish text values")90
when (selection) {91
case Some(val selected) -> {92
requireWindow(93
!protectedText && value != None,94
"text selection requires public text"95
)96
checkTextRange(value!!.toByteArray(), selected.range)97
}99
case None -> {}100
}101
}102
}104
/** Ordered references in one active provider; they do not change parenthood or focus. */105
public enum SemanticDescendant : Equals<SemanticDescendant> {106
Node(SemanticNodeId), Item(SemanticNodeId, SemanticItemKey)107
public override operator fun equals(other: SemanticDescendant): Boolean = when ((this, other)) {108
case(Node(val left), Node(val right)) -> left == right109
case(Item(val left, val key), Item(val right, val otherKey)) ->110
left == right && key == otherKey111
else -> false112
}113
internal val node: SemanticNodeId114
get() = when (this) {115
case Node(val id) -> id116
case Item(val id, _) -> id117
}118
}120
public struct SemanticRelations(121
val labelledBy: Array<SemanticNodeId> = [],122
val describedBy: Array<SemanticNodeId> = [],123
val errorMessages: Array<SemanticNodeId> = [],124
val controls: Array<SemanticNodeId> = [],125
val activeDescendant: SemanticDescendant? = None,126
val rowHeaders: Array<SemanticNodeId> = [],127
val columnHeaders: Array<SemanticNodeId> = []128
) : Equals<SemanticRelations> {129
public override operator fun equals(other: SemanticRelations): Boolean = sameSemanticIds(130
labelledBy,131
other.labelledBy132
) &&133
sameSemanticIds(describedBy, other.describedBy) &&134
sameSemanticIds(errorMessages, other.errorMessages) &&135
sameSemanticIds(controls, other.controls) &&136
activeDescendant ==137
other.activeDescendant &&138
sameSemanticIds(rowHeaders, other.rowHeaders) &&139
sameSemanticIds(columnHeaders, other.columnHeaders)141
internal val references: Array<Array<SemanticNodeId>>142
get() = [143
labelledBy,144
describedBy,145
errorMessages,146
controls,147
rowHeaders,148
columnHeaders,149
when (activeDescendant) {150
case Some(val value) -> [value.node];151
case None -> []152
}153
]154
}156
internal fun sameSemanticIds(left: Array<SemanticNodeId>, right: Array<SemanticNodeId>): Boolean {157
if (left === right) return true158
if (left.size != right.size) return false159
for (index in 0L..<left.size)160
if (left[index] != right[index]) return false161
return true162
}164
/** Bounds are not a promise that their center is a valid clickable point. */165
public struct SemanticGeometry(166
val bounds: LogicalRect,167
val visibleBounds: LogicalRect? = Some(bounds)168
) {169
internal fun check() {170
checkSemanticRect(bounds)171
when (visibleBounds) {172
case Some(val visible) -> {173
checkSemanticRect(visible)174
requireWindow(175
visible.origin.x >=176
bounds.origin.x &&177
visible.origin.y >=178
bounds.origin.y &&179
visible.origin.x +180
visible.size.width <=181
bounds.origin.x +182
bounds.size.width &&183
visible.origin.y +184
visible.size.height <=185
bounds.origin.y +186
bounds.size.height,187
"visible semantic geometry must be inside its bounds"188
)189
}191
case None -> {}192
}193
}194
}196
private fun checkSemanticRect(value: LogicalRect) {197
checkRect(value)198
requireWindow(199
(value.origin.x + value.size.width).isFinite() &&200
(value.origin.y + value.size.height).isFinite(),201
"semantic rectangle overflow"202
)203
}205
/** Completion describes the UI action, not any asynchronous business it starts. */206
public enum SemanticActionResult {207
Completed, InvalidArgument, Unsupported, Unavailable, Rejected, Busy208
}210
/** Native capabilities are derived from these actual implementations. */211
public struct SemanticActions(212
val invoke: (() -> SemanticActionResult)? = None,213
val toggle: (() -> SemanticActionResult)? = None,214
val setValue: ((String) -> SemanticActionResult)? = None,215
val focus: ((Boolean) -> SemanticActionResult)? = None,216
val setSelection: ((Utf8Selection) -> SemanticActionResult)? = None,217
val replaceText: ((Utf8Range, String) -> SemanticActionResult)? = None,218
val showContextMenu: (() -> SemanticActionResult)? = None,219
val setScrollPosition: ((Double) -> SemanticActionResult)? = None,220
val scrollBackward: (() -> SemanticActionResult)? = None,221
val scrollForward: (() -> SemanticActionResult)? = None,222
/** Completes only when matching accepted geometry is visible, without changing focus. */223
val reveal: (() -> SemanticActionResult)? = None,224
val setNumber: ((Double) -> SemanticActionResult)? = None,225
val increment: (() -> SemanticActionResult)? = None,226
val decrement: (() -> SemanticActionResult)? = None,227
val setSelected: ((Boolean) -> SemanticActionResult)? = None,228
val setExpanded: ((Boolean) -> SemanticActionResult)? = None,229
val dismiss: (() -> SemanticActionResult)? = None,230
val revealText: ((Utf8Range, SemanticTextScroll) -> SemanticActionResult)? = None231
) {232
public val isEmpty: Boolean get() = capabilities == 0233
internal val capabilities: Int234
get() {235
var result = 0236
when (invoke) {237
case Some(_) -> result += 1;238
case None -> {}239
}240
when (toggle) {241
case Some(_) -> result += 2;242
case None -> {}243
}244
when (setValue) {245
case Some(_) -> result += 4;246
case None -> {}247
}248
when (focus) {249
case Some(_) -> result += 8;250
case None -> {}251
}252
when (setSelection) {253
case Some(_) -> result += 16;254
case None -> {}255
}256
when (replaceText) {257
case Some(_) -> result += 32;258
case None -> {}259
}260
when (showContextMenu) {261
case Some(_) -> result += 64;262
case None -> {}263
}264
when (setScrollPosition) {265
case Some(_) -> result += 128;266
case None -> {}267
}268
when (scrollBackward) {269
case Some(_) -> result += 256;270
case None -> {}271
}272
when (scrollForward) {273
case Some(_) -> result += 512;274
case None -> {}275
}276
when (reveal) {277
case Some(_) -> result += 1024;278
case None -> {}279
}280
when (setNumber) {281
case Some(_) -> result += 2048;282
case None -> {}283
}284
when (increment) {285
case Some(_) -> result += 4096;286
case None -> {}287
}288
when (decrement) {289
case Some(_) -> result += 8192;290
case None -> {}291
}292
when (setSelected) {293
case Some(_) -> result += 16384;294
case None -> {}295
}296
when (setExpanded) {297
case Some(_) -> result += 32768;298
case None -> {}299
}300
when (dismiss) {301
case Some(_) -> result += 65536;302
case None -> {}303
}304
when (revealText) {305
case Some(_) -> result += 131072;306
case None -> {}307
}308
return result309
}310
}312
internal fun actionCode(value: SemanticActionResult): Int = when (value) {313
case Completed -> 1314
case InvalidArgument -> 2315
case Unsupported -> 3316
case Unavailable -> 4317
case Rejected -> 5318
case Busy -> 6319
}