fix(cua-macos): resolve the zoom window when its control role is unavailable
This commit is contained in:
1 parent
82c5faca9a
commit
53c51d8590
5 files changed
+28
-23
No files matched your search
@@ -21,11 +21,11 @@
|
||||
en: 60db6c41c868f7db
|
||||
zh: 1de5d504b2d84e61
|
||||
/dsh-cua-native-helper/observation-and-input:
|
||||
en: af666f9393f24db8
|
||||
zh: 13f78e94f6bb144b
|
||||
en: a1de529f35c130d4
|
||||
zh: ec19b62804df2264
|
||||
/dsh-cua-native-helper/verification:
|
||||
en: d1c47a2f63350417
|
||||
zh: 5277d8245529b5a3
|
||||
en: 277dcf59fa285e3b
|
||||
zh: 225742e6f46baac4
|
||||
/dsh-cua-native-helper/further-exploration:
|
||||
en: 265e1927952ce6d7
|
||||
zh: 7c35d9fd98b6e6c8
|
||||
|
||||
@@ -119,7 +119,7 @@ System file-panel keyboard routing resolves the remote recipient through the sel
|
||||
|
||||
Keyboard modifier names are plain strings. The shared object API passes the names through unchanged; the macOS helper accepts `command`/`cmd`, `shift`, `option`/`alt`, `control`/`ctrl`, and `fn`, and rejects an unknown name with `INVALID_ARGUMENT`. It does not parse chord strings.
|
||||
|
||||
For `AXZoomWindow`, the helper reads the target window’s size before dispatch. If AppKit returns `kAXErrorAttributeUnsupported` (`-25205`), the helper reports success only if a second read of the same window shows a size change. It dispatches the zoom action once.
|
||||
The helper dispatches `AXZoomWindow` once. If `AXUIElementPerformAction` returns `kAXErrorAttributeUnsupported` (`-25205`), the helper reports success when it reads two different valid sizes from the same window immediately before and after dispatch. A move alone or a resize after the second read leaves the error in place. A concurrent resize by another source can also satisfy this check.
|
||||
|
||||
Tree observation and action discovery treat a generic AX failure reading one element’s action names as missing metadata. Discovery skips attributes whose writability cannot be determined. `invoke` requires a successful or unsupported-action query before reporting that no default action exists. `setValue` attempts a write only when the element confirms that `AXValue` is writable.
|
||||
|
||||
@@ -157,7 +157,7 @@ Run `python3 packages/experimental/cua-macos/native/tests/observation_benchmark.
|
||||
|
||||
Use `--panels-only` to verify that a document-window request for a sheet control reports its sheet ID and that the control can be read from the selected sheet. Fixture windows can join application sets so Stage Manager does not shrink them during background input. Use `--hover-only` with `e2e.py` or `electron_e2e.py` to verify hover independently of keyboard and file-panel scenarios. Add `--alternate-hover` to `e2e.py` for AX reveal, descendant entry, click and exit with sampled system-pointer stability. `--input-overlays` verifies that pass-through overlays allow hover and input-blocking overlays reject it without moving the pointer.
|
||||
|
||||
Run `python3 packages/experimental/cua-macos/native/tests/e2e.py` after building to exercise an isolated two-window AppKit fixture. It independently records button counts, Unicode text, actual scroll position, right-click callbacks, and drag release position. Scroll, right-button down/up, and drag down/up counters must each increase exactly once per requested gesture. The check also verifies a real NSOpenPanel sheet, path-entry keyboard routing and the selected file URL. It covers scoped snapshot replacement, screenshot dimensions, stale app cleanup and EOF shutdown. `--artifacts DIRECTORY` writes fixture-only screenshots and a private protocol transcript; the transcript contains the running-app inventory and is not a publication artifact.
|
||||
Run `python3 packages/experimental/cua-macos/native/tests/e2e.py` after building to exercise an isolated two-window AppKit fixture. It independently records button counts, Unicode text, actual scroll position, right-click callbacks, and drag release position. Scroll, right-button down/up, and drag down/up counters must each increase exactly once per requested gesture. The check also verifies a real NSOpenPanel sheet, path-entry keyboard routing and the selected file URL. It covers scoped snapshot replacement, screenshot dimensions, stale app cleanup and EOF shutdown. `--artifacts DIRECTORY` writes fixture-only screenshots and a private protocol transcript; the transcript contains the running-app inventory and is not a publication artifact. With `--selection-only`, the test zooms and restores the second window and checks both windows’ sizes against the fixture’s own observations.
|
||||
|
||||
For a Blender keyboard check, run `python3 packages/experimental/cua-macos/native/tests/blender_keyboard_e2e.py --blender /absolute/path/to/Blender.app/Contents/MacOS/Blender`. It launches one owned factory-startup GUI with private user directories, observes actual Text Editor text, selection and received modifier flags, and checks Command+A replacement, Shift+Left selection and ordinary input after modifier release. It requires an unlocked macOS session and Accessibility permission. The test activates its own instance; run it without concurrent desktop automation. `--helper` selects a previous compatible binary for a negative control; `--artifacts` selects the parent of a new private evidence directory. No Blender runtime is downloaded.
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ AppKit 在主事件循环上运行。阻塞式 socket 接收与握手使用后
|
||||
|
||||
键盘修饰键名称是普通字符串。共享对象 API 原样传递名称;macOS helper 接受 `command`/`cmd`、`shift`、`option`/`alt`、`control`/`ctrl` 和 `fn`,未知名称返回 `INVALID_ARGUMENT`。它不解析组合键字符串。
|
||||
|
||||
执行 `AXZoomWindow` 前,helper 读取目标窗口的大小。若 AppKit 返回 `kAXErrorAttributeUnsupported`(`-25205`),只有再次读取同一窗口并确认大小已改变时,helper 才报告成功。缩放动作只执行一次。
|
||||
helper 只派发一次 `AXZoomWindow`。如果 `AXUIElementPerformAction` 返回 `kAXErrorAttributeUnsupported`(`-25205`),且派发前后两次读取的同一窗口尺寸均有效且不同,helper 会报告成功。窗口仅移动位置,或在第二次读取后才改变大小时,helper 会保留原错误。如果用户或应用恰好在两次读取之间调整了窗口大小,也会被判为成功。
|
||||
|
||||
读取树或枚举动作时,某个元素的动作名查询返回一般性 AX 失败,helper 将其视为缺少动作元数据。枚举时跳过无法确认可写性的属性。`invoke` 需要成功查询元素动作才能报告没有默认动作。`setValue` 仅在元素确认 `AXValue` 可写时尝试写入。
|
||||
|
||||
@@ -157,7 +157,7 @@ AppKit 在主事件循环上运行。阻塞式 socket 接收与握手使用后
|
||||
|
||||
使用 `--panels-only` 验证通过文档窗口操作 sheet 控件时会返回该 sheet 的窗口 ID,并验证选择 sheet 后能读取该控件。fixture 窗口可加入应用集合,避免 Stage Manager 在后台输入时缩小它们。使用 `e2e.py` 或 `electron_e2e.py` 的 `--hover-only`,可独立于键盘和文件面板场景验证悬停。为 `e2e.py` 加上 `--alternate-hover` 可验证 AX 展开、进入子控件、点击和移出,并采样确认系统指针不变。`--input-overlays` 验证穿透鼠标的覆盖窗口允许悬停、拦截输入的覆盖窗口拒绝悬停且不移动指针。
|
||||
|
||||
构建后运行 `python3 packages/experimental/cua-macos/native/tests/e2e.py`,操作一个隔离的双窗口 AppKit fixture。fixture 独立记录按钮计数、Unicode 文本、实际滚动位置、右键回调和拖动释放位置。滚动、右键按下/抬起和拖动按下/抬起计数每次手势必须恰好增加一次。检查还验证真实 NSOpenPanel sheet、路径输入的键盘路由和选中文件 URL,并覆盖范围内快照替换、截图尺寸、过期应用清理和 EOF 退出。`--artifacts DIRECTORY` 写出仅包含 fixture 的截图和私有协议记录;协议记录包含运行中应用清单,不用于公开发布。
|
||||
构建后运行 `python3 packages/experimental/cua-macos/native/tests/e2e.py`,操作一个隔离的双窗口 AppKit fixture。fixture 独立记录按钮计数、Unicode 文本、实际滚动位置、右键回调和拖动释放位置。滚动、右键按下/抬起和拖动按下/抬起计数每次手势必须恰好增加一次。检查还验证真实 NSOpenPanel sheet、路径输入的键盘路由和选中文件 URL,并覆盖范围内快照替换、截图尺寸、过期应用清理和 EOF 退出。`--artifacts DIRECTORY` 写出仅包含 fixture 的截图和私有协议记录;协议记录包含运行中应用清单,不用于公开发布。加上 `--selection-only` 后,测试会缩放并还原第二个窗口,用测试应用记录的尺寸核对两个窗口。
|
||||
|
||||
Blender 键盘检查使用 `python3 packages/experimental/cua-macos/native/tests/blender_keyboard_e2e.py --blender /absolute/path/to/Blender.app/Contents/MacOS/Blender`。它以独立用户目录启动一个采用出厂配置的 GUI,观察 Text Editor 的实际文本、选区和修饰键标志,检查 Command+A 替换、Shift+Left 选区及修饰键释放后的普通输入。需要解锁的 macOS 会话和辅助功能权限。测试会激活自建实例,运行时避免并发桌面自动化。`--helper` 选择以前兼容的二进制作为反例对照,`--artifacts` 指定新建私有证据目录的父目录。不下载 Blender 运行时。
|
||||
|
||||
|
||||
@@ -225,7 +225,8 @@ final class AXAccess {
|
||||
}
|
||||
let result: AXError
|
||||
if action == "AXZoomWindow" {
|
||||
let window = try? string(element, "AXRole") == "AXWindow" ? element : self.element(element, "AXWindow")
|
||||
let role = try? string(element, "AXRole")
|
||||
let window = role == "AXWindow" ? element : try? self.element(element, "AXWindow")
|
||||
result = try Self.performZoom(readSize: {
|
||||
guard let window else { return nil }
|
||||
return Self.dimensions(try? self.attribute(window, "AXSize"))
|
||||
@@ -235,7 +236,7 @@ final class AXAccess {
|
||||
}
|
||||
guard result == .success else { throw failure(result, "perform \(action)") }
|
||||
}
|
||||
/// AppKit can resize a window and still report attributeUnsupported. Repeating the action could undo the zoom.
|
||||
/// Dispatch once. Only an observed resize of the same window can override attributeUnsupported.
|
||||
static func performZoom(readSize: () -> CGSize?, dispatch: () throws -> AXError) rethrows -> AXError {
|
||||
let before = readSize()
|
||||
let result = try dispatch()
|
||||
|
||||
@@ -108,19 +108,23 @@ import Testing
|
||||
@Test func zoomReconcilesOnlyAnObservedResizeAfterAttributeUnsupported() {
|
||||
let small = CGSize(width: 600, height: 400)
|
||||
let large = CGSize(width: 950, height: 400)
|
||||
let cases: [(CGSize?, CGSize?, AXError, AXError)] = [
|
||||
(small, large, .attributeUnsupported, .success),
|
||||
(large, small, .attributeUnsupported, .success),
|
||||
(small, small, .attributeUnsupported, .attributeUnsupported),
|
||||
(nil, large, .attributeUnsupported, .attributeUnsupported),
|
||||
(small, nil, .attributeUnsupported, .attributeUnsupported),
|
||||
(.zero, large, .attributeUnsupported, .attributeUnsupported),
|
||||
(small, .zero, .attributeUnsupported, .attributeUnsupported),
|
||||
(small, large, .cannotComplete, .cannotComplete),
|
||||
(small, large, .apiDisabled, .apiDisabled),
|
||||
(nil, nil, .success, .success),
|
||||
let zeroHeight = CGSize(width: 600, height: 0)
|
||||
let zeroWidth = CGSize(width: 0, height: 400)
|
||||
let cases: [(CGSize?, CGSize?, AXError, AXError, Int)] = [
|
||||
(small, large, .attributeUnsupported, .success, 2),
|
||||
(large, small, .attributeUnsupported, .success, 2),
|
||||
(small, small, .attributeUnsupported, .attributeUnsupported, 2),
|
||||
(nil, large, .attributeUnsupported, .attributeUnsupported, 1),
|
||||
(small, nil, .attributeUnsupported, .attributeUnsupported, 2),
|
||||
(zeroHeight, large, .attributeUnsupported, .attributeUnsupported, 1),
|
||||
(zeroWidth, large, .attributeUnsupported, .attributeUnsupported, 1),
|
||||
(small, zeroHeight, .attributeUnsupported, .attributeUnsupported, 2),
|
||||
(small, zeroWidth, .attributeUnsupported, .attributeUnsupported, 2),
|
||||
(small, large, .cannotComplete, .cannotComplete, 1),
|
||||
(small, large, .apiDisabled, .apiDisabled, 1),
|
||||
(nil, nil, .success, .success, 1),
|
||||
]
|
||||
for (before, after, reply, expected) in cases {
|
||||
for (before, after, reply, expected, expectedReads) in cases {
|
||||
var calls = 0
|
||||
var reads = 0
|
||||
let result = AXAccess.performZoom(readSize: {
|
||||
@@ -132,6 +136,6 @@ import Testing
|
||||
})
|
||||
#expect(result == expected)
|
||||
#expect(calls == 1)
|
||||
#expect(reads == (reply == .attributeUnsupported && (before?.width ?? 0) > 0 ? 2 : 1))
|
||||
#expect(reads == expectedReads)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user