Files
zed/crates
Nathan Sobo f4fe0be1f8 gpui: Composite native views into the scene on macOS (#67311)
## Summary

Adds `NativeView` to GPUI: an element that places a platform view (an
`NSView` on macOS) in a window and composites it with the rest of the
scene, so that GPUI content can be drawn both under and over it. Delta
uses this to show a `WKWebView` in a pane tab with GPUI dialogs and
toolbars drawn over the page.

What it covers on macOS:

- **Compositing.** The native view sits behind the window's Metal layer,
and the renderer cuts a hole in the scene where the view shows, so GPUI
elements painted after it appear above it. The window's layer is
non-opaque only while a scene shows a native view.
- **Keyboard input.** Keys go to a focused native view first. An
embedder can reserve actions that must keep working whatever the view
does with keys, including the first key of a multi-key binding. AppKit
controls beside a native view keep their own input.
- **Pointer.** GPUI elements over a native view block clicks to it, and
the native view chooses the cursor while the pointer is over an
unobscured part of it.
- **Accessibility.** VoiceOver can reach a native view that is shown.

Other platforms get the element and a no-op implementation:
`NativeView::new` reports that the window cannot show native views.

Also included is a small `div` fix that the embedder needed: an item a
scroll handle is asked to scroll to before the handle's first frame is
now scrolled to once it has been laid out.

## Testing

- Two examples: `cargo run -p gpui --example native_view` and `--example
native_view_appkit_field`, which show native views with GPUI drawn over
them.
- The test platform's window records native view placement, with unit
tests for the placement, input-routing policy and reserved-action logic.
- Exercised through Delta's browser tabs on macOS 26: typing, shortcuts,
splits, zoom, dialogs drawn over the page, and hiding and showing tabs.
- Not exercised by hand: the black-flash, stale-cursor and VoiceOver
fixes in the last two commits.

## Self-review

- [x] I've reviewed my diff for quality, security, reliability, and
performance.
- [ ] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist).
- [x] Tests cover the new or changed behavior.

Release Notes:

- N/A
- [GPUI] Added `NativeView`, an element that composites an `NSView` into
a window's scene with GPUI content drawn over it. Only macOS supports it
for now; `NativeView::new` returns an error on other platforms.
- [GPUI] Fixed `ScrollHandle::scroll_to_item` being ignored when called
before the handle's first frame.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: zed-zippy[bot] <234243425+zed-zippy[bot]@users.noreply.github.com>
2026-11-22 03:18:59 +00:00
..
2026-09-17 08:49:31 +00:00
2026-11-11 19:41:39 +00:00
…
2026-10-19 14:16:08 +00:00
…