Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,73 @@
import Foundation

enum SnapshotPresentation {
/// The only snapshot node shape accepted by response payload assembly.
///
/// The encoded shape intentionally remains byte-for-byte compatible with the former
/// `SnapshotNode` wire model. Construction stays file-private to this presentation module:
/// acquisition backends can return `RawAXNode` values, but cannot recreate a presented node.
struct PresentedNode: Codable {
let index: Int
let type: String
let label: String?
let identifier: String?
let value: String?
let rect: SnapshotRect
let enabled: Bool
let focused: Bool?
let selected: Bool?
let hittable: Bool
let depth: Int
let parentIndex: Int?
let hiddenContentAbove: Bool?
let hiddenContentBelow: Bool?
let actions: [String]?

fileprivate init(presenting raw: RawAXNode) {
self.init(
presenting: raw,
rect: raw.rect,
index: raw.index,
depth: raw.depth,
parentIndex: raw.parentIndex
)
}

fileprivate init(presenting node: SnapshotPresentationNode) {
self.init(
presenting: node.raw,
rect: node.effectiveRect,
index: node.raw.index,
depth: node.raw.depth,
parentIndex: node.raw.parentIndex
)
}

fileprivate init(
presenting raw: RawAXNode,
rect: SnapshotRect,
index: Int,
depth: Int,
parentIndex: Int?
) {
self.index = index
type = raw.type
label = raw.label
identifier = raw.identifier
value = raw.value
self.rect = rect
enabled = raw.enabled
focused = raw.focused
selected = raw.selected
hittable = raw.hittable
self.depth = depth
self.parentIndex = parentIndex
hiddenContentAbove = raw.hiddenContentAbove
hiddenContentBelow = raw.hiddenContentBelow
actions = raw.actions
}
}

private static let eligibleInteractiveTypes: Set<String> = [
"Button",
"Cell",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,69 +70,7 @@ struct SnapshotAcquisition {
let viewport: CGRect
}

/// The only snapshot node shape accepted by response payload assembly.
///
/// It has no memberwise initializer, so response assembly has to choose one of the explicit
/// presentation constructors. The encoded shape intentionally remains byte-for-byte compatible
/// with the former `SnapshotNode` wire model.
struct PresentedNode: Codable {
let index: Int
let type: String
let label: String?
let identifier: String?
let value: String?
let rect: SnapshotRect
let enabled: Bool
let focused: Bool?
let selected: Bool?
let hittable: Bool
let depth: Int
let parentIndex: Int?
let hiddenContentAbove: Bool?
let hiddenContentBelow: Bool?
let actions: [String]?

init(presenting raw: RawAXNode) {
self.init(
presenting: raw,
rect: raw.rect,
index: raw.index,
depth: raw.depth,
parentIndex: raw.parentIndex
)
}

init(presenting node: SnapshotPresentationNode) {
self.init(
presenting: node.raw,
rect: node.effectiveRect,
index: node.raw.index,
depth: node.raw.depth,
parentIndex: node.raw.parentIndex
)
}

init(
presenting raw: RawAXNode,
rect: SnapshotRect,
index: Int,
depth: Int,
parentIndex: Int?
) {
self.index = index
type = raw.type
label = raw.label
identifier = raw.identifier
value = raw.value
self.rect = rect
enabled = raw.enabled
focused = raw.focused
selected = raw.selected
hittable = raw.hittable
self.depth = depth
self.parentIndex = parentIndex
hiddenContentAbove = raw.hiddenContentAbove
hiddenContentBelow = raw.hiddenContentBelow
actions = raw.actions
}
}
/// Keep the wire payload's existing spelling while making the presented-node type owned by the
/// presentation module. Its constructors live in `RunnerTests+SnapshotPresentation.swift` and are
/// file-private there, so acquisition backends can carry a `PresentedNode` but cannot construct one.
typealias PresentedNode = SnapshotPresentation.PresentedNode
Loading