-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathAXScrollAreaResolver.swift
44 lines (34 loc) · 1.13 KB
/
AXScrollAreaResolver.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import AXEssibility
import AppKit
import Foundation
enum AXScrollAreaResolverError: Error {
case noResult
}
enum AXScrollAreaResolver {
static func resolveFocusedElement(_ parent: AnyFocusedAccessibilityElement) throws -> CGRect {
var match: AnyAccessibilityElement?
match = try? processElement(AnyAccessibilityElement(parent.reference))
guard let match, let frame = match.frame else {
throw AXScrollAreaResolverError.noResult
}
return frame
}
private static func processElement(_ element: AnyAccessibilityElement) throws -> AnyAccessibilityElement? {
var resolvedElement: AnyAccessibilityElement?
let children = try element.value(.children, as: [AXUIElement].self)
.map { AnyAccessibilityElement($0, messagingTimeout: element.messagingTimeout) }
if (try? element.value(.focused, as: Bool.self)) == true {
return element
}
if (try? element.value(.selected, as: Bool.self)) == true {
return element
}
for child in children {
if let result = try? processElement(child) {
resolvedElement = result
break
}
}
return resolvedElement
}
}