Skip to content

macOS: native child views are invisible to VoiceOver #1680

Done

Description

@designnotdrum

A native view added as a subview of the window's content view (through WindowHandle::with_raw_handle) never shows up in the accessibility tree, so VoiceOver can't reach it. We hit this embedding a WKWebView (via wry's build_as_child) to show HTML email inside a Rune window.

What's going on

AccessKit's SubclassingAdapter replaces the content view's accessibilityChildren, accessibilityHitTest: and accessibilityFocusedUIElement with its own (vendor/accesskit_macos/src/subclass.rs, children, hit_test and focus, around lines 131-161 at 21e5342). Those only answer from the AccessKit tree, so AppKit's normal subview children are dropped.

Repro

  1. Any Rune window on macOS. Add a visible WKWebView as a subview of the content view and load some HTML with a link in it.
  2. From another process, walk the window with AXUIElementCopyAttributeValue(..., kAXChildrenAttribute) the way VoiceOver does, or just turn VoiceOver on and VO+Right Arrow through the window.
  3. Hit test a point inside the web view with AXUIElementCopyElementAtPosition.

Expected: the walk reaches an AXWebArea with the page's text and links, and the hit test lands inside it.

Actual: the content view's accessibilityChildren is only AccessKitNode. The walk finds no web area, and the hit test fails with -25208.

Workaround we're using

Replacing those three methods at runtime on the AccessKitSubclassOf... class, so each keeps AccessKit's answer and adds the visible native subviews. With that, the walk reaches AXWebArea with its links, images and tables, and the hit test lands on the right cell. It works, but it depends on AccessKit's class name and adds unsafe code on our side. One gotcha we hit: WebKit fills in its tree lazily, so the first walk after the view appears comes back empty and a second one shortly after is complete.

Ask

A supported way to host a native view in the accessibility tree at an element's position. Something like an El role that names a native child view, so VoiceOver reads it in layout order instead of after everything else.

Related: #111

Activity

  1. opencodejr commented on Nov 25, 2026

    @opencodejr
    Contributor

    Thanks for the detailed write-up and the workaround. The code agrees with what you found: in vendor/accesskit_macos/src/subclass.rs, the children, focus and hit_test overrides answer only from the AccessKit tree, through Adapter::view_children, focus and hit_test. AppKit's own answer is used only when there's no adapter or the call is off the main thread. Rune's vendor/accesskit_macos.patch adds that main-thread guard and nothing else there, so the content view's native subviews never get into the tree. I also didn't find any public way in Rune today to attach a native view to an element in the accessibility tree. WindowHandle::with_raw_handle only gives you the raw handle.

    I'm tracking this as a feature request: a supported way to host a native child view at an element's position, so VoiceOver reads it in layout order and hit tests and focus reach it. The point about WebKit building its tree lazily is useful, since whatever we add has to cope with a first walk that comes back empty. Related: #412 (a native web view element) and #111 (WCAG and VoiceOver).

  2. opencodejr commented on Nov 25, 2026

    @opencodejr
    Contributor

    I looked at making this change but haven't opened a PR. The environment I work in can't build or run macOS code, and this fix is unsafe Objective-C runtime code in vendor/accesskit_macos/src/subclass.rs that would run on every Rune window's content view. I don't want to propose that without compiling it and checking it with VoiceOver.

    What I found while looking:

    • Rune uses accesskit_macos::SubclassingAdapter (crates/rune/src/a11y/macos.rs). The vendored crate is rebuilt from vendor/accesskit_macos.patch by scripts/vendor-accesskit-macos.sh, so a fix belongs in that patch.
    • A minimal fix along the lines of your workaround:
      • accessibilityChildren: AccessKit's root plus the superclass's own children.
      • accessibilityHitTest:: the superclass's answer when it lands somewhere other than the content view itself, otherwise AccessKit's.
      • accessibilityFocusedUIElement: forwarded to the window's first responder when that responder is a native subview.
    • One thing to check first: crates/rune/src/system_material/macos.rs adds its own host view under the content view. It must not show up as an extra child or capture hit tests.
    • With that minimal fix, the native view is still read after the whole Rune tree, not in its place. Putting it at an element's position, like the El role you suggest, needs an API decision from the maintainers.

    Your workaround and the note that WebKit fills in its tree lazily are both good starting points for whoever picks this up.

  3. Hona commented on Nov 27, 2026

    @Hona
    Member

    Fixed in #2633 (80f235400).

    Design decision:

    • Updated vendor/accesskit_macos/src/subclass.rs (and vendor/accesskit_macos.patch) so the content view's accessibilityChildren, accessibilityHitTest:, and accessibilityFocusedUIElement preserve visible native child NSViews alongside Rune's AccessKit tree:
      • accessibilityChildren keeps AccessKit's nodes and appends non-empty [super accessibilityChildren] after releasing the adapter's RefCell borrow, so native subviews (such as a WKWebView added via WindowHandle::with_raw_handle) are reachable by VoiceOver and AX tree walks (including lazily populated WebKit trees on subsequent walks).
      • accessibilityHitTest: asks [super accessibilityHitTest:] first and returns the hit when it lands on a native subview rather than the content view or an ancestor (such as NSWindow, which AppKit returns via NSAccessibilityUnignoredAncestor when no subview matches), falling through to AccessKit otherwise.
      • accessibilityFocusedUIElement forwards to window.firstResponder when it is a strict descendant NSView (with a re-entrancy guard), falling through to AccessKit otherwise.
    • Explicitly hid Rune's internal RuneMaterialHost backdrop view (crates/rune/src/system_material/macos.rs) from AppKit accessibility (isAccessibilityElement = NO, accessibilityIsIgnored = YES, empty accessibilityChildren / accessibilityChildrenInNavigationOrder, and nil accessibilityHitTest:) so system material views do not leak into VoiceOver or capture hit tests.
    • Native child views appear after Rune's AccessKit nodes in the window's children list; placing a native view inline at a specific El's layout position remains tied to a first-class native view element API (Native web view element (for inline players such as YouTube embeds) #412).

    Verification:

    • Verified locally on Windows: cargo check -p accesskit_macos --target aarch64-apple-darwin, cargo clippy -p accesskit_macos --target aarch64-apple-darwin -- -D warnings, clean git apply --check of vendor/accesskit_macos.patch against upstream accesskit_macos 0.27.2, and unit tests (cargo test -p rune --lib a11y::macos_tests and system_material::tests).
    • Not verified on macOS hardware: live macOS VoiceOver, WKWebView lazy AX tree walks, and AppKit hit-testing were not run locally on this Windows machine. Please reopen if anything still behaves unexpectedly with VoiceOver on macOS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions